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

Bugfix 1.2.1 #75

Merged
merged 10 commits into from
Apr 14, 2020
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1313628.svg)](https://doi.org/10.5281/zenodo.1313628)
[![PyPI version](https://badge.fury.io/py/gstools.svg)](https://badge.fury.io/py/gstools)
[![Conda Version](https://img.shields.io/conda/vn/conda-forge/gstools.svg)](https://anaconda.org/conda-forge/gstools)
[![Build Status](https://travis-ci.org/GeoStat-Framework/GSTools.svg?branch=master)](https://travis-ci.org/GeoStat-Framework/GSTools)
[![Build Status](https://travis-ci.com/GeoStat-Framework/GSTools.svg?branch=master)](https://travis-ci.com/GeoStat-Framework/GSTools)
[![Coverage Status](https://coveralls.io/repos/github/GeoStat-Framework/GSTools/badge.svg?branch=master)](https://coveralls.io/github/GeoStat-Framework/GSTools?branch=master)
[![Documentation Status](https://readthedocs.org/projects/gstools/badge/?version=stable)](https://geostat-framework.readthedocs.io/projects/gstools/en/stable/?badge=stable)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
Expand Down
4 changes: 2 additions & 2 deletions examples/07_transformations/02_discrete.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
discrete fields
-------------
Discrete fields
---------------

Here we transform a field to a discrete field with values.
If we do not give thresholds, the pairwise means of the given
Expand Down
2 changes: 1 addition & 1 deletion gstools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@

try:
from gstools._version import __version__
except ModuleNotFoundError: # pragma: nocover
except ImportError: # pragma: nocover
# package is not installed
__version__ = "0.0.0.dev0"

Expand Down
11 changes: 11 additions & 0 deletions gstools/covmodel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ def correlation(self, r):
1 + 0.5 / self.alpha * (r / self.len_scale) ** 2, -self.alpha
)

def calc_integral_scale(self): # noqa: D102
return (
self.len_scale
* np.sqrt(np.pi * self.alpha * 0.5)
* sps.gamma(self.alpha - 0.5)
/ sps.gamma(self.alpha)
)


# Stable Model ################################################################

Expand Down Expand Up @@ -325,6 +333,9 @@ def correlation(self, r):
r = np.array(np.abs(r), dtype=np.double)
return np.exp(-np.power(r / self.len_scale, self.alpha))

def calc_integral_scale(self): # noqa: D102
return self.len_scale * sps.gamma(1.0 + 1.0 / self.alpha)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-) That looks a lot faster

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is!!



# Matérn Model ################################################################

Expand Down
4 changes: 2 additions & 2 deletions gstools/transform/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def discrete(fld, values, thresholds="arithmetic"):
fld : :any:`Field`
Spatial Random Field class containing a generated field.
Field will be transformed inplace.
values : :any:`np.ndarray`
values : :any:`numpy.ndarray`
The discrete values the field will take
thresholds : :class:`str` or :any:`np.ndarray`, optional
thresholds : :class:`str` or :any:`numpy.ndarray`, optional
the thresholds, where the value classes are separated
possible values are:
* "arithmetic": the mean of the 2 neighbouring values
Expand Down
2 changes: 1 addition & 1 deletion gstools/variogram/estimator.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ cdef inline void normalization_cressie(
if counts[i] == 0:
counts[i] = 1
variogram[i] = (
(1./counts[i] * variogram[i])**4 /
0.5 * (1./counts[i] * variogram[i])**4 /
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that!

(0.457 + 0.494 / counts[i] + 0.045 / counts[i]**2)
)

Expand Down
18 changes: 11 additions & 7 deletions gstools/variogram/variogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


def _set_estimator(estimator):
"""Translate the verbose Python estimator identifier to single char"""
"""Translate the verbose Python estimator identifier to single char."""
if estimator.lower() == "matheron":
cython_estimator = "m"
elif estimator.lower() == "cressie":
Expand Down Expand Up @@ -50,16 +50,18 @@ def vario_estimate_unstructured(
\gamma(r_k) = \frac{1}{2 N(r_k)} \sum_{i=1}^{N(r_k)} (z(\mathbf x_i) -
z(\mathbf x_i'))^2 \; ,

with :math:`r_k \leq \| \mathbf x_i - \mathbf x_i' \| < r_{k+1}` being the bins.
with :math:`r_k \leq \| \mathbf x_i - \mathbf x_i' \| < r_{k+1}`
being the bins.

Or if the estimator "cressie" was chosen:

.. math::
\gamma(r_k) = \frac{\left(\frac{1}{N(r_k)} \sum_{i=1}^{N(r_k)}
\gamma(r_k) = \frac{\frac{1}{2}\left(\frac{1}{N(r_k)}\sum_{i=1}^{N(r_k)}
\left|z(\mathbf x_i) - z(\mathbf x_i')\right|^{0.5}\right)^4}
{0.457 + 0.494 / N(r_k) + 0.045 / N^2(r_k)} \; ,

with :math:`r_k \leq \| \mathbf x_i - \mathbf x_i' \| < r_{k+1}` being the bins.
with :math:`r_k \leq \| \mathbf x_i - \mathbf x_i' \| < r_{k+1}`
being the bins.
The Cressie estimator is more robust to outliers.

Notes
Expand Down Expand Up @@ -133,16 +135,18 @@ def vario_estimate_structured(field, direction="x", estimator="matheron"):
\gamma(r_k) = \frac{1}{2 N(r_k)} \sum_{i=1}^{N(r_k)} (z(\mathbf x_i) -
z(\mathbf x_i'))^2 \; ,

with :math:`r_k \leq \| \mathbf x_i - \mathbf x_i' \| < r_{k+1}` being the bins.
with :math:`r_k \leq \| \mathbf x_i - \mathbf x_i' \| < r_{k+1}`
being the bins.

Or if the estimator "cressie" was chosen:

.. math::
\gamma(r_k) = \frac{\left(\frac{1}{N(r_k)} \sum_{i=1}^{N(r_k)}
\gamma(r_k) = \frac{\frac{1}{2}\left(\frac{1}{N(r_k)}\sum_{i=1}^{N(r_k)}
\left|z(\mathbf x_i) - z(\mathbf x_i')\right|^{0.5}\right)^4}
{0.457 + 0.494 / N(r_k) + 0.045 / N^2(r_k)} \; ,

with :math:`r_k \leq \| \mathbf x_i - \mathbf x_i' \| < r_{k+1}` being the bins.
with :math:`r_k \leq \| \mathbf x_i - \mathbf x_i' \| < r_{k+1}`
being the bins.
The Cressie estimator is more robust to outliers.

Warnings
Expand Down
5 changes: 2 additions & 3 deletions tests/test_variogram_structured.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_list(self):
def test_cressie_1d(self):
z = [41.2, 40.2, 39.7, 39.2, 40.1, 38.3, 39.1, 40.0, 41.1, 40.3]
gamma = variogram.vario_estimate_structured(z, estimator="cressie")
self.assertAlmostEqual(gamma[1], 1.546, places=3)
self.assertAlmostEqual(gamma[1], 1.546 / 2.0, places=3)

def test_1d(self):
# literature values
Expand Down Expand Up @@ -169,8 +169,7 @@ def test_uncorrelated_cressie_2d(self):
field, direction="y", estimator="cressie"
)

# TODO figure out what is going on here
var = 0.177
var = 1.0 / 12.0
self.assertAlmostEqual(gamma_x[0], 0.0, places=1)
self.assertAlmostEqual(gamma_x[len(gamma_x) // 2], var, places=1)
self.assertAlmostEqual(gamma_y[0], 0.0, places=1)
Expand Down