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

Bugfix for writing wring center wavelengths into L2B classifiers.

parent 36ae2aa1
Pipeline #3054 failed with stage
in 14 minutes and 24 seconds
......@@ -41,7 +41,7 @@ from ..misc.definition_dicts import datasetid_to_sat_sen, sat_sen_to_datasetid
from ..misc.exceptions import ClassifierNotAvailableError
from ..misc.logging import close_logger
from ..model.gms_object import GMS_object
from ..model.metadata import get_LayerBandsAssignment
from ..model.metadata import get_LayerBandsAssignment, get_center_wavelengths_by_LBA
from .L2A_P import L2A_object
from ..model.gms_object import GMS_identifier
from .classification import classify_image
......@@ -1068,10 +1068,10 @@ class RefCube(object):
@property
def wavelengths(self):
if not self._wavelenths and self.satellite and self.sensor and self.LayerBandsAssignment:
srf = SRF(GMS_identifier(satellite=self.satellite, sensor=self.sensor, subsystem=None, image_type='RSD',
dataset_ID=-9999, proc_level='L1A', logger=None),
no_thermal=True, no_pan=False)
self._wavelenths = [srf.conv[b] for b in self.LayerBandsAssignment]
self._wavelenths = get_center_wavelengths_by_LBA(satellite=self.satellite,
sensor=self.sensor,
LBA=self.LayerBandsAssignment)
return self._wavelenths
@wavelengths.setter
......@@ -1356,6 +1356,11 @@ class ClusterClassifier_Generator(object):
# print('Creating %s cluster classifier for LBA %s => %s...'
# % (method, '_'.join(src_LBA), '_'.join(tgt_LBA)))
# Get center wavelength positions
# NOTE: they cannot be taken from RefCube instances because they always represent L1A LBAs
src_wavelengths = get_center_wavelengths_by_LBA(src_cube.satellite, src_cube.sensor, src_LBA)
tgt_wavelengths = get_center_wavelengths_by_LBA(tgt_cube.satellite, tgt_cube.sensor, tgt_LBA)
# Get training data for source and target image according to the given LayerBandsAssignments
# e.g., source: Landsat 7 image in LBA 1__2__3__4__5__7 and target L8 in 1__2__3__4__5__6__7
src_data = src_cube.get_band_combination(src_LBA)
......@@ -1398,12 +1403,15 @@ class ClusterClassifier_Generator(object):
ML.tgt_LBA = tgt_LBA
ML.src_n_bands = len(ML.src_LBA)
ML.tgt_n_bands = len(ML.tgt_LBA)
ML.src_wavelengths = list(np.array(src_cube.wavelengths).astype(np.float32))
ML.tgt_wavelengths = list(np.array(tgt_cube.wavelengths).astype(np.float32))
ML.src_wavelengths = list(np.array(src_wavelengths).astype(np.float32))
ML.tgt_wavelengths = list(np.array(tgt_wavelengths).astype(np.float32))
ML.n_clusters = n_clusters
ML.clusterlabel = clusterlabel
ML.cluster_center = cluster_center
assert len(ML.src_LBA) == len(ML.src_wavelengths)
assert len(ML.tgt_LBA) == len(ML.tgt_wavelengths)
# append to classifier collection
cls_collection[
'__'.join(src_LBA)][tgt_cube.satellite, tgt_cube.sensor][
......
......@@ -25,7 +25,7 @@ from py_tools_ds.geo.projection import WKT2EPSG
from sicor.options import get_options as get_ac_options
from ..options.config import GMS_config as CFG
from ..io.input_reader import open_specific_file_within_archive, Solar_Irradiance_reader, SRF_reader
from ..io.input_reader import open_specific_file_within_archive, Solar_Irradiance_reader, SRF_reader, SRF
from ..io.output_writer import enviHdr_keyOrder
from ..algorithms import geoprocessing as GEOP
from ..misc import helper_functions as HLP_F
......@@ -2031,6 +2031,24 @@ def get_bands_after_AC(GMS_id):
return ac_out_bands
def get_center_wavelengths_by_LBA(satellite, sensor, LBA, subsystem=None):
# type: (str, str, list) -> list
"""Returns a list of center wavelengths of spectral bands for the given satellite/sensor/LayerBandsAss. combination.
:param satellite: target satellite (e.g., 'Sentinel-2A')
:param sensor: target sensor (e.g., 'MSI')
:param LBA: LayerBandsAssignment
:param subsystem: target sensor subsystem (e.g., 'VNIR')
"""
from ..model.gms_object import GMS_identifier # would cause circular import
srf = SRF(GMS_identifier(satellite=satellite, sensor=sensor, subsystem=subsystem, image_type='RSD',
dataset_ID=-9999, proc_level='L1A', logger=None),
no_thermal=True, no_pan=False)
return [srf.conv[b] for b in LBA]
def get_dict_LayerOptTherm(GMS_id, LayerBandsAssignment):
dict_out = collections.OrderedDict()
[dict_out.update({lr: 'thermal' if isTHERMAL(GMS_id, lr) else 'optical'}) for lr in LayerBandsAssignment]
......
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