Skip to content

Commit 2791737

Browse files
committed
lint
1 parent 5ae90d9 commit 2791737

3 files changed

Lines changed: 35 additions & 34 deletions

File tree

xpublish_wms/wms/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
OGC WMS router for datasets with CF convention metadata
33
"""
44

5+
import asyncio
56
import logging
67

78
import cachey
@@ -32,19 +33,19 @@ async def wms_handler(
3233
logger.info(f"WMS: {method}")
3334

3435
if method == "getcapabilities":
35-
return get_capabilities(dataset, request, query_params)
36+
return await asyncio.to_thread(get_capabilities, dataset, request, query_params)
3637
elif method == "getmap":
3738
getmap_service = GetMap(cache=cache)
3839
return await getmap_service.get_map(dataset, query_params)
3940
elif method == "getfeatureinfo" or method == "gettimeseries":
40-
return get_feature_info(dataset, query_params)
41+
return await asyncio.to_thread(get_feature_info, dataset, query_params)
4142
elif method == "getverticalprofile":
4243
query_params["elevation"] = "all"
43-
return get_feature_info(dataset, query_params)
44+
return await asyncio.to_thread(get_feature_info, dataset, query_params)
4445
elif method == "getmetadata":
45-
return get_metadata(dataset, cache, query_params)
46+
return await get_metadata(dataset, cache, query_params)
4647
elif method == "getlegendgraphic":
47-
return get_legend_info(dataset, query_params)
48+
return await asyncio.to_thread(get_legend_info, dataset, query_params)
4849
else:
4950
raise HTTPException(
5051
status_code=404,

xpublish_wms/wms/get_map.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ class GetMap:
3333
DEFAULT_STYLE: str = "raster/default"
3434
DEFAULT_PALETTE: str = "turbo"
3535

36-
BBOX_BUFFER = 30_000 # meters
37-
3836
cache: cachey.Cache
3937

4038
# Data selection
@@ -280,36 +278,38 @@ async def render(
280278
if minmax_only:
281279
logger.warning("Falling back to default minmax")
282280
return {"min": float(da.min()), "max": float(da.max())}
283-
284-
try:
285-
da = filter_data_within_bbox(da, self.bbox, self.BBOX_BUFFER)
286-
except Exception as e:
287-
logger.error(f"Error filtering data within bbox: {e}")
288-
logger.warning("Falling back to full layer")
289281

290-
print(f"Projection time: {time.time() - projection_start}")
282+
# x and y are only set for triangle grids, we dont subset the data for triangle grids
283+
# at this time.
284+
if x is None:
285+
try:
286+
# Grab a buffer around the bbox to ensure we have enough data to render
287+
# TODO: Base this on actual data resolution?
288+
if self.crs == "EPSG:4326":
289+
buffer = 0.5 # degrees
290+
elif self.crs == "EPSG:3857":
291+
buffer = 30000 # meters
292+
else:
293+
# Default to 0.5, this should never happen
294+
buffer = 0.5
295+
296+
# Filter the data to only include the data within the bbox + buffer so
297+
# we don't have to render a ton of empty space or pull down more chunks
298+
# than we need
299+
da = filter_data_within_bbox(da, self.bbox, buffer)
300+
except Exception as e:
301+
logger.error(f"Error filtering data within bbox: {e}")
302+
logger.warning("Falling back to full layer")
303+
304+
logger.debug(f"Projection time: {time.time() - projection_start}")
291305

292306
start_dask = time.time()
293307

294308
da = await asyncio.to_thread(da.compute)
295309

296-
# da = da.persist()
297-
# if x is not None and y is not None:
298-
# x = x.persist()
299-
# y = y.persist()
300-
# else:
301-
# da["x"] = da.x.persist()
302-
# da["y"] = da.y.persist()
303-
304-
print(da.x[1].values -da.x[0].values)
305-
print(da.y[1].values - da.y[0].values)
306-
307-
print(f"dask compute: {time.time() - start_dask}")
310+
logger.debug(f"dask compute: {time.time() - start_dask}")
308311

309312
if minmax_only:
310-
# da = da.persist()
311-
# data_sel = filter_data_within_bbox(da, self.bbox, self.BBOX_BUFFER)
312-
313313
try:
314314
return {
315315
"min": float(np.nanmin(da)),
@@ -366,7 +366,7 @@ async def render(
366366
how="linear",
367367
span=(vmin, vmax),
368368
)
369-
print(f"Shade time: {time.time() - start_shade}")
369+
logger.debug(f"Shade time: {time.time() - start_shade}")
370370

371371
im = shaded.to_pil()
372372
im.save(buffer, format="PNG")

xpublish_wms/wms/get_metadata.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .get_map import GetMap
1212

1313

14-
def get_metadata(ds: xr.Dataset, cache: cachey.Cache, params: dict) -> Response:
14+
async def get_metadata(ds: xr.Dataset, cache: cachey.Cache, params: dict) -> Response:
1515
"""
1616
Return the WMS metadata for the dataset
1717
@@ -39,7 +39,7 @@ def get_metadata(ds: xr.Dataset, cache: cachey.Cache, params: dict) -> Response:
3939
da = ds[layer_name]
4040
payload = get_timesteps(da, params)
4141
elif metadata_type == "minmax":
42-
payload = get_minmax(ds, cache, params)
42+
payload = await get_minmax(ds, cache, params)
4343
else:
4444
raise HTTPException(
4545
status_code=400,
@@ -79,14 +79,14 @@ def get_timesteps(da: xr.DataArray, params: dict) -> dict:
7979
}
8080

8181

82-
def get_minmax(ds: xr.Dataset, cache: cachey.Cache, params: dict) -> dict:
82+
async def get_minmax(ds: xr.Dataset, cache: cachey.Cache, params: dict) -> dict:
8383
"""
8484
Returns the min and max range of values for a given layer in a given area
8585
8686
If BBOX is not specified, the entire selected temporal and elevation range is used.
8787
"""
8888
getmap = GetMap(cache=cache)
89-
return getmap.get_minmax(ds, params)
89+
return await getmap.get_minmax(ds, params)
9090

9191

9292
def get_layer_details(ds: xr.Dataset, layer_name: str) -> dict:

0 commit comments

Comments
 (0)