From c2a4f147faa60467f56bd2308645baf8be56c256 Mon Sep 17 00:00:00 2001 From: tomrink <rink@ssec.wisc.edu> Date: Sun, 2 Jan 2022 09:35:12 -0600 Subject: [PATCH] snapshot... --- modules/icing/pirep_goes.py | 112 ++++++++++++++++++++++++++---------- 1 file changed, 82 insertions(+), 30 deletions(-) diff --git a/modules/icing/pirep_goes.py b/modules/icing/pirep_goes.py index 7efbb790..83018033 100644 --- a/modules/icing/pirep_goes.py +++ b/modules/icing/pirep_goes.py @@ -4,8 +4,8 @@ import pickle import matplotlib.pyplot as plt import os from util.util import get_time_tuple_utc, GenericException, add_time_range_to_filename, is_night, is_day, \ - check_oblique, make_times, find_bin_index, get_timestamp, homedir, write_icing_file, make_for_full_domain_predict, \ - make_for_full_domain_predict2 + check_oblique, get_timestamp, homedir, write_icing_file, make_for_full_domain_predict, \ + make_for_full_domain_predict2, get_indexes_within_threshold from util.plot import make_icing_image from util.geos_nav import get_navigation, get_lon_lat_2d_mesh from util.setup import model_path_day, model_path_night @@ -1627,8 +1627,8 @@ def normalize(data, param, mean_std_dict, add_noise=False, noise_scale=1.0, seed return data -lon_space = np.linspace(-180, 180, 361) -lat_space = np.linspace(-90, 90, 181) +lon_space = np.linspace(-180, 180, 721) +lat_space = np.linspace(-90, 90, 361) def spatial_filter(icing_dict): @@ -1637,6 +1637,7 @@ def spatial_filter(icing_dict): grd_y_hi = lat_space.shape[0] - 1 grd_bins = np.full((lat_space.shape[0], lon_space.shape[0]), 0) + grd_bins_keys = [[[] for i in range(lon_space.shape[0])] for j in range(lat_space.shape[0])] for key in keys: rpts = icing_dict.get(key) @@ -1653,33 +1654,84 @@ def spatial_filter(icing_dict): continue grd_bins[lat_idx, lon_idx] += 1 + grd_bins_keys[lat_idx][lon_idx].append(key) - return grd_bins - - -# def spatial_filter2(icing_dict): -# keys = icing_dict.keys() -# grd_x_hi = lon_space.shape[0] - 1 -# grd_y_hi = lat_space.shape[0] - 1 -# -# grd_bins = np.full((lat_space.shape[0], lon_space.shape[0]), 0) -# -# for key in keys: -# tup = icing_dict.get(key) -# lat = tup[0] -# lon = tup[1] -# -# lon_idx = np.searchsorted(lon_space, lon) -# lat_idx = np.searchsorted(lat_space, lat) -# -# if lon_idx < 0 or lon_idx > grd_x_hi: -# continue -# if lat_idx < 0 or lat_idx > grd_y_hi: -# continue -# -# grd_bins[lat_idx, lon_idx] += 1 -# -# return grd_bins + return grd_bins, grd_bins_keys + + +def spatial_filter2(icing_dict): + keys = icing_dict.keys() + grd_x_hi = lon_space.shape[0] - 1 + grd_y_hi = lat_space.shape[0] - 1 + + grd_bins = np.full((lat_space.shape[0], lon_space.shape[0]), 0) + grd_bins_keys = [[[] for i in range(lon_space.shape[0])] for j in range(lat_space.shape[0])] + + for key in keys: + tup = icing_dict.get(key) + lat = tup[0] + lon = tup[1] + + lon_idx = np.searchsorted(lon_space, lon) + lat_idx = np.searchsorted(lat_space, lat) + + if lon_idx < 0 or lon_idx > grd_x_hi: + continue + if lat_idx < 0 or lat_idx > grd_y_hi: + continue + + grd_bins[lat_idx, lon_idx] += 1 + grd_bins_keys[lat_idx][lon_idx].append(key) + + return grd_bins, grd_bins_keys + + +def process_boeing(boeing_dct, pirep_dct, threshold=3000): + + boeing_times = list(boeing_dct.keys()) + pirep_times = np.array(list(pirep_dct.keys())) + + pt_s = [] + bt_s = [] + bi_s = [] + for k, bt in enumerate(boeing_times): + idx_s, v_s = get_indexes_within_threshold(pirep_times, bt, threshold=threshold) + if len(idx_s) > 0: + bt_s.append(bt) + bi_s.append(k) + pt_s.append(v_s[0]) + + boeing_times = np.array(boeing_times) + + sub_pirep_dct = {} + sub_boeing_dct = {} + for key in pt_s: + sub_pirep_dct[key] = pirep_dct.get(key) + for key in bt_s: + sub_boeing_dct[key] = boeing_dct.get(key) + + grd_bins, _ = spatial_filter(sub_pirep_dct) + grd_bins_boeing, key_bins = spatial_filter2(sub_boeing_dct) + + grd_bins = np.where(grd_bins > 0, 1, grd_bins) + grd_bins_boeing = np.where(grd_bins_boeing > 0, 1, grd_bins_boeing) + + ovrlp_grd_bins = grd_bins + grd_bins_boeing + print(np.sum(ovrlp_grd_bins == 2)) + + ovlp_keys = [] + for j in range(lat_space.shape[0]): + for i in range(lon_space.shape[0]): + if ovrlp_grd_bins[j, i] == 2: + keys = key_bins[j][i] + nkeys = len(keys) + for k in range(nkeys): + ovlp_keys.append(keys[k]) + set_a = set(ovlp_keys) + set_b = set(boeing_times) + print(len(set_a), len(set_b)) + set_b.difference_update(set_a) + print(len(set_b)) # dt_str_0: start datetime string in format YYYY-MM-DD_HH:MM (default) -- GitLab