Skip to content

Commit

Permalink
Merge pull request #107 from ARamsay17/dev
Browse files Browse the repository at this point in the history
L2 products outside of rho wave subset discarded
  • Loading branch information
oceancolorcoder authored Oct 27, 2023
2 parents d7bdca9 + c981b74 commit b81a26d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 41 deletions.
75 changes: 41 additions & 34 deletions Source/ProcessInstrumentUncertainties.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ def rrsHyperUNC(self, uncGrp: HDFGroup, rhoScalar: float, rhoVec: np.array, rhoD
:return: dictionary of output uncertainties that are generated
"""

waveSubset = np.array(waveSubset, dtype=float) # convert waveSubset to numpy array
esXstd = xSlice['esSTD_RAW']
liXstd = xSlice['liSTD_RAW']
ltXstd = xSlice['ltSTD_RAW']
Expand All @@ -482,12 +484,16 @@ def rrsHyperUNC(self, uncGrp: HDFGroup, rhoScalar: float, rhoVec: np.array, rhoD

if rhoScalar is not None: # make rho a constant array if scalar
rho = np.ones(len(list(esXstd.keys())))*rhoScalar
rhoUnc, _ = self.interp_common_wvls(np.array(rhoDelta, dtype=float),
rhoUNC, _ = self.interp_common_wvls(np.array(rhoDelta, dtype=float),
waveSubset,
np.asarray(list(esXstd.keys()), dtype=float))
else:
rho = np.array(list(rhoVec.values()), dtype=float)
rhoUNC = rhoDelta
rho, _ = self.interp_common_wvls(np.array(list(rhoVec.values()), dtype=float),
waveSubset,
np.asarray(list(esXstd.keys()), dtype=float))
rhoUNC, _ = self.interp_common_wvls(rhoDelta,
waveSubset,
np.asarray(list(esXstd.keys()), dtype=float))

# define dictionaries for uncertainty components
Cal = {}
Expand Down Expand Up @@ -540,7 +546,7 @@ def rrsHyperUNC(self, uncGrp: HDFGroup, rhoScalar: float, rhoVec: np.array, rhoD
ones, ones]

lw_uncertainties = [np.array(list(ltXstd.values())).flatten() * lt,
rhoUnc,
rhoUNC,
np.array(list(liXstd.values())).flatten() * li,
Cal['LI']/200, Cal['LT']/200,
cStab['LI'], cStab['LT'],
Expand Down Expand Up @@ -582,7 +588,7 @@ def rrsHyperUNC(self, uncGrp: HDFGroup, rhoScalar: float, rhoVec: np.array, rhoD
output = {}

# interpolate output uncertainties to the waveSubset (common wavebands of interpolated es, li, & lt)
wvls = np.asarray(list(xSlice['es'].keys()), dtype=float)
# wvls = np.asarray(list(xSlice['es'].keys()), dtype=float)

lwAbsUnc, _ = self.interp_common_wvls(lwAbsUnc,
np.array(uncGrp.getDataset("ES_RADCAL_CAL").columns['1'], dtype=float),
Expand All @@ -599,34 +605,34 @@ def rrsHyperUNC(self, uncGrp: HDFGroup, rhoScalar: float, rhoVec: np.array, rhoD

## Band Convolution of Uncertainties
if ConfigFile.settings["bL2WeightSentinel3A"]:
output["lwUNC_Sentinel3A"] = Convolve.band_Conv_Uncertainty([lw_vals, wvls],
output["lwUNC_Sentinel3A"] = Convolve.band_Conv_Uncertainty([lw_vals, waveSubset],
[lwAbsUnc, None], "S3A")
output["rrsUNC_Sentinel3A"] = Convolve.band_Conv_Uncertainty([rrs_vals, wvls],
output["rrsUNC_Sentinel3A"] = Convolve.band_Conv_Uncertainty([rrs_vals, waveSubset],
[rrsAbsUnc, None], "S3A")
elif ConfigFile.settings["bL2WeightSentinel3B"]:
output["lwUNC_Sentinel3B"] = Convolve.band_Conv_Uncertainty([lw_vals, wvls],
output["lwUNC_Sentinel3B"] = Convolve.band_Conv_Uncertainty([lw_vals, waveSubset],
[lwAbsUnc, None], "S3B")
output["rrsUNC_Sentinel3B"] = Convolve.band_Conv_Uncertainty([rrs_vals, wvls],
output["rrsUNC_Sentinel3B"] = Convolve.band_Conv_Uncertainty([rrs_vals, waveSubset],
[rrsAbsUnc, None], "S3B")
if ConfigFile.settings['bL2WeightMODISA']:
output["lwUNC_MODISA"] = Convolve.band_Conv_Uncertainty([lw_vals, wvls],
output["lwUNC_MODISA"] = Convolve.band_Conv_Uncertainty([lw_vals, waveSubset],
[lwAbsUnc, None], "MOD-A")
output["rrsUNC_MODISA"] = Convolve.band_Conv_Uncertainty([rrs_vals, wvls],
output["rrsUNC_MODISA"] = Convolve.band_Conv_Uncertainty([rrs_vals, waveSubset],
[rrsAbsUnc, None], "MOD-A")
if ConfigFile.settings['bL2WeightMODIST']:
output["lwUNC_MODIST"] = Convolve.band_Conv_Uncertainty([lw_vals, wvls],
output["lwUNC_MODIST"] = Convolve.band_Conv_Uncertainty([lw_vals, waveSubset],
[lwAbsUnc, None], "MOD-T")
output["rrsUNC_MODIST"] = Convolve.band_Conv_Uncertainty([rrs_vals, wvls],
output["rrsUNC_MODIST"] = Convolve.band_Conv_Uncertainty([rrs_vals, waveSubset],
[rrsAbsUnc, None], "MOD-T")
if ConfigFile.settings['bL2WeightVIIRSN']:
output["lwUNC_VIIRSN"] = Convolve.band_Conv_Uncertainty([lw_vals, wvls],
output["lwUNC_VIIRSN"] = Convolve.band_Conv_Uncertainty([lw_vals, waveSubset],
[lwAbsUnc, None], "VIIRS")
output["rrsUNC_VIIRSN"] = Convolve.band_Conv_Uncertainty([rrs_vals, wvls],
output["rrsUNC_VIIRSN"] = Convolve.band_Conv_Uncertainty([rrs_vals, waveSubset],
[rrsAbsUnc, None], "VIIRS")
if ConfigFile.settings['bL2WeightVIIRSJ']:
output["lwUNC_VIIRSJ"] = Convolve.band_Conv_Uncertainty([lw_vals, wvls],
output["lwUNC_VIIRSJ"] = Convolve.band_Conv_Uncertainty([lw_vals, waveSubset],
[lwAbsUnc, None], "VIIRS")
output["rrsUNC_VIIRSJ"] = Convolve.band_Conv_Uncertainty([rrs_vals, wvls],
output["rrsUNC_VIIRSJ"] = Convolve.band_Conv_Uncertainty([rrs_vals, waveSubset],
[rrsAbsUnc, None], "VIIRS")
pass
output.update({"lwUNC": lwAbsUnc, "rrsUNC": rrsAbsUnc})
Expand All @@ -647,6 +653,7 @@ def rrsHyperUNCFACTORY(self, node, uncGrp, rhoScalar, rhoVec, rhoDelta, waveSubs
:return: dictionary of output uncertainties that are generated
"""

waveSubset = np.array(waveSubset, dtype=float) # convert waveSubset to numpy array
esXstd = xSlice['esSTD_RAW']
liXstd = xSlice['liSTD_RAW']
ltXstd = xSlice['ltSTD_RAW']
Expand Down Expand Up @@ -772,49 +779,49 @@ def rrsHyperUNCFACTORY(self, node, uncGrp, rhoScalar, rhoVec, rhoDelta, waveSubs
output = {} # create dictionary to store uncertainty values which are returned from methods

# interpolate output uncertainties to the waveSubset (common wavebands of interpolated es, li, & lt)
wvls = np.asarray(list(xSlice['es'].keys()), dtype=float)
# wvls = np.asarray(list(xSlice['es'].keys()), dtype=float)
lwAbsUnc, _ = self.interp_common_wvls(lwAbsUnc,
np.array(uncGrp.getDataset("ES_RADCAL_UNC").columns['wvl'], dtype=float),
wvls)
waveSubset)
lw_vals, _ = self.interp_common_wvls(lw_vals,
np.array(uncGrp.getDataset("ES_RADCAL_UNC").columns['wvl'], dtype=float),
wvls)
waveSubset)
rrsAbsUnc, _ = self.interp_common_wvls(rrsAbsUnc,
np.array(uncGrp.getDataset("ES_RADCAL_UNC").columns['wvl'], dtype=float),
wvls)
waveSubset)
rrs_vals, _ = self.interp_common_wvls(rrs_vals,
np.array(uncGrp.getDataset("ES_RADCAL_UNC").columns['wvl'], dtype=float),
wvls)
waveSubset)

if ConfigFile.settings["bL2WeightSentinel3A"]:
output["lwUNC_Sentinel3A"] = Convolve.band_Conv_Uncertainty([lw_vals, wvls],
output["lwUNC_Sentinel3A"] = Convolve.band_Conv_Uncertainty([lw_vals, waveSubset],
[lwAbsUnc, None], "S3A")
output["rrsUNC_Sentinel3A"] = Convolve.band_Conv_Uncertainty([rrs_vals, wvls],
output["rrsUNC_Sentinel3A"] = Convolve.band_Conv_Uncertainty([rrs_vals, waveSubset],
[rrsAbsUnc, None], "S3A")
elif ConfigFile.settings["bL2WeightSentinel3B"]:
output["lwUNC_Sentinel3B"] = Convolve.band_Conv_Uncertainty([lw_vals, wvls],
output["lwUNC_Sentinel3B"] = Convolve.band_Conv_Uncertainty([lw_vals, waveSubset],
[lwAbsUnc, None], "S3B")
output["rrsUNC_Sentinel3B"] = Convolve.band_Conv_Uncertainty([rrs_vals, wvls],
output["rrsUNC_Sentinel3B"] = Convolve.band_Conv_Uncertainty([rrs_vals, waveSubset],
[rrsAbsUnc, None], "S3B")
if ConfigFile.settings['bL2WeightMODISA']:
output["lwUNC_MODISA"] = Convolve.band_Conv_Uncertainty([lw_vals, wvls],
output["lwUNC_MODISA"] = Convolve.band_Conv_Uncertainty([lw_vals, waveSubset],
[lwAbsUnc, None], "MOD-A")
output["rrsUNC_MODISA"] = Convolve.band_Conv_Uncertainty([rrs_vals, wvls],
output["rrsUNC_MODISA"] = Convolve.band_Conv_Uncertainty([rrs_vals, waveSubset],
[rrsAbsUnc, None], "MOD-A")
if ConfigFile.settings['bL2WeightMODIST']:
output["lwUNC_MODIST"] = Convolve.band_Conv_Uncertainty([lw_vals, wvls],
output["lwUNC_MODIST"] = Convolve.band_Conv_Uncertainty([lw_vals, waveSubset],
[lwAbsUnc, None], "MOD-T")
output["rrsUNC_MODIST"] = Convolve.band_Conv_Uncertainty([rrs_vals,wvls],
output["rrsUNC_MODIST"] = Convolve.band_Conv_Uncertainty([rrs_vals,waveSubset],
[rrsAbsUnc, None], "MOD-T")
if ConfigFile.settings['bL2WeightVIIRSN']:
output["lwUNC_VIIRSN"] = Convolve.band_Conv_Uncertainty([lw_vals, wvls],
output["lwUNC_VIIRSN"] = Convolve.band_Conv_Uncertainty([lw_vals, waveSubset],
[lwAbsUnc, None], "VIIRS")
output["rrsUNC_VIIRSN"] = Convolve.band_Conv_Uncertainty([rrs_vals, wvls],
output["rrsUNC_VIIRSN"] = Convolve.band_Conv_Uncertainty([rrs_vals, waveSubset],
[rrsAbsUnc, None], "VIIRS")
if ConfigFile.settings['bL2WeightVIIRSJ']:
output["lwUNC_VIIRSJ"] = Convolve.band_Conv_Uncertainty([lw_vals, wvls],
output["lwUNC_VIIRSJ"] = Convolve.band_Conv_Uncertainty([lw_vals, waveSubset],
[lwAbsUnc, None], "VIIRS")
output["rrsUNC_VIIRSJ"] = Convolve.band_Conv_Uncertainty([rrs_vals, wvls],
output["rrsUNC_VIIRSJ"] = Convolve.band_Conv_Uncertainty([rrs_vals, waveSubset],
[rrsAbsUnc, None], "VIIRS")
pass
output.update({"lwUNC": lwAbsUnc, "rrsUNC": rrsAbsUnc})
Expand Down
12 changes: 6 additions & 6 deletions Source/ProcessL2.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,9 @@ def spectralReflectance(node, sensor, timeObj, xSlice, F0, F0_unc, rhoScalar, rh
rrsUNC[k] = 0

deleteKey = []
for k in esXSlice: # loop through wavebands
if (k in liXSlice) and (k in ltXSlice):

for wvl in waveSubset: # loop through wavebands
k = str(wvl)
if (k in esXSlice) and (k in liXSlice) and (k in ltXSlice):
# Initialize the new dataset if this is the first slice
if k not in newESData.columns:
newESData.columns[k] = []
Expand Down Expand Up @@ -440,7 +440,7 @@ def spectralReflectance(node, sensor, timeObj, xSlice, F0, F0_unc, rhoScalar, rh
rrs = lw / es

#Calculate the normalized water leaving radiance
nLw = rrs*f0
nLw = rrs*f0 # need to chop the keys to match Z17 output

# nLw uncertainty;
nLwUNC[k] = np.power((rrsUNC[k]*f0)**2 + f0UNC**2, 0.5)
Expand All @@ -460,7 +460,7 @@ def spectralReflectance(node, sensor, timeObj, xSlice, F0, F0_unc, rhoScalar, rh
newLTDataMedian.columns[k].append(ltMedian)

# Only populate valid wavelengths. Mark others for deletion
if float(k) in waveSubset:
if float(k) in waveSubset: # should be redundant!
newRrsUncorrData.columns[k].append(rrs_uncorr)
newLWData.columns[k].append(lw)
newRrsData.columns[k].append(rrs)
Expand Down Expand Up @@ -1532,7 +1532,7 @@ def _sliceRawData(ES_raw, LI_raw, LT_raw):
if k != "Datetag" and k != "Datetime" and k != "Timetag2":
wavelengthStr.append(k)
wavelength.append(float(k))
waveSubset = wavelength # Only used for Zhang; No subsetting for threeC or Mobley corrections
waveSubset = wavelength # Only used for Zhang; No subsetting for threeC or Mobley corrections
rhoVec = {}

Rho_Uncertainty_Obj = Propagate(M=100, cores=1)
Expand Down
3 changes: 2 additions & 1 deletion Source/Uncertainty_Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ def zhangWrapper(windSpeedMean, AOD, cloud, sza, wTemp, sal, relAz, waveBands):
# === environmental conditions during experiment ===
env = collections.OrderedDict()
env['wind'] = windSpeedMean
env['od'] = AOD
# clip AOD to 0.2 to ensure no error in Z17, potential underestimation of uncertainty however
env['od'] = AOD if AOD < 0.2 else 0.2
env['C'] = cloud # Not used
env['zen_sun'] = sza
env['wtem'] = wTemp
Expand Down

0 comments on commit b81a26d

Please sign in to comment.