Newer
Older
import ruamel_yaml as yml
import numpy as np
from glob import glob
import scene as scn
# import tests
import ocean_day_tests as odt

Paolo Veglio
committed
# #################################################################### #
# TEST CASE
# data:
_datapath = '/ships19/hercules/pveglio/mvcm_viirs_hires'
_fname_mod02 = glob(f'{_datapath}/VNP02MOD.A2022173.1454.001.*.uwssec.nc')[0]
_fname_mod03 = glob(f'{_datapath}/VNP03MOD.A2022173.1454.001.*.uwssec.nc')[0]
_fname_img02 = glob(f'{_datapath}/VNP02IMG.A2022173.1454.001.*.uwssec.nc')[0]
_fname_img03 = glob(f'{_datapath}/VNP03IMG.A2022173.1454.001.*.uwssec.nc')[0]

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_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_1430.V01.nc4'
_geos_ocean = 'GEOS.fpit.asm.tavg1_2d_ocn_Nx.GEOS5124.20220622_1430.V01.nc4'

Paolo Veglio
committed
_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'

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'{geos_atm_1}',
'GEOS_atm_2': f'{geos_atm_2}',
'GEOS_land': f'{geos_land}',
'GEOS_ocean': f'{geos_ocean}',
'GEOS_constants': f'{geos_constants}',
'NDVI': f'{ndvi_file}',
'SST': f'{sst_file}',

Paolo Veglio
committed
'ANC_DIR': f'{data_path}/ancillary'
}
viirs_data = rd.read_data('viirs', f'{mod02}', f'{mod03}')

Paolo Veglio
committed
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)
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
sunglint_angle = thresholds['Sun_Glint']['bounds'][3]
scene_flags = scn.find_scene(viirs_data, sunglint_angle)
cmin1 = np.ones(viirs_data.M01.shape)
cmin2 = np.ones(viirs_data.M01.shape)
cmin3 = np.ones(viirs_data.M01.shape)
cmin4 = np.ones(viirs_data.M01.shape)
# confidence = np.zeros((8, viirs_data['M01'].shape[0], viirs_data['M01'].shape[1]))
cmin1 = odt.simple_test(viirs_data.M15.values, thresholds['Daytime_Ocean']['bt11'], cmin1)
cmin1 = 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 = odt.simple_test(viirs_data.M14.values-viirs_data.M15.values,
thresholds['Daytime_Ocean']['diff_11_86um'], cmin2)
# PLACEHOLDER FOR 11-12 MICRON BTD TEST UNTIL I INCLUDE THE CITHR() FUNCTION FROM C IN CYTHON
cmin2 = odt.test_11_12_diff(viirs_data.M15.values, viirs_data.M16.values,
thresholds['Daytime_Ocean']['diff11_12um'], cmin2)
cmin2 = odt.test_11_4_diff(viirs_data.M15.values, viirs_data.M12.values,
thresholds['Daytime_Ocean']['test11_4lo'], cmin2)
cmin3 = odt.nir_refl_test(viirs_data.M07.values, thresholds['Daytime_Ocean'],
thresholds['Sun_Glint'], viirs_data, cmin3)
cmin3 = odt.vis_nir_ratio_test(viirs_data.M05.values, viirs_data.M07.values,
thresholds['Daytime_Ocean'], thresholds['Sun_Glint'], cmin3)
cmin3 = 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'])
confidence = cmin1 * cmin2 * cmin3 * cmin4
return cmin1, cmin2, cmin3
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__":