pnps.input_pulse#

Data-driven input pulse: inject a stored complex spectrum as the source field.

The synthetic pulse of pnps.pulse.gaussian_pulse_spectrum() 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 (see pnps.beams.build_beamlet_fields()), so any measured or separately simulated field composes exactly. This module reads such a field from an HDF5 file, prepares it, and puts it on the simulation’s frequency axis.

Notes#

Conventions.

A source file stores the discrete Fourier transform of a field array: a complex spectrum E[j] on an ascending, uniform, absolute angular-frequency axis omega[j] = j * delta_omega (a one-sided rfft axis, as numpy.fft.rfft gives for a real field), whose inverse DFT is the analytic field sampled on the centred time axis t[n] = (n - N/2) * delta_t with N = 2 * (M - 1) and delta_t = 2 * pi / (N * delta_omega). That is the same layout this package uses for its own state, and reading the file on the file’s own t axis is what makes the reported centring shift a physically meaningful number rather than a wrapped one.

The steps, in the order they must be applied:

  1. load_input_pulse() — read omega and the complex spectrum;

  2. spectral_window() — optional smooth band-pass, to drop content the experiment (or the simulation) does not carry;

  3. centre_pulse() — required: move the pulse’s temporal peak to t = 0. A pulse sitting far from its grid’s time origin carries a spectral phase rotating by up to pi per sample; the resampling of step 5 is then interpolating a phase-wrapped field, which no interpolation scheme can do. It is also what puts the pulse at the centre of the simulation’s time window instead of at its edge;

  4. normalise_peak() — optional; the beamlet builder rescales the assembled 3-D beam to the requested energy, so only the shape of the injected spectrum matters and its absolute scale is free;

  5. injected_spectrum() — evaluate the pulse on a pnps.grids.TimeGrid by exact DFT interpolation (pnps.pulse.resample_spectrum()), zero outside the source’s support, and return it in the storage convention of pnps.pulse.gaussian_pulse_spectrum().

Steps 1-4 are pure functions returning new InputPulse objects and accumulating a human-readable history; step 5 is what pnps.setup.build_setup() calls when Config.input_pulse is set.

Why exact DFT interpolation and not a spline.

The source grid and the simulation grid are not commensurate (here 1.72 THz against 24.2 THz of angular-frequency spacing), so the field must be interpolated in frequency. The samples of a spectrum on a uniform grid determine a unique trigonometric polynomial — the transform of the field samples in the conjugate time domain — and evaluating that polynomial is exact, not approximate, for any field contained in the source’s time window. Interpolating real and imaginary parts separately 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 a simulated resonant-dispersive-wave field, the exact interpolant reproduces the source energy to 2e-11 when the target time window is long enough to hold the whole source period.

Module Attributes

PEAK_OVERSAMPLE

Oversampling factor used to locate the temporal peak in peak_time().

MAX_PEAK_OFFSET_FRACTION

Fraction of the simulation's time window within which an injected pulse's peak must sit for injected_spectrum() to accept it.

Functions

centre_pulse(pulse[, oversample])

Advance the pulse so its intensity peak sits at t = 0.

injected_spectrum(tgrid, pulse)

Evaluate a prepared input pulse on the simulation's frequency axis.

load_input_pulse(path[, omega_key, e_omega_key])

Read an input pulse from an HDF5 file.

normalise_peak(pulse)

Scale the spectrum to unit peak amplitude, recording the factor.

peak_time(pulse[, oversample])

Time of the temporal intensity peak on the source's centred axis, in s.

spectral_window(pulse, lam_min, lam_max[, ...])

Smooth tanh band-pass of a stored pulse, (lam_min, lam_max) in m.

Classes

InputPulse(omega, e_omega[, source, md5, ...])

A stored complex spectrum to be used as the simulation's source field.

pnps.input_pulse.MAX_PEAK_OFFSET_FRACTION = 0.25#

Fraction of the simulation’s time window within which an injected pulse’s peak must sit for injected_spectrum() to accept it. A quarter window is generous — the pulse also has to fit inside Config.time_headroom alongside the delay scan — while still catching the failure this guard exists for: a field injected without centre_pulse(), which lands at the window edge rather than its centre.

pnps.input_pulse.PEAK_OVERSAMPLE = 8#

Oversampling factor used to locate the temporal peak in peak_time(). The parabolic vertex refines below the sample spacing, so 8 is ample: on the source grid used here it puts the peak time within ~1e-4 fs.

class pnps.input_pulse.InputPulse(omega, e_omega, source='', md5='', history=(), tshift=0.0, norm=1.0)[source]#

Bases: object

A stored complex spectrum to be used as the simulation’s source field.

Equality and hashing are by identity (eq=False): the object holds arrays, and it is carried inside the hashable pnps.setup.Config.

Attributes:
omeganumpy.ndarray

Ascending, uniformly spaced, absolute angular-frequency axis in rad/s. It must be a contiguous run of bins of a one-sided rfft axis, i.e. every omega[j] an integer multiple of the spacing.

e_omeganumpy.ndarray

Complex spectrum on omega, as stored: the DFT of the field array whose inverse transform is the analytic field on the centred time axis (n - N/2) * delta_t (see the module docstring). Absolute scale is arbitrary.

sourcestr

Provenance: where the field came from (a file name).

md5str

MD5 checksum of the source file, hex-encoded.

historytuple of str

The preparation steps applied so far, in order, each a short human-readable record. Written into the scan file so a trace says how its input was built.

tshiftfloat

Cumulative time shift applied by centre_pulse(), in s (positive = the pulse arrived late and was advanced).

normfloat

Cumulative amplitude factor divided out by normalise_peak().

omega: Float[ndarray, 'n_bins']#
e_omega: Complex[ndarray, 'n_bins']#
source: str = ''#
md5: str = ''#
history: tuple[str, ...] = ()#
tshift: float = 0.0#
norm: float = 1.0#
property delta_omega: float[source]#

Angular-frequency sample spacing in rad/s.

Returns:
float

The uniform spacing of omega, in rad/s.

property n_bins: int[source]#

Length of the full one-sided axis this pulse is a run of bins of.

Returns:
int

Bin count of the one-sided axis from 0 to omega[-1].

property n_time: int[source]#

Sample count of the implied source time grid, 2 * (n_bins - 1).

Returns:
int

The source time-grid length N.

property delta_t: float[source]#

Time step of the implied source time grid in s.

Returns:
float

2 * pi / (n_time * delta_omega), in s.

property support: tuple[float, float][source]#

Angular-frequency range carrying non-zero amplitude, in rad/s.

Every preparation step here is multiplicative, so exact zeros in the source survive: this is the band the source file actually defines, and injected_spectrum() puts exact zeros outside it rather than letting the interpolant invent values there.

Returns:
tuple of (float, float)

Lowest and highest angular frequency with non-zero amplitude, in rad/s.

Raises:
PulseError

If the spectrum is identically zero.

property energy: float[source]#

sum |E|^2 * delta_omega: energy in the spectrum’s own units.

Returns:
float

The spectral energy, in the source file’s units of |E|^2 times rad/s (only ratios of it are meaningful).

padded()[source]#

Embed the spectrum in its full one-sided axis, zero-filled.

Length n_time: the one-sided bins followed by zeros for the negative frequencies, i.e. an FFT-ordered spectrum of an analytic field with reference frequency 0.

Returns:
numpy.ndarray

Complex FFT-ordered spectrum, shape (n_time,).

time_axis(oversample=1)[source]#

Centred time axis of the implied source grid, refined oversample x.

Parameters:
oversampleint

Refinement factor of the sample spacing, >= 1.

Returns:
numpy.ndarray

Times (n - N/2) * delta_t / oversample in s, shape (n_time * oversample,).

pnps.input_pulse.centre_pulse(pulse, oversample=8)[source]#

Advance the pulse so its intensity peak sits at t = 0.

A pure linear spectral phase is physically irrelevant, but numerically it is what decides whether the field can be resampled at all (see the module docstring) and where in the simulation’s time window the pulse lands — a pulse left at the window edge is the failure this step exists to prevent. The shift is applied as exp(+1j * omega * tshift), which advances the field by tshift.

Parameters:
pulseInputPulse

The pulse to centre.

oversampleint

Temporal refinement of the peak search, see peak_time().

Returns:
tuple of (InputPulse, float)

The centred pulse and the shift applied, in s.

pnps.input_pulse.injected_spectrum(tgrid, pulse)[source]#

Evaluate a prepared input pulse on the simulation’s frequency axis.

Exact DFT interpolation of the source spectrum (see the module docstring), zeroed outside the source’s InputPulse.support, and returned in the same convention as pnps.pulse.gaussian_pulse_spectrum(): the FFT of the analytic envelope on the centred time axis, so ifft of the result is the envelope with the pulse at t = 0.

The pulse must have been centred (centre_pulse()) first, and this is checked rather than assumed: the interpolation is only meaningful for a field sitting at the origin of the source’s time window, and an uncentred field would be injected at the edge of the simulation’s.

Parameters:
tgridTimeGrid

The simulation’s temporal grid; its omega axis is the target.

pulseInputPulse

A prepared (windowed, centred) input pulse.

Returns:
numpy.ndarray

Complex spectrum on tgrid.omega, shape (tgrid.nt,).

Raises:
PulseError

If the source’s support does not overlap the simulation’s frequency axis at all, or if the pulse has not been centred.

pnps.input_pulse.load_input_pulse(path, omega_key='ω', e_omega_key='Eω')[source]#

Read an input pulse from an HDF5 file.

Parameters:
pathstr or pathlib.Path

The HDF5 file.

omega_key, e_omega_keystr

Dataset names of the absolute angular-frequency axis (rad/s) and the complex spectrum on it.

Returns:
InputPulse

With source and md5 filled in for provenance.

Raises:
PulseFileError

If either key does not name a dataset, or the spectrum is not complex.

PulseError

If the axis fails the grid requirements of InputPulse.

pnps.input_pulse.normalise_peak(pulse)[source]#

Scale the spectrum to unit peak amplitude, recording the factor.

The beamlet builder normalises the assembled 3-D beam to the configured pre-mask energy, so the injected spectrum’s absolute scale is free; fixing the peak at 1 makes the recorded input truth Iω an O(1) quantity whatever units the source file used. The factor divided out is kept in norm so the source amplitude is recoverable.

Parameters:
pulseInputPulse

The pulse to normalise.

Returns:
InputPulse

A new pulse with max |e_omega| == 1; the input is unchanged.

Raises:
PulseError

If the spectrum is identically zero.

pnps.input_pulse.peak_time(pulse, oversample=8)[source]#

Time of the temporal intensity peak on the source’s centred axis, in s.

The analytic field is evaluated on an oversample-times finer axis by zero-padding the spectrum (the exact band-limited interpolation), and the peak is refined below that spacing by the vertex of the parabola through the largest sample and its neighbours. Neighbours are taken cyclically, so a pulse sitting at the wrap point of the source window is handled.

Parameters:
pulseInputPulse

The pulse whose peak is sought.

oversampleint

Temporal refinement factor for the search.

Returns:
float

Peak time in s, on the axis (n - N/2) * delta_t.

pnps.input_pulse.spectral_window(pulse, lam_min, lam_max, wfrac_blue=0.05, wfrac_red=0.03)[source]#

Smooth tanh band-pass of a stored pulse, (lam_min, lam_max) in m.

Unity well inside the band, rolling off with tanh edges of width wfrac_blue * omega(lam_min) on the blue side and wfrac_red * omega(lam_max) on the red. Use it to remove content the instrument being modelled does not carry — for a simulated dispersive-wave field, say, the residual near-infrared driver remnant that survived the filter chain and would otherwise dominate the chi3 interaction. The windowed field is the ground truth a retrieval is compared against, so the window belongs to the run’s provenance and is recorded in history.

Parameters:
pulseInputPulse

The pulse to window.

lam_min, lam_maxfloat

Band-pass edges in m.

wfrac_blue, wfrac_redfloat

Edge widths as a fraction of the corresponding edge frequency.

Returns:
InputPulse

A new pulse; the input is unchanged.

Raises:
PulseError

If lam_min >= lam_max or an edge width is not positive.