Skip to main content

xpublish-edr

PyPI Conda Version

Tests codecov pre-commit.ci status

Xpublish routers for the OGC EDR API.

Documentation and code

URLs for the docs and code.

Installation

For conda users you can

conda install --channel conda-forge xpublish_edr

or, if you are a pip users

pip install xpublish_edr

Example

import xarray as xr
import xpublish
from xpublish.routers import base_router, zarr_router
from xpublish_edr.cf_edr_router import cf_edr_router

ds = xr.open_dataset("dataset.nc")

rest = xpublish.Rest(
    datasets,
    routers=[
        (base_router, {"tags": ["info"]}),
        (cf_edr_router, {"tags": ["edr"], "prefix": "/edr"}),
        (zarr_router, {"tags": ["zarr"], "prefix": "/zarr"}),
    ],
)

Dataset metadata requirements

For /position, /area, and /cube, xpublish-edr needs to know the dataset's native CRS and which dimensions are X and Y. There are three supported ways to provide that information.

CF metadata

Use a grid_mapping attribute on each data variable and CF attrs on the X/Y coordinates:

import pyproj
import xarray as xr

crs = pyproj.CRS.from_epsg(3857)

ds["spatial_ref"] = xr.DataArray(0, attrs=crs.to_cf())
ds["temperature"].attrs["grid_mapping"] = "spatial_ref"
ds["x"].attrs.update(
    axis="X",
    standard_name="projection_x_coordinate",
)
ds["y"].attrs.update(
    axis="Y",
    standard_name="projection_y_coordinate",
)

For native longitude/latitude grids, use CF longitude/latitude coordinate attrs instead of projected X/Y attrs:

ds["lon"].attrs["standard_name"] = "longitude"
ds["lat"].attrs["standard_name"] = "latitude"

Datasets that already have a scalar spatial_ref or crs variable with CF CRS attrs are also accepted.

GeoZarr metadata

Use proj: attrs for the CRS and spatial:dimensions for the Y/X dimensions:

ds.attrs["proj:code"] = "EPSG:3857"
ds.attrs["spatial:dimensions"] = ["y", "x"]  # [Y, X] order

Use proj:wkt2 instead of proj:code if the CRS is stored as WKT.

Automatic raster metadata

For raster-style datasets with x/y dimensions but no explicit X/Y coordinate arrays, provide CRS and affine transform metadata. rasterix detects the raster dimensions and materializes regular 1D X/Y coordinates before selection.

CF/GDAL form:

ds["spatial_ref"] = xr.DataArray(
    0,
    attrs={
        **crs.to_cf(),
        "GeoTransform": "0 1000 0 3000 0 -1000",
    },
)
ds["temperature"].attrs["grid_mapping"] = "spatial_ref"

GeoZarr form:

ds.attrs["proj:code"] = "EPSG:3857"
ds.attrs["spatial:transform"] = [1000, 0, 0, 0, -1000, 3000]
ds.attrs["spatial:dimensions"] = ["y", "x"]

datetime and z queries also require indexed CF T and Z coordinates.

Spatial selection currently expects regular 1D X/Y coordinate grids, or an affine transform that can be materialized into regular 1D X/Y coordinates. 2D curvilinear spatial selection and proj:projjson CRS attrs are not currently supported.

OGC EDR Spec Compliance

This package attempts to follow the spec where reasonable, adding functionality where the value is demonstrable.

Note: POST is supported on /position and /area as a non-spec extension so that requests with large geometries (many points, complex polygons) can submit them in the request body instead of being limited by URL length. All selection parameters (datetime, z, parameter-name, crs, f, method) are still passed as query string parameters. See the per-query tables below for supported body content types.

collections and Resource Paths Support

xpublish-edr does not currently support the /collections/{collectionId}/query path template described in the spec. Instead the path resource appears as /{dataset_id}/edr/{query}. This is because of the path structure of xpublish. In the future, if xpublish supports DataTree it could provide a path to supporting the spec compliant collections resource path.

However, despite the collections resource not existing, this implementation supports collection metadata at the dataset level through the /{dataset_id}/edr/ resource.

Supported Queries

8.2.1 Position query

<<<<<<< New base: Secure actions with zizmor

Query Compliant Comments
coords Required for GET; for POST the points are read from the request body
z
datetime
parameter-name
crs Uses the dataset metadata described above. Default request CRS is EPSG:4326
f Supports cf_covjson, csv, geojson netcdf, parquet
method Optional: controls data selection. Use "nearest" for nearest neighbor selection, or "linear" for interpolated selection. Uses nearest if not specified
POST body Non-spec extension. Supported content types: text/csv (columns x/y, lon/lat, or longitude/latitude); application/geo+json (Point, MultiPoint, Feature, FeatureCollection, or GeometryCollection)
Query Compliant Comments
------------- ------------- -------------
coords Required for GET; for POST the points are read from the request body
z
datetime
parameter-name
crs Requires a CF compliant grid mapping on the target dataset. Default is EPSG:4326
f Supports cf_covjson, csv, geojson netcdf, parquet
method Optional: controls data selection. Use "nearest" for nearest neighbor selection, or "linear" for interpolated selection. Uses nearest if not specified
POST body Non-spec extension. Supported content types: text/csv (columns x/y, lon/lat, or longitude/latitude); application/geo+json (Point, MultiPoint, Feature, FeatureCollection, or GeometryCollection)
=======
Query Compliant Comments
---------------- --------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
coords Required for GET; for POST the points are read from the request body
z
datetime
parameter-name
crs Requires a CF compliant grid mapping on the target dataset. Default is EPSG:4326
f Supports cf_covjson, csv, geojson netcdf, parquet
method Optional: controls data selection. Use "nearest" for nearest neighbor selection, or "linear" for interpolated selection. Uses nearest if not specified
POST body Non-spec extension. Supported content types: text/csv (columns x/y, lon/lat, or longitude/latitude); application/geo+json (Point, MultiPoint, Feature, FeatureCollection, or GeometryCollection)

Current commit: Switch to ruff, mdformat, pyproj-fmt, and repo review

Any additional query parameters are assumed to be additional selections to make on the dimensions/coordinates. These queries will use the specified selections method.

8.2.3 Area query

<<<<<<< New base: Secure actions with zizmor

Query Compliant Comments
coords POLYGON and MULTIPOLYGON supported. Required for GET; for POST the polygon is read from the request body
z
datetime
parameter-name
crs Uses the dataset metadata described above. Default request CRS is EPSG:4326
f Supports cf_covjson, csv, geojson netcdf, parquet
method Optional: controls data selection. Use "nearest" for nearest neighbor selection, or "linear" for interpolated selection. Uses nearest if not specified
POST body Non-spec extension. Supported content types: application/geo+json (Polygon, MultiPolygon, Feature, FeatureCollection, or GeometryCollection); application/wkt / text/plain (raw WKT Polygon or MultiPolygon)
Query Compliant Comments
------------- ------------- -------------
coords POLYGON and MULTIPOLYGON supported. Required for GET; for POST the polygon is read from the request body
z
datetime
parameter-name
crs Requires a CF compliant grid mapping on the target dataset. Default is EPSG:4326
f Supports cf_covjson, csv, geojson netcdf, parquet
method Optional: controls data selection. Use "nearest" for nearest neighbor selection, or "linear" for interpolated selection. Uses nearest if not specified
POST body Non-spec extension. Supported content types: application/geo+json (Polygon, MultiPolygon, Feature, FeatureCollection, or GeometryCollection); application/wkt / text/plain (raw WKT Polygon or MultiPolygon)
=======
Query Compliant Comments
---------------- --------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
coords POLYGON and MULTIPOLYGON supported. Required for GET; for POST the polygon is read from the request body
z
datetime
parameter-name
crs Requires a CF compliant grid mapping on the target dataset. Default is EPSG:4326
f Supports cf_covjson, csv, geojson netcdf, parquet
method Optional: controls data selection. Use "nearest" for nearest neighbor selection, or "linear" for interpolated selection. Uses nearest if not specified
POST body Non-spec extension. Supported content types: application/geo+json (Polygon, MultiPolygon, Feature, FeatureCollection, or GeometryCollection); application/wkt / text/plain (raw WKT Polygon or MultiPolygon)

Current commit: Switch to ruff, mdformat, pyproj-fmt, and repo review

method is not applicable for the coordinates of area queries, only for selecting datetime, z, or additional dimensions.

For POLYGON coordinates, points that are located within OR on the polygons boundary are included in the response.

8.2.4 Cube query

<<<<<<< New base: Secure actions with zizmor

Query Compliant Comments
bbox Bounding box in minx,miny,maxx,maxy format
z
datetime
parameter-name
crs Uses the dataset metadata described above. Default request CRS is EPSG:4326
f Supports cf_covjson, csv, geojson netcdf, parquet, geotiff
method Optional: controls data selection. Use "nearest" for nearest neighbor selection, or "linear" for interpolated selection. Uses nearest if not specified
Query Compliant Comments
------------- ------------- -------------
bbox Bounding box in minx,miny,maxx,maxy format
z
datetime
parameter-name
crs Requires a CF compliant grid mapping on the target dataset. Default is EPSG:4326
f Supports cf_covjson, csv, geojson netcdf, parquet, geotiff
method Optional: controls data selection. Use "nearest" for nearest neighbor selection, or "linear" for interpolated selection. Uses nearest if not specified
=======
Query Compliant Comments
---------------- --------- --------------------------------------------------------------------------------------------------------------------------------------------------------
bbox Bounding box in minx,miny,maxx,maxy format
z
datetime
parameter-name
crs Requires a CF compliant grid mapping on the target dataset. Default is EPSG:4326
f Supports cf_covjson, csv, geojson netcdf, parquet, geotiff
method Optional: controls data selection. Use "nearest" for nearest neighbor selection, or "linear" for interpolated selection. Uses nearest if not specified

Current commit: Switch to ruff, mdformat, pyproj-fmt, and repo review

method is not applicable for the coordinates of cube queries, only for selecting datetime, z, or additional dimensions.

Cube queries are not flattened like area queries, so the response is returned as sliced by xarray. This is particularly useful for subsetting regular grids.

Get in touch

Report bugs, suggest features or view the source code on GitHub.

License and copyright

xpublish-edr is licensed under BSD 3-Clause "New" or "Revised" License (BSD-3-Clause).

Development occurs on GitHub at https://github.com/gulfofmaine/xpublish-edr/issues.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xpublish_edr-0.11.1.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xpublish_edr-0.11.1-py3-none-any.whl (37.0 kB view details)

Uploaded Python 3

File details

Details for the file xpublish_edr-0.11.1.tar.gz.

File metadata

  • Download URL: xpublish_edr-0.11.1.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for xpublish_edr-0.11.1.tar.gz
Algorithm Hash digest
SHA256 da017610c7af4aeff25704e31b51d8eb81a6643c3477ed0a5c8d10da018774d7
MD5 e79215015ecdbf27558f1eb537edf2f7
BLAKE2b-256 b3bb741ea515fb19014f90da184f32d4f7c58e8dacfba90bb10cd2586739cc8c

See more details on using hashes here.

Provenance

The following attestation bundles were made for xpublish_edr-0.11.1.tar.gz:

Publisher: publish-to-pypi.yml on xpublish-community/xpublish-edr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file xpublish_edr-0.11.1-py3-none-any.whl.

File metadata

  • Download URL: xpublish_edr-0.11.1-py3-none-any.whl
  • Upload date:
  • Size: 37.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for xpublish_edr-0.11.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4aeeaebf6a069d278c24882f707083094c7ddfeedb1a056ab9b9ba1a6e734960
MD5 2bfe92646a3cca8d6e10abfd8f3db0e1
BLAKE2b-256 1823cc1302b8c1d70c25f0c22ce9913563784507ae55255adba488002d29375e

See more details on using hashes here.

Provenance

The following attestation bundles were made for xpublish_edr-0.11.1-py3-none-any.whl:

Publisher: publish-to-pypi.yml on xpublish-community/xpublish-edr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.11.1 This release

2 files

0.11.0

2 files

0.10.2

2 files

0.10.1

2 files

0.10.0

2 files

0.9.1

2 files

0.9.0

2 files

0.8.1

2 files

0.8.0

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page