示例#1
0
    def test_rotation_unstruct_3d(self):
        self.cov_model = gs.Gaussian(dim=3,
                                     var=1.5,
                                     len_scale=4.0,
                                     anis=(0.25, 0.5))
        x_len = len(self.x_grid_c)
        y_len = len(self.y_grid_c)
        z_len = len(self.z_grid_c)
        x_u, y_u, z_u = np.meshgrid(self.x_grid_c, self.y_grid_c,
                                    self.z_grid_c)
        x_u = np.reshape(x_u, x_len * y_len * z_len)
        y_u = np.reshape(y_u, x_len * y_len * z_len)
        z_u = np.reshape(z_u, x_len * y_len * z_len)

        srf = gs.SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
        field = srf((x_u, y_u, z_u), seed=self.seed, mesh_type="unstructured")
        field_str = np.reshape(field, (y_len, x_len, z_len))

        self.cov_model.angles = (-np.pi / 2.0, -np.pi / 2.0)
        srf = gs.SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
        field_rot = srf((x_u, y_u, z_u),
                        seed=self.seed,
                        mesh_type="unstructured")
        field_rot_str = np.reshape(field_rot, (y_len, x_len, z_len))

        self.assertAlmostEqual(field_str[0, 0, 0], field_rot_str[-1, -1, 0])
        self.assertAlmostEqual(field_str[1, 2, 0], field_rot_str[-3, -1, 1])
        self.assertAlmostEqual(field_str[0, 0, 1], field_rot_str[-1, -2, 0])
示例#2
0
    def test_rotation_struct_3d(self):
        self.cov_model.dim = 3
        self.cov_model.anis = 0.25
        srf = gs.SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
        field = srf(
            (self.x_grid_c, self.y_grid_c, self.z_grid_c),
            seed=self.seed,
            mesh_type="structured",
        )

        self.cov_model.angles = -np.pi / 2.0
        srf = gs.SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
        field_rot = srf(
            (self.x_grid_c, self.y_grid_c, self.z_grid_c),
            seed=self.seed,
            mesh_type="structured",
        )

        self.assertAlmostEqual(field[0, 0, 0], field_rot[0, 7, 0])
        self.assertAlmostEqual(field[0, 0, 1], field_rot[0, 7, 1])

        self.cov_model.angles = (0, -np.pi / 2.0)
        srf = gs.SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
        field_rot = srf(
            (self.x_grid_c, self.y_grid_c, self.z_grid_c),
            seed=self.seed,
            mesh_type="structured",
        )

        self.assertAlmostEqual(field[0, 0, 0], field_rot[7, 0, 0])
        self.assertAlmostEqual(field[0, 1, 0], field_rot[7, 1, 0])
        self.assertAlmostEqual(field[1, 1, 0], field_rot[7, 1, 1])
示例#3
0
 def test_assertions(self):
     # self.cov_model.dim = 0
     # self.assertRaises(ValueError, gs.SRF, self.cov_model, self.mean, self.mode_no)
     # self.cov_model.dim = 4
     # self.assertRaises(ValueError, gs.SRF, self.cov_model, self.mean, self.mode_no)
     self.cov_model.dim = 3
     self.cov_model.anis = (0.25, 0.5)
     srf = gs.SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
     self.assertRaises(ValueError, srf, [self.x_tuple])
     self.assertRaises(ValueError, srf, [self.x_grid, self.y_grid])
     srf = gs.SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
     self.assertRaises(ValueError, srf, [self.x_tuple, self.y_tuple])
     self.assertRaises(ValueError, srf,
                       [self.x_grid, self.y_grid, self.z_grid])
示例#4
0
 def test_anisotropy_2d(self):
     self.cov_model.dim = 2
     srf = gs.SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
     field_iso = srf((self.x_grid, self.y_grid),
                     seed=self.seed,
                     mesh_type="structured")
     self.cov_model.anis = 0.5
     srf = gs.SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
     field_aniso = srf((self.x_grid, self.y_grid),
                       seed=self.seed,
                       mesh_type="structured")
     self.assertAlmostEqual(field_iso[0, 0], field_aniso[0, 0])
     self.assertAlmostEqual(field_iso[0, 4], field_aniso[0, 2])
     self.assertAlmostEqual(field_iso[0, 10], field_aniso[0, 5])
示例#5
0
 def change_srf(self, seed):
     """
     Spatial random field with new seed
     :param seed: int, random number generator seed
     :return: None
     """
     self.srf = gstools.SRF(self.model, seed=seed, mode_no=self.mode_no)
示例#6
0
 def test_shape_1d(self):
     self.cov_model.dim = 1
     srf = gs.SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
     field_str = srf([self.x_grid], seed=self.seed, mesh_type="structured")
     field_unstr = srf([self.x_tuple],
                       seed=self.seed,
                       mesh_type="unstructured")
     self.assertEqual(field_str.shape, (len(self.x_grid), ))
     self.assertEqual(field_unstr.shape, (len(self.x_tuple), ))
示例#7
0
 def test_vector_mean(self):
     srf = gs.SRF(
         self.cov_model_2d,
         mean=(0.5, 0),
         generator="VectorField",
         seed=198412031,
     )
     srf.structured((self.x_grid, self.y_grid))
     self.assertAlmostEqual(np.mean(srf.field[0]), 1.3025621393180298)
     self.assertAlmostEqual(np.mean(srf.field[1]), -0.04729596839446052)
示例#8
0
    def test_rotation_unstruct_2d(self):
        self.cov_model.dim = 2
        x_len = len(self.x_grid_c)
        y_len = len(self.y_grid_c)
        x_u, y_u = np.meshgrid(self.x_grid_c, self.y_grid_c)
        x_u = np.reshape(x_u, x_len * y_len)
        y_u = np.reshape(y_u, x_len * y_len)

        self.cov_model.anis = 0.25
        srf = gs.SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)

        field = srf((x_u, y_u), seed=self.seed, mesh_type="unstructured")
        field_str = np.reshape(field, (y_len, x_len))

        self.cov_model.angles = -np.pi / 2.0
        srf = gs.SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
        field_rot = srf((x_u, y_u), seed=self.seed, mesh_type="unstructured")
        field_rot_str = np.reshape(field_rot, (y_len, x_len))

        self.assertAlmostEqual(field_str[0, 0], field_rot_str[-1, 0])
        self.assertAlmostEqual(field_str[1, 2], field_rot_str[-3, 1])
示例#9
0
 def __init__(self, model, mode_no=1000, log=False):
     """
     :param model: instance of covariance model class, which parent is gstools.covmodel.CovModel
     :param mode_no: number of Fourier modes, default: 1000 as in gstools package
     """
     self.model = model
     self.mode_no = mode_no
     self.srf = gstools.SRF(model, mode_no=mode_no)
     self.mu = self.srf.mean
     self.sigma = np.sqrt(model.var)
     self.dim = model.dim
     self.log = log
示例#10
0
 def test_anisotropy_3d(self):
     self.cov_model.dim = 3
     srf = gs.SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
     field_iso = srf(
         (self.x_grid, self.y_grid, self.z_grid),
         seed=self.seed,
         mesh_type="structured",
     )
     self.cov_model.anis = (0.5, 4.0)
     srf = gs.SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
     field_aniso = srf(
         (self.x_grid, self.y_grid, self.z_grid),
         seed=self.seed,
         mesh_type="structured",
     )
     self.assertAlmostEqual(field_iso[0, 0, 0], field_aniso[0, 0, 0])
     self.assertAlmostEqual(field_iso[0, 4, 0], field_aniso[0, 2, 0])
     self.assertAlmostEqual(field_iso[0, 10, 0], field_aniso[0, 5, 0])
     self.assertAlmostEqual(field_iso[0, 0, 0], field_aniso[0, 0, 0])
     self.assertAlmostEqual(field_iso[0, 0, 1], field_aniso[0, 0, 4])
     self.assertAlmostEqual(field_iso[0, 0, 3], field_aniso[0, 0, 12])
示例#11
0
 def test_multi_field(self):
     x = np.random.RandomState(19970221).rand(100) * 100.0
     model = gs.Exponential(dim=1, var=2, len_scale=10)
     srf = gs.SRF(model)
     field1 = srf(x, seed=19970221)
     field2 = srf(x, seed=20011012)
     bins = np.arange(20) * 2
     bin_center, gamma1 = gs.vario_estimate(x, field1, bins)
     bin_center, gamma2 = gs.vario_estimate(x, field2, bins)
     bin_center, gamma = gs.vario_estimate(x, [field1, field2], bins)
     gamma_mean = 0.5 * (gamma1 + gamma2)
     for i in range(len(gamma)):
         self.assertAlmostEqual(gamma[i], gamma_mean[i], places=2)
示例#12
0
 def test_calls(self):
     srf = gs.SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
     field = srf((self.x_tuple, self.y_tuple), seed=self.seed)
     field2 = srf.unstructured((self.x_tuple, self.y_tuple), seed=self.seed)
     self.assertAlmostEqual(field[0], srf.field[0])
     self.assertAlmostEqual(field[0], field2[0])
     field = srf(
         (self.x_tuple, self.y_tuple),
         seed=self.seed,
         mesh_type="structured",
     )
     field2 = srf.structured((self.x_tuple, self.y_tuple), seed=self.seed)
     self.assertAlmostEqual(field[0, 0], srf.field[0, 0])
     self.assertAlmostEqual(field[0, 0], field2[0, 0])
示例#13
0
 def test_mesh_pyvista(self):
     """Test the `.mesh` call with various PyVista meshes."""
     # Create model
     self.cov_model.dim = 3
     srf = gs.SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
     # Get the field the normal way for comparison
     field = srf((self.x_tuple, self.y_tuple, self.z_tuple), seed=self.seed)
     # Create mesh space with PyVista
     pv_mesh = pv.PolyData(np.c_[self.x_tuple, self.y_tuple, self.z_tuple])
     # Run the helper
     _ = srf.mesh(pv_mesh, seed=self.seed, points="centroids")
     self.assertTrue(np.allclose(field, pv_mesh["field"]))
     # points="centroids"
     _ = srf.mesh(pv_mesh, seed=self.seed, points="points")
     self.assertTrue(np.allclose(field, pv_mesh["field"]))
示例#14
0
 def test_meshio(self):
     points = np.array([
         [0.0, 0.0, 0.0],
         [0.0, 1.0, 0.0],
         [0.0, 0.0, 1.0],
         [1.0, 0.0, 0.0],
     ])
     cells = [("tetra", np.array([[0, 1, 2, 3]]))]
     mesh = meshio.Mesh(points, cells)
     model = gs.Gaussian(dim=3, len_scale=0.1)
     srf = gs.SRF(model)
     srf.mesh(mesh, points="points")
     self.assertEqual(len(srf.field), 4)
     srf.mesh(mesh, points="centroids")
     self.assertEqual(len(srf.field), 1)
示例#15
0
    def test_extdrift(self):
        ext_drift = []
        cond_drift = []
        for i, grid in enumerate(self.grids):
            dim = i + 1
            model = gs.Exponential(
                dim=dim,
                var=2,
                len_scale=10,
                anis=[0.9, 0.8],
                angles=[2, 1, 0.5],
            )
            srf = gs.SRF(model)
            field = srf(grid)
            ext_drift.append(field)
            field = field.reshape(self.grid_shape[:dim])
            cond_drift.append(field[self.data_idx[:dim]])

        for Model in self.cov_models:
            for dim in self.dims:
                model = Model(
                    dim=dim,
                    var=2,
                    len_scale=10,
                    anis=[0.5, 0.2],
                    angles=[0.4, 0.2, 0.1],
                )
                extdrift = gs.krige.ExtDrift(
                    model,
                    self.cond_pos[:dim],
                    self.cond_val,
                    cond_drift[dim - 1],
                )
                field_1, __ = extdrift.unstructured(
                    self.grids[dim - 1], ext_drift=ext_drift[dim - 1]
                )
                field_1 = field_1.reshape(self.grid_shape[:dim])
                field_2, __ = extdrift.structured(
                    self.pos[:dim], ext_drift=ext_drift[dim - 1]
                )
                # extdrift.plot()
                self.assertAlmostEqual(
                    np.max(np.abs(field_1 - field_2)), 0.0, places=2
                )
                for i, val in enumerate(self.cond_val):
                    self.assertAlmostEqual(
                        field_2[self.data_idx[:dim]][i], val, places=2
                    )
示例#16
0
 def test_incomprrandmeth(self):
     self.cov_model = gs.Gaussian(dim=2, var=0.5, len_scale=1.0)
     srf = gs.SRF(
         self.cov_model,
         mean=self.mean,
         mode_no=self.mode_no,
         generator="IncomprRandMeth",
         mean_velocity=0.5,
     )
     field = srf((self.x_tuple, self.y_tuple), seed=476356)
     self.assertAlmostEqual(field[0, 0], 1.23693272)
     self.assertAlmostEqual(field[0, 1], 0.89242284)
     field = srf((self.x_grid, self.y_grid),
                 seed=4734654,
                 mesh_type="structured")
     self.assertAlmostEqual(field[0, 0, 0], 1.07812013)
     self.assertAlmostEqual(field[0, 1, 0], 1.06180674)
示例#17
0
    def test_vario_est(self):
        srf = gs.SRF(self.cmod, seed=12345)
        field = srf.structured((self.lat, self.lon))

        bin_edges = [0.01 * i for i in range(30)]
        bin_center, emp_vario = gs.vario_estimate(
            *((self.lat, self.lon), field, bin_edges),
            latlon=True,
            mesh_type="structured",
            sampling_size=2000,
            sampling_seed=12345,
        )
        mod = gs.Gaussian(latlon=True, rescale=gs.EARTH_RADIUS)
        mod.fit_variogram(bin_center, emp_vario, nugget=False)
        # allow 10 percent relative error
        self.assertLess(_rel_err(mod.var, self.cmod.var), 0.1)
        self.assertLess(_rel_err(mod.len_scale, self.cmod.len_scale), 0.1)
示例#18
0
 def error_test(self):
     # try fitting directional variogram
     mod = gs.Gaussian(latlon=True)
     with self.assertRaises(ValueError):
         mod.fit_variogram([0, 1], [[0, 1], [0, 1], [0, 1]])
     # try to use fixed dim=2 with latlon
     with self.assertRaises(ValueError):
         ErrMod(latlon=True)
     # try to estimate latlon vario on wrong dim
     with self.assertRaises(ValueError):
         gs.vario_estimate([[1], [1], [1]], [1], [0, 1], latlon=True)
     # try to estimate directional vario with latlon
     with self.assertRaises(ValueError):
         gs.vario_estimate([[1], [1]], [1], [0, 1], latlon=True, angles=1)
     # try to create a vector field with latlon
     with self.assertRaises(ValueError):
         srf = gs.SRF(mod, generator="VectorField", mode_no=2)
         srf([1, 2])
示例#19
0
 def test_shape_3d(self):
     self.cov_model.dim = 3
     srf = gs.SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
     field_str = srf(
         (self.x_grid, self.y_grid, self.z_grid),
         seed=self.seed,
         mesh_type="structured",
     )
     field_unstr = srf(
         (self.x_tuple, self.y_tuple, self.z_tuple),
         seed=987654,
         mesh_type="unstructured",
     )
     self.assertEqual(
         field_str.shape,
         (len(self.x_grid), len(self.y_grid), len(self.z_grid)),
     )
     self.assertEqual(field_unstr.shape, (len(self.x_tuple), ))
 def test_auto_fit(self):
     x = y = range(60)
     pos = gs.generate_grid([x, y])
     model = gs.Gaussian(dim=2, var=1, len_scale=10)
     srf = gs.SRF(model,
                  seed=20170519,
                  normalizer=gs.normalizer.LogNormal())
     srf(pos)
     ids = np.arange(srf.field.size)
     samples = np.random.RandomState(20210201).choice(ids,
                                                      size=60,
                                                      replace=False)
     # sample conditioning points from generated field
     cond_pos = pos[:, samples]
     cond_val = srf.field[samples]
     krige = gs.krige.Ordinary(
         model=gs.Stable(dim=2),
         cond_pos=cond_pos,
         cond_val=cond_val,
         normalizer=gs.normalizer.BoxCox(),
         fit_normalizer=True,
         fit_variogram=True,
     )
     # test fitting during kriging
     self.assertTrue(np.abs(krige.normalizer.lmbda - 0.0) < 1e-1)
     self.assertAlmostEqual(krige.model.len_scale, 10.2677, places=4)
     self.assertAlmostEqual(
         krige.model.sill,
         krige.normalizer.normalize(cond_val).var(),
         places=4,
     )
     # test fitting during vario estimate
     bin_center, gamma, normalizer = gs.vario_estimate(
         cond_pos,
         cond_val,
         normalizer=gs.normalizer.BoxCox,
         fit_normalizer=True,
     )
     model = gs.Stable(dim=2)
     model.fit_variogram(bin_center, gamma)
     self.assertAlmostEqual(model.var, 0.6426670183, places=4)
     self.assertAlmostEqual(model.len_scale, 9.635193952, places=4)
     self.assertAlmostEqual(model.nugget, 0.001617908408, places=4)
     self.assertAlmostEqual(model.alpha, 2.0, places=4)
示例#21
0
    def test_transform(self):
        self.cov_model.dim = 2
        srf = gs.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")
        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")
        values = [-1, 0, 0.5, 1]
        tf.discrete(srf, values, thresholds="equal")
        np.testing.assert_array_equal(np.unique(srf.field), values)
示例#22
0
import meshio
import gstools as gs

# generate a triangulated hexagon with meshzoo
points, cells = meshzoo.ngon(6, 4)
mesh = meshio.Mesh(points, {"triangle": cells})

###############################################################################
# Now we prepare the SRF class as always. We will generate an ensemble of
# fields on the generated mesh.

# number of fields
fields_no = 12
# model setup
model = gs.Gaussian(dim=2, len_scale=0.5)
srf = gs.SRF(model, mean=1)

###############################################################################
# To generate fields on a mesh, we provide a separate method: :any:`SRF.mesh`.
# First we generate fields on the mesh-centroids controlled by a seed.
# You can specify the field name by the keyword `name`.

for i in range(fields_no):
    srf.mesh(mesh, points="centroids", name="c-field-{}".format(i), seed=i)

###############################################################################
# Now we generate fields on the mesh-points again controlled by a seed.

for i in range(fields_no):
    srf.mesh(mesh, points="points", name="p-field-{}".format(i), seed=i)
示例#23
0
For :math:`\ell_{\mathrm{low}}=0` this results in:

.. math::
   \gamma_{\ell_{\mathrm{up}}}(r) &=
   \sigma^2_{\ell_{\mathrm{up}}}\cdot\left(1-
   \frac{2H}{\alpha} \cdot
   E_{1+\frac{2H}{\alpha}}
   \left[\left(\frac{r}{\ell_{\mathrm{up}}}\right)^{\alpha}\right]
   \right) \\
   \sigma^2_{\ell_{\mathrm{up}}} &=
   C\cdot\frac{\ell_{\mathrm{up}}^{2H}}{2H}
"""
import numpy as np
import gstools as gs

x = y = np.linspace(0, 100, 100)
model = gs.TPLStable(
    dim=2,  # spatial dimension
    var=1,  # variance (C is calculated internally, so variance is actually 1)
    len_low=0,  # lower truncation of the power law
    len_scale=10,  # length scale (a.k.a. range), len_up = len_low + len_scale
    nugget=0.1,  # nugget
    anis=0.5,  # anisotropy between main direction and transversal ones
    angles=np.pi / 4,  # rotation angles
    alpha=1.5,  # shape parameter from the stable model
    hurst=0.7,  # hurst coefficient from the power law
)
srf = gs.SRF(model, mean=1.0, seed=19970221)
srf.structured([x, y])
srf.plot()
示例#24
0
import pyvista as pv

import gstools as gs

###############################################################################
# We create a structured grid with PyVista containing 50 segments on all three
# axes each with a length of 2 (whatever unit).

dim, spacing = (50, 50, 50), (2, 2, 2)
grid = pv.UniformGrid(dim, spacing)

###############################################################################
# Now we set up the SRF class as always. We'll use an anisotropic model.

model = gs.Gaussian(dim=3, len_scale=[16, 8, 4], angles=(0.8, 0.4, 0.2))
srf = gs.SRF(model, seed=19970221)

###############################################################################
# The PyVista mesh can now be directly passed to the :any:`SRF.mesh` method.
# When dealing with meshes, one can choose if the field should be generated
# on the mesh-points (`"points"`) or the cell-centroids (`"centroids"`).
#
# In addition we can set a name, under which the resulting field is stored
# in the mesh.

srf.mesh(grid, points="points", name="random-field")

###############################################################################
# Now we have access to PyVista's abundancy of methods to explore the field.
#
# .. note::
示例#25
0
"""
import numpy as np
import gstools as gs
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

###############################################################################
# Generating synthetic field with anisotropy and rotation by Tait-Bryan angles.

dim = 3
# rotation around z, y, x
angles = [np.deg2rad(90), np.deg2rad(45), np.deg2rad(22.5)]
model = gs.Gaussian(dim=3, len_scale=[16, 8, 4], angles=angles)
x = y = z = range(50)
pos = (x, y, z)
srf = gs.SRF(model, seed=1001)
field = srf.structured(pos)

###############################################################################
# Here we generate the axes of the rotated coordinate system
# to get an impression what the rotation angles do.

# All 3 axes of the rotated coordinate-system
main_axes = gs.rotated_main_axes(dim, angles)
axis1, axis2, axis3 = main_axes

###############################################################################
# Now we estimate the variogram along the main axes. When the main axes are
# unknown, one would need to sample multiple directions and look for the one
# with the longest correlation length (flattest gradient).
# Then check the transversal directions and so on.
示例#26
0
Artificial data
^^^^^^^^^^^^^^^

Here we generate log-normal data following a Gaussian covariance model.
We will generate the "original" field on a 60x60 mesh, from which we will take
samples in order to pretend a situation of data-scarcity.
"""
import numpy as np
import gstools as gs
import matplotlib.pyplot as plt

# structured field with edge length of 50
x = y = range(51)
pos = gs.generate_grid([x, y])
model = gs.Gaussian(dim=2, var=1, len_scale=10)
srf = gs.SRF(model, seed=20170519, normalizer=gs.normalizer.LogNormal())
# generate the original field
srf(pos)

###############################################################################
# Here, we sample 60 points and set the conditioning points and values.

ids = np.arange(srf.field.size)
samples = np.random.RandomState(20210201).choice(ids, size=60, replace=False)

# sample conditioning points from generated field
cond_pos = pos[:, samples]
cond_val = srf.field[samples]

###############################################################################
# Fitting and Interpolation
示例#27
0
"""
Combinations
------------

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()

###############################################################################
# The resulting field could be interpreted as a transmissivity field, where
# the values of low permeability are the ones being the most connected
# and only two kinds of soil exist.
示例#28
0
import gstools as gs

# mainly for setting a white background
pv.set_plot_theme("document")

###############################################################################
# create a uniform grid with PyVista
dims, spacing, origin = (40, 30, 10), (1, 1, 1), (-10, 0, 0)
mesh = pv.UniformGrid(dims=dims, spacing=spacing, origin=origin)

###############################################################################
# create an incompressible random 3d velocity field on the given mesh
# with added mean velocity in x-direction
model = gs.Gaussian(dim=3, var=3, len_scale=1.5)
srf = gs.SRF(model, mean=(0.5, 0, 0), generator="VectorField", seed=198412031)
srf.mesh(mesh, points="points", name="Velocity")

###############################################################################
# Now, we can do the plotting
streamlines = mesh.streamlines(
    "Velocity",
    terminal_speed=0.0,
    n_points=800,
    source_radius=2.5,
)

# set a fancy camera position
cpos = [(25, 23, 17), (0, 10, 0), (0, 0, 1)]

p = pv.Plotter()
示例#29
0
 def setUp(self):
     model = gs.Exponential(dim=3, len_scale=[12, 6, 3])
     x = y = z = range(10)
     self.pos = (x, y, z)
     srf = gs.SRF(model, seed=123456)
     self.field = srf((x, y, z), mesh_type="structured")
示例#30
0
# fix the seed for reproducibility
seed = 20170521
# spatial axis of 50km with a resolution of 1km
x = np.arange(0, 50, 1.0)
# half daily timesteps over three months
t = np.arange(0.0, 90.0, 0.5)

# total spatio-temporal dimension
st_dim = 1 + 1
# space-time anisotropy ratio given in units d / km
st_anis = 0.4

# an exponential variogram with a corr. lengths of 2d and 5km
model = gs.Exponential(dim=st_dim, var=1.0, len_scale=5.0, anis=st_anis)
# create a spatial random field instance
srf = gs.SRF(model, seed=seed)

pos, time = [x], [t]

# a Gaussian random field which is also saved internally for the transformations
srf.structured(pos + time)
P_gau = copy.deepcopy(srf.field)

###############################################################################
# Next, we could take care of the dry periods. Therefore we would simply
# introduce a lower threshold value. But we will combine this step with the
# next one. Anyway, for demonstration purposes, we will also do it with the
# threshold value now.

threshold = 0.85
P_cut = copy.deepcopy(srf.field)