Skip to content

Commit

Permalink
Fix GFI when vertical coords are specified (#36)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
mpiannucci and pre-commit-ci[bot] authored Oct 31, 2023
1 parent e4cfcd1 commit c265cd1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ __pycache__/
build/
dist/
xpublish_wms/_version.py
env/
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "xpublish_wms"
authors = [{ name = "Matthew Iannucci", email = "[email protected]" }]
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" }

Expand All @@ -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",
]

Expand Down
24 changes: 21 additions & 3 deletions xpublish_wms/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions xpublish_wms/wms/get_feature_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,20 @@ 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:
# Select closest to the surface by default
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}")

Expand Down

0 comments on commit c265cd1

Please sign in to comment.