-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_retriever.py
56 lines (40 loc) · 1.61 KB
/
data_retriever.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import podaac.podaac as podaac
import podaac.podaac_utils as p_utils
import podaac.drive as pd
import os
# Uses NASA's PODAAC drive API to search and download dataset granules into specified local folder
def granule_Download(data_id):
p = podaac.Podaac()
u = p_utils.PodaacUtils()
# Authentication of podaac drive access, if you have installed Podaac API, navigate to its folder and
# specify your log in credentials in podaac.ini file.
drive = pd.Drive(username = "", password="", file="podaac.ini", webdav_url="https://podaac-tools.jpl.nasa.gov/drive/files")
# data_var = p.dataset_variables(dataset_id = data_id)
try:
if data_id == "PODAAC-TELND-3AJ63":
granule = p.granule_search(dataset_id = data_id)
print(granule)
else:
granule = p.granule_search(dataset_id = data_id)
print("Dataset with id: {} found".format(data_id))
except:
print("Dataset with id: {} not found".format(data_id))
all_results = drive.mine_drive_urls_from_granule_search(granule_search_response = granule)
results = []
local_path = os.getcwd()
# print(results)
# Include only nc files in results list
for url in all_results:
if (url.split(".")[-1] == "nc"):
results.append(url)
# print(url)
# drive.download_granules(results, path= local_path)
if __name__ == "__main__":
grace_data_id = "PODAAC-TELND-3AJ63"
grace_fo_data_id = "PODAAC-GFLND-3AJ63"
granule_Download(grace_data_id)
# granule_Download(grace_fo_data_id)
# # GRACE
# data_var = p.dataset_variables(dataset_id='PODAAC-TELND-3AJ63')
# # GraceFO
# data_var = p.dataset_variables(dataset_id='PODAAC-GFLND-3AJ63')