diff --git a/preprocess_thresholds.py b/preprocess_thresholds.py index daf69b5b113944a046e22d2c9c0ef7a1c0ec8b4f..e02d4971ba7a7d06a952385f0e1cd5c21ca1d222 100644 --- a/preprocess_thresholds.py +++ b/preprocess_thresholds.py @@ -263,6 +263,94 @@ def get_b1_thresholds(data, thresholds): return locut, midpt, hicut +def get_pn_thresholds(data, thresholds, scene, test_name): + + thresholds = thresholds[scene] + if ((test_name == '4-12um_BTD_Thin_Cirrus_Test') and (scene in ['Land_Night', 'Night_Snow']) or + (test_name == '7.3-11um_BTD_Mid_Level_Cloud_Test') and (scene == 'Land_Night')): + locut = thresholds[test_name]['thr'][0] * np.ones(data.M15.shape) + midpt = thresholds[test_name]['thr'][1] * np.ones(data.M15.shape) + hicut = thresholds[test_name]['thr'][2] * np.ones(data.M15.shape) + power = thresholds[test_name]['thr'][3] * np.ones(data.M15.shape) + + out_thr = xr.DataArray(data=np.dstack((locut, midpt, hicut, np.ones(data.ndvi.shape), power)), + dims=('number_of_lines', 'number_of_pixels', 'z')) + return out_thr + + rad = data.M15.values.reshape(data.M15.shape[0]*data.M15.shape[1]) + bt_bounds = thresholds[test_name]['bt11_bounds'] + + locut, midpt = np.empty(rad.shape), np.empty(rad.shape) + hicut, power = np.empty(rad.shape), np.empty(rad.shape) + lo, hi = np.empty(rad.shape), np.empty(rad.shape) + lo_thr, hi_thr = np.empty(rad.shape), np.empty(rad.shape) + conf_range = np.empty(rad.shape) + + idx = np.nonzero(rad < bt_bounds[0]) + locut[idx] = thresholds[test_name]['low'][0] + midpt[idx] = thresholds[test_name]['low'][1] + hicut[idx] = thresholds[test_name]['low'][2] + power[idx] = thresholds[test_name]['low'][3] + + idx = np.nonzero(rad > bt_bounds[3]) + locut[idx] = thresholds[test_name]['high'][0] + midpt[idx] = thresholds[test_name]['high'][1] + hicut[idx] = thresholds[test_name]['high'][2] + power[idx] = thresholds[test_name]['high'][3] + + # # # # # + idx = np.nonzero((rad >= bt_bounds[0]) & (rad <= bt_bounds[3]) & + (bt_bounds[1] == 0) & (bt_bounds[2] == 0)) + lo[idx] = thresholds[test_name]['bt11_bounds'][0] + hi[idx] = thresholds[test_name]['bt11_bounds'][3] + lo_thr[idx] = thresholds[test_name]['mid1'][0] + hi_thr[idx] = thresholds[test_name]['mid1'][1] + power[idx] = thresholds[test_name]['mid1'][3] + conf_range[idx] = thresholds[test_name]['mid1'][2] + + idx = np.nonzero((rad >= bt_bounds[0]) & (rad < bt_bounds[1])) + lo[idx] = thresholds[test_name]['bt11_bounds'][0] + hi[idx] = thresholds[test_name]['bt11_bounds'][1] + lo_thr[idx] = thresholds[test_name]['mid1'][0] + hi_thr[idx] = thresholds[test_name]['mid1'][1] + power[idx] = thresholds[test_name]['mid1'][3] + conf_range[idx] = thresholds[test_name]['mid1'][2] + + idx = np.nonzero((rad >= bt_bounds[1]) & (rad < bt_bounds[2])) + lo[idx] = thresholds[test_name]['bt11_bounds'][1] + hi[idx] = thresholds[test_name]['bt11_bounds'][2] + lo_thr[idx] = thresholds[test_name]['mid2'][0] + hi_thr[idx] = thresholds[test_name]['mid2'][1] + power[idx] = thresholds[test_name]['mid2'][3] + conf_range[idx] = thresholds[test_name]['mid2'][2] + + idx = np.nonzero((rad >= bt_bounds[2]) & (rad < bt_bounds[3])) + lo[idx] = thresholds[test_name]['bt11_bounds'][2] + hi[idx] = thresholds[test_name]['bt11_bounds'][3] + lo_thr[idx] = thresholds[test_name]['mid3'][0] + hi_thr[idx] = thresholds[test_name]['mid3'][1] + power[idx] = thresholds[test_name]['mid3'][3] + conf_range[idx] = thresholds[test_name]['mid3'][2] + + idx = np.nonzero(((rad >= bt_bounds[0]) & (rad < bt_bounds[3])) | + (bt_bounds[1] == 0.0) | (bt_bounds[2] == 0)) + + a = (rad[idx] - lo[idx])/(hi[idx] - lo[idx]) + midpt[idx] = lo_thr[idx] + (a*(hi_thr[idx] - lo_thr[idx])) + hicut[idx] = midpt[idx] - conf_range[idx] + locut[idx] = midpt[idx] + conf_range[idx] + + locut = locut.reshape(data.M15.shape) + midpt = midpt.reshape(data.M15.shape) + hicut = hicut.reshape(data.M15.shape) + power = power.reshape(data.M15.shape) + + out_thr = xr.DataArray(data=np.dstack((locut, midpt, hicut, np.ones(data.ndvi.shape), power)), + dims=('number_of_lines', 'number_of_pixels', 'z')) + + return out_thr + + def vis_refl_thresholds(data, thresholds, scene): locut, midpt, hicut = get_b1_thresholds(data, thresholds) diff --git a/read_data.py b/read_data.py index 9daa89b9812fa8c092be563b4a66be9e13ac67cb..2d940407f431ff9665ef8c829603eacc71aa5c00 100644 --- a/read_data.py +++ b/read_data.py @@ -143,6 +143,8 @@ def get_data(file_names, sunglint_angle): viirs_data.M15.values - viirs_data.M16.values) viirs_data['M15-M13'] = (('number_of_lines', 'number_of_pixels'), viirs_data.M15.values - viirs_data.M13.values) + viirs_data['M13-M16'] = (('number_of_lines', 'number_of_pixels'), + viirs_data.M13.values - viirs_data.M16.values) scene_flags = scn.find_scene(viirs_data, sunglint_angle) scene = scn.scene_id(scene_flags) diff --git a/tests.py b/tests.py index 2debb8b829696f2342b3126a8ac278f157f426ea..19cceb05fa11f8ff721ceb3a142cdfd3c0ce1c52 100644 --- a/tests.py +++ b/tests.py @@ -271,12 +271,16 @@ class CloudTests: thr_xr['threshold'] = pt.preproc(self.data, self.thresholds[self.scene_name], self.scene_name) thr = np.ones((5,)) # This is only temporary to force the logic of the code # I need to find a better solution at some point - elif test_name == 'Surface_Temperature_Test': - thr_xr['threshold'] = pt.preproc_surf_temp(self.data, self.thresholds[self.scene_name]) - thr = np.ones((5,)) elif test_name == 'SST_Test': thr_xr['threshold'] = (('number_of_lines', 'number_of_pixels', 'z'), np.ones((self.data[band].shape[0], self.data[band].shape[1], 5))*thr) + elif test_name == '7.3-11um_BTD_Mid_Level_Cloud_Test': + thr_xr['threshold'] = pt.get_pn_thresholds(self.data, self.thresholds, self.scene_name, + '7.3-11um_BTD_Mid_Level_Cloud_Test') + thr = np.ones((5,)) + elif test_name == 'Surface_Temperature_Test': + thr_xr['threshold'] = pt.preproc_surf_temp(self.data, self.thresholds[self.scene_name]) + thr = np.ones((5,)) elif test_name == 'NIR_Reflectance_Test': corr_thr = pt.preproc_nir(self.data, self.thresholds, self.scene_name) thr_xr['threshold'] = (('number_of_lines', 'number_of_pixels', 'z'), corr_thr) @@ -284,6 +288,10 @@ class CloudTests: thr_xr['threshold'], self.data['M128'] = pt.vis_refl_thresholds(self.data, self.thresholds, self.scene_name) + elif test_name == '4-12um_BTD_Thin_Cirrus_Test': + thr_xr['threshold'] = pt.get_pn_thresholds(self.data, self.thresholds, self.scene_name, + '4-12um_BTD_Thin_Cirrus_Test') + thr = np.ones((5,)) else: thr_xr['threshold'] = (('number_of_lines', 'number_of_pixels', 'z'), np.ones((self.data[band].shape[0], self.data[band].shape[1], 5))*thr) diff --git a/thresholds.mvcm.snpp.v0.0.1.yaml b/thresholds.mvcm.snpp.v0.0.1.yaml index 4debff3cecad2fe10b8770bf7e859f9283249e00..9a1e87e025fcf0c491f0211cfcfe323379aa6e24 100644 --- a/thresholds.mvcm.snpp.v0.0.1.yaml +++ b/thresholds.mvcm.snpp.v0.0.1.yaml @@ -27,10 +27,12 @@ Land_Night: adj: 0 bt1: 270.0 # WILL FIND A BETTER NAME AT SOME POINT, MAYBE lat: 30.0 - nl4_12hi : [15.0, 10.0, 5.00, 1.0, 1.0] + 4-12um_BTD_Thin_Cirrus_Test: + thr: [15.0, 10.0, 5.00, 1.0, 1.0] CO2_High_Clouds_Test: [222.0, 224.0, 226.0, 1.0, 1.0] Water_Vapor_High_Clouds_Test: [215.0, 220.0, 225.0, 1.0, 1.0] - nl7_11s : [-8.0, -10.0, -11.0, 1.0, 1.0] + 7.3-11um_BTD_Mid_Level_Cloud_Test: + thr: [-8.0, -10.0, -11.0, 1.0, 1.0] # nl7_11s nl_11_4l : [0.0, -0.5, -1.0, 1.0] nl_11_4h : [6.5, 6.0, 5.5, 1.0] nl_11_4m : [-0.5, 6.0, 0.5, 1.0] @@ -203,12 +205,20 @@ Polar_Night_Land: pnl_11_4_pfm : 1.0 pnl_7_11_pfm : 1.0 pnl_4_12_pfm : 1.0 - pnl_11_4l : [2.00, 1.70, 1.40, 1.0] - pnl_11_4h : [1.00, 0.70, 0.40, 1.0] - pnl_11_4m1 : [1.70, 0.70, 0.300, 1.0] - pnl_11_4m2 : [0.00, 0.00, 0.00, 0.0] - pnl_11_4m3 : [0.00, 0.00, 0.00, 0.0] - pnl_11_bounds : [235.0, 000.0, 000.0, 265.0] + 7.3-11um_BTD_Mid_Level_Cloud_Test: + low: [-1.00, 0.00, 1.00, 1.0, 1.0] # pn_7_11l + mid1: [0.00, -4.50, -1.00, 1.0] # pn_7_11m1 + mid2: [-4.50, -10.50, -1.00, 1.0] # pn_7_11m2 + mid3: [-10.50, -20.0, -1.00, 1.0] # pn_7_11m3 + high: [-21.0, -20.0, -19.0,1.0] # pn_7_11h + bt11_bounds: [220.0, 245.0, 255.0, 265.0] # bt11_bnds2 + 4-12um_BTD_Thin_Cirrus_Test: + low: [2.00, 1.70, 1.40, 1.0] + mid1: [1.70, 0.70, 0.300, 1.0] + mid2: [0.00, 0.00, 0.00, 0.0] + mid3: [0.00, 0.00, 0.00, 0.0] + high: [1.00, 0.70, 0.40, 1.0] + bt11_bounds : [235.0, 000.0, 000.0, 265.0] Polar_Day_Coast: 11-12um_Cirrus_Test: @@ -282,22 +292,26 @@ Polar_Night_Snow: cmult: 0 adj: 0 # I NEED TO WORK ON THIS bt1: 270.0 - pn_4_12l : [4.50, 4.00, 3.50, 1.0] - pn_4_12h : [2.50, 2.00, 1.50, 1.0] - pn_4_12m1 : [4.00, 2.00, 0.500, 1.0] - pn_4_12m2 : [0.00, 0.00, 0.00, 0.0] - pn_4_12m3 : [0.00, 0.00, 0.00, 0.0] + 4-12um_BTD_Thin_Cirrus_Test: + low: [4.50, 4.00, 3.50, 1.0] # pn_4_12l + mid1: [4.00, 2.00, 0.500, 1.0] # pn_4_12m1 + mid2: [0.00, 0.00, 0.00, 0.0] # pn_4_12m2 + mid3: [0.00, 0.00, 0.00, 0.0] # pn_4_12m3 + high: [2.50, 2.00, 1.50, 1.0] # pn_4_12h + bt11_bounds: [235.0, 0.0, 0.0, 265.0] # bt_11_bounds pns_4_12_pfm : 1.0 - pn_7_11l : [-1.00, 0.00, 1.00, 1.0, 1.0] - pn_7_11h : [-21.0, -20.0, -19.0,1.0] - pn_7_11m1 : [0.00, -4.50, -1.00, 1.0] - pn_7_11m2 : [-4.50, -10.50, -1.00, 1.0] - pn_7_11m3 : [-10.50, -20.0, -1.00, 1.0] - pn_7_11lw : [0.00, 1.00, 2.00, 1.0] - pn_7_11hw : [-21.0 -20.0, -19.0, 1.0] - pn_7_11m1w : [1.00, -7.00, -1.00, 1.0] - pn_7_11m2w : [-7.00, -16.50, -1.00, 1.0] - pn_7_11m3w : [-16.50, -20.0, -1.00, 1.0] + 7.3-11um_BTD_Mid_Level_Cloud_Test: + low: [-1.00, 0.00, 1.00, 1.0, 1.0] # pn_7_11l + mid1: [0.00, -4.50, -1.00, 1.0] # pn_7_11m1 + mid2: [-4.50, -10.50, -1.00, 1.0] # pn_7_11m2 + mid3: [-10.50, -20.0, -1.00, 1.0] # pn_7_11m3 + high: [-21.0, -20.0, -19.0,1.0] # pn_7_11h + low_ice: [0.00, 1.00, 2.00, 1.0] # pn_7_11lw + mid1_ice: [1.00, -7.00, -1.00, 1.0] # pn_7_11m1w + mid2_ice: [-7.00, -16.50, -1.00, 1.0] # pn_7_11m2w + mid3_ice: [-16.50, -20.0, -1.00, 1.0] # pn_7_11m3w + high_ice: [-21.0 -20.0, -19.0, 1.0] # pn_7_11hw + bt11_bounds: [220.0, 245.0, 255.0, 265.0] # bt11_bnds2 Water_Vapor_High_Clouds_Test: [215.0, 220.0, 225.0, 1.0, 1.0] pn_11_4l : [2.00, 1.70, 1.40, 1.0] pn_11_4h : [0.60, 0.30, 0.00, 1.0] @@ -305,8 +319,6 @@ Polar_Night_Snow: pn_11_4m2 : [0.00, 0.00, 0.00, 0.0] pn_11_4m3 : [0.00, 0.00, 0.00, 0.0] pns_11_4_pfm : 1.0 - bt_11_bounds : [235.0, 000.0, 000.0, 265.0] - bt_11_bnds2 : [220.0, 245.0, 255.0, 265.0] pn_11_4bl : [-3.00, -2.50, -2.00, 1.0] pn_11_4bh : [-3.00, -2.50, -2.00, 1.0] pn_11_4bm1 : [-2.50, -2.50, -0.50, 1.0] @@ -389,7 +401,20 @@ Night_Snow: nsbt2 : 270.0 nsbt3 : 230.0 ns11_4lo : [0.70, 0.60, 0.50, 1.0, 1.0] - ns4_12hi : [4.50, 4.00, 3.50, 1.0, 1.0] + 4-12um_BTD_Thin_Cirrus_Test: + thr: [4.50, 4.00, 3.50, 1.0, 1.0] + 7.3-11um_BTD_Mid_Level_Cloud_Test: + low: [-1.00, 0.00, 1.00, 1.0, 1.0] # pn_7_11l + mid1: [0.00, -4.50, -1.00, 1.0] # pn_7_11m1 + mid2: [-4.50, -10.50, -1.00, 1.0] # pn_7_11m2 + mid3: [-10.50, -20.0, -1.00, 1.0] # pn_7_11m3 + high: [-21.0, -20.0, -19.0,1.0] # pn_7_11h + low_ice: [0.00, 1.00, 2.00, 1.0] # pn_7_11lw + mid1_ice: [1.00, -7.00, -1.00, 1.0] # pn_7_11m1w + mid2_ice: [-7.00, -16.50, -1.00, 1.0] # pn_7_11m2w + mid3_ice: [-16.50, -20.0, -1.00, 1.0] # pn_7_11m3w + high_ice: [-21.0 -20.0, -19.0, 1.0] # pn_7_11hw + bt11_bounds: [220.0, 245.0, 255.0, 265.0] # bt11_bnds2 CO2_High_Clouds_Test: [222.0, 224.0, 226.0, 1.0, 1.0] Water_Vapor_High_Clouds_Test: [215.0, 220.0, 225.0, 1.0, 1.0] ns11_12adj : 0.8