Skip to content

Commit

Permalink
Add optional measurementType field in Parameter, see:
Browse files Browse the repository at this point in the history
https://docs.ogc.org/is/19-086r6/19-086r6.html#col-measurement_type

Not inconsistency in naming of field duration vs period in the description versus the examples. I think period was intended here...
  • Loading branch information
lukas-phaf committed Aug 20, 2024
1 parent 24685e8 commit c0a91a6
Show file tree
Hide file tree
Showing 4 changed files with 69 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
6 changes: 6 additions & 0 deletions src/edr_pydantic/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@
from .unit import Unit


class MeasurementType(EdrBaseModel):
method: str
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"
}
}
}
3 changes: 3 additions & 0 deletions tests/test_edr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
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 +17,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 c0a91a6

Please sign in to comment.