예제 #1
0
 def test_assertions(self):
     # self.cov_model.dim = 0
     # self.assertRaises(ValueError, SRF, self.cov_model, self.mean, self.mode_no)
     # self.cov_model.dim = 4
     # self.assertRaises(ValueError, SRF, self.cov_model, self.mean, self.mode_no)
     self.cov_model.dim = 3
     self.cov_model.anis = (0.25, 0.5)
     srf = 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 = 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])
예제 #2
0
 def test_calls(self):
     srf = 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])
예제 #3
0
파일: test_srf.py 프로젝트: muizzk/GSTools
 def test_anisotropy_2d(self):
     self.cov_model.dim = 2
     srf = 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 = 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])
예제 #4
0
 def setUp(self):
     self.test_dir = tempfile.mkdtemp()
     # structured field with a size 100x100x100 and a grid-size of 1x1x1
     x = y = z = range(100)
     model = Gaussian(dim=3, var=0.6, len_scale=20)
     self.srf_structured = SRF(model)
     self.srf_structured((x, y, z), mesh_type="structured")
     # unstrucutred field
     seed = MasterRNG(19970221)
     rng = np.random.RandomState(seed())
     x = rng.randint(0, 100, size=10000)
     y = rng.randint(0, 100, size=10000)
     model = Exponential(
         dim=2, var=1, len_scale=[12.0, 3.0], angles=np.pi / 8.0
     )
     self.srf_unstructured = SRF(model, seed=20170519)
     self.srf_unstructured([x, y])
예제 #5
0
 def test_shape_1d(self):
     self.cov_model.dim = 1
     srf = 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),))
예제 #6
0
    def test_rotation_struct_2d(self):
        self.cov_model.dim = 2
        self.cov_model.anis = 0.25
        srf = SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
        field = srf(
            (self.x_grid_c, self.y_grid_c),
            seed=self.seed,
            mesh_type="structured",
        )

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

        self.assertAlmostEqual(field[0, 0], field_rot[0, -1])
        self.assertAlmostEqual(field[1, 2], field_rot[2, 6])
예제 #7
0
        def fs():
            for seed in range(256):
                srf = SRF(model, seed=seed)

                def f(x, y):
                    # 0 -> -1, 4 -> 1
                    # 0 -> -.25, 1 -> .25
                    return srf((x * .5 - 1.0, y * .5 - .25))

                print(seed)
                yield f
예제 #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 = 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 = 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 test_srf(self):
        D0 = np.array((0.0, 0.0))
        cov_model = Gaussian(dim=2, var=0.01, len_scale=10.0)
        srf = SRF(cov_model, generator="VectorField", seed=5747387)

        sim = Simulation(2, srf, D0, self.T, self.dt)
        sim.initial_condition(self.pos_2d, self.distribution_2d)
        mean_drift = srf.generator.mean_u * (self.T / self.dt)
        sim()
        self.assertAlmostEqual(sim.pos[0, 0], mean_drift, places=0)
        self.assertAlmostEqual(sim.pos[1, 1], 0.0, places=0)
        self.assertAlmostEqual(sim.pos[0, -1], mean_drift, places=0)
예제 #10
0
 def test_anisotropy_3d(self):
     self.cov_model.dim = 3
     srf = 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 = 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_shape_2d(self):
     self.cov_model.dim = 2
     srf = SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
     field_str = srf(
         (self.x_grid, self.y_grid), seed=self.seed, mesh_type="structured"
     )
     field_unstr = srf(
         (self.x_tuple, self.y_tuple),
         seed=self.seed,
         mesh_type="unstructured",
     )
     self.assertEqual(field_str.shape, (len(self.x_grid), len(self.y_grid)))
     self.assertEqual(field_unstr.shape, (len(self.x_tuple),))
예제 #12
0
    def test_extdrift(self):
        ext_drift = []
        cond_drift = []
        for i, grid in enumerate(self.grids):
            dim = i + 1
            model = Exponential(
                dim=dim,
                var=2,
                len_scale=10,
                anis=[0.9, 0.8],
                angles=[2, 1, 0.5],
            )
            srf = 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 = 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
                    )
예제 #13
0
 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)
예제 #14
0
def random_field_generator(function_space,
                           minval=0,
                           maxval=1,
                           var=1e-2,
                           len_scale=1,
                           len_low=0,
                           seed=20170519):
    mesh = function_space.mesh()
    dim = mesh.geometric_dimension()

    model = TPLStable(dim=dim, var=var, len_scale=len_scale, len_low=len_low)
    # model = Exponential(dim=dim, var=var, len_scale=len_scale)  # FIXME: Diego, the exponential model, instead of TPLStable, resulted in some chemical equilibrium errors (returning to previous at the moment)

    srf = SRF(model, seed=seed)

    ndofs = function_space.dim()
    size = int(ndofs**(1 / dim))

    xyz = [range(size) for _ in range(dim)]

    data = srf(xyz, mesh_type="structured")

    # The min and max values of x,y,z in the mesh
    xyz_min = [mesh.coordinates.dat.data[:, i].min() for i in range(dim)]
    xyz_max = [mesh.coordinates.dat.data[:, i].max() for i in range(dim)]

    xyz = [np.linspace(xyz_min[i], xyz_max[i], size) for i in range(dim)]

    datainterp = RegularGridInterpolator(xyz, data)

    # Now make the VectorFunctionSpace corresponding to V.
    W = fire.VectorFunctionSpace(mesh, function_space.ufl_element())

    # Next, interpolate the coordinates onto the nodes of W.
    X = fire.interpolate(mesh.coordinates, W)

    # Make an output function.
    k = fire.Function(function_space, name="Permeability")

    # Use the external data function to interpolate the values of f.
    kdata = np.array([datainterp(xyz) for xyz in X.dat.data_ro])

    # k.dat.data[:] = mydata(X.dat.data_ro)
    k.dat.data[:] = rescale_field(kdata, minval, maxval)[:, 0]

    return k
예제 #15
0
 def test_incomprrandmeth(self):
     self.cov_model = Gaussian(dim=2, var=0.5, len_scale=1.0, mode_no=100)
     srf = 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)
예제 #16
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 = Gaussian(dim=3, len_scale=0.1)
     srf = SRF(model)
     srf.mesh(mesh, points="points")
     self.assertEqual(len(srf.field), 4)
     srf.mesh(mesh, points="centroids")
     self.assertEqual(len(srf.field), 1)
예제 #17
0
    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")
        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)
예제 #18
0
 def test_simple(self):
     for Model in self.cov_models:
         for dim in self.dims:
             model = Model(
                 dim=dim,
                 var=0.5,
                 len_scale=2,
                 anis=[0.1, 1],
                 angles=[0.5, 0, 0],
             )
             srf = SRF(model, self.mean, seed=19970221)
             srf.set_condition(self.cond_pos[:dim], self.cond_val, "simple")
             field_1 = srf.unstructured(self.pos[:dim])
             field_2 = srf.structured(self.pos[:dim])
             for i, val in enumerate(self.cond_val):
                 self.assertAlmostEqual(val, field_1[i], places=2)
                 self.assertAlmostEqual(val, field_2[dim * (i, )], places=2)
예제 #19
0
class TestExport(unittest.TestCase):
    def setUp(self):
        self.test_dir = tempfile.mkdtemp()
        # structured field with a size 100x100x100 and a grid-size of 1x1x1
        x = y = z = range(50)
        model = Gaussian(dim=3, var=0.6, len_scale=20)
        self.srf_structured = SRF(model)
        self.srf_structured((x, y, z), mesh_type="structured")
        # unstrucutred field
        seed = MasterRNG(19970221)
        rng = np.random.RandomState(seed())
        x = rng.randint(0, 100, size=1000)
        y = rng.randint(0, 100, size=1000)
        model = Exponential(dim=2,
                            var=1,
                            len_scale=[12.0, 3.0],
                            angles=np.pi / 8.0)
        self.srf_unstructured = SRF(model, seed=20170519)
        self.srf_unstructured([x, y])

    def tearDown(self):
        # Remove the test data directory after the test
        shutil.rmtree(self.test_dir)

    @unittest.skipIf(not HAS_PYVISTA, "PyVista is not installed.")
    def test_pyvista(self):
        mesh = self.srf_structured.to_pyvista()
        self.assertIsInstance(mesh, pv.RectilinearGrid)
        mesh = self.srf_unstructured.to_pyvista()
        self.assertIsInstance(mesh, pv.UnstructuredGrid)

    def test_pyevtk_export(self):
        # Structured
        sfilename = os.path.join(self.test_dir, "structured")
        self.srf_structured.vtk_export(sfilename)
        self.assertTrue(os.path.isfile(sfilename + ".vtr"))
        # Unstructured
        ufilename = os.path.join(self.test_dir, "unstructured")
        self.srf_unstructured.vtk_export(ufilename)
        self.assertTrue(os.path.isfile(ufilename + ".vtu"))
예제 #20
0
import numpy as np
from gstools import Gaussian, SRF
import matplotlib.pyplot as plt

# condtions
cond_pos = [0.3, 1.9, 1.1, 3.3, 4.7]
cond_val = [0.47, 0.56, 0.74, 1.47, 1.74]
gridx = np.linspace(0.0, 15.0, 151)
# spatial random field class
model = Gaussian(dim=1, var=0.5, len_scale=2)
srf = SRF(model)
srf.set_condition(cond_pos, cond_val, "ordinary")
fields = []
for i in range(100):
    if i % 10 == 0:
        print(i)
    fields.append(srf(gridx, seed=i))
    label = "Conditioned ensemble" if i == 0 else None
    plt.plot(gridx, fields[i], color="k", alpha=0.1, label=label)
plt.plot(gridx, np.full_like(gridx, srf.mean), label="estimated mean")
plt.plot(gridx, np.mean(fields, axis=0), linestyle=":", label="Ensemble mean")
plt.plot(gridx, srf.krige_field, linestyle="dashed", label="kriged field")
plt.scatter(cond_pos, cond_val, color="k", zorder=10, label="Conditions")
plt.legend()
plt.show()
예제 #21
0
"""
Detrended Ordinary Kriging
--------------------------
"""
import numpy as np
from gstools import SRF, Gaussian, krige


def trend(x):
    """Example for a simple linear trend."""
    return x * 0.1 + 1


# synthetic condtions with trend/drift
drift_model = Gaussian(dim=1, var=0.1, len_scale=2)
drift = SRF(drift_model, seed=101)
cond_pos = np.linspace(0.1, 8, 10)
cond_val = drift(cond_pos) + trend(cond_pos)
# resulting grid
gridx = np.linspace(0.0, 15.0, 151)
drift_field = drift(gridx) + trend(gridx)
# kriging
model = Gaussian(dim=1, var=0.1, len_scale=2)
krig_trend = krige.Ordinary(model, cond_pos, cond_val, trend)
krig_trend(gridx)
ax = krig_trend.plot()
ax.scatter(cond_pos, cond_val, color="k", zorder=10, label="Conditions")
ax.plot(gridx, trend(gridx), ":", label="linear trend")
ax.plot(gridx, drift_field, "--", label="original field")
ax.legend()
from ogs5py import OGS, by_id, show_vtk, specialrange
#from matplotlib import pyplot as plt
from gstools import SRF, Gaussian


# discretization and parameters
rad = specialrange(0, 1000, 100, typ="cub")
obs = rad[21]
angles = 32
storage = 1e-3
transmissivity = 1e-4
rate = -1e-3

# covariance model for conductivity field
cov_model = Gaussian(dim=2, var=2, len_scale=100, anis=[1])
srf = SRF(model=cov_model, mean=-9, seed=1000)

# model setup
model = OGS(task_root="pump_2d_steady", task_id="model", output_dir="out")
model.pcs.add_block(
        PCS_TYPE="GROUNDWATER_FLOW", NUM_TYPE="NEW", TIM_TYPE="STEADY")

# generate a radial mesh and geometry ("boundary" polyline)
model.msh.generate("radial", dim=2, rad=rad, angles=angles)
model.gli.generate("radial", dim=2, rad_out=rad[-1], angles=angles)
model.gli.add_points([0.0, 0.0, 0.0], "pwell")

# generate a 2D conductivity field
cond = np.exp(srf.mesh(model.msh))
model.mpd.add(name="conductivity")
model.mpd.add_block(  # edit recent mpd file
예제 #23
0
from gstools import SRF, Gaussian
from gstools import transform as tf

# structured field with a size of 100x100 and a grid-size of 1x1
x = y = range(100)
model = Gaussian(dim=2, var=1, len_scale=10)
srf = SRF(model, seed=20170519)
srf.structured([x, y])
tf.zinnharvey(srf, conn="high")
srf.plot()
예제 #24
0
import numpy as np
import matplotlib.pyplot as plt
from gstools import SRF, TPLStable
x = y = np.linspace(0, 100, 100)
model = TPLStable(
    dim=2,  # spatial dimension
    var=
    1,  # variance (C is calculated internally, so that the 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 = SRF(model, mean=1, mode_no=1000, seed=19970221, verbose=True)
field = srf((x, y), mesh_type='structured', force_moments=True)
# show the field in xy coordinates
plt.imshow(field.T, origin="lower")
plt.show()
                        # round nodes
                        ogs.msh.NODES[:, 1] = np.around(ogs.msh.NODES[:, 1], 0)
                        ogs.msh.NODES[:, 0] = np.around(ogs.msh.NODES[:, 0], 4)
                        ogs.msh.NODES[:, 2] = np.around(ogs.msh.NODES[:, 2], 4)

                        # ------------------------  heterogeneous field -------------------------------- #
                        # get the centroids of the mesh-elements to evaluate the field
                        cent = ogs.msh.centroids_flat
                        # split up in x and z coordinates
                        x = cent[:, 0]
                        z = cent[:, 2]
                        # generate the random field
                        cov_model = Gaussian(dim=dim,
                                             var=var,
                                             len_scale=len_scale)
                        srf = SRF(cov_model, mean=mean, seed=seed)
                        # use unstructured for a 2D vertical mesh
                        field = srf((x, z),
                                    mesh_type='unstructured',
                                    force_moments=True)  #, mode_no=100)
                        # conductivities as log-normal distributed from the field data
                        cond = np.exp(field)
                        from scipy.stats.mstats import gmean, hmean
                        arimean = np.mean(cond)
                        harmean = hmean(cond)
                        geomean = gmean(cond)
                        print("The geometric mean is: " + str(geomean))
                        #plt.hist(field)
                        # show the heterogeneous field
                        plt.figure(figsize=(20, thickness / length * 20))
                        cond_log = np.log10(cond)
예제 #26
0
        label='exp. variogram in y-dir')

pt.legend()
pt.show()

print('semivariogram model (isotropic):\n', fit_model)
print('semivariogram model (in x-dir.):\n', fit_model_x)
print('semivariogram model (in y-dir.):\n', fit_model_y)

###############################################################################
# creating a SRF from the Herten parameters ###################################
###############################################################################

from gstools import SRF

srf = SRF(fit_model, seed=19770928)
print('Calculating SRF')
new_herten = srf((x_s, y_s), mesh_type='structured')

pt.imshow(new_herten.T, origin='lower')
pt.show()

###############################################################################
# cleanup #####################################################################
###############################################################################

# comment all in case you want to keep the data for playing around with it
os.remove('data.zip')
os.remove('scripts.zip')
rmtree('Herten-analog')
rmtree('tools')
예제 #27
0
import numpy as np
from gstools import SRF, Exponential, Stable, vario_estimate_unstructured

# generate a synthetic field with an exponential model
x = np.random.RandomState(19970221).rand(1000) * 100.0
y = np.random.RandomState(20011012).rand(1000) * 100.0
model = Exponential(dim=2, var=2, len_scale=8)
srf = SRF(model, mean=0, seed=19970221)
field = srf((x, y))
# estimate the variogram of the field with 40 bins
bins = np.arange(40)
bin_center, gamma = vario_estimate_unstructured((x, y), field, bins)
# fit the variogram with a stable model. (no nugget fitted)
fit_model = Stable(dim=2)
fit_model.fit_variogram(bin_center, gamma, nugget=False)
# output
ax = fit_model.plot(x_max=40)
ax.plot(bin_center, gamma)
print(fit_model)
예제 #28
0
import numpy as np
import matplotlib.pyplot as pt
from gstools import SRF, Exponential
from gstools.random import MasterRNG
from gstools import vtk_export

# creating our own unstructured grid
seed = MasterRNG(19970221)
rng = np.random.RandomState(seed())
x = rng.randint(0, 100, size=10000)
y = rng.randint(0, 100, size=10000)

model = Exponential(dim=2, var=1, len_scale=[12., 3.], angles=np.pi / 8.)

srf = SRF(model, seed=20170519)

field = srf((x, y))

vtk_export('field', (x, y), field)

pt.tricontourf(x, y, field.T)
pt.axes().set_aspect('equal')
pt.show()
예제 #29
0
import numpy as np
import matplotlib.pyplot as pt
from gstools import SRF, Gaussian
from gstools.random import MasterRNG

x = y = np.arange(100)

model = Gaussian(dim=2, var=1, len_scale=10)
srf = SRF(model)

ens_no = 4
field = []
seed = MasterRNG(20170519)
for i in range(ens_no):
    field.append(srf((x, y), seed=seed(), mesh_type="structured"))

fig, ax = pt.subplots(2, 2, sharex=True, sharey=True)
ax = ax.flatten()
for i in range(ens_no):
    ax[i].imshow(field[i].T, origin="lower")

pt.show()
예제 #30
0
import numpy as np
import matplotlib.pyplot as pt
from gstools import SRF, Exponential
from gstools.random import MasterRNG

# creating our own unstructured grid
seed = MasterRNG(19970221)
rng = np.random.RandomState(seed())
x = rng.randint(0, 100, size=10000)
y = rng.randint(0, 100, size=10000)

model = Exponential(dim=2, var=1, len_scale=[12.0, 3.0], angles=np.pi / 8.0)

srf = SRF(model, seed=20170519)

field = srf((x, y))
srf.vtk_export("field")

pt.tricontourf(x, y, field.T)
pt.axes().set_aspect("equal")
pt.show()