Skip to content

Commit

Permalink
WIP remove granules.place_order in favor of `granules.place_harmon_…
Browse files Browse the repository at this point in the history
…subset_order`

separate concerns
  • Loading branch information
trey-stafford committed Nov 13, 2024
1 parent 2cacbd7 commit 0da719f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 59 deletions.
84 changes: 34 additions & 50 deletions icepyx/core/granules.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,37 @@ def get_avail(
len(self.avail) > 0
), "Your search returned no results; try different search parameters"

def _place_harmony_subset_order(
def place_harmony_subset_order(
self,
request_params,
# TODO: remove `CMRparams` from this function. This should only take subset params.
CMRparams,
subsetparams,
# TODO: support passing in a geometry filepath
geom_filepath=None,
) -> list[str]:
"""
Place a harmony subset order.
Parameters
----------
CMRparams :
Dictionary of properly formatted CMR search parameters.
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.
geom_filepath : string, default None
String of the full filename and path when the spatial input is a file.
Notes
-----
This function is used by query.Query.order_granules(), which automatically
feeds in the required parameters.
See Also
--------
query.Query.order_granules
"""
request_params = apifmt.combine_params(CMRparams, subsetparams)
concept_id = get_concept_id(
product=request_params["short_name"],
version=request_params["version"],
Expand Down Expand Up @@ -347,55 +373,20 @@ def _place_harmony_subset_order(

return self.orderIDs

def _place_non_subset_order(
def place_non_subset_order(
self,
CMRparams: CMRParams,
):
# TODO: use e.g., `earthaccess` to download files un-processed by harmony.
raise NotImplementedError("Support for non-subset orders is not implemented.")
self.get_avail(CMRparams)
request_params = apifmt.combine_params(CMRparams, {"agent": "NO"})

# DevNote: currently, default subsetting DOES NOT include variable subsetting,
# only spatial and temporal
# DevGoal: add kwargs to allow subsetting and more control over request options.
def place_order(
self,
CMRparams: CMRParams,
subsetparams,
verbose,
subset=True,
geom_filepath=None,
):
"""
Place an order for the available granules for the query object.
Adds the list of zipped files (orders) to the granules data object (which is
stored as the `granules` attribute of the query object).
You must be logged in to Earthdata to use this function.
Place an order for data files with `earthaccess`.
Parameters
----------
CMRparams :
Dictionary of properly formatted CMR search parameters.
reqparams :
Dictionary of properly formatted parameters required for searching, ordering,
or downloading from NSASA (via harmony).
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.
verbose : boolean, default False
Print out all feedback available from the order process.
Progress information is automatically printed regardless of the value of verbose.
subset : boolean, default True
Apply subsetting to the data order from the NSIDC, returning only data that meets the
subset parameters.
Spatial and temporal subsetting based on the input parameters happens
by default when subset=True, but additional subsetting options are available.
Spatial subsetting returns all data that are within the area of interest
(but not complete granules.
This eliminates false-positive granules returned by the metadata-level search)
geom_filepath : string, default None
String of the full filename and path when the spatial input is a file.
Notes
-----
Expand All @@ -406,17 +397,10 @@ def place_order(
--------
query.Query.order_granules
"""
if subset is False:
self._place_non_subset_order(CMRparams)
else:
# TODO: why are we combining these like this? We could just pass in
# these values separately. Eventually would like to collapse this
# down into just one `HarmonySubsetParams`.
request_params = apifmt.combine_params(CMRparams, subsetparams)
return self._place_harmony_subset_order(
request_params,
subsetparams,
)
# TODO: use e.g., `earthaccess` to download files un-processed by harmony.
raise NotImplementedError("Support for non-subset orders is not implemented.")
self.get_avail(CMRparams)
request_params = apifmt.combine_params(CMRparams, {"agent": "NO"})

def download(self, verbose, path, restart=False):
"""
Expand Down
14 changes: 5 additions & 9 deletions icepyx/core/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ def order_granules(
Print out all feedback available from the order process.
Progress information is automatically printed regardless of the value of verbose.
subset :
Apply subsetting to the data order from the NSIDC, returning only data that meets the
Apply subsetting to the data order from Harmony, returning only data that meets the
subset parameters. Spatial and temporal subsetting based on the input parameters happens
by default when subset=True, but additional subsetting options are available.
Spatial subsetting returns all data that are within the area of interest (but not complete
Expand Down Expand Up @@ -1048,8 +1048,8 @@ def order_granules(
.
Retry request status is: complete
"""
# breakpoint()
# raise RefactoringException
if not subset:
raise NotImplementedError

# This call ensures that `self._cmr_reqparams` is set.
self.cmr_reqparams
Expand Down Expand Up @@ -1097,20 +1097,16 @@ def order_granules(
)
for gran in gran_name_list:

Check failure on line 1098 in icepyx/core/query.py

View workflow job for this annotation

GitHub Actions / test

"object" is not iterable   "__iter__" method not defined (reportGeneralTypeIssues)
tempCMRparams["readable_granule_name[]"] = gran
self.granules.place_order(
self.granules.place_subset_order(

Check failure on line 1100 in icepyx/core/query.py

View workflow job for this annotation

GitHub Actions / test

Cannot access attribute "place_subset_order" for class "Granules"   Attribute "place_subset_order" is unknown (reportAttributeAccessIssue)
tempCMRparams,
self.subsetparams(granule_name=gran, **kwargs),
verbose,
subset,
geom_filepath=self._spatial._geom_file,
)

else:
self.granules.place_order(
self.granules.place_subset_order(

Check failure on line 1107 in icepyx/core/query.py

View workflow job for this annotation

GitHub Actions / test

Cannot access attribute "place_subset_order" for class "Granules"   Attribute "place_subset_order" is unknown (reportAttributeAccessIssue)
cmr_params,
self.subsetparams(**kwargs),
verbose,
subset,
geom_filepath=self._spatial._geom_file,
)

Expand Down

0 comments on commit 0da719f

Please sign in to comment.