File: fci_rsr.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 (74 lines) | stat: -rw-r--r-- 2,330 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2020-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/>.

"""Read the MTG FCI relative spectral response functions.

Data from EUMETSAT:
https://sftp.eumetsat.int/public/folder/UsCVknVOOkSyCdgpMimJNQ/User-Materials/MTGUP/Materials/FCI-SRF_Apr2022/
"""

import logging

from netCDF4 import Dataset

from pyspectral.bandnames import BANDNAMES
from pyspectral.raw_reader import InstrumentRSR
from pyspectral.utils import convert2hdf5 as tohdf5

LOG = logging.getLogger(__name__)

FCI_BAND_NAMES = list(BANDNAMES['fci'].values())


class FciRSR(InstrumentRSR):
    """Container for the MTG FCI RSR data."""

    def __init__(self, bandname, platform_name):
        """MTG FCI RSR data container."""
        super().__init__(bandname, platform_name)

        self.instrument = 'fci'
        self._get_options_from_config()

        LOG.debug("Filename with all bands: %s", str(self.filename))
        self._load()

    def _load(self, scale=1000000.0):
        """Load the FCI RSR data for the band requested."""
        LOG.debug("File: %s", str(self.filename))

        ncf = Dataset(self.path / self.filename, 'r')

        wvl = ncf.variables['wavelength'][:] * scale
        resp = ncf.variables['srf'][:]

        bandnames = ncf.variables['channel_id'][:]
        for idx, band_name in enumerate(bandnames):
            if band_name == self.bandname:
                self.rsr = {'wavelength': wvl[:, idx], 'response': resp[:, idx]}


def main():
    """Create the internal Pyspectral hdf5 output for FCI."""
    for platform_name in ["Meteosat-12", 'MTG-I1']:
        tohdf5(FciRSR, platform_name, FCI_BAND_NAMES)


if __name__ == "__main__":
    main()