-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KDP-1528: Initial README and example.py
- Loading branch information
1 parent
0b35d6e
commit 92db409
Showing
3 changed files
with
201 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,163 @@ | ||
# edr_pydantic | ||
# OGC Enviromental Data Retrieval (EDR) API Pydantic | ||
|
||
This repository contains the edr-pydantic Python package. It provides [Pydantic](https://pydantic-docs.helpmanual.io/) models | ||
for [OGC Enviromental Data Retrieval (EDR) API](https://ogcapi.ogc.org/edr/). | ||
This can, for example, be used to develop an EDR API using FastAPI. | ||
|
||
## Install | ||
```shell | ||
pip install edr-pydantic | ||
``` | ||
|
||
Or to install from source: | ||
|
||
```shell | ||
pip install git+https://github.com/KNMI/edr-pydantic.git | ||
``` | ||
|
||
## Usage | ||
|
||
```python | ||
from edr_pydantic.collections import Collection | ||
from edr_pydantic.data_queries import EDRQuery, EDRQueryLink | ||
from edr_pydantic.extent import Extent, Spatial | ||
from edr_pydantic.link import Link | ||
from edr_pydantic.observed_property import ObservedProperty | ||
from edr_pydantic.parameter import Parameter | ||
from edr_pydantic.unit import Unit | ||
from edr_pydantic.variables import Variables | ||
|
||
c = Collection( | ||
id="hrly_obs", | ||
title="Hourly Site Specific observations", | ||
description="Observation data for UK observing sites", | ||
extent=Extent( | ||
spatial=Spatial( | ||
bbox=[ | ||
[-15.0, 48.0, 5.0, 62.0] | ||
], | ||
crs="WGS84" | ||
) | ||
), | ||
links=[ | ||
Link( | ||
href="https://example.org/uk-hourly-site-specific-observations", | ||
rel="service-doc" | ||
) | ||
], | ||
data_queries={ | ||
'position': EDRQuery( | ||
link=EDRQueryLink( | ||
href="https://example.org/edr/collections/hrly_obs/position?coords={coords}", | ||
rel="data", | ||
variables=Variables( | ||
query_type="position", | ||
output_formats=[ | ||
"CoverageJSON" | ||
] | ||
) | ||
) | ||
) | ||
}, | ||
parameter_names={ | ||
"Wind Direction": Parameter( | ||
unit=Unit( | ||
label="degree true" | ||
), | ||
observedProperty=ObservedProperty( | ||
id="https://codes.wmo.int/common/quantity-kind/_windDirection", | ||
label="Wind Direction" | ||
) | ||
) | ||
} | ||
) | ||
|
||
print(c.model_dump_json(indent=2, exclude_none=True)) | ||
``` | ||
|
||
Will print | ||
```json | ||
{ | ||
"id": "hrly_obs", | ||
"title": "Hourly Site Specific observations", | ||
"description": "Observation data for UK observing sites", | ||
"links": [ | ||
{ | ||
"href": "https://example.org/uk-hourly-site-specific-observations", | ||
"rel": "service-doc" | ||
} | ||
], | ||
"extent": { | ||
"spatial": { | ||
"bbox": [ | ||
[ | ||
-15.0, | ||
48.0, | ||
5.0, | ||
62.0 | ||
] | ||
], | ||
"crs": "WGS84" | ||
} | ||
}, | ||
"data_queries": { | ||
"position": { | ||
"link": { | ||
"href": "https://example.org/edr/collections/hrly_obs/position?coords={coords}", | ||
"rel": "data", | ||
"variables": { | ||
"query_type": "position", | ||
"output_formats": [ | ||
"CoverageJSON" | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"parameter_names": { | ||
"Wind Direction": { | ||
"type": "Parameter", | ||
"unit": { | ||
"label": "degree true" | ||
}, | ||
"observedProperty": { | ||
"id": "https://codes.wmo.int/common/quantity-kind/_windDirection", | ||
"label": "Wind Direction" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Contributing | ||
|
||
Make an editable install from within the repository root | ||
|
||
```shell | ||
pip install -e '.[test]' | ||
``` | ||
|
||
### Running tests | ||
|
||
```shell | ||
pytest tests/ | ||
``` | ||
|
||
## Real world usage | ||
|
||
This library is used to build an Environmental Data Retrieval (EDR) API, serving observation data from surface weather data station data from the KNMI. See the [KNMI Data Platform](https://developer.dataplatform.knmi.nl/edr-api). | ||
|
||
## TODOs | ||
Help is wanted in the following areas to fully implement the EDR spec: | ||
|
||
## License | ||
|
||
Apache License, Version 2.0 | ||
|
||
## Authors | ||
|
||
Members of the KNMI Data Platform team. Reachable at opendata@knmi.nl. | ||
|
||
## Copyright | ||
|
||
Koninklijk Nederlands Meteorologisch Instituut (KNMI) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from edr_pydantic.collections import Collection | ||
from edr_pydantic.data_queries import EDRQuery | ||
from edr_pydantic.data_queries import EDRQueryLink | ||
from edr_pydantic.extent import Extent | ||
from edr_pydantic.extent import Spatial | ||
from edr_pydantic.link import Link | ||
from edr_pydantic.observed_property import ObservedProperty | ||
from edr_pydantic.parameter import Parameter | ||
from edr_pydantic.unit import Unit | ||
from edr_pydantic.variables import Variables | ||
|
||
c = Collection( | ||
id="hrly_obs", | ||
title="Hourly Site Specific observations", | ||
description="Observation data for UK observing sites", | ||
extent=Extent(spatial=Spatial(bbox=[[-15.0, 48.0, 5.0, 62.0]], crs="WGS84")), | ||
links=[Link(href="https://example.org/uk-hourly-site-specific-observations", rel="service-doc")], | ||
data_queries={ | ||
"position": EDRQuery( | ||
link=EDRQueryLink( | ||
href="https://example.org/edr/collections/hrly_obs/position?coords={coords}", | ||
rel="data", | ||
variables=Variables(query_type="position", output_formats=["CoverageJSON"]), | ||
) | ||
) | ||
}, | ||
parameter_names={ | ||
"Wind Direction": Parameter( | ||
unit=Unit(label="degree true"), | ||
observedProperty=ObservedProperty( | ||
id="https://codes.wmo.int/common/quantity-kind/_windDirection", label="Wind Direction" | ||
), | ||
) | ||
}, | ||
) | ||
|
||
print(c.model_dump_json(indent=2, exclude_none=True)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters