diff --git a/xpublish_wms/grids/regular.py b/xpublish_wms/grids/regular.py index 7e0304f..6e7fff9 100644 --- a/xpublish_wms/grids/regular.py +++ b/xpublish_wms/grids/regular.py @@ -50,9 +50,15 @@ def project( # build new y coordinate coords["y"] = ("y", da.cf["latitude"].values, da.cf["latitude"].attrs) # build new data array + shape = da.shape + if shape == (len(da.cf["latitude"]), len(da.cf["longitude"])): + dims = ("y", "x") + else: + dims = ("x", "y") + da = xr.DataArray( data=da, - dims=("y", "x"), + dims=dims, coords=coords, name=da.name, attrs=da.attrs, diff --git a/xpublish_wms/wms/get_capabilities.py b/xpublish_wms/wms/get_capabilities.py index 455533a..3118845 100644 --- a/xpublish_wms/wms/get_capabilities.py +++ b/xpublish_wms/wms/get_capabilities.py @@ -246,8 +246,8 @@ def get_capabilities(ds: xr.Dataset, request: Request, query_params: dict) -> Re additonal_coords = ds.gridded.additional_coords(da) for coord in additonal_coords: - values = da.cf.coords[coord].values - units = da.cf.coords[coord].attrs.get("units", "") + values = da[coord].values + units = da[coord].attrs.get("units", "") coord_element = ET.SubElement( layer, "Dimension", diff --git a/xpublish_wms/wms/get_map.py b/xpublish_wms/wms/get_map.py index ac954ef..732a8e8 100644 --- a/xpublish_wms/wms/get_map.py +++ b/xpublish_wms/wms/get_map.py @@ -233,11 +233,13 @@ def select_custom_dim(self, da: xr.DataArray) -> xr.DataArray: for dim, value in self.dim_selectors.items(): if dim in da.coords: dtype = da[dim].dtype - if np.issubdtype(dtype, np.integer): + if 'timedelta' in str(dtype): + value = pd.to_timedelta(value) + elif np.issubdtype(dtype, np.integer): value = int(value) elif np.issubdtype(dtype, np.floating): value = float(value) - da = da.sel({dim: value}) + da = da.sel({dim: value}, method="nearest") # Squeeze single value dimensions da = da.squeeze()