From 2e56935c2d918ff4698b7ae69cd7d1c6a882d7d6 Mon Sep 17 00:00:00 2001 From: tomrink <rink@ssec.wisc.edu> Date: Tue, 26 Jul 2022 12:41:08 -0500 Subject: [PATCH] fix some cf issues --- modules/icing/util.py | 95 +++++++++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 31 deletions(-) diff --git a/modules/icing/util.py b/modules/icing/util.py index 5550385a..38f55ec0 100644 --- a/modules/icing/util.py +++ b/modules/icing/util.py @@ -3,7 +3,7 @@ import deeplearning.icing_fcn as icing_fcn import deeplearning.icing_cnn as icing_cnn from icing.pirep_goes import setup, time_filter_3 from icing.moon_phase import moon_phase -from util.util import get_time_tuple_utc, is_day, check_oblique, get_average, homedir, write_icing_file_nc4,\ +from util.util import get_time_tuple_utc, is_day, check_oblique, get_median, homedir, write_icing_file_nc4,\ write_icing_file_nc4_viirs,\ make_for_full_domain_predict, make_for_full_domain_predict_viirs_clavrx, prepare_evaluate from util.plot import make_icing_image @@ -130,7 +130,7 @@ def run_icing_predict(clvrx_dir='/Users/tomrink/data/clavrx/RadC/', output_dir=h for j in range(num_lines): for i in range(num_elems): k = i + j*num_elems - avg_bt.append(get_average(bt_10_4[k])) + avg_bt.append(get_median(bt_10_4[k])) if not check_oblique(satzen[k]): continue @@ -155,32 +155,65 @@ def run_icing_predict(clvrx_dir='/Users/tomrink/data/clavrx/RadC/', output_dir=h preds_2d_dct[flvl] = fd_preds probs_2d_dct[flvl] = fd_probs - if (day_night == 'AUTO' or day_night == 'DAY') and num_day_tiles > 0: - - day_data_dct = {name: [] for name in day_train_params} - for name in day_train_params: - for k in day_idxs: - day_data_dct[name].append(data_dct[name][k]) - day_grd_dct = {name: None for name in day_train_params} - for ds_name in day_train_params: - day_grd_dct[ds_name] = np.stack(day_data_dct[ds_name]) - - preds_day_dct, probs_day_dct = model_module.run_evaluate_static(day_grd_dct, num_day_tiles, day_model_path, - day_night='DAY', l1b_or_l2=l1b_andor_l2, - prob_thresh=prob_thresh, - use_flight_altitude=use_flight_altitude, - flight_levels=flight_levels) - day_idxs = np.array(day_idxs) - for flvl in flight_levels: - day_preds = preds_day_dct[flvl] - day_probs = probs_day_dct[flvl] - fd_preds = preds_2d_dct[flvl] - fd_probs = probs_2d_dct[flvl] - fd_preds[day_idxs] = day_preds[:] - fd_probs[day_idxs] = day_probs[:] - - if (day_night == 'AUTO' or day_night == 'NIGHT') and num_nght_tiles > 0: + if day_night == 'AUTO' or day_night == 'DAY': + if num_day_tiles > 0: + day_data_dct = {name: [] for name in day_train_params} + for name in day_train_params: + for k in day_idxs: + day_data_dct[name].append(data_dct[name][k]) + day_grd_dct = {name: None for name in day_train_params} + for ds_name in day_train_params: + day_grd_dct[ds_name] = np.stack(day_data_dct[ds_name]) + + preds_day_dct, probs_day_dct = model_module.run_evaluate_static(day_grd_dct, num_day_tiles, day_model_path, + day_night='DAY', l1b_or_l2=l1b_andor_l2, + prob_thresh=prob_thresh, + use_flight_altitude=use_flight_altitude, + flight_levels=flight_levels) + day_idxs = np.array(day_idxs) + for flvl in flight_levels: + day_preds = preds_day_dct[flvl] + day_probs = probs_day_dct[flvl] + fd_preds = preds_2d_dct[flvl] + fd_probs = probs_2d_dct[flvl] + fd_preds[day_idxs] = day_preds[:] + fd_probs[day_idxs] = day_probs[:] + + if num_nght_tiles > 0: + mode = 'NIGHT' + model_path = night_model_path + if use_dnb and lunar_illuminated: + model_path = day_model_path + mode = 'DAY' + nght_train_params = train_params_dnb + + nght_data_dct = {name: [] for name in nght_train_params} + for name in nght_train_params: + for k in nght_idxs: + nght_data_dct[name].append(data_dct[name][k]) + nght_grd_dct = {name: None for name in nght_train_params} + for ds_name in nght_train_params: + nght_grd_dct[ds_name] = np.stack(nght_data_dct[ds_name]) + + preds_nght_dct, probs_nght_dct = model_module.run_evaluate_static(nght_grd_dct, num_nght_tiles, + model_path, + day_night=mode, + l1b_or_l2=l1b_andor_l2, + prob_thresh=prob_thresh, + use_flight_altitude=use_flight_altitude, + flight_levels=flight_levels) + nght_idxs = np.array(nght_idxs) + for flvl in flight_levels: + nght_preds = preds_nght_dct[flvl] + nght_probs = probs_nght_dct[flvl] + fd_preds = preds_2d_dct[flvl] + fd_probs = probs_2d_dct[flvl] + fd_preds[nght_idxs] = nght_preds[:] + fd_probs[nght_idxs] = nght_probs[:] + + elif day_night == 'NIGHT': model_path = night_model_path + all_idxs = np.arange(num_lines * num_elems) mode = 'NIGHT' if use_dnb and lunar_illuminated: @@ -190,7 +223,7 @@ def run_icing_predict(clvrx_dir='/Users/tomrink/data/clavrx/RadC/', output_dir=h nght_data_dct = {name: [] for name in nght_train_params} for name in nght_train_params: - for k in nght_idxs: + for k in all_idxs: nght_data_dct[name].append(data_dct[name][k]) nght_grd_dct = {name: None for name in nght_train_params} for ds_name in nght_train_params: @@ -201,15 +234,15 @@ def run_icing_predict(clvrx_dir='/Users/tomrink/data/clavrx/RadC/', output_dir=h prob_thresh=prob_thresh, use_flight_altitude=use_flight_altitude, flight_levels=flight_levels) - nght_idxs = np.array(nght_idxs) for flvl in flight_levels: nght_preds = preds_nght_dct[flvl] nght_probs = probs_nght_dct[flvl] fd_preds = preds_2d_dct[flvl] fd_probs = probs_2d_dct[flvl] - fd_preds[nght_idxs] = nght_preds[:] - fd_probs[nght_idxs] = nght_probs[:] + fd_preds[all_idxs] = nght_preds[:] + fd_probs[all_idxs] = nght_probs[:] + # combine day and night into full grid ------------------------------------------ for flvl in flight_levels: fd_preds = preds_2d_dct[flvl] fd_probs = probs_2d_dct[flvl] -- GitLab