def test_read_coeffs_warnings(self):
     """Test warnings issued by Calibrator.read_coeffs."""
     version_dicts = [
         # Non-nominal coefficients
         {'name': 'v123',
          'status': CoeffStatus.PROVISIONAL},
         # Unknown coefficients
         {'name': None,
          'status': None}
     ]
     with mock.patch.object(Calibrator, 'version_hashs') as version_hashs:
         for version_dict in version_dicts:
             version_hashs.get.return_value = version_dict
             with self.assertWarns(RuntimeWarning):
                 Calibrator.read_coeffs(None)
Example #2
0
    def test_user_coefficients_file(self):
        if sys.version_info.major < 3:
            cal = Calibrator('noaa19', coeffs_file="/path/to/unknow/defaults.json")
        else:
            with self.assertWarnsRegex(RuntimeWarning,
                                       "Unknown calibration coefficients version!"):
                cal = Calibrator('noaa19', coeffs_file="/path/to/unknow/defaults.json")

        self.assertEqual(cal.dark_count[0], 0)
        self.assertEqual(cal.gain_switch[0], 1000)
        self.assertEqual(cal.s0[0], 2)
        self.assertEqual(cal.s1[0], 0)
        self.assertEqual(cal.s2[0], 0)
        # check that the version is set to None if an unknown file is used
        if sys.version_info.major > 2:
            self.assertIsNone(cal.version)
Example #3
0
 def calibration(self):
     """Get the property 'calibration'."""
     calibration = Calibrator(
         self.spacecraft_name,
         custom_coeffs=self.custom_calibration,
         coeffs_file=self.calibration_file
     )
     return calibration
Example #4
0
 def test_vis_deprecation_warning(self):
     counts = np.arange(10)
     year = 2010
     jday = 1
     spacecraft_id = "noaa19"
     channel = 0
     corr = 2
     message = (
         "Using the 'corr' argument is depricated in favor of making the units"
         " of the function result clear. Please make any unit conversion outside this function."
     )
     cal = Calibrator(spacecraft_id)
     with self.assertWarnsRegex(DeprecationWarning, message):
         calibrate_solar(counts, channel, year, jday, cal, corr=corr)
     # check that the version is set in this case
     self.assertIsNotNone(cal.version)
Example #5
0
    def test_calibration_vis(self):

        counts = np.array([[
            0, 0, 0, 0, 0, 512, 512, 512, 512, 512, 1023, 1023, 1023, 1023,
            1023
        ],
                           [
                               41, 41, 41, 41, 41, 150, 150, 150, 150, 150,
                               700, 700, 700, 700, 700
                           ]])
        year = 1997
        jday = 196
        spacecraft_id = "noaa14"
        cal = Calibrator(spacecraft_id)
        corr = 1

        channel = 0

        ref1 = calibrate_solar(counts[:, channel::5], channel, year, jday, cal,
                               corr)

        channel = 1

        ref2 = calibrate_solar(counts[:, channel::5], channel, year, jday, cal,
                               corr)

        channel = 2

        data = np.ma.array(counts[:, channel::5], mask=True)

        ref3 = calibrate_solar(data, channel, year, jday, cal, corr)

        expected = (np.array([[np.nan, 60.891074, 126.953364],
                              [0., 14.091565, 85.195791]]),
                    np.array([[np.nan, 72.98262, 152.16334],
                              [0., 16.889821, 102.113687]]),
                    np.array([[-32001., -32001., -32001.],
                              [-32001., -32001., -32001.]]))

        np.testing.assert_allclose(ref1, expected[0])
        np.testing.assert_allclose(ref2, expected[1])
        np.testing.assert_allclose(ref3.filled(-32001), expected[2])
Example #6
0
    def test_calibration_vis(self):

        counts = np.array([[
            0, 0, 0, 0, 0, 512, 512, 512, 512, 512, 1023, 1023, 1023, 1023,
            1023
        ],
                           [
                               41, 41, 41, 41, 41, 150, 150, 150, 150, 150,
                               700, 700, 700, 700, 700
                           ]])
        year = 2010
        jday = 1
        spacecraft_id = "noaa19"
        cal = Calibrator(spacecraft_id)
        corr = 1
        channel = 0

        ref1 = calibrate_solar(counts[:, channel::5], channel, year, jday, cal,
                               corr)

        channel = 1

        ref2 = calibrate_solar(counts[:, channel::5], channel, year, jday, cal,
                               corr)

        channel = 2

        data = np.ma.array(counts[:, channel::5], mask=True)

        ref3 = calibrate_solar(data, channel, year, jday, cal, corr)

        expected = (np.array([[np.nan, 27.37909518, 110.60103456],
                              [0.11943135, 6.03671211, 57.99695154]]),
                    np.array([[np.nan, 3.05229160e+01, 1.24811455e+02],
                              [1.23011792e-01, 6.82715447e+00,
                               6.52122414e+01]]),
                    np.array([[0., 523.41775, 1034.41775],
                              [41., 150., 711.41775]]))
        np.testing.assert_allclose(ref1, expected[0])
        np.testing.assert_allclose(ref2, expected[1])
        np.testing.assert_allclose(ref3, expected[2])
Example #7
0
 def test_custom_coefficients(self):
     custom_coeffs = {
         "channel_1": {
             "dark_count": 0,
             "gain_switch": 1000,
             "s0": 2,
             "s1": 0,
             "s2": 0
         }
     }
     # The coefficients are choosen to preserve the counts of channel 1 if counts are less than 1000
     counts = np.arange(10)
     year = 2010
     jday = 1
     spacecraft_id = "noaa19"
     channel = 0
     cal = Calibrator(spacecraft_id, custom_coeffs=custom_coeffs)
     scaled_radiance = calibrate_solar(counts, channel, year, jday, cal)
     np.testing.assert_allclose(scaled_radiance, counts)
     # check that the version is set to None if custom coeffs are used
     if sys.version_info.major > 2:
         self.assertIsNone(cal.version)
Example #8
0
 def calibrator(self):
     """Create a calibrator for the data."""
     from pygac.calibration import Calibrator
     pg_spacecraft = ''.join(self.platform_name.split()).lower()
     return Calibrator(pg_spacecraft)
Example #9
0
    def test_calibration_ir(self):
        counts = np.array([[0, 0, 612, 0, 0,
                            512, 512, 487, 512, 512,
                            923, 923, 687, 923, 923],
                           [41, 41, 634, 41, 41,
                            150, 150, 461, 150, 150,
                            700, 700, 670, 700, 700],
                           [241, 241, 656, 241, 241,
                            350, 350, 490, 350, 350,
                            600, 600, 475, 600, 600]])
        prt_counts = np.array([0, 230, 230])
        ict_counts = np.array([[745.3, 397.9, 377.8],
                               [744.8, 398.1, 378.4],
                               [745.7, 398., 378.3]])
        space_counts = np.array([[987.3,  992.5,  989.4],
                                 [986.9,  992.8,  989.6],
                                 [986.3,  992.3,  988.9]])

        spacecraft_id = "noaa14"
        cal = Calibrator(spacecraft_id)
        ch3 = calibrate_thermal(counts[:, 2::5],
                                prt_counts,
                                ict_counts[:, 0],
                                space_counts[:, 0],
                                line_numbers=np.array([1, 2, 3]),
                                channel=3,
                                cal=cal)

        expected_ch3 = np.array([[298.28466, 305.167571, 293.16182],
                                 [296.878502, 306.414234, 294.410224],
                                 [295.396779, 305.020259, 305.749526]])

        np.testing.assert_allclose(expected_ch3, ch3)

        ch4 = calibrate_thermal(counts[:, 3::5],
                                prt_counts,
                                ict_counts[:, 1],
                                space_counts[:, 1],
                                line_numbers=np.array([1, 2, 3]),
                                channel=4,
                                cal=cal)

        expected_ch4 = np.array([[325.828062, 275.414804, 196.214709],
                                 [322.359517, 312.785057, 249.380649],
                                 [304.326806, 293.490822, 264.148021]])

        np.testing.assert_allclose(expected_ch4, ch4)

        ch5 = calibrate_thermal(counts[:, 4::5],
                                prt_counts,
                                ict_counts[:, 2],
                                space_counts[:, 2],
                                line_numbers=np.array([1, 2, 3]),
                                channel=5,
                                cal=cal)

        expected_ch5 = np.array([[326.460316, 272.146547, 187.434456],
                                 [322.717606, 312.388155, 244.241633],
                                 [303.267012, 291.590832, 260.05426]])

        np.testing.assert_allclose(expected_ch5, ch5)
 def test_default_coeffs(self):
     """Test identification of default coefficients."""
     _, version = Calibrator.read_coeffs(None)
     self.assertIsNotNone(version)
Example #11
0
    def test_calibration_ir(self):
        counts = np.array([[
            0, 0, 612, 0, 0, 512, 512, 487, 512, 512, 923, 923, 687, 923, 923
        ],
                           [
                               41, 41, 634, 41, 41, 150, 150, 461, 150, 150,
                               700, 700, 670, 700, 700
                           ],
                           [
                               241, 241, 656, 241, 241, 350, 350, 490, 350,
                               350, 600, 600, 475, 600, 600
                           ]])
        prt_counts = np.array([0, 230, 230])
        ict_counts = np.array([[745.3, 397.9, 377.8], [744.8, 398.1, 378.4],
                               [745.7, 398., 378.3]])
        space_counts = np.array([[987.3, 992.5, 989.4], [986.9, 992.8, 989.6],
                                 [986.3, 992.3, 988.9]])

        spacecraft_id = "noaa19"
        cal = Calibrator(spacecraft_id)
        ch3 = calibrate_thermal(counts[:, 2::5],
                                prt_counts,
                                ict_counts[:, 0],
                                space_counts[:, 0],
                                line_numbers=np.array([1, 2, 3]),
                                channel=3,
                                cal=cal)

        expected_ch3 = np.array([[298.36742, 305.248478, 293.238328],
                                 [296.960275, 306.493766, 294.488956],
                                 [295.476935, 305.101309, 305.829827]])

        np.testing.assert_allclose(expected_ch3, ch3)

        ch4 = calibrate_thermal(counts[:, 3::5],
                                prt_counts,
                                ict_counts[:, 1],
                                space_counts[:, 1],
                                line_numbers=np.array([1, 2, 3]),
                                channel=4,
                                cal=cal)

        expected_ch4 = np.array([[326.576534, 275.348988, 197.688755],
                                 [323.013104, 313.207077, 249.36352],
                                 [304.58091, 293.579308, 264.0631]])

        np.testing.assert_allclose(expected_ch4, ch4)

        ch5 = calibrate_thermal(counts[:, 4::5],
                                prt_counts,
                                ict_counts[:, 2],
                                space_counts[:, 2],
                                line_numbers=np.array([1, 2, 3]),
                                channel=5,
                                cal=cal)

        expected_ch5 = np.array([[326.96161, 272.090164, 188.267991],
                                 [323.156317, 312.673269, 244.184452],
                                 [303.439383, 291.649444, 259.973091]])

        np.testing.assert_allclose(expected_ch5, ch5)