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

Fixed issue #61 ([AC]: RuntimeWarning: All-NaN slice encountered).

parent dc832011
...@@ -523,7 +523,7 @@ class L1B_object(L1A_object): ...@@ -523,7 +523,7 @@ class L1B_object(L1A_object):
ref_band4match = 1 ref_band4match = 1
self.logger.info( self.logger.info(
'Target band for matching: %s (%snm)' % (shift_band4match, shift_cwl[shift_band4match - 1])) 'Target band for matching: %s (%snm)' % (shift_band4match, shift_cwl[shift_band4match - 1]))
self.logger.info( self.logger.info(
'Reference band for matching: %s (%snm)' % (ref_band4match, ref_cwl[ref_band4match - 1])) 'Reference band for matching: %s (%snm)' % (ref_band4match, ref_cwl[ref_band4match - 1]))
......
...@@ -976,7 +976,8 @@ class AtmCorr(object): ...@@ -976,7 +976,8 @@ class AtmCorr(object):
:param bandwise: if True, a 3D array with bandwise information for each pixel is generated :param bandwise: if True, a 3D array with bandwise information for each pixel is generated
:return: :return:
""" """
# TODO how to handle nans? # TODO ac_error values are very close to 0 -> a scale factor of 255 yields int8 values below 10
# TODO => better to stretch the whole array to values between 0 and 100 and save original min/max?
if self.results.data_errors is not None: if self.results.data_errors is not None:
for inObj in self.inObjs: for inObj in self.inObjs:
...@@ -985,26 +986,29 @@ class AtmCorr(object): ...@@ -985,26 +986,29 @@ class AtmCorr(object):
nodata = self.results.nodata[inObj.arr.xgsd] # 2D mask with True outside of image coverage nodata = self.results.nodata[inObj.arr.xgsd] # 2D mask with True outside of image coverage
ac_bandNs = [bandN for bandN in inObj.arr.bandnames if bandN in self.results.data_ac.keys()] ac_bandNs = [bandN for bandN in inObj.arr.bandnames if bandN in self.results.data_ac.keys()]
out_dtype = np.int8 if CFG.ac_scale_factor_errors <= 255 else np.int16
out_nodata_val = get_outFillZeroSaturated(out_dtype)[0]
# generate raw ac_errors array # generate raw ac_errors array
ac_errors = np.dstack((self.results.data_errors[bandN] for bandN in ac_bandNs)) ac_errors = np.dstack((self.results.data_errors[bandN] for bandN in ac_bandNs))
# apply scale factor from config to data pixels and overwrite nodata area with nodata value
ac_errors *= CFG.ac_scale_factor_errors # scale using scale factor (output is float16)
ac_errors[np.isnan(ac_errors)] = out_nodata_val # replace NaNs with outnodata
ac_errors[nodata] = out_nodata_val # set all positions where SICOR nodata mask is 1 to outnodata
ac_errors = np.around(ac_errors).astype(out_dtype) # round floats to next even int8/int16 value
# average array over bands if no bandwise information is requested
if not bandwise: if not bandwise:
# in case of only one subsystem: directly compute median errors here # in case of only one subsystem: directly compute median errors here
if len(self.inObjs) == 1: if len(self.inObjs) == 1:
ac_errors = np.nanmedian(ac_errors, axis=2).astype(ac_errors.dtype) ac_errors = np.median(ac_errors, axis=2).astype(ac_errors.dtype)
# in case of multiple subsystems: dont compute median here but first apply geometric homogenization # in case of multiple subsystems: dont compute median here but first apply geometric homogenization
# -> median could only be computed for each subsystem separately # -> median could only be computed for each subsystem separately
else: else:
pass pass
# apply scale factor from config to data pixels and overwrite nodata area with nodata value
ac_errors *= CFG.ac_scale_factor_errors # scale using scale factor (output is float16)
out_dtype = np.int8 if CFG.ac_scale_factor_errors <= 255 else np.int16
ac_errors[nodata] = get_outFillZeroSaturated(out_dtype)[0]
ac_errors = ac_errors.astype(out_dtype)
# set inObj.ac_errors # set inObj.ac_errors
inObj.ac_errors = ac_errors # setter generates a GeoArray with the same bandnames like inObj.arr inObj.ac_errors = ac_errors # setter generates a GeoArray with the same bandnames like inObj.arr
......
...@@ -510,7 +510,8 @@ class Test_in_normal_mode(unittest.TestCase): ...@@ -510,7 +510,8 @@ class Test_in_normal_mode(unittest.TestCase):
# self.job_id = 26186925 # 1 Sentinel-2A, Bug NoneType' object has no attribute 'find' # self.job_id = 26186925 # 1 Sentinel-2A, Bug NoneType' object has no attribute 'find'
# self.job_id = 26187051 # GMS41: 1 Landsat, FileNotFoundError # self.job_id = 26187051 # GMS41: 1 Landsat, FileNotFoundError
# self.job_id = 26187052 # GMS41: 1 Landsat, DB query returns no DEM # self.job_id = 26187052 # GMS41: 1 Landsat, DB query returns no DEM
self.job_id = 26187053 # GMS41: AC: The input 'list_GMS_objs' contains duplicates: ['', ''] # self.job_id = 26187053 # GMS41: AC: The input 'list_GMS_objs' contains duplicates: ['', '']
self.job_id = 26187750 # GEOMS: [AC]: RuntimeWarning: All-NaN slice encountered
self.PC = process_controller(self.job_id, **dict(is_test=False, parallelization_level='scenes', db_host=db_host, self.PC = process_controller(self.job_id, **dict(is_test=False, parallelization_level='scenes', db_host=db_host,
delete_old_output=True, disable_exception_handler=True)) delete_old_output=True, disable_exception_handler=True))
......
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