示例#1
0
    def process(self, cube):
        """
        Identify the probability of having a phenomenon occur within a
        vicinity.

        The steps for this are as follows:
            1.   Calculate the occurrence of a phenomenon within
                 a defined vicinity.
            2.   If the cube contains a realization dimension coordinate,
                 find the mean.
            3.   Compute neighbourhood processing.

        Args:
            cube (iris.cube.Cube):
                A cube that has been thresholded.

        Returns:
            cube (iris.cube.Cube):
                A cube containing neighbourhood probabilities to represent the
                probability of an occurrence within the vicinity given a
                pre-defined spatial uncertainty.

        """
        cube = OccurrenceWithinVicinity(self.distance).process(cube)
        try:
            if cube.coord_dims('realization'):
                ens_members = cube.coord('realization').points
                # BUG in iris: collapsed returns a masked cube regardless of
                # input status.  If input is not masked, output mask does not
                # match data.  Fix is to re-cast output to an unmasked array.
                cube_is_masked = isinstance(cube.data, np.ma.MaskedArray)
                cube = cube.collapsed('realization', iris.analysis.MEAN)
                if not cube_is_masked:
                    cube.data = np.array(cube.data)
                cube.remove_coord('realization')
                cube.attributes['source_realizations'] = ens_members
        except iris.exceptions.CoordinateNotFoundError:
            pass

        cube = NeighbourhoodProcessing(
            self.neighbourhood_method,
            self.radii,
            lead_times=self.lead_times,
            weighted_mode=self.weighted_mode,
            ens_factor=self.ens_factor).process(cube)

        cube.rename(cube.name() + '_in_vicinity')
        return cube
示例#2
0
    def process(self, cube):
        """
        Identify the probability of having a phenomenon occur within a
        vicinity.

        The steps for this are as follows:
            1.   Calculate the occurrence of a phenomenon within
                 a defined vicinity.
            2.   If the cube contains a realization dimension coordinate,
                 find the mean.
            3.   Compute neighbourhood processing.

        Args:
            cube (iris.cube.Cube):
                A cube that has been thresholded.

        Returns:
            cube (iris.cube.Cube):
                A cube containing neighbourhood probabilities to represent the
                probability of an occurrence within the vicinity given a
                pre-defined spatial uncertainty.

        """
        cube = OccurrenceWithinVicinity(self.distance).process(cube)
        try:
            if cube.coord_dims('realization'):
                ens_members = cube.coord('realization').points
                cube = cube.collapsed('realization', iris.analysis.MEAN)
                cube.remove_coord('realization')
                cube.attributes['source_realizations'] = ens_members
        except iris.exceptions.CoordinateNotFoundError:
            pass

        cube = NeighbourhoodProcessing(
            self.neighbourhood_method, self.radii,
            lead_times=self.lead_times,
            weighted_mode=self.weighted_mode,
            ens_factor=self.ens_factor).process(cube)
        cube.rename(cube.name() + '_in_vicinity')
        return cube