From 13107c4ccf76d7344ea6026a2cc36b71bd4d192b Mon Sep 17 00:00:00 2001
From: tomrink <rink@ssec.wisc.edu>
Date: Thu, 12 May 2022 10:47:45 -0500
Subject: [PATCH] snapshot...

---
 modules/util/viirs.py | 57 ++++++++++++++++++++++++-------------------
 1 file changed, 32 insertions(+), 25 deletions(-)

diff --git a/modules/util/viirs.py b/modules/util/viirs.py
index d7c64d62..e17297be 100644
--- a/modules/util/viirs.py
+++ b/modules/util/viirs.py
@@ -10,32 +10,39 @@ img_res_params = ['M07_highres', 'M08_highres', 'M10_highres', 'M12_highres', 'M
 
 
 def run_all(directory):
-    mod_files = Path(directory).rglob('*.uwssec.nc')
 
-    mod_tiles = []
-    img_tiles = []
-
-    for idx, mfile in enumerate(mod_files):
-        if idx % 16 == 0:
-            w_o_ext, ext = os.path.splitext(mfile)
-            ifile = w_o_ext+'.highres'+ext
-            if not os.path.exists(ifile):
-                continue
-            print(mfile)
-            run(mfile, ifile, mod_tiles, img_tiles)
-
-    mod_nda = np.stack(mod_tiles)
-    img_nda = np.stack(img_tiles)
-
-    mod_mean = mod_nda.mean()
-    img_mean = img_nda.mean()
-    mod_std = mod_nda.std()
-    img_std = img_nda.std()
-
-    mod_nda = (mod_nda - mod_mean) / mod_std
-    img_nda = (img_nda - img_mean) / img_std
-
-    return mod_nda, img_nda
+    cnt = 0
+    for p in os.scandir(directory):
+        if not p.is_dir():
+            continue
+        cnt += 1
+        mod_files = glob.glob('*.uwssec.nc')
+
+        mod_tiles = []
+        img_tiles = []
+
+        for idx, mfile in enumerate(mod_files):
+            if idx % 16 == 0:
+                w_o_ext, ext = os.path.splitext(mfile)
+                ifile = w_o_ext+'.highres'+ext
+                if not os.path.exists(ifile):
+                    continue
+                print(mfile)
+                run(mfile, ifile, mod_tiles, img_tiles)
+
+        mod_nda = np.stack(mod_tiles)
+        img_nda = np.stack(img_tiles)
+
+        mod_mean = mod_nda.mean()
+        img_mean = img_nda.mean()
+        mod_std = mod_nda.std()
+        img_std = img_nda.std()
+
+        mod_nda = (mod_nda - mod_mean) / mod_std
+        img_nda = (img_nda - img_mean) / img_std
+
+    np.save('/data/Personal/rink/viirs/mod_res_'+cnt, mod_nda)
+    np.save('/data/Personal/rink/viirs/img_res_'+cnt, img_nda)
 
 
 def run(mod_res_filename, img_res_filename, mod_tiles, img_tiles):
-- 
GitLab