Skip to content

Commit 2e7ac19

Browse files
committed
Refactor Query.granules property to cached_property
1 parent a89d069 commit 2e7ac19

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

icepyx/core/query.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import datetime as dt
2+
from functools import cached_property
13
import pprint
24
from typing import Optional, Union, cast
35

@@ -734,10 +736,11 @@ def order_vars(self) -> Variables:
734736

735737
return self._order_vars
736738

737-
@property
739+
@cached_property
738740
def granules(self) -> Granules:
739741
"""
740-
Return the granules object, which provides the underlying functionality for searching, ordering,
742+
Return the granules object, which provides the underlying functionality
743+
hing, ordering,
741744
and downloading granules for the specified product.
742745
Users are encouraged to use the built-in wrappers
743746
rather than trying to access the granules object themselves.
@@ -751,15 +754,13 @@ def granules(self) -> Granules:
751754
752755
Examples
753756
--------
754-
>>> reg_a = ipx.Query('ATL06',[-55, 68, -48, 71],['2019-02-20','2019-02-28']) # doctest: +SKIP
757+
>>> reg_a = ipx.Query('ATL06',[-55, 68, -48,
758+
71],['2019-02-20','2019-02-28']) #
759+
+SKIP
755760
>>> reg_a.granules # doctest: +SKIP
756761
<icepyx.core.granules.Granules at [location]>
757762
"""
758-
759-
if not hasattr(self, "_granules") or self._granules is None:
760-
self._granules = Granules()
761-
762-
return self._granules
763+
return Granules()
763764

764765
# ----------------------------------------------------------------------
765766
# Methods - Get and display neatly information at the product level
@@ -947,8 +948,6 @@ def avail_granules(
947948
"""
948949

949950
# REFACTOR: add test to make sure there's a session
950-
if not hasattr(self, "_granules"):
951-
self.granules
952951
try:
953952
self.granules.avail
954953
except AttributeError:
@@ -1043,8 +1042,6 @@ def order_granules(
10431042

10441043
# REFACTOR: add checks here to see if the granules object has been created,
10451044
# and also if it already has a list of avail granules (if not, need to create one and add session)
1046-
if not hasattr(self, "_granules"):
1047-
self.granules
10481045

10491046
# Place multiple orders, one per granule, if readable_granule_name is used.
10501047
if "readable_granule_name[]" in self.CMRparams:
@@ -1056,7 +1053,7 @@ def order_granules(
10561053
)
10571054
for gran in gran_name_list:
10581055
tempCMRparams["readable_granule_name[]"] = gran
1059-
self._granules.place_order(
1056+
self.granules.place_order(
10601057
tempCMRparams,
10611058
cast(EGIRequiredParamsDownload, self.reqparams),
10621059
self.subsetparams(**kwargs),
@@ -1066,7 +1063,7 @@ def order_granules(
10661063
)
10671064

10681065
else:
1069-
self._granules.place_order(
1066+
self.granules.place_order(
10701067
self.CMRparams,
10711068
cast(EGIRequiredParamsDownload, self.reqparams),
10721069
self.subsetparams(**kwargs),
@@ -1129,19 +1126,16 @@ def download_granules(
11291126
# os.mkdir(path)
11301127
# os.chdir(path)
11311128

1132-
if not hasattr(self, "_granules"):
1133-
self.granules
1134-
11351129
if restart is True:
11361130
pass
11371131
else:
11381132
if (
1139-
not hasattr(self._granules, "orderIDs")
1140-
or len(self._granules.orderIDs) == 0
1133+
not hasattr(self.granules, "orderIDs")
1134+
or len(self.granules.orderIDs) == 0
11411135
):
11421136
self.order_granules(verbose=verbose, subset=subset, **kwargs)
11431137

1144-
self._granules.download(verbose, path, restart=restart)
1138+
self.granules.download(verbose, path, restart=restart)
11451139

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

0 commit comments

Comments
 (0)