From c265cd14f3fe6b3d14cfbffe63745f19f994ed79 Mon Sep 17 00:00:00 2001 From: Matthew Iannucci Date: Tue, 31 Oct 2023 09:25:33 -0400 Subject: [PATCH] Fix GFI when vertical coords are specified (#36) * Fix GFI when vertical coords are specified * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update target versions since dependencies havent all bee updated * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Udpate python version for packaging --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .github/workflows/publish-to-pypi.yml | 2 +- .gitignore | 1 + pyproject.toml | 3 ++- xpublish_wms/grid.py | 24 +++++++++++++++++++++--- xpublish_wms/wms/get_feature_info.py | 9 +++++++-- 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index ccb0d42..5f188ae 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -22,7 +22,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.x" + python-version: "3.11.x" # - name: Get tags # run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* diff --git a/.gitignore b/.gitignore index 967c7ee..94d579e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ __pycache__/ build/ dist/ xpublish_wms/_version.py +env/ diff --git a/pyproject.toml b/pyproject.toml index e22ee49..70ba475 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ name = "xpublish_wms" authors = [{ name = "Matthew Iannucci", email = "matt.iannucci@rpsgroup.com" }] description = "WMS plugin for xpublish" readme = "README.md" -requires-python = ">=3.9" +requires-python = ">=3.9,<3.12" keywords = ["xarray", "xpublish", "wms"] license = { file = "LICENSE.txt" } @@ -21,6 +21,7 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Scientific/Engineering", ] diff --git a/xpublish_wms/grid.py b/xpublish_wms/grid.py index b0001c8..2a5fcc8 100644 --- a/xpublish_wms/grid.py +++ b/xpublish_wms/grid.py @@ -100,7 +100,13 @@ def tessellate(self, da: xr.DataArray) -> np.ndarray: """Tessellate the given data array into triangles. Only required for RenderingMode.Triangle""" pass - def sel_lat_lng(self, subset: xr.Dataset, lng, lat, parameters) -> Tuple[xr.Dataset, list, list]: + def sel_lat_lng( + self, + subset: xr.Dataset, + lng, + lat, + parameters, + ) -> Tuple[xr.Dataset, list, list]: """Select the given dataset by the given lon/lat and optional elevation""" subset = subset.cf.interp(longitude=lng, latitude=lat) x_axis = [strip_float(subset.cf["longitude"])] @@ -183,7 +189,13 @@ def project(self, da: xr.DataArray, crs: str) -> xr.DataArray: da = da.unify_chunks() return da - def sel_lat_lng(self, subset: xr.Dataset, lng, lat, parameters) -> Tuple[xr.Dataset, list, list]: + def sel_lat_lng( + self, + subset: xr.Dataset, + lng, + lat, + parameters, + ) -> Tuple[xr.Dataset, list, list]: topology = self.ds.cf["grid_topology"] merged_ds = None @@ -515,7 +527,13 @@ def tessellate(self, da: xr.DataArray) -> np.ndarray: else: return self._grid.tessellate(da) - def sel_lat_lng(self, subset: xr.Dataset, lng, lat, parameters) -> Tuple[xr.Dataset, list, list]: + def sel_lat_lng( + self, + subset: xr.Dataset, + lng, + lat, + parameters, + ) -> Tuple[xr.Dataset, list, list]: if self._grid is None: return None else: diff --git a/xpublish_wms/wms/get_feature_info.py b/xpublish_wms/wms/get_feature_info.py index ce1f94c..598902a 100644 --- a/xpublish_wms/wms/get_feature_info.py +++ b/xpublish_wms/wms/get_feature_info.py @@ -161,7 +161,7 @@ def get_feature_info(ds: xr.Dataset, query: dict) -> Response: # Dont select an elevation, just keep all elevation coords elevation = selected_ds.cf["vertical"].values elif len(elevation) == 1: - selected_ds = selected_ds.cf.interp(vertical=elevation) + selected_ds = selected_ds.cf.sel(vertical=elevation, method="nearest") elif len(elevation) > 1: selected_ds = selected_ds.cf.sel(vertical=slice(elevation[0], elevation[1])) else: @@ -169,7 +169,12 @@ def get_feature_info(ds: xr.Dataset, query: dict) -> Response: selected_ds = selected_ds.cf.sel(vertical=0, method="nearest") try: - selected_ds, x_axis, y_axis = ds.grid.sel_lat_lng(subset=selected_ds, lng=x_coord[x], lat=y_coord[y], parameters=parameters) + selected_ds, x_axis, y_axis = ds.grid.sel_lat_lng( + subset=selected_ds, + lng=x_coord[x], + lat=y_coord[y], + parameters=parameters, + ) except ValueError: raise HTTPException(500, f"Unsupported grid type: {ds.grid.name}")