From ce61d369c03667e35b91265cc48f107c6fac1b13 Mon Sep 17 00:00:00 2001
From: Paolo Veglio <paolo.veglio@ssec.wisc.edu>
Date: Thu, 22 Dec 2022 17:22:29 +0000
Subject: [PATCH] removed CLDMSK from inputs. fixed the code to run within the
 sips delivery

---
 hires_module.py | 63 +++++++++++++++++++++++++++++++++----------------
 scene.py        | 12 +++++-----
 setup.py        | 11 +++++----
 sort_inputs.py  |  5 ++--
 4 files changed, 59 insertions(+), 32 deletions(-)

diff --git a/hires_module.py b/hires_module.py
index 97936bf..e8134a0 100644
--- a/hires_module.py
+++ b/hires_module.py
@@ -1,6 +1,7 @@
 import numpy as np
 import xarray as xr
 import netCDF4 as nc
+import sys
 
 from glob import glob
 
@@ -22,13 +23,18 @@ importlib.reload(tst)
 # TEST CASE
 # data:
 _datapath = '/ships19/hercules/pveglio/mvcm_viirs_hires'
-_fname_mod02 = glob(f'{_datapath}/VNP02MOD.A2022173.1454.001.*.uwssec_bowtie_corrected.nc')[0]
-_fname_mod03 = glob(f'{_datapath}/VNP03MOD.A2022173.1454.001.*.uwssec.nc')[0]
-_fname_img02 = glob(f'{_datapath}/VNP02IMG.A2022173.1454.001.*.uwssec_bowtie_corrected.nc')[0]
-_fname_img03 = glob(f'{_datapath}/VNP03IMG.A2022173.1454.001.*.uwssec.nc')[0]
+#_fname_mod02 = glob(f'{_datapath}/VNP02MOD.A2022173.1454.001.*.uwssec_bowtie_corrected.nc')[0]
+#_fname_mod03 = glob(f'{_datapath}/VNP03MOD.A2022173.1454.001.*.uwssec.nc')[0]
+#_fname_img02 = glob(f'{_datapath}/VNP02IMG.A2022173.1454.001.*.uwssec_bowtie_corrected.nc')[0]
+#_fname_img03 = glob(f'{_datapath}/VNP03IMG.A2022173.1454.001.*.uwssec.nc')[0]
+_fname_mod02 = ''
+_fname_mod03 = ''
+_fname_img02 = ''
+_fname_img03 = ''
 
 # MVCM output
-_cld_mask = f'{_datapath}/CLDMSK_L2_VIIRS_SNPP.A2022173.1454.001.2022174035130.nc'
+#_cld_mask = f'{_datapath}/CLDMSK_L2_VIIRS_SNPP.A2022173.1454.001.2022174035130.nc'
+_cld_mask = ''
 
 # thresholds:
 _threshold_file = '/home/pveglio/mvcm/thresholds.mvcm.snpp.v0.0.1.yaml'
@@ -60,14 +66,14 @@ def main(*,
          geos_constants: str = _geos_constants,
          ndvi_file: str = _ndvi_file,
          sst_file: str = _sst_file,
-         cloud_mask_file: str = _cld_mask,
+#         cloud_mask_file: str = _cld_mask,
          out_fname: str = 'temp.nc') -> None:
 
-    f = nc.Dataset(cloud_mask_file)
+#    f = nc.Dataset(cloud_mask_file)
 
-    cm = f['geophysical_data/Cloud_Mask'][:]
+#    cm = f['geophysical_data/Cloud_Mask'][:]
 
-    f.close()
+#    f.close()
     check = nc.Dataset(mod02)
     if 'M01' not in list(check['observation_data'].variables):
         check.close()
@@ -76,6 +82,7 @@ def main(*,
     if check.isopen():
         check.close()
 
+    print(threshold_file)
     with open(threshold_file) as f:
         text = f.read()
     thresholds = yml.safe_load(text)
@@ -100,14 +107,14 @@ def main(*,
     if 'I01' not in viirs_data:
         return
 
-    cm_flag = np.array((np.array(cm[0, :, :], np.byte) &
-                       (pow(2, 1) + pow(2, 2)))/pow(2, 1))
-
-    mvcm_conf = np.ones(cm_flag.shape)
-    # conf[cm_flag == 3] = 1
-    mvcm_conf[cm_flag == 2] = 0.95
-    mvcm_conf[cm_flag == 1] = 0.66
-    mvcm_conf[cm_flag == 0] = 0
+#    cm_flag = np.array((np.array(cm[0, :, :], np.byte) &
+#                       (pow(2, 1) + pow(2, 2)))/pow(2, 1))
+#
+#    mvcm_conf = np.ones(cm_flag.shape)
+#    # conf[cm_flag == 3] = 1
+#    mvcm_conf[cm_flag == 2] = 0.95
+#    mvcm_conf[cm_flag == 1] = 0.66
+#    mvcm_conf[cm_flag == 0] = 0
 
     viirs_lores = rd.read_data('viirs', mod02, data_path + '/' + mod03)
 
@@ -171,11 +178,11 @@ def main(*,
     date = mod02.split('.')[1]
     time = mod02.split('.')[2]
 
-    mvcm_confidence = mvcm_conf.repeat(2, 0).repeat(2, 1)
+#    mvcm_confidence = mvcm_conf.repeat(2, 0).repeat(2, 1)
     out_xr = xr.Dataset(
                 data_vars=dict(
                     hires_confidence=(['number_of_lines', 'number_of_pixels'], confidence),
-                    mvcm_confidence=(['number_of_lines', 'number_of_pixels'], mvcm_confidence),
+ #                   mvcm_confidence=(['number_of_lines', 'number_of_pixels'], mvcm_confidence),
                     ocean_day_mask=(['number_of_lines', 'number_of_pixels'], viirs_data.Ocean_Day.values),
                     ),
                 coords=dict(
@@ -215,4 +222,20 @@ def read_bits(byte, bits):
 
 
 if __name__ == "__main__":
-    main()
+    main(data_path=sys.argv[1],
+         mod02=sys.argv[2],
+         mod03=sys.argv[3],
+         img02=sys.argv[4],
+         img03=sys.argv[5],
+         threshold_file=sys.argv[6],
+         geos_atm_1=sys.argv[7],
+         geos_atm_2=sys.argv[8],
+         geos_land=sys.argv[9],
+         geos_ocean=sys.argv[10],
+         geos_constants=sys.argv[11],
+         ndvi_file=sys.argv[12],
+         sst_file=sys.argv[13],
+#         cloud_mask_file=sys.argv[14],
+         out_fname=sys.argv[14])
+
+
diff --git a/scene.py b/scene.py
index 0e37c57..c921417 100644
--- a/scene.py
+++ b/scene.py
@@ -38,14 +38,14 @@ night = 200
 # #################################################################### #
 # TEST CASE
 # data:
-datapath = '/ships19/hercules/pveglio/mvcm_viirs_hires'
-fname_mod02 = glob(f'{datapath}/VNP02MOD.A2022173.1448.001.*.uwssec*.nc')[0]
-fname_mod03 = glob(f'{datapath}/VNP03MOD.A2022173.1448.001.*.uwssec.nc')[0]
-fname_img02 = glob(f'{datapath}/VNP02IMG.A2022173.1448.001.*.uwssec*.nc')[0]
-fname_img03 = glob(f'{datapath}/VNP03IMG.A2022173.1448.001.*.uwssec.nc')[0]
+#datapath = '/ships19/hercules/pveglio/mvcm_viirs_hires'
+#fname_mod02 = glob(f'{datapath}/VNP02MOD.A2022173.1448.001.*.uwssec*.nc')[0]
+#fname_mod03 = glob(f'{datapath}/VNP03MOD.A2022173.1448.001.*.uwssec.nc')[0]
+#fname_img02 = glob(f'{datapath}/VNP02IMG.A2022173.1448.001.*.uwssec*.nc')[0]
+#fname_img03 = glob(f'{datapath}/VNP03IMG.A2022173.1448.001.*.uwssec.nc')[0]
 
 # thresholds:
-threshold_file = '/home/pveglio/mvcm_leo/thresholds/new_thresholds.mvcm.snpp.v1.0.0.yaml'
+#threshold_file = '/home/pveglio/mvcm_leo/thresholds/new_thresholds.mvcm.snpp.v1.0.0.yaml'
 
 # ancillary files:
 geos_atm_1 = 'GEOS.fpit.asm.inst3_2d_asm_Nx.GEOS5124.20220622_1200.V01.nc4'
diff --git a/setup.py b/setup.py
index b55c6ff..192f920 100644
--- a/setup.py
+++ b/setup.py
@@ -26,12 +26,15 @@ sourcefiles = ['src/get_Reynolds_SST.c',      # SST
                ]
 
 include_dirs = ['include',
-                '/opt/hdfeos2/2.20-gcc-8.3/include',
-                '/opt/netcdf4/4.7.0-gcc-8.3/include',
+                '/opt/hdf4/4.2.9-gcc-4.9.2/include',
+                '/opt/hdfeos2/2.19-gcc-4.9.2/include',
+                '/opt/netcdf4/4.3.3-gcc-4.9.2/include',
                 numpy.get_include(), ]
 
-library_dirs = ['/opt/hdfeos2/2.20-gcc-8.3/lib',
-                '/opt/netcdf4/4.7.0fcc-8.3/lib']
+library_dirs = ['/opt/hdf4/4.2.9-gcc-4.9.2/lib',
+                '/opt/hdfeos2/2.19-gcc-4.9.2/lib',
+                '/opt/netcdf4/4.3.3-gcc-4.9.2/lib',
+                ]
 
 extensions = [Extension('ancillary_data', sourcefiles,
                         include_dirs=include_dirs,
diff --git a/sort_inputs.py b/sort_inputs.py
index 1734c20..df8a9ac 100644
--- a/sort_inputs.py
+++ b/sort_inputs.py
@@ -63,7 +63,8 @@ def create_filenames(vnp02mod_fname):
                   'data_path': datapath,
                   'cloud_mask_file': cld_msk
                   }
-
+    for k in list(out_fnames):
+        print(f'{k}: {out_fnames[k]}')
     return out_fnames
 
 
@@ -93,4 +94,4 @@ def call_mvcm():
 
 
 if __name__ == "__main__":
-    call_mvcm()
+    create_filenames
-- 
GitLab