From c0a91a65372ff922cb9a0cd206f3acf2de74d28a Mon Sep 17 00:00:00 2001 From: Lukas Phaf Date: Tue, 20 Aug 2024 16:26:48 +0200 Subject: [PATCH 1/5] Add optional measurementType field in Parameter, see: 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... --- pyproject.toml | 2 +- src/edr_pydantic/parameter.py | 6 +++ tests/test_data/parameter-names.json | 59 ++++++++++++++++++++++++++++ tests/test_edr.py | 3 ++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/test_data/parameter-names.json diff --git a/pyproject.toml b/pyproject.toml index 471c791..df908ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] diff --git a/src/edr_pydantic/parameter.py b/src/edr_pydantic/parameter.py index d8da3cb..0482784 100644 --- a/src/edr_pydantic/parameter.py +++ b/src/edr_pydantic/parameter.py @@ -11,6 +11,11 @@ from .unit import Unit +class MeasurementType(EdrBaseModel): + method: str + period: str + + class Parameter(EdrBaseModel, extra="allow"): type: Literal["Parameter"] = "Parameter" id: Optional[str] = None @@ -18,6 +23,7 @@ class Parameter(EdrBaseModel, extra="allow"): 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): diff --git a/tests/test_data/parameter-names.json b/tests/test_data/parameter-names.json new file mode 100644 index 0000000..1583484 --- /dev/null +++ b/tests/test_data/parameter-names.json @@ -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" + } + } +} diff --git a/tests/test_edr.py b/tests/test_edr.py index c68e4ac..86ff619 100644 --- a/tests/test_edr.py +++ b/tests/test_edr.py @@ -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 = [ @@ -15,6 +17,7 @@ ("simple-instance.json", Instance), ("landing-page.json", LandingPageModel), ("doc-example-extent.json", Extent), + ("parameter-names.json", RootModel[dict[str, Parameter]]), ] From 4500ec65dfa178419efe23dd4401f9a47055d965 Mon Sep 17 00:00:00 2001 From: Lukas Phaf Date: Tue, 20 Aug 2024 16:30:18 +0200 Subject: [PATCH 2/5] Fix for Python 3.8. --- tests/test_edr.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_edr.py b/tests/test_edr.py index 86ff619..81c6da8 100644 --- a/tests/test_edr.py +++ b/tests/test_edr.py @@ -1,5 +1,6 @@ import json from pathlib import Path +from typing import Dict import pytest from edr_pydantic.capabilities import LandingPageModel @@ -17,7 +18,7 @@ ("simple-instance.json", Instance), ("landing-page.json", LandingPageModel), ("doc-example-extent.json", Extent), - ("parameter-names.json", RootModel[dict[str, Parameter]]), + ("parameter-names.json", RootModel[Dict[str, Parameter]]), ] From 6238c9bb2eac0568b0aad7f182362cd16b437118 Mon Sep 17 00:00:00 2001 From: Lukas Phaf Date: Thu, 22 Aug 2024 13:31:06 +0200 Subject: [PATCH 3/5] Add TODO's. --- src/edr_pydantic/parameter.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/edr_pydantic/parameter.py b/src/edr_pydantic/parameter.py index 0482784..2db9fc4 100644 --- a/src/edr_pydantic/parameter.py +++ b/src/edr_pydantic/parameter.py @@ -12,7 +12,10 @@ class MeasurementType(EdrBaseModel): + # TODO: Confusion in spec on field name, method versus period. + # See https://github.com/opengeospatial/ogcapi-environmental-data-retrieval/issues/573 method: str + # TODO: Add validation of ISO 8601 duration period: str From e445f07d7278702abdd3825def0c327bedf89183 Mon Sep 17 00:00:00 2001 From: Lukas Phaf Date: Thu, 22 Aug 2024 13:38:39 +0200 Subject: [PATCH 4/5] Point to existing issue. --- src/edr_pydantic/parameter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/edr_pydantic/parameter.py b/src/edr_pydantic/parameter.py index 2db9fc4..1090916 100644 --- a/src/edr_pydantic/parameter.py +++ b/src/edr_pydantic/parameter.py @@ -13,7 +13,7 @@ class MeasurementType(EdrBaseModel): # TODO: Confusion in spec on field name, method versus period. - # See https://github.com/opengeospatial/ogcapi-environmental-data-retrieval/issues/573 + # See https://github.com/opengeospatial/ogcapi-environmental-data-retrieval/issues/560 method: str # TODO: Add validation of ISO 8601 duration period: str From 29a9e577976cf5d4e91700eecfbfc865396d0a62 Mon Sep 17 00:00:00 2001 From: Lukas Phaf Date: Thu, 22 Aug 2024 13:49:09 +0200 Subject: [PATCH 5/5] Fix comments. --- src/edr_pydantic/parameter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/edr_pydantic/parameter.py b/src/edr_pydantic/parameter.py index 1090916..466dbde 100644 --- a/src/edr_pydantic/parameter.py +++ b/src/edr_pydantic/parameter.py @@ -12,10 +12,10 @@ class MeasurementType(EdrBaseModel): - # TODO: Confusion in spec on field name, method versus period. - # See https://github.com/opengeospatial/ogcapi-environmental-data-retrieval/issues/560 method: str - # TODO: Add validation of ISO 8601 duration + # 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