Пример #1
0
    def make_cir(self, output_filepath):
        self.log.info('Creating CIR product')

        # Get the bands - TA stand geotiff goes B G R N T
        with rasterio.open(self.input_filepath) as src:
            R, G, B = map(src.read, (4, 6, 5))

            band_count = src.count

            if band_count == 8:
                A = src.read(8)

            kwargs = src.meta

        if 'NIR' in self.contrast_bounds and 'lower' in self.contrast_bounds['NIR'] and 'upper' in self.contrast_bounds['NIR']:
            lower = self.contrast_bounds['NIR']['lower']
            upper = self.contrast_bounds['NIR']['upper']

            R = rescale_intensity_to_bounds(R, lower, upper)
            G = rescale_intensity_to_bounds(G, lower, upper)
            B = rescale_intensity_to_bounds(B, lower, upper)
        else:
            R = np.multiply(R, 10.0)
            G = np.multiply(G, 10.0)
            B = np.multiply(B, 10.0)

        R = convert_16bit_to_8bit(R)
        G = convert_16bit_to_8bit(G)
        B = convert_16bit_to_8bit(B)

        kwargs.update(dtype=np.uint8, compress='LZW', photometric='rgb')

        if band_count == 8:
            A = convert_16bit_to_8bit(A)
            kwargs.update(alpha='yes', count=4)
        else:
            kwargs.update(alpha='no', count=3)

        self.log.info('Writing file: %s', str(output_filepath))

        with rasterio.open(output_filepath, 'w', **kwargs) as dst:
            dst.write(R, 1)
            dst.write(G, 2)
            dst.write(B, 3)

            if band_count == 8:
                dst.write(A, 4)
Пример #2
0
    def make_ndvi(self, output_filepath):
        self.log.info('Creating NDVI product')

        # Get the bands - TA stand geotiff goes B G R N T
        with rasterio.open(self.input_filepath) as src:
            NIR, RED = map(src.read, (4, 6))
            band_count = src.count
            tags_dict = dict(src.tags())

            if 'NDVI_BETA' in tags_dict and 'NDVI_ALPHA' in tags_dict:
                sndvi_beta = float(tags_dict['NDVI_BETA'])
                sndvi_alpha = float(tags_dict['NDVI_ALPHA'])

            if band_count == 8:
                A = src.read(8)

            kwargs = src.meta

        ndvi = self.calculate_ndvi(RED, NIR,
                                   alpha=sndvi_alpha,
                                   beta=sndvi_beta,
                                   low=0, high=1.0)
        ndvi *= UINT8

        self.log.debug('Clipping data to 8bit as a precaution')
        ndvi = np.clip(ndvi, 0, UINT8).astype(np.uint8)

        self.log.debug('NDVI mean: %s', str(np.mean(ndvi)))
        self.log.debug('NDVI std: %s', str(np.std(ndvi)))

        kwargs.update(dtype=np.uint8, compress='LZW', photometric='rgb')

        if band_count == 8:
            A = convert_16bit_to_8bit(A)
            kwargs.update(alpha='yes', count=4)
        else:
            kwargs.update(alpha='no', count=3)

        self.log.info('Writing file: %s', str(output_filepath))

        with rasterio.open(output_filepath, 'w', **kwargs) as dst:
            dst.write(ndvi, 1)
            dst.write(ndvi, 2)
            dst.write(ndvi, 3)

            if band_count == 8:
                dst.write(A, 4)
Пример #3
0
    def make_synthetic_nc(self, out_filepath):
        self.log.info('Creating synthetic NC product')

        with rasterio.open(self.input_filepath) as src:
            B, G, R = map(src.read, (1, 2, 3))
            B2, G2, R2 = map(src.read, (4, 5, 6))

            band_count = src.count

            if band_count == 8:
                A = src.read(8)

            kwargs = src.meta

        B = np.asarray(B, dtype=np.float)
        G = np.asarray(G, dtype=np.float)
        R = np.asarray(R, dtype=np.float)

        B2 = np.asarray(B2, dtype=np.float)
        G2 = np.asarray(G2, dtype=np.float)
        R2 = np.asarray(R2, dtype=np.float)

        pan = 0.3 * R2 + 0.59 * G2 + 0.11 * R2

        del R2, G2, B2

        R, G, B = pansharpen(R, G, B, pan, method='browley', W=0.25)

        del pan

        R = np.asarray(R, dtype=np.uint16)
        G = np.asarray(G, dtype=np.uint16)
        B = np.asarray(B, dtype=np.uint16)

        if 'NIR' in self.contrast_bounds and 'lower' in self.contrast_bounds['NIR'] and 'upper' in self.contrast_bounds['NIR']:
            lower = self.contrast_bounds['NIR']['lower']
            upper = self.contrast_bounds['NIR']['upper']

            R = rescale_intensity_to_bounds(R, lower, upper)
            G = rescale_intensity_to_bounds(G, lower, upper)
            B = rescale_intensity_to_bounds(B, lower, upper)
        else:
            R = np.multiply(R, 20.0)
            G = np.multiply(G, 20.0)
            B = np.multiply(B, 20.0)

        R = convert_16bit_to_8bit(R)
        G = convert_16bit_to_8bit(G)
        B = convert_16bit_to_8bit(B)

        kwargs.update(dtype=np.uint8, compress='LZW', photometric='rgb')

        if band_count == 8:
            A = convert_16bit_to_8bit(A)
            kwargs.update(alpha='yes', count=4)
        else:
            kwargs.update(alpha='no', count=3)

        self.log.info('Writing file: %s', str(out_filepath))

        with rasterio.open(out_filepath, 'w', **kwargs) as dst:
            dst.write(R, 1)
            dst.write(G, 2)
            dst.write(B, 3)

            if band_count == 8:
                dst.write(A, 4)