Skip to content

Commit

Permalink
Merge pull request #310 from GeoStat-Framework/update_uniform_trans
Browse files Browse the repository at this point in the history
Update uniform trans
  • Loading branch information
MuellerSeb authored Jun 15, 2023
2 parents 3149b70 + 01c9e14 commit 0bfefc1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/gstools/transform/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -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
-------
Expand All @@ -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):
Expand Down
21 changes: 20 additions & 1 deletion src/gstools/transform/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -562,14 +564,31 @@ 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.
"""
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,
Expand Down

0 comments on commit 0bfefc1

Please sign in to comment.