Skip to content
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
27 changes: 27 additions & 0 deletions mandible/umm_classes/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
ArchiveAndDistributionInformation,
CollectionReference,
DataGranule,
Geometry,
HorizontalSpatialDomain,
Identifier,
Instrument,
Expand Down Expand Up @@ -58,6 +59,32 @@ def data_granule(
return obj


def horizontal_spatial_domain(
zone_identifier: Optional[str] = None,
geometry: Optional[Geometry] = None,
# TODO(reweeden): Implement typing
orbit: Optional[dict[str, Any]] = None,
# TODO(reweeden): Implement typing
track: Optional[dict[str, Any]] = None,
) -> HorizontalSpatialDomain:
obj: HorizontalSpatialDomain = {}
if zone_identifier is not None:
obj["ZoneIdentifier"] = zone_identifier
if geometry is not None:
obj["Geometry"] = geometry
if orbit is not None:
obj["Orbit"] = orbit
if track is not None:
obj["Track"] = track

if orbit is None and track is None:
raise ValueError(
"one of 'orbit' or 'track' is required",
)

return obj

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to hold off on adding the orbit and track params and adding the oneOf validation? As it stands now this factory function can produce an empty dict which is invalid as far as the jsonschema goes. I would say if you're not going to add orbit then at least I'd make geometry required / raise a ValueError if geometry is not provided. But I think it would be just cleaner to implement the whole thing, it should be an additional like 10 lines of code.

Comment on lines +62 to +85

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also keep the params in the order they are defined in the schema and build the resulting dict in that order when possible, and in this case it is! And I'd keep the formatting consistent with the implementations (empty line before the return statement).

All said and done if I was doing this PR I would commit this:

Suggested change
def horizontal_spatial_domain(
geometry: Optional[Geometry] = None,
zone_identifier: Optional[str] = None,
) -> HorizontalSpatialDomain:
obj: HorizontalSpatialDomain = {}
if geometry is not None:
obj["Geometry"] = geometry
if zone_identifier is not None:
obj["ZoneIdentifier"] = zone_identifier
return obj
def horizontal_spatial_domain(
zone_identifier: Optional[str] = None,
geometry: Optional[Geometry] = None,
# TODO(reweeden): Implement typing
orbit: Optional[dict[str, Any]] = None,
# TODO(reweeden): Implement typing
track: Optional[dict[str, Any]] = None,
) -> HorizontalSpatialDomain:
obj: HorizontalSpatialDomain = {}
if zone_identifier is not None:
obj["ZoneIdentifier"] = zone_identifier
if geometry is not None:
obj["Geometry"] = geometry
if orbit is not None:
obj["Orbit"] = orbit
if track is not None:
obj["Track"] = track
if orbit is None and track is None:
raise ValueError(
"one of 'orbit' or 'track' is required",
)
return obj



def identifier(
type: str,
identifier: str,
Expand Down
3 changes: 1 addition & 2 deletions mandible/umm_classes/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ class HorizontalSpatialDomain(TypedDict):
https://git.earthdata.nasa.gov/projects/EMFD/repos/unified-metadata-model/browse/granule/v1.6.5/umm-g-json-schema.json#497
"""

# TODO(reweeden): Implement
ZoneIdentifier: NotRequired[dict[str, Any]]
ZoneIdentifier: NotRequired[str]
Geometry: NotRequired[Geometry]
# TODO(reweeden): Implement
Orbit: NotRequired[dict[str, Any]]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mandible"
version = "0.10.3"
version = "0.10.4"
description = "A generic framework for writing satellite data ingest systems"
authors = ["Rohan Weeden <reweeden@alaska.edu>", "Matt Perry <mperry37@alaska.edu>"]
license = "APACHE-2"
Expand Down
Loading