@@ -86,18 +86,26 @@ def get_results(params: dict, headers: dict=None):
8686 headers = headers ).json ()
8787 return response
8888
89- def get_granules (params : dict ):
89+ def get_granules (params : dict , ShortName : str , SingleDay_flag : bool ):
9090 response = get_results (params = params )
9191 if 'feed' in response .keys ():
92+ time_start = np .array ([]).astype ('datetime64[ns]' )
9293 s3_files_list = []
9394 for curr_entry in response ['feed' ]['entry' ]:
95+ time_start = np .append (time_start ,np .datetime64 (curr_entry ['time_start' ],'ns' ))
9496 for curr_link in curr_entry ['links' ]:
9597 if "direct download access via S3" in curr_link ['title' ]:
9698 s3_files_list .append (curr_link ['href' ])
9799 break
98100 elif 'errors' in response .keys ():
99101 raise Exception (response ['errors' ][0 ])
100102
103+ # reduce granule list to single day if only one day in requested range
104+ if (('MONTHLY' in ShortName ) or ('DAILY' in ShortName )):
105+ if ((SingleDay_flag == True ) and (len (s3_files_list ) > 1 )):
106+ day_index = np .argmin (np .abs (time_start - np .datetime64 (StartDate ,'D' )))
107+ s3_files_list = s3_files_list [day_index :(day_index + 1 )]
108+
101109 return s3_files_list
102110
103111
@@ -130,12 +138,12 @@ def get_granules(params: dict):
130138 + 'Program will exit now !\n ' )
131139
132140
133- # for monthly and daily datasets, do not include the month or day before
141+ SingleDay_flag = False
134142 if (('MONTHLY' in ShortName ) or ('DAILY' in ShortName )):
135143 if np .datetime64 (EndDate ,'D' ) - np .datetime64 (StartDate ,'D' ) \
136144 > np .timedelta64 (1 ,'D' ):
145+ # for monthly and daily datasets, do not include the month or day before
137146 StartDate = str (np .datetime64 (StartDate ,'D' ) + np .timedelta64 (1 ,'D' ))
138- SingleDay_flag = False
139147 else :
140148 # for single day ranges we need to make the adjustment
141149 # after the CMR request
@@ -162,8 +170,9 @@ def get_granules(params: dict):
162170 ### Query CMR for the desired ECCO Dataset
163171
164172 # grans means 'granules', PO.DAAC's term for individual files in a dataset
165- s3_files_list = get_granules (input_search_params )
166-
173+ s3_files_list = get_granules (input_search_params ,ShortName ,SingleDay_flag )
174+
175+
167176 return s3_files_list
168177
169178
0 commit comments