feat: add gstools.mps — Multiple Point Statistics via Direct Sampling#416
Draft
n0228a wants to merge 11 commits into
Draft
feat: add gstools.mps — Multiple Point Statistics via Direct Sampling#416n0228a wants to merge 11 commits into
n0228a wants to merge 11 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
gstools.mpssubpackage implementing Multiple Point Statistics (MPS)simulation via the Direct Sampling (DS) algorithm (Mariethoz et al. 2010) with
the DSBC parametrization (Juda et al. 2022). MPS is a fundamentally different
paradigm from two-point geostatistics: instead of a parametric covariance model,
spatial structure is learned directly from a training image (TI), enabling
reproduction of curvilinear, connected patterns — channels, fractures, categorical
facies — that variogram-based methods cannot capture.
Supersedes #409.
Public API
Four classes exported from
gstools.mps.DirectSampling,MPSModel, andTrainingImageare also available at the top-levelgstoolsnamespace;Variableis available asgstools.mps.Variable.VariableHolds one variable's data and its per-variable configuration:
data— n-D NumPy arraycategorical— whether to use weighted mismatch distance (Mariethoz2010 Eq. 3)distance— continuous metric:"l1"(Juda2022 Eq. 7, default),"l2","l<p>"(arbitrary Minkowski),"variation"or"variation<p>"(Mariethoz2010Eq. 9, with automatic mean-shift correction)
n_neighbors— data-event size (maximum neighbours, default 32)max_radius— optional Euclidean cap on neighbour selectionweight— relative weight in the multivariate joint distance;Nonefor equalshare; weights are automatically normalized and do not need to sum to 1
TrainingImageThe MPS analogue of
CovModel. Three construction modes:Shared option:
distance_power— spatial-decay exponent δ for neighbourweighting (Mariethoz2010 Eq. 5);
0.0(default) gives uniform weights.NaN masking — undefined TI cells (NaN) are excluded from distance
comparisons and never pasted into the simulation grid.
MPSModelConfiguration object bundling a
TrainingImagewith search parameters:scan_fraction,threshold,cond_weight,boundary.DirectSamplingSubclasses
gstools.field.base.Fieldand follows the same call interface asSRF. Takes anMPSModel.All search parameters (
scan_fraction,threshold,cond_weight,boundary,n_neighbors,max_radius) are read-only onDirectSampling— theyreflect the underlying
MPSModelandVariableobjects.n_neighborsandmax_radiuscollapse to a scalar when all variables share the same value,otherwise return a
{name: value}dict. To change them, mutate theMPSModelor
Variabledirectly.Key capabilities:
"sequential"or an explicit(N, dim)visit-order array via thepathargument
scan_fractioncaps the per-node TI scan (Juda2022 §2)threshold=0.0— DSBC mode: full scan, best-candidate selectionboundary="strict"(default) or"partial"— partial drops lags that exceedthe TI extent and searches with the reduced template (Mariethoz2010 §6.2)
set_condition(cond_pos, cond_val)— hard-data conditioning with nearest-nodesnapping and per-variable collision resolution;
cond_valaccepts a{variable: array}dict for multivariate TIs, withnp.nanto leave avariable unconditioned at a point; conditioning weight is set via
MPSModelset_nonstationary()— per-node rotation and anisotropy maps for geometriclag transform (Mariethoz2010 §6.2); enables spatially varying orientation
without modifying the TI
set_mv_transforms()— per-variable mean / normalizer / trend post-processingnum_threads(orgstools.config.NUM_THREADS)path_seed,node_seed) for independent control of visitorder vs. TI scan randomness
{variable: ndarray}dict; each variable alsostored as a named field accessible via
ds["facies"]/ds.all_fieldsUsage
Module layout
training_image.pyVariable,TrainingImage— data and distance functionsdata_event.pyDataEvent— internal value object bundling per-variable data-event arraysdistance.pymodel.pyMPSModel— validated search-parameter configneighbors.pyscan.pyrunner.pysimulate.py_DirectSamplingEngine+ds_simulateentry pointdirect_sampling.pyDirectSampling— publicFieldsubclassExamples (
examples/13_mps/)00_simple_unconditional.py01_conditional.pyset_condition()02_continuous.py03_channel_strebelle.py04_channel_strebelle_nonstat.py05_channel_strebelle_radial.py06_channel_multivariate_fig8.py07_variation_distance_fig6.py08_bivariate_joint_fig4.py09_continuous_stone_fig3.py00_mps_overview.ipynbReferences
to perform multiple-point geostatistical simulations. Water Resources Research.
https://doi.org/10.1029/2008WR007621
the Direct Sampling algorithm for multiple-point statistical simulations.
Applied Computing and Geosciences.
https://doi.org/10.1016/j.acags.2022.100091
using multiple-point statistics. Mathematical Geology.