Beispiel #1
0
    def test_get_effective_wavelength(self):
        """Test getting the effective wavelength."""
        # mymock:
        with patch('pyspectral.rayleigh.RelativeSpectralResponse') as mymock:
            instance = mymock.return_value
            instance.rsr = RelativeSpectralResponseTestData().rsr

            this = rayleigh.Rayleigh('Himawari-8', 'ahi')
            with self.assertRaises(BandFrequencyOutOfRange):
                this.get_effective_wavelength(0.9)

            # Only ch3 (~0.63) testdata implemented yet...
            ewl = this.get_effective_wavelength(0.65)
            self.assertAlmostEqual(ewl, 0.6356167)

        # mymock:
        with patch('pyspectral.rayleigh.RelativeSpectralResponse') as mymock:
            instance = mymock.side_effect = IOError(
                'Fake that there is no spectral response file...')

            this = rayleigh.Rayleigh('Himawari-8', 'ahi')
            ewl = this.get_effective_wavelength(0.7)
            self.assertEqual(ewl, 0.7)
            ewl = this.get_effective_wavelength(0.9)
            self.assertEqual(ewl, 0.9)
            ewl = this.get_effective_wavelength(0.455)
            self.assertEqual(ewl, 0.455)
Beispiel #2
0
    def test_rayleigh_init(self, download_luts, exists):
        """Test creating the Rayleigh object."""
        download_luts.return_code = None
        exists.return_code = True

        # mymock:
        with patch('pyspectral.rayleigh.RelativeSpectralResponse') as mymock:
            instance = mymock.return_value
            instance.rsr = RelativeSpectralResponseTestData().rsr

            with self.assertRaises(AttributeError):
                this = rayleigh.Rayleigh('Himawari-8',
                                         'ahi',
                                         atmosphere='unknown')

            with self.assertRaises(AttributeError):
                this = rayleigh.Rayleigh('Himawari-8',
                                         'ahi',
                                         aerosol_type='unknown')

            this = rayleigh.Rayleigh('Himawari-8',
                                     'ahi',
                                     atmosphere='subarctic winter')
            self.assertTrue(
                os.path.basename(this.reflectance_lut_filename).endswith(
                    'subarctic_winter.h5'))
            self.assertTrue(this.sensor == 'ahi')

            this = rayleigh.Rayleigh('NOAA-19',
                                     'avhrr/3',
                                     atmosphere='tropical')
            self.assertTrue(this.sensor == 'avhrr3')
Beispiel #3
0
    def test_get_reflectance_no_rsr(self, get_reflectance_lut, download_luts,
                                    exists):
        """Test getting the reflectance correction, simulating that we have no RSR data."""
        rayl = TEST_RAYLEIGH_LUT
        wvl_coord = TEST_RAYLEIGH_WVL_COORD
        azid_coord = TEST_RAYLEIGH_AZID_COORD
        sunz_sec_coord = TEST_RAYLEIGH_SUNZ_COORD
        satz_sec_coord = TEST_RAYLEIGH_SATZ_COORD

        get_reflectance_lut.return_value = (rayl, wvl_coord, azid_coord,
                                            satz_sec_coord, sunz_sec_coord)
        download_luts.return_code = None
        exists.return_code = True

        with patch('pyspectral.rayleigh.RelativeSpectralResponse') as mymock:
            instance = mymock.return_value
            mymock.side_effect = IOError(
                "No rsr data in pyspectral for this platform and sensor")
            instance.rsr = None
            instance.unit = '1e-6 m'
            instance.si_scale = 1e-6
            sun_zenith = np.array([50., 10.])
            sat_zenith = np.array([39., 16.])
            azidiff = np.array([170., 110.])
            blueband = np.array([29., 12.])
            ufo = rayleigh.Rayleigh('UFO', 'unknown')

            retv = ufo.get_reflectance(sun_zenith, sat_zenith, azidiff, 0.441,
                                       blueband)
            self.assertTrue(np.allclose(retv, TEST_RAYLEIGH_RESULT3))
Beispiel #4
0
    def setUp(self):
        """Setup the test"""

        self.rsr = RelativeSpectralResponseTestData()

        # mymock:
        with patch('pyspectral.rayleigh.RelativeSpectralResponse') as mymock:
            instance = mymock.return_value
            instance.rsr = RelativeSpectralResponseTestData().rsr
            instance.unit = '1e-6 m'
            instance.si_scale = 1e-6

            self.viirs_rayleigh = rayleigh.Rayleigh(
                'NOAA-20', 'viirs', atmosphere='midlatitude summer')
Beispiel #5
0
    def setUp(self):
        """Set up the test."""
        self.cwvl = 0.4440124
        self.rsr = RelativeSpectralResponseTestData()
        self._res1 = da.from_array(TEST_RAYLEIGH_RESULT1, chunks=2)
        self._res2 = da.from_array(TEST_RAYLEIGH_RESULT2, chunks=2)
        self._res3 = da.from_array(TEST_RAYLEIGH_RESULT3, chunks=2)

        # mymock:
        with patch('pyspectral.rayleigh.RelativeSpectralResponse') as mymock:
            instance = mymock.return_value
            instance.rsr = RelativeSpectralResponseTestData().rsr
            instance.unit = '1e-6 m'
            instance.si_scale = 1e-6

            self.viirs_rayleigh = rayleigh.Rayleigh(
                'NOAA-20', 'viirs', atmosphere='midlatitude summer')