Skip to content

Commit

Permalink
Merge pull request #222 from yukaribbba/add_fy3g_mersirm_rsr
Browse files Browse the repository at this point in the history
Add a RSR convert script for FY-3G MERSI-RM sensor
  • Loading branch information
adybbroe authored May 3, 2024
2 parents f55b7b9 + fc249dc commit 33a25ac
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pyspectral/etc/pyspectral.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ download_from_internet: True
# Everything below this line should not need to be changed!
# Changes may be done if you want to change the name of the radiance<->Tb LUT filrnames,
# or if you want to store those files in different directories dependning on the platform/sensor.
# Also, if you want to read the original agency specific spectral responses you
# Also, if you want to read the original agency specific spectral responses you
# can specify their file names and directory paths here.
# Adam Dybbroe, 2018-03-20

Expand Down Expand Up @@ -61,7 +61,7 @@ download_from_internet: True

# rootdir: /path/to/original/jpss1/viirs/data
# tb2rad_lut_filename: /path/to/radiance/tb/lut/data/tb2rad_lut_noaa20_viirs_ir3.7.npz

# section1:
# filename: J1_VIIRS_Detector_RSR_V2/J1_VIIRS_RSR_{bandname}_Detector_Fused_V2.txt
# bands: [M1, M2, M3, M4, M5, M6, M7]
Expand All @@ -73,11 +73,11 @@ download_from_internet: True
# section3:
# filename: J1_VIIRS_V1_RSR_used_in_V2/J1_VIIRS_RSR_M8_Det_V1.txt
# bands: [M8]

# section4:
# filename: J1_VIIRS_Detector_RSR_V2.1/J1_VIIRS_RSR_M9_Det_V2.1.txt
# bands: [M9]

# section5:
# filename: J1_VIIRS_V1_RSR_used_in_V2/J1_VIIRS_RSR_{bandname}_Det_V1.txt
# bands: [M10, M11, M12, M14, M15]
Expand Down Expand Up @@ -105,7 +105,7 @@ download_from_internet: True
# tb2rad_lut_filename:
# m12: /path/to/radiance/tb/lut/data/tb2rad_lut_snpp_viirs_m12.npz
# i4: /path/to/radiance/tb/lut/data/tb2rad_lut_snpp_viirs_i4.npz

# section1:
# filename: GT_F1_SC_RSR_Release1.0_Best_Mbands/GT_F1_SC_RSR_Release1.0_Best_{bandname}_V2.71_ib_oob.txt
# bands: [M1, M2, M3, M4, M5, M6, M7]
Expand Down Expand Up @@ -313,6 +313,16 @@ download_from_internet: True
# ch24: FY3D_MERSI_SRF_CH24_Pub.txt
# ch25: FY3D_MERSI_SRF_CH25_Pub.txt

# FY-3G-mersi-rm:
# path: D:/FY-3G_MERSI-RM_SRF
# ch1: SRF_FY3G_SRF_CH01.txt
# ch2: SRF_FY3G_SRF_CH02.txt
# ch3: SRF_FY3G_SRF_CH03.txt
# ch4: SRF_FY3G_SRF_CH04.txt
# ch5: SRF_FY3G_SRF_CH05.txt
# ch6: SRF_FY3G_SRF_CH06.txt
# ch7: SRF_FY3G_SRF_CH07.txt
# ch8: SRF_FY3G_SRF_CH08.txt

# NOAA-19-avhrr/3:
# path: /path/to/original/noaa19/avhrr/data
Expand Down
1 change: 1 addition & 0 deletions pyspectral/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
'Meteosat-12': 'fci',
'MTG-I1': 'fci',
'FY-3D': 'mersi-2',
'FY-3G': 'mersi-rm',
'Metop-SG-A1': 'metimage',
'EOS-Aqua': 'modis',
'EOS-Terra': 'modis',
Expand Down
86 changes: 86 additions & 0 deletions rsr_convert_scripts/mersirm_rsr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/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-3G MERSI-RM relative spectral responses.
Data from https://img.nsmc.org.cn/PORTAL/NSMC/DATASERVICE/SRF/FY3G/FY-3G_MERSI-RM_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

FY3_MERSIRM_BAND_NAMES = ['ch1', 'ch2', 'ch3', 'ch4', 'ch5', 'ch6', 'ch7', 'ch8']


class MersiRMRSR(InstrumentRSR):
"""Container for the FY-3 MERSI-RM RSR data."""

def __init__(self, bandname, platform_name):
"""Initialise the FY-3 MERSI-RM relative spectral response data."""
super(MersiRMRSR, self).__init__(bandname, platform_name, FY3_MERSIRM_BAND_NAMES)

self.instrument = INSTRUMENTS.get(platform_name, 'mersi-rm')

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))

self.filename = self.requested_band_filename

def _load(self, scale=0.001):
"""Load the MERSI-RM RSR data for the band requested.
Wavelength is given in nanometers.
"""
data = np.genfromtxt(self.requested_band_filename,
unpack=True,
names=['wavelength',
'response'],
skip_header=1)

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

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


def convert_mersirm():
"""Read original MERSI-RM RSR data and convert to common Pyspectral hdf5 format."""
# For FY-3G
tohdf5(MersiRMRSR, 'FY-3G', FY3_MERSIRM_BAND_NAMES)


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

convert_mersirm()

0 comments on commit 33a25ac

Please sign in to comment.