From a4535430b82b431caf75d2c4baf9f0224016b3ad Mon Sep 17 00:00:00 2001
From: tomrink <rink@ssec.wisc.edu>
Date: Sat, 3 Dec 2022 11:39:36 -0600
Subject: [PATCH] snapshot...

---
 modules/icing/pirep_goes.py | 112 +++++++++++++++++++-----------------
 1 file changed, 60 insertions(+), 52 deletions(-)

diff --git a/modules/icing/pirep_goes.py b/modules/icing/pirep_goes.py
index 8620fddf..a3b24a18 100644
--- a/modules/icing/pirep_goes.py
+++ b/modules/icing/pirep_goes.py
@@ -1237,8 +1237,8 @@ def apply_qc_icing_pireps(icing_alt, cld_top_hgt, cld_geo_dz, cld_phase, cld_opd
             #     continue
 
         # if not (500.0 < icing_alt[i] < 3000.0):
-        if not (icing_alt[i] < 4000.0):
-            continue
+        # if not (icing_alt[i] < 4000.0):
+        #     continue
 
         keep_0 = np.logical_or(cld_mask[i,] == 2, cld_mask[i,] == 3)  # cloudy
         keep_1 = np.invert(np.isnan(cld_top_hgt[i,]))
@@ -1250,7 +1250,7 @@ def apply_qc_icing_pireps(icing_alt, cld_top_hgt, cld_geo_dz, cld_phase, cld_opd
             continue
 
         # Test 1
-        keep = np.where(keep, (cld_top_hgt[i,] + closeness_top) > 4000.0, False)
+        keep = np.where(keep, (cld_top_hgt[i,] + closeness_top) > icing_alt[i], False)
         # keep = np.where(keep, (cld_top_hgt[i,] - max_depth) < icing_alt[i], False)
 
         # keep = np.where(keep, np.logical_and(bt_11um[i,] > 228.0, bt_11um[i,] < 270.0), False)
@@ -1297,8 +1297,8 @@ def apply_qc_no_icing_pireps(icing_alt, cld_top_hgt, cld_geo_dz, cld_phase, cld_
             #     continue
 
         # if not (500.0 < icing_alt[i] < 3000.0):
-        if not (icing_alt[i] < 4000.0):
-            continue
+        # if not (icing_alt[i] < 4000.0):
+        #     continue
 
         keep_0 = np.logical_or(cld_mask[i,] == 2, cld_mask[i,] == 3)  # cloudy
         keep_1 = np.invert(np.isnan(cld_top_hgt[i,]))
@@ -1309,7 +1309,7 @@ def apply_qc_no_icing_pireps(icing_alt, cld_top_hgt, cld_geo_dz, cld_phase, cld_
         if num_keep == 0:
             continue
 
-        keep = np.where(keep, (cld_top_hgt[i,] + closeness_top) > 4000.0, False)
+        keep = np.where(keep, (cld_top_hgt[i,] + closeness_top) > icing_alt[i], False)
         # keep = np.where(keep, (cld_top_hgt[i,] - max_depth) < icing_alt[i], False)
 
         # keep = np.where(keep, np.logical_and(bt_11um[i,] > 228.0, bt_11um[i,] < 270.0), False)
@@ -1590,53 +1590,61 @@ def tile_extract(icing_files, no_icing_files, trnfile='/home/rink/tiles_train.h5
     ice_flt_alt_s = np.array(ice_flt_alt_s)
     num_ice = icing_int_s.shape[0]
 
-    # No icing  ------------------------------------------------------------
-    num_no_ice = 0
-    for fidx in range(len(no_icing_files)):
-        fname = no_icing_files[fidx]
-        f = h5py.File(fname, 'r')
-        h5_s_no_icing.append(f)
-
-        times = f['time']
-        num_obs = len(times)
-        lons = f['longitude']
-        lats = f['latitude']
-        flt_altitude = f['icing_altitude'][:]
-
-        for i in range(num_obs):
-            cld_msk = f[cld_mask_name][i, n_a:n_b, m_a:m_b]
-            for ds_name in params:
-                dat = f[ds_name][i, n_a:n_b, m_a:m_b]
-                if L1B_or_L2 == 'L2':
-                    keep = np.logical_or(cld_msk == 2, cld_msk == 3)  # cloudy
-                    np.where(keep, dat, np.nan)
-                no_icing_data_dct[ds_name].append(dat)
-            num_no_ice += 1
-            no_ice_time_s.append(times[i])
-            no_ice_lon_s.append(lons[i])
-            no_ice_lat_s.append(lats[i])
-            no_ice_flt_alt_s.append(flt_altitude[i])
-
-        print(fname)
-
-    for ds_name in params:
-        lst = no_icing_data_dct[ds_name]
-        no_icing_data_dct[ds_name] = np.stack(lst, axis=0)
-    no_icing_int_s = np.full(num_no_ice, -1)
-    no_ice_time_s = np.array(no_ice_time_s)
-    no_ice_lon_s = np.array(no_ice_lon_s)
-    no_ice_lat_s = np.array(no_ice_lat_s)
-    no_ice_flt_alt_s = np.array(no_ice_flt_alt_s)
-
-    icing_intensity = np.concatenate([icing_int_s, no_icing_int_s])
-    icing_times = np.concatenate([ice_time_s, no_ice_time_s])
-    icing_lons = np.concatenate([ice_lon_s, no_ice_lon_s])
-    icing_lats = np.concatenate([ice_lat_s, no_ice_lat_s])
-    icing_alt = np.concatenate([ice_flt_alt_s, no_ice_flt_alt_s])
+    # # No icing  ------------------------------------------------------------
+    # num_no_ice = 0
+    # for fidx in range(len(no_icing_files)):
+    #     fname = no_icing_files[fidx]
+    #     f = h5py.File(fname, 'r')
+    #     h5_s_no_icing.append(f)
+    #
+    #     times = f['time']
+    #     num_obs = len(times)
+    #     lons = f['longitude']
+    #     lats = f['latitude']
+    #     flt_altitude = f['icing_altitude'][:]
+    #
+    #     for i in range(num_obs):
+    #         cld_msk = f[cld_mask_name][i, n_a:n_b, m_a:m_b]
+    #         for ds_name in params:
+    #             dat = f[ds_name][i, n_a:n_b, m_a:m_b]
+    #             if L1B_or_L2 == 'L2':
+    #                 keep = np.logical_or(cld_msk == 2, cld_msk == 3)  # cloudy
+    #                 np.where(keep, dat, np.nan)
+    #             no_icing_data_dct[ds_name].append(dat)
+    #         num_no_ice += 1
+    #         no_ice_time_s.append(times[i])
+    #         no_ice_lon_s.append(lons[i])
+    #         no_ice_lat_s.append(lats[i])
+    #         no_ice_flt_alt_s.append(flt_altitude[i])
+    #
+    #     print(fname)
+    #
+    # for ds_name in params:
+    #     lst = no_icing_data_dct[ds_name]
+    #     no_icing_data_dct[ds_name] = np.stack(lst, axis=0)
+    # no_icing_int_s = np.full(num_no_ice, -1)
+    # no_ice_time_s = np.array(no_ice_time_s)
+    # no_ice_lon_s = np.array(no_ice_lon_s)
+    # no_ice_lat_s = np.array(no_ice_lat_s)
+    # no_ice_flt_alt_s = np.array(no_ice_flt_alt_s)
+    #
+    # icing_intensity = np.concatenate([icing_int_s, no_icing_int_s])
+    # icing_times = np.concatenate([ice_time_s, no_ice_time_s])
+    # icing_lons = np.concatenate([ice_lon_s, no_ice_lon_s])
+    # icing_lats = np.concatenate([ice_lat_s, no_ice_lat_s])
+    # icing_alt = np.concatenate([ice_flt_alt_s, no_ice_flt_alt_s])
+
+    icing_intensity = icing_int_s
+    icing_times = ice_time_s
+    icing_lons = ice_lon_s
+    icing_lats = ice_lat_s
+    icing_alt = ice_flt_alt_s
 
     data_dct = {}
+    # for ds_name in params:
+    #     data_dct[ds_name] = np.concatenate([icing_data_dct[ds_name], no_icing_data_dct[ds_name]])
     for ds_name in params:
-        data_dct[ds_name] = np.concatenate([icing_data_dct[ds_name], no_icing_data_dct[ds_name]])
+        data_dct[ds_name] = icing_data_dct[ds_name]
 
     # do sort -------------------------------------
     ds_indexes = np.argsort(icing_times)
@@ -1781,8 +1789,8 @@ def tile_extract(icing_files, no_icing_files, trnfile='/home/rink/tiles_train.h5
     for h5f in h5_s_icing:
         h5f.close()
 
-    for h5f in h5_s_no_icing:
-        h5f.close()
+    # for h5f in h5_s_no_icing:
+    #     h5f.close()
 
 
 def write_file(outfile, params, param_types, data_dct, icing_intensity, icing_times, icing_lons, icing_lats, icing_alt):
-- 
GitLab