|
| 1 | +"""TPL-Gaussian model vs. Matern model family.""" |
| 2 | +import os |
| 3 | +import numpy as np |
| 4 | +import matplotlib as mpl |
| 5 | +from matplotlib import pyplot as plt |
| 6 | +import gstools as gs |
| 7 | + |
| 8 | +plt.style.use("default") |
| 9 | +mpl.rc("text", usetex=True) |
| 10 | +mpl.rc("lines", linewidth=3.5) |
| 11 | +plt.close("all") |
| 12 | + |
| 13 | + |
| 14 | +def dashes(i=1, max_d=12, space=1): |
| 15 | + """Dashes for matplotlib.""" |
| 16 | + return i * [space, space] + [max_d - 2 * i * space, space] |
| 17 | + |
| 18 | + |
| 19 | +def format_ax(axis): |
| 20 | + """Format axis.""" |
| 21 | + axis.set_xlim([-0.06, 3.06]) |
| 22 | + axis.set_xticks(range(4)) |
| 23 | + axis.set_xticklabels(["$0$", r"$\ell$", r"$2\ell$", r"$3\ell$"]) |
| 24 | + axis.set_xlabel("distance") |
| 25 | + axis.set_ylabel("semivariance") |
| 26 | + axis.set_ylim([0, 1]) |
| 27 | + axis.grid(linestyle=":") |
| 28 | + axis.legend() |
| 29 | + |
| 30 | + |
| 31 | +save = True |
| 32 | +x = np.geomspace(0.01, 3, 10) |
| 33 | +grid = np.linspace(0, 10, 100) |
| 34 | + |
| 35 | +# Matern(nu=1.5) vs TPL-Gaussian |
| 36 | + |
| 37 | +fig, ax = plt.subplots(figsize=[5, 3]) |
| 38 | + |
| 39 | +m1 = gs.Matern(dim=2, integral_scale=1, nu=1.5) |
| 40 | +fit_m1 = gs.TPLGaussian(dim=2) |
| 41 | +fit_m1.fit_variogram(x, m1.variogram(x), len_low=0, nugget=0) |
| 42 | +m1.plot(ax=ax, x_max=3, label="Matern(nu=1.5)", color="k", linewidth=2) |
| 43 | +fit_m1.plot( |
| 44 | + ax=ax, x_max=3, label="TPL-Gaussian(hurst=1.0)", linestyle=":", color="C0" |
| 45 | +) |
| 46 | + |
| 47 | +print(m1) |
| 48 | +print(fit_m1) |
| 49 | + |
| 50 | +format_ax(ax) |
| 51 | +fig.tight_layout() |
| 52 | +if save: |
| 53 | + fig.savefig( |
| 54 | + os.path.join("..", "results", "06_matern_tpl_1-5.pdf"), dpi=300 |
| 55 | + ) |
| 56 | + fig.show() |
| 57 | + |
| 58 | +# Matern(nu=0.5) vs TPL-Gaussian |
| 59 | + |
| 60 | +fig, ax = plt.subplots(figsize=[5, 3]) |
| 61 | + |
| 62 | +m2 = gs.Matern(dim=2, integral_scale=1, nu=0.5) |
| 63 | +fit_m2 = gs.TPLGaussian(dim=2) |
| 64 | +fit_m2.fit_variogram(x, m2.variogram(x), len_low=0, nugget=0) |
| 65 | +m2.plot(ax=ax, x_max=3, label="Matern(nu=0.5)", color="k", linewidth=2) |
| 66 | +fit_m2.plot( |
| 67 | + ax=ax, x_max=3, label="TPL-Gaussian(hurst=0.45)", linestyle=":", color="C0" |
| 68 | +) |
| 69 | + |
| 70 | +print(m2) |
| 71 | +print(fit_m2) |
| 72 | + |
| 73 | +format_ax(ax) |
| 74 | +fig.tight_layout() |
| 75 | +if save: |
| 76 | + fig.savefig( |
| 77 | + os.path.join("..", "results", "07_matern_tpl_0-5.pdf"), dpi=300 |
| 78 | + ) |
| 79 | + fig.show() |
| 80 | + |
| 81 | +# model families |
| 82 | + |
| 83 | +fig, ax = plt.subplots(figsize=[5, 3]) |
| 84 | + |
| 85 | +gau = gs.Gaussian(integral_scale=1) |
| 86 | +exp = gs.Exponential(integral_scale=1) |
| 87 | +nus = [0.5, 0.75, 1.0, 1.5, 2.0] |
| 88 | +# ax = exp.plot(ax=ax, x_max=3, linestyle="-.", color="k") |
| 89 | +ax = gau.plot(ax=ax, x_max=3, linestyle="-", color="k") |
| 90 | +for i, nu in enumerate(nus): |
| 91 | + m = gs.Matern(integral_scale=1, nu=nu) |
| 92 | + ax = m.plot( |
| 93 | + ax=ax, |
| 94 | + x_max=3, |
| 95 | + label=f"Matern(nu={nu:.2})", |
| 96 | + linewidth=2, |
| 97 | + dashes=dashes(i), |
| 98 | + color="C0", |
| 99 | + ) |
| 100 | +format_ax(ax) |
| 101 | +fig.tight_layout() |
| 102 | +if save: |
| 103 | + fig.savefig(os.path.join("..", "results", "08_matern_family.pdf"), dpi=300) |
| 104 | +fig.show() |
| 105 | + |
| 106 | +fig, ax = plt.subplots(figsize=[5, 3]) |
| 107 | + |
| 108 | +hursts = [0.45, 0.5, 0.6, 0.8, 0.999] |
| 109 | +# ax = exp.plot(ax=ax, x_max=3, linestyle="-.", color="k") |
| 110 | +ax = gau.plot(ax=ax, x_max=3, linestyle="-", color="k") |
| 111 | +for i, hurst in enumerate(hursts): |
| 112 | + m = gs.TPLGaussian(integral_scale=1, hurst=hurst) |
| 113 | + ax = m.plot( |
| 114 | + ax=ax, |
| 115 | + x_max=3, |
| 116 | + label=f"TPL-Gaussian(hurst={hurst:.2})", |
| 117 | + linewidth=2, |
| 118 | + dashes=dashes(i), |
| 119 | + color="C0", |
| 120 | + ) |
| 121 | +format_ax(ax) |
| 122 | +fig.tight_layout() |
| 123 | +if save: |
| 124 | + fig.savefig(os.path.join("..", "results", "09_tpl_family.pdf"), dpi=300) |
| 125 | +fig.show() |
| 126 | + |
| 127 | +# Fields |
| 128 | + |
| 129 | +fig, ax = plt.subplots(figsize=[5, 4]) |
| 130 | +srf = gs.SRF(m1, seed=1234) |
| 131 | +field1a = srf.structured((grid, grid)) |
| 132 | +srf.plot(ax=ax, contour_plot=False) |
| 133 | +ax.set_title("Matern(nu=1.5)") |
| 134 | +fig.tight_layout() |
| 135 | +if save: |
| 136 | + fig.savefig( |
| 137 | + os.path.join("..", "results", "10_field_matern_1-5.pdf"), dpi=300 |
| 138 | + ) |
| 139 | +fig.show() |
| 140 | + |
| 141 | +fig, ax = plt.subplots(figsize=[5, 4]) |
| 142 | +srf = gs.SRF(m2, seed=1234) |
| 143 | +srf.structured((grid, grid)) |
| 144 | +srf.plot(ax=ax, contour_plot=False) |
| 145 | +ax.set_title("Matern(nu=0.5)") |
| 146 | +fig.tight_layout() |
| 147 | +if save: |
| 148 | + fig.savefig( |
| 149 | + os.path.join("..", "results", "11_field_matern_0-5.pdf"), dpi=300 |
| 150 | + ) |
| 151 | +fig.show() |
0 commit comments