Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variogram fitting update #78

Merged
merged 32 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
178298b
CovModel: set default default_values for opt-args to 0
MuellerSeb Mar 28, 2020
b878826
covmodel: better check for opt-args in init
MuellerSeb Mar 28, 2020
f4d7f99
tests: blackened again
MuellerSeb Mar 28, 2020
d6fd0cb
Examples: add example to find best variogram model
MuellerSeb Mar 28, 2020
2eb23be
examples: blackened again
MuellerSeb Mar 28, 2020
bcd0836
covmodels: add formula for integral scale of rational and stable models
MuellerSeb Mar 28, 2020
0fb9b11
covmodel: update the fitting routine; more finetuning possible now; c…
MuellerSeb Mar 28, 2020
50e2a52
examples: update best model example with auto calc r2
MuellerSeb Mar 28, 2020
0649e61
variogram: fix cressie bug
MuellerSeb Mar 28, 2020
cbcef65
tests: fix cressie tests
MuellerSeb Mar 28, 2020
309428a
tests: better plotting for sphinx [skip ci]
MuellerSeb Mar 28, 2020
7d4bc26
covmodel: separate function to check if arg in bounds of model
MuellerSeb Mar 29, 2020
b17b476
covmodel fit: allow fixing the sill of the model during estimation
MuellerSeb Mar 29, 2020
2ddd396
covmodel fit: better flag name if sill is constrained
MuellerSeb Mar 29, 2020
651b817
covmodel fit: allow specifying fixed values for each parameter
MuellerSeb Mar 29, 2020
912b641
covmodel plot: determine plot range by len_scale not int_scale
MuellerSeb Mar 29, 2020
5cc4abd
covmodel: saver calculation of spectral_rad_pdf by taking abs values …
MuellerSeb Mar 29, 2020
fad698b
variogram: updated DOC (cressie correction)
MuellerSeb Mar 30, 2020
15e2d80
covmodel.tools: better setting for angles
MuellerSeb Apr 14, 2020
a856ea2
RNG.sample_sphere: allow arbitrary dim; better check for passed size
MuellerSeb Apr 14, 2020
6536328
Tests: more tests on vario fitting
MuellerSeb Apr 19, 2020
c6c4bdc
CovModel: saver setting of arg-bounds; allow resetting args
MuellerSeb Apr 20, 2020
747081d
Tests: check bounds setting
MuellerSeb Apr 20, 2020
fc9e2e4
Travis: don't build forks of base-repo twice
MuellerSeb Apr 20, 2020
ba731d8
CovModel.fit: better handling of fitting bounds; check it
MuellerSeb Apr 20, 2020
4d51020
fit: no cover for logistic weights (experimental)
MuellerSeb Apr 20, 2020
a24a53f
remove redundant no cover comment (already in .coveragerc)
MuellerSeb Apr 20, 2020
cd757f4
Fit: some code-style updates
MuellerSeb Apr 20, 2020
60b80ea
Models: better check for cdf/ppf when present; update code-style
MuellerSeb Apr 20, 2020
889ef70
Export: remove double import of pyvista; code-style update
MuellerSeb Apr 20, 2020
1c0428d
Variogram: 'mathoron' typo fix
MuellerSeb Apr 20, 2020
3a1be89
CovModel.fit: distribute function on smaller helper functions
MuellerSeb Apr 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# do not build pull request from base repo twice (only build PRs of forks)
if: type != pull_request OR fork = true

# language is python
language: python
python: 3.8

Expand Down
2 changes: 1 addition & 1 deletion examples/02_cov_model/00_intro.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# use CovModel as the base-class
class Gau(gs.CovModel):
def cor(self, h):
return np.exp(-h ** 2)
return np.exp(-(h ** 2))


###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion examples/02_cov_model/05_additional_para.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def default_opt_arg(self):
return {"alpha": 1.5}

def cor(self, h):
return np.exp(-h ** self.alpha)
return np.exp(-(h ** self.alpha))


###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion examples/02_cov_model/06_fitting_para_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def default_opt_arg(self):
return {"alpha": 1.5}

def cor(self, h):
return np.exp(-h ** self.alpha)
return np.exp(-(h ** self.alpha))


# Exemplary variogram data (e.g. estimated from field observations)
Expand Down
6 changes: 3 additions & 3 deletions examples/03_variogram/01_variogram_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def generate_transmissivity():
# dashed lines.

plt.figure() # new figure
line, = plt.plot(bin_center, gamma, label="estimated variogram (isotropic)")
(line,) = plt.plot(bin_center, gamma, label="estimated variogram (isotropic)")
plt.plot(
bin_center,
fit_model.variogram(bin_center),
Expand All @@ -239,7 +239,7 @@ def generate_transmissivity():
label="exp. variogram (isotropic)",
)

line, = plt.plot(x_plot, gamma_x[:21], label="estimated variogram in x-dir")
(line,) = plt.plot(x_plot, gamma_x[:21], label="estimated variogram in x-dir")
plt.plot(
x_plot,
fit_model_x.variogram(x_plot),
Expand All @@ -248,7 +248,7 @@ def generate_transmissivity():
label="exp. variogram in x-dir",
)

line, = plt.plot(y_plot, gamma_y[:21], label="estimated variogram in y-dir")
(line,) = plt.plot(y_plot, gamma_y[:21], label="estimated variogram in y-dir")
plt.plot(
y_plot,
fit_model_y.variogram(y_plot),
Expand Down
64 changes: 64 additions & 0 deletions examples/03_variogram/02_find_best_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
Finding the best fitting variogram model
----------------------------------------
"""
import numpy as np
import gstools as gs
from matplotlib import pyplot as plt

###############################################################################
# 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 = gs.Exponential(dim=2, var=2, len_scale=8)
srf = gs.SRF(model, mean=0, seed=19970221)
field = srf((x, y))

###############################################################################
# Estimate the variogram of the field with 40 bins and plot the result.

bins = np.arange(40)
bin_center, gamma = gs.vario_estimate_unstructured((x, y), field, bins)

###############################################################################
# Define a set of models to test.

models = {
"gaussian": gs.Gaussian,
"exponential": gs.Exponential,
"matern": gs.Matern,
"stable": gs.Stable,
"rational": gs.Rational,
"linear": gs.Linear,
"circular": gs.Circular,
"spherical": gs.Spherical,
}
scores = {}

###############################################################################
# Iterate over all models, fit their variogram and calculate the r2 score.

# plot the estimated variogram
plt.scatter(bin_center, gamma, label="data")
ax = plt.gca()

# fit all models to the estimated variogram
for model in models:
fit_model = models[model](dim=2)
para, pcov, r2 = fit_model.fit_variogram(bin_center, gamma, return_r2=True)
fit_model.plot(x_max=40, ax=ax)
scores[model] = r2

###############################################################################
# Create a ranking based on the score and determine the best models

ranking = [
(k, v)
for k, v in sorted(scores.items(), key=lambda item: item[1], reverse=True)
]
print("RANKING")
for i, (model, score) in enumerate(ranking, 1):
print(i, model, score)

plt.show()
Loading