本文整理汇总了Python中numpy.ma.masked_less_equal方法的典型用法代码示例。如果您正苦于以下问题:Python ma.masked_less_equal方法的具体用法?Python ma.masked_less_equal怎么用?Python ma.masked_less_equal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.ma
的用法示例。
在下文中一共展示了ma.masked_less_equal方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_less_equal [as 别名]
def __call__(self, value, clip=None):
if clip is None:
clip = self.clip
result, is_scalar = self.process_value(value)
result = ma.masked_less_equal(result, 0, copy=False)
self.autoscale_None(result)
vmin, vmax = self.vmin, self.vmax
if vmin > vmax:
raise ValueError("minvalue must be less than or equal to maxvalue")
elif vmin <= 0:
raise ValueError("values must all be positive")
elif vmin == vmax:
result.fill(0)
else:
if clip:
mask = ma.getmask(result)
result = ma.array(np.clip(result.filled(vmax), vmin, vmax),
mask=mask)
# in-place equivalent of above can be much faster
resdat = result.data
mask = result.mask
if mask is np.ma.nomask:
mask = (resdat <= 0)
else:
mask |= resdat <= 0
cbook._putmask(resdat, mask, 1)
np.log(resdat, resdat)
resdat -= np.log(vmin)
resdat /= (np.log(vmax) - np.log(vmin))
result = np.ma.array(resdat, mask=mask, copy=False)
if is_scalar:
result = result[0]
return result
示例2: autoscale
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_less_equal [as 别名]
def autoscale(self, A):
'''
Set *vmin*, *vmax* to min, max of *A*.
'''
A = ma.masked_less_equal(A, 0, copy=False)
self.vmin = ma.min(A)
self.vmax = ma.max(A)
示例3: autoscale_None
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_less_equal [as 别名]
def autoscale_None(self, A):
' autoscale only None-valued vmin or vmax'
if self.vmin is not None and self.vmax is not None:
return
A = ma.masked_less_equal(A, 0, copy=False)
if self.vmin is None:
self.vmin = ma.min(A)
if self.vmax is None:
self.vmax = ma.max(A)
示例4: mask_to_limits
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_less_equal [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
示例5: autoscale
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_less_equal [as 别名]
def autoscale(self, A):
"""
Set *vmin*, *vmax* to min, max of *A*.
"""
A = ma.masked_less_equal(A, 0, copy=False)
self.vmin = ma.min(A)
self.vmax = ma.max(A)
示例6: operation
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_less_equal [as 别名]
def operation(self, opname, value):
"""Do operation on map values.
Do operations on the current map values. Valid operations are:
* 'elilt' or 'eliminatelessthan': Eliminate less than <value>
* 'elile' or 'eliminatelessequal': Eliminate less or equal than <value>
Args:
opname (str): Name of operation. See list above.
values (*): A scalar number (float) or a tuple of two floats,
dependent on operation opname.
Examples::
surf.operation('elilt', 200) # set all values < 200 as undef
"""
if opname in ("elilt", "eliminatelessthan"):
self._values = ma.masked_less(self._values, value)
elif opname in ("elile", "eliminatelessequal"):
self._values = ma.masked_less_equal(self._values, value)
else:
raise ValueError("Invalid operation name")
# ==================================================================================
# Operations restricted to inside/outside polygons
# ==================================================================================
示例7: _mask_to_limits
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_less_equal [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_less_equal [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