Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
tf.normal_force_moments(srf) # force ergodicity of the given field
self.assertAlmostEqual(srf.field.mean(), srf.mean)
self.assertAlmostEqual(srf.field.var(), srf.model.var)
tf.zinnharvey(srf) # make high values mostly connected
tf.normal_force_moments(srf) # force ergodicity of the given field
tf.normal_to_lognormal(srf) # log-normal
srf((self.x_grid, self.y_grid), seed=self.seed, mesh_type="structured")
tf.normal_to_arcsin(srf)
srf((self.x_grid, self.y_grid), seed=self.seed, mesh_type="structured")
tf.normal_to_uquad(srf)
srf((self.x_grid, self.y_grid), seed=self.seed, mesh_type="structured")
tf.normal_to_uniform(srf)
srf((self.x_grid, self.y_grid), seed=self.seed, mesh_type="structured")
tf.binary(srf)
srf((self.x_grid, self.y_grid), seed=self.seed, mesh_type="structured")
tf.boxcox(srf)
srf((self.x_grid, self.y_grid), seed=self.seed, mesh_type="structured")
values = np.linspace(np.min(srf.field), np.max(srf.field), 3)
tf.discrete(srf, values)
srf((self.x_grid, self.y_grid), seed=self.seed, mesh_type="structured")
values = [-1, 0, 1]
thresholds = [-0.9, 0.1]
tf.discrete(srf, values, thresholds)
np.testing.assert_array_equal(np.unique(srf.field), [-1, 0, 1])
srf((self.x_grid, self.y_grid), seed=self.seed, mesh_type="structured")
values = [-1, 0, 1]
tf.discrete(srf, values, thresholds="arithmetic")
np.testing.assert_array_equal(np.unique(srf.field), [-1.0, 0.0, 1.0])
srf((self.x_grid, self.y_grid), seed=self.seed, mesh_type="structured")
def test_transform(self):
self.cov_model.dim = 2
srf = SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
srf((self.x_grid, self.y_grid), seed=self.seed, mesh_type="structured")
tf.normal_force_moments(srf) # force ergodicity of the given field
self.assertAlmostEqual(srf.field.mean(), srf.mean)
self.assertAlmostEqual(srf.field.var(), srf.model.var)
tf.zinnharvey(srf) # make high values mostly connected
tf.normal_force_moments(srf) # force ergodicity of the given field
tf.normal_to_lognormal(srf) # log-normal
srf((self.x_grid, self.y_grid), seed=self.seed, mesh_type="structured")
tf.normal_to_arcsin(srf)
srf((self.x_grid, self.y_grid), seed=self.seed, mesh_type="structured")
tf.normal_to_uquad(srf)
srf((self.x_grid, self.y_grid), seed=self.seed, mesh_type="structured")
tf.normal_to_uniform(srf)
srf((self.x_grid, self.y_grid), seed=self.seed, mesh_type="structured")
tf.binary(srf)
srf((self.x_grid, self.y_grid), seed=self.seed, mesh_type="structured")
tf.boxcox(srf)
srf((self.x_grid, self.y_grid), seed=self.seed, mesh_type="structured")
Zinn & Harvey transformation
----------------------------
Here, we transform a field with the so called "Zinn & Harvey" transformation presented in
`Zinn & Harvey (2003) `__.
With this transformation, one could overcome the restriction that in ordinary
Gaussian random fields the mean values are the ones being the most connected.
"""
import gstools as gs
# structured field with a size of 100x100 and a grid-size of 1x1
x = y = range(100)
model = gs.Gaussian(dim=2, var=1, len_scale=10)
srf = gs.SRF(model, seed=20170519)
srf.structured([x, y])
gs.transform.zinnharvey(srf, conn="high")
srf.plot()
You can combine different transformations simply by successively applying them.
Here, we first force the single field realization to hold the given moments,
namely mean and variance.
Then we apply the Zinn & Harvey transformation to connect the low values.
Afterwards the field is transformed to a binary field and last but not least,
we transform it to log-values.
"""
import gstools as gs
# structured field with a size of 100x100 and a grid-size of 1x1
x = y = range(100)
model = gs.Gaussian(dim=2, var=1, len_scale=10)
srf = gs.SRF(model, mean=-9, seed=20170519)
srf.structured([x, y])
gs.transform.normal_force_moments(srf)
gs.transform.zinnharvey(srf, conn="low")
gs.transform.binary(srf)
gs.transform.normal_to_lognormal(srf)
srf.plot()
"""
binary fields
-------------
Here we transform a field to a binary field with only two values.
The dividing value is the mean by default and the upper and lower values
are derived to preserve the variance.
"""
import gstools as gs
# structured field with a size of 100x100 and a grid-size of 1x1
x = y = range(100)
model = gs.Gaussian(dim=2, var=1, len_scale=10)
srf = gs.SRF(model, seed=20170519)
srf.structured([x, y])
gs.transform.binary(srf)
srf.plot()
Here, we first force the single field realization to hold the given moments,
namely mean and variance.
Then we apply the Zinn & Harvey transformation to connect the low values.
Afterwards the field is transformed to a binary field and last but not least,
we transform it to log-values.
"""
import gstools as gs
# structured field with a size of 100x100 and a grid-size of 1x1
x = y = range(100)
model = gs.Gaussian(dim=2, var=1, len_scale=10)
srf = gs.SRF(model, mean=-9, seed=20170519)
srf.structured([x, y])
gs.transform.normal_force_moments(srf)
gs.transform.zinnharvey(srf, conn="low")
gs.transform.binary(srf)
gs.transform.normal_to_lognormal(srf)
srf.plot()
"""
log-normal fields
-----------------
Here we transform a field to a log-normal distribution:
"""
import gstools as gs
# structured field with a size of 100x100 and a grid-size of 1x1
x = y = range(100)
model = gs.Gaussian(dim=2, var=1, len_scale=10)
srf = gs.SRF(model, seed=20170519)
srf.structured([x, y])
gs.transform.normal_to_lognormal(srf)
srf.plot()
We provide two transformations to obtain bimodal distributions:
* `arcsin `__.
* `uquad `__.
Both transformations will preserve the mean and variance of the given field by default.
"""
import gstools as gs
# structured field with a size of 100x100 and a grid-size of 1x1
x = y = range(100)
model = gs.Gaussian(dim=2, var=1, len_scale=10)
srf = gs.SRF(model, seed=20170519)
field = srf.structured([x, y])
gs.transform.normal_to_arcsin(srf)
srf.plot()