correct_intermittency_1d
- mdtools.dynamics.correct_intermittency_1d(a, intermittency, inplace=True, debug=False)[source]
Correct for intermittent behavior of discrete variables stored in a 1-dimensional array.
Fill gaps between same values with a gap size smaller or equal to a given maximum gap size with the enclosing values. For instance, 0,1,1,0,1,1,2 is replaced by 0,0,0,0,1,1,2, when intermittency is set to
2
.- Parameters:
a (
array_like
) – 1-dimensional array, in which to fill gaps between same values with the enclosing values. For higher dimensional arrays usemdtools.dynamics.correct_intermittency()
.intermittency (
int
) – The maximum allowed gap size. All gaps with a size smaller or equal to the maximum gap size are considered to be negligible and are filled with their enclosing values. If intermittency is less than one, a will be returned without any changes.inplace (
bool
, optional) – IfTrue
(default), modify a inplace instead of creating a copy of a. Works only, if a is anumpy.ndarray
.debug (
bool
, optional) – IfTrue
, check the input arguments.Deprecated since version 0.0.0.dev0: This argument is without use and will be removed in a future release.
- Returns:
a (
numpy.ndarray
) – The input array asnumpy.ndarray
with gaps of size<=intermittency
between same values filled with the enclosing values.
See also
mdtools.dynamics.correct_intermittency()
Correct for intermittent behavior of discrete variables stored in a sequence of arrays
mdtools.dynamics.replace_short_sequences()
Replace consecutive occurrences of the same value that are shorter than a given minimum length by a given value
mdtools.dynamics.replace_short_sequences_global()
TODO
Notes
This is a faster version of
mdtools.dynamics.correct_intermittency()
for 1-dimensional arrays. See there for more details.Examples
>>> a = np.array([1, 2, 2, 1, 3, 3, 3, 1, 3, 3, 3]) >>> mdt.dyn.correct_intermittency_1d(a, ... intermittency=1, ... inplace=False) array([1, 2, 2, 1, 3, 3, 3, 3, 3, 3, 3]) >>> mdt.dyn.correct_intermittency_1d(a, ... intermittency=2, ... inplace=False) array([1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3]) >>> mdt.dyn.correct_intermittency_1d(a, ... intermittency=3, ... inplace=False) array([1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3])
An intermittency value larger than
len(a)-2
leads to the same result as an intermittency value oflen(a)-2
. The first and the last elements are never changed:>>> mdt.dyn.correct_intermittency_1d(a, ... intermittency=len(a)-2, ... inplace=False) array([1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3]) >>> mdt.dyn.correct_intermittency_1d(a, ... intermittency=len(a)-1, ... inplace=False) array([1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3])
If intermittency is less than one, the input array is returned as
numpy.ndarray
:>>> mdt.dyn.correct_intermittency_1d(a, ... intermittency=0, ... inplace=False) array([1, 2, 2, 1, 3, 3, 3, 1, 3, 3, 3])
Inplace modification:
>>> b = mdt.dyn.correct_intermittency_1d(a, ... intermittency=3, ... inplace=True) >>> a is b True