class TestSeviriConversions(unittest.TestCase):
    """Testing the conversions between radiances and brightness temperatures"""
    def setUp(self):
        """Set up"""

        with patch('pyspectral.radiance_tb_conversion.RelativeSpectralResponse'
                   ) as mymock:
            instance = mymock.return_value
            instance.rsr = SEV_RSR
            instance.unit = 'cm-1'
            instance.si_scale = 100.

            self.sev1 = RadTbConverter('Meteosat-9',
                                       'seviri',
                                       'IR3.9',
                                       wavespace='wavenumber')

        self.sev2 = SeviriRadTbConverter('Meteosat-9', 'IR3.9')

    def test_rad2tb(self):
        """Unit testing the radiance to brightness temperature conversion"""
        res = self.sev1.tb2radiance(TEST_TBS, lut=False)
        self.assertTrue(np.allclose(TRUE_RADS_SEVIRI, res['radiance']))

    def test_conversion_simple(self):
        """Test the tb2radiance function to convert radiances to Tb's
        using tabulated coefficients based on a non-linear approximation

        """
        retv = self.sev2.tb2radiance(TEST_TBS)
        rads = retv['radiance']
        # Units space = wavenumber (cm-1):
        tbs = self.sev2.radiance2tb(rads)
        self.assertTrue(np.allclose(TEST_TBS, tbs))

        np.random.seed()
        tbs1 = 200.0 + np.random.random(50) * 150.0
        retv = self.sev2.tb2radiance(tbs1)
        rads = retv['radiance']
        tbs = self.sev2.radiance2tb(rads)
        self.assertTrue(np.allclose(tbs1, tbs))

    def test_conversions_methods(self):
        """Using the two diferent conversion methods to verify that they give
        approximately the same results. Conversion from Tb's to Radiances
        only
        """
        # Units space = wavenumber (cm-1):
        retv2 = self.sev2.tb2radiance(TEST_TBS)
        retv1 = self.sev1.tb2radiance(TEST_TBS)

        rads1 = retv1['radiance']
        rads2 = retv2['radiance']
        self.assertTrue(np.allclose(rads1, rads2))

    def tearDown(self):
        """Clean up"""
        pass
class TestSeviriConversions(unittest.TestCase):

    """Testing the conversions between radiances and brightness temperatures"""

    def setUp(self):
        """Set up"""

        with patch('pyspectral.radiance_tb_conversion.RelativeSpectralResponse') as mymock:
            instance = mymock.return_value
            instance.rsr = SEV_RSR
            instance.unit = 'cm-1'
            instance.si_scale = 100.

            self.sev1 = RadTbConverter('Meteosat-9', 'seviri', 'IR3.9',
                                       wavespace='wavenumber')

        self.sev2 = SeviriRadTbConverter('Meteosat-9', 'IR3.9')

    def test_rad2tb(self):
        """Unit testing the radiance to brightness temperature conversion"""
        res = self.sev1.tb2radiance(TEST_TBS, lut=False)
        self.assertTrue(np.allclose(TRUE_RADS_SEVIRI, res['radiance']))

    def test_conversion_simple(self):
        """Test the tb2radiance function to convert radiances to Tb's
        using tabulated coefficients based on a non-linear approximation

        """
        retv = self.sev2.tb2radiance(TEST_TBS)
        rads = retv['radiance']
        # Units space = wavenumber (cm-1):
        tbs = self.sev2.radiance2tb(rads)
        self.assertTrue(np.allclose(TEST_TBS, tbs))

        np.random.seed()
        tbs1 = 200.0 + np.random.random(50) * 150.0
        retv = self.sev2.tb2radiance(tbs1)
        rads = retv['radiance']
        tbs = self.sev2.radiance2tb(rads)
        self.assertTrue(np.allclose(tbs1, tbs))

    def test_conversions_methods(self):
        """Using the two diferent conversion methods to verify that they give
        approximately the same results. Conversion from Tb's to Radiances
        only
        """
        # Units space = wavenumber (cm-1):
        retv2 = self.sev2.tb2radiance(TEST_TBS)
        retv1 = self.sev1.tb2radiance(TEST_TBS)

        rads1 = retv1['radiance']
        rads2 = retv2['radiance']
        self.assertTrue(np.allclose(rads1, rads2))

    def tearDown(self):
        """Clean up"""
        pass
    def setUp(self):
        """Set up"""
        # mymock:
        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

            self.modis = RadTbConverter('EOS-Aqua', 'modis', '20')
            self.modis2 = RadTbConverter('EOS-Aqua', 'modis', 3.75)
Example #4
0
    def setUp(self):
        """Set up."""
        # mymock:
        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

            self.modis = RadTbConverter('EOS-Aqua', 'modis', '20')
            self.modis2 = RadTbConverter('EOS-Aqua', 'modis', 3.75)
Example #5
0
    def setUp(self):
        """Set up."""
        with patch('pyspectral.radiance_tb_conversion.RelativeSpectralResponse'
                   ) as mymock:
            instance = mymock.return_value
            instance.rsr = SEV_RSR
            instance.unit = 'cm-1'
            instance.si_scale = 100.

            self.sev1 = RadTbConverter('Meteosat-9',
                                       'seviri',
                                       'IR3.9',
                                       wavespace='wavenumber')

        self.sev2 = SeviriRadTbConverter('Meteosat-9', 'IR3.9')
    def setUp(self):
        """Set up"""

        with patch('pyspectral.radiance_tb_conversion.RelativeSpectralResponse') as mymock:
            instance = mymock.return_value
            instance.rsr = SEV_RSR
            instance.unit = 'cm-1'
            instance.si_scale = 100.

            self.sev1 = RadTbConverter('Meteosat-9', 'seviri', 'IR3.9',
                                       wavespace='wavenumber')

        self.sev2 = SeviriRadTbConverter('Meteosat-9', 'IR3.9')
Example #7
0
    def test_get_bandname(self, download_rsr, load, isfile, exists):
        """Test getting the band name from the wave length."""
        load.return_code = None
        download_rsr.return_code = None
        isfile.return_code = True
        exists.return_code = True

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

            with self.assertRaises(AttributeError):
                RadTbConverter('Suomi-NPP', 'viirs', 3.7)
Example #8
0
class TestRadTbConversions(unittest.TestCase):
    """Testing the conversions between radiances and brightness temperatures."""
    def setUp(self):
        """Set up."""
        # mymock:
        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

            self.modis = RadTbConverter('EOS-Aqua', 'modis', '20')
            self.modis2 = RadTbConverter('EOS-Aqua', 'modis', 3.75)

    @patch('os.path.exists')
    @patch('os.path.isfile')
    @patch('pyspectral.rsr_reader.RelativeSpectralResponse.load')
    @patch('pyspectral.rsr_reader.download_rsr')
    def test_get_bandname(self, download_rsr, load, isfile, exists):
        """Test getting the band name from the wave length."""
        load.return_code = None
        download_rsr.return_code = None
        isfile.return_code = True
        exists.return_code = True

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

            with self.assertRaises(AttributeError):
                RadTbConverter('Suomi-NPP', 'viirs', 3.7)

    def test_rad2tb(self):
        """Unit testing the radiance to brightness temperature conversion."""
        res = self.modis.tb2radiance(TEST_TBS, lut=False)
        self.assertTrue(np.allclose(TRUE_RADS, res['radiance']))

        res = self.modis2.tb2radiance(TEST_TBS, lut=False)
        self.assertTrue(np.allclose(TRUE_RADS, res['radiance']))

        rad = res['radiance']
        tbs = self.modis.radiance2tb(rad)
        self.assertTrue(np.allclose(TEST_TBS, tbs, atol=0.25))

        res = self.modis.tb2radiance(TEST_TBS, lut=False, normalized=False)
        integral = self.modis.rsr_integral
        self.assertTrue(np.allclose(TRUE_RADS * integral, res['radiance']))

        res = self.modis.tb2radiance(237., lut=False)
        self.assertAlmostEqual(16570.579551068, res['radiance'])

        res = self.modis.tb2radiance(277., lut=False)
        self.assertAlmostEqual(167544.39368663222, res['radiance'])

        res = self.modis.tb2radiance(1.1, lut=False)
        self.assertAlmostEqual(0.0, res['radiance'])

        res = self.modis.tb2radiance(11.1, lut=False)
        self.assertAlmostEqual(0.0, res['radiance'])

        res = self.modis.tb2radiance(100.1, lut=False)
        self.assertAlmostEqual(5.3940515573e-06, res['radiance'])

        res = self.modis.tb2radiance(200.1, lut=False)
        self.assertAlmostEqual(865.09759706, res['radiance'])

    def tearDown(self):
        """Clean up."""
        pass
class TestRadTbConversions(unittest.TestCase):

    """Testing the conversions between radiances and brightness temperatures"""

    def setUp(self):
        """Set up"""
        # mymock:
        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

            self.modis = RadTbConverter('EOS-Aqua', 'modis', '20')
            self.modis2 = RadTbConverter('EOS-Aqua', 'modis', 3.75)

    @patch('os.path.exists')
    @patch('os.path.isfile')
    @patch('pyspectral.rsr_reader.RelativeSpectralResponse.load')
    @patch('pyspectral.rsr_reader.download_rsr')
    def test_get_bandname(self, download_rsr, load, isfile, exists):
        """Test getting the band name from the wave length
        """
        load.return_code = None
        download_rsr.return_code = None
        isfile.return_code = True
        exists.return_code = True

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

            with self.assertRaises(AttributeError):
                _ = RadTbConverter('Suomi-NPP', 'viirs', 3.7)

    def test_rad2tb(self):
        """Unit testing the radiance to brightness temperature conversion"""
        res = self.modis.tb2radiance(TEST_TBS, lut=False)
        self.assertTrue(np.allclose(TRUE_RADS, res['radiance']))

        res = self.modis2.tb2radiance(TEST_TBS, lut=False)
        self.assertTrue(np.allclose(TRUE_RADS, res['radiance']))

        rad = res['radiance']
        tbs = self.modis.radiance2tb(rad)
        self.assertTrue(np.allclose(TEST_TBS, tbs, atol=0.25))

        res = self.modis.tb2radiance(TEST_TBS, lut=False, normalized=False)
        integral = self.modis.rsr_integral
        self.assertTrue(np.allclose(TRUE_RADS * integral, res['radiance']))

        res = self.modis.tb2radiance(237., lut=False)
        self.assertAlmostEqual(16570.592171157, res['radiance'])

        res = self.modis.tb2radiance(277., lut=False)
        self.assertAlmostEqual(167544.3823631, res['radiance'])

        res = self.modis.tb2radiance(1.1, lut=False)
        self.assertAlmostEqual(0.0, res['radiance'])

        res = self.modis.tb2radiance(11.1, lut=False)
        self.assertAlmostEqual(0.0, res['radiance'])

        res = self.modis.tb2radiance(100.1, lut=False)
        self.assertAlmostEqual(5.3940515573e-06, res['radiance'])

        res = self.modis.tb2radiance(200.1, lut=False)
        self.assertAlmostEqual(865.09776189, res['radiance'])

    def tearDown(self):
        """Clean up"""
        pass