diff --git a/docs/_ext/jfjoch_downloads.py b/docs/_ext/jfjoch_downloads.py index f93438361..a10fb221a 100644 --- a/docs/_ext/jfjoch_downloads.py +++ b/docs/_ext/jfjoch_downloads.py @@ -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. diff --git a/docs/landing/hero_frame.py b/docs/landing/hero_frame.py new file mode 100644 index 000000000..709ee42d8 --- /dev/null +++ b/docs/landing/hero_frame.py @@ -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 [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) diff --git a/docs/landing/hero_frame.webp b/docs/landing/hero_frame.webp new file mode 100644 index 000000000..10becc5a4 Binary files /dev/null and b/docs/landing/hero_frame.webp differ diff --git a/docs/landing/index.html b/docs/landing/index.html index 31e9016f4..8d03dae29 100644 --- a/docs/landing/index.html +++ b/docs/landing/index.html @@ -35,7 +35,11 @@ try { var t = localStorage.getItem("jfj-theme"); if (t) document.documentElement
- +
+ A diffraction image: rows of Bragg spots, the beam stop's shadow and the gaps between detector modules +
Lysozyme · one 0.2° frame · EIGER2 16M · SLS X10SA
+

Paul Scherrer Institute · open source

From the detector to the merged reflections.

@@ -46,7 +50,7 @@ try { var t = localStorage.getItem("jfj-theme"); if (t) document.documentElement Download Read the documentation
-

rugnux <diffraction image file>is the whole command: cell, space group and resolution come out of the data.

+

rugnux <diffraction image file>rugnux <diffraction image file> <CIF/PDB model file>

diff --git a/docs/landing/landing.css b/docs/landing/landing.css index f95f805fc..1c35befc4 100644 --- a/docs/landing/landing.css +++ b/docs/landing/landing.css @@ -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; } } diff --git a/docs/landing/landing.js b/docs/landing/landing.js index c4fdd47f0..ba94b5979 100644 --- a/docs/landing/landing.js +++ b/docs/landing/landing.js @@ -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" :