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

Address a few warnings #155

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
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
8 changes: 4 additions & 4 deletions monet/monet_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _dataset_to_monet(dset, lat_name="latitude", lon_name="longitude", latlon2d=
print("dset must be an xarray.DataArray or xarray.Dataset")

if "south_north" in dset.dims: # WRF WPS file
dset = dset.rename(dict(south_north="y", west_east="x"))
dset = dset.swap_dims(dict(south_north="y", west_east="x"))
try:
if isinstance(dset, xr.Dataset):
if "XLAT_M" in dset.data_vars:
Expand Down Expand Up @@ -194,7 +194,7 @@ def _coards_to_netcdf(dset, lat_name="lat", lon_name="lon"):
lons, lats = meshgrid(lon, lat)
x = arange(len(lon))
y = arange(len(lat))
dset = dset.rename({lon_name: "x", lat_name: "y"})
dset = dset.swap_dims({lon_name: "x", lat_name: "y"})
dset.coords["longitude"] = (("y", "x"), lons)
dset.coords["latitude"] = (("y", "x"), lats)
dset["x"] = x
Expand Down Expand Up @@ -223,7 +223,7 @@ def _dataarray_coards_to_netcdf(dset, lat_name="lat", lon_name="lon"):
lons, lats = meshgrid(lon, lat)
x = arange(len(lon))
y = arange(len(lat))
dset = dset.rename({lon_name: "x", lat_name: "y"})
dset = dset.swap_dims({lon_name: "x", lat_name: "y"})
dset.coords["latitude"] = (("y", "x"), lats)
dset.coords["longitude"] = (("y", "x"), lons)
dset["x"] = x
Expand Down Expand Up @@ -389,7 +389,7 @@ def _df_to_da(self, d=None): # TODO: should be `to_ds` or `to_xarray`
d = self._obj
if d.index.name is not None:
index_name = d.index.name
ds = d.to_xarray().rename({index_name: "x"}).expand_dims("y")
ds = d.to_xarray().swap_dims({index_name: "x"}).expand_dims("y")
if "time" in ds.data_vars.keys():
ds["time"] = ds.time.squeeze() # it is only 1D
if "latitude" in ds.data_vars.keys():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_remap.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_combine_da_da():
new = combine_da_to_da(model, obs, merge=False, interp_time=False)

# Check
assert new.dims == {"z": 5, "y": n, "x": n}
assert new.sizes == {"z": 5, "y": n, "x": n}
assert float(new.longitude.min()) == pytest.approx(0.1)
assert float(new.longitude.max()) == pytest.approx(0.9)
assert float(new.latitude.min()) == pytest.approx(0.1)
Expand All @@ -105,6 +105,6 @@ def test_combine_da_da():

# Use orthogonal selection to get track
a = new.data.values[:, new.y, new.x]
assert a.shape == (model.dims["z"], n), "model levels but obs grid points"
assert a.shape == (model.sizes["z"], n), "model levels but obs grid points"
assert (np.diff(a.mean(axis=0)) >= 0).all(), "obs profile goes S"
assert np.isclose(np.diff(a.mean(axis=1)), 1, atol=1e-15, rtol=0).all(), "obs profile goes U"
Loading