krigekit.variogram_empirical#
Empirical variogram clouds, binning, directions, and anisotropy estimates.
Functions#
|
Compute the raw empirical variogram cloud (all admissible pairs). |
|
Traditional (LMC) cross-variogram cloud on collocated data. |
|
Cross-variogram cloud between two co-located variables A and B. |
|
Bin a variogram cloud and average it. |
|
Perpendicular distance from offset vectors |
|
Boolean mask selecting pairs aligned with azimuth_anis. |
|
Estimate anisotropy directions from a variogram cloud via weighted PCA. |
|
Fit the 3-D anisotropy orientation by a model-based profile search. |
|
Mean variogram as a function of azimuth, within a near-origin radius. |
|
Experimental directional variograms along arbitrary (2D/3D) axes. |
Module Contents#
- krigekit.variogram_empirical.raw_vgm(coords, vals, cutoff=np.inf, times=None, t_cutoff=np.inf, calc_angle=False, maxobs=None, nmax=None, metric=None, seed=None, verbose=True, great_circle=False, anisotropy=None, n_jobs=None, max_memory_fraction=0.8)#
Compute the raw empirical variogram cloud (all admissible pairs).
- Parameters:
coords (array-like, shape (n, dim)) – Sample coordinates;
dimmay be 1, 2 or 3.vals (array-like, shape (n,)) – Sample values.
cutoff (float, optional) – Maximum spatial lag
|h|to keep (default: no cutoff).times (array-like, optional) – Per-sample time stamps for a space-time variogram.
t_cutoff (float, optional) – Maximum absolute time lag to keep.
calc_angle (bool, optional) – Also compute
angle_h(andangle_vin 3D) for each pair.maxobs (int, optional) – Randomly subsample to at most
maxobspoints before pairing.seed (int, optional) – Random seed for the subsampling.
verbose (bool, optional) – Print a progress indicator.
great_circle (bool, optional) – Treat 2D coordinates as
(lon, lat)in degrees and use the great-circle distance (km) for thedistancelag andcutoff.anisotropy (dict, optional) – Arguments accepted by
calc_anisotropic_lag(). When supplied,cutoffis applied to the equivalent major-axis lag and the cloud includes ananisotropic_distancecolumn. The physical Euclidean lag remains available asdistance.n_jobs (int, optional) – Number of worker threads for vectorized pair chunks.
None(default) chooses adaptively from the post-maxobscandidate-pair count, up to four workers.1is sequential and-1uses all available CPUs.max_memory_fraction (float or None, optional) – Refuse clouds whose estimated final numeric columns exceed this fraction of currently available RAM (default 0.8).
Nonedisables the safety check.
- Returns:
pandas.DataFrame – The variogram cloud (see module docstring for the columns).
- krigekit.variogram_empirical.raw_cross_vgm(coords, valsA, valsB, cutoff=np.inf, times=None, t_cutoff=np.inf, calc_angle=False, maxobs=None, nmax=None, metric=None, seed=None, verbose=True, anisotropy=None, n_jobs=None, max_memory_fraction=0.8)#
Traditional (LMC) cross-variogram cloud on collocated data.
Both variables are measured at the same
coords(isotopic data). Pairs are formed within the single point set and the cross-semivariance:gamma_AB(h) = 0.5 * (A_i - A_j) * (B_i - B_j)
is stored in the
variogramcolumn. Unlike the pseudo estimator incross_vgm(), this is symmetric in A/B, its sill is the LMC cross-sill you can feed into cokriging, and it costs O(n**2 / 2) rather than O(nA*nB).The returned cloud has exactly the same columns as
raw_vgm(), so it flows straight intoavg_vgm(),estimate_aniso_angle(),directional_vgm()and the variogram-map plots. Calling it withvalsB is valsAreproduces the direct variogram of A.For heterotopic data (A and B at different locations) the true cross-variogram is not computable; use
cross_vgm()(pseudo estimator) or restrict to a collocated subset before calling this function.n_jobs=Noneadaptively selects up to four pair-chunk workers aftermaxobsand cutoff candidate generation.1is sequential and-1uses all available CPUs.max_memory_fractiondefaults to 0.8 and raisesMemoryErrorwhen the estimated final cloud exceeds that fraction of available RAM. PassNoneto disable the guard.
- krigekit.variogram_empirical.cross_vgm(coordsA, valsA, coordsB, valsB, cutoff=np.inf, residual=True, timesA=None, timesB=None, t_cutoff=np.inf, calc_angle=False, maxobs=None, maxobsA=None, maxobsB=None, seed=None, verbose=True, anisotropy=None, n_jobs=None, max_memory_fraction=0.8)#
Cross-variogram cloud between two co-located variables A and B.
Pairs are formed across the two data sets (every A vs every B). When
residualis True the means are removed first so the result is a cross-covariance-style estimator.Warning
This is the pseudo cross-variogram
0.5 * E[(A(x) - B(x+h))**2], not the linear-model-of-coregionalisation (LMC) cross-variogram0.5 * E[(A(x) - A(x+h)) * (B(x) - B(x+h))]. Its sill mixesvar(A) + var(B) - 2*cov(A, B), so do not read an LMC cross-sill directly off it. For heterotopic data (A and B at different locations) the true cross-variogram is not computable and this pseudo form is a reasonable substitute; for a cokriging cross-sill, derivecov(A, B)from collocated hard-data pairs instead.n_jobs=Noneadaptively selects up to four pair-chunk workers after subsampling and cutoff candidate generation.1is sequential and-1uses all available CPUs.max_memory_fractiondefaults to 0.8 and raisesMemoryErrorwhen the estimated final cloud exceeds that fraction of available RAM. PassNoneto disable the guard.
- krigekit.variogram_empirical.avg_vgm(rawvgm, h_col='distance', t_col=None, cutoff=None, t_cutoff=None, h_width=None, t_width=None, h_bins=None, t_bins=None, tor_hori=None, tor_vert=None, angleh=None, anglev=None, angleh_tor=15, anglev_tor=10, robust=None, estimator='matheron', vgm_col='variogram')#
Bin a variogram cloud and average it.
Supports distance (and optional time) binning, directional and bandwidth filtering, and either the classic (Matheron) mean or the robust Cressie–Hawkins estimator (
estimator="cressie"), Dowd ("dowd"), or Genton.h_widthandt_widthmay be positive scalars for fixed-width bins or one-dimensional arrays of explicit bin edges. Edge-array bins are left-closed and right-open, except that the final edge is included; lags outside the edge range are omitted. Arrays passed through the legacyh_binsandt_binsarguments use the same edge convention.Directional filtering follows variogram-axis symmetry. If only
anglehis supplied, azimuthsanglehandangleh + 180are treated as the same horizontal axis. If bothanglehandanglevare supplied, the same 3D axis is represented by(angleh, anglev)and the reversed lag vector(angleh + 180, -anglev).- Returns:
pandas.DataFrame – Grouped variogram table whose columns are a
(variable, statistic)MultiIndex with statisticsmean,stdandcount. The averaged semivariogram is available asresult[(vgm_col, "mean")].
- krigekit.variogram_empirical.distance_pnt_line(dx, dy, azimuth)#
Perpendicular distance from offset vectors
(dx, dy)to a line through the origin with the given azimuth (degrees, clockwise from +Y).
- krigekit.variogram_empirical.filter_vgm(dx, dy, azimuth, azimuth_anis, bandwidth=None, angle_tol=10)#
Boolean mask selecting pairs aligned with azimuth_anis.
This is a 2D/horizontal-axis helper. A pair is kept when its azimuth is within
angle_tolof the target axis, treatingazimuth_anisandazimuth_anis + 180as equivalent. Ifbandwidthis given, the pair must also fall withinbandwidth / 2of the directional line.For 3D azimuth+dip filtering, use
avg_vgm(), which flips the sign of dip for the reversed azimuth.
- krigekit.variogram_empirical.estimate_aniso_angle(rawvgm, x='d0', y='d1', dist='distance', vgm='variogram', r_max=None, z='d2', dim3d=False, robust=False, get_eigens=False, dx=None, dy=None, dz=None)#
Estimate anisotropy directions from a variogram cloud via weighted PCA.
Near-origin lags are grouped into cells, each cell weighted inversely by its (normalised) mean variogram – low variogram means strong continuity – and an eigen-decomposition of the weighted second moment about the origin yields the principal axes. Each cell contributes its mean lag vector (not the bin edge), so the estimate is insensitive to the bin size. Bins are sized per axis from each axis’s own lag extent, so a thin or short axis (e.g. a shallow
zslab) is still resolved rather than collapsing under a single horizontal-scale spacing. Passdx/dy/dzto override the spacing per axis.The estimate is sensitive to
r_max: too small and a gridded cloud is dominated by axis-aligned lags (the sampling lattice – which can throw the azimuth off by tens of degrees), too large and it mixes nested structures. A good choice is roughly half the shortest structure’s range. Sweepingr_maxto find a stable value does not help reliably – there is no clean plateau – so prefer one principled near-origin radius. This is an approximate orientation estimate (a few degrees at best), best used to seed a fixed-orientation fit (VariogramModel.fit_anisotropy()), not as a final answer.- Returns:
If ``get_eigens`` is True (
(eigvals, eigvecs)sorted descending.)If ``dim3d`` is False (
((azimuth_deg,), (anis1,)).)If ``dim3d`` is True (
((azimuth_deg, dip_deg, plunge_deg), (anis1, anis2)).)azimuth_degis the compass azimuth (0 = North, 90 = East) of the major(maximum-continuity) axis,
dip_degits tilt below the horizontal plane(positive downward), and
plunge_degthe twist of the minor axes aboutthe major axis – exactly the
azimuth/dip/plungeconvention ofthe model and the Fortran engine, so the angles feed straight into
VariogramModel.set_vgm().anis1andanis2are theminor1/major and minor2/major axis-length ratios (the same meaning as the
engine’s
anis1/anis2minor-axis ratios), estimated from theeigenvalue spectrum.
plungeis folded into(-90, 90]and is theleast well-determined angle from sparse clouds.
- krigekit.variogram_empirical.fit_aniso_angle(rawvgm, n_struct=1, x='d0', y='d1', z='d2', dist='distance', vgm='variogram', n_bins=16, starts=None, use_seed=True, max_nfev=500)#
Fit the 3-D anisotropy orientation by a model-based profile search.
Unlike
estimate_aniso_angle()(a fast PCA of the lag cloud), this fits the model to the data: for each candidate orientation,n_structspherical structures’ sills and anisotropic ranges are fitted with the orientation held fixed, against a denoised binned cloud, and the orientation giving the lowest residual is kept. The objective is multi-modal, so the search is multi-started over a coarse(azimuth, dip)grid plus theestimate_aniso_angle()seed.Returns
((azimuth, dip, plunge), (anis1, anis2))– the same shape asestimate_aniso_angle()– butanis1/anis2are the fitted minor/major range ratios of the strongest structure (true ratios, not the PCA spread proxy).This is far more robust on scattered, strongly anisotropic clouds, where the PCA seed can be tens of degrees wrong, at a higher cost. It is not immune to a regular sampling lattice: on gridded clouds the lattice biases the residual, and the near-origin PCA seed may be better. Spherical structures are used as the orientation probe regardless of the eventual model type.
- Parameters:
rawvgm (pandas.DataFrame) – Raw variogram cloud with signed lag columns
x/y/zand avgmvalue column.n_struct (int) – Number of nested spherical structures to fit while probing orientation.
n_bins (int) – Cells per cutoff radius for the denoising bins (lag cells use the cell mean lag vector, so the result is insensitive to the exact bin size).
starts (sequence of (azimuth, dip, plunge), optional) – Override the default coarse start grid.
use_seed (bool) – Also start from the
estimate_aniso_angle()PCA estimate.
- krigekit.variogram_empirical.estimate_angle_angular_profile(rawvgm, angle='angle_h', dist='distance', r_profile=None, da=10, a_tol=2.5, close=False, vgm='variogram', dim3d=False)#
Mean variogram as a function of azimuth, within a near-origin radius.
Sweeps the azimuth in steps of da degrees (overlapping by
a_tol) and returns the per-sector mean ofangle,distandvgm.
- krigekit.variogram_empirical.directional_vgm(rawvgm, directions, h_width=None, h_bins=15, bandwidth=None, angle_tol=22.5, dist='distance', vgm='variogram', robust=False, dim=None)#
Experimental directional variograms along arbitrary (2D/3D) axes.
For each direction the pairs whose lag vector falls within
angle_tolof that axis (and within the perpendicularbandwidth) are selected and binned by lag distance – the multi-dimensional analogue of the gstoolsvario_estimate(direction=...)workflow.- Parameters:
rawvgm (DataFrame) – Variogram cloud with
d0..d{dim-1}lag components.directions (array-like, shape (n_dir, dim)) – Direction vectors (need not be normalised). Use
rotation_matrix_3d()to obtain a rotated orthonormal axis set.h_width (float, optional) – Fixed bin width applied to every direction. When
None(default) the width is computed per direction asmax_proj / h_bins, wheremax_projis the largest projected lag along that axis. This gives equal resolution across all axes regardless of range, which matters for strongly anisotropic data where a single cutoff-derived width would leave the short-range axes with very few bins.h_bins (int) – Number of bins per direction when
h_widthisNone.bandwidth (float, optional) – Maximum perpendicular distance from the directional line.
angle_tol (float, optional) – Angular tolerance (degrees) between a lag and the direction.
- Returns:
DataFrame – Long format with columns
direction(axis index),lag(mean projected lag in the bin),variogramandcount.