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 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 NdArrayFloat

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(2024, 8, 1, tzinfo=timezone.utc)]),
        ),
    ),
    ranges={
        "temperature": NdArrayFloat(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": [
                    "2024-08-01T00:00:00Z"
                ]
            }
        }
    },
    "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, MultiPolygon and MultiPolygonSeries domain types are not supported.
  • The Section domain type is not supported.
  • 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

covjson_pydantic-0.7.0.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

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

covjson_pydantic-0.7.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file covjson_pydantic-0.7.0.tar.gz.

File metadata

  • Download URL: covjson_pydantic-0.7.0.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for covjson_pydantic-0.7.0.tar.gz
Algorithm Hash digest
SHA256 9642672ce6c566a1a6dc6c1923c8dce13226cca43cc82b3c871421b521aaa5e2
MD5 5cc5e1026f319c8878587da550c695f1
BLAKE2b-256 77c55e7c474ce0a804ff759d4549aab227f6778264684a7040be60f089713a79

See more details on using hashes here.

File details

Details for the file covjson_pydantic-0.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for covjson_pydantic-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af47bff748174d08c426e208e6ae829bfa2f8c4b6a5343ac82c1209f83bfccd1
MD5 76612683d65358fb3f6f99b49c986e85
BLAKE2b-256 c3a08e0d62342e1905b85ac9cd89da7ca0b8010258cc265d7163aae0e0177baa

See more details on using hashes here.

Supported by

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