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

PR-6418 Additional UMM-G factories #38

Merged
merged 2 commits into from
Feb 27, 2025
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
14 changes: 7 additions & 7 deletions mandible/umm_classes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
metadata_specification,
platform,
provider_date,
range_date_time,
ummg,
)
from .related_url_builder import RelatedUrlBuilder
Expand Down Expand Up @@ -335,20 +336,19 @@ class UmmgTemporalExtentRangeDateTimeMixin(UmmgBase):
def get_beginning_date_time(self) -> datetime.datetime:
pass

@abstractmethod
def get_ending_date_time(self) -> datetime.datetime:
pass
def get_ending_date_time(self) -> Optional[datetime.datetime]:
return None

def get_temporal_extent(self) -> TemporalExtent:
return {
"RangeDateTime": {
"BeginningDateTime": self.date_to_str(
"RangeDateTime": range_date_time(
beginning_date_time=self.date_to_str(
self.get_beginning_date_time(),
),
"EndingDateTime": self.date_to_str(
ending_date_time=self.date_to_str(
self.get_ending_date_time(),
),
},
),
}


Expand Down
41 changes: 40 additions & 1 deletion mandible/umm_classes/factory.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Factory functions for creating small pieces of UMM"""

from typing import Optional, Union
from typing import Any, Optional, Union

from .types import (
AccessConstraints,
AdditionalAttribute,
ArchiveAndDistributionInformation,
CollectionReference,
DataGranule,
HorizontalSpatialDomain,
Identifier,
Instrument,
MeasuredParameter,
Expand All @@ -17,6 +18,7 @@
Platform,
Project,
ProviderDate,
RangeDateTime,
RelatedUrl,
SpatialExtent,
TemporalExtent,
Expand Down Expand Up @@ -106,6 +108,19 @@ def provider_date(type: str, date: str) -> ProviderDate:
}


def range_date_time(
beginning_date_time: str,
ending_date_time: Optional[str] = None,
) -> RangeDateTime:
obj: RangeDateTime = {
"BeginningDateTime": beginning_date_time,
}
if ending_date_time is not None:
obj["EndingDateTime"] = ending_date_time

return obj


def related_url(
url: str,
type: str,
Expand Down Expand Up @@ -136,6 +151,30 @@ def related_url(
return obj


def spatial_extent(
granule_localities: Optional[list[str]] = None,
horizontal_spatial_domain: Optional[HorizontalSpatialDomain] = None,
# TODO(reweeden): Implement typing
vertical_spatial_domains: Optional[list[dict[str, Any]]] = None,
) -> SpatialExtent:
obj: SpatialExtent = {}

if granule_localities is not None:
obj["GranuleLocalities"] = granule_localities
if horizontal_spatial_domain is not None:
obj["HorizontalSpatialDomain"] = horizontal_spatial_domain
if vertical_spatial_domains is not None:
obj["VerticalSpatialDomains"] = vertical_spatial_domains

if not obj:
raise ValueError(
"one of 'granule_localities', 'horizontal_spatial_domain', or "
"'vertical_spatial_domains' is required",
)

return obj


def ummg(
granule_ur: str,
provider_dates: list[ProviderDate],
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.9.3"
version = "0.9.4"
description = "A generic framework for writing satellite data ingest systems"
authors = ["Rohan Weeden <[email protected]>", "Matt Perry <[email protected]>"]
license = "APACHE-2"
Expand Down