diff --git a/icepyx/core/query.py b/icepyx/core/query.py index e39425372..71b6dad59 100644 --- a/icepyx/core/query.py +++ b/icepyx/core/query.py @@ -997,6 +997,58 @@ def avail_granules( else: return granules.info(self.granules.avail) + def _order_subset_granules(self, **kwargs): + # This call ensures that `self._cmr_reqparams` is set. + self.cmr_reqparams + if self._cmr_reqparams._reqtype == "search": + self._cmr_reqparams._reqtype = "download" + + # TODO: is it necessary to delete the `self._subsetparams` attr? We are + # performing a subset so this seems the opposite of what is expected. + if hasattr(self, "_subsetparams") and self._subsetparams is None: + del self._subsetparams + + # TODO: this shouldn't be necessary: + cmr_params = {**self.CMRparams, **self.cmr_reqparams} + + # REFACTOR: add checks here to see if the granules object has been created, + # and also if it already has a list of avail granules (if not, need to create one and add session) + + # Place multiple orders, one per granule, if readable_granule_name is used. + # TODO/Question: is "readable granule name" a thing in harmony? This may + # only be relevant for non-subset requests that will be handled by e.g., + # `earthaccess`. + # Answer: there appears to be a `granuleName` parameter that harmony can + # take for its own internal queries to CMR, but it is unclear how that + # works. See https://harmony.earthdata.nasa.gov/docs#query-parameters + # `harmony-py` accepts `granule_name` as an input. + if "readable_granule_name[]" in cmr_params: + gran_name_list = cmr_params["readable_granule_name[]"] + tempCMRparams = cmr_params.copy() + if len(gran_name_list) > 1: + print( + "Harmony only allows ordering of one granule by name at a time;" + " your orders will be placed accordingly." + ) + for gran in gran_name_list: + tempCMRparams["readable_granule_name[]"] = gran + self.granules.place_harmony_subset_order( + tempCMRparams, + self.subsetparams(granule_name=gran, **kwargs), + geom_filepath=self._spatial._geom_file, + ) + + else: + self.granules.place_harmony_subset_order( + cmr_params, + self.subsetparams(**kwargs), + geom_filepath=self._spatial._geom_file, + ) + + def _order_whole_granules(self): + raise NotImplementedError + self._subsetparams = None + # DevGoal: display output to indicate number of granules successfully ordered (and number of errors) # DevGoal: deal with subset=True for variables now, and make sure that if a variable subset # Coverage kwarg is input it's successfully passed through all other functions even if this is the only one run. @@ -1023,9 +1075,7 @@ def order_granules( **kwargs : key-value pairs Additional parameters to be passed to the subsetter. By default temporal and spatial subset keys are passed. - Acceptable key values are ['format','projection','projection_parameters','Coverage']. - The variable 'Coverage' list should be constructed using the `order_vars.wanted` attribute of the object. - At this time (2020-05), only variable ('Coverage') parameters will be automatically formatted. + Acceptable key values are [TODO]. See Also -------- @@ -1044,59 +1094,12 @@ def order_granules( . Retry request status is: complete """ - if not subset: - raise NotImplementedError - - # This call ensures that `self._cmr_reqparams` is set. - self.cmr_reqparams - if self._cmr_reqparams._reqtype == "search": - self._cmr_reqparams._reqtype = "download" - - if subset is False: - self._subsetparams = None - elif ( - subset is True - and hasattr(self, "_subsetparams") - and self._subsetparams is None - ): - del self._subsetparams - - # TODO: this shouldn't be necessary: - cmr_params = {**self.CMRparams, **self.cmr_reqparams} - - # REFACTOR: add checks here to see if the granules object has been created, - # and also if it already has a list of avail granules (if not, need to create one and add session) - - # Place multiple orders, one per granule, if readable_granule_name is used. - # TODO/Question: is "readable granule name" a thing in harmony? This may - # only be relevant for non-subset requests that will be handled by e.g., - # `earthaccess`. - # Answer: there appears to be a `granuleName` parameter that harmony can - # take for its own internal queries to CMR, but it is unclear how that - # works. See https://harmony.earthdata.nasa.gov/docs#query-parameters - # `harmony-py` accepts `granule_name` as an input. - if "readable_granule_name[]" in cmr_params: - gran_name_list = cmr_params["readable_granule_name[]"] - tempCMRparams = cmr_params.copy() - if len(gran_name_list) > 1: - print( - "Harmony only allows ordering of one granule by name at a time;" - " your orders will be placed accordingly." - ) - for gran in gran_name_list: - tempCMRparams["readable_granule_name[]"] = gran - self.granules.place_subset_order( - tempCMRparams, - self.subsetparams(granule_name=gran, **kwargs), - geom_filepath=self._spatial._geom_file, - ) - - else: - self.granules.place_subset_order( - cmr_params, - self.subsetparams(**kwargs), - geom_filepath=self._spatial._geom_file, + if subset: + self._order_subset_granules( + **kwargs, ) + else: + self._order_whole_granules() # DevGoal: put back in the kwargs here so that people can just call download granules with subset=False! def download_granules(