Beispiel #1
0
    def test_rescale(self):
        model1 = Exponential()
        model2 = Exponential(rescale=2.1)
        model3 = Exponential(rescale=2.1, len_scale=2.1)

        self.assertAlmostEqual(model1.integral_scale,
                               2.1 * model2.integral_scale)
        self.assertAlmostEqual(model1.integral_scale, model3.integral_scale)
Beispiel #2
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
                    )
Beispiel #3
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])
Beispiel #4
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)
###############################################################################
# estimate the variogram on an unstructured grid ##############################
###############################################################################

bins = np.linspace(0, 10, 50)
print('Estimating unstructured variogram')
bin_center, gamma = vario_estimate_unstructured(
    (x_u, y_u),
    herten_log_trans.reshape(-1),
    bins,
    sampling_size=2000,
    sampling_seed=19920516,
)

# fit an exponential model
fit_model = Exponential(dim=2)
fit_model.fit_variogram(bin_center, gamma, nugget=False)

pt.plot(bin_center, gamma)
plot_variogram(fit_model, x_max=bins[-1])

###############################################################################
# estimate the variogram on a structured grid #################################
###############################################################################

# estimate the variogram on a structured grid
# use only every 10th value, otherwise calculations would take very long
x_s_skip = x_s[::10]
y_s_skip = y_s[::10]
herten_trans_skip = herten_log_trans[::10, ::10]
Beispiel #6
0
p.show()

###############################################################################
# Variogram Analysis
# ^^^^^^^^^^^^^^^^^^
#
# Next, we need to compute a variogram for the temperature probe data and fit that variogram to an exponential model

bins = np.linspace(0, 12300, 1000)
bin_center, gamma = vario_estimate_unstructured(
    project["Observed Temperature"].points.T,
    project["Observed Temperature"]["temperature (C)"],
    bins,
)

fit_model = Exponential(dim=3)
fit_model.fit_variogram(bin_center, gamma, nugget=False)

plt.figure(figsize=(10, 5))
plt.plot(bin_center, gamma)
plot_variogram(fit_model, x_max=bins[-1], ax=plt.gca())
plt.xlabel("Lag Distance")
plt.ylabel("Variogram")
plt.show()

###############################################################################
# Performing the Kriging
# ^^^^^^^^^^^^^^^^^^^^^^
# Then we pass the fitted exponential model when instantiating the kriging operator from GSTools.

# Create the kriging model
Beispiel #7
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()
Beispiel #8
0
import numpy as np
import matplotlib.pyplot as plt
from gstools import SRF, Gaussian, Exponential

# the grid
x = np.arange(100)
y = np.arange(100)

# a smooth Gaussian covariance model
model = Gaussian(dim=2, var=1, len_scale=10)

srf = SRF(model, generator='VectorField')
srf((x, y), mesh_type='structured', seed=19841203)
srf.plot()

# a rougher exponential covariance model
model2 = Exponential(dim=2, var=1, len_scale=10)

srf.model = model2
srf((x, y), mesh_type='structured', seed=19841203)
srf.plot()