From aa22e3ecd08bce6f42e63e50c93591c0818e44e0 Mon Sep 17 00:00:00 2001 From: tomrink <rink@ssec.wisc.edu> Date: Tue, 29 Nov 2022 10:55:55 -0600 Subject: [PATCH] snapshot... --- modules/icing/pirep_goes.py | 204 +++++++++++++++++++++++++++--------- 1 file changed, 155 insertions(+), 49 deletions(-) diff --git a/modules/icing/pirep_goes.py b/modules/icing/pirep_goes.py index 8d2f9684..6b3d13e9 100644 --- a/modules/icing/pirep_goes.py +++ b/modules/icing/pirep_goes.py @@ -2258,6 +2258,138 @@ def tiles_info(filename): print('Icing 6: ', np.sum(iint == 6)) +# def analyze(preds_file, labels, prob_avg, test_file): +# +# if preds_file is not None: +# labels, prob_avg, cm_avg = pickle.load(open(preds_file, 'rb')) +# +# h5f = h5py.File(test_file, 'r') +# nda = h5f['flight_altitude'][:] +# iint = h5f['icing_intensity'][:] +# cld_hgt = h5f['cld_height_acha'][:] +# cld_dz = h5f['cld_geo_thick'][:] +# cld_tmp = h5f['cld_temp_acha'][:] +# +# print('report altitude (m): ', np.histogram(nda, bins=12)) +# +# 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 < 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), np.sum(nda == 3), np.sum(nda == 4)) +# print('No icing: ', np.histogram(nda[iint == 0], bins=5)[0]) +# print('---------------------------') +# print('Icing: ', np.histogram(nda[iint == 1], bins=5)[0]) +# print('---------------------------') +# +# print('No Icing(Negative): mean cld_dz, cld_hgt') +# print('Icing(Positive): ", "') +# print('level 0: ') +# print(np.nanmean(cld_dz[(nda == 0) & (iint == 0)]), np.nanmean(cld_hgt[(nda == 0) & (iint == 0)]), np.nanmean(cld_tmp[(nda == 0) & (iint == 0)])) +# print(np.nanmean(cld_dz[(nda == 0) & (iint == 1)]), np.nanmean(cld_hgt[(nda == 0) & (iint == 1)]), np.nanmean(cld_tmp[(nda == 0) & (iint == 1)])) +# print('------------') +# +# print('level 1: ') +# print(np.nanmean(cld_dz[(nda == 1) & (iint == 0)]), np.nanmean(cld_hgt[(nda == 1) & (iint == 0)]), np.nanmean(cld_tmp[(nda == 1) & (iint == 0)])) +# print(np.nanmean(cld_dz[(nda == 1) & (iint == 1)]), np.nanmean(cld_hgt[(nda == 1) & (iint == 1)]), np.nanmean(cld_tmp[(nda == 1) & (iint == 1)])) +# print('------------') +# +# print('level 2: ') +# print(np.nanmean(cld_dz[(nda == 2) & (iint == 0)]), np.nanmean(cld_hgt[(nda == 2) & (iint == 0)]), np.nanmean(cld_tmp[(nda == 2) & (iint == 0)])) +# print(np.nanmean(cld_dz[(nda == 2) & (iint == 1)]), np.nanmean(cld_hgt[(nda == 2) & (iint == 1)]), np.nanmean(cld_tmp[(nda == 2) & (iint == 1)])) +# print('------------') +# +# print('level 3: ') +# print(np.nanmean(cld_dz[(nda == 3) & (iint == 0)]), np.nanmean(cld_hgt[(nda == 3) & (iint == 0)]), np.nanmean(cld_tmp[(nda == 3) & (iint == 0)])) +# print(np.nanmean(cld_dz[(nda == 3) & (iint == 1)]), np.nanmean(cld_hgt[(nda == 3) & (iint == 1)]), np.nanmean(cld_tmp[(nda == 3) & (iint == 1)])) +# print('------------') +# +# print('level 4: ') +# print(np.nanmean(cld_dz[(nda == 4) & (iint == 0)]), np.nanmean(cld_hgt[(nda == 4) & (iint == 0)]), np.nanmean(cld_tmp[(nda == 4) & (iint == 0)])) +# print(np.nanmean(cld_dz[(nda == 4) & (iint == 1)]), np.nanmean(cld_hgt[(nda == 4) & (iint == 1)]), np.nanmean(cld_tmp[(nda == 4) & (iint == 1)])) +# print('----------------------------------------------------------') +# print('----------------------------------------------------------') +# +# if prob_avg is None: +# return +# +# preds = np.where(prob_avg > 0.5, 1, 0) +# +# true_ice = (labels == 1) & (preds == 1) +# false_ice = (labels == 0) & (preds == 1) +# +# true_no_ice = (labels == 0) & (preds == 0) +# false_no_ice = (labels == 1) & (preds == 0) +# +# print('Total (Positive/Icing Prediction: ') +# print('True icing: ', np.histogram(nda[true_ice], bins=5)[0]) +# print('-------------------------') +# print('False no icing (False Negative/Miss): ', np.histogram(nda[false_no_ice], bins=5)[0]) +# 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('level 3: ') +# print(np.nanmean(cld_dz[(nda == 3) & false_no_ice]), np.nanmean(cld_hgt[(nda == 3) & false_no_ice]), np.nanmean(cld_tmp[(nda == 3) & false_no_ice])) +# print(np.nanmean(cld_dz[(nda == 3) & true_ice]), np.nanmean(cld_hgt[(nda == 3) & true_ice]), np.nanmean(cld_tmp[(nda == 3) & true_ice])) +# print('------------') +# +# print('level 4: ') +# print(np.nanmean(cld_dz[(nda == 4) & false_no_ice]), np.nanmean(cld_hgt[(nda == 4) & false_no_ice]), np.nanmean(cld_tmp[(nda == 4) & false_no_ice])) +# print(np.nanmean(cld_dz[(nda == 4) & true_ice]), np.nanmean(cld_hgt[(nda == 4) & true_ice]), np.nanmean(cld_tmp[(nda == 4) & true_ice])) +# print('---------------------------------------------------') +# print('---------------------------------------------------') +# +# print('Total (Negative/No Icing Prediction: ') +# print('True no icing: ', np.histogram(nda[true_no_ice], bins=5)[0]) +# print('-------------------------') +# print('* False icing (False Positive/False Alarm) *: ', np.histogram(nda[false_ice], bins=5)[0]) +# 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('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('------------') +# +# print('level 3: ') +# print(np.nanmean(cld_dz[(nda == 3) & false_ice]), np.nanmean(cld_hgt[(nda == 3) & false_ice]), np.nanmean(cld_tmp[(nda == 3) & false_ice])) +# print(np.nanmean(cld_dz[(nda == 3) & true_no_ice]), np.nanmean(cld_hgt[(nda == 3) & true_no_ice]), np.nanmean(cld_tmp[(nda == 3) & true_no_ice])) +# print('------------') +# +# print('level 4: ') +# print(np.nanmean(cld_dz[(nda == 4) & false_ice]), np.nanmean(cld_hgt[(nda == 4) & false_ice]), np.nanmean(cld_tmp[(nda == 4) & false_ice])) +# print(np.nanmean(cld_dz[(nda == 4) & true_no_ice]), np.nanmean(cld_hgt[(nda == 4) & true_no_ice]), np.nanmean(cld_tmp[(nda == 4) & true_no_ice])) +# + def analyze(preds_file, labels, prob_avg, test_file): if preds_file is not None: @@ -2275,16 +2407,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 < 6000)] = 2 - nda[np.logical_and(nda >= 6000, nda < 8000)] = 3 - nda[np.logical_and(nda >= 8000, nda < 15000)] = 4 + nda[np.logical_and(nda >= 0, nda < 2500)] = 0 + nda[np.logical_and(nda >= 2500, nda < 15000)] = 1 + # nda[np.logical_and(nda >= 8000, nda < 15000)] = 2 - print(np.sum(nda == 0), np.sum(nda == 1), np.sum(nda == 2), np.sum(nda == 3), np.sum(nda == 4)) - print('No icing: ', np.histogram(nda[iint == 0], bins=5)[0]) + #print(np.sum(nda == 0), np.sum(nda == 1), np.sum(nda == 2)) + print(np.sum(nda == 0), np.sum(nda == 1)) + print('No icing: ', np.histogram(nda[iint == 0], bins=2)[0]) print('---------------------------') - print('Icing: ', np.histogram(nda[iint == 1], bins=5)[0]) + print('Icing: ', np.histogram(nda[iint == 1], bins=2)[0]) print('---------------------------') print('No Icing(Negative): mean cld_dz, cld_hgt') @@ -2299,19 +2430,11 @@ def analyze(preds_file, labels, prob_avg, test_file): print(np.nanmean(cld_dz[(nda == 1) & (iint == 1)]), np.nanmean(cld_hgt[(nda == 1) & (iint == 1)]), np.nanmean(cld_tmp[(nda == 1) & (iint == 1)])) print('------------') - print('level 2: ') - print(np.nanmean(cld_dz[(nda == 2) & (iint == 0)]), np.nanmean(cld_hgt[(nda == 2) & (iint == 0)]), np.nanmean(cld_tmp[(nda == 2) & (iint == 0)])) - print(np.nanmean(cld_dz[(nda == 2) & (iint == 1)]), np.nanmean(cld_hgt[(nda == 2) & (iint == 1)]), np.nanmean(cld_tmp[(nda == 2) & (iint == 1)])) - print('------------') + # print('level 2: ') + # print(np.nanmean(cld_dz[(nda == 2) & (iint == 0)]), np.nanmean(cld_hgt[(nda == 2) & (iint == 0)]), np.nanmean(cld_tmp[(nda == 2) & (iint == 0)])) + # print(np.nanmean(cld_dz[(nda == 2) & (iint == 1)]), np.nanmean(cld_hgt[(nda == 2) & (iint == 1)]), np.nanmean(cld_tmp[(nda == 2) & (iint == 1)])) + # print('------------') - print('level 3: ') - print(np.nanmean(cld_dz[(nda == 3) & (iint == 0)]), np.nanmean(cld_hgt[(nda == 3) & (iint == 0)]), np.nanmean(cld_tmp[(nda == 3) & (iint == 0)])) - print(np.nanmean(cld_dz[(nda == 3) & (iint == 1)]), np.nanmean(cld_hgt[(nda == 3) & (iint == 1)]), np.nanmean(cld_tmp[(nda == 3) & (iint == 1)])) - print('------------') - - print('level 4: ') - print(np.nanmean(cld_dz[(nda == 4) & (iint == 0)]), np.nanmean(cld_hgt[(nda == 4) & (iint == 0)]), np.nanmean(cld_tmp[(nda == 4) & (iint == 0)])) - print(np.nanmean(cld_dz[(nda == 4) & (iint == 1)]), np.nanmean(cld_hgt[(nda == 4) & (iint == 1)]), np.nanmean(cld_tmp[(nda == 4) & (iint == 1)])) print('----------------------------------------------------------') print('----------------------------------------------------------') @@ -2327,9 +2450,9 @@ def analyze(preds_file, labels, prob_avg, test_file): false_no_ice = (labels == 1) & (preds == 0) print('Total (Positive/Icing Prediction: ') - print('True icing: ', np.histogram(nda[true_ice], bins=5)[0]) + print('True icing: ', np.histogram(nda[true_ice], bins=2)[0]) print('-------------------------') - print('False no icing (False Negative/Miss): ', np.histogram(nda[false_no_ice], bins=5)[0]) + print('False no icing (False Negative/Miss): ', np.histogram(nda[false_no_ice], bins=2)[0]) print('By flight level:') print('No Icing(Negative): mean cld_dz, cld_hgt') print('Icing(Positive): ", "') @@ -2343,26 +2466,18 @@ def analyze(preds_file, labels, prob_avg, test_file): 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('level 3: ') - print(np.nanmean(cld_dz[(nda == 3) & false_no_ice]), np.nanmean(cld_hgt[(nda == 3) & false_no_ice]), np.nanmean(cld_tmp[(nda == 3) & false_no_ice])) - print(np.nanmean(cld_dz[(nda == 3) & true_ice]), np.nanmean(cld_hgt[(nda == 3) & true_ice]), np.nanmean(cld_tmp[(nda == 3) & 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('level 4: ') - print(np.nanmean(cld_dz[(nda == 4) & false_no_ice]), np.nanmean(cld_hgt[(nda == 4) & false_no_ice]), np.nanmean(cld_tmp[(nda == 4) & false_no_ice])) - print(np.nanmean(cld_dz[(nda == 4) & true_ice]), np.nanmean(cld_hgt[(nda == 4) & true_ice]), np.nanmean(cld_tmp[(nda == 4) & true_ice])) print('---------------------------------------------------') print('---------------------------------------------------') print('Total (Negative/No Icing Prediction: ') - print('True no icing: ', np.histogram(nda[true_no_ice], bins=5)[0]) + print('True no icing: ', np.histogram(nda[true_no_ice], bins=2)[0]) print('-------------------------') - print('* False icing (False Positive/False Alarm) *: ', np.histogram(nda[false_ice], bins=5)[0]) + print('* False icing (False Positive/False Alarm) *: ', np.histogram(nda[false_ice], bins=2)[0]) print('-------------------------') print('level 0: ') @@ -2375,19 +2490,10 @@ def analyze(preds_file, labels, prob_avg, test_file): 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('------------') - - print('level 3: ') - print(np.nanmean(cld_dz[(nda == 3) & false_ice]), np.nanmean(cld_hgt[(nda == 3) & false_ice]), np.nanmean(cld_tmp[(nda == 3) & false_ice])) - print(np.nanmean(cld_dz[(nda == 3) & true_no_ice]), np.nanmean(cld_hgt[(nda == 3) & true_no_ice]), np.nanmean(cld_tmp[(nda == 3) & true_no_ice])) - print('------------') - - print('level 4: ') - print(np.nanmean(cld_dz[(nda == 4) & false_ice]), np.nanmean(cld_hgt[(nda == 4) & false_ice]), np.nanmean(cld_tmp[(nda == 4) & false_ice])) - print(np.nanmean(cld_dz[(nda == 4) & true_no_ice]), np.nanmean(cld_hgt[(nda == 4) & true_no_ice]), np.nanmean(cld_tmp[(nda == 4) & true_no_ice])) + # 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