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

More dim fixes #51

Merged
merged 3 commits into from
Dec 15, 2023
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
2 changes: 1 addition & 1 deletion xpublish_wms/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def sel_lat_lng(
if "time" in mask.cf.coords:
mask = mask.cf.isel(time=0).squeeze(drop=True).cf.drop_vars("time")
else:
mask = mask.cf.squeeze(drop=True).cf
mask = mask.cf.squeeze(drop=True)

subset[parameter] = subset[parameter].where(mask == 1)

Expand Down
9 changes: 7 additions & 2 deletions xpublish_wms/wms/get_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,20 @@ def select_time(self, da: xr.DataArray) -> xr.DataArray:
:param da:
:return:
"""
time_dim = da.cf.coords.get(self.TIME_CF_NAME, None)
if not time_dim or time_dim not in da.dims:
time_dim = da.cf.coordinates.get(self.TIME_CF_NAME, None)
if time_dim is not None and len(time_dim):
time_dim = time_dim[0]

if not time_dim or time_dim not in list(da.dims):
return da

if self.time is not None:
da = da.cf.sel({self.TIME_CF_NAME: self.time}, method="nearest")
elif self.TIME_CF_NAME in da.cf.coords:
da = da.cf.isel({self.TIME_CF_NAME: -1})

return da

def select_elevation(self, ds: xr.Dataset, da: xr.DataArray) -> xr.DataArray:
"""
Ensure elevation selection
Expand Down
Loading