Skip to content

Commit fd05229

Browse files
authored
Merge pull request #347 from GeoStat-Framework/fix_integral_spectal_density
Integral model: separate calculation at origin for spectral density
2 parents af19c44 + cf2ae45 commit fd05229

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/gstools/covmodel/models.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -460,21 +460,21 @@ def cor(self, h):
460460

461461
def spectral_density(self, k): # noqa: D102
462462
k = np.asarray(k, dtype=np.double)
463-
x = (k * self.len_rescaled / 2.0) ** 2
463+
fac = (0.5 * self.len_rescaled / np.sqrt(np.pi)) ** self.dim
464+
lim = fac * self.nu / (self.nu + self.dim)
464465
# for nu > 50 we just use an approximation of the gaussian model
465466
if self.nu > 50.0:
466-
return (
467-
(0.5 * self.len_rescaled / np.sqrt(np.pi)) ** self.dim
468-
* np.exp(-x)
469-
* self.nu
470-
/ (self.nu + self.dim)
471-
* (1.0 + 2 * x / (self.nu + self.dim + 2))
472-
)
473-
return (
474-
self.nu
475-
/ (x ** (self.nu * 0.5) * 2 * (k * np.sqrt(np.pi)) ** self.dim)
476-
* inc_gamma_low((self.nu + self.dim) / 2.0, x)
477-
)
467+
x = (k * self.len_rescaled / 2) ** 2
468+
return lim * np.exp(-x) * (1 + 2 * x / (self.nu + self.dim + 2))
469+
# separate calculation at origin
470+
s = (self.nu + self.dim) / 2
471+
res = np.empty_like(k)
472+
k_gz = np.logical_not(np.isclose(k, 0))
473+
x = (k[k_gz] * self.len_rescaled / 2) ** 2
474+
# limit at k=0 (inc_gamma_low(s, x) / x**s -> 1/s for x -> 0)
475+
res[np.logical_not(k_gz)] = lim
476+
res[k_gz] = 0.5 * self.nu * fac / x**s * inc_gamma_low(s, x)
477+
return res
478478

479479
def calc_integral_scale(self): # noqa: D102
480480
return (

0 commit comments

Comments
 (0)