From daadf4161342b25aad77a683be1ecde57d0c2664 Mon Sep 17 00:00:00 2001 From: tomrink <rink@ssec.wisc.edu> Date: Tue, 3 Jan 2023 11:32:38 -0600 Subject: [PATCH] snapshot... --- modules/icing/pirep_goes.py | 121 +++++++++++++++++++++++++----------- 1 file changed, 85 insertions(+), 36 deletions(-) diff --git a/modules/icing/pirep_goes.py b/modules/icing/pirep_goes.py index 08e84c2b..e1564816 100644 --- a/modules/icing/pirep_goes.py +++ b/modules/icing/pirep_goes.py @@ -127,7 +127,10 @@ def get_goes_datasource(timestamp): def get_grid_values(h5f, grid_name, j_c, i_c, half_width, num_j=None, num_i=None, scale_factor_name='scale_factor', add_offset_name='add_offset', fill_value_name='_FillValue', range_name='actual_range', fill_value=None): - hfds = h5f[grid_name] + try: + hfds = h5f[grid_name] + except Exception: + return None attrs = hfds.attrs if attrs is None: raise GenericException('No attributes object for: '+grid_name) @@ -337,9 +340,11 @@ def run(pirep_dct, platform, outfile=None, outfile_l1b=None, dt_str_start=None, cnt_b += 1 if cnt_a > 0 and cnt_a != len(ds_list): - raise GenericException('weirdness') + continue + #raise GenericException('weirdness') if cnt_b > 0 and cnt_b != len(l1b_ds_list): - raise GenericException('weirdness') + continue + #raise GenericException('weirdness') if cnt_a == len(ds_list) and cnt_b == len(l1b_ds_list): lon_c.append(lon_s[0]) @@ -2557,9 +2562,15 @@ def analyze(preds_file, labels, prob_avg, test_file): iint = np.where(iint == -1, 0, iint) iint = np.where(iint != 0, 1, iint) - nda[np.logical_and(nda >= 0, nda < 2000)] = 0 - nda[np.logical_and(nda >= 2000, nda < 4000)] = 1 - nda[np.logical_and(nda >= 4000, nda < 15000)] = 2 + # nda[np.logical_and(nda >= 0, nda < 2000)] = 0 + # nda[np.logical_and(nda >= 2000, nda < 4000)] = 1 + # nda[np.logical_and(nda >= 4000, nda < 15000)] = 2 + + nda[np.logical_and(nda >= 0, nda < 5000)] = 0 + nda[np.logical_and(nda >= 5000, nda < 8000)] = 1 + # nda[np.logical_and(nda >= 5200, nda < 6000)] = 2 + # nda[np.logical_and(nda >= 6000, nda < 8000)] = 3 + # nda[np.logical_and(nda >= 8000, nda < 15000)] = 4 print(np.sum(nda == 0), np.sum(nda == 1), np.sum(nda == 2)) print('No icing: ', np.sum((iint == 0) & (nda == 0)), np.sum((iint == 0) & (nda == 1))) @@ -2599,27 +2610,63 @@ def analyze(preds_file, labels, prob_avg, test_file): true_no_ice = (labels == 0) & (preds == 0) false_no_ice = (labels == 1) & (preds == 0) + # tp = true_ice + # tn = true_no_ice + # fp = false_ice + # fn = false_no_ice + + tp_0 = np.sum(true_ice & (nda == 0)) + tp_1 = np.sum(true_ice & (nda == 1)) + + tn_0 = np.sum(true_no_ice & (nda == 0)) + tn_1 = np.sum(true_no_ice & (nda == 1)) + + fp_0 = np.sum(false_ice & (nda == 0)) + fp_1 = np.sum(false_ice & (nda == 1)) + + fn_0 = np.sum(false_no_ice & (nda == 0)) + fn_1 = np.sum(false_no_ice & (nda == 1)) + + recall_0 = tp_0 / (tp_0 + fn_0) + recall_1 = tp_1 / (tp_1 + fn_1) + + precision_0 = tp_0 / (tp_0 + fp_0) + precision_1 = tp_1 / (tp_1 + fp_1) + + mcc_0 = ((tp_0 * tn_0) - (fp_0 * fn_0)) / np.sqrt((tp_0 + fp_0) * (tp_0 + fn_0) * (tn_0 + fp_0) * (tn_0 + fn_0)) + mcc_1 = ((tp_1 * tn_1) - (fp_1 * fn_1)) / np.sqrt((tp_1 + fp_1) * (tp_1 + fn_1) * (tn_1 + fp_1) * (tn_1 + fn_1)) + + + # precision = true_ice / (true_ice + false_ice) + # recall = true_ice / (true_ice + false_no_ice) + # f1 = 2 * (precision * recall) / (precision + recall) + # tp = true_ice + # tn = true_no_ice + # fp = false_ice + # fn = false_no_ice + # mcc = ((tp * tn) - (fp * fn)) / np.sqrt((tp + fp) * (tp + fn) * (tn + fp) * (tn + fn)) + print('Total (Positive/Icing Prediction: ') print('True icing: ', np.sum(true_ice & (nda == 0)), np.sum(true_ice & (nda == 1))) print('-------------------------') print('False no icing (False Negative/Miss): ', np.sum(false_no_ice & (nda == 0)), np.sum(false_no_ice & (nda == 1))) - print('By flight level:') - print('No Icing(Negative): mean cld_dz, cld_hgt') - print('Icing(Positive): ", "') - print('level 0: ') - print(np.nanmean(cld_dz[(nda == 0) & false_no_ice]), np.nanmean(cld_hgt[(nda == 0) & false_no_ice]), np.nanmean(cld_tmp[(nda == 0) & false_no_ice])) - print(np.nanmean(cld_dz[(nda == 0) & true_ice]), np.nanmean(cld_hgt[(nda == 0) & true_ice]), np.nanmean(cld_tmp[(nda == 0) & true_ice])) - print('------------') - - print('level 1: ') - print(np.nanmean(cld_dz[(nda == 1) & false_no_ice]), np.nanmean(cld_hgt[(nda == 1) & false_no_ice]), np.nanmean(cld_tmp[(nda == 1) & false_no_ice])) - print(np.nanmean(cld_dz[(nda == 1) & true_ice]), np.nanmean(cld_hgt[(nda == 1) & true_ice]), np.nanmean(cld_tmp[(nda == 1) & true_ice])) - print('------------') - - # print('level 2: ') - # print(np.nanmean(cld_dz[(nda == 2) & false_no_ice]), np.nanmean(cld_hgt[(nda == 2) & false_no_ice]), np.nanmean(cld_tmp[(nda == 2) & false_no_ice])) - # print(np.nanmean(cld_dz[(nda == 2) & true_ice]), np.nanmean(cld_hgt[(nda == 2) & true_ice]), np.nanmean(cld_tmp[(nda == 2) & true_ice])) + # print('By flight level:') + # print('No Icing(Negative): mean cld_dz, cld_hgt') + # print('Icing(Positive): ", "') + # print('level 0: ') + # print(np.nanmean(cld_dz[(nda == 0) & false_no_ice]), np.nanmean(cld_hgt[(nda == 0) & false_no_ice]), np.nanmean(cld_tmp[(nda == 0) & false_no_ice])) + # print(np.nanmean(cld_dz[(nda == 0) & true_ice]), np.nanmean(cld_hgt[(nda == 0) & true_ice]), np.nanmean(cld_tmp[(nda == 0) & true_ice])) # print('------------') + # + # print('level 1: ') + # print(np.nanmean(cld_dz[(nda == 1) & false_no_ice]), np.nanmean(cld_hgt[(nda == 1) & false_no_ice]), np.nanmean(cld_tmp[(nda == 1) & false_no_ice])) + # print(np.nanmean(cld_dz[(nda == 1) & true_ice]), np.nanmean(cld_hgt[(nda == 1) & true_ice]), np.nanmean(cld_tmp[(nda == 1) & true_ice])) + # print('------------') + # + # # print('level 2: ') + # # print(np.nanmean(cld_dz[(nda == 2) & false_no_ice]), np.nanmean(cld_hgt[(nda == 2) & false_no_ice]), np.nanmean(cld_tmp[(nda == 2) & false_no_ice])) + # # print(np.nanmean(cld_dz[(nda == 2) & true_ice]), np.nanmean(cld_hgt[(nda == 2) & true_ice]), np.nanmean(cld_tmp[(nda == 2) & true_ice])) + # # print('------------') print('---------------------------------------------------') print('---------------------------------------------------') @@ -2630,22 +2677,24 @@ def analyze(preds_file, labels, prob_avg, test_file): print('* False icing (False Positive/False Alarm) *: ', np.sum(false_ice & (nda == 0)), np.sum(false_ice & (nda == 1))) print('-------------------------') - print('level 0: ') - print(np.nanmean(cld_dz[(nda == 0) & false_ice]), np.nanmean(cld_hgt[(nda == 0) & false_ice]), np.nanmean(cld_tmp[(nda == 0) & false_ice])) - print(np.nanmean(cld_dz[(nda == 0) & true_no_ice]), np.nanmean(cld_hgt[(nda == 0) & true_no_ice]), np.nanmean(cld_tmp[(nda == 0) & true_no_ice])) - print('------------') - - print('level 1: ') - print(np.nanmean(cld_dz[(nda == 1) & false_ice]), np.nanmean(cld_hgt[(nda == 1) & false_ice]), np.nanmean(cld_tmp[(nda == 1) & false_ice])) - print(np.nanmean(cld_dz[(nda == 1) & true_no_ice]), np.nanmean(cld_hgt[(nda == 1) & true_no_ice]), np.nanmean(cld_tmp[(nda == 1) & true_no_ice])) - print('------------') + print('Recall: ', recall_0, recall_1) + print('Precision: ', precision_0, precision_1) + print('MCC: ', mcc_0, mcc_1) - # print('level 2: ') - # print(np.nanmean(cld_dz[(nda == 2) & false_ice]), np.nanmean(cld_hgt[(nda == 2) & false_ice]), np.nanmean(cld_tmp[(nda == 2) & false_ice])) - # print(np.nanmean(cld_dz[(nda == 2) & true_no_ice]), np.nanmean(cld_hgt[(nda == 2) & true_no_ice]), np.nanmean(cld_tmp[(nda == 2) & true_no_ice])) + # print('level 0: ') + # print(np.nanmean(cld_dz[(nda == 0) & false_ice]), np.nanmean(cld_hgt[(nda == 0) & false_ice]), np.nanmean(cld_tmp[(nda == 0) & false_ice])) + # print(np.nanmean(cld_dz[(nda == 0) & true_no_ice]), np.nanmean(cld_hgt[(nda == 0) & true_no_ice]), np.nanmean(cld_tmp[(nda == 0) & true_no_ice])) # print('------------') - - return flt_alt[iint == 0], flt_alt[iint == 1] + # + # print('level 1: ') + # print(np.nanmean(cld_dz[(nda == 1) & false_ice]), np.nanmean(cld_hgt[(nda == 1) & false_ice]), np.nanmean(cld_tmp[(nda == 1) & false_ice])) + # print(np.nanmean(cld_dz[(nda == 1) & true_no_ice]), np.nanmean(cld_hgt[(nda == 1) & true_no_ice]), np.nanmean(cld_tmp[(nda == 1) & true_no_ice])) + # print('------------') + # + # # print('level 2: ') + # # print(np.nanmean(cld_dz[(nda == 2) & false_ice]), np.nanmean(cld_hgt[(nda == 2) & false_ice]), np.nanmean(cld_tmp[(nda == 2) & false_ice])) + # # print(np.nanmean(cld_dz[(nda == 2) & true_no_ice]), np.nanmean(cld_hgt[(nda == 2) & true_no_ice]), np.nanmean(cld_tmp[(nda == 2) & true_no_ice])) + # # print('------------') def get_training_parameters(day_night='DAY', l1b_andor_l2='both'): -- GitLab