-
Notifications
You must be signed in to change notification settings - Fork 12
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 API extending xgcm vertical regridding #388
Conversation
Tasks left:
The current plan for handling
If auto derive is selected the vertical coordinate attributes will be checked for |
Codecov ReportPatch coverage:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## main #388 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 14 15 +1
Lines 1428 1517 +89
=========================================
+ Hits 1428 1517 +89
☔ View full report in Codecov by Sentry. |
Hey @jasonb5, I threw the notes from the past few meetings here since they are action items. Feel free to check-box or update as needed. Action Items from Meetings (11/2022 - 1/2023)
|
I see what's going on here, when horizontal regridding was first implemented the method would call Should we even be adding bounds outside of what was generated during the regridding process? If we do want the methods to fill out the bounds should it be for all dimensions or only the dimensions involved in the process e.g. horizontal generates only "X", "Y"?
I haven't been able to reproduce this yet, I'm not sure what is using the yaksa package. |
The original dataset includes So – we shouldn't generate the bounds, but I do think we should carry over the original bounds (that are unaffected by horizontal regridding). I'm not sure how much we need to worry about yaksa, I get the warning on main branch, too (even after re-creating the dev environment). |
@pochedls This logic sounds good, I'll update accordingly. |
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.
Hi Jason, here is my final review. The suggestions are mostly renaming things.
mock_regridder = mock.MagicMock() | ||
mock_regridder.return_value.vertical.return_value = "output data" | ||
|
||
mock_data = mock.MagicMock() | ||
|
||
with mock.patch.dict(accessor.VERTICAL_REGRID_TOOLS, {"xgcm": mock_regridder}): | ||
output = self.ac.vertical("ts", mock_data, tool="xgcm", target_data=None) | ||
|
||
assert output == "output data" |
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.
The use of MagicMock is neat here. For those interested (probably just me), the xgcm vertical regridder object is being mocked (mock_regridder
) and set as the xgcm
dictionary value in accessor.VERTICAL_REGRID_TOOLS
. The return value of mock_regridder
is set to "output_data"
, which is being tested in the assertion on line 1088. This test is to check if the correct vertical regridding tool is being referenced.
The actual result of the regridder object is not being tested (hence "output_data"
) because it is already tested through class TestXGCMRegridder
.
) | ||
|
||
regridder = regrid_tool(self._ds, output_grid, **options) | ||
output_ds = regridder.horizontal(data_var, self._ds) | ||
|
||
return output_ds | ||
|
||
def vertical( |
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.
Based on #501, are we also considering calling this vertical_xgcm
and not having a general wrapper with tool="xgcm"
?
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.
That's correct, I'll address it in the next PR.
def create_grid(**kwargs: CoordOptionalBnds) -> xr.Dataset: | ||
"""Creates a grid from coordinate mapping. | ||
|
||
Parameters | ||
---------- | ||
lat : Union[np.ndarray, xr.DataArray] | ||
Array of latitude values. | ||
lon : Union[np.ndarray, xr.DataArray] | ||
Array of longitude values. | ||
lat_bnds : Optional[Union[np.ndarray, xr.DataArray]] | ||
Array of bounds for latitude values. | ||
lon_bnds : Optional[Union[np.ndarray, xr.DataArray]] | ||
Array of bounds for longitude values. | ||
**kwargs : CoordOptionalBnds | ||
Mapping of coordinate name and data with optional bounds. See | ||
:py:data:`xcdat.axis.VAR_NAME_MAP` for valid coordinate names. |
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.
This update (#496) will go in a new PR after this PR is merged right?
xcdat/regridder/base.py
Outdated
Coord = Union[np.ndarray, xr.DataArray] | ||
|
||
CoordOptionalBnds = Union[Coord, Tuple[Coord, Coord]] | ||
|
||
|
||
def preserve_bounds( |
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.
Do you think this function will be used publicly, or should it be private (_preserve_bounds()
)?
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'm guessing it won't be used publicly, I'll rename it .
xcdat/regridder/base.py
Outdated
output_ds: xr.Dataset, | ||
output_grid: xr.Dataset, | ||
input_ds: xr.Dataset, | ||
ignore_dims: List[CFAxisKey], |
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.
output_ds: xr.Dataset, | |
output_grid: xr.Dataset, | |
input_ds: xr.Dataset, | |
ignore_dims: List[CFAxisKey], | |
input_ds: xr.Dataset, | |
output_grid: xr.Dataset, | |
output_ds: xr.Dataset, | |
ignore_dims: List[CFAxisKey], |
It's more intuitive to me to have the input params input_ds
and output_grid
first since they contain the bounds info, which are copied/preserved to the output_ds
.
I'm thinking input -> output basically. Not a big deal though, especially if this should be a private function (my previous comment).
Co-authored-by: Tom Vo <[email protected]>
Co-authored-by: Tom Vo <[email protected]>
🎉🎊 |
Description
Adds vertical regridding via xgcm.
Checklist
If applicable: