1
|
|
|
#!/usr/bin/env python |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
|
4
|
|
|
# Copyright (c) 2016-2017 Adam.Dybbroe |
5
|
|
|
|
6
|
|
|
# Author(s): |
7
|
|
|
|
8
|
|
|
# Adam.Dybbroe <[email protected]> |
9
|
|
|
|
10
|
|
|
# This program is free software: you can redistribute it and/or modify |
11
|
|
|
# it under the terms of the GNU General Public License as published by |
12
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
13
|
|
|
# (at your option) any later version. |
14
|
|
|
|
15
|
|
|
# This program is distributed in the hope that it will be useful, |
16
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
# GNU General Public License for more details. |
19
|
|
|
|
20
|
|
|
# You should have received a copy of the GNU General Public License |
21
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
22
|
|
|
|
23
|
|
|
"""Base class for reading raw instrument spectral responses |
24
|
|
|
""" |
25
|
|
|
|
26
|
|
|
import os |
27
|
|
|
import logging |
28
|
|
|
from pyspectral.config import get_config |
29
|
|
|
|
30
|
|
|
LOG = logging.getLogger(__name__) |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
class InstrumentRSR(object): |
34
|
|
|
|
35
|
|
|
"""Base class for the raw (agency dependent) instrument response functions""" |
36
|
|
|
|
37
|
|
|
def __init__(self, bandname, platform_name, bandnames=None): |
38
|
|
|
self.platform_name = platform_name |
39
|
|
|
self.bandname = bandname |
40
|
|
|
self.instrument = None |
41
|
|
|
self.filenames = {} |
42
|
|
|
self.requested_band_filename = None |
43
|
|
|
self.bandnames = bandnames |
44
|
|
|
if not self.bandnames: |
45
|
|
|
self.bandnames = [] |
46
|
|
|
for band in self.bandnames: |
47
|
|
|
self.filenames[band] = None |
48
|
|
|
self.rsr = None |
49
|
|
|
|
50
|
|
|
self.output_dir = None |
51
|
|
|
self.path = None |
52
|
|
|
self.options = {} |
53
|
|
|
self.requested_band_filename = None |
54
|
|
|
|
55
|
|
|
def _get_options_from_config(self): |
56
|
|
|
"""Get configuration settings from configuration file""" |
57
|
|
|
|
58
|
|
|
options = get_config() |
59
|
|
|
self.output_dir = options.get('rsr_dir', './') |
60
|
|
|
self.path = options[self.platform_name + '-' + self.instrument]['path'] |
61
|
|
|
self.options = options |
62
|
|
|
|
63
|
|
|
def _get_bandfilenames(self): |
64
|
|
|
"""Get the instrument rsr filenames""" |
65
|
|
|
for band in self.bandnames: |
66
|
|
|
LOG.debug("Band = %s", str(band)) |
67
|
|
|
self.filenames[band] = os.path.join(self.path, |
68
|
|
|
self.options[self.platform_name + '-' + |
69
|
|
|
self.instrument][band]) |
70
|
|
|
LOG.debug(self.filenames[band]) |
71
|
|
|
if not os.path.exists(self.filenames[band]): |
72
|
|
|
LOG.warning("Couldn't find an existing file for this band: %s", |
73
|
|
|
str(self.filenames[band])) |
74
|
|
|
|
75
|
|
|
def _load(self, scale=1.0): |
76
|
|
|
"""Load the instrument RSR from file(s)""" |
77
|
|
|
|
78
|
|
|
raise NotImplementedError( |
79
|
|
|
"Instrument rsr loader needs to be defined in the subclass") |
80
|
|
|
|