Skip to content

Commit 98b5de3

Browse files
committed
Updated ecco_access to accept text searches of ECCO variable lists, and non-ECCO ShortNames
1 parent ae33a21 commit 98b5de3

5 files changed

Lines changed: 311 additions & 16 deletions

File tree

ecco_access/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717

1818
from .ecco_acc_dates import date_adjustment
1919

20+
from .ecco_varlist import ecco_podaac_varlist_query
21+
22+
2023

2124
__all__ = ['ecco_access',
2225
'ecco_download',
2326
'ecco_s3_retrieve',
24-
'ecco_acc_dates']
27+
'ecco_acc_dates',
28+
'ecco_varlist']

ecco_access/ecco_access.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
### This function allows users to query ECCO variables and datasets, and then gain access via direct download, or opening files remotely on S3
22

3-
43
from .ecco_download import ecco_podaac_query
54
from .ecco_download import ecco_podaac_download
65
from .ecco_download import ecco_podaac_download_diskaware
@@ -15,6 +14,11 @@
1514

1615
from .ecco_acc_dates import date_adjustment
1716

17+
from .ecco_varlist import ecco_podaac_varlist_query
18+
19+
20+
import requests
21+
1822

1923
def ecco_podaac_access(query,version='v4r4',grid=None,time_res='all',\
2024
StartDate=None,EndDate=None,snapshot_interval=None,\
@@ -29,9 +33,9 @@ def ecco_podaac_access(query,version='v4r4',grid=None,time_res='all',\
2933
Parameters
3034
----------
3135
query: str, list, or dict, defines datasets or variables to access.
32-
If query is str, it specifies either a dataset ShortName (which is
33-
assumed if the string begins with 'ECCO_'), or a text string that
34-
can be used to search the ShortNames, variable names, and descriptions.
36+
If query is str, it specifies either a dataset ShortName (if query
37+
matches a NASA Earthdata ShortName), or a text string that can be
38+
used to search the ECCO ShortNames, variable names, and descriptions.
3539
A query may also be a list of multiple ShortNames and/or text searches,
3640
or a dict that contains grid,time_res specifiers as keys and ShortNames
3741
or text searches as values, e.g.,
@@ -44,8 +48,8 @@ def ecco_podaac_access(query,version='v4r4',grid=None,time_res='all',\
4448
4549
grid: ('native','latlon',None), specifies whether to query datasets with output
4650
on the native grid or the interpolated lat/lon grid.
47-
The default None will query both types of grids, unless specified
48-
otherwise in a query dict (e.g., the example above).
51+
The default None will query both types of grids (and datasets with no spatial
52+
dimension), unless specified otherwise in a query dict (e.g., the example above).
4953
5054
time_res: ('monthly','daily','snapshot','all'), specifies which time resolution
5155
to include in query and downloads. 'all' includes all time resolutions,
@@ -143,10 +147,15 @@ def ecco_podaac_access(query,version='v4r4',grid=None,time_res='all',\
143147
def shortnames_find(query_list,grid,time_res):
144148
shortnames_list = []
145149
for query_item in query_list:
146-
if 'ECCO_' in query_item:
150+
# see if the query is an existing NASA Earthdata ShortName
151+
# if not, then do a text search of the ECCO variable lists
152+
response = requests.get(url="https://cmr.earthdata.nasa.gov/search/collections.json",
153+
params={'ShortName':query_item})
154+
if len(response.json()['feed']['entry']) > 0:
147155
shortnames_list.append(query_item)
148156
else:
149-
print('query is not a ShortName')
157+
shortname_match = ecco_podaac_varlist_query(query_item,version,grid,time_res)
158+
shortnames_list.append(shortname_match)
150159

151160
return shortnames_list
152161

@@ -156,6 +165,11 @@ def shortnames_find(query_list,grid,time_res):
156165
if isinstance(query,dict):
157166
shortnames = []
158167
for gridtime_spec,curr_query in query.items():
168+
try:
169+
curr_grid,curr_time_res = gridtime_spec.split(',')
170+
except:
171+
raise ValueError("Keys of dict 'query' must be of the form grid,time_res\n'\
172+
+'with 1 comma in the middle")
159173
if isinstance(curr_query,str):
160174
curr_query = [curr_query]
161175
shortnames += shortnames_find(curr_query,\
@@ -288,9 +302,9 @@ def ecco_podaac_to_xrdataset(query,version='v4r4',grid=None,time_res='all',\
288302
Parameters
289303
----------
290304
query: str, list, or dict, defines datasets or variables to access.
291-
If query is str, it specifies either a dataset ShortName (which is
292-
assumed if the string begins with 'ECCO_'), or a text string that
293-
can be used to search the ShortNames, variable names, and descriptions.
305+
If query is str, it specifies either a dataset ShortName (if query
306+
matches a NASA Earthdata ShortName), or a text string that can be
307+
used to search the ECCO ShortNames, variable names, and descriptions.
294308
A query may also be a list of multiple ShortNames and/or text searches,
295309
or a dict that contains grid,time_res specifiers as keys and ShortNames
296310
or text searches as values, e.g.,

ecco_access/ecco_download.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ def setup_earthdata_login_auth(url: str='urs.earthdata.nasa.gov'):
8888

8989
### Helper subroutines to make the API calls to search CMR and parse response
9090
def set_params(params: dict):
91-
params.update({'scroll': "true", 'page_size': 2000})
91+
# params.update({'scroll': "true", 'page_size': 2000})
92+
params.update({'page_size': 2000})
9293
return {par: val for par, val in params.items() if val is not None}
9394

9495
def get_results(params: dict, headers: dict=None):
@@ -100,13 +101,14 @@ def get_results(params: dict, headers: dict=None):
100101

101102
def get_granules(params: dict):
102103
response, headers = get_results(params=params)
103-
scroll = headers['CMR-Scroll-Id']
104+
# scroll = headers['CMR-Scroll-Id']
104105
hits = int(headers['CMR-Hits'])
105106
if hits==0:
106107
raise Exception("No granules matched your input parameters.")
107108
df = pd.read_csv(StringIO(response.text))
108109
while hits > df.index.size:
109-
response, _ = get_results(params=params, headers={'CMR-Scroll-Id': scroll})
110+
# response, _ = get_results(params=params, headers={'CMR-Scroll-Id': scroll})
111+
response, _ = get_results(params=params)
110112
data = pd.read_csv(StringIO(response.text))
111113
df = pd.concat([df, data])
112114
return df

ecco_access/ecco_s3_retrieve.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ def ecco_podaac_s3_query(ShortName,StartDate,EndDate,snapshot_interval='monthly'
9191

9292
### Helper subroutines to make the API calls to search CMR and parse response
9393
def set_params(params: dict):
94-
params.update({'scroll': "true", 'page_size': 2000})
94+
# params.update({'scroll': "true", 'page_size': 2000})
95+
params.update({'page_size': 2000})
9596
return {par: val for par, val in params.items() if val is not None}
9697

9798
def get_results(params: dict, headers: dict=None):

0 commit comments

Comments
 (0)