diff --git a/modules/icing/pirep_goes.py b/modules/icing/pirep_goes.py index f94b1778f6f317413092345f41f35ab1b3ba977c..82245672a3cdef992df756ed21d0192de5589f0f 100644 --- a/modules/icing/pirep_goes.py +++ b/modules/icing/pirep_goes.py @@ -612,13 +612,12 @@ def analyze(ice_dct, no_ice_dct): lon_space_hdeg = np.linspace(-180, 180, 721) lat_space_hdeg = np.linspace(-90, 90, 361) -# grd_bins = np.full((lat_space.shape[0], lon_space.shape[0]), t_delta) def check_no_overlap(lon, lat, ts, grd_bins, t_delta=600.0): - grd_x_hi = lon_space.shape[0] - 1 - grd_y_hi = lat_space.shape[0] - 1 + grd_x_hi = lon_space_hdeg.shape[0] - 1 + grd_y_hi = lat_space_hdeg.shape[0] - 1 lon_idx = np.searchsorted(lon_space_hdeg, lon) lat_idx = np.searchsorted(lat_space_hdeg, lat) @@ -719,7 +718,7 @@ def process(ice_dct, no_ice_dct, neg_ice_dct): ridxs = np.random.permutation(np.arange(ice_keys_2.shape[0])) ice_keys_2 = ice_keys_2[ridxs] ice_tidx_2 = ice_tidx_2[ridxs] - num = int(ice_keys_2.shape[0] * 0.7) + num = int(ice_keys_2.shape[0] * 0.9) ice_keys_2 = ice_keys_2[0:num] ice_tidx_2 = ice_tidx_2[0:num] print('2: reduced: ', ice_tidx_2.shape) @@ -732,28 +731,29 @@ def process(ice_dct, no_ice_dct, neg_ice_dct): ice_keys = np.concatenate([ice_keys_1, ice_keys_2, ice_keys_3, ice_keys_4, ice_keys_5_6]) ice_tidx = np.concatenate([ice_tidx_1, ice_tidx_2, ice_tidx_3, ice_tidx_4, ice_tidx_5_6]) print('icing total reduced: ', ice_tidx.shape) + print('----------------------------') sidxs = np.argsort(ice_keys) ice_keys = ice_keys[sidxs] ice_tidx = ice_tidx[sidxs] - grd_bins = np.full((lat_space_hdeg.shape[0], lon_space_hdeg.shape[0]), -(t_delta+1)) - cnt = 0 - for idx, key in enumerate(ice_keys): - rpts = ice_dct[key] - - tup = rpts[ice_tidx[idx]] - lat, lon = tup[0], tup[1] - if not check_no_overlap(lon, lat, key, grd_bins, t_delta=t_delta): - continue - cnt += 1 - - n_rpts = new_ice_dct.get(key) - if n_rpts is None: - n_rpts = [] - new_ice_dct[key] = n_rpts - n_rpts.append(tup) - print('icing total no overlap: ', cnt) + # grd_bins = np.full((lat_space_hdeg.shape[0], lon_space_hdeg.shape[0]), -(t_delta+1)) + # cnt = 0 + # for idx, key in enumerate(ice_keys): + # rpts = ice_dct[key] + # + # tup = rpts[ice_tidx[idx]] + # lat, lon = tup[0], tup[1] + # if not check_no_overlap(lon, lat, key, grd_bins, t_delta=t_delta): + # continue + # cnt += 1 + # + # n_rpts = new_ice_dct.get(key) + # if n_rpts is None: + # n_rpts = [] + # new_ice_dct[key] = n_rpts + # n_rpts.append(tup) + # print('icing total no overlap: ', cnt) # ----------------------------------------------------- no_ice_keys = np.array(no_ice_keys) @@ -763,44 +763,77 @@ def process(ice_dct, no_ice_dct, neg_ice_dct): ridxs = np.random.permutation(np.arange(no_ice_keys.shape[0])) no_ice_keys = no_ice_keys[ridxs] no_ice_tidx = no_ice_tidx[ridxs] - no_ice_keys = no_ice_keys[::5] - no_ice_tidx = no_ice_tidx[::5] + no_ice_keys = no_ice_keys[::4] + no_ice_tidx = no_ice_tidx[::4] print('no ice reduced: ', no_ice_keys.shape[0]) + print('---------------------------------') sidxs = np.argsort(no_ice_keys) no_ice_keys = no_ice_keys[sidxs] no_ice_tidx = no_ice_tidx[sidxs] + # grd_bins = np.full((lat_space_hdeg.shape[0], lon_space_hdeg.shape[0]), -(t_delta+1)) + # cnt = 0 + # for idx, key in enumerate(no_ice_keys): + # rpts = no_ice_dct[key] + # tup = rpts[no_ice_tidx[idx]] + # + # lat, lon = tup[0], tup[1] + # if not check_no_overlap(lon, lat, key, grd_bins, t_delta=t_delta): + # continue + # cnt += 1 + # + # n_rpts = new_no_ice_dct.get(key) + # if n_rpts is None: + # n_rpts = [] + # new_no_ice_dct[key] = n_rpts + # n_rpts.append(tup) + # print('no icing total no overlap: ', cnt) + # ------------------------------------------------- + + all_which = np.concatenate([np.full(len(ice_keys), 1), np.full(len(no_ice_keys), 0)]) + all_keys = np.concatenate([ice_keys, no_ice_keys]) + all_tidx = np.concatenate([ice_tidx, no_ice_tidx]) + sidxs = np.argsort(all_keys) + all_keys = all_keys[sidxs] + all_tidx = all_tidx[sidxs] + all_which = all_which[sidxs] + grd_bins = np.full((lat_space_hdeg.shape[0], lon_space_hdeg.shape[0]), -(t_delta+1)) - cnt = 0 - for idx, key in enumerate(no_ice_keys): - rpts = no_ice_dct[key] - tup = rpts[no_ice_tidx[idx]] + cnt_i = 0 + cnt_ni = 0 + for idx, key in enumerate(all_keys): + i_ni = all_which[idx] + + if i_ni == 0: + rpts = no_ice_dct[key] + tup = rpts[all_tidx[idx]] + elif i_ni == 1: + rpts = ice_dct[key] + tup = rpts[all_tidx[idx]] lat, lon = tup[0], tup[1] + if not check_no_overlap(lon, lat, key, grd_bins, t_delta=t_delta): continue - cnt += 1 - n_rpts = new_no_ice_dct.get(key) - if n_rpts is None: - n_rpts = [] - new_no_ice_dct[key] = n_rpts - n_rpts.append(tup) - print('no icing total no overlap: ', cnt) - # ------------------------------------------------- - - # Previous for neg icing - # neg_ice_keys = np.array(neg_ice_keys) - # print('neg ice total: ', neg_ice_keys.shape[0]) - # np.random.seed(42) - # np.random.shuffle(neg_ice_keys) - # neg_ice_keys = neg_ice_keys[0:12000] - # uniq_sorted_neg_ice = np.unique(neg_ice_keys) - # print('neg ice reduced: ', uniq_sorted_neg_ice.shape) - # - # for key in uniq_sorted_neg_ice: - # new_neg_ice_dct[key] = neg_ice_dct[key] + if i_ni == 0: + cnt_ni += 1 + n_rpts = new_no_ice_dct.get(key) + if n_rpts is None: + n_rpts = [] + new_no_ice_dct[key] = n_rpts + n_rpts.append(tup) + elif i_ni == 1: + cnt_i += 1 + n_rpts = new_ice_dct.get(key) + if n_rpts is None: + n_rpts = [] + new_ice_dct[key] = n_rpts + n_rpts.append(tup) + + print('no overlap ICE: ', cnt_i) + print('no overlap NO ICE: ', cnt_ni) # ----------------------------------------------------- neg_ice_keys = np.array(neg_ice_keys)