Skip to main content

The Pydantic models for CoverageJSON

Project description

CoverageJSON Pydantic

Test Coverage Package version Downloads License

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 install from source:

pip install git+https://github.com/KNMI/covjson-pydantic.git

Usage

import datetime
from covjson_pydantic.coverage import Coverage
from covjson_pydantic.domain import Domain
from covjson_pydantic.ndarray import NdArray

c = Coverage(
    domain=Domain(
        domainType="PointSeries",
        axes={
            "x": {"dataType": "float", "values": [1.23]},
            "y": {"values": [4.56]},
            "t": {"dataType": "datetime", "values": [datetime.datetime.now()]}
        },
    ),
    ranges={
        "temperature": NdArray(axisNames=["x", "y", "t"], shape=[1, 1, 1], values=[42.0])
    }
)
print(c.json(exclude_none=True))

Will print

{
    "type": "Coverage",
    "domain": {
        "type": "Domain",
        "domainType": "PointSeries",
        "axes": {
            "x": {
                "dataType": "float",
                "values": [
                    1.23
                ]
            },
            "y": {
                "values": [
                    4.56
                ]
            },
            "t": {
                "dataType": "datetime",
                "values": [
                    "2023-01-19T13:14:47.126631Z"
                ]
            }
        }
    },
    "ranges": {
        "temperature": {
            "type": "NdArray",
            "dataType": "float",
            "axisNames": [
                "x",
                "y",
                "t"
            ],
            "shape": [
                1,
                1,
                1
            ],
            "values": [
                42.0
            ]
        }
    }
}

Contributing

Make an editable install from within the repository root

pip install -e '.[test]'

Running tests

pytest tests/

Real world usage

This library is used to build an Environmental Data Retrieval (EDR) API, serving automatic weather data station data from the KNMI. See the KNMI Data Platform.

TODOs

Help is wanted in the following areas to fully implement the CovJSON spec:

  • The polygon based domain types are not supported.
  • The Trajectory and Section domain type are not supported.
  • The NdArray only supports float data.
  • Not all requirements in the spec relating different fields are implemented.

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)

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

covjson-pydantic-0.1.0.tar.gz (17.6 kB view hashes)

Uploaded Source

Built Distribution

covjson_pydantic-0.1.0-py3-none-any.whl (13.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page