Skip to content

Commit

Permalink
Merge pull request #11 from KNMI/measurement-type
Browse files Browse the repository at this point in the history
Add optional measurementType field in Parameter
  • Loading branch information
lukas-phaf authored Aug 22, 2024
2 parents 24685e8 + 29a9e57 commit 2389a44
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
"Topic :: Scientific/Engineering :: GIS",
"Typing :: Typed",
]
version = "0.3.0"
version = "0.4.0"
dependencies = ["pydantic>=2.3,<3"]

[project.optional-dependencies]
Expand Down
9 changes: 9 additions & 0 deletions src/edr_pydantic/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@
from .unit import Unit


class MeasurementType(EdrBaseModel):
method: str
# TODO: Add validation of ISO 8601 duration (including leading minus sign)
# TODO: Confusion in spec on the field name, duration versus period.
# See https://github.com/opengeospatial/ogcapi-environmental-data-retrieval/issues/560
period: str


class Parameter(EdrBaseModel, extra="allow"):
type: Literal["Parameter"] = "Parameter"
id: Optional[str] = None
label: Optional[str] = None
description: Optional[str] = None
unit: Optional[Unit] = None
observedProperty: ObservedProperty # noqa: N815
measurementType: Optional[MeasurementType] = None # noqa: N815

@model_validator(mode="after")
def must_not_have_unit_if_observed_property_has_categories(self):
Expand Down
59 changes: 59 additions & 0 deletions tests/test_data/parameter-names.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"Temperature_altitude_above_msl": {
"type": "Parameter",
"description": "Temperature for Specific altitude above MSL",
"unit": {
"label": "K",
"symbol": {
"value": "K",
"type": "http://qudt.org/vocab/unit/K"
}
},
"observedProperty": {
"id": "http://codes.wmo.int/grib2/codeflag/4.2/_0-0-0",
"label": "Temperature_altitude_above_msl"
},
"measurementType": {
"method": "instantaneous",
"period": "PT0S"
}
},
"u-component_of_wind_altitude_above_msl": {
"type": "Parameter",
"description": "u-component of wind for Specific altitude above MSL",
"unit": {
"label": "m/s",
"symbol": {
"value": "m%20s",
"type": "http://qudt.org/vocab/unit/M-PER-SEC.html"
}
},
"observedProperty": {
"id": "http://codes.wmo.int/grib2/codeflag/4.2/_0-2-2",
"label": "u-component_of_wind_altitude_above_msl"
},
"measurementType": {
"method": "instantaneous",
"period": "PT0S"
}
},
"v-component_of_wind_altitude_above_msl": {
"type": "Parameter",
"description": "v-component of wind for Specific altitude above MSL",
"unit": {
"label": "m/s",
"symbol": {
"value": "m%20s",
"type": "http://qudt.org/vocab/unit/M-PER-SEC.html"
}
},
"observedProperty": {
"id": "http://codes.wmo.int/grib2/codeflag/4.2/_0-2-3",
"label": "v-component_of_wind_altitude_above_msl"
},
"measurementType": {
"method": "instantaneous",
"period": "PT0S"
}
}
}
4 changes: 4 additions & 0 deletions tests/test_edr.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import json
from pathlib import Path
from typing import Dict

import pytest
from edr_pydantic.capabilities import LandingPageModel
from edr_pydantic.collections import Collections
from edr_pydantic.collections import Instance
from edr_pydantic.extent import Extent
from edr_pydantic.parameter import Parameter
from edr_pydantic.unit import Unit
from pydantic import RootModel
from pydantic import ValidationError

happy_cases = [
Expand All @@ -15,6 +18,7 @@
("simple-instance.json", Instance),
("landing-page.json", LandingPageModel),
("doc-example-extent.json", Extent),
("parameter-names.json", RootModel[Dict[str, Parameter]]),
]


Expand Down

0 comments on commit 2389a44

Please sign in to comment.