From 4e1ed229d28ea5059bb3d53b6a178abc72dcb0ac Mon Sep 17 00:00:00 2001 From: rink <rink@ssec.wisc.edu> Date: Mon, 12 Oct 2020 10:09:53 -0500 Subject: [PATCH] snapshot.. --- modules/aeolus/aeolus_amv.py | 92 ++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/modules/aeolus/aeolus_amv.py b/modules/aeolus/aeolus_amv.py index 8b5fb607..d3ee930c 100644 --- a/modules/aeolus/aeolus_amv.py +++ b/modules/aeolus/aeolus_amv.py @@ -24,6 +24,96 @@ class MyGenericException(Exception): self.message = message +class AMVFiles: + + def __init__(self, files_path, file_time_span, pattern, band='14'): + self.flist = glob.glob(files_path + pattern) + self.band = band + self.ftimes = [] + for pname in flist: # TODO: make better with regular expressions (someday) + dto = self.get_datetime(pname) + dto_start = dto + dto_end = dto + datetime.timedelta(minutes=file_time_span) + ftimes.append((dto_start.timestamp(), dto_end.timestamp())) + + def get_datetime(self): + pass + + def get_navigation(self): + pass + + def get_file_containing_time(self, timestamp): + k = -1 + for i in range(len(ftimes)): + if (timestamp >= ftimes[i][0]) and (timestamp < ftimes[i][1]): + k = i + break + if k < 0: + return None, None, None + + return flist[k], ftimes[k], k + + def get_parameters(self): + pass + + +class Framework(AMVFiles): + def __init__(self, files_path, file_time_span, band='14'): + super().__init__(self, files_path, file_time_span, '*WINDS_AMV_EN-' + band + '*.nc', band) + + def get_navigation(self): + GEOSNavigation(sub_lon=-75.0) + + def get_datetime(self, pathname): + fname = os.path.split(pathname)[1] + toks = fname.split('_') + dstr = toks[4] + tstr = toks[5] + dtstr = dstr + tstr + dto = datetime.datetime.strptime(dtstr, '%Y%j%H%M').replace(tzinfo=timezone.utc) + + return dto + + +class OPS(AMVFiles): + def __init__(self, files_path, file_time_span, band='14'): + super().__init__(self, files_path, file_time_span, 'OR_ABI-L2-DMWF*'+'C'+band+'*.nc', band) + + def get_navigation(self): + return GEOSNavigation(sub_lon=-75.0) + + def get_datetime(self, pathname): + fname = os.path.split(pathname)[1] + toks = fname.split('_') + dtstr = toks[3] + dtstr = dtstr[:-3] + dto = datetime.datetime.strptime(dtstr, 's%Y%j%H%M').replace(tzinfo=timezone.utc) + + return dto + + +class CarrStereo(AMVFiles): + def __init__(self, files_path, file_time_span, band='14'): + super().__init__(self, files_path, file_time_span, '*WINDS_AMV_EN-' + band + '*.nc', band) + + def get_navigation(self): + return GEOSNavigation(sub_lon=-137.0) + + def get_datetime(self, pathname): + fname = os.path.split(pathname)[1] + toks = fname.split('_') + dtstr = toks[3] + dto = datetime.datetime.strptime(dtstr, '%Y%j.%H%M.ch').replace(tzinfo=timezone.utc) + + return dto + + def get_parameters(self): + params = ['Lat', 'Lon', 'Element', 'Line', 'V_3D', 'H_3D', 'pres', 'Fcst_Spd', 'Fcst_Dir', 'SatZen', + 'InversionFlag', 'CloudPhase', 'CloudType'] + + return params + + def get_datetime(pathname): fname = os.path.split(pathname)[1] toks = fname.split('_') @@ -276,6 +366,8 @@ amv_press_name = 'MedianPress' amv_lon_name = 'Lon' amv_lat_name = 'Lat' amv_press_name = 'pres' +amv_h3d_name = 'H_3D' +amv_alt_name = 'Altitude' # ------------------------------- sub_lon = -137.0 # GOES-17 # sub_lon = -75.0 # GOES-16 -- GitLab