示例#1
0
    def test_integral(self, get_rsr_version, download_rsr, load, isfile, exists):
        """Test the calculation of the integral of the spectral responses"""
        load.return_code = None
        download_rsr.return_code = None
        isfile.return_code = True
        exists.return_code = True
        get_rsr_version.return_code = RSR_DATA_VERSION

        with patch('pyspectral.rsr_reader.get_config', return_value=TEST_CONFIG):
            test_rsr = RelativeSpectralResponse('EOS-Aqua', 'modis')
            test_rsr.rsr = TEST_RSR2
            res = test_rsr.integral('20')
            self.assertAlmostEqual(res['det-1'], 0.185634, 6)
示例#2
0
    def test_integral(self, get_rsr_version, download_rsr, load, isfile, exists):
        """Test the calculation of the integral of the spectral responses"""
        load.return_code = None
        download_rsr.return_code = None
        isfile.return_code = True
        exists.return_code = True
        get_rsr_version.return_code = RSR_DATA_VERSION

        with patch('pyspectral.rsr_reader.get_config', return_value=TEST_CONFIG):
            test_rsr = RelativeSpectralResponse('EOS-Aqua', 'modis')
            test_rsr.rsr = TEST_RSR2
            res = test_rsr.integral('20')
            self.assertAlmostEqual(res['det-1'], 0.185634, 6)
    def _get_rsr(self):
        """Get the relative spectral responses.

        Get the relative spectral responses from file, find the bandname, and
        convert to the requested wave-spave (wavelength or wave number)

        """
        sensor = RelativeSpectralResponse(self.platform_name, self.instrument)

        if self.wavespace == WAVE_NUMBER:
            LOG.debug("Converting to wavenumber...")
            self.rsr, info = convert2wavenumber(sensor.rsr)
        else:
            self.rsr = sensor.rsr
            info = {'unit': sensor.unit, 'si_scale': sensor.si_scale}

        self._wave_unit = info['unit']
        self._wave_si_scale = info['si_scale']

        if isinstance(self.band, str):
            self.bandname = BANDNAMES.get(self.instrument,
                                          BANDNAMES['generic']).get(
                                              self.band, self.band)
        elif isinstance(self.band, Number):
            self.bandwavelength = self.band
            self.bandname = get_bandname_from_wavelength(
                self.instrument, self.band, self.rsr)

        self.wavelength_or_wavenumber = (
            self.rsr[self.bandname][self.detector][self.wavespace] *
            self._wave_si_scale)
        self.response = self.rsr[self.bandname][self.detector]['response']
        # Get the integral of the spectral response curve:
        self.rsr_integral = np.trapz(self.response,
                                     self.wavelength_or_wavenumber)
示例#4
0
    def get_effective_wavelength(self, bandname):
        """Get the effective wavelength with Rayleigh scattering in mind"""
        try:
            rsr = RelativeSpectralResponse(self.platform_name, self.sensor)
        except(IOError, OSError):
            LOG.exception(
                "No spectral responses for this platform and sensor: %s %s", self.platform_name, self.sensor)
            if isinstance(bandname, (float, integer_types)):
                LOG.warning(
                    "Effective wavelength is set to the requested band wavelength = %f", bandname)
                return bandname
            return None

        if isinstance(bandname, str):
            bandname = BANDNAMES.get(self.sensor, BANDNAMES['generic']).get(bandname, bandname)
        elif isinstance(bandname, (float, integer_types)):
            if not(0.4 < bandname < 0.8):
                raise BandFrequencyOutOfRange(
                    'Requested band frequency should be between 0.4 and 0.8 microns!')
            bandname = get_bandname_from_wavelength(self.sensor, bandname, rsr.rsr)

        wvl, resp = rsr.rsr[bandname][
            'det-1']['wavelength'], rsr.rsr[bandname]['det-1']['response']

        cwvl = get_central_wave(wvl, resp, weight=1. / wvl**4)
        LOG.debug("Band name: %s  Effective wavelength: %f", bandname, cwvl)

        return cwvl
示例#5
0
    def test_rsr_reponse(self, download_rsr, load, isfile, exists):
        """Test the RelativeSpectralResponse class initialisation"""
        load.return_code = None
        download_rsr.return_code = None
        isfile.return_code = True
        exists.return_code = True

        with patch('pyspectral.rsr_reader.get_config',
                   return_value=TEST_CONFIG):
            with self.assertRaises(AttributeError):
                test_rsr = RelativeSpectralResponse('GOES-16')
                test_rsr = RelativeSpectralResponse(instrument='ABI')

            test_rsr = RelativeSpectralResponse('GOES-16', 'AbI')
            self.assertEqual(test_rsr.platform_name, 'GOES-16')
            self.assertEqual(test_rsr.instrument, 'abi')
            test_rsr = RelativeSpectralResponse('GOES-16', 'ABI')
            self.assertEqual(test_rsr.instrument, 'abi')

        with patch('pyspectral.rsr_reader.get_config',
                   return_value=TEST_CONFIG):
            test_rsr = RelativeSpectralResponse('GOES-16', 'abi')

        self.assertEqual(test_rsr.platform_name, 'GOES-16')
        self.assertEqual(test_rsr.instrument, 'abi')
        self.assertEqual(test_rsr.filename,
                         os.path.join(TEST_RSR_DIR, 'rsr_abi_GOES-16.h5'))

        with patch('pyspectral.rsr_reader.get_config',
                   return_value=TEST_CONFIG):
            test_rsr = RelativeSpectralResponse(
                filename=os.path.join(TEST_RSR_DIR, 'rsr_abi_GOES-16.h5'))

        self.assertEqual(test_rsr.filename,
                         os.path.join(TEST_RSR_DIR, 'rsr_abi_GOES-16.h5'))
    def get_rsr(self):
        """Get all spectral responses for the sensor"""

        from pyspectral.utils import convert2wavenumber
        from pyspectral.rsr_reader import RelativeSpectralResponse

        sensor = RelativeSpectralResponse(self.platform, self.satnumber,
                                          self.instrument)
        LOG.debug("Wavenumber? " + str(self.wavespace))
        if self.wavespace == WAVE_NUMBER:
            LOG.debug("Converting to wavenumber...")
            self.rsr, info = convert2wavenumber(sensor.rsr)
        else:
            self.rsr = sensor.rsr
            info = {'unit': sensor.unit, 'si_scale': sensor.si_scale}

        self._wave_unit = info['unit']
        self._wave_si_scale = info['si_scale']
示例#7
0
def main(arguments):
    """Retrieve wavelength range based on user-supplied arguments."""
    platform = arguments.platform_name
    sensor = arguments.sensor
    threshold = arguments.minimum_response

    rsr = RelativeSpectralResponse(platform, sensor)
    if arguments.bandname:
        bands = [arguments.bandname]
    else:
        bands = rsr.band_names
    det = arguments.detector

    for bname in bands:
        wvls = get_wave_range(rsr.rsr[bname][det], threshold)
        print(f'name:  {bname}')
        print(
            f'  wavelength: [{wvls[0]:5.3f}, {wvls[1]:5.3f}, {wvls[2]:5.3f}]')
示例#8
0
    def test_convert(self, get_rsr_version, download_rsr, load, isfile, exists):
        """Test the conversion method"""
        load.return_code = None
        download_rsr.return_code = None
        isfile.return_code = True
        exists.return_code = True
        get_rsr_version.return_code = RSR_DATA_VERSION

        with patch('pyspectral.rsr_reader.get_config', return_value=TEST_CONFIG):
            test_rsr = RelativeSpectralResponse('EOS-Aqua', 'modis')
            test_rsr.rsr = TEST_RSR
            test_rsr.convert()
            self.assertAlmostEqual(test_rsr.rsr['20']['det-1']['central_wavenumber'], 2647.397, 3)
            self.assertTrue(np.allclose(test_rsr.rsr['20']['det-1'][WAVE_NUMBER], RESULT_WVN_RSR, 5))
            self.assertEqual(test_rsr._wavespace, WAVE_NUMBER)

            with self.assertRaises(NotImplementedError):
                test_rsr.convert()
示例#9
0
    def test_convert(self, get_rsr_version, download_rsr, load, isfile, exists):
        """Test the conversion method"""
        load.return_code = None
        download_rsr.return_code = None
        isfile.return_code = True
        exists.return_code = True
        get_rsr_version.return_code = RSR_DATA_VERSION

        with patch('pyspectral.rsr_reader.get_config', return_value=TEST_CONFIG):
            test_rsr = RelativeSpectralResponse('EOS-Aqua', 'modis')
            test_rsr.rsr = TEST_RSR
            test_rsr.convert()
            self.assertAlmostEqual(test_rsr.rsr['20']['det-1']['central_wavenumber'], 2647.397, 3)
            self.assertTrue(np.allclose(test_rsr.rsr['20']['det-1'][WAVE_NUMBER], RESULT_WVN_RSR, 5))
            self.assertEqual(test_rsr._wavespace, WAVE_NUMBER)

            with self.assertRaises(NotImplementedError):
                test_rsr.convert()
示例#10
0
        band = args.bandname
    elif args.wavelength:
        req_wvl = args.wavelength

    figscale = 1.0
    if wvlmin:
        figscale = (wvlmax - wvlmin) / 4.
    figsize = (figscale * 1. + 10, figscale * 0.5 + 5)

    plt.figure(figsize=figsize)
    something2plot = False

    for platform in platform_names:
        for sensor in sensors:
            try:
                rsr = RelativeSpectralResponse(platform, sensor)
            except IOError:
                # LOG.exception('Failed getting the rsr data for platform %s ' +
                #              'and sensor %s', platform, sensor)
                rsr = None
            else:
                break

        if not rsr:
            continue

        something2plot = True
        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)
sza = -62.64299
saa = 165.6918

storm_lat = -3.2609048
storm_lon = 163.2608

storm_time = datetime(2018, 12, 29, 13, 30, tzinfo=pytz.utc)

# Below are pre-defined BT values for the storm coordinates and time given above.
# Also included are the wavelength ranges required for the plotting later on.

# This threshold is used to define min/max wavelength
rsr_thresh = 0.15

# NOAA-20 / VIIRS first
rsr = RelativeSpectralResponse('NOAA-20', 'viirs')
viirsi_data = {
    'I04': [208.000] + get_wave_range(rsr.rsr['I4']['det-1'], rsr_thresh),
    'I05': [161.955] + get_wave_range(rsr.rsr['I5']['det-1'], rsr_thresh)
}

viirsm_data = {
    'M12': [203.000] + get_wave_range(rsr.rsr['M12']['det-1'], rsr_thresh),
    'M13': [191.920] + get_wave_range(rsr.rsr['M13']['det-1'], rsr_thresh),
    'M14': [165.503] + get_wave_range(rsr.rsr['M14']['det-1'], rsr_thresh),
    'M15': [163.733] + get_wave_range(rsr.rsr['M15']['det-1'], rsr_thresh),
    'M16': [165.274] + get_wave_range(rsr.rsr['M16']['det-1'], rsr_thresh)
}

# Now GOES-17 / ABI
rsr = RelativeSpectralResponse('GOES-17', 'abi')
示例#12
0
print("... read responce functions")
from pyspectral.near_infrared_reflectance import Calculator
from pyspectral.solar import (SolarIrradianceSpectrum, TOTAL_IRRADIANCE_SPECTRUM_2000ASTM)

solar_irr = SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=0.0005)

#from pyspectral.seviri_rsr import load
#seviri = load()
#rsr = {'wavelength': seviri['IR3.9']['wavelength'], 
#       'response': seviri['IR3.9']['met10']['95']}
#sflux = solar_irr.solar_flux_over_band(rsr)

solar_irr = SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=0.0005)
from pyspectral.rsr_reader import RelativeSpectralResponse
seviri = RelativeSpectralResponse('Meteosat-10', 'seviri')
sflux = solar_irr.inband_solarflux(seviri.rsr['IR3.9'])

ch39 = local_data['IR_039']
ch11 = local_data['IR_108']
ch13 = local_data['IR_134']
lonlats = ch39.area.get_lonlats()

from pyorbital.astronomy import sun_zenith_angle
sunz = sun_zenith_angle(tslot, lonlats[0], lonlats[1])

print("... create look-up-table")
#refl37 = Calculator(rsr)
refl37 = Calculator('Meteosat-9', 'seviri', 'IR3.9', solar_flux=sflux)
#refl37.make_tb2rad_lut('/tmp/seviri_37_tb2rad_lut.npz')
# new syntax -> 
示例#13
0
_DEFAULT_TIME_FORMAT = '%Y-%m-%d %H:%M:%S'

#: Default log format
_DEFAULT_LOG_FORMAT = '[%(levelname)s: %(asctime)s : %(name)s] %(message)s'
LOG = logging.getLogger('test_ahi')
handler = logging.StreamHandler(sys.stderr)

formatter = logging.Formatter(fmt=_DEFAULT_LOG_FORMAT,
                              datefmt=_DEFAULT_TIME_FORMAT)
handler.setFormatter(formatter)
handler.setLevel(logging.DEBUG)
LOG.setLevel(logging.DEBUG)
logging.getLogger("").setLevel(logging.DEBUG)
LOG.addHandler(handler)

ahi = RelativeSpectralResponse('Himawari-8', 'ahi')
solar_irr = SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM,
                                    dlambda=0.005)
sflux = solar_irr.inband_solarflux(ahi.rsr['ch7'])
LOG.info("Solar flux over Band: " + str(sflux))

# sunz = [80., 80.5]
# tb7 = [288.0, 390.0]
# tb14 = [282.0, 272.0]
# tb16 = [275.0, 269.0]

sunz = np.random.rand(5500, 550) * 120.
tb7 = np.random.rand(5500, 550) * 120. + 260.0
tb14 = np.random.rand(5500, 550) * 30. + 260.0
tb16 = np.random.rand(5500, 550) * 30. + 250.0