コード例 #1
0
ファイル: _interpolator.py プロジェクト: SGPeckham/iris
    def __init__(self, src_grid_cube, target_grid_cube,
                 extrapolation_mode='linear'):
        """
        Create a linear regridder for conversions between the source
        and target grids.

        Args:

        * src_grid_cube:
            The :class:`~iris.cube.Cube` providing the source grid.
        * target_grid_cube:
            The :class:`~iris.cube.Cube` providing the target grid.

        Kwargs:

        * extrapolation_mode:
            Must be one of the following strings:

              * 'linear' - The extrapolation points will be calculated by
                extending the gradient of closest two points.
              * 'nan' - The extrapolation points will be be set to NaN.
              * 'error' - An exception will be raised, notifying an
                attempt to extrapolate.
              * 'mask' - The extrapolation points will always be masked, even
                if the source data is not a MaskedArray.
              * 'nanmask' - If the source data is a MaskedArray the
                extrapolation points will be masked. Otherwise they will be
                set to NaN.

            Default mode of extrapolation is 'linear'

        """
        # Snapshot the state of the cubes to ensure that the regridder
        # is impervious to external changes to the original source cubes.
        self._src_grid = eregrid._snapshot_grid(src_grid_cube)
        self._target_grid = eregrid._snapshot_grid(target_grid_cube)
        # The extrapolation mode.
        if extrapolation_mode not in _LINEAR_EXTRAPOLATION_MODES:
            msg = 'Extrapolation mode {!r} not supported.'
            raise ValueError(msg.format(extrapolation_mode))
        self._extrapolation_mode = extrapolation_mode

        # The need for an actual Cube is an implementation quirk
        # caused by the current usage of the experimental regrid
        # function.
        self._target_grid_cube_cache = None
コード例 #2
0
ファイル: _area_weighted.py プロジェクト: SGPeckham/iris
    def __init__(self, src_grid_cube, target_grid_cube, mdtol=0):
        """
        Create an area-weighted regridder for conversions between the source
        and target grids.

        Args:

        * src_grid_cube:
            The :class:`~iris.cube.Cube` providing the source grid.
        * target_grid_cube:
            The :class:`~iris.cube.Cube` providing the target grid.

        Kwargs:

        * mdtol (float):
            Tolerance of missing data. The value returned in each element of
            the returned array will be masked if the fraction of masked data
            exceeds mdtol. mdtol=0 means no missing data is tolerated while
            mdtol=1 will mean the resulting element will be masked if and only
            if all the contributing elements of data are masked.
            Defaults to 0.

        """
        # Snapshot the state of the cubes to ensure that the regridder is
        # impervious to external changes to the original source cubes.
        self._src_grid = eregrid._snapshot_grid(src_grid_cube)
        self._target_grid = eregrid._snapshot_grid(target_grid_cube)
        # Missing data tolerance.
        msg = 'Value for mdtol must be in range 0 - 1, got {}.'
        if mdtol < 0 or mdtol > 1:
            raise ValueError(msg.format(mdtol))
        self._mdtol = mdtol

        # The need for an actual Cube is an implementation quirk caused by the
        # current usage of the experimental regrid function.
        self._target_grid_cube_cache = None