Beispiel #1
0
 def test_dec10216(self):
     res = dec10216(np.array([255, 255, 255, 255, 255], dtype=np.uint8))
     exp = (np.ones((4, )) * 1023).astype(np.uint16)
     self.assertTrue(np.all(res == exp))
     res = dec10216(np.array([1, 1, 1, 1, 1], dtype=np.uint8))
     exp = np.array([4, 16, 64, 257], dtype=np.uint16)
     self.assertTrue(np.all(res == exp))
Beispiel #2
0
 def test_dec10216(self):
     res = dec10216(np.array([255, 255, 255, 255, 255], dtype=np.uint8))
     exp = (np.ones((4, )) * 1023).astype(np.uint16)
     self.assertTrue(np.all(res == exp))
     res = dec10216(np.array([1, 1, 1, 1, 1], dtype=np.uint8))
     exp = np.array([4,  16,  64, 257], dtype=np.uint16)
     self.assertTrue(np.all(res == exp))
Beispiel #3
0
    def get_dataset(self, dsid, info,
                    xslice=slice(None), yslice=slice(None)):

        channel = dsid.name
        channel_list = self._channel_list

        if channel not in channel_list:
            raise KeyError('Channel % s not available in the file' % channel)
        elif channel not in ['HRV']:
            shape = (self.mda['number_of_lines'], self.mda['number_of_columns'])

            # Check if there is only 1 channel in the list as a change
            # is needed in the arrray assignment ie channl id is not present
            if len(channel_list) == 1:
                raw = self.dask_array['visir']['line_data']
            else:
                i = channel_list.index(channel)
                raw = self.dask_array['visir']['line_data'][:, i, :]

            data = dec10216(raw.flatten())
            data = da.flipud(da.fliplr((data.reshape(shape))))

        else:
            shape = (self.mda['hrv_number_of_lines'], self.mda['hrv_number_of_columns'])

            raw2 = self.dask_array['hrv']['line_data'][:, 2, :]
            raw1 = self.dask_array['hrv']['line_data'][:, 1, :]
            raw0 = self.dask_array['hrv']['line_data'][:, 0, :]

            shape_layer = (self.mda['number_of_lines'], self.mda['hrv_number_of_columns'])
            data2 = dec10216(raw2.flatten())
            data2 = da.flipud(da.fliplr((data2.reshape(shape_layer))))
            data1 = dec10216(raw1.flatten())
            data1 = da.flipud(da.fliplr((data1.reshape(shape_layer))))
            data0 = dec10216(raw0.flatten())
            data0 = da.flipud(da.fliplr((data0.reshape(shape_layer))))

            data = np.zeros(shape)
            idx = range(0, shape[0], 3)
            data[idx, :] = data2
            idx = range(1, shape[0], 3)
            data[idx, :] = data1
            idx = range(2, shape[0], 3)
            data[idx, :] = data0

        xarr = xr.DataArray(data, dims=['y', 'x']).where(data != 0).astype(np.float32)

        if xarr is None:
            dataset = None
        else:
            dataset = self.calibrate(xarr, dsid)
            dataset.attrs['units'] = info['units']
            dataset.attrs['wavelength'] = info['wavelength']
            dataset.attrs['standard_name'] = info['standard_name']
            dataset.attrs['platform_name'] = self.platform_name
            dataset.attrs['sensor'] = 'seviri'

        return dataset
Beispiel #4
0
    def get_dataset(self,
                    key,
                    info,
                    out=None,
                    xslice=slice(None),
                    yslice=slice(None)):

        if key.name not in self.channel_order_list:
            raise KeyError('Channel % s not available in the file' % key.name)
        elif key.name not in ['HRV']:
            ch_idn = self.channel_order_list.index(key.name)
            data = dec10216(
                self.memmap['visir']['line_data'][:, ch_idn, :])[::-1, ::-1]

            data = np.ma.masked_array(data, mask=(data == 0))
            res = Dataset(data, dtype=np.float32)
        else:
            data2 = dec10216(self.memmap["hrv"]["line_data"][:,
                                                             2, :])[::-1, ::-1]
            data1 = dec10216(self.memmap["hrv"]["line_data"][:,
                                                             1, :])[::-1, ::-1]
            data0 = dec10216(self.memmap["hrv"]["line_data"][:,
                                                             0, :])[::-1, ::-1]
            # Make empty array:
            shape = data0.shape[0] * 3, data0.shape[1]
            data = np.zeros(shape)
            idx = range(0, shape[0], 3)
            data[idx, :] = data2
            idx = range(1, shape[0], 3)
            data[idx, :] = data1
            idx = range(2, shape[0], 3)
            data[idx, :] = data0

            data = np.ma.masked_array(data, mask=(data == 0))
            res = Dataset(data, dtype=np.float32)

        if res is not None:
            out = res
        else:
            return None

        self.calibrate(out, key)
        out.info['units'] = info['units']
        out.info['wavelength'] = info['wavelength']
        out.info['standard_name'] = info['standard_name']
        out.info['platform_name'] = self.platform_name
        out.info['sensor'] = 'seviri'

        return out
Beispiel #5
0
 def read_band(self, key, info):
     """Read the data."""
     shape = int(np.ceil(self.mda['data_field_length'] / 8.))
     if self.mda['number_of_bits_per_pixel'] == 16:
         dtype = '>u2'
         shape //= 2
     elif self.mda['number_of_bits_per_pixel'] in [8, 10]:
         dtype = np.uint8
     shape = (shape, )
     data = np.memmap(self.filename, mode='r',
                      offset=self.mda['total_header_length'],
                      dtype=dtype,
                      shape=shape)
     data = da.from_array(data, chunks=shape[0])
     if self.mda['number_of_bits_per_pixel'] == 10:
         data = dec10216(data)
     data = data.reshape((self.mda['number_of_lines'],
                          self.mda['number_of_columns']))
     return data
Beispiel #6
0
 def read_band(self, key, info):
     """Read the data."""
     shape = int(np.ceil(self.mda['data_field_length'] / 8.))
     if self.mda['number_of_bits_per_pixel'] == 16:
         dtype = '>u2'
         shape /= 2
     elif self.mda['number_of_bits_per_pixel'] in [8, 10]:
         dtype = np.uint8
     shape = (shape, )
     data = np.memmap(self.filename, mode='r',
                      offset=self.mda['total_header_length'],
                      dtype=dtype,
                      shape=shape)
     data = da.from_array(data, chunks=shape[0])
     if self.mda['number_of_bits_per_pixel'] == 10:
         data = dec10216(data)
     data = data.reshape((self.mda['number_of_lines'],
                          self.mda['number_of_columns']))
     return data
Beispiel #7
0
    def get_dataset(self, dsid, info, xslice=slice(None), yslice=slice(None)):

        channel = dsid.name
        channel_list = self._channel_list

        if channel not in channel_list:
            raise KeyError('Channel % s not available in the file' % channel)
        elif channel not in ['HRV']:
            shape = (self.mda['number_of_lines'],
                     self.mda['number_of_columns'])

            # Check if there is only 1 channel in the list as a change
            # is needed in the arrray assignment ie channl id is not present
            if len(channel_list) == 1:
                raw = self.dask_array['visir']['line_data']
            else:
                i = channel_list.index(channel)
                raw = self.dask_array['visir']['line_data'][:, i, :]

            data = dec10216(raw.flatten())
            data = da.flipud(da.fliplr((data.reshape(shape))))

        else:
            # Upper HRV stacked directly on top of Lower HRV
            # (in actuality, these two are offset to eachother)
            shape = (self.mda['hrv_number_of_lines'],
                     self.mda['hrv_number_of_columns'])

            raw2 = self.dask_array['hrv']['line_data'][:, 2, :]
            raw1 = self.dask_array['hrv']['line_data'][:, 1, :]
            raw0 = self.dask_array['hrv']['line_data'][:, 0, :]

            shape_layer = (self.mda['number_of_lines'],
                           self.mda['hrv_number_of_columns'])
            data2 = dec10216(raw2.flatten())
            data2 = da.flipud(da.fliplr((data2.reshape(shape_layer))))
            data1 = dec10216(raw1.flatten())
            data1 = da.flipud(da.fliplr((data1.reshape(shape_layer))))
            data0 = dec10216(raw0.flatten())
            data0 = da.flipud(da.fliplr((data0.reshape(shape_layer))))

            data = np.zeros(shape)
            idx = range(0, shape[0], 3)
            data[idx, :] = data2
            idx = range(1, shape[0], 3)
            data[idx, :] = data1
            idx = range(2, shape[0], 3)
            data[idx, :] = data0

            # Full disk area (ReferenceGridHRV), with HRV-UPPER and
            # HRV-Lower embedded inside.
            # see section 3.1.5 of MSG Level 1.5 Image Data Format Description
            ref_grid = self.header['15_DATA_HEADER']['ImageDescription'][
                'ReferenceGridHRV']
            ysize = ref_grid['NumberOfLines']
            xsize = ref_grid['NumberOfColumns']
            fulldisk = np.zeros((ysize, xsize))
            hrv_coverage = self.trailer['15TRAILER']['ImageProductionStats'][
                'ActualL15CoverageHRV']
            un = ysize - hrv_coverage['UpperNorthLineActual']
            uw = xsize - hrv_coverage['UpperWestColumnActual']
            us = ysize - hrv_coverage['UpperSouthLineActual']
            ue = xsize - hrv_coverage['UpperEastColumnActual']
            fulldisk[un:us + 1, uw:ue + 1] = data[:us + 1 - un, :]
            ln = ysize - hrv_coverage['LowerNorthLineActual']
            lw = xsize - hrv_coverage['LowerWestColumnActual']
            ls = ysize - hrv_coverage['LowerSouthLineActual']
            le = xsize - hrv_coverage['LowerEastColumnActual']
            fulldisk[ln:ls + 1, lw:le + 1] = data[ln:, :]
            data = fulldisk

        xarr = xr.DataArray(data,
                            dims=['y',
                                  'x']).where(data != 0).astype(np.float32)

        if xarr is None:
            dataset = None
        else:
            dataset = self.calibrate(xarr, dsid)
            dataset.attrs['units'] = info['units']
            dataset.attrs['wavelength'] = info['wavelength']
            dataset.attrs['standard_name'] = info['standard_name']
            dataset.attrs['platform_name'] = self.platform_name
            dataset.attrs['sensor'] = 'seviri'

        return dataset