-
Notifications
You must be signed in to change notification settings - Fork 8
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
Regridding to larger grid results in NaNs outside of data range #33
Conversation
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.
Thanks for making this PR!
I see that the linter check fails. You can fix the formatting by running ruff's formatter:
ruff format .
Could you add some tests to confirm the code works as intended? (and is not accidentally broken by others in the future)
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.
Thanks for making the changes and adding the test!
After updating the changelog, feel free to merge this PR. I think you should be able to now. It's probably best to use the "squash and merge" option.
uncovered_target_grid[coord] = (coords[coord] <= data[coord].max()) & ( | ||
coords[coord] >= data[coord].min() | ||
) |
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.
It does look a bit ugly now after formatting. You can add parenthesis to make it look better:
uncovered_target_grid[coord] = (coords[coord] <= data[coord].max()) & ( | |
coords[coord] >= data[coord].min() | |
) | |
uncovered_target_grid[coord] = ( | |
(coords[coord] <= data[coord].max()) & | |
(coords[coord] >= data[coord].min()) | |
) |
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.
I agree with this. Your suggestion is what I originally had, but ruff
switched it back after formatting. Do you think we should use our preferred format or do as ruff
suggests?
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.
Oh odd. Well it's best to keep it formatted, despite it being a bit ugly.
Alternatively you could use the np.bitwise_and
function:
uncovered_target_grid = np.bitwise_and(
coords[coord] <= data[coord].max(), coords[coord] >= data[coord].min()
)
But I think this is acceptable.
@@ -141,8 +143,9 @@ def conservative_regrid_dataarray( | |||
coord_attrs = [data[coord].attrs for coord in data_coords] | |||
|
|||
for coord in coords: | |||
mask = ((coords[coord] <= data[coord].max()) | |||
& (coords[coord] >= data[coord].min())) | |||
uncovered_target_grid = (coords[coord] <= data[coord].max()) & ( |
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.
Same here (formatting)
Fixes the issue where regridding to larger grid did not result in NaNs at locations where there was no starting data. Uses a mask after regridding to fill along each coordinate with the NaNs.