G2S: The GeoStatistical Server

An extensible geostatistical framework connecting programming interfaces to simulation algorithms through a shared server.

SNESIM

SNESIM is a categorical multiple-point simulation algorithm based on a search-tree representation of training-image patterns. In G2S it is exposed as a separate algorithm intended for categorical simulation problems and multi-grid workflows.

Parameters for SNESIM

Usage: result = g2s(flag1, value1, flag2, value2, ...)

Schema outputs include result["simulation"] / result.simulation, result["time"] / result.time, result["progress"] / result.progress, and result["job_id"] / result.job_id.

Flag Description Mandatory
-ti Training image or list of training images. SNESIM currently expects categorical data. ✔
-di Destination image (simulation grid). NaN values are simulated and non-NaN values are used as conditioning data. ✔
-dt Data type. For SNESIM this should describe categorical variables, typically 1 for each variable. ✔
-ii Training-image index image. Use this to select which training image is used at each simulated node.  
-j Number of worker threads. Decimal values in ]0,1[ represent a fraction of the available logical cores.  
-mg Maximum multigrid level. The execution proceeds from this level down to 0.  
-tpl Template radius. A value of 3 means offsets in [-3,+3]. Provide one value per dimension if needed.  
--tree-strategy Tree-selection strategy. Supported values are first, ii, and merged. Default: merged.  
-tree-root Root directory used for the SNESIM tree cache.  
-force-tree Force a rebuild of the tree cache instead of reusing cached trees.  
-s Random seed.  

Examples

#This code requires the G2S server to be running

import numpy
from PIL import Image
import requests
from io import BytesIO
from g2s import g2s
import matplotlib.pyplot as plt

# load example training image ('strebelle') from same repo path style
url = "https://raw.githubusercontent.com/GAIA-UNIL/TrainingImagesTIFF/master/strebelle.tiff"
resp = requests.get(url, timeout=30)
resp.raise_for_status()
ti_raw = numpy.array(Image.open(BytesIO(resp.content)))

# SNESIM call using G2S
# 5 grid levels total: 4 -> 3 -> 2 -> 1 -> 0 (because -mg is the max level)
_schema_result = g2s(
    '-a', 'snesim',
    '-ti', ti_raw,
    '-di', numpy.zeros((1000, 1000)) * numpy.nan,
    '-dt', [1],                   # 1 => categorical
    '-j', 0.5,
    '-mg', 4,
    '-tpl', 3
)
simulation = _schema_result["simulation"]
t = _schema_result.get("time")

print("SNESIM duration:", t)

# display results
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(7, 4))
fig.suptitle('SNESIM Unconditional simulation', size='xx-large')
ax1.imshow(ti_raw, cmap='tab20')
ax1.set_title('Training image (categorical)')
ax1.axis('off')
ax2.imshow(simulation, cmap='tab20')
ax2.set_title('Simulation')
ax2.axis('off')
plt.show()

%This code requires the G2S server to be running

% This code requires the G2S server to be running.
% load example training image ('strebelle')
url = 'https://raw.githubusercontent.com/GAIA-UNIL/TrainingImagesTIFF/master/strebelle.tiff';
try
    ti = imread(url);
catch
    % Older MATLAB releases may not support direct HTTP reads with imread.
    localTi = websave(fullfile(tempdir, 'strebelle.tiff'), url);
    ti = imread(localTi);
end
ti = single(ti);

% SNESIM call using G2S
% 5 grid levels total: 4 -> 3 -> 2 -> 1 -> 0 (because -mg is the max level)
schemaResult = g2s('-a', 'snesim', ...
                            '-ti', single(ti), ...
                            '-di', single(nan(1000, 1000)), ...
                            '-dt', [1], ...
                            '-j', 1.001, ...
                            '-mg', 4, ...
                            '-tpl', 3);
simulation = schemaResult.simulation;
elapsed = schemaResult.time;

fprintf('SNESIM duration: %.3f s\n', elapsed);

% Display results
figure;
sgtitle('SNESIM unconditional simulation');
subplot(1, 2, 1);
imagesc(ti);
title('Training image (Strebelle)');
axis image off;
subplot(1, 2, 2);
imagesc(simulation);
title('Simulation');
axis image off;
colormap(parula);

Notes

  • SNESIM is intended for categorical variables.
  • The multigrid controls are specific to this algorithm.
  • Tree caching is managed internally by the executable and can be controlled with -tree-root and -force-tree.