コード例 #1
0
    def test_reflectance(self):
        """Test the derivation of the reflective part of a 3.7 micron band"""

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

            with self.assertRaises(NotImplementedError):
                dummy = Calculator('Suomi-NPP', 'viirs', 10.8)

            refl37 = Calculator('Suomi-NPP', 'viirs', 3.7)
            self.assertEqual(refl37.bandwavelength, 3.7)
            self.assertEqual(refl37.bandname, '20')

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

            refl37 = Calculator('EOS-Aqua', 'modis', '20')

        sunz = np.array([80.])
        tb3 = np.array([290.])
        tb4 = np.array([282.])
        refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
        self.assertAlmostEqual(refl.data[0], 0.251245010648, 6)

        tb3x = refl37.emissive_part_3x()
        self.assertAlmostEqual(tb3x, 276.213054, 6)

        sunz = np.array([80.])
        tb3 = np.array([295.])
        tb4 = np.array([282.])
        refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
        self.assertAlmostEqual(refl.data[0], 0.452497961, 6)

        tb3x = refl37.emissive_part_3x()
        self.assertAlmostEqual(tb3x, 270.077268, 6)

        sunz = np.array([50.])
        tb3 = np.array([300.])
        tb4 = np.array([285.])
        refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
        self.assertAlmostEqual(refl.data[0], 0.1189217, 6)

        tb3x = refl37.emissive_part_3x()
        self.assertAlmostEqual(tb3x, 282.455426, 6)
コード例 #2
0
    def test_reflectance(self):
        """Test the derivation of the reflective part of a 3.7 micron band."""
        with patch('pyspectral.radiance_tb_conversion.RelativeSpectralResponse') as mymock:
            instance = mymock.return_value
            # VIIRS doesn't have a channel '20' like MODIS so the generic
            # mapping this test will end up using will find 'ch20' for VIIRS
            viirs_rsr = {'ch20': TEST_RSR['20'], '99': TEST_RSR['99']}
            instance.rsr = viirs_rsr
            instance.unit = '1e-6 m'
            instance.si_scale = 1e-6

            with self.assertRaises(NotImplementedError):
                dummy = Calculator('Suomi-NPP', 'viirs', 10.8)
                del dummy

            refl37 = Calculator('Suomi-NPP', 'viirs', 3.7)
            self.assertEqual(refl37.bandwavelength, 3.7)
            self.assertEqual(refl37.bandname, 'ch20')

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

            refl37 = Calculator('EOS-Aqua', 'modis', '20')

        sunz = np.array([80.])
        tb3 = np.array([290.])
        tb4 = np.array([282.])
        refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
        np.testing.assert_allclose(refl[0], 0.251245010648, 6)

        tb3x = refl37.emissive_part_3x()
        np.testing.assert_allclose(tb3x, 276.213054, 6)

        sunz = np.array([80.])
        tb3 = np.array([295.])
        tb4 = np.array([282.])
        refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
        np.testing.assert_allclose(refl[0], 0.452497961, 6)

        tb3x = refl37.emissive_part_3x()
        np.testing.assert_allclose(tb3x, 270.077268, 6)

        sunz = np.array([50.])
        tb3 = np.array([300.])
        tb4 = np.array([285.])
        refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
        np.testing.assert_allclose(refl[0], 0.1189217, 6)

        tb3x = refl37.emissive_part_3x()
        np.testing.assert_allclose(tb3x, 282.455426, 6)

        sunz = np.array([50.])
        tb3 = np.ma.masked_array([300.], mask=False)
        tb4 = np.ma.masked_array([285.], mask=False)
        refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
        self.assertTrue(hasattr(refl, 'mask'))

        try:
            import dask.array as da
            sunz = da.from_array([50.], chunks=10)
            tb3 = da.from_array([300.], chunks=10)
            tb4 = da.from_array([285.], chunks=10)
            refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
            self.assertTrue(hasattr(refl, 'compute'))
        except ImportError:
            pass
コード例 #3
0
    def test_reflectance(self):
        """Test the derivation of the reflective part of a 3.7 micron band."""
        with patch('pyspectral.radiance_tb_conversion.RelativeSpectralResponse') as mymock:
            instance = mymock.return_value
            # VIIRS doesn't have a channel '20' like MODIS so the generic
            # mapping this test will end up using will find 'ch20' for VIIRS
            viirs_rsr = {'ch20': TEST_RSR['20'], '99': TEST_RSR['99']}
            instance.rsr = viirs_rsr
            instance.unit = '1e-6 m'
            instance.si_scale = 1e-6

            with self.assertRaises(NotImplementedError):
                dummy = Calculator('Suomi-NPP', 'viirs', 10.8)
                del dummy

            refl37 = Calculator('Suomi-NPP', 'viirs', 3.7)
            self.assertEqual(refl37.bandwavelength, 3.7)
            self.assertEqual(refl37.bandname, 'ch20')
            # Default sunz-threshold used to stay on day side and away from terminator:
            self.assertEqual(refl37.sunz_threshold, 85.0)

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

            refl37 = Calculator('EOS-Aqua', 'modis', '20')
            self.assertEqual(refl37.sunz_threshold, TERMINATOR_LIMIT)
            self.assertEqual(refl37.masking_limit, TERMINATOR_LIMIT)

            refl37_sz88 = Calculator('EOS-Aqua', 'modis', '20', sunz_threshold=88.0, masking_limit=None)
            self.assertEqual(refl37_sz88.sunz_threshold, 88.0)
            self.assertIsNone(refl37_sz88.masking_limit)
            self.assertAlmostEqual(refl37_sz88.bandwavelength, 3.780282, 5)
            self.assertEqual(refl37_sz88.bandname, '20')

        sunz = 80.
        tb3 = 290.
        tb4 = 282.
        refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
        np.testing.assert_allclose(refl[0], 0.251245010648, 6)

        sunz = 85.
        tb3 = 290.
        tb4 = 282.
        refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
        np.testing.assert_allclose(refl[0], 1.12236884, 6)

        sunz = np.array([85.1])
        refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
        self.assertTrue(np.isnan(refl[0]))

        refl_sz88 = refl37_sz88.reflectance_from_tbs(sunz, tb3, tb4)
        np.testing.assert_allclose(refl_sz88[0], 1.2064644, 6)
        sunz = np.array([86.0])
        self.assertTrue(np.isnan(refl[0]))

        tb3x = refl37.emissive_part_3x()
        np.testing.assert_allclose(tb3x, 276.213054, 6)

        sunz = np.array([80.])
        tb3 = np.array([295.])
        tb4 = np.array([282.])
        refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
        np.testing.assert_allclose(refl[0], 0.452497961, 6)

        tb3x = refl37.emissive_part_3x()
        np.testing.assert_allclose(tb3x, 270.077268, 6)

        sunz = np.array([50.])
        tb3 = np.array([300.])
        tb4 = np.array([285.])
        refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
        np.testing.assert_allclose(refl[0], 0.1189217, 6)

        tb3x = refl37.emissive_part_3x()
        np.testing.assert_allclose(tb3x, 282.455426, 6)

        sunz = np.array([50.])
        tb3 = np.ma.masked_array([300.], mask=False)
        tb4 = np.ma.masked_array([285.], mask=False)
        refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
        self.assertTrue(hasattr(refl, 'mask'))

        try:
            import dask.array as da
            sunz = da.from_array([50.], chunks=10)
            tb3 = da.from_array([300.], chunks=10)
            tb4 = da.from_array([285.], chunks=10)
            refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
            self.assertTrue(hasattr(refl, 'compute'))
        except ImportError:
            pass
コード例 #4
0
    def test_reflectance(self):
        """Test the derivation of the reflective part of a 3.7 micron band"""

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

            with self.assertRaises(NotImplementedError):
                dummy = Calculator('Suomi-NPP', 'viirs', 10.8)

            refl37 = Calculator('Suomi-NPP', 'viirs', 3.7)
            self.assertEqual(refl37.bandwavelength, 3.7)
            self.assertEqual(refl37.bandname, '20')

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

            refl37 = Calculator('EOS-Aqua', 'modis', '20')

        sunz = np.array([80.])
        tb3 = np.array([290.])
        tb4 = np.array([282.])
        refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
        np.testing.assert_allclose(refl[0], 0.251245010648, 6)

        tb3x = refl37.emissive_part_3x()
        np.testing.assert_allclose(tb3x, 276.213054, 6)

        sunz = np.array([80.])
        tb3 = np.array([295.])
        tb4 = np.array([282.])
        refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
        np.testing.assert_allclose(refl[0], 0.452497961, 6)

        tb3x = refl37.emissive_part_3x()
        np.testing.assert_allclose(tb3x, 270.077268, 6)

        sunz = np.array([50.])
        tb3 = np.array([300.])
        tb4 = np.array([285.])
        refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
        np.testing.assert_allclose(refl[0], 0.1189217, 6)

        tb3x = refl37.emissive_part_3x()
        np.testing.assert_allclose(tb3x, 282.455426, 6)

        sunz = np.array([50.])
        tb3 = np.ma.masked_array([300.], mask=False)
        tb4 = np.ma.masked_array([285.], mask=False)
        refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
        self.assertTrue(hasattr(refl, 'mask'))

        try:
            import dask.array as da
            sunz = da.from_array([50.], chunks=10)
            tb3 = da.from_array([300.], chunks=10)
            tb4 = da.from_array([285.], chunks=10)
            refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
            self.assertTrue(hasattr(refl, 'compute'))
        except ImportError:
            pass