From 2b7ea42343a82370b27f1d15d8a8ff8347d39d95 Mon Sep 17 00:00:00 2001 From: Paolo Veglio <paolo.veglio@ssec.wisc.edu> Date: Wed, 1 Mar 2023 15:54:18 +0000 Subject: [PATCH] spatial variability restoral test implemented --- mvcm/restoral.py | 33 +++++++++++++++++++++ thresholds/thresholds.mvcm.snpp.v0.0.1.yaml | 20 ++++++------- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/mvcm/restoral.py b/mvcm/restoral.py index 8d5a7d9..1129ffd 100644 --- a/mvcm/restoral.py +++ b/mvcm/restoral.py @@ -4,6 +4,7 @@ import xarray as xr from typing import Dict from attrs import define, field, validators, Factory from numpy.lib.stride_tricks import sliding_window_view +from copy import deepcopy import logging @@ -77,6 +78,38 @@ class Restoral(object): """ data: xr.Dataset = field(validator=[validators.instance_of(xr.Dataset), ]) thresholds: str = field(validator=[validators.instance_of(Dict), ]) + scene_flag: Dict = field(validator=[validators.instance_of(Dict), ]) + confidence: np.ndarray = field(validator=[validators.instance_of(np.ndarray), ]) + + # VIIRS does not have water vapor channels (6.7um and 7.2um) for this test + def night_snow_inversion(self): + pass + + def spatial_variability(self): + + threshold = self.thresholds['Daytime_Ocean_Spatial_Variability'] + bt = self.data.M15.values + reflectance = self.data.M07.values + confidence = deepcopy(self.confidence) + + var_bt = spatial_var(bt, threshold['var_11um']) + var_reflectance = spatial_var(reflectance, threshold['var_0_86um']) + + idx = np.nonzero((self.confidence > 0.95) & (self.scene_flag['day'] == 1) & + (var_bt == 1) & (var_reflectance == 1)) + confidence[idx] = 1 + + idx = np.nonzero((self.confidence > 0.66) & ( + ((self.scene_flag['night'] == 1) & (var_bt == 1)) | + ((self.scene_flag['day'] == 1) & (var_bt == 1) & (var_reflectance == 1)))) + confidence[idx] = 0.96 + + idx = np.nonzero((self.confidence <= 0.66) & (var_bt == 1)) + confidence[idx] = 0.67 + + logger.info('spatial_variability restoral test performed successfully') + + return confidence def spatial_var(rad, threshold): diff --git a/thresholds/thresholds.mvcm.snpp.v0.0.1.yaml b/thresholds/thresholds.mvcm.snpp.v0.0.1.yaml index 801c795..f2a2b7d 100644 --- a/thresholds/thresholds.mvcm.snpp.v0.0.1.yaml +++ b/thresholds/thresholds.mvcm.snpp.v0.0.1.yaml @@ -39,7 +39,7 @@ Land_Night: perform: True 7.3-11um_BTD_Mid_Level_Cloud_Test: thr: [-8.0, -10.0, -11.0, 1.0, 1.0] # nl7_11s - 11-4um_BT_Difference_Test: + 11-4um_BT_Difference_Test_Land: thr_low: [0.0, -0.5, -1.0, 1.0] thr_mid: [-0.5, 6.0, 0.5, 1.0] thr_hi: [6.5, 6.0, 5.5, 1.0] @@ -234,7 +234,7 @@ Ocean_Night: thr: [3.0, 6.0, 7.0, 1.0, 1.0] variability: 0.40 perform: True - 11-4um_BT_Difference_Test: + 11-4um_BT_Difference_Test_Ocean: coeffs: [-0.7093, 0.1128, -0.1567] corr: 0.0 # no_intadj locut_coeff: [-4.0, 4.0] # no11_4load @@ -285,7 +285,7 @@ Polar_Night_Land: # Surface_Temperature_Test_2: 12.0 # | merge these three coefficients # Surface_Temperature_Test_pfm: 1.0 # __| # Surface_Temperature_Test: [20.0, 12.0, 1.0] # <- First attempt to merge the three values above - 11-4um_BT_Difference_Test: + 11-4um_BT_Difference_Test_Land: low: [2.00, 1.70, 1.40, 1.0] mid1: [1.70, 0.70, 0.3, 1.0] mid2: [0.00, 0.00, 0.00, 0.0] @@ -388,7 +388,7 @@ Polar_Day_Snow: 1.38um_High_Cloud_Test: thr: [0.060, 0.0525, 0.045, 1.0, 1.0] perform: True - 11-4um_BT_Difference_Test: + 11-4um_BT_Difference_Test_Land: low: [20.0, 18.0, 16.0, 1.0] mid1: [18.0, 16.0, 2.0, 1.0] mid2: [0.0, 0.0, 0.0, 0.0] @@ -426,7 +426,7 @@ Polar_Night_Snow: 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] - 11-4um_BT_Difference_Test: + 11-4um_BT_Difference_Test_Land: top: low: [2.00, 1.70, 1.40, 1.0] mid1: [1.70, 0.30, 0.300, 1.0] @@ -520,7 +520,7 @@ Polar_Night_Ocean: thr: [3.0, 6.0, 7.0, 1.0, 1.0] variability: 040 perform: True - 11-4um_BT_Difference_Test: + 11-4um_BT_Difference_Test_Ocean: coeffs: [-0.7093, 0.1128, -0.1567] corr: 0.0 # pno_intadj locut_coeff: [-4.0, 4.0] # pno11_4load @@ -542,7 +542,7 @@ Day_Snow: 1.38um_High_Cloud_Test: thr: [0.060, 0.0525, 0.045, 1.0, 1.0] perform: True - 11-4um_BT_Difference_Test: + 11-4um_BT_Difference_Test_Land: low: [20.0, 18.0, 16.0, 1.0] mid1: [18.0, 16.0, 2.0, 1.0] mid2: [0.0, 0.0, 0.0, 0.0] @@ -565,7 +565,7 @@ Night_Snow: 4-12um_BTD_Thin_Cirrus_Test: thr: [4.50, 4.00, 3.50, 1.0, 1.0] perform: True - 11-4um_BT_Difference_Test: + 11-4um_BT_Difference_Test_Land: thr: [0.70, 0.60, 0.50, 1.0, 1.0] bottom: low: [20.0, 18.0, 16.0, 1.0] @@ -606,8 +606,8 @@ Antarctic_Day: ant4_11_pfm : 1.0 Daytime_Ocean_Spatial_Variability: - dovar11 : 0.40 - dovar86 : 0.0020 + var_11um: 0.40 + var_0_86um: 0.0020 Sun_Glint: # snglntv : [1.02, 1.17] -- GitLab