Skip to content

Commit

Permalink
vario: add no_data option to vario_estimate_structured (solves #83)
Browse files Browse the repository at this point in the history
  • Loading branch information
MuellerSeb committed Nov 8, 2020
1 parent 73801c9 commit 0abedea
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions gstools/variogram/variogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ def vario_estimate(
return bin_centres, estimates


def vario_estimate_structured(field, direction="x", estimator="matheron"):
def vario_estimate_structured(
field, direction="x", estimator="matheron", no_data=np.nan
):
r"""Estimates the variogram on a regular grid.
The indices of the given direction are used for the bins.
Expand Down Expand Up @@ -314,6 +316,10 @@ def vario_estimate_structured(field, direction="x", estimator="matheron"):
Default: "matheron"
no_data : :class:`float`, optional
Value to identify missing data in the given field.
Default: `numpy.nan`
Returns
-------
:class:`numpy.ndarray`
Expand All @@ -327,12 +333,19 @@ def vario_estimate_structured(field, direction="x", estimator="matheron"):
-----
Internally uses double precision and also returns doubles.
"""
masked = np.ma.is_masked(field)
missing_mask = (
np.isnan(field) if np.isnan(no_data) else np.isclose(field, no_data)
)
missing = np.any(missing_mask)
masked = np.ma.is_masked(field) or missing
if masked:
mask = np.array(np.ma.getmaskarray(field), dtype=np.int32)
field = np.ma.array(field, ndmin=1, dtype=np.double)
if missing:
field.mask = np.logical_or(field.mask, missing_mask)
mask = np.array(np.ma.getmaskarray(field), dtype=np.int32)
else:
field = np.array(field, ndmin=1, dtype=np.double)
missing_mask = None # free space

axis_to_swap = AXIS_DIR.get(direction)
if axis_to_swap is None:
Expand Down

0 comments on commit 0abedea

Please sign in to comment.