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

Fix GFI when vertical coords are specified #36

Merged
merged 6 commits into from
Oct 31, 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 .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
Loading