Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a RSR convert script for FY-4B GHI sensor #192

Merged
merged 17 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ The following people have made contributions to this project:
- [Xin Zhang (zxdawn)](https://github.com/zxdawn)
- [Rolf Helge Pfeiffer](https://github.com/HelgeCPH)
- [Antonio Valentino](https://github.com/avalentino)
- [Lu Liu (yukaribbba)](https://github.com/yukaribbba)
10 changes: 10 additions & 0 deletions pyspectral/etc/pyspectral.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ download_from_internet: True
# ch14: FY4B_AGRI_SRF_CH14_Pub.txt
# ch15: FY4B_AGRI_SRF_CH15_Pub.txt

# FY-4B-ghi:
# path: D:/satpy_config/FY4B_GHI_SRF
# ch1: FY4B_GHI_SRF_CH01_Pub.txt
# ch2: FY4B_GHI_SRF_CH02_Pub.txt
# ch3: FY4B_GHI_SRF_CH03_Pub.txt
# ch4: FY4B_GHI_SRF_CH04_Pub.txt
# ch5: FY4B_GHI_SRF_CH05_Pub.txt
# ch6: FY4B_GHI_SRF_CH06_Pub.txt
# ch7: FY4B_GHI_SRF_CH07_Pub.txt

#Electro-L-N2-msu-gs:
# path: /path/to/rsrs/rtcoef_electro-l_2_msugs_srf/
# ch1: rtcoef_electro-l_2_msugs_srf_ch01.txt
Expand Down
112 changes: 112 additions & 0 deletions rsr_convert_scripts/ghi_rsr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2018-2023 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 FY-4B GHI relative spectral responses.

Data from https://img.nsmc.org.cn/PORTAL/NSMC/DATASERVICE/SRF/FY4B/FY4B_GHI_SRF.zip
"""
import os

import numpy as np

from pyspectral.raw_reader import InstrumentRSR
from pyspectral.utils import INSTRUMENTS
from pyspectral.utils import convert2hdf5 as tohdf5
from pyspectral.utils import get_logger, logging_on

FY4_GHI_BAND_NAMES = ['ch1', 'ch2', 'ch3', 'ch4', 'ch5', 'ch6', 'ch7']
BANDNAME_SCALE2MICROMETERS = {'FY-4B': {'ch1': 0.001,
'ch2': 0.001,
'ch3': 0.001,
'ch4': 0.001,
'ch5': 0.001,
'ch6': 0.001,
'ch7': 1.0,
}}


class GHIRSR(InstrumentRSR):
"""Container for the FY-4 GHI RSR data."""

def __init__(self, bandname, platform_name):
"""Initialise the FY-4 GHI relative spectral response data."""
super(GHIRSR, self).__init__(bandname, platform_name, FY4_GHI_BAND_NAMES)

self.instrument = INSTRUMENTS.get(platform_name, 'ghi')
if type(self.instrument) is list:
self.instrument = 'ghi'

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]
scale = BANDNAME_SCALE2MICROMETERS[platform_name].get(bandname)
if scale:
self._load(scale=scale)
else:
LOG.error(
"Failed determine the scale used to convert to wavelength in micrometers - channel = %s", bandname)
raise AttributeError('no scale for bandname %s', bandname)

else:
LOG.warning("Couldn't find an existing file for this band: %s",
str(self.bandname))

self.filename = self.requested_band_filename

def _load(self, scale=0.001):
"""Load the GHI RSR data for the band requested.

Wavelength is given in nanometers.
"""
data = np.genfromtxt(self.requested_band_filename,
unpack=True, delimiter='\t',
names=['wavelength',
'response'],
skip_header=1)

wavelength = data[0] * scale
response = data[1]

# Response can be either 0-1 or 0-100 depending on RSR source - this scales to 0-1 range.
if np.nanmax(response > 1):
response = response / 100.

# Cut unneeded points
pts = np.argwhere(response > 0.001)

wavelength = np.squeeze(wavelength[pts])
response = np.squeeze(response[pts])

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


def convert_ghi():
"""Read original GHI RSR data and convert to common Pyspectral hdf5 format."""
# For FY-4B
tohdf5(GHIRSR, 'FY-4B', FY4_GHI_BAND_NAMES)


if __name__ == "__main__":
LOG = get_logger(__name__)
logging_on()

convert_ghi()
Loading