Skip to content
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

Merged
merged 5 commits into from
Feb 29, 2024

Conversation

kjdoore
Copy link
Collaborator

@kjdoore kjdoore commented Feb 23, 2024

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.

Copy link
Contributor

@BSchilperoort BSchilperoort left a 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)

src/xarray_regrid/methods/conservative.py Outdated Show resolved Hide resolved
BSchilperoort
BSchilperoort previously approved these changes Feb 28, 2024
Copy link
Contributor

@BSchilperoort BSchilperoort left a 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.

Comment on lines +96 to +98
uncovered_target_grid[coord] = (coords[coord] <= data[coord].max()) & (
coords[coord] >= data[coord].min()
)
Copy link
Contributor

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:

Suggested change
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())
)

Copy link
Collaborator Author

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?

Copy link
Contributor

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()) & (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here (formatting)

@BSchilperoort BSchilperoort merged commit 4f9a7eb into xarray-contrib:main Feb 29, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regridding to larger grid not resulting in NaNs where no starting data
2 participants