QMCPy logo¶
Generate three lightweight scatter-plot logos from a two-dimensional randomized digital net, deterministic digital net, and lattice transformed to a zero-mean multivariate normal distribution with covariance [[2, 1], [1, 3]]. The deterministic net starts at index 1 because its origin maps to non-finite Gaussian coordinates.
In [1]:
Copied!
from pathlib import Path
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import numpy as np
from qmcpy import DigitalNetB2, Gaussian, Lattice
n = 128
seed = 7
covariance = np.array([[2.0, 1.0], [1.0, 3.0]])
assert np.all(np.linalg.eigvalsh(covariance) > 0)
configurations = (
(DigitalNetB2(dimension=2, seed=seed), "_net", 0),
(Lattice(dimension=2, seed=seed), "_lattice", 0),
(DigitalNetB2(dimension=2, randomize=False, order="GRAY"), "_det_net", 1),
)
# Work whether Jupyter starts in the repository root or in demos/.
start = Path.cwd().resolve()
repo_root = None
for path in (start, *start.parents):
if (path / "pyproject.toml").exists() and (path / "qmcpy").is_dir():
repo_root = path
break
if repo_root is None:
raise RuntimeError(
"Could not locate repository root (expected pyproject.toml and qmcpy/). Run this notebook from within the QMCSoftware repository."
)
current_logo = repo_root / "docs" / "assets" / "logos" / "qmcpy_logo.png"
from pathlib import Path
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import numpy as np
from qmcpy import DigitalNetB2, Gaussian, Lattice
n = 128
seed = 7
covariance = np.array([[2.0, 1.0], [1.0, 3.0]])
assert np.all(np.linalg.eigvalsh(covariance) > 0)
configurations = (
(DigitalNetB2(dimension=2, seed=seed), "_net", 0),
(Lattice(dimension=2, seed=seed), "_lattice", 0),
(DigitalNetB2(dimension=2, randomize=False, order="GRAY"), "_det_net", 1),
)
# Work whether Jupyter starts in the repository root or in demos/.
start = Path.cwd().resolve()
repo_root = None
for path in (start, *start.parents):
if (path / "pyproject.toml").exists() and (path / "qmcpy").is_dir():
repo_root = path
break
if repo_root is None:
raise RuntimeError(
"Could not locate repository root (expected pyproject.toml and qmcpy/). Run this notebook from within the QMCSoftware repository."
)
current_logo = repo_root / "docs" / "assets" / "logos" / "qmcpy_logo.png"
In [2]:
Copied!
# Read the dominant opaque RGB color from the present logo.
rgba = mpimg.imread(current_logo)
opaque_rgb = rgba[..., :3][rgba[..., 3] > 0.99]
rgb, counts = np.unique(
np.round(opaque_rgb * 255).astype(np.uint8), axis=0, return_counts=True
)
logo_color = rgb[counts.argmax()] / 255
# Read the dominant opaque RGB color from the present logo.
rgba = mpimg.imread(current_logo)
opaque_rgb = rgba[..., :3][rgba[..., 3] > 0.99]
rgb, counts = np.unique(
np.round(opaque_rgb * 255).astype(np.uint8), axis=0, return_counts=True
)
logo_color = rgb[counts.argmax()] / 255
In [3]:
Copied!
for sampler, output_suffix, start_index in configurations:
normal = Gaussian(sampler, mean=np.zeros(2), covariance=covariance)
points = normal(n_min=start_index, n_max=start_index + n, warn=False)
target = repo_root / "docs" / "logos" / f"qmcpy_logo{output_suffix}.png"
target.parent.mkdir(parents=True, exist_ok=True)
fig, ax = plt.subplots(figsize=(8, 8), facecolor="none")
ax.scatter(points[:, 0], points[:, 1], s=150, color=logo_color, edgecolors="none")
ax.set_aspect("equal")
center = (points.min(axis=0) + points.max(axis=0)) / 2
radius = np.ptp(points, axis=0).max() * 0.54
ax.set_xlim(center[0] - radius, center[0] + radius)
ax.set_ylim(center[1] - radius, center[1] + radius)
ax.axis("off")
fig.subplots_adjust(left=0, right=1, bottom=0, top=1)
fig.savefig(target, dpi=196, transparent=True)
saved_logo = mpimg.imread(target)
print(f"Wrote: {target.relative_to(repo_root)}")
# Verifty all PNG outputs are transparent 1568 x 1568 RGBA
assert saved_logo.shape == (1568, 1568, 4) # Square RGBA image
assert saved_logo[..., 3].min() == 0 # Has transparent pixels
assert saved_logo[..., 3].max() == 1 # Has opaque pixels
plt.show()
for sampler, output_suffix, start_index in configurations:
normal = Gaussian(sampler, mean=np.zeros(2), covariance=covariance)
points = normal(n_min=start_index, n_max=start_index + n, warn=False)
target = repo_root / "docs" / "logos" / f"qmcpy_logo{output_suffix}.png"
target.parent.mkdir(parents=True, exist_ok=True)
fig, ax = plt.subplots(figsize=(8, 8), facecolor="none")
ax.scatter(points[:, 0], points[:, 1], s=150, color=logo_color, edgecolors="none")
ax.set_aspect("equal")
center = (points.min(axis=0) + points.max(axis=0)) / 2
radius = np.ptp(points, axis=0).max() * 0.54
ax.set_xlim(center[0] - radius, center[0] + radius)
ax.set_ylim(center[1] - radius, center[1] + radius)
ax.axis("off")
fig.subplots_adjust(left=0, right=1, bottom=0, top=1)
fig.savefig(target, dpi=196, transparent=True)
saved_logo = mpimg.imread(target)
print(f"Wrote: {target.relative_to(repo_root)}")
# Verifty all PNG outputs are transparent 1568 x 1568 RGBA
assert saved_logo.shape == (1568, 1568, 4) # Square RGBA image
assert saved_logo[..., 3].min() == 0 # Has transparent pixels
assert saved_logo[..., 3].max() == 1 # Has opaque pixels
plt.show()