Skip to content

Commit

Permalink
Merge pull request #148 from adybbroe/add-fci-rsr-april2022
Browse files Browse the repository at this point in the history
Updated the FCI spectral responses as of April 2022
  • Loading branch information
adybbroe committed May 19, 2022
2 parents 68be69a + ed08c84 commit 6948a7a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 56 deletions.
35 changes: 18 additions & 17 deletions pyspectral/bandnames.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2021 Adam.Dybbroe
# Copyright (c) 2021, 2022 Adam.Dybbroe

# Author(s):

Expand Down Expand Up @@ -73,6 +73,7 @@
# MODIS RSR files were made before 'chX' became standard in pyspectral
BANDNAMES['modis'] = {str(chan_num): str(chan_num) for chan_num in range(1, 37)}


BANDNAMES['seviri'] = {'VIS006': 'VIS0.6',
'VIS008': 'VIS0.8',
'IR_016': 'NIR1.6',
Expand Down Expand Up @@ -163,22 +164,22 @@
'IR133': 'ch16'
}

BANDNAMES['fci'] = {'vis_04': 'ch1',
'vis_05': 'ch2',
'vis_06': 'ch3',
'vis_08': 'ch4',
'vis_09': 'ch5',
'nir_13': 'ch6',
'nir_16': 'ch7',
'nir_22': 'ch8',
'ir_38': 'ch9',
'wv_63': 'ch10',
'wv_73': 'ch11',
'ir_87': 'ch12',
'ir_97': 'ch13',
'ir_105': 'ch14',
'ir_123': 'ch15',
'ir_133': 'ch16'
BANDNAMES['fci'] = {'vis_04': 'VIS0.4',
'vis_05': 'VIS0.5',
'vis_06': 'VIS0.6_HR',
'vis_08': 'VIS0.8',
'vis_09': 'VIS0.9',
'nir_13': 'NIR1.3',
'nir_16': 'NIR1.6',
'nir_22': 'NIR2.2_HR',
'ir_38': 'IR3.8_HR',
'wv_63': 'WV6.3',
'wv_73': 'WV7.3',
'ir_87': 'IR8.7',
'ir_97': 'IR9.7',
'ir_105': 'IR10.5_HR',
'ir_123': 'IR12.3',
'ir_133': 'IR13.3'
}

BANDNAMES['slstr'] = {'S1': 'ch1',
Expand Down
8 changes: 5 additions & 3 deletions pyspectral/raw_reader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016-2019 Pytroll developers
# Copyright (c) 2016-2022 Pytroll developers
#
# Author(s):
#
Expand All @@ -25,6 +25,7 @@
import os
import logging
from pyspectral.config import get_config
from pathlib import Path

LOG = logging.getLogger(__name__)

Expand All @@ -48,14 +49,15 @@ def __init__(self, bandname, platform_name, bandnames=None):

self.output_dir = None
self.path = None
self.filename = None
self.options = {}
self.requested_band_filename = None

def _get_options_from_config(self):
"""Get configuration settings from configuration file."""
options = get_config()
self.output_dir = options.get('rsr_dir', './')
self.path = options[self.platform_name + '-' + self.instrument]['path']
self.path = Path(options[self.platform_name + '-' + self.instrument]['path'])
self.filename = options[self.platform_name + '-' + self.instrument].get('filename')
self.options = options

def _get_bandfilenames(self):
Expand Down
4 changes: 2 additions & 2 deletions pyspectral/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
'MTG-I1': 'fci'
}

HTTP_PYSPECTRAL_RSR = "https://zenodo.org/record/6026563/files/pyspectral_rsr_data.tgz"
HTTP_PYSPECTRAL_RSR = "https://zenodo.org/record/6557386/files/pyspectral_rsr_data.tgz"

RSR_DATA_VERSION_FILENAME = "PYSPECTRAL_RSR_VERSION"
RSR_DATA_VERSION = "v1.0.18"
RSR_DATA_VERSION = "v1.1.0"

ATM_CORRECTION_LUT_VERSION = {}
ATM_CORRECTION_LUT_VERSION['antarctic_aerosol'] = {'version': 'v1.0.1',
Expand Down
55 changes: 21 additions & 34 deletions rsr_convert_scripts/fci_rsr.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2020 Pytroll developers
# Copyright (c) 2020-2022 Pytroll developers
#
# Author(s):
#
Expand All @@ -22,63 +22,50 @@

"""Read the MTG FCI relative spectral response functions.
Data from EUMETSAT NWP-SAF:
https://nwpsaf.eu/downloads/rtcoef_rttov12/ir_srf/rtcoef_mtg_1_fci_srf.html
Data from EUMETSAT:
https://sftp.eumetsat.int/public/folder/UsCVknVOOkSyCdgpMimJNQ/User-Materials/MTGUP/Materials/FCI-SRF_Apr2022/
"""

import os
import logging
import numpy as np
from netCDF4 import Dataset
from pyspectral.utils import convert2hdf5 as tohdf5
from pyspectral.raw_reader import InstrumentRSR

from pyspectral.bandnames import BANDNAMES
LOG = logging.getLogger(__name__)

FCI_BAND_NAMES = ['ch1', 'ch2', 'ch3', 'ch4', 'ch5', 'ch6', 'ch7', 'ch8', 'ch9', 'ch10',
'ch11', 'ch12', 'ch13', 'ch14', 'ch15', 'ch16']
FCI_BAND_NAMES = list(BANDNAMES['fci'].values())


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

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

self.instrument = 'fci'

self._get_options_from_config()
self._get_bandfilenames()

LOG.debug("Filenames: %s", str(self.filenames))
if self.filenames[bandname] and os.path.exists(self.filenames[bandname]):
self.requested_band_filename = self.filenames[bandname]
self._load()

else:
LOG.warning("Couldn't find an existing file for this band: %s",
str(self.bandname))
LOG.debug("Filename with all bands: %s", str(self.filename))
self._load()

# To be compatible with VIIRS....
self.filename = self.requested_band_filename

def _load(self, scale=10000.0):
def _load(self, scale=1000000.0):
"""Load the FCI RSR data for the band requested."""
data = np.genfromtxt(self.requested_band_filename,
unpack=True,
names=['wavenumber',
'response'],
skip_header=4)
LOG.debug("File: %s", str(self.filename))

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

# Data are wavenumbers in cm-1:
wavelength = 1. / data['wavenumber'] * scale
response = data['response']
wvl = ncf.variables['wavelength'][:] * scale
resp = ncf.variables['srf'][:]

self.rsr = {'wavelength': wavelength[::-1], 'response': response[::-1]}
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():
"""Main function creating the internal Pyspectral hdf5 output for FCI."""
"""Create the internal Pyspectral hdf5 output for FCI."""
for platform_name in ["Meteosat-12", 'MTG-I1']:
tohdf5(FciRSR, platform_name, FCI_BAND_NAMES)

Expand Down

0 comments on commit 6948a7a

Please sign in to comment.