File: aatsr_reader.py

package info (click to toggle)
pyspectral 0.13.6%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,184 kB
  • sloc: python: 6,070; makefile: 123
file content (79 lines) | stat: -rw-r--r-- 2,455 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016-2022 Pytroll developers
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""Interface to the original Envisat AATSR spectral response functions.

From ESA: http://envisat.esa.int/handbooks/aatsr/aux-files/consolidatedsrfs.xls

"""
import logging

import numpy as np
from xlrd import open_workbook

from pyspectral.config import get_config
from pyspectral.utils import convert2hdf5 as tohdf5

LOG = logging.getLogger(__name__)

AATSR_BAND_NAMES = ['ir12', 'ir11', 'ir37', 'v16', 'v870', 'v659', 'v555']


class AatsrRSR(object):
    """Class for Envisat AATSR RSR."""

    def __init__(self, bandname, platform_name='Envisat'):
        """Read the aatsr relative spectral responses for all channels."""
        self.platform_name = platform_name
        self.instrument = 'aatsr'
        self.bandname = bandname
        self.rsr = None

        options = get_config()

        self.aatsr_path = options[
            self.platform_name + '-' + self.instrument].get('path')

        self.output_dir = options.get('rsr_dir', './')

        self._load()

    def _load(self, filename=None):
        """Read the AATSR rsr data."""
        if not filename:
            filename = self.aatsr_path

        wb_ = open_workbook(filename)

        for sheet in wb_.sheets():
            ch_name = sheet.name.strip()
            if ch_name == 'aatsr_' + self.bandname:

                data = np.array([s.split() for s in
                                 sheet.col_values(0,
                                                  start_rowx=3, end_rowx=258)])
                data = data.astype('f')
                wvl = data[:, 0]
                resp = data[:, 1]

                self.rsr = {'wavelength': wvl, 'response': resp}


if __name__ == "__main__":
    tohdf5(AatsrRSR, 'Envisat', AATSR_BAND_NAMES)