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

Fix failing xesmf remap test #119

Merged
merged 8 commits into from
Dec 20, 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
27 changes: 14 additions & 13 deletions monet/monet_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _monet_to_latlon(da):
dset = da.to_dataset()
dset["x"] = da.longitude[0, :].values
dset["y"] = da.latitude[:, 0].values
dset = dset.drop(["latitude", "longitude"])
dset = dset.drop_vars(["latitude", "longitude"])
dset = dset.set_coords(["x", "y"])
dset = dset.rename({"x": "lon", "y": "lat"})
if isinstance(da, xr.DataArray):
Expand Down Expand Up @@ -1303,7 +1303,7 @@ def remap_xesmf(self, dataarray, method="bilinear", **kwargs):

Parameters
----------
daaarray : ndarray or xarray DataArray
dataarray : ndarray or xarray DataArray
Description of parameter `dset`.
radius_of_influence : float or integer
radius of influcence for pyresample in meters.
Expand All @@ -1323,6 +1323,9 @@ def remap_xesmf(self, dataarray, method="bilinear", **kwargs):
out = resample.resample_xesmf(source, target, method=method, **kwargs)
return _rename_to_monet_latlon(out)

else:
print("xesmf unavailable. Try `import xesmf` and check the failure message.")

def combine_point(self, data, suffix=None, pyresample=True, **kwargs):
"""Short summary.

Expand Down Expand Up @@ -1452,20 +1455,15 @@ def cf_to_dt64(x):
return da

def remap_xesmf(self, data, **kwargs):
"""Resample the xesmf
"""Resample using xESMF.

Parameters
----------
data : type
Description of parameter `data`.
**kwargs : type
Description of parameter `**kwargs`.

Returns
-------
type
Description of returned object.

data : xarray.DataArray or xarray.Dataset
Data to be remapped.
**kwargs
Passed on to :func:`~monet.util.resample.resample_xesmf`
and then to ``xesmf.Regridder``.
"""
if has_xesmf:
try:
Expand All @@ -1481,6 +1479,9 @@ def remap_xesmf(self, data, **kwargs):
print("data must be an xarray.DataArray or xarray.Dataset")
# TODO: raise

else:
print("xesmf unavailable. Try `import xesmf` and check the failure message.")

def _remap_xesmf_dataset(self, dset, filename="monet_xesmf_regrid_file.nc", **kwargs):
skip_keys = ["lat", "lon", "time", "TFLAG"]
vars = pd.Series(list(dset.variables))
Expand Down
4 changes: 4 additions & 0 deletions tests/test_remap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import monet # noqa: F401


def test_import_xesmf():
import xesmf # noqa: F401


def test_remap_ds_ds():
# Barry noted a problem with this

Expand Down