<jupyter_start><jupyter_text>lidisa `lidisa` is a **li**ghtweight implementation of **di**rect **s**ampling in Python. This is a simplified version of the algorithm described in *The Direct Sampling method to perform multiple‐point geostatistical simulations* published by Mariethoz, <NAME> Straubhaar in *Water Resources Research* (2010). It requires only `numpy` and `numba` as dependencies and makes use of the `numba` just-in-time compiler to significantly speed up sampling. `lidisa` is able to conduct both conditional and unconditional sampling of new images based on training data. This notebook shows a short workflow for using the direct sampler to create a new image based on a training image.<jupyter_code>from lidisa import dsampler
import numpy as np
import matplotlib.pyplot as plt
training_image = np.load('./data/sample_image.npy') # 40 x 40 pixel 2D Numpy array
simulator = dsampler(training_image,sampling_mode='unconditional',radius=4,threshold=0.4)<jupyter_output><empty_output><jupyter_text>`simulator` is a generator and we may use it to iteratively create new randomly sampled images. The state of the simulation is retained in `simulator`.<jupyter_code>out = [x for x in simulator]<jupyter_output><empty_output><jupyter_text>As we can see, many of the patterns from the training image are reproduced in the random realization!<jupyter_code>fig,axes = plt.subplots(1,2,figsize = (8,4))
axes[0].imshow(out[-1],vmin=0,vmax=6), axes[1].imshow(training_image,vmin=0,vmax=6)
axes[0].set_title('Randomly generated'),axes[1].set_title('Training image')
[ax.axis('off') for ax in axes];<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup