diff --git a/modules/aeolus/aeolus_amv.py b/modules/aeolus/aeolus_amv.py index 311e149a13fc1070681ae86c2216e60ee40b994c..f948bb3cfbb9d2ea37bff6e29c794320148de4b2 100644 --- a/modules/aeolus/aeolus_amv.py +++ b/modules/aeolus/aeolus_amv.py @@ -6,6 +6,7 @@ import xarray as xr from netCDF4 import Dataset, Dimension, Variable from aeolus.geos_nav import GEOSNavigation from util.util import haversine_np +import math amv_file_duration = 60 # minutes @@ -263,8 +264,8 @@ def get_aeolus_time_dict_s(files_path, lon360=False, do_sort=True, chan='mie'): dct_s = [] for fname in sorted_filenames: a_dct = get_aeolus_time_dict(fname, lon360=lon360, do_sort=do_sort) - t_dct = time_dict_to_nd(a_dct) - dct_s.append(t_dct) + # t_dct = time_dict_to_nd(a_dct) + dct_s.append(a_dct) t_dct = dct_s[0] @@ -274,6 +275,61 @@ def get_aeolus_time_dict_s(files_path, lon360=False, do_sort=True, chan='mie'): return t_dct +def time_dict_to_cld_layers(time_dict): + time_dict_layers = {} + + keys = list(time_dict.keys()) + for key in keys: + prof_s = time_dict[key] + layers = [] + prof = prof_s[0] + + if len(prof) == 1: + tup = prof[0] + layers.append((tup[0], tup[1], tup[3], tup[4])) + time_dict_layers[key] = layers + continue + + top = -9999.9 + last_bot = -9999.9 + tup = None + for i in range(len(prof)): + tup = prof[i] + + if i == 0: + top = tup[3] + bot = tup[4] + last_bot = bot + else: + if math.fabs(last_bot - tup[3]) > 10.0: + layers.append((tup[0], tup[1], top, last_bot)) + top = tup[3] + last_bot = tup[4] + + layers.append((tup[0], tup[1], top, tup[4])) + + time_dict_layers[key] = layers + + return time_dict_layers + + +def time_dict_to_nd_2(time_dict): + keys = list(time_dict.keys()) + for key in keys: + vals = time_dict[key] + if vals is not None: + time_dict[key] = np.stack(vals) + + return time_dict + + +def get_cloud_layers_dict(filename, lon360=False): + a_d = get_aeolus_time_dict(filename, lon360=lon360) + c_d = time_dict_to_cld_layers(a_d) + cld_lyr_dct = time_dict_to_nd_2(c_d) + return cld_lyr_dct + + def run_amv_aeolus_best_fit(match_dict, aeolus_dict): keys = list(match_dict.keys())