Skip to content
Snippets Groups Projects
Commit 83001e08 authored by tomrink's avatar tomrink
Browse files

remove duplicated code

parent 15b29953
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ import h5py ...@@ -10,6 +10,7 @@ import h5py
from netCDF4 import Dataset from netCDF4 import Dataset
from aeolus.aeolus_amv import get_aeolus_time_dict from aeolus.aeolus_amv import get_aeolus_time_dict
from aeolus.datasource import CLAVRx
from util.lon_lat_grid import earth_to_indexs from util.lon_lat_grid import earth_to_indexs
from util.geos_nav import GEOSNavigation from util.geos_nav import GEOSNavigation
from util.util import bin_data_by, get_bin_ranges from util.util import bin_data_by, get_bin_ranges
...@@ -63,77 +64,6 @@ num_elems = 5424 ...@@ -63,77 +64,6 @@ num_elems = 5424
num_lines = 5424 num_lines = 5424
def get_filelist():
filelist = []
for i in range(len(datadirs)):
dir = datadirs[i]
dirpath = os.path.join(datapath, dir)
list = glob.glob(os.path.join(dirpath, "*.nc"))
filelist = filelist + list
return filelist
def get_datetime(pathname):
fname = os.path.split(pathname)[1]
toks = fname.split('_')
dtstr = toks[4]
dtstr = dtstr[1:12]
dto = datetime.datetime.strptime(dtstr, '%Y%j%H%M').replace(tzinfo=timezone.utc)
return dto
def get_datetime_2(pathname):
fname = os.path.split(pathname)[1]
toks = fname.split('.')
dstr = toks[2]
tstr = toks[3]
dtstr = dstr+'.'+tstr
dto = datetime.datetime.strptime(dtstr, '%Y%j.%H%M').replace(tzinfo=timezone.utc)
return dto
def get_datetime_3(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
def get_file_containing_time(timestamp, files_path, dto_func, file_time_span):
global first_time, ftimes, flist
if first_time is True:
if files_path is not None:
flist = glob.glob(files_path + '*.nc')
else:
flist = get_filelist()
for pname in flist: # TODO: make better with regular expressions (someday)
dto = dto_func(pname)
dto_start = dto
dto_end = dto + datetime.timedelta(minutes=file_time_span)
ftimes.append((dto_start.timestamp(), dto_end.timestamp()))
first_time = False
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 time_dict_to_cld_layers(time_dict): def time_dict_to_cld_layers(time_dict):
time_dict_layers = {} time_dict_layers = {}
...@@ -203,11 +133,8 @@ def get_cloud_layers_dict(filename, lon360=False): ...@@ -203,11 +133,8 @@ def get_cloud_layers_dict(filename, lon360=False):
def compare_aeolus_max_height(aeolus_dict, files_path, grid_value_name='cld_height_acha', one_cld_layer_only=False, highest_layer=False): def compare_aeolus_max_height(aeolus_dict, files_path, grid_value_name='cld_height_acha', one_cld_layer_only=False, highest_layer=False):
if files_path is not None: clvrx_files = CLAVRx(files_path)
f_list = glob.glob(files_path + '*.nc') num_files = len(clvrx_files.flist)
else:
f_list = get_filelist()
num_files = len(f_list)
keys = list(aeolus_dict.keys()) keys = list(aeolus_dict.keys())
...@@ -218,7 +145,7 @@ def compare_aeolus_max_height(aeolus_dict, files_path, grid_value_name='cld_heig ...@@ -218,7 +145,7 @@ def compare_aeolus_max_height(aeolus_dict, files_path, grid_value_name='cld_heig
a_times = [[] for i in range(num_files)] a_times = [[] for i in range(num_files)]
for key in keys: for key in keys:
_, _, f_idx = get_file_containing_time(key, files_path, get_datetime, 10) _, _, f_idx = clvrx_files.get_file_containing_time(key)
if f_idx is None: if f_idx is None:
continue continue
layers = aeolus_dict.get(key) layers = aeolus_dict.get(key)
...@@ -265,7 +192,7 @@ def compare_aeolus_max_height(aeolus_dict, files_path, grid_value_name='cld_heig ...@@ -265,7 +192,7 @@ def compare_aeolus_max_height(aeolus_dict, files_path, grid_value_name='cld_heig
num_hits = 0 num_hits = 0
total = 0 total = 0
for f_idx, file in enumerate(f_list): for f_idx, file in enumerate(clvrx_files.flist):
try: try:
h5f = h5py.File(file, 'r') h5f = h5py.File(file, 'r')
except Exception: except Exception:
......
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