pnps.io_h5#
HDF5 scan file, in the layout the Croak retrieval package reads.
One scan produces one <scan_name>_collected.h5. Datasets are written in C
order with the delay first and the frequency fastest on disk, (N_tau, nz,
N_omega), so a reader in a column-major language sees (N_omega, nz, N_tau).
Conventions carried in /grid:
omegais the absolute angular frequency axis in FFT order — readers must not assume monotonicity;delay_convention = "gate": the test arm was advanced byexp(+1j omega tau); do not reverse the delay axis;spectra are in the state’s unnormalised-FFT units (scaling as the fourth power of the transverse sample count at fixed extent).
Resume marker: datasets are created zero-filled, and an all-zero delay slice
means “not yet computed”. Sharding for
multi-process/multi-GPU scans writes <scan_name>_collected.shard<i>.h5
files with identical layout, merged by merge_shards().
Module Attributes
Oversampling factor of the |
|
The |
Functions
|
Complex beamlet spectrum: vignetted amplitude carrying the input phase. |
|
Create the collected file with zero-filled full-size datasets. |
|
Three-arm post-hole pulse energy of a built setup, in J. |
|
Read the engine provenance a scan file recorded. |
|
Read a scan file back, with the frequency axis in ascending order. |
|
Copy every computed delay slice from shard files into |
|
Refine |
|
Whether delay point |
|
Assemble the |
|
Temporal intensity of a spectrum, natively and oversampled. |
|
Dataset names for the per-window traces. |
|
Write one delay point's results into the collected file. |
Classes
|
A scan file read back: the trace, its axes and the truths recorded with it. |
- pnps.io_h5.ENGINE_KEYS = ('backend', 'stepper', 'pnps_engine', 'solprop_tableau', 'frame_pinned', 'gamma_k_applied', 'evanescent_clamp', 'index_model', 'measure', 'reduction')#
The
/gridkeys that describe the engine a file was produced with (pnps.bridge.Bridge.metadatasupplies exactly these).
- pnps.io_h5.OVERSAMPLE = 8#
Oversampling factor of the
To/Ito*time-domain truth arrays.
- class pnps.io_h5.SimulatedScan(omega, omega0, t, tau, trace, zsave, z_index, window_key, i_omega, i_t, tau_fwhm, i_omega_beamlet, i_t_beamlet, to, i_to, i_to_beamlet, lap_lost, metadata)[source]#
Bases:
objectA scan file read back: the trace, its axes and the truths recorded with it.
- Attributes:
- omeganumpy.ndarray
Absolute angular frequency in rad/s, ascending, shape
(n_omega,).- omega0float
Carrier angular frequency in rad/s.
- tnumpy.ndarray
Centred time axis in s, shape
(n_t,).- taunumpy.ndarray
The delay axis in s, shape
(n_delays,).- tracenumpy.ndarray
The trace in frequency order:
(n_delays, n_omega)for one plane, or(n_delays, n_z, n_omega)for every plane.- zsavenumpy.ndarray
The save positions in m, shape
(n_z,).- z_indexint or None
The plane the trace is taken at, or None for every plane.
- window_keystr
The dataset the trace was read from (
"Iω_win","Iω_full", …).- i_omeganumpy.ndarray
The input spectrum, in frequency order.
- i_tnumpy.ndarray
The input temporal intensity on
t.- tau_fwhmfloat
The input pulse’s intensity FWHM in s.
- i_omega_beamletnumpy.ndarray
The vignetted beamlet spectrum (the gate’s), in frequency order.
- i_t_beamletnumpy.ndarray
The beamlet temporal intensity on
t.- tonumpy.ndarray
The oversampled time axis in s.
- i_tonumpy.ndarray
The oversampled input intensity on
to.- i_to_beamletnumpy.ndarray
The oversampled beamlet intensity on
to.- lap_lostnumpy.ndarray or None
The energy per bin the lap budget removed at each delay, in frequency order,
(n_delays, n_omega), in the trace’s units (pnps.simulate.run_delay_point()); None in a file written without it. With the last plane of"Iω_beam"it gives a band’s share (pnps.absorber.lap_loss_share()).- metadatadict
Every scalar and string of
/grid, by key.
- omega: Float[ndarray, 'n_omega']#
- t: Float[ndarray, 'n_t']#
- tau: Float[ndarray, 'n_delays']#
- trace: Float[ndarray, 'n_delays *planes n_omega']#
- zsave: Float[ndarray, 'n_z']#
- i_omega: Float[ndarray, 'n_omega']#
- i_t: Float[ndarray, 'n_t']#
- i_omega_beamlet: Float[ndarray, 'n_omega']#
- i_t_beamlet: Float[ndarray, 'n_t']#
- to: Float[ndarray, 'n_t_fine']#
- i_to: Float[ndarray, 'n_t_fine']#
- i_to_beamlet: Float[ndarray, 'n_t_fine']#
- pnps.io_h5.beamlet_truth(i_beamlet, e_in)[source]#
Complex beamlet spectrum: vignetted amplitude carrying the input phase.
The input-mask hole is a real amplitude filter and the illumination profile is real, so a beamlet’s spectrum is the input spectrum times a real non-negative chromatic vignetting factor: its spectral phase is exactly the input phase, and only the amplitude changes. The amplitude is recovered from the recorded beamlet power spectrum.
Where the input spectrum is below
1e-12of its peak the phase is not meaningfully defined, and both returned arrays are zeroed there — so|e_beamlet|**2equals the returned power spectrum everywhere, which the rawi_beamletwould not (it is a k-space sum and stays non-zero in bins where the input has effectively vanished).- Parameters:
- i_beamletnumpy.ndarray
Beamlet power spectrum on the frequency grid, shape
(nt,).- e_innumpy.ndarray
Complex input pulse spectrum on the same grid.
- Returns:
- tuple of numpy.ndarray
(i_beamlet_defined, e_beamlet), satisfyingabs(e_beamlet)**2 == i_beamlet_defined.
- pnps.io_h5.create_scan_file(path, taus, n_z, n_omega, n_windows, grid_meta)[source]#
Create the collected file with zero-filled full-size datasets.
Idempotent: an existing file is left untouched (resume relies on this).
- Parameters:
- pathstr or pathlib.Path
Target file path.
- tausnumpy.ndarray
The full delay axis in s.
- n_z, n_omega, n_windowsint
Dataset dimensions.
- grid_metadict
The
/gridmetadata fromscan_grid_metadata().
- pnps.io_h5.delivered_energy(setup)[source]#
Three-arm post-hole pulse energy of a built setup, in J.
Config.energyis the pre-mask energy of all three arms together; what the slab actually receives is whatever the input holes pass. That fraction is not grid-invariant: the pre-mask normalisation divides by the illumination’s energy over the whole momentum grid, and the HE11 far field’s tails are not fully contained, so a finer grid captures more of them and delivers slightly less through the holes. The delivered energy is therefore recorded per file rather than quoted as a constant of the instrument (a stored constant is only meaningful at the sample count it was measured on).- Parameters:
- setupSetup
The configuration; the energy is computed once, when it is built (
pnps.form_input.beamlet_diagnostics()).
- Returns:
- float
Energy of the gate pair plus the test arm in J.
- pnps.io_h5.engine_metadata(path)[source]#
Read the engine provenance a scan file recorded.
For creating a merge target with the same
/gridas its shards without building a bridge (which would allocate the whole engine).- Parameters:
- pathstr or pathlib.Path
A scan or shard file written by
create_scan_file().
- Returns:
- dict
The
ENGINE_KEYSentries, strings decoded.
- Raises:
- KeyError
If the file lacks one of them (it was not written by this engine).
- pnps.io_h5.load_simulated_scan(path, window_key='Iω_win', *, z_index=-1, z_thickness=None)[source]#
Read a scan file back, with the frequency axis in ascending order.
- Parameters:
- pathstr or pathlib.Path
The
<scan_name>_collected.h5file.- window_keystr, optional
The trace dataset:
"Iω_win"(the default, the first window),"Iω_win_reimaged","Iω_win_2", …,"Iω_full", the whole signal region (Iω_win / Iω_fullis the collection efficiency), or"Iω_beam", the whole beam.- z_indexint or “all”, optional
The save plane, by index (negative counts from the last, the default), or
"all"for every plane.- z_thicknessfloat or None, optional
Select the plane nearest this slab thickness in m instead; it takes precedence over z_index.
- Returns:
- SimulatedScan
The trace, its axes and the recorded truths.
- Raises:
- ScanError
If the file has no
/gridor delay axis, no such trace, or the plane is out of range.
- pnps.io_h5.merge_shards(target, shard_paths)[source]#
Copy every computed delay slice from shard files into
target.All files must share the layout (created from the same configuration). Returns the number of slices copied. Slices that are all-zero in a shard (not computed there) are skipped; a slice already present in the target is overwritten only by a computed shard slice.
- Parameters:
- targetstr or pathlib.Path
The collected file to merge into (must exist).
- shard_pathssequence of str or pathlib.Path
The shard files to copy from.
- Returns:
- int
The number of delay slices copied, summed over shards.
- pnps.io_h5.oversampled_time_axis(t, oversample=8)[source]#
Refine
tbyoversampleinto theToaxis, same span and centring.- Parameters:
- tnumpy.ndarray
Centred native time axis, shape
(nt,), in s.- oversampleint
Refinement factor.
- Returns:
- numpy.ndarray
Shape
(oversample * nt,), in s.
- pnps.io_h5.point_done(path, index)[source]#
Whether delay point
indexalready holds data (resume marker).- Parameters:
- pathstr or pathlib.Path
The collected or shard file (must exist).
- indexint
Position on the delay axis.
- Returns:
- bool
True if the point’s
Iω_winslice is not all zero.
- pnps.io_h5.scan_grid_metadata(setup, zsave, h_target, engine)[source]#
Assemble the
/gridmetadata dictionary for a scan file.Includes the axes and conventions Croak reads, the input-pulse truth (
Eω_re/_im), the vignetted-beamlet truth in both of the flavours the collected traces come in (seebeamlet_truth()), and the numerical parameters of the run, including the engine provenance a bridge records (pnps.bridge.Bridge.metadata:backend,stepper,pnps_engine,solprop_tableau,frame_pinned,gamma_k_applied,evanescent_clamp,index_model,measure,reduction).The beamlet truth is recorded twice because the two trace observables measure different things and must be compared against different truths.
Eω_beamletis k-integrated, the partner ofIω_win;Eω_beamlet_reimagedis the on-axis focal amplitude, the partner ofIω_win_reimaged. They are not proportional — the focal spot area goes asomega^-2, so their ratio sweeps through nearly an order of magnitude across a DUV band.Both are recorded in the state’s arbitrary units: the beamlet spectra are k-space sums over a grid whose normalisation depends on the transverse sample count, so only their shape is meaningful (that shape is invariant to the sample count to machine precision, being fixed by the momentum resolution rather than the sample count).
With an injected input pulse (
Config.input_pulse) the provenance of that field is recorded too — source file and checksum, the preparation history, the centring shift, the normalisation, the source’s own band, the band the simulation grid actually carries, and the fraction of the injected spectral energy that survived the grid — so the trace says which pulse it measured and how that pulse was put onto the grid.- Parameters:
- setupSetup
The assembled simulation (
pnps.setup.build_setup()).- zsavenumpy.ndarray
Save positions in m, shape
(n_z,).- h_targetfloat
Largest step of the replayed schedule in m.
- engineMapping of str to object
Engine provenance from the bridge (
pnps.bridge.Bridge.metadata), merged in as is.
- Returns:
- dict
Dataset name to value for the
/gridgroup.
- pnps.io_h5.temporal_truth(e_omega, oversample=8)[source]#
Temporal intensity of a spectrum, natively and oversampled.
Itis|ifft(E)|^2on the native time axis.Itois the same envelope evaluated on theoversample-times finer axis, by zero-padding the spectrum in the middle (the exact band-limited interpolation, since the envelope is band-limited by construction) and rescaling byoversample^2so that the two share one intensity scale.- Parameters:
- e_omeganumpy.ndarray
Complex spectrum on the FFT-ordered frequency axis, shape
(nt,).- oversampleint
Refinement factor for the second output.
- Returns:
- tuple of numpy.ndarray
(It, Ito)with shapes(nt,)and(oversample * nt,).
Examples
Both arrays describe one envelope, so their peaks agree:
>>> import numpy as np >>> spectrum = np.fft.fft(np.exp(-((np.arange(64) - 32.0) ** 2) / 8)) >>> it, ito = temporal_truth(spectrum) >>> bool(abs(it.max() / ito.max() - 1) < 1e-12) True
- pnps.io_h5.trace_names(n_windows)[source]#
Dataset names for the per-window traces.
The first window has no suffix; later ones get
_2,_3, …- Parameters:
- n_windowsint
Number of collection windows, >= 1.
- Returns:
- list of str
2 * n_windowsnames: for each window, the k-integrated trace followed by its reimaged partner.
- pnps.io_h5.write_point(path, index, result)[source]#
Write one delay point’s results into the collected file.
- Parameters:
- pathstr or pathlib.Path
The collected file (must exist).
- indexint
Position on the delay axis.
- resultdict
Output of
pnps.simulate.simulate_delay_point()for one delay:i_omega_win/i_omega_reimagedof shape(nz, n_windows, nt),i_omega_fullandi_omega_beamof shape(nz, nt), andlap_lostof shape(nt,).