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 Oct 23, 2024
1 parent a89d069 commit 2e7ac19
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions icepyx/core/query.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime as dt
from functools import cached_property
import pprint
from typing import Optional, Union, cast

Expand Down Expand Up @@ -734,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 @@ -751,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 @@ -947,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 @@ -1043,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 @@ -1056,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 @@ -1066,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 @@ -1129,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 2e7ac19

Please sign in to comment.