The Pydantic models for CoverageJSON
Project description
CoverageJSON Pydantic
This repository contains the coveragejson-pydantic Python package. It provides Pydantic models for CoverageJSON. This can, for example, be used to develop an API using FastAPI serving or receiving CoverageJSON.
Install
pip install covjson-pydantic
Or you can install directly from source:
pip install git+https://github.com/KNMI/covjson-pydantic.git
Usage
from datetime import datetime, timezone
from pydantic import AwareDatetime
from covjson_pydantic.coverage import Coverage
from covjson_pydantic.domain import Domain, Axes, ValuesAxis, DomainType
from covjson_pydantic.ndarray import NdArray
c = Coverage(
domain=Domain(
domainType=DomainType.point_series,
axes=Axes(
x=ValuesAxis[float](values=[1.23]),
y=ValuesAxis[float](values=[4.56]),
t=ValuesAxis[AwareDatetime](values=[datetime.now(tz=timezone.utc)])
)
),
ranges={
"temperature": NdArray(axisNames=["x", "y", "t"], shape=[1, 1, 1], values=[42.0])
}
)
print(c.model_dump_json(exclude_none=True, indent=4))
Will print
{
"type": "Coverage",
"domain": {
"type": "Domain",
"domainType": "PointSeries",
"axes": {
"x": {
"values": [
1.23
]
},
"y": {
"values": [
4.56
]
},
"t": {
"values": [
"2023-09-14T11:54:02.151493Z"
]
}
}
},
"ranges": {
"temperature": {
"type": "NdArray",
"dataType": "float",
"axisNames": [
"x",
"y",
"t"
],
"shape": [
1,
1,
1
],
"values": [
42.0
]
}
}
}
Contributing
Make an editable installation from within the repository root
pip install -e '.[test]'
Running tests
pytest tests/
Linting and typing
Linting and typing (mypy) is done using pre-commit hooks.
pip install pre-commit
pre-commit install
pre-commit run
Related packages
- edr-pydantic - Pydantic data models for the Environmental Data Retrieval (EDR) API
- geojson-pydantic - Pydantic data models for the GeoJSON spec
Real world usage
This library is used to build an OGC Environmental Data Retrieval (EDR) API, serving automatic weather data station data from The Royal Netherlands Meteorological Institute (KNMI). See the KNMI Data Platform EDR API.
TODOs
Help is wanted in the following areas to fully implement the CovJSON spec:
- The polygon based domain types are not supported.
- The
Trajectory
andSection
domain type are not supported. - The
NdArray
only supportsfloat
data. - Not all requirements in the spec relating different fields are implemented.
License
Apache License, Version 2.0
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for covjson_pydantic-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66b7c6c4dee765ab7cf4cbc5f5179419ebcf02fa12555a5b6283a39e92be468f |
|
MD5 | 4f1f0fccb57d00146d104588797114bc |
|
BLAKE2b-256 | f37e8d95e2d5ae6ba8c380cb42699b817cffc7f7b4615aca30e2a134f8079b04 |