From 08ffd13c98110cf114bd63fea9f38bc17ab6e32f Mon Sep 17 00:00:00 2001
From: tomrink <rink@ssec.wisc.edu>
Date: Mon, 30 Aug 2021 10:26:39 -0500
Subject: [PATCH] snapshot...

---
 modules/icing/pirep_goes.py | 42 ++++++++++++++++++++++++++++++++++++-
 modules/util/util.py        | 22 +++++++++++--------
 2 files changed, 54 insertions(+), 10 deletions(-)

diff --git a/modules/icing/pirep_goes.py b/modules/icing/pirep_goes.py
index 38d14246..6f27d558 100644
--- a/modules/icing/pirep_goes.py
+++ b/modules/icing/pirep_goes.py
@@ -4,7 +4,7 @@ import pickle
 import matplotlib.pyplot as plt
 import os
 from util.util import get_time_tuple_utc, GenericException, add_time_range_to_filename, is_night, is_day, \
-    get_grid_values_all, check_oblique
+    get_grid_values_all, check_oblique, make_times, find_bin_index
 from aeolus.datasource import CLAVRx, GOESL1B
 from util.geos_nav import GEOSNavigation
 import h5py
@@ -1522,6 +1522,32 @@ def time_filter(icing_dct, dt_str_0=None, dt_str_1=None, format_code='%Y-%m-%d_%
     return keep_times, keep_reports
 
 
+# dt_str_0: start datetime string in format YYYY-MM-DD_HH:MM (default)
+# dt_str_1: end datetime string in format YYYY-MM-DD_HH:MM (default)
+# format_code: Python Datetime format code, default: '%Y-%m-%d_%H:%M'
+# return a flatten list of icing reports
+def time_filter_2(times, dt_str_0=None, dt_str_1=None, format_code='%Y-%m-%d_%H:%M'):
+    ts_0 = 0
+    if dt_str_0 is not None:
+        dto_0 = datetime.datetime.strptime(dt_str_0, format_code).replace(tzinfo=timezone.utc)
+        ts_0 = dto_0.timestamp()
+
+    ts_1 = np.finfo(np.float64).max
+    if dt_str_1 is not None:
+        dto_1 = datetime.datetime.strptime(dt_str_1, format_code).replace(tzinfo=timezone.utc)
+        ts_1 = dto_1.timestamp()
+
+    keep_idxs = []
+    keep_times = []
+
+    for ts, idx in enumerate(times):
+        if ts_0 <= ts < ts_1:
+            keep_times.append(ts)
+            keep_idxs.append(idx)
+
+    return keep_times, keep_idxs
+
+
 def analyze_moon_phase(icing_dict):
     ts = api.load.timescale()
     eph = api.load('de421.bsp')
@@ -1546,6 +1572,20 @@ def analyze_moon_phase(icing_dict):
     print(len(icing_dict), cnt)
 
 
+def collect(icing_times, icing_intensity):
+    nbins = 6
+    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']
+
+    keep_idxs = [[[] for j in range(nbins)] for i in range(len(jdays))]
+
+    for jd in jdays:
+        fltr_times, fltr_idxs = time_filter_2(icing_times, '2019-'+jd+'_00:00', '2019-'+jd+'_00:00', format_code='%Y-%j_%H:%M')
+        _, ts_edges = make_times('2019-'+jd+'_00:00', None, num_steps=6, format_code='%Y-%j_%H:%M', hours=4)
+        bin_idxs = find_bin_index(np.array(ts_edges), np.array(fltr_times))
+
+
+
 # ------------ This code will not be needed when we implement a Fully Connected CNN -----------------------------------
 # Example GOES file to retrieve GEOS parameters in MetPy form (CONUS)
 exmp_file = '/Users/tomrink/data/OR_ABI-L1b-RadC-M6C14_G16_s20193140811215_e20193140813588_c20193140814070.nc'
diff --git a/modules/util/util.py b/modules/util/util.py
index 8a9ce465..dd715f52 100644
--- a/modules/util/util.py
+++ b/modules/util/util.py
@@ -185,20 +185,24 @@ def value_to_index(nda, value):
     return idx
 
 
-def find_bin_index(nda, value):
+def find_bin_index(nda, value_s):
     idxs = np.arange(nda.shape[0])
+    iL_s = np.zeros(value_s.shape[0])
+    iL_s[:,] = -1
 
-    above = value >= nda
-    if not above.any():
-        return -1
+    for k, v in enumerate(value_s):
+        above = v >= nda
+        if not above.any():
+            continue
 
-    below = value < nda
-    if not below.any():
-        return -1
+        below = v < nda
+        if not below.any():
+            continue
 
-    iL = idxs[above].max()
+        iL = idxs[above].max()
+        iL_s[k] = iL
 
-    return iL
+    return iL_s
 
 
 # array solzen must be degrees, missing values must NaN. For small roughly 50x50km regions only
-- 
GitLab