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 AGRI bands to the BANDNAMES dict #150

Merged
merged 3 commits into from
Sep 28, 2022
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
16 changes: 16 additions & 0 deletions pyspectral/bandnames.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@
'C16': 'ch16'
}

BANDNAMES['agri'] = {'C01': 'ch1',
'C02': 'ch2',
'C03': 'ch3',
'C04': 'ch4',
'C05': 'ch5',
'C06': 'ch6',
'C07': 'ch7',
'C08': 'ch8',
'C09': 'ch9',
'C10': 'ch10',
'C11': 'ch11',
'C12': 'ch12',
'C13': 'ch13',
'C14': 'ch14',
}

BANDNAMES['ahi'] = {'B01': 'ch1',
'B02': 'ch2',
'B03': 'ch3',
Expand Down
76 changes: 46 additions & 30 deletions rsr_convert_scripts/agri_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) 2018, 2019 Pytroll developers
# Copyright (c) 2018, 2019, 2022 Pytroll developers
#
# Author(s):
#
Expand All @@ -21,8 +21,9 @@
# 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-4A AGRI relative spectral responses. Data from
http://fy4.nsmc.org.cn/portal/cn/fycv/srf.html
"""Read the FY-4A AGRI relative spectral responses.

Data from http://fy4.nsmc.org.cn/portal/cn/fycv/srf.html
"""
import os
import numpy as np
Expand All @@ -31,30 +32,45 @@
from pyspectral.raw_reader import InstrumentRSR
from pyspectral.utils import logging_on, get_logger

FY4A_BAND_NAMES = ['ch1', 'ch2', 'ch3', 'ch4', 'ch5', 'ch6', 'ch7', 'ch8',
'ch9', 'ch10', 'ch11', 'ch12', 'ch13', 'ch14']
BANDNAME_SCALE2MICROMETERS = {'ch1': 0.001,
'ch2': 0.001,
'ch3': 0.001,
'ch4': 1.0,
'ch5': 1.0,
'ch6': 1.0,
'ch7': 1.0,
'ch8': 1.0,
'ch9': 1.0,
'ch10': 1.0,
'ch11': 1.0,
'ch12': 1.0,
'ch13': 1.0,
'ch14': 1.0}
FY4_AGRI_BAND_NAMES = ['ch1', 'ch2', 'ch3', 'ch4', 'ch5', 'ch6', 'ch7', 'ch8',
'ch9', 'ch10', 'ch11', 'ch12', 'ch13', 'ch14', 'ch15']
BANDNAME_SCALE2MICROMETERS = {'FY-4A': {'ch1': 0.001,
'ch2': 0.001,
'ch3': 0.001,
'ch4': 1.0,
'ch5': 1.0,
'ch6': 1.0,
'ch7': 1.0,
'ch8': 1.0,
'ch9': 1.0,
'ch10': 1.0,
'ch11': 1.0,
'ch12': 1.0,
'ch13': 1.0,
'ch14': 1.0},
'FY-4B': {'ch1': 0.001,
'ch2': 0.001,
'ch3': 0.001,
'ch4': 0.001,
'ch5': 0.001,
'ch6': 0.001,
'ch7': 1.0,
'ch8': 1.0,
'ch9': 1.0,
'ch10': 1.0,
'ch11': 1.0,
'ch12': 1.0,
'ch13': 1.0,
'ch14': 1.0,
'ch15': 1.0}}


class AGRIRSR(InstrumentRSR):
"""Container for the FY-4 AGRI RSR data"""
"""Container for the FY-4 AGRI RSR data."""

def __init__(self, bandname, platform_name):
"""Initialise the FY-4 AGRI relative spectral response data"""
super(AGRIRSR, self).__init__(bandname, platform_name, FY4A_BAND_NAMES)
"""Initialise the FY-4 AGRI relative spectral response data."""
super(AGRIRSR, self).__init__(bandname, platform_name, FY4_AGRI_BAND_NAMES)

self.instrument = INSTRUMENTS.get(platform_name, 'agri')

Expand All @@ -64,7 +80,7 @@ def __init__(self, bandname, platform_name):
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.get(bandname)
scale = BANDNAME_SCALE2MICROMETERS[platform_name].get(bandname)
if scale:
self._load(scale=scale)
else:
Expand All @@ -79,9 +95,9 @@ def __init__(self, bandname, platform_name):
self.filename = self.requested_band_filename

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

Wavelength is given in nanometers.
Wavelength is given in nanometers.
"""
data = np.genfromtxt(self.requested_band_filename,
unpack=True,
Expand All @@ -95,14 +111,14 @@ def _load(self, scale=0.001):
self.rsr = {'wavelength': wavelength, 'response': response}


def main():
"""Main"""
for platform_name in ["FY-4A", ]:
tohdf5(AGRIRSR, platform_name, FY4A_BAND_NAMES)
def convert_agri():
"""Read original AGRI RSR data and convert to common Pyspectral hdf5 format."""
for platform_name in ["FY-4A", "FY-4B"]:
tohdf5(AGRIRSR, platform_name, FY4_AGRI_BAND_NAMES)


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

main()
convert_agri()