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

Adding ESMF.LocStream capabilities to xESMF #81

Merged
merged 13 commits into from
Mar 6, 2020
4 changes: 4 additions & 0 deletions xesmf/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,7 @@ def test_esmf_locstream():
lon2d, lat2d = np.meshgrid(lon, lat)
with pytest.raises(ValueError):
ls = esmf_locstream(lon2d, lat2d)
with pytest.raises(ValueError):
ls = esmf_locstream(lon, lat2d)
with pytest.raises(ValueError):
ls = esmf_locstream(lon2d, lat)
33 changes: 33 additions & 0 deletions xesmf/tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def test_regrid_dask():
# clean-up
regridder.clean_weight_file()

# -----------------------------------------
# testing locstream out
regridder = xe.Regridder(ds_in, ds_locs, 'bilinear', locstream_out=True)

Expand All @@ -259,6 +260,15 @@ def test_regrid_dask():
# clean-up
regridder.clean_weight_file()

# -----------------------------------------
# testing locstream in
regridder = xe.Regridder(ds_locs, ds_in, 'nearest_s2d', locstream_in=True)

outdata = regridder(ds_locs['lat'].data)

# clean-up
regridder.clean_weight_file()

JiaweiZhuang marked this conversation as resolved.
Show resolved Hide resolved
def test_regrid_dataarray_dask():
# xarray.DataArray containing chunked dask array

Expand Down Expand Up @@ -293,6 +303,15 @@ def test_regrid_dataarray_dask():
# clean-up
regridder.clean_weight_file()

# -----------------------------------------
# testing locstream in
regridder = xe.Regridder(ds_locs, ds_in, 'nearest_s2d', locstream_in=True)

outdata = regridder(ds_locs['lat'])

# clean-up
Copy link
Owner

Choose a reason for hiding this comment

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

I would separate out the tests for locstreams into different functions

regridder.clean_weight_file()

JiaweiZhuang marked this conversation as resolved.
Show resolved Hide resolved
def test_regrid_dataset():
# xarray.Dataset containing in-memory numpy array

Expand Down Expand Up @@ -323,12 +342,22 @@ def test_regrid_dataset():
# clean-up
regridder.clean_weight_file()

# -----------------------------------------
# testing locstream out
regridder = xe.Regridder(ds_in, ds_locs, 'bilinear', locstream_out=True)
ds_result = regridder(ds_in)
# clean-up
regridder.clean_weight_file()

# -----------------------------------------
# testing locstream in
regridder = xe.Regridder(ds_locs, ds_in, 'nearest_s2d', locstream_in=True)

outdata = regridder(ds_locs)

# clean-up
regridder.clean_weight_file()

JiaweiZhuang marked this conversation as resolved.
Show resolved Hide resolved
def test_ds_to_ESMFlocstream():

from xesmf.frontend import ds_to_ESMFlocstream
Expand All @@ -337,3 +366,7 @@ def test_ds_to_ESMFlocstream():
assert shape == (1,4,)
with pytest.raises(ValueError):
locstream, shape = ds_to_ESMFlocstream(ds_in)
ds_bogus = ds_in.copy()
ds_bogus['lon'] = ds_locs['lon']
with pytest.raises(ValueError):
locstream, shape = ds_to_ESMFlocstream(ds_bogus)