Пример #1
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"
        corr = 1

        channel = 0

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

        channel = 1

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

        channel = 2

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

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

        expected = (np.array([[-5.300497, 60.891074, 126.953364],
                              [0., 14.091565, 85.195791]]),
                    np.array([[-6.353052, 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])
Пример #2
0
    def get_calibrated_channels(self):
        """Calibrate and return the channels."""
        channels = self.get_counts()
        self.get_times()
        self.update_meta_data()
        year = self.times[0].year
        delta = self.times[0].date() - datetime.date(year, 1, 1)
        jday = delta.days + 1

        corr = self.meta_data['sun_earth_distance_correction_factor']

        # 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
Пример #3
0
    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
Пример #4
0
    def get_dataset(self, key, info):
        """Get the dataset."""
        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)