Commit 6d0a28a1 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Added possibility to ignore bands removed by AC.


Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent 33d08993
......@@ -17,8 +17,8 @@ from .sensorspecs import get_LayerBandsAssignment
def RSR_reader(satellite, sensor, subsystem='',
LayerBandsAssignment=None, sort_by_cwl=False, no_thermal=False, no_pan=False, v=False):
# type: (str, str, str, list, bool, bool, bool, bool) -> collections.OrderedDict
LayerBandsAssignment=None, sort_by_cwl=False, after_ac=False, no_thermal=False, no_pan=False, v=False):
# type: (str, str, str, list, bool, bool, bool, bool, bool) -> collections.OrderedDict
"""Read RSR for any sensor and return a dictionary containing band names as keys and RSR numpy arrays as values.
:param satellite: satellite to read the relative spectral response for
......@@ -27,6 +27,8 @@ def RSR_reader(satellite, sensor, subsystem='',
:param LayerBandsAssignment: custom list of bands to read, e.g., ['1', '3', '8']
:param sort_by_cwl: whether to sort the returned bands list by central wavelength position
(default: False)
:param after_ac: whether to ignore bands that are not available anymore after atmospheric correction
(default: False)
:param no_thermal: whether to exclude thermal bands from the returned bands list (default: False)
:param no_pan: whether to exclude panchromatic bands from the returned bands list (default: False)
:param v: verbose mode
......@@ -35,7 +37,7 @@ def RSR_reader(satellite, sensor, subsystem='',
RSR_dir = os.path.join(__path__[0], 'data', satellite, sensor)
LBA = LayerBandsAssignment or get_LayerBandsAssignment(satellite, sensor, subsystem,
no_thermal=no_thermal, no_pan=no_pan,
sort_by_cwl=sort_by_cwl)
sort_by_cwl=sort_by_cwl, after_ac=after_ac)
bandnames = ['band_%s' % b for b in LBA]
for bandname in bandnames:
......@@ -53,8 +55,8 @@ def RSR_reader(satellite, sensor, subsystem='',
class RelativeSpectralResponse(object):
def __init__(self, satellite, sensor, subsystem='', wvl_unit='nanometers', specres_nm=1, format_bandnames=False,
LayerBandsAssignment=None, sort_by_cwl=False, no_thermal=False, no_pan=False, v=False):
# type: (str, str, str, str, float, bool, list, bool, bool, bool, bool) -> None
LayerBandsAssignment=None, sort_by_cwl=False, after_ac=False, no_thermal=False, no_pan=False, v=False):
# type: (str, str, str, str, float, bool, list, bool, bool, bool, bool, bool) -> None
"""RelativeSpectralResponse instance provides relative spectral response functions, wavelength positions, etc..
:param satellite: satellite to create the RelativeSpectralResponse instance for
......@@ -66,6 +68,8 @@ class RelativeSpectralResponse(object):
:param LayerBandsAssignment: custom list of bands to include, e.g., ['1', '3', '8']
:param sort_by_cwl: whether to sort the returned bands list by central wavelength position
(default: False)
:param after_ac: whether to ignore bands that are not available anymore after atmospheric correction
(default: False)
:param no_thermal whether to exclude thermal bands from the returned bands list
(default: False)
:param no_pan: whether to exclude panchromatic bands from the returned bands list
......@@ -93,7 +97,8 @@ class RelativeSpectralResponse(object):
self.v = v
self.from_satellite_sensor(satellite, sensor, subsystem,
sort_by_cwl=sort_by_cwl, no_thermal=no_thermal, no_pan=no_pan, v=v)
sort_by_cwl=sort_by_cwl, after_ac=after_ac,
no_thermal=no_thermal, no_pan=no_pan, v=v)
def from_satellite_sensor(self, satellite, sensor, subsystem='', **kwargs):
rsr_dict = RSR_reader(satellite, sensor, subsystem, **kwargs) # (ordered according to LBA)
......
......@@ -80,6 +80,7 @@ sensors = {
'sensor': 'LDCM',
'LBA': ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11'],
'LBA_sorted': ['1', '2', '3', '4', '5', '9', '6', '7', '8', '10', '11'],
'LBA_after_AC': ['1', '2', '3', '4', '5', '6', '7'],
'pan': ['8'],
'thermal': ['10', '11']
},
......@@ -89,6 +90,7 @@ sensors = {
'sensor': 'OLI_TIRS',
'LBA': ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11'],
'LBA_sorted': ['1', '2', '3', '4', '5', '9', '6', '7', '8', '10', '11'],
'LBA_after_AC': ['1', '2', '3', '4', '5', '6', '7'],
'pan': ['8'],
'thermal': ['10', '11']
},
......@@ -98,6 +100,7 @@ sensors = {
'sensor': 'OLI',
'LBA': ['1', '2', '3', '4', '5', '6', '7', '8', '9'],
'LBA_sorted': ['1', '2', '3', '4', '5', '9', '6', '7', '8'],
'LBA_after_AC': ['1', '2', '3', '4', '5', '6', '7'],
'pan': ['8']
},
......@@ -212,12 +215,14 @@ sensors = {
'satellite': 'Sentinel-2A',
'sensor': 'MSI',
'LBA': ['1', '2', '3', '4', '5', '6', '7', '8', '8A', '9', '10', '11', '12'],
'LBA_after_AC': ['1', '2', '3', '4', '5', '6', '7', '8', '8A', '11', '12'],
},
'S2B_full': {
'satellite': 'Sentinel-2B',
'sensor': 'MSI',
'LBA': ['1', '2', '3', '4', '5', '6', '7', '8', '8A', '9', '10', '11', '12'],
'LBA_after_AC': ['1', '2', '3', '4', '5', '6', '7', '8', '8A', '11', '12'],
},
'S2A10': {
......@@ -239,6 +244,7 @@ sensors = {
'sensor': 'MSI',
'subsystem': 'S2A60',
'LBA': ['1', '9', '10'],
'LBA_after_AC': ['1'],
},
'S2B10': {
......@@ -260,6 +266,7 @@ sensors = {
'sensor': 'MSI',
'subsystem': 'S2A60',
'LBA': ['1', '9', '10'],
'LBA_after_AC': ['1'],
},
}
......@@ -267,7 +274,7 @@ sensors = {
df_sensors = \
DataFrame\
.from_dict(sensors, orient='index')\
.loc[:, ['satellite', 'sensor', 'subsystem', 'LBA', 'LBA_sorted', 'pan', 'thermal']]
.loc[:, ['satellite', 'sensor', 'subsystem', 'LBA', 'LBA_sorted', 'LBA_after_AC', 'pan', 'thermal']]
# class SensorSpecs(DataFrame):
......@@ -277,7 +284,7 @@ df_sensors = \
# self.satellite =
def get_sensorspecs(satellite, sensor, subsystem='', no_thermal=False, no_pan=False, sort_by_cwl=False):
def get_sensorspecs(satellite, sensor, subsystem=''):
if (satellite, sensor) in [('Landsat-4', 'TM'), ('Landsat-5', 'TM'), ('Landsat-7', 'ETM+')] and not subsystem:
subsystem = 'SAM'
......@@ -302,7 +309,8 @@ def get_sensorspecs(satellite, sensor, subsystem='', no_thermal=False, no_pan=Fa
return specs
def get_LayerBandsAssignment(satellite, sensor, subsystem='', no_thermal=False, no_pan=False, sort_by_cwl=False):
def get_LayerBandsAssignment(satellite, sensor, subsystem='', no_thermal=False, no_pan=False, after_ac=False,
sort_by_cwl=False):
specs = get_sensorspecs(satellite, sensor, subsystem)
LBA = specs['LBA']
......@@ -315,4 +323,7 @@ def get_LayerBandsAssignment(satellite, sensor, subsystem='', no_thermal=False,
if no_pan and 'pan' in specs:
LBA = [i for i in LBA if i not in specs['pan']]
if after_ac and 'LBA_after_AC' in specs:
LBA = [i for i in LBA if i in specs['LBA_after_AC']]
return LBA
......@@ -77,3 +77,8 @@ class Test_get_LayerBandsAssignment(unittest.TestCase):
LBA = get_LayerBandsAssignment('Landsat-7', 'ETM+', no_thermal=True, sort_by_cwl=True)
self.assertEqual(len(LBA), 7)
self.assertEqual(LBA, ['1', '2', '3', '8', '4', '5', '7'])
def test_after_ac(self):
LBA = get_LayerBandsAssignment('Sentinel-2A', 'MSI', after_ac=True)
self.assertEqual(len(LBA), 11)
self.assertEqual(LBA, ['1', '2', '3', '4', '5', '6', '7', '8', '8A', '11', '12'])
Supports Markdown
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