def stretch_logarithmic(self, factor=100.):
        """Move data into range [1:factor] through normalized logarithm."""
        logger.debug("Perform a logarithmic contrast stretch.")
        crange = (0., 1.0)

        b__ = float(crange[1] - crange[0]) / np.log(factor)
        c__ = float(crange[0])

        def _band_log(arr):
            slope = (factor - 1.) / float(arr.max() - arr.min())
            arr = 1. + (arr - arr.min()) * slope
            arr = c__ + b__ * da.log(arr)
            return arr

        band_results = []
        for band in self.data['bands'].values:
            if band == 'A':
                continue
            band_data = self.data.sel(bands=band)
            res = _band_log(band_data.data)
            band_results.append(res)

        if 'A' in self.data.coords['bands'].values:
            band_results.append(self.data.sel(bands='A'))
        self.data.data = da.stack(band_results,
                                  axis=self.data.dims.index('bands'))
def stretch_logarithmic ( self , factor = 100. ) : logger . debug ( "Perform a logarithmic contrast stretch." ) crange = ( 0. , 1.0 ) b__ = float ( crange [ 1 ] - crange [ 0 ] ) / np . log ( factor ) c__ = float ( crange [ 0 ] ) def _band_log ( arr ) : slope = ( factor - 1. ) / float ( arr . max ( ) - arr . min ( ) ) arr = 1. + ( arr - arr . min ( ) ) * slope arr = c__ + b__ * da . log ( arr ) return arr band_results = [ ] for band in self . data [ 'bands' ] . values : if band == 'A' : continue band_data = self . data . sel ( bands = band ) res = _band_log ( band_data . data ) band_results . append ( res ) if 'A' in self . data . coords [ 'bands' ] . values : band_results . append ( self . data . sel ( bands = 'A' ) ) self . data . data = da . stack ( band_results , axis = self . data . dims . index ( 'bands' ) )
Move data into range [1:factor] through normalized logarithm.