Commit 5f0ebea3 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Implemented accuracy layer for geometric homogenization.

parent b8d0dead
...@@ -550,6 +550,7 @@ class L1B_object(L1A_object): ...@@ -550,6 +550,7 @@ class L1B_object(L1A_object):
COREG_obj.coreg_info) # no clipping to trueCornerLonLat until here -> only shift correction COREG_obj.coreg_info) # no clipping to trueCornerLonLat until here -> only shift correction
self.coreg_info.update({'reference scene ID': self.spatRef_scene.scene_ID}) self.coreg_info.update({'reference scene ID': self.spatRef_scene.scene_ID})
self.coreg_info.update({'reference entity ID': self.spatRef_scene.entity_ID}) self.coreg_info.update({'reference entity ID': self.spatRef_scene.entity_ID})
self.coreg_info.update({'shift_reliability': COREG_obj.shift_reliability})
if COREG_obj.success: if COREG_obj.success:
self.coreg_info['success'] = True self.coreg_info['success'] = True
......
...@@ -67,6 +67,9 @@ class AccuracyCube(GeoArray): ...@@ -67,6 +67,9 @@ class AccuracyCube(GeoArray):
elif errArrName == 'mask_clouds_confidence': elif errArrName == 'mask_clouds_confidence':
bandnames.append('confidence of cloud mask') bandnames.append('confidence of cloud mask')
elif errArrName == 'spat_homo_errors':
bandnames.append('shift reliability percentage')
elif errArrName == 'spec_homo_errors': elif errArrName == 'spec_homo_errors':
if CFG.spechomo_bandwise_accuracy: if CFG.spechomo_bandwise_accuracy:
bandnames.extend(['error of spectral homogenization %s' % bN for bN in errArr.bandnames]) bandnames.extend(['error of spectral homogenization %s' % bN for bN in errArr.bandnames])
...@@ -93,4 +96,10 @@ class AccuracyCube(GeoArray): ...@@ -93,4 +96,10 @@ class AccuracyCube(GeoArray):
err_layers['spec_homo_errors'].arr = \ err_layers['spec_homo_errors'].arr = \
np.median(err_layers['spec_homo_errors'], axis=2).astype(err_layers['spec_homo_errors'].dtype) np.median(err_layers['spec_homo_errors'], axis=2).astype(err_layers['spec_homo_errors'].dtype)
return np.array(np.dstack(err_layers.values()), dtype='int16') # stack all accuracy layers together
accArr = np.dstack(err_layers.values()).astype('int16')
# apply int16 nodata value
accArr[self._GMS_obj.arr.mask_nodata.astype(np.int8) == 0] = get_outFillZeroSaturated('int16')[0]
return accArr
...@@ -19,7 +19,7 @@ dtype_lib_GDAL_Python = {"uint8": 1, "int8": 1, "uint16": 2, "int16": 3, "uint32 ...@@ -19,7 +19,7 @@ dtype_lib_GDAL_Python = {"uint8": 1, "int8": 1, "uint16": 2, "int16": 3, "uint32
proc_chain = ['L1A', 'L1B', 'L1C', 'L2A', 'L2B', 'L2C'] proc_chain = ['L1A', 'L1B', 'L1C', 'L2A', 'L2B', 'L2C']
db_jobs_statistics_def = {'pending': 1, 'started': 2, None: 2, 'L1A': 3, 'L1B': 4, 'L1C': 5, 'L2A': 6, 'L2B': 7, db_jobs_statistics_def = {'pending': 1, 'started': 2, None: 2, 'L1A': 3, 'L1B': 4, 'L1C': 5, 'L2A': 6, 'L2B': 7,
'L2C': 8, 'FAILED': 9} # NOTE: OrderedDicts passed to L1A_map have proc_level=None 'L2C': 8, 'FAILED': 9} # NOTE: OrderedDicts passed to L1A_map have proc_level=None
bandslist_all_errors = ['ac_errors', 'mask_clouds_confidence', 'spec_homo_errors'] bandslist_all_errors = ['ac_errors', 'mask_clouds_confidence', 'spat_homo_errors', 'spec_homo_errors']
def get_GMS_sensorcode(GMS_identifier): def get_GMS_sensorcode(GMS_identifier):
......
...@@ -66,6 +66,8 @@ class MultiSlotLock(Lock): ...@@ -66,6 +66,8 @@ class MultiSlotLock(Lock):
else: else:
pass pass
return self
def __exit__(self, exc_type=None, exc_value=None, traceback=None): def __exit__(self, exc_type=None, exc_value=None, traceback=None):
if self.allowed_threads and self.conn: if self.allowed_threads and self.conn:
super().__exit__(exc_type=exc_type, exc_value=exc_value, traceback=traceback) super().__exit__(exc_type=exc_type, exc_value=exc_value, traceback=traceback)
......
...@@ -44,6 +44,7 @@ class Dataset(object): ...@@ -44,6 +44,7 @@ class Dataset(object):
self._pathGen = None self._pathGen = None
self._ac_options = {} self._ac_options = {}
self._ac_errors = None self._ac_errors = None
self._spat_homo_errors = None
self._spec_homo_errors = None self._spec_homo_errors = None
self._accuracy_layers = None self._accuracy_layers = None
......
...@@ -277,6 +277,7 @@ class GMS_object(Dataset): ...@@ -277,6 +277,7 @@ class GMS_object(Dataset):
'corrected_shifts_map': {'x': 0, 'y': 0}, 'corrected_shifts_map': {'x': 0, 'y': 0},
'original map info': self.meta_odict['map info'], 'original map info': self.meta_odict['map info'],
'updated map info': None, 'updated map info': None,
'shift_reliability': None,
'reference scene ID': None, 'reference scene ID': None,
'reference entity ID': None, 'reference entity ID': None,
'reference geotransform': None, 'reference geotransform': None,
...@@ -400,6 +401,24 @@ class GMS_object(Dataset): ...@@ -400,6 +401,24 @@ class GMS_object(Dataset):
def ac_errors(self): def ac_errors(self):
self._ac_errors = None self._ac_errors = None
@property
def spat_homo_errors(self):
if not self._spat_homo_errors and self.coreg_info['shift_reliability'] is not None:
errArr = GeoArray(np.full(self.arr.shape[:2], self.coreg_info['shift_reliability'], dtype=np.uint8),
geotransform=self.arr.geotransform,
projection=self.arr.projection,
bandnames=['shift_reliability'],
nodata=DEF_D.get_outFillZeroSaturated(np.uint8)[0])
errArr[self.arr.mask_nodata.astype(np.int8) == 0] = errArr.nodata
self._spat_homo_errors = errArr
return self._spat_homo_errors
@spat_homo_errors.deleter
def spat_homo_errors(self):
self._spat_homo_errors = None
@property @property
def spec_homo_errors(self): def spec_homo_errors(self):
"""Returns an instance of GeoArray containing error information calculated during spectral homogenization. """Returns an instance of GeoArray containing error information calculated during spectral homogenization.
...@@ -1303,7 +1322,7 @@ class GMS_object(Dataset): ...@@ -1303,7 +1322,7 @@ class GMS_object(Dataset):
attributes2write.append('mask_clouds') attributes2write.append('mask_clouds')
if self.proc_level == 'L2C': if self.proc_level == 'L2C':
if CFG.ac_estimate_accuracy or CFG.spechomo_estimate_accuracy: if CFG.ac_estimate_accuracy or CFG.spathomo_estimate_accuracy or CFG.spechomo_estimate_accuracy:
attributes2write.append('accuracy_layers') attributes2write.append('accuracy_layers')
else: else:
self.logger.info('Accuracy layers are not written because their generation has been disabled in the ' self.logger.info('Accuracy layers are not written because their generation has been disabled in the '
...@@ -1654,6 +1673,7 @@ class GMS_object(Dataset): ...@@ -1654,6 +1673,7 @@ class GMS_object(Dataset):
del self.masks del self.masks
del self.mask_clouds_confidence del self.mask_clouds_confidence
del self.ac_errors del self.ac_errors
del self.spat_homo_errors
del self.spec_homo_errors del self.spec_homo_errors
del self.accuracy_layers del self.accuracy_layers
......
...@@ -350,6 +350,8 @@ class JobConfig(object): ...@@ -350,6 +350,8 @@ class JobConfig(object):
gp('coreg_max_shift_allowed', json_processors['L1B']['coreg_max_shift_allowed']) gp('coreg_max_shift_allowed', json_processors['L1B']['coreg_max_shift_allowed'])
self.coreg_window_size = \ self.coreg_window_size = \
gp('coreg_window_size', json_processors['L1B']['coreg_window_size']) gp('coreg_window_size', json_processors['L1B']['coreg_window_size'])
self.spathomo_estimate_accuracy = \
gp('spathomo_estimate_accuracy', json_processors['L1B']['spathomo_estimate_accuracy'])
# L1C # L1C
self.exec_L1CP = gp('exec_L1CP', [ self.exec_L1CP = gp('exec_L1CP', [
......
...@@ -87,7 +87,8 @@ ...@@ -87,7 +87,8 @@
"spatial_ref_plusminus_years": 10, /*maximum time interval between target and reference scene in years*/ "spatial_ref_plusminus_years": 10, /*maximum time interval between target and reference scene in years*/
"coreg_band_wavelength_for_matching": 550, /*optimal wavelength [nm] of the spectral bands used for matching*/ "coreg_band_wavelength_for_matching": 550, /*optimal wavelength [nm] of the spectral bands used for matching*/
"coreg_max_shift_allowed": 5, /*maximum shift distance in reference image pixel units (default: 5 px)*/ "coreg_max_shift_allowed": 5, /*maximum shift distance in reference image pixel units (default: 5 px)*/
"coreg_window_size": [256, 256] "coreg_window_size": [256, 256],
"spathomo_estimate_accuracy": false
}, },
"L1C": { /*Level 1C processing: atmospheric correction*/ "L1C": { /*Level 1C processing: atmospheric correction*/
......
...@@ -75,7 +75,8 @@ gms_schema_input = dict( ...@@ -75,7 +75,8 @@ gms_schema_input = dict(
coreg_band_wavelength_for_matching=dict(type='integer', required=False, min=350, max=2500), coreg_band_wavelength_for_matching=dict(type='integer', required=False, min=350, max=2500),
coreg_max_shift_allowed=dict(type='float', required=False, min=0), coreg_max_shift_allowed=dict(type='float', required=False, min=0),
coreg_window_size=dict(type='list', required=False, minlength=0, maxlength=2, coreg_window_size=dict(type='list', required=False, minlength=0, maxlength=2,
schema=dict(type='integer', required=False, min=8)) schema=dict(type='integer', required=False, min=8)),
spathomo_estimate_accuracy=dict(type='boolean', required=False),
)), )),
L1C=dict(type='dict', required=False, schema=dict( L1C=dict(type='dict', required=False, schema=dict(
run_processor=dict(type='boolean', required=False), run_processor=dict(type='boolean', required=False),
......
...@@ -767,7 +767,8 @@ class process_controller(object): ...@@ -767,7 +767,8 @@ class process_controller(object):
highest_procL_Objs = [] highest_procL_Objs = []
for pL in reversed(proc_chain): for pL in reversed(proc_chain):
if getattr(self.config, 'exec_%sP' % pL)[0]: if getattr(self.config, 'exec_%sP' % pL)[0]:
highest_procL_Objs = getattr(self, '%s_newObjects' % pL) if pL != 'L2A' else self.L2A_tiles highest_procL_Objs = \
getattr(self, '%s_newObjects' % pL) if pL != 'L2A' else (self.L2A_tiles or self.L2A_newObjects)
break break
gms_objects2summarize = highest_procL_Objs + self.failed_objects gms_objects2summarize = highest_procL_Objs + self.failed_objects
......
...@@ -206,6 +206,7 @@ class BaseTestCases: ...@@ -206,6 +206,7 @@ class BaseTestCases:
cls.PC.config.CPUs_all_jobs = 2 cls.PC.config.CPUs_all_jobs = 2
cls.PC.config.max_parallel_reads_writes = 2 cls.PC.config.max_parallel_reads_writes = 2
# cls.PC.config.spathomo_estimate_accuracy = True
# cls.PC.config.ac_estimate_accuracy = True # FIXME # cls.PC.config.ac_estimate_accuracy = True # FIXME
# cls.PC.config.spechomo_estimate_accuracy = True # FIXME # cls.PC.config.spechomo_estimate_accuracy = True # FIXME
......
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