Skip to content
Draft
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
100 changes: 100 additions & 0 deletions xpublish_edr/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,106 @@

return router

@hookimpl
def ogc_router(self, deps: Dependencies):
"""Register OGC routers at the application level"""
router = APIRouter(tags=["OGC EDR"])

@router.get(
"/collections/{collection_id}/position", summary="OGC EDR Position endpoint",
)
def get_position(
collection_id: str,
request: Request,
query: Annotated[EDRPositionQuery, Query()],
):
"""Stub for OGC EDR position endpoint"""
dataset = deps.dataset(collection_id)
try:
ds = query.select(dataset, dict(request.query_params))
except ValueError as e:
logger.error(
f"Error selecting from query while selecting by position: {e}",
)
raise HTTPException(
status_code=404,
detail=f"Error selecting from query: {e.args[0]}",
)

logger.debug(f"Dataset filtered by query params {ds}")

try:
ds = select_by_position(ds, query.project_geometry(ds), query.method)
except GEOSException as e:
logger.error(
f"Error parsing coordinates to geometry while selecting by position: {e}",
)
raise HTTPException(
status_code=422,
detail="Could not parse coordinates to geometry, "
+ "check the format of the 'coords' query parameter",
)
except KeyError as e:
logger.error(f"Error selecting by position: {e}")
raise HTTPException(
status_code=404,
detail="Dataset does not have CF Convention compliant metadata",
)

logger.debug(
f"Dataset filtered by position ({query.geometry}): {ds}",
)

try:
ds = project_dataset(ds, query.crs)
except Exception as e:
logger.error(
f"Error projecting dataset while selecting by position: {e}",
)
raise HTTPException(
status_code=404,
detail="Error projecting dataset",
)

logger.debug(f"Dataset projected to {query.crs}: {ds}")

if query.format:
try:
format_fn = position_formats()[query.format]
except KeyError as e:
logger.error(
f"Error getting format function while selecting by position: {e}",
)
raise HTTPException(
404,
f"{query.format} is not a valid format for EDR position queries. "
"Get `./position/formats` for valid formats",
)

return format_fn(ds)

return to_cf_covjson(ds)

return router

@hookimpl
def ogc_collection_dataqueries(self, collection_id: str, ds: xr.Dataset):
"""Register data queries for OGC collection metadata"""
return {
"position": {
"link": {
"href": f"/collections/{collection_id}/position",
"variables": {},
"rel": "alternate",
"type": "application/geo+json",
"hreflang": "en",
"title": "OGC EDR Position Query Endpoint",
"length": 0,
"templated": True,
},
},
}

@hookimpl
def dataset_router(self, deps: Dependencies):
"""Register dataset level router for EDR endpoints"""
Expand All @@ -94,7 +194,7 @@
position_output_formats,
area_output_formats,
cube_output_formats,
).dict(

Check warning on line 197 in xpublish_edr/plugin.py

View workflow job for this annotation

GitHub Actions / run (3.11, ubuntu-latest)

The `dict` method is deprecated; use `model_dump` instead.

Check warning on line 197 in xpublish_edr/plugin.py

View workflow job for this annotation

GitHub Actions / run (3.11, ubuntu-latest)

The `dict` method is deprecated; use `model_dump` instead.

Check warning on line 197 in xpublish_edr/plugin.py

View workflow job for this annotation

GitHub Actions / run (3.11, ubuntu-latest)

The `dict` method is deprecated; use `model_dump` instead.

Check warning on line 197 in xpublish_edr/plugin.py

View workflow job for this annotation

GitHub Actions / run (3.13, ubuntu-latest)

The `dict` method is deprecated; use `model_dump` instead.

Check warning on line 197 in xpublish_edr/plugin.py

View workflow job for this annotation

GitHub Actions / run (3.13, ubuntu-latest)

The `dict` method is deprecated; use `model_dump` instead.

Check warning on line 197 in xpublish_edr/plugin.py

View workflow job for this annotation

GitHub Actions / run (3.13, ubuntu-latest)

The `dict` method is deprecated; use `model_dump` instead.

Check warning on line 197 in xpublish_edr/plugin.py

View workflow job for this annotation

GitHub Actions / run (3.12, ubuntu-latest)

The `dict` method is deprecated; use `model_dump` instead.

Check warning on line 197 in xpublish_edr/plugin.py

View workflow job for this annotation

GitHub Actions / run (3.12, ubuntu-latest)

The `dict` method is deprecated; use `model_dump` instead.

Check warning on line 197 in xpublish_edr/plugin.py

View workflow job for this annotation

GitHub Actions / run (3.12, ubuntu-latest)

The `dict` method is deprecated; use `model_dump` instead.
exclude_none=True,
)

Expand Down Expand Up @@ -173,7 +273,7 @@
return format_fn(ds)

return to_cf_covjson(ds)

Check warning on line 276 in xpublish_edr/plugin.py

View workflow job for this annotation

GitHub Actions / run (3.11, ubuntu-latest)

saving variable air with floating point data as an integer dtype without any _FillValue to use for NaNs

Check warning on line 276 in xpublish_edr/plugin.py

View workflow job for this annotation

GitHub Actions / run (3.11, ubuntu-latest)

saving variable air with floating point data as an integer dtype without any _FillValue to use for NaNs

Check warning on line 276 in xpublish_edr/plugin.py

View workflow job for this annotation

GitHub Actions / run (3.13, ubuntu-latest)

saving variable air with floating point data as an integer dtype without any _FillValue to use for NaNs

Check warning on line 276 in xpublish_edr/plugin.py

View workflow job for this annotation

GitHub Actions / run (3.13, ubuntu-latest)

saving variable air with floating point data as an integer dtype without any _FillValue to use for NaNs

Check warning on line 276 in xpublish_edr/plugin.py

View workflow job for this annotation

GitHub Actions / run (3.12, ubuntu-latest)

saving variable air with floating point data as an integer dtype without any _FillValue to use for NaNs

Check warning on line 276 in xpublish_edr/plugin.py

View workflow job for this annotation

GitHub Actions / run (3.12, ubuntu-latest)

saving variable air with floating point data as an integer dtype without any _FillValue to use for NaNs
@router.get("/area", summary="Area query")
def get_area(
request: Request,
Expand Down Expand Up @@ -241,7 +341,7 @@
return format_fn(ds)

return to_cf_covjson(ds)

Check warning on line 344 in xpublish_edr/plugin.py

View workflow job for this annotation

GitHub Actions / run (3.11, ubuntu-latest)

saving variable air with floating point data as an integer dtype without any _FillValue to use for NaNs

Check warning on line 344 in xpublish_edr/plugin.py

View workflow job for this annotation

GitHub Actions / run (3.13, ubuntu-latest)

saving variable air with floating point data as an integer dtype without any _FillValue to use for NaNs

Check warning on line 344 in xpublish_edr/plugin.py

View workflow job for this annotation

GitHub Actions / run (3.12, ubuntu-latest)

saving variable air with floating point data as an integer dtype without any _FillValue to use for NaNs
@router.get("/cube", summary="Cube query")
def get_cube(
request: Request,
Expand Down
Loading