當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。