[Git][debian-gis-team/pyspectral][upstream] New upstream version 0.12.3+ds

Antonio Valentino (@antonio.valentino) gitlab at salsa.debian.org
Fri Nov 25 08:23:00 GMT 2022



Antonio Valentino pushed to branch upstream at Debian GIS Project / pyspectral


Commits:
40cd5d3e by Antonio Valentino at 2022-11-25T08:13:07+00:00
New upstream version 0.12.3+ds
- - - - -


12 changed files:

- CHANGELOG.md
- CHANGELOG_RSR_DATA.rst
- bin/composite_rsr_plot.py
- bin/plot_rsr.py
- pyspectral/etc/pyspectral.yaml
- pyspectral/rayleigh.py
- pyspectral/rsr_reader.py
- pyspectral/tests/test_rayleigh.py
- pyspectral/tests/test_rsr_reader.py
- pyspectral/tests/test_utils.py
- pyspectral/utils.py
- rsr_convert_scripts/agri_rsr.py


Changes:

=====================================
CHANGELOG.md
=====================================
@@ -1,3 +1,29 @@
+## Version <v0.12.3> (2022/11/22)
+
+### Issues Closed
+
+* [Issue 172](https://github.com/pytroll/pyspectral/issues/172) - Bug plotting spectral responses with MODIS ([PR 174](https://github.com/pytroll/pyspectral/pull/174) by [@adybbroe](https://github.com/adybbroe))
+* [Issue 166](https://github.com/pytroll/pyspectral/issues/166) - raise keyerror when loading B07 of himawari_ahi using DataQuery
+* [Issue 155](https://github.com/pytroll/pyspectral/issues/155) - NOAA-6 spectral responses are wrong for channel 1 & 2
+* [Issue 149](https://github.com/pytroll/pyspectral/issues/149) - Add FY4B AGRI bands
+* [Issue 143](https://github.com/pytroll/pyspectral/issues/143) - Implement RSRs for AGRI aboard FengYun-4B ([PR 171](https://github.com/pytroll/pyspectral/pull/171) by [@simonrp84](https://github.com/simonrp84))
+
+In this release 5 issues were closed.
+
+### Pull Requests Merged
+
+#### Bugs fixed
+
+* [PR 174](https://github.com/pytroll/pyspectral/pull/174) - Fix bug getting bandname from RSR data ([172](https://github.com/pytroll/pyspectral/issues/172))
+
+#### Features added
+
+* [PR 173](https://github.com/pytroll/pyspectral/pull/173) - Fix4agri on fy4a and fy4b
+* [PR 171](https://github.com/pytroll/pyspectral/pull/171) - Update for FY-4B ([143](https://github.com/pytroll/pyspectral/issues/143))
+
+In this release 3 pull requests were closed.
+
+
 ## Version <v0.12.2> (2022/10/24)
 
 ### Issues Closed


=====================================
CHANGELOG_RSR_DATA.rst
=====================================
@@ -2,6 +2,14 @@ Changelog for the Relative Spectral Response data
 =================================================
 
 
+Version <v1.2.2> (Tue Nov 15 14:44:03 2022)
+-------------------------------------------
+
+ * Added RSR file for AGRI onboard FY-4B
+ * Corrected RSR file for AGRI onboard FY-3B
+   Values were between 0 and 100, now scaled to between 0 and 1
+
+
 Version <v1.2.1> (Mon Oct 24 16:26:14 2022)
 -------------------------------------------
 


=====================================
bin/composite_rsr_plot.py
=====================================
@@ -28,7 +28,7 @@ import matplotlib.pyplot as plt
 import numpy as np
 
 from pyspectral.rsr_reader import RelativeSpectralResponse
-from pyspectral.utils import get_bandname_from_wavelength, get_logger, logging_off, logging_on
+from pyspectral.utils import INSTRUMENTS, get_logger, logging_off, logging_on
 
 
 def plot_band(plt_in, band_name, rsr_obj, **kwargs):
@@ -149,6 +149,8 @@ if __name__ == "__main__":
 
     for platform in platform_names:
         for sensor in sensors:
+            if platform in INSTRUMENTS and sensor not in INSTRUMENTS.get(platform):
+                continue
             try:
                 rsr = RelativeSpectralResponse(platform, sensor)
             except IOError:
@@ -165,7 +167,7 @@ if __name__ == "__main__":
         LOG.debug("Platform name %s and Sensor: %s", str(rsr.platform_name), str(rsr.instrument))
 
         if req_wvl:
-            bands = get_bandname_from_wavelength(sensor, req_wvl, rsr.rsr, 0.25, multiple_bands=True)
+            bands = rsr.get_bandname_from_wavelength(req_wvl, 0.25, multiple_bands=True)
             if not bands:
                 continue
             if isinstance(bands, list):
@@ -184,7 +186,7 @@ if __name__ == "__main__":
             wvlx = wvlmin
             prev_band = None
             while wvlx < wvlmax:
-                bands = get_bandname_from_wavelength(sensor, wvlx, rsr.rsr, wavel_res, multiple_bands=True)
+                bands = rsr.get_bandname_from_wavelength(wvlx, wavel_res, multiple_bands=True)
 
                 if isinstance(bands, list):
                     b__ = bands[0]


=====================================
bin/plot_rsr.py
=====================================
@@ -25,7 +25,6 @@ import matplotlib.pyplot as plt
 import numpy as np
 
 from pyspectral.rsr_reader import RelativeSpectralResponse
-from pyspectral.utils import get_bandname_from_wavelength
 
 if __name__ == "__main__":
 
@@ -69,7 +68,7 @@ if __name__ == "__main__":
         band = args.bandname
     else:
         wavelength = args.wavelength
-        band = get_bandname_from_wavelength(sensor, wavelength, rsr.rsr)
+        band = rsr.get_bandname_from_wavelength(wavelength)
 
     detectors = rsr.rsr[band].keys()
     for det in detectors:


=====================================
pyspectral/etc/pyspectral.yaml
=====================================
@@ -211,22 +211,40 @@ download_from_internet: True
 #   ch15: GOES-R_ABI_FM2_SRF_CWG_ch15.txt
 #   ch16: GOES-R_ABI_FM2_SRF_CWG_ch16.txt
 
-# FY-4A-agri:
-#     path: /path/to/original/fy4a/agri/data
-#     ch1: FY4A_AGRI_SRF_CH01.txt
-#     ch2: FY4A_AGRI_SRF_CH02.txt
-#     ch3: FY4A_AGRI_SRF_CH03.txt
-#     ch4: FY4A_AGRI_SRF_CH04.txt
-#     ch5: FY4A_AGRI_SRF_CH05.txt
-#     ch6: FY4A_AGRI_SRF_CH06.txt
-#     ch7: FY4A_AGRI_SRF_CH07.txt
-#     ch8: FY4A_AGRI_SRF_CH08.txt
-#     ch9: FY4A_AGRI_SRF_CH09.txt
-#     ch10: FY4A_AGRI_SRF_CH10.txt
-#     ch11: FY4A_AGRI_SRF_CH11.txt
-#     ch12: FY4A_AGRI_SRF_CH12.txt
-#     ch13: FY4A_AGRI_SRF_CH13.txt
-#     ch14: FY4A_AGRI_SRF_CH14.txt
+#FY-4A-agri:
+#    path: D:/rsr/FY4A/
+#    ch1: FY4A_AGRI_SRF_CH01_Pub.txt
+#    ch2: FY4A_AGRI_SRF_CH02_Pub.txt
+#    ch3: FY4A_AGRI_SRF_CH03_Pub.txt
+#    ch4: FY4A_AGRI_SRF_CH04_Pub.txt
+#    ch5: FY4A_AGRI_SRF_CH05_Pub.txt
+#    ch6: FY4A_AGRI_SRF_CH06_Pub.txt
+#    ch7: FY4A_AGRI_SRF_CH07_CH08_Pub.txt
+#    ch8: FY4A_AGRI_SRF_CH07_CH08_Pub.txt
+#    ch9: FY4A_AGRI_SRF_CH09_Pub.txt
+#    ch10: FY4A_AGRI_SRF_CH10_Pub.txt
+#    ch11: FY4A_AGRI_SRF_CH11_Pub.txt
+#    ch12: FY4A_AGRI_SRF_CH12_Pub.txt
+#    ch13: FY4A_AGRI_SRF_CH13_Pub.txt
+#    ch14: FY4A_AGRI_SRF_CH14_Pub.txt
+
+#FY-4B-agri:
+#     path: D:/rsr/FY4B/
+#     ch1: FY4B_AGRI_SRF_CH01_Pub.txt
+#     ch2: FY4B_AGRI_SRF_CH02_Pub.txt
+#     ch3: FY4B_AGRI_SRF_CH03_Pub.txt
+#     ch4: FY4B_AGRI_SRF_CH04_Pub.txt
+#     ch5: FY4B_AGRI_SRF_CH05_Pub.txt
+#     ch6: FY4B_AGRI_SRF_CH06_Pub.txt
+#     ch7: FY4B_AGRI_SRF_CH07 & CH08_Pub.txt
+#     ch8: FY4B_AGRI_SRF_CH07 & CH08_Pub.txt
+#     ch9: FY4B_AGRI_SRF_CH09_Pub.txt
+#     ch10: FY4B_AGRI_SRF_CH10_Pub.txt
+#     ch11: FY4B_AGRI_SRF_CH11_Pub.txt
+#     ch12: FY4B_AGRI_SRF_CH12_Pub.txt
+#     ch13: FY4B_AGRI_SRF_CH13_Pub.txt
+#     ch14: FY4B_AGRI_SRF_CH14_Pub.txt
+#     ch15: FY4B_AGRI_SRF_CH15_Pub.txt
 
 #Electro-L-N2-msu-gs:
 #     path: /path/to/rsrs/rtcoef_electro-l_2_msugs_srf/


=====================================
pyspectral/rayleigh.py
=====================================
@@ -150,12 +150,16 @@ class Rayleigh(RayleighConfigBaseClass):
         self.sensor = sensor
         self.coeff_filename = None
 
-        # Try fix instrument naming
+        # Try to fix instrument naming
         instr = INSTRUMENTS.get(platform_name, sensor)
         if instr != sensor:
-            sensor = instr
-            LOG.warning("Inconsistent sensor/satellite input - " +
-                        "sensor set to %s", sensor)
+            if isinstance(instr, list):
+                if sensor not in instr:
+                    raise ValueError("This satellite has multiple sensors, you must explicitly state which to use.")
+            else:
+                sensor = instr
+                LOG.warning("Inconsistent sensor/satellite input - " +
+                            "sensor set to %s", sensor)
 
         self.sensor = sensor.replace('/', '')
 


=====================================
pyspectral/rsr_reader.py
=====================================
@@ -26,9 +26,9 @@ from os.path import expanduser
 
 import numpy as np
 
+from pyspectral.bandnames import BANDNAMES
 from pyspectral.config import get_config
 from pyspectral.utils import (
-    BANDNAMES,
     INSTRUMENTS,
     RSR_DATA_VERSION,
     RSR_DATA_VERSION_FILENAME,
@@ -38,6 +38,7 @@ from pyspectral.utils import (
     convert2str,
     convert2wavenumber,
     download_rsr,
+    get_bandname_from_wavelength,
     get_central_wave,
 )
 
@@ -335,6 +336,11 @@ class RelativeSpectralResponse(RSRDataBaseClass):
                 self.set_band_wavelengths_per_detector(h5f, bandname, dname)
                 self.set_band_central_wavelength_per_detector(h5f, bandname, dname)
 
+    def get_bandname_from_wavelength(self, wavelength, epsilon=0.1, multiple_bands=False):
+        """Get the band name from the wavelength."""
+        return get_bandname_from_wavelength(self.instrument, wavelength, self.rsr,
+                                            epsilon=epsilon, multiple_bands=multiple_bands)
+
 
 def check_and_download(dest_dir=None, dry_run=False):
     """Do a check for the version and attempt downloading only if needed."""


=====================================
pyspectral/tests/test_rayleigh.py
=====================================
@@ -120,8 +120,8 @@ def _create_fake_lut_hdf5_file(base_dir, atm_type) -> str:
     return filename
 
 
-def _create_rayleigh():
-    rayl = rayleigh.Rayleigh('NOAA-20', 'viirs', atmosphere='midlatitude summer')
+def _create_rayleigh(platform='NOAA-20', sensor='VIIRS'):
+    rayl = rayleigh.Rayleigh(platform, sensor, atmosphere='midlatitude summer')
     return rayl
 
 
@@ -280,6 +280,24 @@ class TestRayleigh:
         retv = rayleigh.Rayleigh.reduce_rayleigh_highzenith(sun_zenith, in_rayleigh, 30., 90., 1.5)
         np.testing.assert_allclose(retv, TEST_RAYLEIGH_RESULT_R2)
 
+    def test_rayleigh_getname(self):
+        """Test logic for Rayleigh instrument selection."""
+
+        with pytest.raises(ValueError):
+            _create_rayleigh(platform='FY-4B')
+
+        rayl = _create_rayleigh(platform='FY-4A', sensor='agri')
+        assert rayl.sensor == 'agri'
+
+        rayl = _create_rayleigh(platform='FY-4B', sensor='agri')
+        assert rayl.sensor == 'agri'
+
+        rayl = _create_rayleigh(platform='FY-4B', sensor='ghi')
+        assert rayl.sensor == 'ghi'
+
+        with pytest.raises(ValueError):
+            _create_rayleigh(platform='FY-4B', sensor='nosensor')
+
     @patch('pyspectral.rayleigh.da', None)
     def test_get_reflectance_redband_outside_clip(self, fake_lut_hdf5):
         """Test getting the reflectance correction - using red band reflections outside 20 to 100."""


=====================================
pyspectral/tests/test_rsr_reader.py
=====================================
@@ -385,6 +385,20 @@ class TestPopulateRSRObject(unittest.TestCase):
         expected = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
         assertNumpyArraysEqual(test_rsr.rsr['M1']['det-1']['response'].data, expected)
 
+    @patch('pyspectral.rsr_reader.RelativeSpectralResponse.load')
+    @patch('pyspectral.rsr_reader.RelativeSpectralResponse._check_consistent_input')
+    def test_get_bandname_from_rsr(self,
+                                   check_consistent_input, load):
+        """Test get the matching band name from the rsr object."""
+        load.return_value = None
+        check_consistent_input.return_value = None
+
+        test_rsr = RelativeSpectralResponse('EOS-Aqua', 'modis')
+        test_rsr.rsr = TEST_RSR
+
+        myband = test_rsr.get_bandname_from_wavelength(3.75)
+        assert myband == '20'
+
     def test_rsr_dict(self):
         """Test finding correct band names from utils dicts."""
         test_rsr = RSRDict(instrument='viirs')
@@ -442,6 +456,16 @@ def test_get_rsr_from_platform_and_instrument(get_rsr_version,
         assert test_rsr.instrument == exp_instrument
         assert os.path.basename(test_rsr.filename) == exp_filename
 
+    # def test_get_bandname_from_wavelength_inconsistent_instrument_name(self):
+    #     """Test the right bandname is found provided the wavelength in micro meters.
+
+    #     Here we test that if you enter with a sensor name different from what
+    #     is set in the RSR object, an error is raised.
+
+    #     """
+    #     with pytest.raises(AttributeError):
+    #         bname = utils.get_bandname_from_wavelength('ahi', 0.4, self.rsr)
+
 
 @pytest.mark.parametrize(
     ("version", "exp_download"),


=====================================
pyspectral/tests/test_utils.py
=====================================
@@ -33,7 +33,7 @@ import pytest
 import responses
 
 from pyspectral import utils
-from pyspectral.utils import bytes2string, check_and_adjust_instrument_name, np2str
+from pyspectral.utils import bytes2string, check_and_adjust_instrument_name, are_instruments_identical, np2str
 
 TEST_RSR = {'20': {}, }
 TEST_RSR2 = {'20': {}, }
@@ -415,3 +415,27 @@ def test_check_and_adjust_instrument_name_instrument_name_inconsistent(caplog,
 
     log_output = "Inconsistent instrument/satellite input - instrument set to {instr}".format(instr=exp_sensor_name)
     assert log_output in caplog.text
+
+
+ at pytest.mark.parametrize(
+    ("platform_name", "input_value_sensor", "exp_sensor_name"),
+    [
+        ('GOES-16', 'abi', 'abi'),
+        ('FY-4B', 'ghi', 'ghi'),
+        ('Meteosat-12', 'fci', 'fci'),
+    ],
+)
+def test_check_and_adjust_instrument_name_correct(platform_name, input_value_sensor, exp_sensor_name):
+    """Check instrument name is not changed if correct."""
+    assert check_and_adjust_instrument_name(platform_name, input_value_sensor) == exp_sensor_name
+
+
+def test_are_instruments_identical():
+    """Test that error is raised if non-string is passed to the function."""
+    res = are_instruments_identical('thing1', 'thing1')
+    assert res is True
+    res = are_instruments_identical('thing1', 'thing2')
+    assert res is False
+
+    with pytest.raises(ValueError):
+        are_instruments_identical(['thing1', 'thing3'], 'thing2')


=====================================
pyspectral/utils.py
=====================================
@@ -42,56 +42,66 @@ LOG = logging.getLogger(__name__)
 WAVE_LENGTH = 'wavelength'
 WAVE_NUMBER = 'wavenumber'
 
-
-INSTRUMENTS = {'NOAA-19': 'avhrr/3',
-               'NOAA-18': 'avhrr/3',
-               'NOAA-17': 'avhrr/3',
-               'NOAA-16': 'avhrr/3',
-               'NOAA-15': 'avhrr/3',
-               'NOAA-14': 'avhrr/2',
-               'NOAA-12': 'avhrr/2',
-               'NOAA-11': 'avhrr/2',
-               'NOAA-9': 'avhrr/2',
-               'NOAA-7': 'avhrr/2',
+INSTRUMENTS = {'Envisat': 'aatsr',
+               'GOES-16': 'abi',
+               'GOES-17': 'abi',
+               'GOES-18': 'abi',
+               'GOES-19': 'abi',
+               'FY-4A': 'agri',
+               'FY-4B': ['agri', 'ghi'],
+               'Himawari-8': 'ahi',
+               'Himawari-9': 'ahi',
+               'GEO-KOMPSAT-2A': 'ami',
                'NOAA-10': 'avhrr/1',
-               'NOAA-8': 'avhrr/1',
                'NOAA-6': 'avhrr/1',
+               'NOAA-8': 'avhrr/1',
                'TIROS-N': 'avhrr/1',
+               'NOAA-11': 'avhrr/2',
+               'NOAA-12': 'avhrr/2',
+               'NOAA-14': 'avhrr/2',
+               'NOAA-7': 'avhrr/2',
+               'NOAA-9': 'avhrr/2',
                'Metop-A': 'avhrr/3',
                'Metop-B': 'avhrr/3',
                'Metop-C': 'avhrr/3',
-               'Suomi-NPP': 'viirs',
-               'NOAA-20': 'viirs',
+               'NOAA-15': 'avhrr/3',
+               'NOAA-16': 'avhrr/3',
+               'NOAA-17': 'avhrr/3',
+               'NOAA-18': 'avhrr/3',
+               'NOAA-19': 'avhrr/3',
+               'HY-1C': 'cocts',
+               'Meteosat-12': 'fci',
+               'MTG-I1': 'fci',
+               'FY-3D': 'mersi-2',
+               'Metop-SG-A1': 'metimage',
                'EOS-Aqua': 'modis',
                'EOS-Terra': 'modis',
-               'FY-3E': 'mersi-2',
-               'FY-3D': 'mersi-2',
-               'FY-3C': 'virr',
-               'FY-3B': 'virr',
-               'Feng-Yun 3D': 'mersi-2',
-               'Meteosat-11': 'seviri',
+               'Sentinel-2A': 'msi',
+               'Sentinel-2B': 'msi',
+               'Arctica-M-N1': 'msu-gsa',
+               'Electro-L-N2': 'msu-gs',
+               'Sentinel-3A': ['olci', 'slstr'],
+               'Sentinel-3B': ['olci', 'slstr'],
+               'Landsat-8': 'oli',
                'Meteosat-10': 'seviri',
-               'Meteosat-9': 'seviri',
+               'Meteosat-11': 'seviri',
                'Meteosat-8': 'seviri',
-               'FY-4A': 'agri',
-               'FY-4B': 'agri',
-               'GEO-KOMPSAT-2A': 'ami',
-               'MTG-I1': 'fci',
-               'Meteosat-12': 'fci',
-               'GOES-16': 'abi',
-               'GOES-17': 'abi',
-               'GOES-18': 'abi',
-               'Arctica-M-N1': 'msu-gsa'
-               }
+               'Meteosat-9': 'seviri',
+               'NOAA-20': 'viirs',
+               'NOAA-21': 'viirs',
+               'Suomi-NPP': 'viirs',
+               'FY-3B': 'virr',
+               'FY-3C': 'virr'}
+
 
 INSTRUMENT_TRANSLATION_DASH2SLASH = {'avhrr-1': 'avhrr/1',
                                      'avhrr-2': 'avhrr/2',
                                      'avhrr-3': 'avhrr/3'}
 
-HTTP_PYSPECTRAL_RSR = "https://zenodo.org/record/7245133/files/pyspectral_rsr_data.tgz"
+HTTP_PYSPECTRAL_RSR = "https://zenodo.org/record/7311143/files/pyspectral_rsr_data.tgz"
 
 RSR_DATA_VERSION_FILENAME = "PYSPECTRAL_RSR_VERSION"
-RSR_DATA_VERSION = "v1.2.1"
+RSR_DATA_VERSION = "v1.2.2"
 
 ATM_CORRECTION_LUT_VERSION = {}
 ATM_CORRECTION_LUT_VERSION['antarctic_aerosol'] = {'version': 'v1.0.1',
@@ -212,8 +222,6 @@ def get_central_wave(wav, resp, weight=1.0):
 
 def get_bandname_from_wavelength(sensor, wavelength, rsr, epsilon=0.1, multiple_bands=False):
     """Get the bandname from h5 rsr provided the approximate wavelength."""
-    # channel_list = [channel for channel in rsr.rsr if abs(
-    # rsr.rsr[channel]['det-1']['central_wavelength'] - wavelength) < epsilon]
     chdist_min = 2.0
     chfound = []
     for channel in rsr:
@@ -523,6 +531,14 @@ def bytes2string(var):
     return var
 
 
+def _replace_inst_name(instruments):
+    """Replace an instrument name if it's not available on a platform."""
+    if isinstance(instruments, list):
+        return instruments[0]
+    else:
+        return instruments
+
+
 def check_and_adjust_instrument_name(platform_name, instrument):
     """Check instrument name and try fix if inconsistent.
 
@@ -531,8 +547,16 @@ def check_and_adjust_instrument_name(platform_name, instrument):
     removing the '/'.
     """
     instr = INSTRUMENTS.get(platform_name, instrument.lower())
-    if not are_instruments_identical(instr, instrument.lower()):
-        instrument = instr
+    if isinstance(instr, list):
+        for inst in instr:
+            goodinst = are_instruments_identical(inst, instrument.lower())
+            if goodinst:
+                break
+    else:
+        goodinst = are_instruments_identical(instr, instrument.lower())
+
+    if not goodinst:
+        instrument = _replace_inst_name(instr)
         LOG.warning("Inconsistent instrument/satellite input - instrument set to %s",
                     instrument)
 
@@ -546,9 +570,11 @@ def are_instruments_identical(name1, name2):
     (following WMO Oscar) is is with a slash as in 'avhrr/1', but where a
     naming using a dash instead is equally accepted, as in 'avhrr-1'.
     """
+    if not isinstance(name1, str) or not isinstance(name2, str):
+        raise ValueError("Instrument names must be strings.")
+
     if name1 == name2:
         return True
     if name1 == INSTRUMENT_TRANSLATION_DASH2SLASH.get(name2):
         return True
-
     return False


=====================================
rsr_convert_scripts/agri_rsr.py
=====================================
@@ -17,9 +17,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.
+"""Read the FY-4A/B AGRI relative spectral responses.
 
-Data from http://fy4.nsmc.org.cn/portal/cn/fycv/srf.html
+Data from http://satellite.nsmc.org.cn/PortalSite/StaticContent/DocumentDownload.aspx?TypeID=590
 """
 import os
 
@@ -68,13 +68,19 @@ class AGRIRSR(InstrumentRSR):
 
     def __init__(self, bandname, platform_name):
         """Initialise the FY-4 AGRI relative spectral response data."""
-        super(AGRIRSR, self).__init__(bandname, platform_name, FY4_AGRI_BAND_NAMES)
+        if platform_name == 'FY-4A':
+            super(AGRIRSR, self).__init__(bandname, platform_name, FY4_AGRI_BAND_NAMES[:-1])
+        else:
+            super(AGRIRSR, self).__init__(bandname, platform_name, FY4_AGRI_BAND_NAMES)
 
         self.instrument = INSTRUMENTS.get(platform_name, 'agri')
+        if type(self.instrument) is list:
+            self.instrument = 'agri'
 
         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]
@@ -98,21 +104,34 @@ class AGRIRSR(InstrumentRSR):
         Wavelength is given in nanometers.
         """
         data = np.genfromtxt(self.requested_band_filename,
-                             unpack=True,
+                             unpack=True, delimiter='\t',
                              names=['wavelength',
                                     'response'],
-                             skip_header=0)
+                             skip_header=1)
+
+        wavelength = data[0] * scale
+        response = data[1]
 
-        wavelength = data['wavelength'] * scale
-        response = data['response'] / 100.
+        # 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_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)
+    # For FY-4A
+    # tohdf5(AGRIRSR, 'FY-4A', FY4_AGRI_BAND_NAMES[:-1])
+
+    # For FY-4B
+    tohdf5(AGRIRSR, 'FY-4B', FY4_AGRI_BAND_NAMES)
 
 
 if __name__ == "__main__":



View it on GitLab: https://salsa.debian.org/debian-gis-team/pyspectral/-/commit/40cd5d3ee8f398a51589daeb4e8b9bf5d5a0cf12

-- 
View it on GitLab: https://salsa.debian.org/debian-gis-team/pyspectral/-/commit/40cd5d3ee8f398a51589daeb4e8b9bf5d5a0cf12
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-grass-devel/attachments/20221125/79154f7d/attachment-0001.htm>


More information about the Pkg-grass-devel mailing list