Commit 8777c184 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Bugfix for issue #57 (Atmospheric correction fails if no DEM is available).

Bugfix exception handler. Added tests to test_exception_handler.


Former-commit-id: 8c958955
parent 4aff0ae2
......@@ -789,6 +789,10 @@ class AtmCorr(object):
# returns an instance of S2Mask or None if cloud mask is not given by input GMS objects
) # NOTE: all keys of this dict are later converted to attributes of RSImage
# remove empty values from RSImage kwargs because SICOR treats any kind of RSImage attributes as given
# => 'None'-attributes may cause issues
rs_data = {k: v for k, v in rs_data.items() if v is not None}
script = False
# check if ECMWF data are available - if not, start the download
......
......@@ -87,13 +87,14 @@ class ExceptionHandler(object):
self.increment_progress()
# GMS_mapper inputs CONTAIN failed_GMS_objects -> log and directly return failed_GMS_object
# GMS_mapper inputs CONTAIN failed_GMS_objects -> log and return mapper inputs as received
else:
GMS_obj = self.get_sample_GMS_obj(self.GMS_objs) # type: failed_GMS_object
# FIXME in case self.GMS_objs is a list and the failed object is not at first position
# FIXME GMS_obj.failedMapper will not work
print("Scene %s (entity ID %s) skipped %s due to an unexpected exception in %s."
% (GMS_obj.scene_ID, GMS_obj.entity_ID, self.GMS_mapper_name,
GMS_obj.failedMapper)) # TODO should be logged by PC.logger
self.GMS_objs = GMS_obj
return self.GMS_objs # type: Union[GMS_object, List[GMS_object], failed_GMS_object]
......@@ -137,7 +138,7 @@ class ExceptionHandler(object):
@staticmethod
def get_sample_GMS_obj(GMS_objs):
# type: (Union[list, tuple, collections.OrderedDict]) -> GMS_object
# type: (Union[list, tuple, collections.OrderedDict, failed_GMS_object]) -> Union[GMS_object, failed_GMS_object]
return \
GMS_objs if isinstance(GMS_objs, collections.OrderedDict) else \
GMS_objs[0] if isinstance(GMS_objs, (list, tuple)) else GMS_objs
......
......@@ -14,6 +14,7 @@ from gms_preprocessing import process_controller
from gms_preprocessing.misc.exception_handler import log_uncaught_exceptions
from gms_preprocessing.algorithms.L1A_P import L1A_object
from gms_preprocessing.misc.database_tools import get_info_from_postgreSQLdb
from gms_preprocessing.model.gms_object import failed_GMS_object
from . import db_host
......@@ -42,7 +43,13 @@ class BaseTest_ExceptionHandler:
@staticmethod
@log_uncaught_exceptions
def dummy_L1A_mapper_success(dummy_GMSobj):
return L1A_object(**dummy_GMSobj)
return dummy_GMSobj
@staticmethod
@log_uncaught_exceptions
def dummy_mapper_multiple_inputs(list_dummy_GMSobjs):
list_dummy_GMSobjs[0].proc_level = 'changed'
return list_dummy_GMSobjs
@staticmethod
@log_uncaught_exceptions
......@@ -79,6 +86,12 @@ class Test_ExceptionHandler_NoSubsystems(BaseTest_ExceptionHandler.Test_Exceptio
with(self.assertRaises(RuntimeError)):
self.dummy_gms_mapper_fail(self.PC.config.data_list[0])
def test_exception_handler_receives_failed_object(self):
failed_obj = failed_GMS_object(self.PC.config.data_list[0],
failedMapper='dummy_mapper', exc_type=RuntimeError, exc_val='SomeVal', exc_tb='')
returnVal = self.dummy_L1A_mapper_success(failed_obj)
self.assertIsInstance(returnVal, failed_GMS_object)
class Test_ExceptionHandler_Subsystems(BaseTest_ExceptionHandler.Test_ExceptionHandler):
""""""
......@@ -139,3 +152,15 @@ class Test_ExceptionHandler_Subsystems(BaseTest_ExceptionHandler.Test_ExceptionH
self.assertEqual(self.get_current_progress_stats(), [0, 0, 0, 0, 0, 0, 0, 0, 1])
self.assertEqual(self.get_current_progress_stats(), [0, 0, 0, 0, 0, 0, 0, 0, 1])
def test_exception_handler_receives_failed_objects(self):
failed_obj = failed_GMS_object(self.PC.config.data_list[0],
failedMapper='dummy_mapper', exc_type=RuntimeError, exc_val='SomeVal', exc_tb='')
L1A_obj = L1A_object(**self.PC.config.data_list[0])
# in case the mapper inputs contain a failed_object,
# the exception handler must directly return the mapper inputs as received without calling the mapper function
mapper_inputs = [failed_obj, L1A_obj]
returnVal = self.dummy_mapper_multiple_inputs(mapper_inputs)
self.assertTrue(mapper_inputs == returnVal)
self.assertTrue(returnVal[0].proc_level != 'changed')
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