Ejemplo n.º 1
0
        def compute(self, data):
            """
            :param xarray.Dataset data:
            :return: xarray.Dataset
            """
            # We need to reshape our data into Y, X, Band, Time

            squashed_together_dimensions, normal_datacube_dimensions = self._vars_to_transpose(
                data)

            squashed = data.to_array(dim='variable').transpose(
                *squashed_together_dimensions)
            assert squashed.dims == squashed_together_dimensions

            # Grab a copy of the coordinates we need for creating the output DataArray
            output_coords = copy(squashed.coords)
            if 'time' in output_coords:
                del output_coords['time']
            if 'source' in output_coords:
                del output_coords['source']

            # Call Dale's function here
            squashed = gmpcm(squashed.data, num_threads=self.num_threads)
            all_zeros = (squashed == 0.).all(axis=-1)
            squashed[all_zeros] = np.nan

            # Jam the raw numpy array back into a pleasantly labelled DataArray
            output_dims = squashed_together_dimensions[:-1]
            as_datarray = xarray.DataArray(squashed,
                                           dims=output_dims,
                                           coords=output_coords)

            return as_datarray.transpose(
                *normal_datacube_dimensions).to_dataset(dim='variable')
Ejemplo n.º 2
0
        def compute(self, data):
            """
            :param xarray.Dataset data:
            :return: xarray.Dataset
            """

            # We need to reshape our data into Y, X, Band, Time
            squashed_together_dimensions, output_dimensions = self._vars_to_transpose(
                data)

            squashed = data.to_array(dim='variable').transpose(
                *squashed_together_dimensions)
            assert squashed.dims == squashed_together_dimensions

            # Grab a copy of the coordinates we need for creating the output DataArray
            output_coords = copy(squashed.coords)
            if 'variable' in output_coords:
                del output_coords['variable']
            if 'time' in output_coords:
                del output_coords['time']
            if 'source' in output_coords:
                del output_coords['source']

            # Call Dale's geometric median & spectral mad functions here
            gm = pcm.gmpcm(squashed.data)
            squashed = pcm.smad(squashed.data, gm)

            # Jam the raw numpy array back into a pleasantly labelled DataArray
            as_datarray = xarray.DataArray(squashed,
                                           dims=output_dimensions,
                                           coords=output_coords)

            return as_datarray.transpose(*output_dimensions).to_dataset(
                name='smad')