-
Notifications
You must be signed in to change notification settings - Fork 301
Cache linear interpolator #1997
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
Closed
corinnebosley
wants to merge
1
commit into
SciTools:master
from
corinnebosley:trajectory_optimisation_1
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -237,12 +237,17 @@ def interpolate(cube, sample_points, method=None): | |
| # Use a cache with _nearest_neighbour_indices_ndcoords() | ||
| cache = {} | ||
|
|
||
| # Cache the linear interpolator | ||
| scheme = iris.analysis.Linear() | ||
| coords, points = zip(*sample_points) | ||
| interpolator = scheme.interpolator(cube, coords) | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The corresponding import statement needs to be removed. |
||
| for i in range(trajectory_size): | ||
| point = [(coord, values[i]) for coord, values in sample_points] | ||
|
|
||
| if method in ["linear", None]: | ||
| column = linear_regrid(cube, point) | ||
| new_cube.data[..., i] = column.data | ||
| column = interpolator([val[i] for _, val in sample_points]) | ||
| new_cube.data[..., i] = column | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still needs the new_cube.data[..., i] = column.data |
||
| elif method == "nearest": | ||
| column_index = _nearest_neighbour_indices_ndcoords(cube, point, cache=cache) | ||
| column = cube[column_index] | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
These lines need to be protected by
if method in ('linear', None)- partly because it's wasted effort otherwise, but mostly because they will fail when trying to do nearest-neighbour interpolation over multi-dimensional coordinates.NB. The docstring for
iris.analysis.trajectory.interpolateis a little ambiguous about the default value ofmethod, but it turns out that the default is not just simply "linear", but switches to "nearest" when using multi-dimensional coordinates. 👎 I definitely don't propose to change that behaviour in this PR, but it would be nice to clarify the docstring (again, possibly in a separate PR - small is beautiful).