Skip to content

Commit

Permalink
blackened examples [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
MuellerSeb committed Aug 29, 2019
1 parent a2f7d5a commit 6d45b54
Show file tree
Hide file tree
Showing 20 changed files with 161 additions and 103 deletions.
1 change: 1 addition & 0 deletions examples/00_gaussian.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from gstools import SRF, Gaussian

# 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)
Expand Down
19 changes: 10 additions & 9 deletions examples/01_tpl_stable.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import numpy as np
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
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)
srf.structured([x, y])
Expand Down
5 changes: 3 additions & 2 deletions examples/02_fit_variogram.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
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.
y = np.random.RandomState(20011012).rand(1000) * 100.
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))
Expand Down
42 changes: 25 additions & 17 deletions examples/03_cov_model.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from gstools import CovModel
import numpy as np

# use CovModel as the base-class
class Gau(CovModel):
def correlation(self, r):
return np.exp(-(r/self.len_scale)**2)
return np.exp(-(r / self.len_scale) ** 2)


model = Gau(dim=2, var=2., len_scale=10)
model = Gau(dim=2, var=2.0, len_scale=10)

from gstools.covmodel.plot import plot_variogram

plot_variogram(model)

print(model.dim, model.var, model.len_scale, model.nugget, model.sill)
Expand All @@ -17,49 +20,53 @@ def correlation(self, r):
model.nugget = 0.1
print(model.dim, model.var, model.len_scale, model.nugget, model.sill)

model = Gau(dim=3, var=2., len_scale=10, anis=0.5)
model = Gau(dim=3, var=2.0, len_scale=10, anis=0.5)
print(model.anis)
print(model.len_scale_vec)

model = Gau(dim=3, var=2., len_scale=[10, 5, 4])
model = Gau(dim=3, var=2.0, len_scale=[10, 5, 4])
print(model.anis)
print(model.len_scale)
print(model.len_scale_vec)

model = Gau(dim=3, var=2., len_scale=10, angles=2.5)
model = Gau(dim=3, var=2.0, len_scale=10, angles=2.5)
print(model.angles)

model = Gau(dim=3, var=2., len_scale=10, nugget=0.5)
print(model.variogram(10.))
print(model.variogram_normed(10.))
print(model.covariance(10.))
print(model.correlation(10.))
model = Gau(dim=3, var=2.0, len_scale=10, nugget=0.5)
print(model.variogram(10.0))
print(model.variogram_normed(10.0))
print(model.covariance(10.0))
print(model.correlation(10.0))

model = Gau(dim=3, var=2., len_scale=10)
model = Gau(dim=3, var=2.0, len_scale=10)
print(model.spectrum(0.1))
print(model.spectral_density(0.1))

model = Gau(dim=3, var=2., len_scale=10)
model = Gau(dim=3, var=2.0, len_scale=10)
print(model.integral_scale)
print(model.integral_scale_vec)

model = Gau(dim=3, var=2., integral_scale=[10, 4, 2])
model = Gau(dim=3, var=2.0, integral_scale=[10, 4, 2])
print(model.anis)
print(model.len_scale)
print(model.len_scale_vec)
print(model.integral_scale)
print(model.integral_scale_vec)

model = Gau(dim=3, var=2., len_scale=10)
model = Gau(dim=3, var=2.0, len_scale=10)
print(model.percentile_scale(0.9))


class Stab(CovModel):
def default_opt_arg(self):
return {"alpha": 1.5}

def correlation(self, r):
return np.exp(-(r/self.len_scale)**self.alpha)
model1 = Stab(dim=2, var=2., len_scale=10)
model2 = Stab(dim=2, var=2., len_scale=10, alpha=0.5)
return np.exp(-(r / self.len_scale) ** self.alpha)


model1 = Stab(dim=2, var=2.0, len_scale=10)
model2 = Stab(dim=2, var=2.0, len_scale=10, alpha=0.5)
print(model1)
print(model2)

Expand All @@ -73,6 +80,7 @@ def correlation(self, r):
results, pcov = model.fit_variogram(x, y, nugget=False)
print(results)
from matplotlib import pyplot as plt

plt.cla()
plt.scatter(x, y, color="k")
plot_variogram(model)
Expand Down
3 changes: 2 additions & 1 deletion examples/04_export.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from gstools import SRF, Gaussian

x = y = range(100)
model = Gaussian(dim=2, var=1, len_scale=10)
srf = SRF(model)
field = srf((x, y), mesh_type='structured')
field = srf((x, y), mesh_type="structured")
srf.vtk_export("field")
4 changes: 2 additions & 2 deletions examples/05_srf_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
field = []
seed = MasterRNG(20170519)
for i in range(ens_no):
field.append(srf((x, y), seed=seed(), mesh_type='structured'))
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')
ax[i].imshow(field[i].T, origin="lower")

pt.show()
4 changes: 2 additions & 2 deletions examples/06_unstr_srf_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
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.)
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.axes().set_aspect("equal")
pt.show()
4 changes: 2 additions & 2 deletions examples/07_srf_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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.)
model = Exponential(dim=2, var=1, len_scale=[12.0, 3.0], angles=np.pi / 8.0)

srf = SRF(model, seed=20170519)

Expand All @@ -25,5 +25,5 @@

pt.tricontourf(x, y, field.T)
pt.tricontourf(x2, y2, field2.T)
pt.axes().set_aspect('equal')
pt.axes().set_aspect("equal")
pt.show()
Loading

0 comments on commit 6d45b54

Please sign in to comment.