Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional measurementType field in Parameter #11

Merged
merged 5 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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