Input pulses#
By default the source is a transform-limited Gaussian
(pnps.pulse.gaussian_pulse_spectrum()) of duration Config.tau_fwhm, with an
optional chirp (Config.gdd, Config.tod). That is a convenience, not a
requirement. The illumination profile and the chromatic
input holes are real, frequency-dependent amplitude factors applied to one
1-D reference spectrum, so an arbitrary complex field composes exactly:
everything downstream — the vignetting, the recorded beamlet truth, the
propagation — is unchanged. Set pnps.setup.Config.input_pulse and
the field replaces the Gaussian as the source at the mask plane.
from pnps.input_pulse import (
centre_pulse,
load_input_pulse,
normalise_peak,
spectral_window,
)
pulse = load_input_pulse("pulse.h5", omega_key="ω", e_omega_key="Eω")
pulse = spectral_window(pulse, 148e-9, 830e-9) # optional: drop out-of-band content
pulse, tshift = centre_pulse(pulse) # REQUIRED, see below
pulse = normalise_peak(pulse) # optional, cosmetic
cfg = replace(cfg, input_pulse=pulse)
tau_fwhm, gdd and tod become nominal metadata: the injected field
carries the real duration and phase. A non-zero configured chirp alongside an
injected pulse is refused rather than silently added.
What the source file must contain#
An absolute angular-frequency axis (rad/s) and a complex spectrum on it. The
axis must be ascending, uniformly spaced, and a contiguous run of bins of a
one-sided rfft axis (every sample an integer multiple of the spacing) —
which is what the rfft of a real field gives. That requirement is what
fixes the implied time grid: delta_t = 2 pi / (N delta_omega) with
N = 2 (M - 1) from the top bin, and the file’s inverse DFT is the analytic
field on the centred axis t[n] = (n - N/2) delta_t. Reading the file on
its own t axis is what makes the reported centring shift a physically
meaningful number instead of a wrapped one.
Centring is not optional#
Two independent reasons, and the second is the one that bites:
A pulse far from its grid’s time origin carries a spectral phase rotating by up to \(\pi\) per sample. Nothing can resample that — not a spline, not a linear interpolation of real and imaginary parts.
It is what puts the pulse at the centre of the simulation’s time window. A field injected uncentred lands at the window edge.
pnps.input_pulse.centre_pulse() finds the temporal intensity peak on an
8x oversampled grid, refines it below that spacing with a parabolic vertex,
and advances the field by the result — accurate to ~1e-21 s on the fields
used here. The shift is returned, accumulated in InputPulse.tshift, and
written to the scan file.
The storage convention of the source file does not matter, and the loader does not ask: mis-reading it costs exactly half the source window, the peak search then finds a peak half a window away, and the two cancel. Only the centred pulse is used.
Forgetting the step is refused rather than tolerated:
pnps.input_pulse.injected_spectrum() measures the peak time itself and
raises if the pulse sits further than a quarter of the simulation window from
its origin.
Resampling: exact DFT interpolation#
The source grid and the simulation grid are generally not commensurate (for
a simulated resonant-dispersive-wave field, 1.72 THz against 24.2 THz of
angular-frequency spacing).
pnps.pulse.resample_spectrum() evaluates the unique trigonometric
polynomial the source samples define — the transform of the field samples in
the conjugate time domain — which is exact for any field contained in the
source’s time window, at any ratio of spacings. Interpolating real and
imaginary parts with a spline is not: it is accurate only where the complex
spectrum turns slowly between samples, which a chirped or off-centre pulse
violates.
Measured on that field: with a target window long enough to hold the whole source period the resampling preserves the spectral energy to 2e-11. On the production 260 fs window it preserves it to 1.7e-5, and that residual is the window, not the interpolation — 6.6e-6 of the source pulse’s energy lies beyond ±130 fs and folds coherently back onto the pulse, exactly as it would for any field on a periodic grid. The transform-limited duration moves by 5e-4 fs.
Frequencies outside the source’s support (its exactly-zero bins) are set to zero rather than left to the interpolant, so the file’s band is the band the source file actually defines.
Band-limiting, and what the grid can carry#
The injected field then gets the same C-infinity input band-limit
pnps.setup.build_setup() applies to the synthetic pulse. This is
deliberate rather than incidental: content outside the simulation window is
absorbed within a micrometre of the entrance by the band-edge absorber, so
tapering it at input is what keeps the recorded z = 0 truth equal to the
field that actually propagates. For that field on a 143–600 nm grid
it costs 0.57% of the energy — the tail beyond 600 nm — and the file records
both the source’s own band (input_band) and the band the grid ends up
carrying (input_band_nm), together with the fraction retained
(input_energy_fraction).
Provenance in the scan file#
/grid gains, whenever a pulse is injected: input_pulse = 1,
input_source and input_source_md5, input_history (the preparation steps
in order, e.g. load(ω, Eω); tanh_window(148.0-830.0 nm, wfrac 0.05/0.03); centre(tshift=+5.770060 fs); normalise(peak=1.017788e+06)),
input_tshift, input_norm, input_resampling, input_band,
input_band_nm and input_energy_fraction. Every file also records
delivered_energy, the post-hole energy of all the arms — which is not
grid-invariant (see pnps.io_h5.delivered_energy()), so it belongs in
the file rather than in a table.
A worked example#
examples/injected_pulse.py writes a chirped Gaussian to a source file in the layout
above (one-sided rfft axis, centred-array storage), prepares it with the steps
shown, and runs a smoke scan with it. It prints the measured centring shift (5.07 fs
for a 5 fs offset: the chirp moves the intensity peak) and the chirp the scan file’s
input truth carries, which must be the source’s (it is, to four digits).
uv run python examples/injected_pulse.py