Docs landing page: a real diffraction frame in the hero, and the command with a model

The generated spot-and-ring drawing is replaced by one 0.2 deg rotation frame of the in-house
lysozyme standard (EIGER2 16M, SLS X10SA): Bragg spots on their lunes, the beam stop and its arm,
the module gaps. docs/landing/hero_frame.py makes the 920 px WebP (67 KB) from the master
file - crop about the beam centre, log tone map from the frame's own background, block mean+max
downsampling - and is run by hand; the WebP is committed and copied by the landing-page step.
The dark theme shows it inverted through a CSS filter.

The hero's command line drops its explanatory sentence and gains the second form,
rugnux <diffraction image file> <CIF/PDB model file>.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu
(cherry picked from commit ff26000bfe7446cb4fda739c3b72596f8a8b7047)
This commit is contained in:
leonarski_f committed 2026-10-26 10:53:25 +01:00
1 parent 4dbcb35708
commit f960bd7a80
6 files changed
+91 -52

No files matched your search

+1 -1
View File
@@ -22,7 +22,7 @@ RELEASES = "https://gitea.psi.ch/mx/jungfraujoch/releases"
# docs/landing/: the front page, rendered from its template into the output root as index.html at
# the end of the build (write_landing below), with the same download blocks as the Sphinx pages.
LANDING_FILES = ("landing.css", "landing.js")
LANDING_FILES = ("landing.css", "landing.js", "hero_frame.webp")
# program -> [(platform, requirements, [(label, asset name with {v}, regex for the live lookup)])]
# The first button of a platform is the recommended one and is drawn filled.
+58
View File
@@ -0,0 +1,58 @@
#!/usr/bin/env python3
"""Make the front page's hero image (docs/landing/hero_frame.webp) from one frame of an NXmx
HDF5 dataset. Not part of the documentation build: run it by hand when the image is to change,
and commit the WebP.
hero_frame.py <master.h5> [frame] [out.webp]
The frame is cropped to a square about the beam centre (from the master file), tone-mapped with
a log curve set from its own background level, and downsampled with a block mean+max blend so
the Bragg spots stay visible at a ninth of the size. Masked pixels (module gaps, bad pixels) are
drawn light grey. Dark spots on a light background; the page inverts it for the dark theme.
Needs numpy, h5py, hdf5plugin and Pillow.
"""
import sys
import h5py
import hdf5plugin # noqa: F401 - registers the bitshuffle/LZ4 filters for h5py
import numpy as np
from PIL import Image
OUT_PX = 920 # twice the largest size the hero shows it at
CROP = 0.68 # fraction of the largest square about the beam centre: larger spots, fewer gaps
master = sys.argv[1]
frame = int(sys.argv[2]) if len(sys.argv) > 2 else 0
out = sys.argv[3] if len(sys.argv) > 3 else "hero_frame.webp"
with h5py.File(master, "r") as f:
data = f["/entry/data"]
dset = data["data"] if "data" in data else data["data_000001"]
img = dset[frame].astype(np.float64)
det = f["/entry/instrument/detector"]
cx, cy = float(det["beam_center_x"][()]), float(det["beam_center_y"][()])
bad = img >= 2**31 # masked and gap pixels carry the all-ones value
img[bad] = 0
# Square crop about the beam centre, a fraction of the largest the detector allows, in whole
# output pixels.
k = int(CROP * 2 * min(cx, cy, img.shape[1] - cx, img.shape[0] - cy)) // OUT_PX
half = k * OUT_PX // 2
x0, y0 = int(cx) - half, int(cy) - half
img = img[y0:y0 + 2 * half, x0:x0 + 2 * half]
bad = bad[y0:y0 + 2 * half, x0:x0 + 2 * half]
# Log tone map: the background sits at a light grey, spots at 20x background are black.
bkg = max(np.median(img[~bad]), 1.0)
t = np.clip(np.log1p(img / (1.2 * bkg)) / np.log1p(20.0), 0, 1)
n = OUT_PX
t = t.reshape(n, k, n, k)
gap = bad.reshape(n, k, n, k).mean(axis=(1, 3)) > 0.5
v = 0.3 * t.mean(axis=(1, 3)) + 0.7 * t.max(axis=(1, 3))
g = (255 * (1 - 0.92 * v)).astype(np.uint8)
g[gap] = 238
Image.fromarray(g).save(out, quality=82, method=6)
print(out, "beam centre", cx, cy, "crop", 2 * half, "px, block", k, "background", bkg)
Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

+6 -2
View File
@@ -35,7 +35,11 @@ try { var t = localStorage.getItem("jfj-theme"); if (t) document.documentElement
<main>
<section class="hero">
<svg class="hero__art" aria-hidden="true" viewBox="0 0 600 600"></svg>
<figure class="hero__art">
<img src="hero_frame.webp" width="920" height="920" alt="A diffraction image: rows of Bragg spots, the beam stop's shadow and the gaps between detector modules"
title="Lysozyme, one 0.2&deg; rotation frame on an EIGER2 16M, SLS beamline X10SA, Paul Scherrer Institute">
<figcaption>Lysozyme &middot; one 0.2&deg; frame &middot; EIGER2 16M &middot; SLS X10SA</figcaption>
</figure>
<div class="hero__text">
<p class="eyebrow">Paul Scherrer Institute &middot; open source</p>
<h1>From the detector to the merged reflections.</h1>
@@ -46,7 +50,7 @@ try { var t = localStorage.getItem("jfj-theme"); if (t) document.documentElement
<a class="btn btn--primary" href="#download">Download</a>
<a class="btn btn--ghost" href="documentation.html">Read the documentation</a>
</div>
<p class="hero__run"><code>rugnux &lt;diffraction image file&gt;</code><span>is the whole command: cell, space group and resolution come out of the data.</span></p>
<p class="hero__run"><code>rugnux &lt;diffraction image file&gt;</code><code>rugnux &lt;diffraction image file&gt; &lt;CIF/PDB model file&gt;</code></p>
</div>
</section>
+25 -17
View File
@@ -16,8 +16,7 @@
--accent: #e9a23b;
--accent-soft: rgba(233, 162, 59, 0.16);
--shadow: 0 1px 2px rgba(27, 29, 42, 0.06), 0 8px 24px rgba(27, 29, 42, 0.06);
--ring: rgba(57, 73, 171, 0.22);
--spot: rgba(57, 73, 171, 0.55);
--art-filter: none;
}
@media (prefers-color-scheme: dark) {
@@ -35,8 +34,7 @@
--accent: #f0b65b;
--accent-soft: rgba(240, 182, 91, 0.16);
--shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
--ring: rgba(142, 157, 255, 0.24);
--spot: rgba(170, 181, 255, 0.7);
--art-filter: invert(1) contrast(1.05);
}
}
@@ -54,8 +52,7 @@
--accent: #f0b65b;
--accent-soft: rgba(240, 182, 91, 0.16);
--shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
--ring: rgba(142, 157, 255, 0.24);
--spot: rgba(170, 181, 255, 0.7);
--art-filter: invert(1) contrast(1.05);
}
* { box-sizing: border-box; }
@@ -152,12 +149,23 @@ main > section, .top, .foot {
width: 100%;
max-width: 460px;
justify-self: end;
aspect-ratio: 1;
margin: 0;
}
/* A real detector frame, dark spots on light grey; inverted for the dark theme. */
.hero__art img {
display: block;
width: 100%;
height: auto;
border-radius: 14px;
box-shadow: var(--shadow);
filter: var(--art-filter);
}
.hero__art figcaption {
margin-top: 10px;
font-size: 0.78em;
color: var(--fg-muted);
text-align: right;
}
.hero__art .ring { fill: none; stroke: var(--ring); stroke-width: 1; }
.hero__art .ring--strong { stroke-width: 1.6; }
.hero__art .spot { fill: var(--spot); }
.hero__art .beam { stroke: var(--accent); stroke-width: 2; }
.hero__text { grid-column: 1; grid-row: 1; max-width: 600px; }
@@ -198,14 +206,13 @@ main > section, .top, .foot {
.hero__run {
display: flex;
flex-wrap: wrap;
align-items: baseline;
gap: 10px 14px;
flex-direction: column;
align-items: flex-start;
gap: 8px;
margin: 0;
color: var(--fg-muted);
font-size: 0.95em;
}
.hero__run code { font-size: 1em; padding: 0.35em 0.7em; }
.hero__run code { font-size: 1em; padding: 0.35em 0.7em; max-width: 100%; overflow-wrap: anywhere; }
/* ---- programs -------------------------------------------------------------------------------- */
@@ -363,7 +370,8 @@ a.jfj-dl__btn--missing, a.jfj-dl__btn--missing:hover {
.top__nav { gap: 14px; margin-left: 0; order: 3; width: 100%; font-size: 0.95em; }
.theme-toggle { margin-left: auto; }
.hero { grid-template-columns: 1fr; padding-top: 28px; padding-bottom: 40px; }
.hero__art { grid-column: 1; grid-row: 1; max-width: 220px; justify-self: center; opacity: 0.9; }
.hero__art { grid-column: 1; grid-row: 1; max-width: 260px; justify-self: center; }
.hero__art figcaption { text-align: center; }
.hero__text { grid-row: 2; }
.programs__grid { grid-template-columns: 1fr; }
}
+1 -32
View File
@@ -1,4 +1,4 @@
// The front page: theme toggle, the hero's diffraction-pattern drawing, and the download section's
// The front page: theme toggle and the download section's
// "your system" highlight. The download buttons themselves are repointed at the newest release by
// _static/jfjoch_downloads.js, shared with the Sphinx download pages.
(function () {
@@ -16,37 +16,6 @@
try { localStorage.setItem("jfj-theme", next); } catch (e) {}
});
// ---- hero art: resolution rings and a scatter of spots, the same every time --------------
var art = document.querySelector(".hero__art");
if (art) {
var seed = 7;
function rand() { seed = (seed * 16807) % 2147483647; return seed / 2147483647; }
var ns = "http://www.w3.org/2000/svg", out = [];
function el(name, attrs) {
var e = document.createElementNS(ns, name);
for (var k in attrs) e.setAttribute(k, attrs[k]);
return e;
}
var cx = 300, cy = 300;
[60, 110, 160, 210, 260].forEach(function (r, i) {
art.appendChild(el("circle", { cx: cx, cy: cy, r: r, "class": "ring" + (i === 2 ? " ring--strong" : "") }));
});
// beam centre
art.appendChild(el("path", { d: "M" + (cx - 9) + " " + cy + "h18M" + cx + " " + (cy - 9) + "v18", "class": "beam" }));
// spots: denser near the middle, fainter and smaller towards the edge, a few bright ones
for (var i = 0; i < 230; i++) {
var a = rand() * Math.PI * 2;
var r = Math.sqrt(rand()) * 285;
if (r < 25) continue;
var x = cx + r * Math.cos(a), y = cy + r * Math.sin(a);
var fade = 1 - r / 320;
var size = 1.2 + fade * 2.2 * rand() + (rand() > 0.94 ? 2.5 : 0);
var c = el("circle", { cx: x.toFixed(1), cy: y.toFixed(1), r: size.toFixed(1), "class": "spot" });
c.style.opacity = (0.25 + 0.75 * fade * rand()).toFixed(2);
art.appendChild(c);
}
}
// ---- "your system": highlight the platform the browser runs on ----------------------------
var ua = navigator.userAgent || "", platform = navigator.platform || "";
var os = /Windows/.test(ua) ? "windows" : /Mac/.test(platform) || /Macintosh/.test(ua) ? "macos" :