diff --git a/modules/deeplearning/icing_cnn.py b/modules/deeplearning/icing_cnn.py index e9cbd3a8501a2a936c2c379cb399c928c4e11d24..d4399867a2f2ebab5511d6d2f6a202e699ec5e8b 100644 --- a/modules/deeplearning/icing_cnn.py +++ b/modules/deeplearning/icing_cnn.py @@ -53,25 +53,24 @@ mean_std_dct.update(mean_std_dct_l1b) mean_std_dct.update(mean_std_dct_l2) # -- NIGHT L2 ----------------------------- -# train_params_l2 = ['cld_height_acha', 'cld_geo_thick', 'cld_temp_acha', 'cld_press_acha', 'supercooled_cloud_fraction', -# 'cld_emiss_acha', 'conv_cloud_fraction', 'cld_reff_acha', 'cld_opd_acha'] -# -- DAY L2 ------------- -train_params_l2 = ['cld_height_acha', 'cld_geo_thick', 'cld_temp_acha', 'cld_press_acha', 'supercooled_cloud_fraction', -## 'cld_emiss_acha', 'conv_cloud_fraction', 'cld_reff_dcomp', 'cld_opd_dcomp', 'cld_cwp_dcomp', 'iwc_dcomp', 'lwc_dcomp'] - 'cld_emiss_acha', 'conv_cloud_fraction', 'cld_reff_dcomp', 'cld_opd_dcomp', 'iwc_dcomp', 'lwc_dcomp'] +train_params_l2_night = ['cld_height_acha', 'cld_geo_thick', 'cld_temp_acha', 'cld_press_acha', 'supercooled_cloud_fraction', + 'cld_emiss_acha', 'conv_cloud_fraction', 'cld_reff_acha', 'cld_opd_acha'] +# -- DAY L2 -------------------------------- +train_params_l2_day = ['cld_height_acha', 'cld_geo_thick', 'cld_temp_acha', 'cld_press_acha', 'supercooled_cloud_fraction', + 'cld_emiss_acha', 'conv_cloud_fraction', 'cld_reff_dcomp', 'cld_opd_dcomp', 'iwc_dcomp', 'lwc_dcomp'] # -- DAY L1B -------------------------------- -train_params_l1b = ['temp_10_4um_nom', 'temp_11_0um_nom', 'temp_12_0um_nom', 'temp_13_3um_nom', 'temp_3_75um_nom', - 'temp_6_2um_nom', 'temp_6_7um_nom', 'temp_7_3um_nom', 'temp_8_5um_nom', 'temp_9_7um_nom', - 'refl_0_47um_nom', 'refl_0_65um_nom', 'refl_0_86um_nom', 'refl_1_38um_nom', 'refl_1_60um_nom'] +train_params_l1b_day = ['temp_10_4um_nom', 'temp_11_0um_nom', 'temp_12_0um_nom', 'temp_13_3um_nom', 'temp_3_75um_nom', + 'temp_6_2um_nom', 'temp_6_7um_nom', 'temp_7_3um_nom', 'temp_8_5um_nom', 'temp_9_7um_nom', + 'refl_0_47um_nom', 'refl_0_65um_nom', 'refl_0_86um_nom', 'refl_1_38um_nom', 'refl_1_60um_nom'] # -- NIGHT L1B ------------------------------- -# train_params_l1b = ['temp_10_4um_nom', 'temp_11_0um_nom', 'temp_12_0um_nom', 'temp_13_3um_nom', 'temp_3_75um_nom', -# 'temp_6_2um_nom', 'temp_6_7um_nom', 'temp_7_3um_nom', 'temp_8_5um_nom', 'temp_9_7um_nom'] -# -- DAY LUNAR --------------------- +train_params_l1b_night = ['temp_10_4um_nom', 'temp_11_0um_nom', 'temp_12_0um_nom', 'temp_13_3um_nom', 'temp_3_75um_nom', + 'temp_6_2um_nom', 'temp_6_7um_nom', 'temp_7_3um_nom', 'temp_8_5um_nom', 'temp_9_7um_nom'] +# -- DAY LUNAR --------------------------------- # train_params_l1b = ['cld_height_acha', 'cld_geo_thick', 'cld_temp_acha', 'cld_press_acha', 'supercooled_cloud_fraction', # 'cld_emiss_acha', 'conv_cloud_fraction', 'cld_reff_dcomp', 'cld_opd_dcomp', 'iwc_dcomp', 'lwc_dcomp'] # --------------------------------------------- -train_params = train_params_l2 +train_params = train_params_l1b_day + train_params_l2_day # -- Zero out params (Experimentation Only) ------------ zero_out_params = ['cld_reff_dcomp', 'cld_opd_dcomp', 'iwc_dcomp', 'lwc_dcomp'] DO_ZERO_OUT = False @@ -118,7 +117,17 @@ def build_residual_block(input, drop_rate, num_neurons, activation, block_name, class IcingIntensityNN: - def __init__(self, gpu_device=0, datapath=None): + def __init__(self, day_night='DAY', gpu_device=0, datapath=None): + + if day_night == 'DAY': + self.train_params_l1b = train_params_l1b_day + self.train_params_l2 = train_params_l2_day + self.train_params = train_params_l1b_day + train_params_l2_day + else: + self.train_params_l1b = train_params_l1b_night + self.train_params_l2 = train_params_l2_night + self.train_params = train_params_l1b_night + train_params_l2_night + self.train_data = None self.train_label = None self.test_data = None @@ -202,7 +211,7 @@ class IcingIntensityNN: self.data_dct = None - n_chans = len(train_params) + n_chans = len(self.train_params) if TRIPLET: n_chans *= 3 self.X_img = tf.keras.Input(shape=(img_width, img_width, n_chans)) @@ -252,7 +261,7 @@ class IcingIntensityNN: nd_idxs = np.sort(nd_idxs) data = [] - for param in train_params: + for param in self.train_params: nda = self.get_parameter_data(param, nd_idxs, is_training) # Manual Corruption Process. Better: see use of tf.keras.layers.GaussianNoise # if NOISE_TRAINING and is_training: @@ -295,12 +304,12 @@ class IcingIntensityNN: def get_parameter_data(self, param, nd_idxs, is_training): if is_training: - if param in train_params_l1b: + if param in self.train_params_l1b: h5f = self.h5f_l1b_trn else: h5f = self.h5f_l2_trn else: - if param in train_params_l1b: + if param in self.train_params_l1b: h5f = self.h5f_l1b_tst else: h5f = self.h5f_l2_tst @@ -363,7 +372,7 @@ class IcingIntensityNN: nd_idxs = np.sort(nd_idxs) data = [] - for param in train_params: + for param in self.train_params: nda = self.data_dct[param][nd_idxs, ] nda = normalize(nda, param, mean_std_dct) data.append(nda) @@ -542,7 +551,7 @@ class IcingIntensityNN: activation = tf.nn.leaky_relu momentum = 0.99 - num_filters = len(train_params) * 2 + num_filters = len(self.train_params) * 2 if NOISE_TRAINING: input_2d = tf.keras.layers.GaussianNoise(stddev=NOISE_STDDEV)(self.inputs[0]) @@ -988,7 +997,7 @@ class IcingIntensityNN: self.h5f_l2_tst.close() def run_evaluate(self, filename, ckpt_dir): - data_dct, ll, cc = make_for_full_domain_predict(filename, name_list=train_params) + data_dct, ll, cc = make_for_full_domain_predict(filename, name_list=self.train_params) self.setup_eval_pipeline(data_dct, len(ll)) self.build_model() self.build_training() @@ -1081,7 +1090,7 @@ def run_evaluate_static(h5f, ckpt_dir_s_path, flight_level=4, prob_thresh=0.5, s return ice_lons, ice_lats, preds_2d, lons_2d, lats_2d, x_rad, y_rad -def run_evaluate_static_new(data_dct, num_lines, num_elems, ckpt_dir_s_path, flight_levels=[0, 1, 2, 3, 4], prob_thresh=0.5): +def run_evaluate_static_new(data_dct, num_lines, num_elems, ckpt_dir_s_path, day_night='DAY', flight_levels=[0, 1, 2, 3, 4], prob_thresh=0.5): ckpt_dir_s = os.listdir(ckpt_dir_s_path) ckpt_dir = ckpt_dir_s[0] @@ -1090,7 +1099,7 @@ def run_evaluate_static_new(data_dct, num_lines, num_elems, ckpt_dir_s_path, fli preds_2d_dct = {flvl: None for flvl in flight_levels} for flvl in flight_levels: - nn = IcingIntensityNN() + nn = IcingIntensityNN(day_night=day_night) nn.flight_level = flvl nn.setup_eval_pipeline(data_dct, num_lines * num_elems) nn.build_model()