# Masks and collection windows The instrument has two masks: the input mask, whose holes cut the beamlets from the beam, and the output mask, whose holes are the collection windows in front of the spectrometer. Both are chromatic: a hole at mask-plane position $x$ passes the transverse wavevector $k_x = x\,\omega/(c z_m)$, so its footprint in momentum space scales with frequency. The collection windows are {class}`pnps.extraction.WindowSpec` values, centred where the signal appears ({func}`pnps.geometry.signal_centre`). A hole is a discontinuous function of mask-plane position, so *how* its edge is rendered onto the momentum grid is a modelling choice, not a detail. The choice matters twice over: once for the input beamlets, and once for the collection windows, where it is a different question with a different answer. ## Why a hard hole cannot simply be point-sampled Sampling a function in $k$ is equivalent to periodising its transform in $x$. Point-sampling a hard disc therefore does not give the focal field of that aperture — it gives the *wrapped* focal field, with the Airy tails that run off the grid folded back on top of the beam. On the production grid (hole radius $\approx 15$ momentum bins, grid half-width $\approx 13$ Airy radii) that wrap is a $0.3$–$2\%$ perturbation of the focal amplitude, worst at the red end where the spot is largest. It also shows up as a Gauss-circle staircase in the transmitted energy: the pixel count inside the disc jumps by whole pixels as the chromatic mapping sweeps the edge. Smoothing the edge cures the wrap by making the focal field decay before it reaches the grid boundary. The price is that the aperture is no longer the nominal one. The default renderings, below, avoid both problems. Constructing the exact Airy field analytically in real space and transforming it *does not* solve this. A dark signal corner requires the arm's momentum support to be compact, and truncating the Airy tails at the grid boundary destroys exactly that: the z = 0 leakage into the smallest collection window rises by seventeen orders of magnitude, from $10^{-20}$ of trace peak to $10^{-3}$. Compact support in $k$ and an untruncated Airy in $x$ are mutually exclusive on a periodic grid, so every usable construction is a momentum-space mask. ## Input holes: pixel-area antialiasing `apod="area"`, the default for the input holes (`Config.apod`), renders the hole as the fraction of each momentum pixel that falls inside it. It is the exact hard aperture, parameter-free, exactly compact in $k$, and it *discards* the focal energy that falls off the grid instead of wrapping it back onto the beam. Measured against the exact continuous Airy field of a uniformly illuminated hole, over the central three Airy radii: | input mask | 400 nm | 260 nm | 150 nm | |---|---|---|---| | `supergauss`, p = 16 | 2.40e-2 | 2.40e-2 | 2.40e-2 | | `hard` | 2.28e-2 | 6.58e-3 | 3.09e-3 | | `tanh`, w = 15 µm | 4.09e-3 | 1.95e-3 | 1.86e-3 | | `area` | 3.45e-3 | 1.58e-3 | 3.64e-4 | A supergaussian of order 16 passes only 86% of the nominal hole energy — an effective diameter of 0.93 mm for a 1 mm hole — where `area` passes 98%, the missing 2% being the Airy tail energy genuinely outside the grid. Note that the *shape* of the recorded beamlet truth is much less sensitive than this: the supergaussian factor is very nearly frequency-independent, so the vignetting shape it produces is within $9\times 10^{-4}$ of the exact hard aperture's, better than `hard` manages ($9.7\times 10^{-3}$, the staircase). ## Collection windows: a quadrature weight, not a filter The collected-energy observable is $\sum_k |W E|^2 = \sum_k W^2 |E|^2$. That models a hole whose transmission really is graded. The instrument's hole is hard, and what is wanted is a quadrature rule for $\int_{\text{hole}} |E|^2$ — a weight that enters *once*, not squared. The distinction is not cosmetic. Because $W^2$ is not antisymmetric about the hole edge it under-counts the aperture, while the re-imaged observable, linear in $W$, over-counts it; with a three-pixel tanh edge on the production grid, | aperture / nominal | 0.5 mm | 1.0 mm | 2.5 mm | |---|---|---|---| | collected energy, $\sum W^2$ | 0.735 | 0.837 | 0.927 | | re-imaged, $\sum W$ | 1.123 | 1.031 | 1.005 | | quadrature weight (either) | 1.0002 | 0.9999 | 1.0000 | so the two recorded traces describe different effective apertures, and both differ from the nominal one by an amount that varies with window size — directly distorting a window-size series. `WindowSpec.weighting="quadrature"` uses the profile as the weight for both observables. Any *antisymmetric* edge profile ($\phi(t) + \phi(-t) = 1$) is then unbiased in one dimension; in two dimensions the ring outside the nominal radius is longer than the ring inside, which {func}`pnps.beams.quadrature_holediam` removes analytically by shrinking the edge radius by the profile's second moment. The recommended profile is `"rcos"`, a raised cosine of half-width two momentum bins ({func}`pnps.beams.rcos_edge_default`). It is wide enough to sample smoothly — the residual spectral ripple is $3\times10^{-4}$ on the smallest window, $6\times10^{-5}$ at 1 mm and $4\times10^{-6}$ at 2.5 mm — and, being of *compact* support, it is exactly zero outside the hole. That last property matters more than it sounds: a tanh window has exponential tails that bridge the 250 µm gap between the 2.5 mm window edge and the nearest input arm, and those tails are the entire origin of that window's $1.8\times10^{-3}$ dark floor. With a compact weight the z = 0 corner is dark to floating-point zero, in every window. Two bins is a deliberate compromise: the support must clear the input arms across the whole simulation band, and the gap shrinks towards the red (13.4 bins at 150 nm, 7.7 at 260 nm, 5.0 at 400 nm, 3.35 at 600 nm). Three bins gives about half the ripple but no margin at the red edge. The residual ripple is set by how many momentum bins the window radius spans (7.7 for the smallest window here), and is the one thing a larger `r_max` would buy. Pixel-area weighting (`apod="area"`) is also exact in aperture and exactly compact, but its sampled radial profile is only continuous, not smooth, and it ripples several times more than the raised cosine; it is the right choice for the input amplitude mask, where no quadrature is involved, and the wrong one here. All the numbers in this section come from `examples/mask_study.py`, which measures them on the production transverse grid; the ripple figures depend mildly on the scan range and detrending, so read them as orders of magnitude rather than to two digits. The defaults follow from this: a {class}`~pnps.extraction.WindowSpec` is a `"rcos"` edge two bins wide (`apod_param=None` resolves to {func}`pnps.beams.rcos_edge_default`) with `weighting="quadrature"`, because the instrument's collection holes are hard. `"amplitude"` models a hole whose transmission really is graded; it is the only weighting a profile that is not antisymmetric about the hole edge admits, such as `"planck"` (below). ## Exact hard discs for the generated field Every rendering of a disc on the momentum grid carries a quadrature error that grows as the disc spans fewer bins. For the signal there is a way round it. The field in a signal window is the nonlinear part of the state, $N$, everything the Kerr polarisation generated ({func}`pnps.simulate.visit_nonlinear`); behind compact input holes no linear light reaches the window. $N$ is driven by products of focal fields and is confined near the focus, far inside the transverse box, so its spectrum is a finite Fourier series in $k$ whose coefficients are its real-space samples. Integrals of such a series over a disc are exact sums against the disc's analytic transform, $\int_{|k - k_c| \le R} e^{-i k\cdot r}\,d^2k = e^{-i k_c\cdot r}\, 2\pi R J_1(R|r|)/|r|$: the on-axis spectrum, linear in $N$, always; the collected energy, quadratic, when the autocorrelation of $N$ does not wrap round the box, that is when $N$ fills less than half of it ({func}`pnps.exact_windows.wrap_share` measures how well that holds). Both sums are linear in the grid's samples (of $N$, and of $\eta|N|^2$), so each is a fixed weight on the momentum grid, one per window and frequency: the disc's indicator interpolated by the grid's own (Dirichlet) kernel. {class}`pnps.exact_windows.ExactWindows` builds these masks once and applies them to every plane at the cost of a grid sum, like any other rendering; {func}`pnps.exact_windows.exact_window_spectra` is its one-plane form. Both return the units of the grid's own sums. Unlike the compact renderings the masks reach every bin, which is why they are exact only for $N$ and must never be applied to the whole state with its input arms. A scan collects through them with `Config(exact_windows=True)`. Each plane's windowed spectra (`i_omega_win`, `i_omega_reimaged`) are then the exact discs' on the band, from $N = E - e^{Lz}E(0)$, and every other observable is unchanged. The window's rendering (`apod`, `weighting`) plays no part. - **On the backend (the default).** With the solprop reduction, which `'auto'` resolves to, solprop forms $N$ and the exact discs itself: each window is an aperture with its `exact` profile on the `nonlinear` field (solprop's SEP 53). It holds the input on the device, forms $N$ inside its far-field pass without storing it, and builds the weights there once. No field leaves the device, so a GPU run keeps its speed. - **On the host** (`reduction='host'`). This package forms $N$ and integrates it through {class}`~pnps.exact_windows.ExactWindows`. The price is the input state held for the subtraction and the masks, `n_windows * n_band * n^2` doubles ({func}`pnps.memory.memory_budget` counts both), and a field copy per plane. It is the reference the backend route is tested against, to rounding. Against adaptive quadrature of an analytic compact field the host masks agree to $10^{-15}$, and references that sample the momentum plane 4, 8 and 16 times more finely, by zero-padding $N$ in real space, converge onto them (`tests/test_exact_windows.py`; `examples/window_accuracy.py` makes the comparison on any run file). solprop's weights match these masks to rounding. A disc must stay inside the momentum grid: one that reaches $|k| = \pi/\Delta x$ along either axis on a band frequency would integrate a periodic copy of the spectrum, so a run with such a window is refused before it starts ({func}`pnps.exact_windows.nyquist_reach`), on either route. The production windows are far inside it. The scan file records what was collected. With exact windows each `window_def*_apod` is `"hard"` (`_apod_param` 0, `_weighting` `"quadrature"`), so a reader that rebuilds the aperture from these records, as Croak does, builds the disc; `/grid/exact_windows` is 1 and `/grid/window_field` is `"nonlinear"` (otherwise 0 and `"total"`). The configured rendering is kept as `window_def*_configured_apod`, `_configured_apod_param` and `_configured_weighting`. Because $N$ leaves out the input arms, an exact window that overlaps the far field of an input hole collects the signal without the transmitted input light a detector there would also see. Building such a setup emits a {class}`~pnps.exceptions.WindowOverlapWarning`. The input hole at mask-plane position $h$ reaches a window at distance `zmask` at $h\,z_\text{mask}/f_\text{foc}$, as a disc of diameter `mask_diam` $\cdot z_\text{mask}/f_\text{foc}$. ## Choosing the renderings Two independent choices, described in the sections above, and both defaults: ```python cfg = Config( ..., apod="area", # input holes: the exact hard aperture, apod_param=4.0, # supersampled 4 x 4 where the edge crosses a pixel windows=( # A raised-cosine edge two momentum bins wide, as a quadrature weight. WindowSpec(holex=x, holey=y, holediam=1e-3, zmask=0.1), ), ) ``` Another rendering is a choice made explicitly, for example `WindowSpec(..., apod="tanh", weighting="amplitude")` for a graded hole. It changes what the recorded observables mean, so a scan that uses it is not comparable cell for cell with one that does not. The input is formed afresh for every delay, and `"area"` supersamples only the pixels an edge crosses: forming a 384 × 384 × 600 input takes 0.27 s with `"area"` and 0.55 s with a supergaussian (Apple M5 Max), against about 11 s of propagation per delay at that size. `"area"` is meant for the input holes, not the collection windows: its sampled profile is only continuous, and it ripples more than the raised cosine. ## Planck edges and achromatic windows Two further options give smooth or frequency-independent collection windows, as properties of a {class}`pnps.extraction.WindowSpec` rather than as window types of their own: - `apod="planck"` with a width `apod_param = w` in m: transmission 1 inside the hole and falling to 0 at `holediam/2 + w` with a C-infinity Planck taper — an edge *outside* the nominal hole, so it is an amplitude filter, not a quadrature weight, and is given with `weighting="amplitude"`; - `achromatic_wavelength=λr`: the hole's momentum-space footprint frozen at the wavelength `λr` for every frequency, removing the chromatic vignetting. A diagnostic: no physical mask does this. Both agree with the closed-form Planck-tapered disc, chromatic or frozen, to 1e-12 (`tests/test_planck_windows.py`). solprop's apertures are physical holes with its four profiles, so with either option `reduction="auto"` reduces the planes on the host. `examples/mask_study.py` measures the consequences of these choices on the production grid — the aperture each observable actually implements, the z = 0 leakage into the signal corner, and the spectral ripple each rendering imposes — and is the source of the numbers on this page. `examples/tgfrog_window_series.py` uses the recommended renderings.