From 74fd3bb64325dcfb5f146c4336b61db6d137908e Mon Sep 17 00:00:00 2001
From: tomrink <rink@ssec.wisc.edu>
Date: Mon, 23 May 2022 14:45:53 -0500
Subject: [PATCH] fix bug in scale method

---
 modules/util/viirs_l1b_l2.py | 58 +++++++++++++++++++-----------------
 1 file changed, 30 insertions(+), 28 deletions(-)

diff --git a/modules/util/viirs_l1b_l2.py b/modules/util/viirs_l1b_l2.py
index d6118919..e802b361 100644
--- a/modules/util/viirs_l1b_l2.py
+++ b/modules/util/viirs_l1b_l2.py
@@ -23,7 +23,8 @@ def run_all(directory):
         l2_tiles = []
 
         for idx, l1b_f in enumerate(l1b_files):
-            if idx % 8 == 0:
+            # if idx % 8 == 0:
+            if True:
                 # w_o_ext, ext = os.path.splitext(l1b_f)
                 # l2_f = w_o_ext+'.highres'+ext
                 # if not os.path.exists(l2_f):
@@ -87,42 +88,43 @@ def run(l1b_h5f, l2_h5f, l1b_tiles, l2_tiles, factor=2):
     l2_grd_s = []
 
     for param in emis_params:
-        l1b_grd_s.append(get_grid_values(l1b_h5f, param, 0, 0, None, mod_num_lines, mod_num_pixels, range_name=None))
+        try:
+            grd = get_grid_values(l1b_h5f, param, 0, 0, None, mod_num_lines, mod_num_pixels, range_name=None)
+            l1b_grd_s.append(grd)
+        except:
+            return
 
     for param in l2_params:
-        l2_grd_s.append(get_grid_values(l2_h5f, param, 0, 0, None, img_num_lines, img_num_pixels, range_name=None))
+        try:
+            grd = get_grid_values(l2_h5f, param, 0, 0, None, img_num_lines, img_num_pixels, range_name=None)
+            l2_grd_s.append(grd)
+        except:
+            return
 
     mod_data = np.stack(l1b_grd_s)
     img_data = np.stack(l2_grd_s)
 
-    num_cntr_tiles = 10
-    i_c = int(mod_num_pixels / num_cntr_tiles)  # center
-    j_skip = int(mod_num_y_tiles / num_cntr_tiles) * mod_tile_width
-    for k in range(num_cntr_tiles):
-        j_c = k * j_skip
+    num_keep_x_tiles = 5
+    i_skip = int(mod_num_x_tiles / num_keep_x_tiles) * mod_tile_width
+    i_start = int(mod_num_pixels / 2) + int((num_keep_x_tiles * 3 * 64) / 2)
+
+    num_keep_y_tiles = 16
+    j_skip = int(mod_num_y_tiles / num_keep_y_tiles) * mod_tile_width
+    for j in range(num_keep_y_tiles):
+        j_c = j * j_skip
         j_m = j_c
         j_i = j_m * factor
 
-        i_m = i_c
-        i_i = i_m * factor
-
-        nda = mod_data[:, j_m:j_m + mod_tile_width, i_m:i_m + mod_tile_width]
-        l1b_tiles.append(nda)
-
-        nda = img_data[:, j_i:j_i + img_tile_width, i_i:i_i + img_tile_width]
-        l2_tiles.append(nda)
-
-    # for j in range(mod_num_y_tiles):
-    #     j_m = j * mod_tile_width
-    #     j_i = j_m * 2
-    #     for i in range(mod_num_x_tiles):
-    #         i_m = i * mod_tile_width
-    #         i_i = i_m * 2
-    #
-    #         nda = mod_data[j_m:j_m+mod_tile_width, i_m:i_m+mod_tile_width]
-    #         mod_tiles.append(nda)
-    #         nda = img_data[j_i:j_i+img_tile_width, i_i:i_i+img_tile_width]
-    #         img_tiles.append(nda)
+        for i in range(num_keep_x_tiles):
+            i_c = i * i_skip + i_start
+            i_m = i_c
+            i_i = i_m * factor
+
+            nda = mod_data[:, j_m:j_m + mod_tile_width, i_m:i_m + mod_tile_width]
+            l1b_tiles.append(nda)
+
+            nda = img_data[:, j_i:j_i + img_tile_width, i_i:i_i + img_tile_width]
+            l2_tiles.append(nda)
 
 
 # def hack():
-- 
GitLab