Commit 1574242e authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Bugfix L1A_object.archive_to_rasObj(). Added Test_Landsat8_CollectionData_CompletePipeline.

Former-commit-id: 585ca99c
Former-commit-id: 0e4b2efa
parent 98711b03
...@@ -103,6 +103,10 @@ class L1A_object(GMS_object): ...@@ -103,6 +103,10 @@ class L1A_object(GMS_object):
assert files_in_archive, 'No files in archive for scene %s (entity ID: %s). ' % (self.scene_ID, self.entity_ID) assert files_in_archive, 'No files in archive for scene %s (entity ID: %s). ' % (self.scene_ID, self.entity_ID)
full_LayerBandsAssignment = META.get_LayerBandsAssignment(self.GMS_identifier, no_thermal=False, no_pan=False) full_LayerBandsAssignment = META.get_LayerBandsAssignment(self.GMS_identifier, no_thermal=False, no_pan=False)
####################################################
# get list of raster files to be read from archive #
####################################################
image_files = [] image_files = []
is_ALOS_Landsat_S2 = \ is_ALOS_Landsat_S2 = \
re.search('ALOS', self.satellite) or re.search('Landsat', self.satellite) or \ re.search('ALOS', self.satellite) or re.search('Landsat', self.satellite) or \
...@@ -129,6 +133,9 @@ class L1A_object(GMS_object): ...@@ -129,6 +133,9 @@ class L1A_object(GMS_object):
# create and fill raster object # create and fill raster object
if n_files2search > 1: if n_files2search > 1:
#####################################
# validate number of expected files #
#####################################
if re.search('ETM+', self.sensor) and self.acq_datetime > datetime.datetime(year=2003, month=5, day=31): if re.search('ETM+', self.sensor) and self.acq_datetime > datetime.datetime(year=2003, month=5, day=31):
expected_files_count = 2 * len(full_LayerBandsAssignment) expected_files_count = 2 * len(full_LayerBandsAssignment)
else: else:
...@@ -138,10 +145,24 @@ class L1A_object(GMS_object): ...@@ -138,10 +145,24 @@ class L1A_object(GMS_object):
% (len(full_LayerBandsAssignment), path_archive, % (len(full_LayerBandsAssignment), path_archive,
len(image_files)) len(image_files))
filtered_files = [image_files[full_LayerBandsAssignment.index(i)] for i in self.LayerBandsAssignment] ###############################
# get paths of files to stack #
###############################
# NOTE: image_files is a SORTED list of image filenames; self.LayerBandsAssignment may be sorted by CWL
filtered_files = []
for bN in self.LayerBandsAssignment: # unsorted, e.g., ['1', '2', '3', '4', '5', '9', '6', '7']
for fN, b in zip(image_files, HLP_F.sorted_nicely(full_LayerBandsAssignment)): # both sorted nicely
if b == bN:
filtered_files.append(fN)
paths_files2stack = [os.path.join(gdal_path_archive, i) for i in filtered_files] paths_files2stack = [os.path.join(gdal_path_archive, i) for i in filtered_files]
#########################
# read the raster data #
#########################
rasObj = GEOP.GEOPROCESSING(paths_files2stack[0], self.logger) rasObj = GEOP.GEOPROCESSING(paths_files2stack[0], self.logger)
# in case a subset is to be read: prepare rasObj instance to read a subset
if subset: if subset:
full_dim = [0, rasObj.rowEnd, 0, rasObj.colEnd] full_dim = [0, rasObj.rowEnd, 0, rasObj.colEnd]
sub_dim = [subset[1][0][0], subset[1][0][1], subset[1][1][0], subset[1][0][1]] sub_dim = [subset[1][0][0], subset[1][0][1], subset[1][1][0], subset[1][0][1]]
...@@ -149,6 +170,7 @@ class L1A_object(GMS_object): ...@@ -149,6 +170,7 @@ class L1A_object(GMS_object):
subset = ['block', [[sub_dim[0], sub_dim[1] + 1], [sub_dim[2], sub_dim[3] + 1]]] subset = ['block', [[sub_dim[0], sub_dim[1] + 1], [sub_dim[2], sub_dim[3] + 1]]]
rasObj = GEOP.GEOPROCESSING(paths_files2stack[0], self.logger, subset=subset) rasObj = GEOP.GEOPROCESSING(paths_files2stack[0], self.logger, subset=subset)
# perform layer stack
if CFG.inmem_serialization and path_output is None: # numpy array output if CFG.inmem_serialization and path_output is None: # numpy array output
self.arr = rasObj.Layerstacking(paths_files2stack) self.arr = rasObj.Layerstacking(paths_files2stack)
self.path_InFilePreprocessor = paths_files2stack[0] self.path_InFilePreprocessor = paths_files2stack[0]
......
...@@ -88,8 +88,8 @@ class L2B_object(L2A_object): ...@@ -88,8 +88,8 @@ class L2B_object(L2A_object):
SpH = SpectralHomogenizer(classifier_rootDir=CFG.path_spechomo_classif, logger=self.logger) SpH = SpectralHomogenizer(classifier_rootDir=CFG.path_spechomo_classif, logger=self.logger)
if method == 'LI' or CFG.datasetid_spectral_ref is None: if method == 'LI' or CFG.datasetid_spectral_ref is None:
# linear interpolation # linear interpolation (if intended by user or in case of custom spectral characteristics of target sensor)
# or a custom sensor has been specified -> no classifier for that case available -> linear interpolation # -> no classifier for that case available -> linear interpolation
outArr = SpH.interpolate_cube(self.arr, src_cwls, tgt_cwls, kind='linear') outArr = SpH.interpolate_cube(self.arr, src_cwls, tgt_cwls, kind='linear')
else: else:
...@@ -174,13 +174,16 @@ class SpectralHomogenizer(object): ...@@ -174,13 +174,16 @@ class SpectralHomogenizer(object):
:param tgt_sensor: target sensor, e.g., 'OLI_TIRS' :param tgt_sensor: target sensor, e.g., 'OLI_TIRS'
:param tgt_LBA: target LayerBandsAssignment :param tgt_LBA: target LayerBandsAssignment
:param nodataVal: no data value :param nodataVal: no data value
:param fallback_argskwargs: arguments and keyword arguments for fallback algorithm ({'args:{}, 'kwargs': {}} :param fallback_argskwargs: arguments and keyword arguments for fallback algorithm ({'args':{}, 'kwargs': {}}
:return: predicted array (rows x columns x bands) :return: predicted array (rows x columns x bands)
""" """
# TODO: add LBA validation to .predict() # TODO: add LBA validation to .predict()
PR = RSImage_Predictor(method=method, classifier_rootDir=self.classifier_rootDir) PR = RSImage_Predictor(method=method, classifier_rootDir=self.classifier_rootDir)
# get the classifier ######################
# get the classifier #
######################
cls = None cls = None
exc = Exception() exc = Exception()
try: try:
...@@ -196,7 +199,10 @@ class SpectralHomogenizer(object): ...@@ -196,7 +199,10 @@ class SpectralHomogenizer(object):
self.logger.error(traceback.format_exc()) self.logger.error(traceback.format_exc())
exc = e exc = e
# run prediction ##################
# run prediction #
##################
if cls: if cls:
self.logger.info('Performing spectral homogenization using %s. Target is %s %s %s.' self.logger.info('Performing spectral homogenization using %s. Target is %s %s %s.'
% (method, tgt_satellite, tgt_sensor, tgt_LBA)) % (method, tgt_satellite, tgt_sensor, tgt_LBA))
......
...@@ -278,6 +278,18 @@ class Test_Landsat8_CollectionData(BaseTestCases.TestAll): ...@@ -278,6 +278,18 @@ class Test_Landsat8_CollectionData(BaseTestCases.TestAll):
cls.create_job(26187391, job_config_kwargs) cls.create_job(26187391, job_config_kwargs)
class Test_Landsat8_CollectionData_CompletePipeline(BaseTestCases.TestCompletePipeline):
"""
Parametrized testclass. Tests the level-processes on a Landsat-8 OLI_TIRS scene (collection data).
More information on the dataset will be output after the tests-classes are executed.
"""
@classmethod
def setUpClass(cls):
cfg = job_config_kwargs
# cfg.update(dict(inmem_serialization=True))
cls.create_job(26187391, cfg)
class Test_Sentinel2A_SingleGranuleFormat(BaseTestCases.TestAll): class Test_Sentinel2A_SingleGranuleFormat(BaseTestCases.TestAll):
""" """
Parametrized testclass. Tests the level-processes on a Sentinel-2A MSI scene (1 granule in archive: > 2017). Parametrized testclass. Tests the level-processes on a Sentinel-2A MSI scene (1 granule in archive: > 2017).
......
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