From cbf3d8ee53e56b33d3fc0f5975b54eef7852b2a4 Mon Sep 17 00:00:00 2001
From: tomrink <rink@ssec.wisc.edu>
Date: Mon, 29 Nov 2021 16:24:53 -0600
Subject: [PATCH] throw away unused code

---
 modules/icing/pirep_goes.py | 82 +++++++++++++++++--------------------
 1 file changed, 37 insertions(+), 45 deletions(-)

diff --git a/modules/icing/pirep_goes.py b/modules/icing/pirep_goes.py
index 377843f6..1d23dc59 100644
--- a/modules/icing/pirep_goes.py
+++ b/modules/icing/pirep_goes.py
@@ -1796,51 +1796,6 @@ def analyze_moon_phase(icing_dict):
     print(len(icing_dict), cnt)
 
 
-def collect(icing_times, icing_intensity, jdays=['071', '072', '074', '079', '080', '081', '082', '084', '085', '088',
-     '107', '110', '113', '117', '119', '129', '132', '134', '139', '150', '164', '203', '205', '232', '252', '254']):
-
-    nbins = 6
-
-    keep_idxs_yes = [[[] for j in range(nbins)] for i in range(len(jdays))]
-    keep_idxs_no = [[[] for j in range(nbins)] for i in range(len(jdays))]
-    ice_intsy = [[[] for j in range(7)] for i in range(len(jdays))]
-
-    for jidx, jd in enumerate(jdays):
-        _, ts_edges = make_times('2019-' + jd + '_00:00', None, num_steps=6, format_code='%Y-%j_%H:%M', hours=4)
-
-        fltr_times, fltr_idxs = time_filter_2(icing_times, '2019-'+jd+'_00:00', '2019-'+jd+'_23:59', format_code='%Y-%j_%H:%M')
-        bin_idxs = find_bin_index(np.array(ts_edges), np.array(fltr_times))
-
-        for cnt, bi in enumerate(bin_idxs):
-            #keep_idxs[jidx][bi].append(fltr_idxs[cnt])
-            k = fltr_idxs[cnt]
-            if icing_intensity[k] == -1:
-                keep_idxs_no[jidx][bi].append(k)
-            else:
-                keep_idxs_yes[jidx][bi].append(k)
-
-        ice_intsy[jidx][0] = np.sum(icing_intensity[fltr_idxs] == -1)
-        ice_intsy[jidx][1] = np.sum(icing_intensity[fltr_idxs] == 1)
-        ice_intsy[jidx][2] = np.sum(icing_intensity[fltr_idxs] == 2)
-        ice_intsy[jidx][3] = np.sum(icing_intensity[fltr_idxs] == 3)
-        ice_intsy[jidx][4] = np.sum(icing_intensity[fltr_idxs] == 4)
-        ice_intsy[jidx][5] = np.sum(icing_intensity[fltr_idxs] == 5)
-        ice_intsy[jidx][6] = np.sum(icing_intensity[fltr_idxs] == 6)
-
-        print(jd, '  --------------------')
-        for j in range(nbins):
-            print(len(keep_idxs_no[jidx][j]), len(keep_idxs_yes[jidx][j]))
-        print('no icing: ', ice_intsy[jidx][0])
-        print('icing 1: ', ice_intsy[jidx][1])
-        print('icing 2: ', ice_intsy[jidx][2])
-        print('icing 3: ', ice_intsy[jidx][3])
-        print('icing 4: ', ice_intsy[jidx][4])
-        print('icing 5: ', ice_intsy[jidx][5])
-        print('icing 6: ', ice_intsy[jidx][6])
-
-    return keep_idxs_no, keep_idxs_yes, ice_intsy
-
-
 def tiles_info(filename):
     h5f = h5py.File(filename, 'r')
     iint = h5f['icing_intensity'][:]
@@ -1854,6 +1809,43 @@ def tiles_info(filename):
     print('Icing 6:  ', np.sum(iint == 6))
 
 
+def analyze(preds_file):
+    h5f = h5py.File('/Users/tomrink/data/icing_ml/tiles_202109240000_202111152359_l1b_test_v3_DAY.h5', 'r')
+    nda = h5f['flight_altitude'][:]
+
+    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
+
+    labels, prob_avg, cm_avg = pickle.load(open(preds_file, 'rb'))
+
+    print(np.sum(nda == 0), np.sum(nda == 1), np.sum(nda == 2), np.sum(nda == 3), np.sum(nda == 4))
+    print('---------------------------')
+    print(np.histogram(nda[labels == 0]))
+    print('---------------------------')
+    print(np.histogram(nda[labels == 1]))
+    print('-----------------------------')
+
+    preds = np.where(prob_avg > 0.5, 1, 0)
+
+    true_ice = (labels == 1) & (preds == 1)
+    false_ice = (labels == 0) & (preds == 1)
+
+    print(np.histogram(nda[true_ice]))
+    print('---------------------------')
+    print(np.histogram(nda[false_ice]))
+    print('---------------------------')
+
+    true_no_ice = (labels == 0) & (preds == 0)
+    false_no_ice = (labels == 1) & (preds == 0)
+
+    print(np.histogram(nda[true_no_ice]))
+    print('---------------------------')
+    print(np.histogram(nda[false_no_ice]))
+
+
 def get_training_parameters(day_night='DAY', l1b_andor_l2='BOTH'):
     if day_night == 'DAY':
         train_params_l2 = ['cld_height_acha', 'cld_geo_thick', 'cld_temp_acha', 'cld_press_acha', 'supercooled_cloud_fraction',
-- 
GitLab