Skip to content

Commit 0bfefc1

Browse files
authored
Merge pull request #310 from GeoStat-Framework/update_uniform_trans
Update uniform trans
2 parents 3149b70 + 01c9e14 commit 0bfefc1

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/gstools/transform/array.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ def array_to_lognormal(field):
215215
return np.exp(field)
216216

217217

218-
def array_to_uniform(field, mean=None, var=None):
218+
def array_to_uniform(field, mean=None, var=None, low=0.0, high=1.0):
219219
"""
220-
Transform normal distribution to uniform distribution on [0, 1].
220+
Transform normal distribution to uniform distribution on [low, high].
221221
222222
Parameters
223223
----------
@@ -230,6 +230,12 @@ def array_to_uniform(field, mean=None, var=None):
230230
Variance of the given field.
231231
If None is given, the variance will be calculated.
232232
Default: :any:`None`
233+
low : :class:`float`, optional
234+
Lower bound for the uniform distribution.
235+
Default: 0.0
236+
high : :class:`float`, optional
237+
Upper bound for the uniform distribution.
238+
Default: 1.0
233239
234240
Returns
235241
-------
@@ -239,7 +245,9 @@ def array_to_uniform(field, mean=None, var=None):
239245
field = np.asarray(field)
240246
mean = np.mean(field) if mean is None else float(mean)
241247
var = np.var(field) if var is None else float(var)
242-
return 0.5 * (1 + erf((field - mean) / np.sqrt(2 * var)))
248+
return (
249+
0.5 * (1 + erf((field - mean) / np.sqrt(2 * var))) * (high - low) + low
250+
)
243251

244252

245253
def array_to_arcsin(field, mean=None, var=None, a=None, b=None):

src/gstools/transform/field.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,8 @@ def normal_to_lognormal(
548548

549549
def normal_to_uniform(
550550
fld,
551+
low=0.0,
552+
high=1.0,
551553
field="field",
552554
store=True,
553555
process=False,
@@ -562,14 +564,31 @@ def normal_to_uniform(
562564
----------
563565
fld : :any:`Field`
564566
Field class containing a generated field.
567+
low : :class:`float`, optional
568+
Lower bound for the uniform distribution.
569+
Default: 0.0
570+
high : :class:`float`, optional
571+
Upper bound for the uniform distribution.
572+
Default: 1.0
573+
field : :class:`str`, optional
574+
Name of field to be transformed. The default is "field".
575+
store : :class:`str` or :class:`bool`, optional
576+
Whether to store field inplace (True/False) or under a given name.
577+
The default is True.
578+
process : :class:`bool`, optional
579+
Whether to process in/out fields with trend, normalizer and mean
580+
of given Field instance. The default is False.
565581
keep_mean : :class:`bool`, optional
566582
Whether to keep the mean of the field if process=True.
567583
The default is True.
568584
"""
569585
if not process:
570586
_check_for_default_normal(fld)
571587
kw = dict(
572-
mean=0.0 if process and not keep_mean else fld.mean, var=fld.model.sill
588+
mean=0.0 if process and not keep_mean else fld.mean,
589+
var=fld.model.sill,
590+
low=low,
591+
high=high,
573592
)
574593
return apply_function(
575594
fld=fld,

0 commit comments

Comments
 (0)