3D non-stationary lognormal distribution #353
-
Hello, This is a wonderful Python module; thank you so much to the developer. I am new to geostatistics and want to generate a 3D non-stationary lognormal distribution field. However, I have encountered a problem applying the trend function (e.g., a linear function). I am unsure whether and how to transform the trend function in the lognormal field into the form of a normal distribution field. Below is my code:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hi YuanZhongYan, thank you for the kind words. I cannot really follow your example. For example, what is it with that loop near the bottom of your skript? x_u, y_u, z_u = np.meshgrid(x, y, z, indexing='ij')
tr = trend(x_u, y_u, z_u) And after generating the field do srf.field += tr |
Beta Was this translation helpful? Give feedback.
-
Hey there, GSTools provides trends as a built-in feature. You can pass your function to the SRF class and it will be applied inplace. import numpy as np
import gstools as gs
# Mean and standard deviation values in lognormal distribution
mu_log = 1 * 10 ** (-5)
sigma_log = 5 * 10 ** (-6)
cov = sigma_log / mu_log
# Mean and variance values in normal distribution
var_nor = np.log(1 + cov**2)
mean_nor = np.log(mu_log) - 0.5 * var_nor
dk = 0.5
def trend(x, y, z):
"""This is a linear trend function in the lognormal field."""
return (1 + dk) * mu_log + 2 * dk * mu_log * (z - 30) / 30
x = np.arange(-7.8, 7.8, 0.3)
y = np.arange(-7.8, 7.8, 0.3)
z = np.arange(0, 30.3, 0.3)
model = gs.Exponential(dim=3, var=var_nor, len_scale=[4, 4, 2])
srf = gs.SRF(model, mean=mean_nor, normalizer=gs.normalizer.LogNormal, trend=trend)
srf.set_pos([x, y, z], "structured")
# generate ensemble
for i in range(5):
srf(seed=i, store=f"field_{i}")
# access fields by name
field = srf["field_0"]
# plot fields by name
srf.plot(field="field_0")
Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hey there,
GSTools provides trends as a built-in feature. You can pass your function to the SRF class and it will be applied inplace.
Also, to generate ensembles of fields, you can reuse the same srf with a new seed, and store the fields with a specific name to access them afterwads. I modified your example to demonstrate this. (Note, that I corrected an error in your calculations for the mean and variance.
sigma_nor
as you calculated it, is actually the variance and should be used to calculate,mu_nor
. I renamed both to be clear):