Skip to content

Commit

Permalink
KDP-1528 update spec adherence and remove unused packages
Browse files Browse the repository at this point in the history
  • Loading branch information
rosinaderks committed Oct 9, 2023
1 parent bb021f3 commit 8198d1b
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 90 deletions.
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,3 @@ repos:
pass_filenames: false
additional_dependencies:
- pydantic
- covjson-pydantic
- types-python-dateutil
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 = [
"Typing :: Typed",
]
version = "0.1.0"
dependencies = ["pydantic>=2.3,<3", "covjson-pydantic~=0.2.0"]
dependencies = ["pydantic>=2.3,<3"]

[project.optional-dependencies]
test = ["pytest", "pytest-cov"]
Expand Down
26 changes: 12 additions & 14 deletions src/edr_pydantic/collections.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
from __future__ import annotations

from typing import Dict
from typing import List
from typing import Optional

from .data_queries import DataQueries
from .extent import Extent
from .link import Link
from .my_base_model import EDRBaseModel
from .parameter import ParameterNames
from .parameter import Parameter


# TODO instances or collections as base?
class Collection(EDRBaseModel):
links: List[Link]
id: str
extent: Extent
parameter_names: ParameterNames
title: Optional[str] = None
description: Optional[str] = None
keywords: Optional[List[str]] = None
links: List[Link]
extent: Extent
data_queries: Optional[DataQueries] = None
# TODO required according to A.13, string array or crs object?
# TODO According to req A.13 it should be CRSDetails object
crs: Optional[List[str]] = None
# TODO in req as f?
output_formats: Optional[List[str]] = None
# TODO may have distanceunits, if radius is in link, it shall have distanceunits
parameter_names: Dict[str, Parameter]
# TODO According to req A.13 MAY have distanceunits. If radius is in link, it SHALL have distanceunits
distanceunits: Optional[List[str]] = None


Expand All @@ -33,11 +31,11 @@ class CollectionsModel(EDRBaseModel):
collections: List[Collection]


class InstancesModel(EDRBaseModel):
links: List[Link]
instances: List[Instance]


# For now, the instance metadata corresponds to the first collection metadata. So they have equal classes
class Instance(Collection):
pass


class InstancesModel(EDRBaseModel):
links: List[Link]
instances: List[Instance]
7 changes: 4 additions & 3 deletions src/edr_pydantic/data_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
from .variables import Variables


class EDRQueryLink(EDRBaseModel):
class EDRQueryLink(EDRBaseModel, extra="allow"):
href: str
rel: str
variables: Union[Variables, CubeVariables, CorridorVariables, ItemVariables, RadiusVariables]


# TODO why not normal Link object?
# TODO Why not use the Link object, difference is required variables for this link?
class EDRQuery(EDRBaseModel):
link: EDRQueryLink

Expand All @@ -27,6 +27,7 @@ class DataQueries(EDRBaseModel):
cube: Optional[EDRQuery] = None
trajectory: Optional[EDRQuery] = None
corridor: Optional[EDRQuery] = None
# TODO difference object/req: item, location, plus instances?
# TODO Difference object/req: item, location, plus instances (only for collection)?
locations: Optional[EDRQuery] = None
items: Optional[EDRQuery] = None
instances: Optional[EDRQuery] = None
20 changes: 4 additions & 16 deletions src/edr_pydantic/extent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,25 @@
from pydantic import AwareDatetime

from .my_base_model import EDRBaseModel
from .reference_system import CRSDetails


class Spatial(EDRBaseModel):
bbox: List[List[float]]
# TODO CRS/CRSDetails/CRSOptions/str?
crs: CRSDetails
# TODO not in spec
name: Optional[str] = None
crs: str


class Temporal(EDRBaseModel):
# TODO Array of ISO 8601 Data Array
# TODO: An array of ISO 8601 Date Array, each ISO 8601 Date Array should contain two values first being
# the minimum date time and second the maximum date time for information in the collection
# TODO Check: Array of ISO 8601 Data Array
interval: List[List[AwareDatetime]]
# TODO An array of ISO 8601 datestrings which details the time intervals available in the collection,
# each member of the array can either be a single time, an ISO 8601 time interval or an ISO 8601 time duration
values: List[AwareDatetime]
# TODO Check: ISO 8601 Data Array
values: List[str]
trs: str
# TODO remove name not in spec
name: Optional[str] = None


class Vertical(EDRBaseModel):
interval: List[List[float]]
values: List[float]
# TODO WKT standard str
vrs: str
# TODO no name in spec
name: Optional[str] = None


class Extent(EDRBaseModel):
Expand Down
28 changes: 0 additions & 28 deletions src/edr_pydantic/generic_models.py

This file was deleted.

31 changes: 31 additions & 0 deletions src/edr_pydantic/instances.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from typing import Dict
from typing import List
from typing import Optional

from .data_queries import DataQueries
from .extent import Extent
from .link import Link
from .my_base_model import EDRBaseModel
from .parameter import Parameter


# TODO Difference between Instance and Collection?
class Instance(EDRBaseModel):
id: str
title: Optional[str] = None
description: Optional[str] = None
keywords: Optional[List[str]] = None
links: List[Link]
extent: Extent
data_queries: Optional[DataQueries] = None
# TODO According to req A.13 it should be CRSDetails object
crs: Optional[List[str]] = None
output_formats: Optional[List[str]] = None
parameter_names: Dict[str, Parameter]
# TODO According to req A.13 MAY have distanceunits. If radius is in link, it SHALL have distanceunits
distanceunits: Optional[List[str]] = None


class InstancesModel(EDRBaseModel):
links: List[Link]
instances: List[Instance]
8 changes: 4 additions & 4 deletions src/edr_pydantic/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

class Link(EDRBaseModel):
href: str
hreflang: Optional[str] = None
rel: str
# TODO A.21 & A.23 all links shall include rel and type? rc-collections-info-links
# TODO According to A.21 & A.23 all links shall include type
type: Optional[str] = None
hreflang: Optional[str] = None
title: Optional[str] = None
length: Optional[int] = None
templated: Optional[bool] = None
# TODO dataquery link separate because variables is required there?
variables: Optional[Union[Variables, CubeVariables, CorridorVariables, ItemVariables, RadiusVariables]]
# TODO Dataquery link separate from Link because variables is required there?
variables: Optional[Union[Variables, CubeVariables, CorridorVariables, ItemVariables, RadiusVariables]] = None
1 change: 0 additions & 1 deletion src/edr_pydantic/my_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

class EDRBaseModel(PydanticBaseModel):
model_config = ConfigDict(
populate_by_name=True,
str_strip_whitespace=True,
extra="forbid",
str_min_length=1,
Expand Down
13 changes: 1 addition & 12 deletions src/edr_pydantic/parameter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import annotations

from typing import Dict
from typing import List
from typing import Literal
from typing import Optional
Expand All @@ -12,21 +9,13 @@
from .unit import Unit


class ParameterNames(EDRBaseModel):
parameter_names: Dict[str, Parameter]


class Parameter(EDRBaseModel, extra="allow"):
type: Literal["Parameter"] = "Parameter"
observedProperty: ObservedProperty # noqa: N815
id: Optional[str] = None
label: Optional[str] = None
description: Optional[str] = None
# TODO no duplicates keys
# TODO int in list int should be unique
# TODO category encoding not in parameterobject, we don't use it??
# categoryEncoding: Optional[Dict[str, Union[int, List[int]]]] = None # noqa: N815
unit: Optional[Unit] = None
observedProperty: ObservedProperty # noqa: N815

@model_validator(mode="after")
def must_not_have_unit_if_observed_property_has_categories(self):
Expand Down
7 changes: 0 additions & 7 deletions src/edr_pydantic/reference_system.py

This file was deleted.

4 changes: 2 additions & 2 deletions src/edr_pydantic/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class Variables(EDRBaseModel, extra="allow"):
# TODO query_type requires?? Not according to C.3
# TODO query_type required? Not according to C.3
query_type: str
output_formats: Optional[List[str]] = None
# TODO If a default_output_format property exists the defined value MUST be a value contained either in the
Expand All @@ -26,6 +26,6 @@ class CorridorVariables(Variables):
within_units: List[str]


class ItemVariables(Variables):
class ItemVariables(Variables, extra="allow"):
# TODO query_type shall match query_type?
query_type: str

0 comments on commit 8198d1b

Please sign in to comment.