Skip to content
Draft
Show file tree
Hide file tree
Changes from 9 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
31 changes: 17 additions & 14 deletions icepyx/core/APIformatting.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""Generate and format information for submitting to API (CMR and NSIDC)."""

import datetime as dt
from typing import Any, Generic, Literal, Optional, TypeVar, Union, overload
from typing import Any, Generic, Literal, Optional, TypeVar, overload

from icepyx.core.exceptions import ExhaustiveTypeGuardException, TypeGuardException
from icepyx.core.types import (
from icepyx.core.harmony import HarmonyTemporal
from icepyx.core.types.api import (
CMRParams,
EGIParamsSubset,
EGIRequiredParams,
)

# ----------------------------------------------------------------------
Expand Down Expand Up @@ -38,18 +37,17 @@ def _fmt_temporal(start, end, key):
assert isinstance(start, dt.datetime)
assert isinstance(end, dt.datetime)

if key == "temporal":
if key == "temporal": # search option.
fmt_timerange = (
start.strftime("%Y-%m-%dT%H:%M:%SZ")
+ ","
+ end.strftime("%Y-%m-%dT%H:%M:%SZ")
)
elif key == "time":
fmt_timerange = (
start.strftime("%Y-%m-%dT%H:%M:%S")
+ ","
+ end.strftime("%Y-%m-%dT%H:%M:%S")
)
elif key == "time": # subsetting option.
# Format for harmony. This will do subsetting.
# TODO: change `key` to something more clear. `temporal` is the key
# passed into Harmony, so this is very confusing!
fmt_timerange: HarmonyTemporal = {"start": start, "stop": end}
else:
raise ValueError("An invalid time key was submitted for formatting.")

Expand Down Expand Up @@ -212,20 +210,22 @@ def __get__(
self,
instance: 'Parameters[Literal["required"]]',
owner: Any,
) -> EGIRequiredParams: ...
): # -> EGIRequiredParams: ...
...

@overload
def __get__(
self,
instance: 'Parameters[Literal["subset"]]',
owner: Any,
) -> EGIParamsSubset: ...
): # -> EGIParamsSubset: ...
...

def __get__(
self,
instance: "Parameters",
owner: Any,
) -> Union[CMRParams, EGIRequiredParams, EGIParamsSubset]:
) -> CMRParams:
"""
Returns the dictionary of formatted keys associated with the
parameter object.
Expand Down Expand Up @@ -265,6 +265,9 @@ def __init__(
self,
partype: T,
values: Optional[dict] = None,
# TODO: 'download" reqtype appears to never get used. `None` is most
# common, and `search` is passed in when creating required cmr
# parameters to search for matching granules.
reqtype: Optional[Literal["search", "download"]] = None,
):
assert partype in [
Expand Down
Loading