From faf5e59b927586812495c42c08fc786dd87ac4fa Mon Sep 17 00:00:00 2001
From: tomrink <rink@ssec.wisc.edu>
Date: Tue, 3 May 2022 14:49:52 -0500
Subject: [PATCH] snapshot...

---
 modules/icing/util.py | 51 ++++++++++++++++++++++++++-----------------
 1 file changed, 31 insertions(+), 20 deletions(-)

diff --git a/modules/icing/util.py b/modules/icing/util.py
index 2b9ef39d..d60b2055 100644
--- a/modules/icing/util.py
+++ b/modules/icing/util.py
@@ -50,6 +50,7 @@ def run_icing_predict(clvrx_dir='/Users/tomrink/data/clavrx/RadC/', output_dir=h
                       day_model_path=model_path_day, night_model_path=model_path_night,
                       prob_thresh=0.5, satellite='GOES16', domain='CONUS', day_night='AUTO',
                       l1b_andor_l2='l2', use_flight_altitude=True, res_fac=1, use_nan=False, has_time=False, model_type='FCN'):
+
     if model_type == 'CNN':
         model_module = icing_cnn
     elif model_type == 'FCN':
@@ -72,8 +73,11 @@ def run_icing_predict(clvrx_dir='/Users/tomrink/data/clavrx/RadC/', output_dir=h
 
     if satellite == 'H08':
         clvrx_ds = CLAVRx_H08(clvrx_dir)
-    else:
+    elif satellite == 'GOES16':
         clvrx_ds = CLAVRx(clvrx_dir)
+    elif satellite == 'VIIRS':
+        clvrx_ds = CLAVRx_VIIRS(clvrx_dir)
+
     clvrx_files = clvrx_ds.flist
 
     for fidx, fname in enumerate(clvrx_files):
@@ -82,21 +86,27 @@ def run_icing_predict(clvrx_dir='/Users/tomrink/data/clavrx/RadC/', output_dir=h
         ts = dto.timestamp()
         clvrx_str_time = dto.strftime('%Y-%m-%d_%H:%M')
 
-        data_dct, ll, cc = make_for_full_domain_predict(h5f, name_list=train_params, satellite=satellite, domain=domain, res_fac=res_fac)
+        if satellite == 'GOES16' or satellite == 'H08':
+            data_dct, ll, cc = make_for_full_domain_predict(h5f, name_list=train_params, satellite=satellite, domain=domain, res_fac=res_fac)
 
-        if fidx == 0:
-            num_elems = len(cc)
-            num_lines = len(ll)
-            nav = get_navigation(satellite, domain)
-            lons_2d, lats_2d, x_rad, y_rad = get_lon_lat_2d_mesh(nav, ll, cc, offset=int(8 / res_fac))
+            if fidx == 0:  # These don't change for geostationary fixed grids
+                nav = get_navigation(satellite, domain)
+                lons_2d, lats_2d, x_rad, y_rad = get_lon_lat_2d_mesh(nav, ll, cc, offset=int(8 / res_fac))
 
-        ancil_data_dct, _, _ = make_for_full_domain_predict(h5f, name_list=
-                            ['solar_zenith_angle', 'sensor_zenith_angle', 'cld_height_acha', 'cld_geo_thick', 'temp_10_4um_nom'],
-                            satellite=satellite, domain=domain, res_fac=res_fac)
+            ancil_data_dct, _, _ = make_for_full_domain_predict(h5f, name_list=
+                                ['solar_zenith_angle', 'sensor_zenith_angle', 'cld_height_acha', 'cld_geo_thick', 'temp_10_4um_nom'],
+                                satellite=satellite, domain=domain, res_fac=res_fac)
+        elif satellite == 'VIIRS':
+            data_dct, ll, cc, lats_2d, lons_2d = make_for_full_domain_predict_viirs_clavrx(h5f, name_list=train_params, res_fac=res_fac)
+            ancil_data_dct, _, _, _, _ = make_for_full_domain_predict_viirs_clavrx(h5f, name_list=
+                                ['solar_zenith_angle', 'sensor_zenith_angle', 'cld_height_acha', 'cld_geo_thick', 'temp_11_0um_nom'],
+                                res_fac=res_fac)
+
+        num_elems, num_lines = len(cc), len(ll)
 
         satzen = ancil_data_dct['sensor_zenith_angle']
         solzen = ancil_data_dct['solar_zenith_angle']
-        bt_10_4 = ancil_data_dct['temp_10_4um_nom']
+        bt_10_4 = ancil_data_dct['temp_11_0um_nom']
         day_idxs = []
         nght_idxs = []
         avg_bt = []
@@ -185,15 +195,16 @@ def run_icing_predict(clvrx_dir='/Users/tomrink/data/clavrx/RadC/', output_dir=h
         avg_bt = np.array(avg_bt)
         bt_10_4_2d = avg_bt.reshape((num_lines, num_elems))
 
-        # write_icing_file_nc4(clvrx_str_time, output_dir, preds_2d_dct, probs_2d_dct,
-        #                      x_rad, y_rad, lons_2d, lats_2d, cc, ll,
-        #                      satellite=satellite, domain=domain, use_nan=use_nan, has_time=has_time,
-        #                      prob_thresh=prob_thresh, bt_10_4=bt_10_4_2d)
-
-        write_icing_file_nc4_viirs(clvrx_str_time, output_dir, preds_2d_dct, probs_2d_dct,
-                             lons_2d, lats_2d,
-                             satellite=satellite, domain=domain, use_nan=use_nan, has_time=has_time,
-                             prob_thresh=prob_thresh, bt_10_4=bt_10_4_2d)
+        if satellite == 'GOES16' or satellite == 'H08':
+            write_icing_file_nc4(clvrx_str_time, output_dir, preds_2d_dct, probs_2d_dct,
+                                 x_rad, y_rad, lons_2d, lats_2d, cc, ll,
+                                 satellite=satellite, domain=domain, use_nan=use_nan, has_time=has_time,
+                                 prob_thresh=prob_thresh, bt_10_4=bt_10_4_2d)
+        elif satellite == 'VIIRS':
+            write_icing_file_nc4_viirs(clvrx_str_time, output_dir, preds_2d_dct, probs_2d_dct,
+                                       lons_2d, lats_2d,
+                                       use_nan=use_nan, has_time=has_time,
+                                       prob_thresh=prob_thresh, bt_10_4=bt_10_4_2d)
 
         print('Done: ', clvrx_str_time)
         h5f.close()
-- 
GitLab