Skip to content

Commit

Permalink
Merge 0da3787 into 04f7076
Browse files Browse the repository at this point in the history
  • Loading branch information
adybbroe committed Nov 19, 2018
2 parents 04f7076 + 0da3787 commit 1eeb5ce
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
@@ -1,2 +1,4 @@
etc/pyspectral_rsr_data.tgz filter=lfs diff=lfs merge=lfs -text
pyspectral/etc/pyspectral_rsr_data.tgz filter=lfs diff=lfs merge=lfs -text
doc/_static/mersi2_rsr_band_0040_0070.png filter=lfs diff=lfs merge=lfs -text
doc/_static/mersi2_rsr_band_0040_0070_missingbands.png filter=lfs diff=lfs merge=lfs -text
4 changes: 3 additions & 1 deletion .travis.yml
@@ -1,7 +1,9 @@
language: python
env:
global:
- NUMPY_VERSION=stable
# Set defaults to avoid repeating in most cases
- PYTHON_VERSION=$TRAVIS_PYTHON_VERSION
#- NUMPY_VERSION=stable
- MAIN_CMD='python setup.py'
- CONDA_DEPENDENCIES='scipy numpy coveralls coverage h5py mock requests six appdirs python-geotiepoints dask docutils pyyaml xlrd'
- PIP_DEPENDENCIES=''
Expand Down
9 changes: 7 additions & 2 deletions bin/composite_rsr_plot.py
Expand Up @@ -83,6 +83,10 @@ def get_arguments():
action='store_true')
parser.add_argument("--title", help=("Plot title"),
default=None, type=str)
parser.add_argument("--wavelength_resolution",
help=("The step in wavelength (nanometers) when scanning\n" +
" the spectral range trying to find bands"),
default=0.005, type=float)
parser.add_argument("-o", "--filename", help=("Output plot file name"),
default=None, type=str)
parser.add_argument(
Expand Down Expand Up @@ -116,6 +120,7 @@ def get_arguments():
title = 'Relative Spectral Responses'
filename = args.filename
no_platform_name_in_legend = args.no_platform_name_in_legend
wavel_res = args.wavelength_resolution
verbose = args.verbose

if verbose:
Expand Down Expand Up @@ -176,7 +181,7 @@ def get_arguments():
wvlx = wvlmin
prev_band = None
while wvlx < wvlmax:
bands = get_bandname_from_wavelength(sensor, wvlx, rsr.rsr, 0.05, multiple_bands=True)
bands = get_bandname_from_wavelength(sensor, wvlx, rsr.rsr, wavel_res, multiple_bands=True)

if isinstance(bands, list):
b__ = bands[0]
Expand All @@ -185,7 +190,7 @@ def get_arguments():
else:
b__ = bands

wvlx = wvlx + 0.05
wvlx = wvlx + wavel_res / 5.
if not b__:
continue
if b__ != prev_band:
Expand Down
3 changes: 3 additions & 0 deletions doc/_static/mersi2_rsr_band_0040_0070.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions doc/_static/mersi2_rsr_band_0040_0070_missingbands.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions doc/platforms_supported.rst
Expand Up @@ -37,10 +37,10 @@ have been included in PySpectral.
* - TIROS-N to NOAA-19 avhrr
- e.g. `rsr_avhrr3_NOAA-19.h5`
- GSICS_
* - Metop-A avhrr
* - Metop-A avhrr/3
- `rsr_avhrr3_Metop-A.h5`
- GSICS_
* - Metop-B avhrr
* - Metop-B avhrr/3
- `rsr_avhrr3_Metop-B.h5`
- GSICS_
* - EOS-Terra modis
Expand Down Expand Up @@ -70,6 +70,9 @@ have been included in PySpectral.
* - Landsat-8 oli
- `rsr_oli_Landsat-8.h5`
- NASA-Landsat-OLI_
* - FY-3D mersi-2
- `rsr_mersi-2_FY-3D.h5`
- CMA_ (Acquired via personal contact)


.. _Eumetsat: https://www.eumetsat.int/website/home/Data/Products/Calibration/MSGCalibration/index.html
Expand All @@ -82,3 +85,5 @@ have been included in PySpectral.
.. _ESA-Sentinel-MSI: https://earth.esa.int/documents/247904/685211/S2-SRF_COPE-GSEG-EOPG-TN-15-0007_3.0.xlsx
.. _NASA-Landsat-OLI: https://landsat.gsfc.nasa.gov/wp-content/uploads/2013/06/Ball_BA_RSR.v1.1-1.xlsx
.. _NESDIS: https://ncc.nesdis.noaa.gov/J1VIIRS/J1VIIRSSpectralResponseFunctions.php
.. _CMA: http://www.cma.gov.cn/en2014/

19 changes: 19 additions & 0 deletions doc/rsr_plotting.rst
Expand Up @@ -19,6 +19,25 @@ Plot relative spectral responses for the spectral channel closest to the
.. image:: _static/rsr_band_1080.png

Some sensor bands are quite close, and that requires the search for bands in
the spectral range to use rather small wavelengths increments. Therefore you
might experience the plotting to a bit slow on default. Here an example with
MERSI-2 on FY-3D:

.. code::
python bin/composite_rsr_plot.py -p FY-3D -s mersi-2 -r 0.4 0.7 -t 0.05
.. image:: _static/mersi2_rsr_band_0040_0070.png

It is possible to specify a different wavelength resolution/increments by using
a flag. However, when you do that it might affect how pyspectral identify
bands. If the resolution is too coarse svereal close bands may be considered
one and the same. In the below case it is probably not a good idea to lower the
resolution as one can see (several MESI-2 bands are now missing):

.. code::
python bin/composite_rsr_plot.py -p FY-3D -s mersi-2 -r 0.4 0.7 -t 0.05 --wavelength_resolution 0.05
.. image:: _static/mersi2_rsr_band_0040_0070_missingbands.png
48 changes: 48 additions & 0 deletions pyspectral/etc/pyspectral.yaml
Expand Up @@ -185,6 +185,54 @@ GOES-16-abi:
ch15: GOES-R_ABI_PFM_SRF_CWG_ch15.txt
ch16: GOES-R_ABI_PFM_SRF_CWG_ch16.txt

GOES-17-abi:
path: /path/to/original/goes17/abi/data
ch1: GOES-R_ABI_FM2_SRF_CWG_ch1.txt
ch2: GOES-R_ABI_FM2_SRF_CWG_ch2.txt
ch3: GOES-R_ABI_FM2_SRF_CWG_ch3.txt
ch4: GOES-R_ABI_FM2_SRF_CWG_ch4.txt
ch5: GOES-R_ABI_FM2_SRF_CWG_ch5.txt
ch6: GOES-R_ABI_FM2_SRF_CWG_ch6.txt
ch7: GOES-R_ABI_FM2_SRF_CWG_ch7.txt
ch8: GOES-R_ABI_FM2_SRF_CWG_ch8.txt
ch9: GOES-R_ABI_FM2_SRF_CWG_ch9.txt
ch10: GOES-R_ABI_FM2_SRF_CWG_ch10.txt
ch11: GOES-R_ABI_FM2_SRF_CWG_ch11.txt
ch12: GOES-R_ABI_FM2_SRF_CWG_ch12.txt
ch13: GOES-R_ABI_FM2_SRF_CWG_ch13.txt
ch14: GOES-R_ABI_FM2_SRF_CWG_ch14.txt
ch15: GOES-R_ABI_FM2_SRF_CWG_ch15.txt
ch16: GOES-R_ABI_FM2_SRF_CWG_ch16.txt

FY-3D-mersi-2:
path: /path/to/original/fy3d/mersi2/data
ch1: FY3D_MERSI_SRF_CH01_Pub.txt
ch2: FY3D_MERSI_SRF_CH02_Pub.txt
ch3: FY3D_MERSI_SRF_CH03_Pub.txt
ch4: FY3D_MERSI_SRF_CH04_Pub.txt
ch5: FY3D_MERSI_SRF_CH05_Pub.txt
ch6: FY3D_MERSI_SRF_CH06_Pub.txt
ch7: FY3D_MERSI_SRF_CH07_Pub.txt
ch8: FY3D_MERSI_SRF_CH08_Pub.txt
ch9: FY3D_MERSI_SRF_CH09_Pub.txt
ch10: FY3D_MERSI_SRF_CH10_Pub.txt
ch11: FY3D_MERSI_SRF_CH11_Pub.txt
ch12: FY3D_MERSI_SRF_CH12_Pub.txt
ch13: FY3D_MERSI_SRF_CH13_Pub.txt
ch14: FY3D_MERSI_SRF_CH14_Pub.txt
ch15: FY3D_MERSI_SRF_CH15_Pub.txt
ch16: FY3D_MERSI_SRF_CH16_Pub.txt
ch17: FY3D_MERSI_SRF_CH17_Pub.txt
ch18: FY3D_MERSI_SRF_CH18_Pub.txt
ch19: FY3D_MERSI_SRF_CH19_Pub.txt
ch20: FY3D_MERSI_SRF_CH20_Pub.txt
ch21: FY3D_MERSI_SRF_CH21_Pub.txt
ch22: FY3D_MERSI_SRF_CH22_Pub.txt
ch23: FY3D_MERSI_SRF_CH23_Pub.txt
ch24: FY3D_MERSI_SRF_CH24_Pub.txt
ch25: FY3D_MERSI_SRF_CH25_Pub.txt


NOAA-19-avhrr/3:
path: /path/to/original/noaa19/avhrr/data
ch1: NOAA_19_A308C001.txt
Expand Down
89 changes: 89 additions & 0 deletions pyspectral/mersi2_rsr.py
@@ -0,0 +1,89 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2018 Adam.Dybbroe

# Author(s):

# Adam.Dybbroe <adam.dybbroe@smhi.se>

# 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 MERSI-II relative spectral responses. Data from xuna@cma.gov.cn
(Personal contact with Sara Hörnquist, SMHI).
"""
import os
import numpy as np
from pyspectral.utils import INSTRUMENTS
from pyspectral.utils import convert2hdf5 as tohdf5
from pyspectral.raw_reader import InstrumentRSR

import logging
LOG = logging.getLogger(__name__)

MERSI2_BAND_NAMES = ['ch1', 'ch2', 'ch3', 'ch4', 'ch5', 'ch6', 'ch7', 'ch8',
'ch9', 'ch10', 'ch11', 'ch12', 'ch13', 'ch14', 'ch15', 'ch16',
'ch17', 'ch18', 'ch19', 'ch20', 'ch21', 'ch22', 'ch23', 'ch24',
'ch25']


class Mersi2RSR(InstrumentRSR):

"""Container for the FY3D MERSI-II RSR data"""

def __init__(self, bandname, platform_name):

super(Mersi2RSR, self).__init__(bandname, platform_name, MERSI2_BAND_NAMES)

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

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

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

def _load(self, scale=0.001):
"""Load the MERSI-2 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=0)

wavelength = data['wavelength'] * scale
response = data['response']

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


def main():
"""Main"""
for platform_name in ["FY-3D", ]:
tohdf5(Mersi2RSR, platform_name, MERSI2_BAND_NAMES)


if __name__ == "__main__":
main()
22 changes: 12 additions & 10 deletions pyspectral/utils.py
Expand Up @@ -118,12 +118,14 @@
'Metop-B': 'avhrr/3',
'Metop-C': 'avhrr/3',
'Suomi-NPP': 'viirs',
'NOAA-20': 'viirs'
'NOAA-20': 'viirs',
'FY-3D': 'mersi-2',
'Feng-Yun 3D': 'mersi-2'
}

HTTP_PYSPECTRAL_RSR = "https://zenodo.org/record/1409621/files/pyspectral_rsr_data.tgz"
HTTP_PYSPECTRAL_RSR = "https://zenodo.org/record/1491277/files/pyspectral_rsr_data.tgz"
RSR_DATA_VERSION_FILENAME = "PYSPECTRAL_RSR_VERSION"
RSR_DATA_VERSION = "v1.0.2"
RSR_DATA_VERSION = "v1.0.3"

ATM_CORRECTION_LUT_VERSION = {}
ATM_CORRECTION_LUT_VERSION['antarctic_aerosol'] = {'version': 'v1.0.1',
Expand Down Expand Up @@ -188,16 +190,16 @@


def convert2wavenumber(rsr):
"""Take rsr data set with all channels and detectors for an instrument
"""
Take rsr data set with all channels and detectors for an instrument
each with a set of wavelengths and normalised responses and
convert to wavenumbers and responses
rsr:
Relative Spectral Response function (all bands)
:rsr: Relative Spectral Response function (all bands)
Returns:
retv:
Relative Spectral Responses in wave number space
info:
Dictionary with scale (to go convert to SI units) and unit
:retv: Relative Spectral Responses in wave number space
:info: Dictionary with scale (to go convert to SI units) and unit
"""

retv = {}
Expand Down

0 comments on commit 1eeb5ce

Please sign in to comment.