-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add interpolation routine to make Var.resampled_as
faster
#183
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #183 +/- ##
==========================================
+ Coverage 98.35% 98.45% +0.10%
==========================================
Files 11 11
Lines 1215 1297 +82
==========================================
+ Hits 1195 1277 +82
Misses 20 20 ☔ View full report in Codecov by Sentry. |
5e3c3be
to
d4e432a
Compare
This commit adds an interpolation routine for use in ClimaAnalysis, which seeks to replace Interpolations.jl in Var.jl. The interpolation routine supports N-dimensional linear interpolation on a grid with throw, flat, or periodic boundary conditions. Compared against Interpolations.jl, the interpolation routine does not make a struct and does not allocate anything on the heap when interpolating a point.
This commit removes Interpolations.jl from Var.jl. To do this, the function `_make_interpolant` was removed. Three new functions are added which are `_check_interpolant`, `interpolate_point`, and `interpolate_points`, where the latter two functions replace the functionality of `_make_interpolant`. Furthermore, the function `_find_extp_bound_cond` was refactored to `_find_extp_bound_conds` which find multiple extrapolation condtions using `_find_extp_bound_cond` which is refactored to find the extrapolation condition for a single point. All functions that use an interpolant are updated to use the new interpolation routine. The test for computing the bias in Atmos changes to check approximately close to 0.0, due to floating point errors. The tests that check for errors when interpolating out of bounds now check for ErrorException instead of BoundsError.
function linear_interpolate( | ||
point::Number, | ||
axes, | ||
data::AbstractArray{FT2, N}, | ||
extp_conds, | ||
) where {N, FT2} | ||
point = Tuple(point...) | ||
return linear_interpolate(point, axes, data, extp_conds) | ||
end | ||
|
||
function linear_interpolate( | ||
point::AbstractVector, | ||
axes, | ||
data::AbstractArray{FT2, N}, | ||
extp_conds, | ||
) where {N, FT2} | ||
point = Tuple(coord for coord in point) | ||
return linear_interpolate(point, axes, data, extp_conds) | ||
end | ||
|
||
function linear_interpolate( | ||
point::Tuple, | ||
axes, | ||
data::AbstractArray{FT2, N}, | ||
extp_conds, | ||
) where {N, FT2} | ||
point = promote(point...) | ||
return linear_interpolate(point, axes, data, extp_conds) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add comments to explain what these methods are accomplishing?
Given a tuple consisting of 2-tuple, return a tuple of one element from each tuple according to bits. | ||
""" | ||
function get_indices(indices::NTuple{N}, bits) where {N} | ||
return ntuple(dim -> if (bits & (1 << (dim - 1)) != 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a link to where you found this bit manipulation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also move all the linear interpolation into its own module, so that it will be easier in the future to switch it to something else?
closes #182 - This commit adds an interpolation routine that makes
resampled_as
and any other functions that use interpolations faster.Checklist
OutputVar
s (see issue on ClimaCoupler)Benchmarks from
@time
The image below is from the current postprocessing pipeline using the latest commit on main.
The image below is from the current postprocessing pipeline using this PR.