Skip to content
Snippets Groups Projects
Commit 407b6572 authored by tomrink's avatar tomrink
Browse files

improve get_bounding_goes16_files

parent e41a6d34
No related branches found
No related tags found
No related merge requests found
......@@ -451,10 +451,8 @@ def get_time_tuple_utc(timestamp):
return dt_obj, dt_obj.timetuple()
def get_bounding_goes16_files(timestamp, ch_str):
def get_bounding_goes16_files(timestamp, ch_str, file_time_span=5):
dt_obj, time_tup = get_time_tuple_utc(timestamp)
# yr_dir = str(time_tup.tm_year)
# date_dir = dt_obj.strftime('%Y_%m_%d_%j')
dt_obj_0 = dt_obj - datetime.timedelta(minutes=20)
dt_obj_1 = dt_obj + datetime.timedelta(minutes=20)
......@@ -471,15 +469,11 @@ def get_bounding_goes16_files(timestamp, ch_str):
files_path_1 = goes16_directory + '/' + yr_dir_1 + '/' + date_dir_1 + '/abi' + '/L1b' + '/RadC'
flist_0 = glob.glob(files_path_0 + '/OR_ABI-L1b-RadC-??C' + ch_str + '_G16_s' + date_str_0 + '*.nc')
flist_1 = None
flist_1 = []
if date_str_0 != date_str_1:
flist_1 = glob.glob(files_path_1 + '/OR_ABI-L1b-RadC-??C' + ch_str + '_G16_s' + date_str_1 + '*.nc')
flist = []
if flist_0 is not None:
flist = flist + flist_0
if flist_1 is not None:
flist = flist + flist_1
flist = flist_0 + flist_1
if len(flist) == 0:
return None, None, None, None, None, None
......@@ -499,22 +493,25 @@ def get_bounding_goes16_files(timestamp, ch_str):
farr = farr[sidxs]
ftimes = tarr[sidxs]
tR = ftimes[ftimes >= timestamp].min()
tL = ftimes[ftimes <= timestamp].max()
ftimes_n = ftimes + (dt_obj + datetime.timedelta(minutes=file_time_span)).timestamp()
iC = -1
for k, t in enumerate(ftimes):
if t <= timestamp < ftimes_n[k]:
iC = k
break
iL = np.searchsorted(ftimes, tL, 'left')
iR = iL + 1
iC = iL
tL = ftimes[ftimes <= dt_obj_0.timestamp()].max()
tR = ftimes[ftimes >= dt_obj_1.timestamp()].min()
iL = np.searchsorted(ftimes, tL, 'left')
iR = np.searchsorted(ftimes, tR, 'left')
if iC >= 0:
iL = iC - 1
iR = iC + 1
else:
return None, None, None, None, None, None
fList = farr.tolist()
return fList[iL], ftimes[iL], fList[iC], ftimes[iC], fList[iR], ftimes[iR]
if iL < 0 or iR >= len(ftimes):
return None, None, fList[iC], ftimes[iC], None, None
else:
return fList[iL], ftimes[iL], fList[iC], ftimes[iC], fList[iR], ftimes[iR]
def get_bounding_gfs_files(timestamp):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment