Transform 22
Tutorials

# Check Random Sampling

%matplotlib widget
import matplotlib.pyplot as plt
plt.ioff()
# turn of warnings
import warnings
warnings.filterwarnings('ignore')
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import gstools as gs

"""Direction on the unit sphere."""
vec = np.array(vec, ndmin=2)
norm = np.zeros(vec.shape[1])
for i in range(vec.shape[0]):
norm += vec[i] ** 2
norm = np.sqrt(norm)
return np.einsum("j,ij->ij", 1 / norm, vec), norm

def plot_rand_meth_samples(generator):
"""Plot the samples of the rand meth class."""

fig = plt.figure(figsize=(10, 4))

if generator.model.dim == 3:
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
x = np.outer(np.cos(u), np.sin(v))
y = np.outer(np.sin(u), np.sin(v))
z = np.outer(np.ones(np.size(u)), np.cos(v))
ax.plot_surface(x, y, z, rstride=4, cstride=4, color="b", alpha=0.1)
ax.scatter(norm[0], norm[1], norm[2])
elif generator.model.dim == 2:
u = np.linspace(0, 2 * np.pi, 100)
x = np.cos(u)
y = np.sin(u)
ax.plot(x, y, color="b", alpha=0.1)
ax.scatter(norm[0], norm[1])
ax.set_aspect("equal")
else:
ax.bar(-1, np.sum(np.isclose(norm, -1)), color="C0")
ax.bar(1, np.sum(np.isclose(norm, 1)), color="C0")
ax.set_xticks([-1, 1])
ax.set_xticklabels(("-1", "1"))
ax.set_title("Direction sampling")

x = np.linspace(0, 10 / generator.model.integral_scale)
plot_rand_meth_samples(srf.generator)