From 47b242d571730e8ef3b067f4776a70fe8a92b1c5 Mon Sep 17 00:00:00 2001
From: Paolo Veglio <paolo.veglio@ssec.wisc.edu>
Date: Wed, 10 May 2023 18:47:11 +0000
Subject: [PATCH] first implementation of the input layer for the code

---
 mvcm/cli_mvcm.py       | 112 ++++++++++++
 mvcm/main.py           | 377 +++--------------------------------------
 mvcm/read_data.py      |   2 +-
 mvcm/restoral.py       |   2 +-
 mvcm/spectral_tests.py |   2 +-
 pyproject.toml         |   3 +
 6 files changed, 137 insertions(+), 361 deletions(-)
 create mode 100644 mvcm/cli_mvcm.py

diff --git a/mvcm/cli_mvcm.py b/mvcm/cli_mvcm.py
new file mode 100644
index 0000000..0253013
--- /dev/null
+++ b/mvcm/cli_mvcm.py
@@ -0,0 +1,112 @@
+import argparse
+
+from glob import glob
+
+from mvcm.main import main
+
+_datapath = '/ships19/hercules/pveglio/mvcm_viirs_hires'
+_fname_mod02 = glob(f'{_datapath}/VNP02MOD.A2022173.1312.001.*.uwssec_bowtie_corrected.nc')[0]
+_fname_mod03 = glob(f'{_datapath}/VNP03MOD.A2022173.1312.001.*.uwssec.nc')[0]
+_fname_img02 = glob(f'{_datapath}/VNP02IMG.A2022173.1312.001.*.uwssec_bowtie_corrected.nc')[0]
+_fname_img03 = glob(f'{_datapath}/VNP03IMG.A2022173.1312.001.*.uwssec.nc')[0]
+
+# thresholds:
+_threshold_file = '/home/pveglio/mvcm/thresholds/thresholds.mvcm.snpp.v0.0.1.yaml'
+
+# ancillary files:
+_geos_atm_1 = 'GEOS.fpit.asm.inst3_2d_asm_Nx.GEOS5124.20220622_1200.V01.nc4'
+_geos_atm_2 = 'GEOS.fpit.asm.inst3_2d_asm_Nx.GEOS5124.20220622_1500.V01.nc4'
+_geos_land = 'GEOS.fpit.asm.tavg1_2d_lnd_Nx.GEOS5124.20220622_1330.V01.nc4'
+_geos_ocean = 'GEOS.fpit.asm.tavg1_2d_ocn_Nx.GEOS5124.20220622_1330.V01.nc4'
+_geos_constants = 'GEOS.fp.asm.const_2d_asm_Nx.00000000_0000.V01.nc4'
+_ndvi_file = 'NDVI.FM.c004.v2.0.WS.00-04.177.hdf'
+_sst_file = 'oisst.20220622'
+_eco_file = 'goge1_2_img.v1'
+
+
+def mvcm():
+
+    parser = argparse.ArgumentParser(prog='MVCM', description='')
+
+    parser.add_argument('--satellite',
+                        help='satellite name, not case-sensitive. Available options: [snpp, ]',
+                        choices=['snpp', ])
+    parser.add_argument('--sensor',
+                        help='sensor name, not case-sensitive. Available options: [viirs, ]',
+                        choices=['viirs', ])
+    parser.add_argument('--path',
+                        help='path where the data is stored')
+    parser.add_argument('--l1b',
+                        help='level 1b file name')
+    parser.add_argument('--geolocation',
+                        help='geolocation file name')
+    parser.add_argument('--hires_l1b',
+                        help='VIIRS IMG02 file name')
+    parser.add_argument('--hires_geo',
+                        help='VIIRS IMG03 file name')
+    parser.add_argument('-t', '--threshold',
+                        help='thresholds file name')
+    parser.add_argument('--atmos_1',
+                        help='file name of the first GEOS-IT file for atmospheric parameters')
+    parser.add_argument('--atmos_2',
+                        help='file name of the second GEOS-IT file for atmospheric parameters')
+    parser.add_argument('--land',
+                        help='file name of GEOS-IT land parameters')
+    parser.add_argument('--ocean',
+                        help='file name of GEOS-IT ocean parameters')
+    parser.add_argument('--constants',
+                        help='file name of GEOS-IT constants')
+    parser.add_argument('--ndvi',
+                        help='NDVI file name')
+    parser.add_argument('--sst',
+                        help='Sea surface temperature file name')
+    parser.add_argument('--eco',
+                        help='Ecosystem file')
+    parser.add_argument('-o', '--out',
+                        help='output file name')
+    parser.add_argument('-V', '--version', action='version', version='',
+                        help='print version and exit')
+    parser.add_argument('-v', '--verbose', action='store_true',
+                        help='print verbose information')
+
+    args = parser.parse_args()
+
+    satellite = args.satellite or 'snpp'
+    sensor = args.sensor or 'viirs'
+    data_path = args.path or _datapath
+    mod02 = args.l1b or _fname_mod02
+    mod03 = args.geolocation or _fname_mod03
+    img02 = args.hires_l1b or None
+    img03 = args.hires_geo or None
+    threshold_file = args.threshold or _threshold_file
+    geos_atm_1 = args.atmos_1 or _geos_atm_1
+    geos_atm_2 = args.atmos_2 or _geos_atm_2
+    geos_land = args.land or _geos_land
+    geos_ocean = args.ocean or _geos_ocean
+    constants = args.constants or _geos_constants
+    ndvi_file = args.ndvi or _ndvi_file
+    sst_file = args.sst or _sst_file
+    eco_file = args.eco or _eco_file
+    out_file = args.out or 'test_out.nc'
+    verbose = args.verbose or False
+
+    main(satellite=satellite,
+         sensor=sensor,
+         data_path=data_path,
+         mod02=mod02,
+         mod03=mod03,
+         img02=img02,
+         img03=img03,
+         threshold_file=threshold_file,
+         geos_atm_1=geos_atm_1,
+         geos_atm_2=geos_atm_2,
+         geos_land=geos_land,
+         geos_ocean=geos_ocean,
+         geos_constants=constants,
+         ndvi_file=ndvi_file,
+         sst_file=sst_file,
+         eco_file=eco_file,
+         out_file=out_file,
+         verbose=verbose)
+
+
diff --git a/mvcm/main.py b/mvcm/main.py
index 6f7cd1f..c0aaa7f 100644
--- a/mvcm/main.py
+++ b/mvcm/main.py
@@ -45,9 +45,6 @@ _eco_file = 'goge1_2_img.v1'
 # #################################################################### #
 
 
-logging.basicConfig(level=logging.INFO)
-
-
 def timer(func):
     @functools.wraps(func)
     def wrapper_timer(*args, **kwargs):
@@ -76,7 +73,9 @@ def main(satellite: str = 'snpp',
          geos_constants: str = _geos_constants,
          ndvi_file: str = _ndvi_file,
          sst_file: str = _sst_file,
-         eco_file: str = _eco_file) -> None:
+         eco_file: str = _eco_file,
+         out_file: str = 'temp_out.nc',
+         verbose: bool = False) -> None:
     """Main function for the MVCM.
 
     Parameters
@@ -99,7 +98,6 @@ def main(satellite: str = 'snpp',
         thresholds file name
     geos_atm_1: str
         file name of first GEOS5 file for atmospheric parameters
-
     goes_atm_2: str
         file name of second GEOS5 file for atmospheric parameters
     geos_land: str
@@ -114,12 +112,19 @@ def main(satellite: str = 'snpp',
         Sea surface temperature file name
     eco_file: str
         Ecosystem File
+    out_file: str
+        Output file name
 
     Returns
     -------
     None
     """
 
+    if verbose is True:
+        logging.basicConfig(level=logging.INFO)
+    else:
+        logging.basicConfig(level=logging.WARNING)
+
     file_names = {'MOD02': f'{mod02}',
                   'MOD03': f'{mod03}',
                   'IMG02': f'{img02}',
@@ -141,10 +146,12 @@ def main(satellite: str = 'snpp',
 
     #################
     #################
-    use_hires = False
+    if (img02 is None or img03 is None):
+        use_hires = False
+    else:
+        use_hires = True
     #################
     #################
-    # viirs_data = rd.get_data(satellite, sensor, file_names, hires=True)
     viirs_data = rd.get_data(satellite, sensor, file_names, hires=use_hires)
 
     sunglint_angle = thresholds['Sun_Glint']['bounds'][3]
@@ -265,30 +272,7 @@ def main(satellite: str = 'snpp',
 
     cmin_final = np.min(cmin_3d, axis=0)
     # bit['15'] = np.max(temp_bit, axis=0)
-    '''
-    sunglint_bits = bit['01'] * bit['03'] * bit['05'] * bit['15']
-    sh_water_bits = {'ir': bit['01'] * bit['05'],
-                     'nir_1': bit['10'],
-                     'nir_2': bit['15'],
-                     'sst': bit['03']
-                     }
-    land_bits = bit['15'] * bit['05']
-    # make sure that the land_bits are calculated properly
-    idx = np.nonzero(scene_flags['desert'] == 0)
-    land_bits[idx] = land_bits[idx] * bit['10'][idx] * bit['07'][idx] * bit['11'][idx]
-    coast_bits = bit['05']
-    land_night_bits = bit['16']
-
-    idx = np.nonzero((scene_flags['uniform'] == 1) & (scene_flags['water'] == 1) &
-                     (scene_flags['ice'] == 0) & (cmin >= 0.05) & (cmin <= 0.99))
-    cmin[idx] = Restore.spatial_variability(cmin)[idx]
 
-    idx = np.nonzero((scene_flags['day'] == 1) & (scene_flags['water'] == 1) &
-                     (scene_flags['uniform'] == 1) & (scene_flags['sunglint'] == 1) &
-                     (cmin <= 0.95))
-    print(len(idx[0]))
-    cmin[idx] = Restore.sunglint(sunglint_bits, cmin)[idx]
-    '''
     '''
     idx = np.nonzero((scene_flags['day'] == 1) & (scene_flags['water'] == 1) &
                      (scene_flags['ice'] == 0))
@@ -377,334 +361,11 @@ def main(satellite: str = 'snpp',
     sf = {k: {'dims': ('x', 'y'), 'data': scene_flags[k]} for k in scene_flags}
     out_dict = d | sf
     ds_out = xr.Dataset.from_dict(out_dict)
-    ds_out.to_netcdf('test_w_restorals.nc')
-    # ds_out.to_netcdf('test_hires.nc')
-    # np.savez('test_w_restorals', confidence=cmin, scene_flags=scene_flags,
-    #          lat=viirs_data.latitude.values, lon=viirs_data.longitude.values)
-
-    ##########################################################
-
-    """
-    # ------------------- #
-    # ### Testing Setup ###
-    # ------------------- #
-
-    perform = {'11um BT Test': True,
-               'CO2 High Clouds Test': False,
-               'Water Vapor High Clouds Test': False,
-               'Surface Temperature Test': False,
-               'SST Test': False,
-               '8.6-11um BT Difference Test': False,
-               '11-12um BTD Thin Cirrus Test': False,
-               '11-4um BT Difference Test': False,
-               '7.3-11um BT Difference Mid-level Clouds': False,
-               'Water Vapor Cloud Test': False,
-               '11um BT Variability Test': False,
-               '11-4um BTD Oceanic Stratus': False,
-               'NIR Reflectance Test': False,
-               'Vis/NIR Ratio Test': False,
-               '1.6um or 2.1um NIR Reflectance Test': False,
-               'Visible Reflectance Test': False,
-               'GEMI Test': False,
-               '1.38um High Cloud Test': False,
-               '4-12um BTD Thin Cirrus Test': False
-               }
-
-    # --------------------- #
-    # ### Group 1 Tests ### #
-    # --------------------- #
-
-    if perform['11um BT Test'] is True:
-        # 11um BT Test
-        for scene_name in ['Ocean_Day', 'Ocean_Night', 'Polar_Ocean_Day', 'Polar_Ocean_Night']:
-            SceneType = CloudTests(viirs_data, scene_name, thresholds)
-            cmin_G1 = SceneType.single_threshold_test('11um_Test', 'M15', cmin_G1)
-
-    if perform['CO2 High Clouds Test'] is True:
-        # CO2 High Clouds Test
-        for scene_name in ['Land_Day', 'Land_Night', 'Land_Day_Coast', 'Land_Day_Desert',
-                           'Land_Day_Desert_Coast', 'Ocean_Day', 'Ocean_Night', 'Day_Snow', 'Night_Snow']:
-            SceneType = CloudTests(viirs_data, scene_name, thresholds)
-            cmin_G1 = SceneType.single_threshold_test('CO2_High_Clouds_tests', 'bad_data', cmin_G1)
-
-    if perform['Water Vapor High Clouds Test'] is True:
-        # Water Vapor High Clouds Test
-        for scene_name in ['Land_Day', 'Land_Night', 'Land_Day_Coast', 'Land_Day_Desert',
-                           'Land_Day_Desert_Coast', 'Ocean_Day', 'Ocean_Night', 'Polar_Day_Land',
-                           'Polar_Night_Land', 'Polar_Day_Coast', 'Polar_Day_Desert',
-                           'Polar_Day_Desert_Coast', 'Polar_Day_Snow', 'Polar_Night_Snow', 'Polar_Ocean_Day',
-                           'Polar_Ocean_Night', 'Day_Snow', 'Night_Snow', 'Antarctic_Day']:
-            SceneType = CloudTests(viirs_data, scene_name, thresholds)
-            cmin_G1 = SceneType.single_threshold_test('Water_Vapor_High_Clouds_tests', 'bad_data', cmin_G1)
-
-    if perform['Surface Temperature Test'] is True:
-        # Surface Temperature Test
-        # NOTE: this test requires the thresholds to be preprocessed
-        for scene_name in ['Land_Night', 'Polar_Night_Land']:
-            SceneType = CloudTests(viirs_data, scene_name, thresholds)
-            cmin_G1 = SceneType.single_threshold_test('Surface_Temperature_Test', 'M15-M16', cmin_G1)
-
-    if perform['SST Test'] is True:
-        # SST Test
-        for scene_name in ['Ocean_Day', 'Ocean_Night', 'Polar_Ocean_Day', 'Polar_Ocean_Night']:
-            SceneType = CloudTests(viirs_data, scene_name, thresholds)
-            cmin_G1 = SceneType.single_threshold_test('SST_Test', 'M15-M16', cmin_G1)
-
-    # --------------------- #
-    # ### Group 2 tests ### #
-    # --------------------- #
-
-    if perform['8.6-11um BT Difference Test'] is True:
-        # 8.6-11um BT Difference Test
-        for scene_name in ['Ocean_Day', 'Ocean_Night', 'Polar_Ocean_Day', 'Polar_Ocean_Night']:
-            SceneType = CloudTests(viirs_data, scene_name, thresholds)
-            cmin_G2 = SceneType.single_threshold_test('8.6-11um_Test', 'M15-M14', cmin_G2)
-
-    if perform['11-12um BTD Thin Cirrus Test'] is True:
-        # 11-12um BT BTD Transmissive Cirrus Test
-        # NOTE: some of the tests have some differences in how the thresholds are derived
-        # The commented list scene_name is the complete list, the one currently in use is to test that
-        # the template code works at least with a subset of scenes that have the same way of deriving the
-        # thresholds
-        # for scene_name in ['Land_Day', 'Land_Day_Coast', 'Land_Day_Desert', 'Land_Day_Desert_Coast',
-        #                    'Ocean_Day', 'Ocean_Night', 'Polar_Day_Land', 'Polar_Day_Coast',
-        #                    'Polar_Day_Desert', 'Polar_Day_Desert_Coast', 'Polar_Day_Snow', 'Polar_Night_Snow',
-        #                    'Polar_Ocean_Day', 'Polar_Ocean_Night', 'Day_Snow', 'Night_Snow']:
-        for scene_name in ['Land_Day', 'Land_Day_Coast', 'Land_Day_Desert', 'Land_Day_Desert_Coast',
-                           'Ocean_Day', 'Ocean_Night', 'Polar_Ocean_Day', 'Polar_Ocean_Night']:
-            SceneType = CloudTests(viirs_data, scene_name, thresholds)
-            cmin_G2 = SceneType.single_threshold_test('11-12um_Cirrus_Test', 'M15-M16', cmin_G2)
-
-    if perform['11-4um BT Difference Test'] is True:
-        # 11-4um BT Difference Test
-        for scene_name in ['Ocean_Night', 'Polar_Ocean_Night']:
-            pass
-
-    if perform['7.3-11um BT Difference Mid-level Clouds'] is True:
-        for scene_name in ['Land_Night', 'Polar_Night_Land', 'Polar_Night_Snow', 'Night_Snow']:
-            pass
-
-    if perform['Water Vapor Cloud Test'] is True:
-        for scene_name in ['Polar_Night_Ocean']:
-            pass
-
-    if perform['11um BT Variability Test'] is True:
-        for scene_name in ['Ocean_Night', 'Polar_Night_Ocean']:
-            pass
-
-    if perform['11-4um BTD Oceanic Stratus'] is True:
-        # 11-4um BT Difference for oceanic stratus (low emissivity water cloud) Test
-        for scene_name in ['Land_Day', 'Land_Day_Coast', 'Land_Day_Desert', 'Land_Day_Desert_Coast',
-                           'Ocean_Day', 'Ocean_Night', 'Polar_Day_Land', 'Polar_Day_Coast',
-                           'Polar_Day_Desert', 'Polar_Day_Desert_Coast', 'Polar_Day_Snow', 'Polar_Night_Snow',
-                           'Polar_Ocean_Day', 'Polar_Ocean_Night', 'Day_Snow', 'Night_Snow']:
-            SceneType = CloudTests(viirs_data, scene_name, thresholds)
-            cmin_G2 = SceneType.single_threshold_test('11-4um_Oceanic_Stratus_Test', 'M15-M13', cmin_G2)
-
-    # --------------------- #
-    # ### Group 3 tests ### #
-    # --------------------- #
-
-    if perform['NIR Reflectance Test'] is True:
-        for scene_name in ['Ocean_Day', 'Polar_Ocean_Day']:
-            SceneType = CloudTests(viirs_data, scene_name, thresholds)
-            cmin_G3 = SceneType.single_thredhold_test('NIR_Reflectance_Test', 'M07', cmin_G3)
-
-    if perform['Vis/NIR Ratio Test'] is True:
-        for scene_name in ['Ocean_Day', 'Polar_Ocean_Day']:
-            pass
-
-    if perform['1.6um or 2.1um NIR Reflectance Test'] is True:
-        for scene_name in ['Ocean_Day', 'Polar_Ocean_Day']:
-            pass
-
-    if perform['Visible Reflectance Test'] is True:
-        for scene_name in ['Land_Day', 'Land_Day_Coast', 'Land_Day_Desert', 'Land_Day_Desert_Coast',
-                           'Polar_Day_Land', 'Polar_Day_Coast', 'Polar_Day_Desert', 'Polar_Day_Desert_Coast']:
-            pass
-
-    if perform['GEMI Test'] is True:
-        for scene_name in ['Land_Day_Desert', 'Polar_Day_Desert']:
-            pass
-
-    # --------------------- #
-    # ### Group 4 tests ### #
-    # --------------------- #
-
-    if perform['1.38um High Cloud Test'] is True:
-        # for scene_name in ['Land_Day', 'Land_Day_Coast', 'Land_Day_Desert', 'Land_Day_Desert_Coast',
-        #                    'Ocean_Day', 'Polar_Day_Land', 'Polar_Day_Coast', 'Polar_Day_Desert',
-        #                    'Polar_Day_Desert_Coast', 'Polar_Ocean_Day', 'Day_Snow']:
-        for scene_name in ['Land_Day', 'Land_Day_Coast', 'Land_Day_Desert', 'Land_Day_Desert_Coast',
-                           'Polar_Day_Land', 'Polar_Day_Coast', 'Polar_Day_Desert',
-                           'Polar_Day_Desert_Coast', 'Day_Snow']:
-            # The current loop is missing Ocean_Day and Polar_Ocean_Day because they need some
-            # preprocessing to compute the thresholds. Once things are implemented I can use the commented
-            # loop
-            SceneType = CloudTests(viirs_data, scene_name, thresholds)
-            cmin_G4 = SceneType.single_threshold_test('1.38um_High_Cloud_Test', 'M09', cmin_G4)
-
-    # --------------------- #
-    # ### Group 5 tests ### #
-    # --------------------- #
-
-    if perform['4-12um BTD Thin Cirrus Test'] is True:
-        for scene_name in ['Land_Night', 'Polar_Night_Land', 'Polar_Night_Snow', 'Night_Snow']:
-            pass
-
-    cmin_total = cmin_G1 * cmin_G2 * cmin_G3 * cmin_G4 * cmin_G5
-    return cmin_total
-    """
-
-    '''
-    Land_Day = CloudTests(viirs_data, 'Land_Day', thresholds)
-    Land_Night = CloudTests(viirs_data, 'Land_Night', thresholds)
-    Land_Day_Coast = CloudTests(viirs_data, 'Land_Day_Coast', thresholds)
-    Land_Day_Desert = CloudTests(viirs_data, 'Land_Day_Desert', thresholds)
-    Land_Day_Desert_Coast = CloudTests(viirs_data, 'Land_Day_Desert_Coast', thresholds)
-    Ocean_Day = CloudTests(viirs_data, 'Ocean_Day', thresholds)
-    Ocean_Night = CloudTests(viirs_data, 'Ocean_Night', thresholds)
-    Polar_Day_Land = CloudTests(viirs_data, 'Polar_Day_Land', thresholds)
-    Polar_Night_Land = CloudTests(viirs_data, 'Polar_Night_Land', thresholds)
-    Polar_Day_Coast = CloudTests(viirs_data, 'Polar_Day_Coast', thresholds)
-    Polar_Day_Desert = CloudTests(viirs_data, 'Polar_Day_Desert', thresholds)
-    Polar_Day_Desert_Coast = CloudTests(viirs_data, 'Polar_Day_Desert_Coast', thresholds)
-    Polar_Day_Snow = CloudTests(viirs_data, 'Polar_Day_Snow', thresholds)
-    Polar_Night_Snow = CloudTests(viirs_data, 'Polar_Night_Snow', thresholds)
-    Polar_Ocean_Day = CloudTests(viirs_data, 'Polar_Ocean_Day', thresholds)
-    Polar_Ocean_Night = CloudTests(viirs_data, 'Polar_Ocean_Night', thresholds)
-    Day_Snow = CloudTests(viirs_data, 'Day_Snow', thresholds)
-    Night_Snow = CloudTests(viirs_data, 'Night_Snow', thresholds)
-    Antarctic_Day = CloudTests(viirs_data, 'Antarctic_Day', thresholds)
-
-    # 11um BT Test
-    cmin_G1 = Ocean_Day.single_threshold_test('11um_Test', 'M15', cmin_G1)
-    cmin_G1 = Polar_Ocean_Day.single_threshold_test('11um_Test', 'M15', cmin_G1)
-    cmin_G1 = Polar_Ocean_Night.single_threshold_test('11um_Test', 'M15', cmin_G1)
-
-    # CO2 High Clouds Test
-    # NOTE: VIIRS doesn't have the MODIS equivalent of B35 so this test is not performed
-    cmin_G1 = Land_Day.single_threshold_test('CO2_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Land_Night.single_threshold_test('CO2_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Land_Day_Coast.single_threshold_test('CO2_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Land_Day_Desert.single_threshold_test('CO2_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Land_Day_Desert_Coast.single_threshold_test('CO2_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Ocean_Day.single_threshold_test('CO2_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Ocean_Night.single_threshold_test('CO2_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Day_Snow.single_threshold_test('CO2_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Night_Snow.single_threshold_test('CO2_High_Clouds_Test', 'bad_data', cmin_G1)
-
-    # Water Vapor High Clouds Test
-    # NOTE: VIIRS doesn't have the MODIS equivalent of B27 so this test is not performed
-    cmin_G1 = Land_Day.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Land_Night.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Land_Day_Coast.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Land_Day_Desert.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Land_Day_Desert_Coast.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Ocean_Day.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Ocean_Night.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Polar_Day_Land.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Polar_Night_Land.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Polar_Day_Coast.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Polar_Day_Desert.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Polar_Day_Desert_Coast.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Polar_Day_Snow.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Polar_Night_Snow.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Polar_Ocean_Day.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Polar_Ocean_Night.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Day_Snow.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Night_Snow.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-    cmin_G1 = Antarctic_Day.single_threshold_test('Water_Vapor_High_Clouds_Test', 'bad_data', cmin_G1)
-
-    # Surface Temperature Test
-    # ## NOTE: This requires some calculations for the thresholds.
-    # Moreover this test is using the 11um - 12um difference instead of a single channel
-    # Also, look at the test carefully for these two cases. Polar_Night_Land uses some hardcoded coeffs
-    # (i.e. *_df1 and *_df2) that might be worth moving in the thresholds file for consistency
-    cmin_G1 = Land_Night.single_threshold_test('Surface_Temperature_Test', 'M15-M16', cmin_G1)
-    cmin_G1 = Polar_Night_Land.single_threshold_test('Surface_Temperature_Test', 'M15-M16', cmin_G1)
-
-    # SST Test
-    # ## NOTE: This requires some calculations for the thresholds.
-    # Moreover this test is using the 11um - 12um difference instead of a single channel
-    cmin_G1 = Ocean_Day.single_threshold_test('SST_Test', 'M15-M16', cmin_G1)
-    cmin_G1 = Polar_Ocean_Day.single_threshold_test('SST_Test', 'M15-M16', cmin_G1)
-    cmin_G1 = Polar_Ocean_Night.single_threshold_test('SST_Test', 'M15-M16', cmin_G1)
-    # the following test uses a different set of coefficients compared to the others above
-    cmin_G1 = Ocean_Night.single_threshold_test('SST_Test', 'M15-M16', cmin_G1)
-
-    # 11-8.6um BT Difference Test
-    cmin_G2 = Ocean_Day.single_threshold_test('11-8.6um_Test', 'M15-M14', cmin_G2)
-    cmin_G2 = Ocean_Night.single_threshold_test('11-8.6um_Test', 'M15-M14', cmin_G2)
-    cmin_G2 = Polar_Ocean_Day.single_threshold_test('11-8.6um_Test', 'M15-M14', cmin_G2)
-    cmin_G2 = Polar_Ocean_Night.single_threshold_test('11-8.6um_Test', 'M15-M14', cmin_G2)
-
-    # 11-12um BT Difference
-    cmin_G1 = Ocean_Day.single_threshold_test('11-12BT_diff',
-                                              viirs_data.M15.values-viirs_data.M16.values,
-                                              cmin_G1)
-
-    Ocean_Night = CloudTests(viirs_data, 'Ocean_Night', thresholds)
-
-    cmin_G1 = Ocean_Night.single_threshold_test('11um_test', viirs_data.M15.values, cmin_G1)
-    cmin_G1 = Ocean_Night.single_threshold_test('11-12um_diff',
-                                                viirs_data.M15.values-viirs_data.M16.values,
-                                                cmin_G1)
-
-    c = np.ones((9, viirs_data['M01'].shape[0], viirs_data['M01'].shape[1]))
-    cmin1, c[0, :, :], bit1 = odt.simple_test(viirs_data.M15.values, thresholds['Daytime_Ocean']['bt11'], cmin1)
-    cmin1, c[1, :, :], bit2 = odt.sst_test(viirs_data.M15.values, viirs_data.M16.values,
-                                           viirs_data.sensor_zenith.values, viirs_data.geos_sfct.values,
-                                           thresholds['Daytime_Ocean']['sst'], cmin1)
-    cmin2, c[2, :, :], bit3 = odt.simple_test(viirs_data.M14.values-viirs_data.M15.values,
-                                              thresholds['Daytime_Ocean']['diff_11_86um'], cmin2)
-    cmin2, c[3, :, :], bit4 = odt.test_11_12_diff(viirs_data, thresholds['Daytime_Ocean']['diff11_12um'], cmin2)
-    cmin2, c[4, :, :] = odt.test_11_4_diff(viirs_data.M15.values, viirs_data.M12.values,
-                                           thresholds['Daytime_Ocean']['test11_4lo'], scene_flags, cmin2)
-    cmin3, c[5, :, :] = odt.nir_refl_test(viirs_data.M07.values, thresholds['Daytime_Ocean'],
-                                          thresholds['Sun_Glint'], viirs_data, cmin3)
-    cmin3, c[6, :, :] = odt.vis_nir_ratio_test(viirs_data.M05.values, viirs_data.M07.values,
-                                               thresholds, scene_flags, cmin3)
-    cmin3, c[7, :, :] = odt.nir_refl_test(viirs_data.M10.values, thresholds['Daytime_Ocean'],
-                                          thresholds['Sun_Glint'], viirs_data, cmin3)
-#
-#    confidence[0, :, :] = tests.test_11um(viirs_data.M15.values, thresholds['Daytime_Ocean'])
-#    confidence[1, :, :] = tests.test_11_4diff(viirs_data.M15.values, viirs_data.M13.values,
-#                                              thresholds['Daytime_Ocean'], viirs_data,
-#                                              thresholds['Sun_Glint']['bounds'][3])
-#
-#    confidence[2, :, :] = tests.nir_refl_test(viirs_data.M07.values, thresholds['Daytime_Ocean'],
-#                                              thresholds['Sun_Glint'], viirs_data)
-#
-#    # Note that here I'm using M05/M07 but the corresponding hi-res channels are I1/I2
-#    # IMPORTANT: conf_test_dble() needs to be verified. I don't think it's working as intended at the moment
-#    confidence[3, :, :] = tests.vis_nir_ratio_test(viirs_data.M05.values, viirs_data.M07.values,
-#                                                   thresholds['Daytime_Ocean'], thresholds['Sun_Glint'])
-#
-#    # This test needs to be verified, for the granule I'm running everything is zero
-#    confidence[4, :, :] = tests.test_11um_var(viirs_data.M15.values, thresholds['Nighttime_Ocean'],
-#                                              thresholds['Daytime_Ocean_Spatial_Variability'])
-
-    total_bit = bit1 + bit2 + bit4
-    temp_confidence = cmin1 * cmin2 * cmin3 * cmin4
-    confidence = cmin1 * cmin2 * cmin3 * cmin4
-    # idx = np.nonzero((scene_flags['water'] == 1) & (scene_flags['ice'] == 0) & (scene_flags['uniform'] == 1) &
-    #                  (confidence <= 0.99) & (confidence >= 0.05))
-    # confidence[idx] = restoral.spatial(viirs_data, thresholds['Sun_Glint'], scene_flags, confidence)[idx]
-
-    idx = np.nonzero((scene_flags['water'] == 1) & (scene_flags['sunglint'] == 1) &
-                     (scene_flags['uniform'] == 1) & (confidence <= 0.95))
-    confidence[idx] = restoral.sunglint(viirs_data, thresholds['Sun_Glint'], total_bit, temp_confidence)[idx]
-
-    temp = np.zeros((viirs_data.M01.shape[0], viirs_data.M01.shape[1]))
-    temp[idx] = 1
-    c[8, :, :] = temp
-
-    np.savez('test_confidence', confidence=confidence, conf_test=c,
-             lat=viirs_data.latitude.values, lon=viirs_data.longitude.values)
-
-    return confidence
-    '''
+    # if use_hires is False:
+    #     ds_out.to_netcdf('test_w_restorals.nc')
+    # else:
+    #     ds_out.to_netcdf('test_hires.nc')
+    ds_out.to_netcdf(out_file)
 
 
 def test_main():
diff --git a/mvcm/read_data.py b/mvcm/read_data.py
index a539dfa..a67c2ff 100644
--- a/mvcm/read_data.py
+++ b/mvcm/read_data.py
@@ -18,7 +18,7 @@ _datapath = '/ships19/hercules/pveglio/mvcm_test_data'
 _band_names = ['um0_41', 'um0_44', 'um0_49', 'um0_55', 'um0_64h', 'um0_67', 'um0_74', 'um0_86',
                'um0_86h', 'um1_24', 'um1_37', 'um1_61', 'um2_25', 'um3_70', 'um3_70h', 'um4_05',
                'um8_55', 'um10_76', 'um11_45h', 'um12_01']
-logger = logging.getLogger('__name__')
+logger = logging.getLogger(__name__)
 # logging.basicConfig(level=logging.INFO, format='%(name)s - %(levelname)s - %(message)s')
 # logging.basicConfig(level=logging.INFO, filename='logfile.log', 'filemode='w',
 #                       format='%(name)s %(levelname)s %(message)s')
diff --git a/mvcm/restoral.py b/mvcm/restoral.py
index 860acc7..8da1cf4 100644
--- a/mvcm/restoral.py
+++ b/mvcm/restoral.py
@@ -13,7 +13,7 @@ import mvcm.utility_functions as utils
 
 _bad_data = -999.0
 
-logger = logging.getLogger('__name__')
+logger = logging.getLogger(__name__)
 
 # tracking down the list of restoral tests that need to be implemented
 # and the function that gets called in the C code
diff --git a/mvcm/spectral_tests.py b/mvcm/spectral_tests.py
index 1b21786..dbdea14 100644
--- a/mvcm/spectral_tests.py
+++ b/mvcm/spectral_tests.py
@@ -31,7 +31,7 @@ importlib.reload(preproc)
 importlib.reload(conf)
 importlib.reload(restoral)
 
-logger = logging.getLogger('__name__')
+logger = logging.getLogger(__name__)
 
 
 def restoral_flag(bits):
diff --git a/pyproject.toml b/pyproject.toml
index b4c84ce..a2037e8 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -27,6 +27,9 @@ dependencies = [
     ]
 dynamic = ['version']
 
+[project.scripts]
+mvcm = "mvcm.cli_mvcm:mvcm"
+
 [tool.hatch.version]
 path = 'mvcm/__init__.py'
 
-- 
GitLab