Skip to content

Commit

Permalink
add ability to keep going if one of query_all or download_all fails i…
Browse files Browse the repository at this point in the history
…n quest
  • Loading branch information
JessicaS11 committed Oct 6, 2023
1 parent a96a16f commit 7d73e80
Showing 1 changed file with 42 additions and 62 deletions.
104 changes: 42 additions & 62 deletions icepyx/quest/quest.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def add_icesat2(
# ----------------------------------------------------------------------
# Methods (on all datasets)

# error handling? what happens when one of i fails...
# error handling? what happens when the user tries to re-query?
def search_all(self, **kwargs):
"""
Searches for requred dataset within platform (i.e. ICESat-2, Argo) of interest.
Expand All @@ -152,23 +152,27 @@ def search_all(self, **kwargs):
"""
print("\nSearching all datasets...")

for k, v in self.datasets.items():
print()
if isinstance(v, Query):
print("---ICESat-2---")
try:
msg = v.avail_granules(kwargs[k])
except KeyError:
msg = v.avail_granules()
print(msg)
else:
print(k)
try:
v.search_data(kwargs[k])
except KeyError:
v.search_data()

# error handling? what happens when one of i fails...
try:
for k, v in self.datasets.items():
print()
if isinstance(v, Query):
print("---ICESat-2---")
try:
msg = v.avail_granules(kwargs[k])
except KeyError:
msg = v.avail_granules()
print(msg)
else:
print(k)
try:
v.search_data(kwargs[k])
except KeyError:
v.search_data()
except:
dataset_name = type(v).__name__
print("Error querying data from {0}".format(dataset_name))

# error handling? what happens if the user tries to re-download?
def download_all(self, path="", **kwargs):
"""
Downloads requested dataset(s).
Expand All @@ -184,47 +188,23 @@ def download_all(self, path="", **kwargs):
"""
print("\nDownloading all datasets...")

for k, v in self.datasets.items():
print()
if isinstance(v, Query):
print("---ICESat-2---")
try:
msg = v.download_granules(path, kwargs[k])
except KeyError:
msg = v.download_granules(path)
print(msg)
else:
print(k)
try:
msg = v.download(kwargs[k])
except KeyError:
msg = v.download()
print(msg)

# DEVNOTE: see colocated data branch and phyto team files for code that expands quest functionality


# Todo: remove this later -- just here for debugging
if __name__ == "__main__":
bounding_box = [-150, 30, -120, 60]
date_range = ["2022-06-07", "2022-06-14"]
my_quest = Quest(spatial_extent=bounding_box, date_range=date_range)
# print(my_quest.spatial)
# print(my_quest.temporal)

# my_quest.add_argo(params=["down_irradiance412", "temperature"])
# print(my_quest.datasets["argo"].params)

my_quest.add_icesat2(product="ATL06")
my_quest.datasets["argo"] = "fake argo object"
# print(my_quest.datasets["icesat2"].product)
print(my_quest.datasets)

print(my_quest)

# make sure to add some test cases for passing in kwargs...
my_quest.search_all()
# my_quest.search_all(icesat2={"IDs":True})

# this one still needs work for IS2 because of auth...
my_quest.download_all()
try:
for k, v in self.datasets.items():
print()
if isinstance(v, Query):
print("---ICESat-2---")
try:
msg = v.download_granules(path, kwargs[k])
except KeyError:
msg = v.download_granules(path)
print(msg)
else:
print(k)
try:
msg = v.download(kwargs[k])
except KeyError:
msg = v.download()
print(msg)
except:
dataset_name = type(v).__name__
print("Error downloading data from {0}".format(dataset_name))

0 comments on commit 7d73e80

Please sign in to comment.