当前位置: 首页>>代码示例>>Python>>正文


Python ma.masked_invalid方法代码示例

本文整理汇总了Python中numpy.ma.masked_invalid方法的典型用法代码示例。如果您正苦于以下问题:Python ma.masked_invalid方法的具体用法?Python ma.masked_invalid怎么用?Python ma.masked_invalid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy.ma的用法示例。


在下文中一共展示了ma.masked_invalid方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _contour_args

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_invalid [as 别名]
def _contour_args(self, args, kwargs):
        if self.filled:
            fn = 'contourf'
        else:
            fn = 'contour'
        Nargs = len(args)
        if Nargs <= 2:
            z = ma.asarray(args[0], dtype=np.float64)
            x, y = self._initialize_x_y(z)
            args = args[1:]
        elif Nargs <= 4:
            x, y, z = self._check_xyz(args[:3], kwargs)
            args = args[3:]
        else:
            raise TypeError("Too many arguments to %s; see help(%s)" %
                            (fn, fn))
        z = ma.masked_invalid(z, copy=False)
        self.zmax = ma.maximum(z)
        self.zmin = ma.minimum(z)
        if self.logscale and self.zmin <= 0:
            z = ma.masked_where(z <= 0, z)
            warnings.warn('Log scale: values of z <= 0 have been masked')
            self.zmin = z.min()
        self._contour_level_args(z, args)
        return (x, y, z) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:27,代码来源:contour.py

示例2: set_UVC

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_invalid [as 别名]
def set_UVC(self, U, V, C=None):
        U = ma.masked_invalid(U, copy=False).ravel()
        V = ma.masked_invalid(V, copy=False).ravel()
        mask = ma.mask_or(U.mask, V.mask, copy=False, shrink=True)
        if C is not None:
            C = ma.masked_invalid(C, copy=False).ravel()
            mask = ma.mask_or(mask, C.mask, copy=False, shrink=True)
            if mask is ma.nomask:
                C = C.filled()
            else:
                C = ma.array(C, mask=mask, copy=False)
        self.U = U.filled(1)
        self.V = V.filled(1)
        self.Umask = mask
        if C is not None:
            self.set_array(C)
        self._new_UV = True 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:quiver.py

示例3: _contour_args

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_invalid [as 别名]
def _contour_args(self, args, kwargs):
        if self.filled:
            fn = 'contourf'
        else:
            fn = 'contour'
        Nargs = len(args)
        if Nargs <= 2:
            z = ma.asarray(args[0], dtype=np.float64)
            x, y = self._initialize_x_y(z)
            args = args[1:]
        elif Nargs <= 4:
            x, y, z = self._check_xyz(args[:3], kwargs)
            args = args[3:]
        else:
            raise TypeError("Too many arguments to %s; see help(%s)" %
                            (fn, fn))
        z = ma.masked_invalid(z, copy=False)
        self.zmax = float(z.max())
        self.zmin = float(z.min())
        if self.logscale and self.zmin <= 0:
            z = ma.masked_where(z <= 0, z)
            warnings.warn('Log scale: values of z <= 0 have been masked')
            self.zmin = float(z.min())
        self._contour_level_args(z, args)
        return (x, y, z) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:27,代码来源:contour.py

示例4: set_UVC

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_invalid [as 别名]
def set_UVC(self, U, V, C=None):
        # We need to ensure we have a copy, not a reference
        # to an array that might change before draw().
        U = ma.masked_invalid(U, copy=True).ravel()
        V = ma.masked_invalid(V, copy=True).ravel()
        mask = ma.mask_or(U.mask, V.mask, copy=False, shrink=True)
        if C is not None:
            C = ma.masked_invalid(C, copy=True).ravel()
            mask = ma.mask_or(mask, C.mask, copy=False, shrink=True)
            if mask is ma.nomask:
                C = C.filled()
            else:
                C = ma.array(C, mask=mask, copy=False)
        self.U = U.filled(1)
        self.V = V.filled(1)
        self.Umask = mask
        if C is not None:
            self.set_array(C)
        self._new_UV = True
        self.stale = True 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:22,代码来源:quiver.py

示例5: set_values1d

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_invalid [as 别名]
def set_values1d(self, val, order="C"):
        """Update the values attribute based on a 1D input, multiple options.

        If values are np.nan or values are > UNDEF_LIMIT, they will be
        masked.

        Args:
            order (str): Input is C (default) or F order
        """

        if order == "F":
            val = np.copy(val, order="C")

        val = val.reshape((self.ncol, self.nrow))

        if not isinstance(val, ma.MaskedArray):
            val = ma.array(val)

        val = ma.masked_greater(val, self.undef_limit)
        val = ma.masked_invalid(val)

        self.values = val 
开发者ID:equinor,项目名称:xtgeo,代码行数:24,代码来源:regular_surface.py

示例6: smooth_median

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_invalid [as 别名]
def smooth_median(self, iterations=1, width=1):
    """Smooth a surface using a median filter.

    .. versionadded:: 2.1.0
    """

    mask = ma.getmaskarray(self.values)
    tmpv = ma.filled(self.values, fill_value=np.nan)

    for _itr in range(iterations):
        tmpv = scipy.ndimage.median_filter(tmpv, width)

    tmpv = ma.masked_invalid(tmpv)

    # seems that false areas of invalids (masked) may be made; combat that:
    self.values = tmpv
    self.fill()
    self.values = ma.array(self.values, mask=mask) 
开发者ID:equinor,项目名称:xtgeo,代码行数:20,代码来源:_regsurf_gridding.py

示例7: fit

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_invalid [as 别名]
def fit(self, X: Union[pd.DataFrame, np.ndarray], y=None):

        # Store the min/max for features in training.
        if self.strategy == "minmax":

            data = pd.DataFrame(X)  # ensure a dataframe

            # Calculate max/min allowable values
            max_allowable_value = np.finfo(data.values.dtype).max
            min_allowable_value = np.finfo(data.values.dtype).min

            # Get the max/min values in each feature, ignoring infs
            _posinf_fill_values = data.apply(lambda col: masked_invalid(col).max())
            _neginf_fill_values = data.apply(lambda col: masked_invalid(col).min())

            # Calculate a 1d arrays of fill values for each feature
            self._posinf_fill_values = _posinf_fill_values.apply(
                lambda val: val + self.delta
                if max_allowable_value - self.delta > val
                else max_allowable_value
            )
            self._neginf_fill_values = _neginf_fill_values.apply(
                lambda val: val - self.delta
                if min_allowable_value + self.delta < val
                else min_allowable_value
            )

        return self 
开发者ID:equinor,项目名称:gordo,代码行数:30,代码来源:imputer.py

示例8: infmean

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_invalid [as 别名]
def infmean(arr, axis):
    """ Compute the arithmetic mean along given axis ignoring infs,
    when there is at least one finite number along averaging axis.
    """
    masked = ma.masked_invalid(arr)
    masked = masked.mean(axis=axis)
    if np.isscalar(masked):
        return masked
    if isinstance(masked, ma.core.MaskedConstant):
        return np.inf
    masked[masked.mask] = np.inf
    return masked.data 
开发者ID:analysiscenter,项目名称:batchflow,代码行数:14,代码来源:utils.py

示例9: variation

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_invalid [as 别名]
def variation(a, axis=0, nan_policy='propagate'):
    """
    Computes the coefficient of variation, the ratio of the biased standard
    deviation to the mean.

    Parameters
    ----------
    a : array_like
        Input array.
    axis : int or None, optional
        Axis along which to calculate the coefficient of variation. Default
        is 0. If None, compute over the whole array `a`.
    nan_policy : {'propagate', 'raise', 'omit'}, optional
        Defines how to handle when input contains nan. 'propagate' returns nan,
        'raise' throws an error, 'omit' performs the calculations ignoring nan
        values. Default is 'propagate'.

    Returns
    -------
    variation : ndarray
        The calculated variation along the requested axis.

    References
    ----------
    .. [1] Zwillinger, D. and Kokoska, S. (2000). CRC Standard
       Probability and Statistics Tables and Formulae. Chapman & Hall: New
       York. 2000.

    """
    a, axis = _chk_asarray(a, axis)

    contains_nan, nan_policy = _contains_nan(a, nan_policy)

    if contains_nan and nan_policy == 'omit':
        a = ma.masked_invalid(a)
        return mstats_basic.variation(a, axis)

    return a.std(axis) / a.mean(axis) 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:40,代码来源:stats.py

示例10: _contour_args

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_invalid [as 别名]
def _contour_args(self, args, kwargs):
        if self.filled:
            fn = 'contourf'
        else:
            fn = 'contour'
        Nargs = len(args)
        if Nargs <= 2:
            z = ma.asarray(args[0], dtype=np.float64)
            x, y = self._initialize_x_y(z)
            args = args[1:]
        elif Nargs <= 4:
            x, y, z = self._check_xyz(args[:3], kwargs)
            args = args[3:]
        else:
            raise TypeError("Too many arguments to %s; see help(%s)" %
                            (fn, fn))
        z = ma.masked_invalid(z, copy=False)
        self.zmax = float(z.max())
        self.zmin = float(z.min())
        if self.logscale and self.zmin <= 0:
            z = ma.masked_where(z <= 0, z)
            cbook._warn_external('Log scale: values of z <= 0 have been '
                                 'masked')
            self.zmin = float(z.min())
        self._contour_level_args(z, args)
        return (x, y, z) 
开发者ID:boris-kz,项目名称:CogAlg,代码行数:28,代码来源:contour.py

示例11: get_xy_values

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_invalid [as 别名]
def get_xy_values(self, order="C", asmasked=False):
    """Get X Y coordinate values as numpy 2D arrays."""
    nno = self.ncol * self.nrow

    ier, xvals, yvals = _cxtgeo.surf_xy_as_values(
        self.xori,
        self.xinc,
        self.yori,
        self.yinc * self.yflip,
        self.ncol,
        self.nrow,
        self.rotation,
        nno,
        nno,
        0,
    )
    if ier != 0:
        logger.critical("Error code %s, contact the author", ier)

    # reshape
    xvals = xvals.reshape((self.ncol, self.nrow))
    yvals = yvals.reshape((self.ncol, self.nrow))

    if order == "F":
        xvals = np.array(xvals, order="F")
        yvals = np.array(yvals, order="F")

    if asmasked:
        tmpv = ma.filled(self.values, fill_value=np.nan)
        tmpv = np.array(tmpv, order=order)
        tmpv = ma.masked_invalid(tmpv)
        mymask = ma.getmaskarray(tmpv)
        xvals = ma.array(xvals, mask=mymask, order=order)
        yvals = ma.array(yvals, mask=mymask, order=order)

    return xvals, yvals 
开发者ID:equinor,项目名称:xtgeo,代码行数:38,代码来源:_regsurf_oper.py

示例12: get_values1d

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_invalid [as 别名]
def get_values1d(
        self, order="C", asmasked=False, fill_value=xtgeo.UNDEF, activeonly=False
    ):
        """Get an an 1D, numpy or masked array of the map values.

        Args:
            order (str): Flatteting is in C (default) or F order
            asmasked (bool): If true, return as MaskedArray, other as standard
                numpy ndarray with undef as np.nan or fill_value
            fill_value (str): Relevent only if asmasked is False, this
                will be the value of undef entries
            activeonly (bool): If True, only active cells. Keys 'asmasked' and
                'fill_value' are not revelant.

        Returns:
            A numpy 1D array or MaskedArray

        """

        val = self.values.copy()

        if order == "F":
            val = ma.filled(val, fill_value=np.nan)
            val = np.array(val, order="F")
            val = ma.masked_invalid(val)

        val = val.ravel(order="K")

        if activeonly:
            val = val[~val.mask]

        if not asmasked and not activeonly:
            val = ma.filled(val, fill_value=fill_value)

        return val 
开发者ID:equinor,项目名称:xtgeo,代码行数:37,代码来源:regular_surface.py


注:本文中的numpy.ma.masked_invalid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。