Newer
Older
import ruamel_yaml as yml
import numpy as np
import read_data as rd
import tests

Paolo Veglio
committed
# #################################################################### #
# TEST CASE
# data:
_datapath = '/ships19/hercules/pveglio/mvcm_viirs_hires'
_fname_mod02 = 'VNP02MOD.A2022173.0336.001.2022173154147.uwssec.nc'
_fname_mod03 = 'VNP03MOD.A2022173.0336.001.2022173155356.uwssec.nc'
_fname_img02 = 'VNP02IMG.A2022173.0336.001.2022173154147.uwssec.nc'
_fname_img03 = 'VNP03IMG.A2022173.0336.001.2022173155356.uwssec.nc'

Paolo Veglio
committed
# thresholds:
_threshold_file = '/home/pveglio/mvcm_leo/thresholds/new_thresholds.mvcm.snpp.v1.0.0.yaml'

Paolo Veglio
committed
# ancillary files:
_geos_atm_1 = 'GEOS.fpit.asm.inst3_2d_asm_Nx.GEOS5124.20220622_0300.V01.nc4'
_geos_atm_2 = 'GEOS.fpit.asm.inst3_2d_asm_Nx.GEOS5124.20220622_0600.V01.nc4'
_geos_land = 'GEOS.fpit.asm.tavg1_2d_lnd_Nx.GEOS5124.20220622_0330.V01.nc4'
_geos_ocean = 'GEOS.fpit.asm.tavg1_2d_ocn_Nx.GEOS5124.20220622_0330.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'

Paolo Veglio
committed
# #################################################################### #

Paolo Veglio
committed
def main(*, data_path=_datapath, mod02=_fname_mod02, mod03=_fname_mod03,
img02=_fname_img02, img03=_fname_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=_geos_constants, ndvi_file=_ndvi_file, sst_file=_sst_file):
# datapath = '/ships19/hercules/pveglio/neige_data/snpp_test_input'
# fname_l1b = 'VNP02MOD.A2014213.1548.001.2017301015346.uwssec.bowtie_restored_scaled.nc'
# fname_geo = 'VNP03MOD.A2014213.1548.001.2017301015705.uwssec.nc'
# thresh_file = '/home/pveglio/mvcm_leo/thresholds/new_thresholds.mvcm.snpp.v1.0.0.yaml'
ancillary_file_names = {'GEOS_atm_1': f'{data_path}/ancillary/{geos_atm_1}',
'GEOS_atm_2': f'{data_path}/ancillary/{geos_atm_2}',
'GEOS_land': f'{data_path}/ancillary/{geos_land}',
'GEOS_ocean': f'{data_path}/ancillary/{geos_ocean}',
'GEOS_constants': f'{data_path}/ancillary/{geos_constants}',
'NDVI': f'{data_path}/ancillary/{ndvi_file}',
'SST': f'{data_path}/ancillary/{sst_file}',
'ANC_DIR': f'{data_path}/ancillary'
}
viirs_data = rd.read_data('viirs', f'{data_path}/{mod02}', f'{data_path}/{mod03}')
viirs_data = rd.read_ancillary_data(ancillary_file_names, viirs_data)
with open(threshold_file) as f:
text = f.read()
thresholds = yml.safe_load(text)
confidence = np.zeros((5, viirs_data['M01'].shape[0], viirs_data['M01'].shape[1]))
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)

Paolo Veglio
committed
# 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'])
return confidence
def test_main():
rad1 = [[255, 260, 265, 248, 223],
[278, 285, 270, 268, 256],
[275, 273, 266, 254, 259]]
rad2 = [[270, 273, 271, 268, 265],
[277, 286, 275, 277, 269],
[280, 281, 272, 270, 267]]
thresh_file = '/home/pveglio/mvcm_leo/thresholds/new_thresholds.mvcm.snpp.v1.0.0.yaml'
with open(thresh_file) as f:
text = f.read()
rad1 = np.array(rad1)
rad2 = np.array(rad2)
confidence = np.zeros((2, rad1.shape[0], rad1.shape[1]))
thresholds = yml.safe_load(text)
confidence[0, :, :] = tests.test_11um(rad1, thresholds['Daytime_Ocean'])
confidence[1, :, :] = tests.test_11_4diff(rad1, rad2, thresholds['Daytime_Ocean'])
print(f'Confidence[0,:,:]: \n {confidence[0, :, :]}')
print(f'Confidence[1,:,:]: \n {confidence[1, :, :]}')
return confidence
if __name__ == "__main__":