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-
43from .ecco_download import ecco_podaac_query
54from .ecco_download import ecco_podaac_download
65from .ecco_download import ecco_podaac_download_diskaware
1514
1615from .ecco_acc_dates import date_adjustment
1716
17+ from .ecco_varlist import ecco_podaac_varlist_query
18+
19+
20+ import requests
21+
1822
1923def 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.,
0 commit comments