Skip to content

Commit

Permalink
WIP2 (reset me)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfisher87 committed Aug 23, 2024
1 parent 572210a commit 3fcc23e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 28 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ before_install:
- conda info -a

install:
- conda create --name icepyx-env --channel conda-forge python=3.10 proj geos
- conda create --name icepyx-env --channel conda-forge python=3.10 pip proj geos
- source activate icepyx-env
- pip install -r requirements.txt -r requirements-dev.txt
- pip install -e .[complete]
- pip install -e .[dev,complete]

stages:
- name: basic tests
Expand Down
5 changes: 4 additions & 1 deletion icepyx/core/APIformatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,17 @@ def combine_params(*param_dicts):
"""
Combine multiple dictionaries into one.
Merging is performed in sequence using `dict.update()`; dictionaries later in the
list overwrite those earlier.
Parameters
----------
params : dictionaries
Unlimited number of dictionaries to combine
Returns
-------
single dictionary of all input dictionaries combined
A single dictionary of all input dictionaries combined
Examples
--------
Expand Down
31 changes: 19 additions & 12 deletions icepyx/core/granules.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import os
import pprint
import zipfile
from typing import Sequence
from typing import Sequence, Final, Literal, cast

Check failure on line 13 in icepyx/core/granules.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F401)

icepyx/core/granules.py:13:46: F401 `typing.cast` imported but unused
from xml.etree import ElementTree as ET

import icepyx.core.APIformatting as apifmt
import icepyx.core.exceptions
from icepyx.core.auth import EarthdataAuthMixin
from icepyx.core.types import CMRParams
from icepyx.core.types import CMRParams, EGISpecificParams


def info(grans):
Expand Down Expand Up @@ -177,7 +177,7 @@ def __init__(
def get_avail(
self,
CMRparams: CMRParams | None,
reqparams: ECSParams | None,
reqparams: EGISpecificParams | None,
cloud=False,
):
"""
Expand Down Expand Up @@ -212,15 +212,22 @@ def get_avail(
# if not hasattr(self, 'avail'):
self.avail = []

granule_search_url = "https://cmr.earthdata.nasa.gov/search/granules"
granule_search_url: Final = "https://cmr.earthdata.nasa.gov/search/granules"

headers = {"Accept": "application/json", "Client-Id": "icepyx"}
# note we should also check for errors whenever we ping NSIDC-API -
# make a function to check for errors

# HACK: Really hold the typechecker's hand for this dynamic assignment.
# See: https://github.com/python/mypy/issues/7178#issuecomment-509754282
expected_param_names: set[Literal["short_name", "version", "page_size"]] = {
"short_name",
"version",
"page_size",
}
params = apifmt.combine_params(
CMRparams,
{k: reqparams[k] for k in ["short_name", "version", "page_size"]},
{k: reqparams[k] for k in expected_param_names},
{"provider": "NSIDC_CPRD"},
)

Expand Down Expand Up @@ -273,7 +280,7 @@ def get_avail(
def place_order(
self,
CMRparams: CMRParams,
reqparams: ECSParams,
reqparams: EGISpecificParams,
subsetparams,
verbose,
subset=True,
Expand All @@ -289,9 +296,9 @@ def place_order(
----------
CMRparams :
Dictionary of properly formatted CMR search parameters.
reqparams : dictionary
reqparams :
Dictionary of properly formatted parameters required for searching, ordering,
or downloading from NSIDC.
or downloading from EGI.
subsetparams : dictionary
Dictionary of properly formatted subsetting parameters. An empty dictionary
is passed as input here when subsetting is set to False in query methods.
Expand All @@ -318,9 +325,7 @@ def place_order(
--------
query.Query.order_granules
"""

base_url = "https://n5eil02u.ecs.nsidc.org/egi/request"
breakpoint()
base_url: Final = "https://n5eil02u.ecs.nsidc.org/egi/request"

self.get_avail(CMRparams, reqparams)

Expand All @@ -342,8 +347,10 @@ def place_order(
" granules.",
)


reveal_type(reqparams)

Check failure on line 351 in icepyx/core/granules.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F821)

icepyx/core/granules.py:351:9: F821 Undefined name `reveal_type`
pagenums: Sequence
if reqparams["page_num"] > 0:
if "page_num" in reqparams and reqparams["page_num"] > 0:
pagenums = [reqparams["page_num"]]
else:
pagenums = range(1, total_pages + 1)
Expand Down
6 changes: 4 additions & 2 deletions icepyx/core/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import icepyx.core.spatial as spat
import icepyx.core.temporal as tp
import icepyx.core.validate_inputs as val
from icepyx.core.types import CMRParams
from icepyx.core.types import CMRParams, EGISpecificParams
from icepyx.core.variables import Variables as Variables
from icepyx.core.visualization import Visualize

Expand Down Expand Up @@ -570,10 +570,11 @@ def CMRparams(self) -> CMRParams:
**kwargs,
)

breakpoint()
return self._CMRparams.fmted_keys

@property
def reqparams(self) -> EGISpecificParamsBase:
def reqparams(self) -> EGISpecificParams:
"""
Display the required key:value pairs that will be submitted.
It generates the dictionary if it does not already exist.
Expand All @@ -594,6 +595,7 @@ def reqparams(self) -> EGISpecificParamsBase:
self._reqparams = apifmt.Parameters("required", reqtype="search")
self._reqparams.build_params(product=self.product, version=self._version)

breakpoint()
return self._reqparams.fmted_keys

# @property
Expand Down
22 changes: 12 additions & 10 deletions icepyx/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class CMRParamsWithPolygon(CMRParamsBase):
class EGISpecificParamsBase(TypedDict):
"""Common parameters for searching, ordering, or downloading from EGI.
See: https://wiki.earthdata.nasa.gov/display/SDPSDOCS/EGI+Programmatic+Access+Documentation
EGI shares parameters with CMR, so this data is used in conjunction with CMRParams
to build EGI requests.
Expand All @@ -33,26 +35,26 @@ class EGISpecificParamsBase(TypedDict):
"""
short_name: str # alias: "product"
version: str
page_size: int = 2000
page_size: int # default 2000


class EGISpecificParamsSearch(EGISpecificParamsBase):
"""Parameters for searching through EGI."""


class EGISpecificParamsOrder(EGISpecificParamsBase):
"""Parameters for ordering through EGI."""


class EGISpecificParamsDownload(EGISpecificParamsBase):
"""Parameters for ordering from EGI.
TODO: Validate more strongly (with Pydantic?): page_num >=0.
"""
page_num: int = 0
request_mode: Literal["sync", "async", "stream"] = "async"
include_meta: Literal["Y", "N"] = "Y"
client_string: Literal["icepyx"] = "icepyx"
page_num: int # default 0
request_mode: Literal["sync", "async", "stream"] # default "async"
include_meta: Literal["Y", "N"] # default "Y"
client_string: Literal["icepyx"] # default "icepyx"


class EGIParams(CMRParams, EGISpecificParams):
"""All parameters for searching, ordering, or downloading from EGI.
See: https://wiki.earthdata.nasa.gov/display/SDPSDOCS/EGI+Programmatic+Access+Documentation
"""
EGISpecificParams = EGISpecificParamsSearch | EGISpecificParamsDownload
3 changes: 3 additions & 0 deletions icepyx/core/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SEARCH_BASE_URL: Final = "https://cmr.earthdata.nasa.gov/search/granules"

Check failure on line 1 in icepyx/core/urls.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F821)

icepyx/core/urls.py:1:18: F821 Undefined name `Final`
ORDER_BASE_URL: Final = "https://n5eil02u.ecs.nsidc.org/egi/request"

Check failure on line 2 in icepyx/core/urls.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F821)

icepyx/core/urls.py:2:17: F821 Undefined name `Final`
DOWNLOAD_BASE_URL: Final = "https://n5eil02u.ecs.nsidc.org/esir"

Check failure on line 3 in icepyx/core/urls.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F821)

icepyx/core/urls.py:3:20: F821 Undefined name `Final`

0 comments on commit 3fcc23e

Please sign in to comment.