diff --git a/src/gstools/transform/array.py b/src/gstools/transform/array.py index 32005f00..30c92bb6 100644 --- a/src/gstools/transform/array.py +++ b/src/gstools/transform/array.py @@ -215,9 +215,9 @@ def array_to_lognormal(field): return np.exp(field) -def array_to_uniform(field, mean=None, var=None): +def array_to_uniform(field, mean=None, var=None, low=0.0, high=1.0): """ - Transform normal distribution to uniform distribution on [0, 1]. + Transform normal distribution to uniform distribution on [low, high]. Parameters ---------- @@ -230,6 +230,12 @@ def array_to_uniform(field, mean=None, var=None): Variance of the given field. If None is given, the variance will be calculated. Default: :any:`None` + low : :class:`float`, optional + Lower bound for the uniform distribution. + Default: 0.0 + high : :class:`float`, optional + Upper bound for the uniform distribution. + Default: 1.0 Returns ------- @@ -239,7 +245,9 @@ def array_to_uniform(field, mean=None, var=None): field = np.asarray(field) mean = np.mean(field) if mean is None else float(mean) var = np.var(field) if var is None else float(var) - return 0.5 * (1 + erf((field - mean) / np.sqrt(2 * var))) + return ( + 0.5 * (1 + erf((field - mean) / np.sqrt(2 * var))) * (high - low) + low + ) def array_to_arcsin(field, mean=None, var=None, a=None, b=None): diff --git a/src/gstools/transform/field.py b/src/gstools/transform/field.py index 81824739..5d204407 100644 --- a/src/gstools/transform/field.py +++ b/src/gstools/transform/field.py @@ -548,6 +548,8 @@ def normal_to_lognormal( def normal_to_uniform( fld, + low=0.0, + high=1.0, field="field", store=True, process=False, @@ -562,6 +564,20 @@ def normal_to_uniform( ---------- fld : :any:`Field` Field class containing a generated field. + low : :class:`float`, optional + Lower bound for the uniform distribution. + Default: 0.0 + high : :class:`float`, optional + Upper bound for the uniform distribution. + Default: 1.0 + field : :class:`str`, optional + Name of field to be transformed. The default is "field". + store : :class:`str` or :class:`bool`, optional + Whether to store field inplace (True/False) or under a given name. + The default is True. + process : :class:`bool`, optional + Whether to process in/out fields with trend, normalizer and mean + of given Field instance. The default is False. keep_mean : :class:`bool`, optional Whether to keep the mean of the field if process=True. The default is True. @@ -569,7 +585,10 @@ def normal_to_uniform( if not process: _check_for_default_normal(fld) kw = dict( - mean=0.0 if process and not keep_mean else fld.mean, var=fld.model.sill + mean=0.0 if process and not keep_mean else fld.mean, + var=fld.model.sill, + low=low, + high=high, ) return apply_function( fld=fld,