Skip to content

Commit

Permalink
Refactor Query.granules property to cached_property
Browse files Browse the repository at this point in the history
  • Loading branch information
mfisher87 committed Sep 18, 2024
1 parent f0ca1cb commit 91bd9a8
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions icepyx/core/query.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime as dt
from functools import cached_property
import pprint
from typing import Optional, Union, cast

Expand Down Expand Up @@ -735,10 +736,11 @@ def order_vars(self) -> Variables:

return self._order_vars

@property
@cached_property
def granules(self) -> Granules:
"""
Return the granules object, which provides the underlying functionality for searching, ordering,
Return the granules object, which provides the underlying functionality
hing, ordering,
and downloading granules for the specified product.
Users are encouraged to use the built-in wrappers
rather than trying to access the granules object themselves.
Expand All @@ -752,15 +754,13 @@ def granules(self) -> Granules:
Examples
--------
>>> reg_a = ipx.Query('ATL06',[-55, 68, -48, 71],['2019-02-20','2019-02-28']) # doctest: +SKIP
>>> reg_a = ipx.Query('ATL06',[-55, 68, -48,
71],['2019-02-20','2019-02-28']) #
+SKIP
>>> reg_a.granules # doctest: +SKIP
<icepyx.core.granules.Granules at [location]>
"""

if not hasattr(self, "_granules") or self._granules is None:
self._granules = Granules()

return self._granules
return Granules()

# ----------------------------------------------------------------------
# Methods - Get and display neatly information at the product level
Expand Down Expand Up @@ -948,8 +948,6 @@ def avail_granules(
"""

# REFACTOR: add test to make sure there's a session
if not hasattr(self, "_granules"):
self.granules
try:
self.granules.avail
except AttributeError:
Expand Down Expand Up @@ -1044,8 +1042,6 @@ def order_granules(

# 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)
if not hasattr(self, "_granules"):
self.granules

# Place multiple orders, one per granule, if readable_granule_name is used.
if "readable_granule_name[]" in self.CMRparams:
Expand All @@ -1057,7 +1053,7 @@ def order_granules(
)
for gran in gran_name_list:
tempCMRparams["readable_granule_name[]"] = gran
self._granules.place_order(
self.granules.place_order(
tempCMRparams,
cast(EGIRequiredParamsDownload, self.reqparams),
self.subsetparams(**kwargs),
Expand All @@ -1067,7 +1063,7 @@ def order_granules(
)

else:
self._granules.place_order(
self.granules.place_order(
self.CMRparams,
cast(EGIRequiredParamsDownload, self.reqparams),
self.subsetparams(**kwargs),
Expand Down Expand Up @@ -1130,19 +1126,16 @@ def download_granules(
# os.mkdir(path)
# os.chdir(path)

if not hasattr(self, "_granules"):
self.granules

if restart is True:
pass
else:
if (
not hasattr(self._granules, "orderIDs")
or len(self._granules.orderIDs) == 0
not hasattr(self.granules, "orderIDs")
or len(self.granules.orderIDs) == 0
):
self.order_granules(verbose=verbose, subset=subset, **kwargs)

self._granules.download(verbose, path, restart=restart)
self.granules.download(verbose, path, restart=restart)

# DevGoal: add testing? What do we test, and how, given this is a visualization.
# DevGoal(long term): modify this to accept additional inputs, etc.
Expand Down

0 comments on commit 91bd9a8

Please sign in to comment.