Skip to content
Snippets Groups Projects

RSR_reader now accepts a logger and may ignore missing files. Updated version info.

Merged Daniel Scheffler requested to merge enhancement/revise_rsr_reader into master
2 files
+ 26
7
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 24
5
@@ -28,6 +28,8 @@
import collections
import os
from typing import Dict, Union, List
import logging
import warnings
import numpy as np
from pandas import DataFrame, Series
@@ -39,8 +41,9 @@ from .sensorspecs import get_LayerBandsAssignment
def RSR_reader(satellite, sensor, subsystem='',
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
LayerBandsAssignment=None, sort_by_cwl=False, after_ac=False, no_thermal=False, no_pan=False,
tolerate_missing=False, logger=None, v=False):
# type: (str, str, str, list, bool, bool, bool, bool, bool, logging.Logger, 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
@@ -53,6 +56,8 @@ def RSR_reader(satellite, sensor, subsystem='',
(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 tolerate_missing: If True, a warning is raised instead of a FileNotFoundError if a file is missing.
:param logger: instance of logging.Logger
:param v: verbose mode
"""
RSR_dict = collections.OrderedDict()
@@ -69,10 +74,24 @@ def RSR_reader(satellite, sensor, subsystem='',
try:
RSR_dict[band] = np.loadtxt(RSR_path, skiprows=1)
if v:
print('Reading RSR for %s %s, %s...' % (satellite, sensor, bandname))
msg = 'Reading RSR for %s %s, %s...' % (satellite, sensor, bandname)
if logger:
logger.info(msg)
else:
print(msg)
except FileNotFoundError:
raise FileNotFoundError('No spectral response functions found for %s %s %s at %s! >None< is returned.'
% (satellite, sensor, bandname, RSR_path))
msg = 'No spectral response functions found for %s %s %s at %s!'\
% (satellite, sensor, bandname, RSR_path)
if tolerate_missing:
msg = '%s >None< is returned.' % msg
if logger:
logger.warning(msg)
else:
warnings.warn(msg)
else:
raise FileNotFoundError(msg)
return RSR_dict
Loading