Commit bb6eb452 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Fixed issue # 81 (Wavelength metadata of homogenized product do not match...

Fixed issue # 81 (Wavelength metadata of homogenized product do not match target sensor wavelengths).
parent 7ec71165
......@@ -89,11 +89,12 @@ class L1C_object(L1B_object):
self.logger.info('Calculating viewing zenith array...')
if self.MetaObj.ViewingAngle_arrProv:
# Sentinel-2
self._VZA_arr = GEOP.adjust_acquisArrProv_to_shapeFullArr(self.MetaObj.ViewingAngle_arrProv,
self.shape_fullArr,
meshwidth=10, # for faster processing
subset=None,
bandwise=0)
self._VZA_arr = GEOP.adjust_acquisArrProv_to_shapeFullArr(
{k: v.tolist() for k, v in self.MetaObj.ViewingAngle_arrProv.items()},
self.shape_fullArr,
meshwidth=10, # for faster processing
subset=None,
bandwise=0)
else:
self._VZA_arr = GEOP.calc_VZA_array(self.shape_fullArr, self.arr_pos, self.fullSceneCornerPos,
float(self.MetaObj.ViewingAngle),
......@@ -122,11 +123,12 @@ class L1C_object(L1B_object):
self.logger.info('Calculating viewing azimuth array...')
if self.MetaObj.IncidenceAngle_arrProv:
# Sentinel-2
self._VAA_arr = GEOP.adjust_acquisArrProv_to_shapeFullArr(self.MetaObj.IncidenceAngle_arrProv,
self.shape_fullArr,
meshwidth=10, # for faster processing
subset=None,
bandwise=0)
self._VAA_arr = GEOP.adjust_acquisArrProv_to_shapeFullArr(
{k: v.tolist() for k, v in self.MetaObj.IncidenceAngle_arrProv.items()},
self.shape_fullArr,
meshwidth=10, # for faster processing
subset=None,
bandwise=0)
else:
# only a mean VAA is available
if self.VAA_mean is None:
......
......@@ -66,9 +66,21 @@ class L2B_object(L2A_object):
tgt_sat, tgt_sen = datasetid_to_sat_sen(CFG.datasetid_spectral_ref)
# NOTE: get target LBA at L2A, because spectral characteristics of target sensor do not change after AC
tgt_LBA = get_LayerBandsAssignment(
GMS_identifier(satellite=tgt_sat, sensor=tgt_sen, subsystem=None,
GMS_identifier(satellite=tgt_sat, sensor=tgt_sen, subsystem='',
image_type='RSD', proc_level='L2A', dataset_ID=src_dsID, logger=None))
if CFG.datasetid_spectral_ref is None:
tgt_cwl = CFG.target_CWL
tgt_fwhm = CFG.target_FWHM
else:
# exclude those bands from CFG.target_CWL and CFG.target_FWHM that have been removed after AC
full_LBA = get_LayerBandsAssignment(
GMS_identifier(satellite=tgt_sat, sensor=tgt_sen, subsystem='',
image_type='RSD', proc_level='L1A', dataset_ID=src_dsID, logger=None),
no_thermal=True, no_pan=False, return_fullLBA=True, sort_by_cwl=True, proc_level='L1A')
tgt_cwl = [dict(zip(full_LBA, CFG.target_CWL))[bN] for bN in tgt_LBA]
tgt_fwhm = [dict(zip(full_LBA, CFG.target_FWHM))[bN] for bN in tgt_LBA]
####################################################
# special cases where homogenization is not needed #
####################################################
......@@ -93,7 +105,7 @@ class L2B_object(L2A_object):
if method == 'LI' or CFG.datasetid_spectral_ref is None:
# linear interpolation (if intended by user or in case of custom spectral characteristics of target sensor)
# -> no classifier for that case available -> linear interpolation
im = SpH.interpolate_cube(self.arr, src_cwls, CFG.target_CWL, kind='linear')
im = SpH.interpolate_cube(self.arr, src_cwls, tgt_cwl, kind='linear')
if CFG.spechomo_estimate_accuracy:
self.logger.warning("Unable to compute any error information in case spectral homogenization algorithm "
......@@ -115,7 +127,7 @@ class L2B_object(L2A_object):
compute_errors=CFG.spechomo_estimate_accuracy,
bandwise_errors=CFG.spechomo_bandwise_accuracy,
fallback_argskwargs=dict(
args=dict(source_CWLs=src_cwls, target_CWLs=CFG.target_CWL,),
args=dict(source_CWLs=src_cwls, target_CWLs=tgt_cwl,),
kwargs=dict(kind='linear')
))
......@@ -124,9 +136,9 @@ class L2B_object(L2A_object):
###################
self.LayerBandsAssignment = tgt_LBA
self.MetaObj.CWL = list(CFG.target_CWL)
self.MetaObj.FWHM = list(CFG.target_FWHM)
self.MetaObj.bands = len(CFG.target_CWL)
self.MetaObj.CWL = dict(zip(tgt_LBA, tgt_cwl))
self.MetaObj.FWHM = dict(zip(tgt_LBA, tgt_fwhm))
self.MetaObj.bands = len(tgt_LBA)
self.arr = im # type: GeoArray
self.spec_homo_errors = errs # type: Union[np.ndarray, None] # int16, None if ~CFG.spechomo_estimate_accuracy
......
......@@ -1861,7 +1861,7 @@ map_odictKeys_objAttrnames = {
def get_LayerBandsAssignment(GMS_id, nBands=None, sort_by_cwl=None, no_thermal=None, no_pan=None,
return_fullLBA=False):
return_fullLBA=False, proc_level=''):
# type: (GMS_identifier, int, bool, bool) -> list
"""Returns LayerBandsAssignment corresponding to given satellite, sensor and subsystem and with respect to
CFG.sort_bands_by_cwl, CFG.skip_thermal and CFG.skip_pan.
......@@ -1879,12 +1879,15 @@ def get_LayerBandsAssignment(GMS_id, nBands=None, sort_by_cwl=None, no_thermal=N
(default: CFG.skip_pan)
:param return_fullLBA: in case there is a subsystem:
whether to return LayerBandsAssignment for all bands or for the current subsystem
:param proc_level: processing level for which the LayerBandsAssignment is returned
(overrides the proc_level given with GMS_id)
"""
# set defaults
# NOTE: these values cannot be set in function signature because CFG is not present at library import time
sort_by_cwl = sort_by_cwl if sort_by_cwl is not None else CFG.sort_bands_by_cwl
no_thermal = no_thermal if no_thermal is not None else CFG.skip_thermal
no_pan = no_pan if no_pan is not None else CFG.skip_pan
proc_level = proc_level or GMS_id.proc_level
if GMS_id.image_type == 'RSD':
GMS_sensorcode = get_GMS_sensorcode(GMS_id)
......@@ -1956,7 +1959,7 @@ def get_LayerBandsAssignment(GMS_id, nBands=None, sort_by_cwl=None, no_thermal=N
LayerBandsAssignment = ['1']
# remove those bands that are excluded by atmospheric corrections if proc_level >= L1C
if GMS_id.proc_level not in [None, 'L1A', 'L1B']: # TODO replace with enum procL
if proc_level not in [None, 'L1A', 'L1B']: # TODO replace with enum procL
if CFG.target_radunit_optical == 'BOA_Ref':
# return LBA after AC
......@@ -1967,7 +1970,7 @@ def get_LayerBandsAssignment(GMS_id, nBands=None, sort_by_cwl=None, no_thermal=N
# atmospheric correction is not yet supported -> LBA will be the same after L1C
pass
if GMS_id.proc_level in ['L2B', 'L2C']:
if proc_level in ['L2B', 'L2C']:
# handle different number of bands after spectral homogenization to target sensor
if GMS_id.dataset_ID == CFG.datasetid_spectral_ref:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment