Skip to content

Commit

Permalink
add kwarg capabilities for download_all and a test framework for it
Browse files Browse the repository at this point in the history
  • Loading branch information
JessicaS11 committed Oct 6, 2023
1 parent dc63902 commit a96a16f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
38 changes: 29 additions & 9 deletions icepyx/quest/quest.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def search_all(self, **kwargs):
Each key must match the dataset name (e.g. "icesat2", "argo") as in quest.datasets.keys(),
and the value is a dictionary of acceptable keyword arguments
and values allowable for the `search_data()` function for that dataset.
For instance: `icesat2 = {"IDs":True}, argo = {}`.
For instance: `icesat2 = {"IDs":True}, argo = {"presRange":"10,500"}`.
"""
print("\nSearching all datasets...")

Expand All @@ -162,26 +162,44 @@ def search_all(self, **kwargs):
msg = v.avail_granules()
print(msg)
else:
print(v)
print(k)
try:
v.search_data(kwargs[k])
except KeyError:
v.search_data()

# error handling? what happens when one of i fails...
def download_all(self, path=""):
" " "Downloads requested dataset(s)." " "
def download_all(self, path="", **kwargs):
"""
Downloads requested dataset(s).
Parameters
----------
**kwargs : default None
Optional passing of keyword arguments to supply additional search constraints per datasets.
Each key must match the dataset name (e.g. "icesat2", "argo") as in quest.datasets.keys(),
and the value is a dictionary of acceptable keyword arguments
and values allowable for the `search_data()` function for that dataset.
For instance: `icesat2 = {"verbose":True}, argo = {"keep_existing":True}`.
"""
print("\nDownloading all datasets...")

for i in self.datasets.values():
for k, v in self.datasets.items():
print()
if isinstance(i, Query):
if isinstance(v, Query):
print("---ICESat-2---")
msg = i.download_granules(path)
try:
msg = v.download_granules(path, kwargs[k])
except KeyError:
msg = v.download_granules(path)
print(msg)
else:
i.download()
print(i)
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

Expand All @@ -198,7 +216,9 @@ def download_all(self, path=""):
# 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)

Expand Down
18 changes: 15 additions & 3 deletions icepyx/tests/test_quest.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ def test_search_all_kwargs(quest_instance, kwargs):
quest_instance.search_all(**kwargs)


def test_download_all():
# this will require auth in some cases...
pass
# TESTS NOT IMPLEMENTED
# def test_download_all():
# # this will require auth in some cases...
# pass

# @pytest.mark.parametrize(
# "kwargs",
# [
# {"icesat2": {"verbose":True}},
# # {"argo":{"keep_existing":True},
# # {"icesat2":{"verbose":True}, "argo":{"keep_existing":True}
# ],
# )
# def test_download_all_kwargs(quest_instance, kwargs):
# pass

0 comments on commit a96a16f

Please sign in to comment.