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" ch3 = calibrate_thermal(counts[:, 2::5], prt_counts, ict_counts[:, 0], space_counts[:, 0], line_numbers=np.array([1, 2, 3]), channel=3, spacecraft=spacecraft_id) expected_ch3 = np.array([[298.28524223, 305.16852862, 293.16212655], [296.87900835, 306.41526012, 294.41059746], [295.39720547, 305.02120845, 305.75051609]]) 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, spacecraft=spacecraft_id) expected_ch4 = np.array([[325.828192, 275.414762, 196.214464], [322.359634, 312.785138, 249.380531], [304.326858, 293.490837, 264.147945]]) 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, spacecraft=spacecraft_id) expected_ch5 = np.array([[326.47287181, 272.14169523, 187.40907142], [322.72885806, 312.39588991, 244.22910864], [303.27173737, 291.59183911, 260.0459766]]) np.testing.assert_allclose(expected_ch5, ch5)
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" ch3 = calibrate_thermal(counts[:, 2::5], prt_counts, ict_counts[:, 0], space_counts[:, 0], line_numbers=np.array([1, 2, 3]), channel=3, spacecraft=spacecraft_id) expected_ch3 = np.array([[298.28524223, 305.16852862, 293.16212655], [296.87900835, 306.41526012, 294.41059746], [295.39720547, 305.02120845, 305.75051609]]) 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, spacecraft=spacecraft_id) expected_ch4 = np.array([[325.828192, 275.414762, 196.214464], [322.359634, 312.785138, 249.380531], [304.326858, 293.490837, 264.147945]]) 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, spacecraft=spacecraft_id) expected_ch5 = np.array([[326.47287181, 272.14169523, 187.40907142], [322.72885806, 312.39588991, 244.22910864], [303.27173737, 291.59183911, 260.0459766]]) np.testing.assert_allclose(expected_ch5, ch5)
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" ch3 = calibrate_thermal(counts[:, 2::5], prt_counts, ict_counts[:, 0], space_counts[:, 0], line_numbers=np.array([1, 2, 3]), channel=3, spacecraft=spacecraft_id) expected_ch3 = np.array([[298.36772477, 305.24899954, 293.23847375], [296.96053595, 306.49432811, 294.48914038], [295.47715016, 305.10182601, 305.83036782]]) 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, spacecraft=spacecraft_id) expected_ch4 = np.array([[326.57669548, 275.34893211, 197.68844955], [323.01324859, 313.20717645, 249.3633716], [304.58097221, 293.57932356, 264.0630027]]) 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, spacecraft=spacecraft_id) expected_ch5 = np.array([[326.96168274, 272.09013413, 188.26784127], [323.15638147, 312.67331324, 244.18437795], [303.43940924, 291.64944851, 259.97304154]]) np.testing.assert_allclose(expected_ch5, ch5)
def get_dataset(self, key, info): if self._data is None: self.read() if key.name in ['latitude', 'longitude']: lons, lats = self.get_lonlats() if key.name == 'latitude': return Dataset(lats, id=key) else: return Dataset(lons, id=key) avhrr_channel_index = {'1': 0, '2': 1, '3a': 2, '3b': 2, '4': 3, '5': 4} index = avhrr_channel_index[key.name] mask = False if key.name in ['3a', '3b'] and self._is3b is None: ch3a = bfield(self._data["id"]["id"], 10) self._is3b = np.logical_not(ch3a) if key.name == '3a': mask = np.tile(self._is3b, (1, 2048)) elif key.name == '3b': mask = np.tile(np.logical_not(self._is3b), (1, 2048)) data = self._data["image_data"][:, :, index] if key.calibration == 'counts': return Dataset(data, mask=mask, area=self.get_lonlats(), units='1') pg_spacecraft = ''.join(self.platform_name.split()).lower() jdays = (np.datetime64(self.start_time) - np.datetime64(str( self.year) + '-01-01T00:00:00Z')) / np.timedelta64(1, 'D') if index < 2 or key.name == '3a': data = calibrate_solar(data, index, self.year, jdays, pg_spacecraft) units = '%' if index > 2 or key.name == '3b': if self.times is None: self.times = time_seconds(self._data["timecode"], self.year) line_numbers = ( np.round((self.times - self.times[-1]) / np.timedelta64(166666667, 'ns'))).astype(np.int) line_numbers -= line_numbers[0] if self.prt is None: self.prt, self.ict, self.space = self.get_telemetry() chan = index + 1 data = calibrate_thermal(data, self.prt, self.ict[:, chan - 3], self.space[:, chan - 3], line_numbers, chan, pg_spacecraft) units = 'K' # TODO: check if entirely masked before returning return Dataset(data, mask=mask, units=units)
def calibrate_thermal_channel(self, data, key): """Calibrate a thermal channel.""" from pygac.calibration import calibrate_thermal line_numbers = (np.round((self.times - self.times[-1]) / np.timedelta64(166666667, 'ns'))).astype(int) line_numbers -= line_numbers[0] prt, ict, space = self.telemetry index = _get_channel_index(key) data = calibrate_thermal(data, prt, ict[:, index - 2], space[:, index], line_numbers, index + 1, self.calibrator) return data
def get_calibrated_channels(self): """Calibrate and return the channels.""" channels = self.get_counts() times = self.times self.get_times() self.update_meta_data() year = times[0].year delta = times[0].date() - datetime.date(year, 1, 1) jday = delta.days + 1 corr = self.meta_data['sun_earth_distance_correction_factor'] calibration_coeffs = self.calibration # how many reflective channels are there ? tot_ref = channels.shape[2] - 3 channels[:, :, 0:tot_ref] = calibrate_solar( channels[:, :, 0:tot_ref], np.arange(tot_ref), year, jday, calibration_coeffs, corr ) prt, ict, space = self.get_telemetry() for chan in [3, 4, 5]: channels[:, :, chan - 6] = calibrate_thermal( channels[:, :, chan - 6], prt, ict[:, chan - 3], space[:, chan - 3], self.scans["scan_line_number"], chan, calibration_coeffs ) # Mask out corrupt values channels[self.mask] = np.nan # Apply KLM/POD specific postprocessing self.postproc(channels) # Mask pixels affected by scan motor issue if self.is_tsm_affected(): LOG.info('Correcting for temporary scan motor issue') self.mask_tsm_pixels(channels) return channels
def get_calibrated_channels(self): channels = self.get_counts() self.get_times() year = self.times[0].year delta = self.times[0].date() - datetime.date(year, 1, 1) jday = delta.days + 1 # Earth-Sun distance correction factor corr = 1.0 - 0.0334 * np.cos(2.0 * np.pi * (jday - 2) / 365.25) # how many reflective channels are there ? tot_ref = channels.shape[2] - 3 channels[:, :, 0:tot_ref] = calibrate_solar(channels[:, :, 0:tot_ref], np.arange(tot_ref), year, jday, self.spacecraft_name, corr) prt, ict, space = self.get_telemetry() for chan in [3, 4, 5]: channels[:, :, chan - 6] = calibrate_thermal( channels[:, :, chan - 6], prt, ict[:, chan - 3], space[:, chan - 3], self.scans["scan_line_number"], chan, self.spacecraft_name) return channels
def get_calibrated_channels(self): channels = self.get_counts() self.get_times() year = self.times[0].year delta = self.times[0].date() - datetime.date(year, 1, 1) jday = delta.days + 1 # Earth-Sun distance correction factor corr = 1.0 - 0.0334 * np.cos(2.0 * np.pi * (jday - 2) / 365.25) # how many reflective channels are there ? tot_ref = channels.shape[2] - 3 channels[:, :, 0:tot_ref] = calibrate_solar(channels[:, :, 0:tot_ref], np.arange(tot_ref), year, jday, self.spacecraft_name, corr) prt, ict, space = self.get_telemetry() for chan in [3, 4, 5]: channels[:, :, chan - 6] = calibrate_thermal( channels[:, :, chan - 6], prt, ict[:, chan - 3], space[:, chan - 3], self.scans["scan_line_number"], chan, self.spacecraft_name) # Mask out corrupt values channels[self.mask] = np.nan # Apply KLM/POD specific postprocessing self.postproc(channels) # Mask pixels affected by scan motor issue if self.is_tsm_affected(): LOG.info('Correcting for temporary scan motor issue') self.mask_tsm_pixels(channels) return channels
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_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)