本文整理汇总了Python中numpy.ma.masked_greater方法的典型用法代码示例。如果您正苦于以下问题:Python ma.masked_greater方法的具体用法?Python ma.masked_greater怎么用?Python ma.masked_greater使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.ma
的用法示例。
在下文中一共展示了ma.masked_greater方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_values1d
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_greater [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
示例2: test_assign
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_greater [as 别名]
def test_assign():
"""Create a simple property and assign all values a constant"""
vals = np.array(range(12)).reshape((3, 2, 2))
x = GridProperty(ncol=3, nrow=2, nlay=2, values=vals)
# shall be a maskedarray although input is a np array:
assert isinstance(x.values, npma.core.MaskedArray)
assert x.values.mean() == 5.5
x.values = npma.masked_greater(x.values, 5)
assert x.values.mean() == 2.5
# this shall now broadcast the value 33 to all activecells
x.isdiscrete = True
x.values = 33
assert x.dtype == np.int32
x.isdiscrete = False
x.values = 44.0221
assert x.dtype == np.float64
示例3: mask_to_limits
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_greater [as 别名]
def mask_to_limits(a, limits, inclusive):
"""Mask an array for values outside of given limits.
This is primarily a utility function.
Parameters
----------
a : array
limits : (float or None, float or None)
A tuple consisting of the (lower limit, upper limit). Values in the
input array less than the lower limit or greater than the upper limit
will be masked out. None implies no limit.
inclusive : (bool, bool)
A tuple consisting of the (lower flag, upper flag). These flags
determine whether values exactly equal to lower or upper are allowed.
Returns
-------
A MaskedArray.
Raises
------
A ValueError if there are no values within the given limits.
"""
lower_limit, upper_limit = limits
lower_include, upper_include = inclusive
am = ma.MaskedArray(a)
if lower_limit is not None:
if lower_include:
am = ma.masked_less(am, lower_limit)
else:
am = ma.masked_less_equal(am, lower_limit)
if upper_limit is not None:
if upper_include:
am = ma.masked_greater(am, upper_limit)
else:
am = ma.masked_greater_equal(am, upper_limit)
if am.count() == 0:
raise ValueError("No array values within given limits")
return am
示例4: test_kendalltau
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_greater [as 别名]
def test_kendalltau(self):
# Tests some computations of Kendall's tau
x = ma.fix_invalid([5.05, 6.75, 3.21, 2.66,np.nan])
y = ma.fix_invalid([1.65, 26.5, -5.93, 7.96, np.nan])
z = ma.fix_invalid([1.65, 2.64, 2.64, 6.95, np.nan])
assert_almost_equal(np.asarray(mstats.kendalltau(x,y)),
[+0.3333333,0.4969059])
assert_almost_equal(np.asarray(mstats.kendalltau(x,z)),
[-0.5477226,0.2785987])
#
x = ma.fix_invalid([0, 0, 0, 0,20,20, 0,60, 0,20,
10,10, 0,40, 0,20, 0, 0, 0, 0, 0, np.nan])
y = ma.fix_invalid([0,80,80,80,10,33,60, 0,67,27,
25,80,80,80,80,80,80, 0,10,45, np.nan, 0])
result = mstats.kendalltau(x,y)
assert_almost_equal(np.asarray(result), [-0.1585188, 0.4128009])
# make sure internal variable use correct precision with
# larger arrays
x = np.arange(2000, dtype=float)
x = ma.masked_greater(x, 1995)
y = np.arange(2000, dtype=float)
y = np.concatenate((y[1000:], y[:1000]))
assert_(np.isfinite(mstats.kendalltau(x,y)[1]))
# test for namedtuple attributes
res = mstats.kendalltau(x, y)
attributes = ('correlation', 'pvalue')
check_named_results(res, attributes, ma=True)
示例5: _convert_to_xtgeo_prop
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_greater [as 别名]
def _convert_to_xtgeo_prop(
self, rox, pname, roxgrid, roxprop, realisation
): # pragma: no cover
"""Collect numpy array and convert to XTGeo fmt"""
indexer = roxgrid.get_grid().grid_indexer
self._ncol, self._nrow, self._nlay = indexer.dimensions
if rox.version_required("1.3"):
logger.info(indexer.ijk_handedness)
else:
logger.info(indexer.handedness)
pvalues = roxprop.get_values(realisation=realisation)
self._roxar_dtype = pvalues.dtype
if self._isdiscrete:
mybuffer = np.ndarray(indexer.dimensions, dtype=np.int32)
mybuffer.fill(xtgeo.UNDEF_INT)
else:
mybuffer = np.ndarray(indexer.dimensions, dtype=np.float64)
mybuffer.fill(xtgeo.UNDEF)
cellno = indexer.get_cell_numbers_in_range((0, 0, 0), indexer.dimensions)
ijk = indexer.get_indices(cellno)
iind = ijk[:, 0]
jind = ijk[:, 1]
kind = ijk[:, 2]
mybuffer[iind, jind, kind] = pvalues[cellno]
if self._isdiscrete:
mybuffer = ma.masked_greater(mybuffer, xtgeo.UNDEF_INT_LIMIT)
self.codes = _fix_codes(roxprop.code_names)
logger.info("Fixed codes: %s", self.codes)
else:
mybuffer = ma.masked_greater(mybuffer, xtgeo.UNDEF_LIMIT)
self._values = mybuffer
self._name = pname
示例6: get_fence
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_greater [as 别名]
def get_fence(self, xyfence):
"""Get surface values along fence."""
cxarr = xyfence[:, 0]
cyarr = xyfence[:, 1]
czarr = xyfence[:, 2].copy()
# czarr will be updated "inplace":
istat = _cxtgeo.surf_get_zv_from_xyv(
cxarr,
cyarr,
czarr,
self.ncol,
self.nrow,
self.xori,
self.yori,
self.xinc,
self.yinc,
self.yflip,
self.rotation,
self.get_values1d(),
)
if istat != 0:
logger.warning("Seem to be rotten")
xyfence[:, 2] = czarr
xyfence = ma.masked_greater(xyfence, xtgeo.UNDEF_LIMIT)
xyfence = ma.mask_rows(xyfence)
return xyfence
示例7: _mask_to_limits
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_greater [as 别名]
def _mask_to_limits(a, limits, inclusive):
"""Mask an array for values outside of given limits.
This is primarily a utility function.
Parameters
----------
a : array
limits : (float or None, float or None)
A tuple consisting of the (lower limit, upper limit). Values in the
input array less than the lower limit or greater than the upper limit
will be masked out. None implies no limit.
inclusive : (bool, bool)
A tuple consisting of the (lower flag, upper flag). These flags
determine whether values exactly equal to lower or upper are allowed.
Returns
-------
A MaskedArray.
Raises
------
A ValueError if there are no values within the given limits.
"""
lower_limit, upper_limit = limits
lower_include, upper_include = inclusive
am = ma.MaskedArray(a)
if lower_limit is not None:
if lower_include:
am = ma.masked_less(am, lower_limit)
else:
am = ma.masked_less_equal(am, lower_limit)
if upper_limit is not None:
if upper_include:
am = ma.masked_greater(am, upper_limit)
else:
am = ma.masked_greater_equal(am, upper_limit)
if am.count() == 0:
raise ValueError("No array values within given limits")
return am
示例8: _mask_to_limits
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_greater [as 别名]
def _mask_to_limits(a, limits, inclusive):
"""Mask an array for values outside of given limits.
This is primarily a utility function.
Parameters
----------
a : array
limits : (float or None, float or None)
A tuple consisting of the (lower limit, upper limit). Values in the
input array less than the lower limit or greater than the upper limit
will be masked out. None implies no limit.
inclusive : (bool, bool)
A tuple consisting of the (lower flag, upper flag). These flags
determine whether values exactly equal to lower or upper are allowed.
Returns
-------
A MaskedArray.
Raises
------
A ValueError if there are no values within the given limits.
"""
lower_limit, upper_limit = limits
lower_include, upper_include = inclusive
am = ma.MaskedArray(a)
if lower_limit is not None:
if lower_include:
am = ma.masked_less(am, lower_limit)
else:
am = ma.masked_less_equal(am, lower_limit)
if upper_limit is not None:
if upper_include:
am = ma.masked_greater(am, upper_limit)
else:
am = ma.masked_greater_equal(am, upper_limit)
if am.count() == 0:
raise ValueError("No array values within given limits")
return am
示例9: import_irap_ascii
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_greater [as 别名]
def import_irap_ascii(self, mfile):
"""Import Irap ascii format."""
# version using swig type mapping
logger.debug("Enter function...")
cfhandle = mfile.get_cfhandle()
# read with mode 0, scan to get mx my
xlist = _cxtgeo.surf_import_irap_ascii(cfhandle, 0, 1, 0)
nvn = xlist[1] * xlist[2] # mx * my
xlist = _cxtgeo.surf_import_irap_ascii(cfhandle, 1, nvn, 0)
ier, ncol, nrow, _ndef, xori, yori, xinc, yinc, rot, val = xlist
if ier != 0:
mfile.cfclose()
raise RuntimeError("Problem in {}, code {}".format(__name__, ier))
val = np.reshape(val, (ncol, nrow), order="C")
val = ma.masked_greater(val, xtgeo.UNDEF_LIMIT)
if np.isnan(val).any():
logger.info("NaN values are found, will mask...")
val = ma.masked_invalid(val)
yflip = 1
if yinc < 0.0:
yinc = yinc * -1
yflip = -1
self._ncol = ncol
self._nrow = nrow
self._xori = xori
self._yori = yori
self._xinc = xinc
self._yinc = yinc
self._yflip = yflip
self._rotation = rot
self._values = val
self._filesrc = mfile
self._ilines = np.array(range(1, ncol + 1), dtype=np.int32)
self._xlines = np.array(range(1, nrow + 1), dtype=np.int32)
mfile.cfclose()
示例10: import_ijxyz_ascii
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_greater [as 别名]
def import_ijxyz_ascii(self, mfile): # pylint: disable=too-many-locals
"""Import OW/DSG IJXYZ ascii format."""
# import of seismic column system on the form:
# 2588 1179 476782.2897888889 6564025.6954 1000.0
# 2588 1180 476776.7181777778 6564014.5058 1000.0
logger.debug("Read data from file... (scan for dimensions)")
cfhandle = mfile.get_cfhandle()
xlist = _cxtgeo.surf_import_ijxyz(cfhandle, 0, 1, 1, 1, 0)
ier, ncol, nrow, _ndef, xori, yori, xinc, yinc, rot, iln, xln, val, yflip = xlist
if ier != 0:
mfile.cfclose()
raise RuntimeError("Import from C is wrong...")
# now real read mode
xlist = _cxtgeo.surf_import_ijxyz(cfhandle, 1, ncol, nrow, ncol * nrow, 0)
ier, ncol, nrow, _ndef, xori, yori, xinc, yinc, rot, iln, xln, val, yflip = xlist
if ier != 0:
raise RuntimeError("Import from C is wrong...")
logger.info(xlist)
val = ma.masked_greater(val, xtgeo.UNDEF_LIMIT)
self._xori = xori
self._xinc = xinc
self._yori = yori
self._yinc = yinc
self._ncol = ncol
self._nrow = nrow
self._rotation = rot
self._yflip = yflip
self._values = val.reshape((self._ncol, self._nrow))
self._filesrc = mfile
self._ilines = iln
self._xlines = xln
mfile.cfclose()
示例11: import_petromod_binary
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_greater [as 别名]
def import_petromod_binary(self, mfile, values=True):
"""Import Petromod binary format."""
cfhandle = mfile.get_cfhandle()
logger.info("Enter function %s", __name__)
# read with mode 0, to get mx my and other metadata
dsc, dummy = _cxtgeo.surf_import_petromod_bin(cfhandle, 0, 0.0, 0, 0, 0)
fields = dsc.split(",")
for field in fields:
key, value = field.split("=")
if key == "GridNoX":
self._ncol = int(value)
if key == "GridNoY":
self._nrow = int(value)
if key == "OriginX":
self._xori = float(value)
if key == "OriginY":
self._yori = float(value)
if key == "RotationOriginX":
rota_xori = float(value)
if key == "RotationOriginY":
rota_yori = float(value)
if key == "GridStepX":
self._xinc = int(value)
if key == "GridStepY":
self._yinc = int(value)
if key == "RotationAngle":
self._rotation = float(value)
if key == "Undefined":
undef = float(value)
if self._rotation != 0.0 and (rota_xori != self._xori or rota_yori != self._yori):
xtg.warnuser("Rotation origin and data origin do match")
# reread file for map values
dsc, values = _cxtgeo.surf_import_petromod_bin(
cfhandle, 1, undef, self._ncol, self._nrow, self._ncol * self._nrow
)
values = np.ma.masked_greater(values, xtgeo.UNDEF_LIMIT)
values = values.reshape(self._ncol, self._nrow)
self.values = values
self.filesrc = mfile
mfile.cfclose()