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):
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 entity ID': self.spatRef_scene.entity_ID})
self.coreg_info.update({'shift_reliability': COREG_obj.shift_reliability})
if COREG_obj.success:
self.coreg_info['success'] = True
......
......@@ -67,6 +67,9 @@ class AccuracyCube(GeoArray):
elif errArrName == 'mask_clouds_confidence':
bandnames.append('confidence of cloud mask')
elif errArrName == 'spat_homo_errors':
bandnames.append('shift reliability percentage')
elif errArrName == 'spec_homo_errors':
if CFG.spechomo_bandwise_accuracy:
bandnames.extend(['error of spectral homogenization %s' % bN for bN in errArr.bandnames])
......@@ -93,4 +96,10 @@ class AccuracyCube(GeoArray):
err_layers['spec_homo_errors'].arr = \
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
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,
'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):
......
......@@ -66,6 +66,8 @@ class MultiSlotLock(Lock):
else:
pass
return self
def __exit__(self, exc_type=None, exc_value=None, traceback=None):
if self.allowed_threads and self.conn:
super().__exit__(exc_type=exc_type, exc_value=exc_value, traceback=traceback)
......
......@@ -44,6 +44,7 @@ class Dataset(object):
self._pathGen = None
self._ac_options = {}
self._ac_errors = None
self._spat_homo_errors = None
self._spec_homo_errors = None
self._accuracy_layers = None
......
......@@ -277,6 +277,7 @@ class GMS_object(Dataset):
'corrected_shifts_map': {'x': 0, 'y': 0},
'original map info': self.meta_odict['map info'],
'updated map info': None,
'shift_reliability': None,
'reference scene ID': None,
'reference entity ID': None,
'reference geotransform': None,
......@@ -400,6 +401,24 @@ class GMS_object(Dataset):
def ac_errors(self):
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
def spec_homo_errors(self):
"""Returns an instance of GeoArray containing error information calculated during spectral homogenization.
......@@ -1303,7 +1322,7 @@ class GMS_object(Dataset):
attributes2write.append('mask_clouds')
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')
else:
self.logger.info('Accuracy layers are not written because their generation has been disabled in the '
......@@ -1654,6 +1673,7 @@ class GMS_object(Dataset):
del self.masks
del self.mask_clouds_confidence
del self.ac_errors
del self.spat_homo_errors
del self.spec_homo_errors
del self.accuracy_layers
......
......@@ -350,6 +350,8 @@ class JobConfig(object):
gp('coreg_max_shift_allowed', json_processors['L1B']['coreg_max_shift_allowed'])
self.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
self.exec_L1CP = gp('exec_L1CP', [
......
......@@ -87,7 +87,8 @@
"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_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*/
......
......@@ -75,7 +75,8 @@ gms_schema_input = dict(
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_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(
run_processor=dict(type='boolean', required=False),
......
......@@ -767,7 +767,8 @@ class process_controller(object):
highest_procL_Objs = []
for pL in reversed(proc_chain):
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
gms_objects2summarize = highest_procL_Objs + self.failed_objects
......
......@@ -206,6 +206,7 @@ class BaseTestCases:
cls.PC.config.CPUs_all_jobs = 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.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