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

Merge branch 'enhancement/revise_rsr_reader' into 'master'

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

See merge request !3
parents 3c23e66f 4b763698
Pipeline #4934 passed with stages
in 3 minutes and 6 seconds
......@@ -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
......
......@@ -22,5 +22,5 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
__version__ = '0.2.10'
__versionalias__ = '20190823.02'
__version__ = '0.3.0'
__versionalias__ = '20190925.02'
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