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

Fixes xesmf flag #374

Merged
merged 2 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tests/test_regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,26 @@ def test_regrid(self):
assert "lon_bnds" in output
assert "time_bnds" in output

@pytest.mark.parametrize(
"name,value,attr_name",
[
("periodic", True, "_periodic"),
("extrap_method", "inverse_dist", "_extrap_method"),
("extrap_method", "nearest_s2d", "_extrap_method"),
("extrap_dist_exponent", 0.1, "_extrap_dist_exponent"),
("extrap_num_src_pnts", 10, "_extrap_num_src_pnts"),
("ignore_degenerate", False, "_ignore_degenerate"),
],
)
Comment on lines +441 to +451
Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't know this pytest decorator exists. This is neat for easily testing different function/method parameters!

def test_flags(self, name, value, attr_name):
ds = self.ds.copy()

options = {name: value}

regridder = xesmf.XESMFRegridder(ds, self.new_grid, "bilinear", **options)

assert getattr(regridder, attr_name) == value

def test_no_variable(self):
ds = self.ds.copy()

Expand Down
2 changes: 2 additions & 0 deletions xcdat/regridder/xesmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def __init__(
self._extrap_method = extrap_method
self._extrap_dist_exponent = extrap_dist_exponent
self._extrap_num_src_pnts = extrap_num_src_pnts
self._ignore_degenerate = ignore_degenerate
self._regridder: xe.XESMFRegridder = None
self._extra_options = options

Expand Down Expand Up @@ -178,6 +179,7 @@ def horizontal(self, data_var: str, ds: xr.Dataset) -> xr.Dataset:
extrap_method=self._extrap_method,
extrap_dist_exponent=self._extrap_dist_exponent,
extrap_num_src_pnts=self._extrap_num_src_pnts,
ignore_degenerate=self._ignore_degenerate,
**self._extra_options,
)

Expand Down