Wavefront
Wavefront
dataclass
Wavefront(Ex: ndarray | None = None, Ey: ndarray | None = None, dx: float = 1.0, dy: float = 1.0, dz: float = 1.0, wavelength: float = 1.0, attrs: WavefrontAttrs = WavefrontAttrs(), xmid: float = 0.0, ymid: float = 0.0, zmid: float = 0.0, s_position: float = 0.0)
Bases: WavefrontBase
flowchart TD
beamphysics.Wavefront[Wavefront]
beamphysics.wavefront.wavefront.WavefrontBase[WavefrontBase]
beamphysics.wavefront.wavefront.WavefrontBase --> beamphysics.Wavefront
click beamphysics.Wavefront href "" "beamphysics.Wavefront"
click beamphysics.wavefront.wavefront.WavefrontBase href "" "beamphysics.wavefront.wavefront.WavefrontBase"
Real-space representation of electromagnetic wavefront fields.
This class represents electromagnetic fields in real space (position domain) for optical wavefront propagation and analysis. It stores complex electric field components Ex and Ey on a 3D Cartesian grid with uniform spacing.
The wavefront propagates in the +z direction, with the pulse head at max(z). Field intensities, energies, and other derived quantities follow standard electromagnetic definitions using SI units.
Parameters:
-
Ex(ndarray, default:None) –x-polarized electric field component in V/m, shape (nx, ny, nz)
-
Ey(ndarray, default:None) –y-polarized electric field component in V/m, shape (nx, ny, nz)
-
dx(float, default:1.0) –Grid spacing in x direction (m)
-
dy(float, default:1.0) –Grid spacing in y direction (m)
-
dz(float, default:1.0) –Grid spacing in z direction (m)
-
wavelength(float, default:1.0) –Central wavelength (m)
-
attrs(WavefrontAttrs or mapping, default:WavefrontAttrs()) –openPMD EXT_Wavefront attributes carried through file I/O, such as
beamline. Not interpreted by this class. A mapping keyed by either openPMD or field names is coerced toWavefrontAttrs. -
xmid(float, default:0.0) –Midpoint of the grid in m. The default of 0.0 gives a grid centered on the origin, so that
xvecruns from-(nx-1)*dx/2to+(nx-1)*dx/2. Note thatzhere is the intra-pulse coordinate, not the beamline position: see the note on frames below. -
ymid(float, default:0.0) –Midpoint of the grid in m. The default of 0.0 gives a grid centered on the origin, so that
xvecruns from-(nx-1)*dx/2to+(nx-1)*dx/2. Note thatzhere is the intra-pulse coordinate, not the beamline position: see the note on frames below. -
zmid(float, default:0.0) –Midpoint of the grid in m. The default of 0.0 gives a grid centered on the origin, so that
xvecruns from-(nx-1)*dx/2to+(nx-1)*dx/2. Note thatzhere is the intra-pulse coordinate, not the beamline position: see the note on frames below. -
s_position(float, default:0.0) –Position of this plane along the beamline in m, in whatever frame the caller picked. Advanced by
drift. See the note on frames below.
Attributes:
-
spatial_domain(SpatialDomain) –Always returns SpatialDomain.R (real space)
-
intensity(ndarray) –Total field intensity c ε₀/2 (|Ex|² + |Ey|²) in W/m²
-
energy(float) –Total field energy ε₀/2 ∫∫∫ |E|² dx dy dz in J
-
fluence(ndarray) –Fluence F(x,y) = ε₀/2 ∫ |E(x,y,z)|² dz in J/m²
-
power(ndarray) –Power profile P(z) = ∫∫ I(x,y,z) dx dy in W
-
k0(float) –Central wavenumber 2π/λ in rad/m
-
photon_energy(float) –Central photon energy ℏck₀ in eV
Methods:
-
to_kspace–Transform to k-space representation (WavefrontK)
-
drift–Propagate wavefront by distance z in free space
-
pad–Zero-pad the field arrays
-
crop–Crop the field arrays by removing elements from edges
-
auto_crop–Determine and optionally apply symmetric crop based on intensity thresholds
-
estimate_curvature–Estimate wavefront radius of curvature
-
plot_power–Plot longitudinal power profile
-
plot_fluence–Plot transverse fluence distribution
-
from_genesis4–Create Wavefront from Genesis4 HDF5 field file
-
write_genesis4–Write Wavefront to Genesis4 HDF5 format
-
from_openpmd–Create Wavefront from an openPMD EXT_Wavefront file
-
write_openpmd–Write Wavefront to an openPMD EXT_Wavefront file
Notes
- At least one of Ex or Ey must be provided
- All spacing parameters (dx, dy, dz, wavelength) must be positive
- Field arrays must be complex dtype
- Fourier transforms use norm='ortho' to preserve Plancherel's theorem: ∫∫∫ |E(x,y,z)|² dx dy dz = ∫∫∫ |Ẽ(kx,ky,kz)|² dkx dky dkz
- Statistical moments (mean, sigma) are intensity-weighted
Frames. There are two longitudinal quantities and they belong to different
frames. The mesh's own z axis, positioned by zmid, is the intra-pulse
coordinate: it is co-moving, and drift leaves it alone because the paraxial
kernel is transverse, applied slice by slice with no piston term. s_position
is the position of this plane along the beamline, and drift does advance it,
by the propagation distance.
That split follows ParticleGroup, where drift moves the coordinates that
exist rather than a separate register: there, z records that the particles
propagated. Here the mesh is co-moving and cannot record it, so s_position is
the only place the information can go. Operations that do not move the
wavefront along the beamline -- crop, pad, to_kspace, an applied lens
phase -- leave it alone, just as they leave ParticleGroup.z alone.
s_position is measured in whatever frame the caller picked, so the default of
0.0 is the origin of that frame rather than an unknown. It is written as the
EXT_Wavefront zCoordinate. Genesis4's refposition is not this quantity: it
is the coordinate of the first slice, and corresponds to zmin.
dkx
property
dkx: float
Transverse wavevector spacing in kx direction in rad/m.
dkx = 2π / (nx * dx)
dky
property
dky
Transverse wavevector spacing in ky direction in rad/m.
dky = 2π / (ny * dy)
dkz
property
dkz
Longitudinal wavevector spacing in kz direction in rad/m.
dkz = 2π / (nz * dz)
dthetax
property
dthetax
Angular spacing in thetax direction in rad.
dthetax = wavelength / (nx * dx) = dkx / k0
dthetay
property
dthetay
Angular spacing in thetay direction in rad.
dthetay = wavelength / (ny * dy) = dky / k0
energy
property
energy
Total (time-averaged) energy in J
energy = ϵ0/2 ∫∫∫ |E|^2 dx dy dz
= ϵ0/2 ∫∫∫ |Ẽ|^2 dkx dky dkz
energy_density
property
energy_density
Energy density ϵ0/2 |E|^2 in J/m^3
3D real array
fluence
property
fluence
Transverse fluence profile in J/m².
F(x,y) = ϵ0/2 ∫ |E(x,y,z)|² dz
2D real array with shape (nx, ny).
fluence_profile_x
property
fluence_profile_x
1D fluence profile along x in J/m.
F_x(x) = ϵ0/2 ∫∫ |E(x,y,z)|² dy dz
Integrated over y and z directions.
fluence_profile_y
property
fluence_profile_y
1D fluence profile along y in J/m.
F_y(y) = ϵ0/2 ∫∫ |E(x,y,z)|² dx dz
Integrated over x and z directions.
in_kspace
property
in_kspace
True if the wavefront is in k-space (Fourier domain).
in_rspace
property
in_rspace
True if the wavefront is in real space (position domain).
intensity
property
intensity: ndarray | float
total field intensity in W/m^2 I = c ϵ0/2 (|Ex|^2 + |Ey|^2)
intensity_x
property
intensity_x: ndarray | float
x polarization field intensity in W/m^2 Intensity = c ϵ0/2 |Ex|^2
intensity_y
property
intensity_y: ndarray | float
y polarization field intensity in W/m^2 Intensity = c ϵ0/2 |Ey|^2
k0
property
k0
Central wavenumber in rad/m.
k0 = 2π / wavelength
kxmax
property
kxmax
Maximum kx value in rad/m.
kxmin
property
kxmin
Minimum kx value in rad/m.
kxvec
property
kxvec
Array of kx (transverse wavenumber) values in rad/m.
kymax
property
kymax
Maximum ky value in rad/m.
kymin
property
kymin
Minimum ky value in rad/m.
kyvec
property
kyvec
Array of ky (transverse wavenumber) values in rad/m.
kzmax
property
kzmax
Maximum kz value in rad/m.
kzmin
property
kzmin
Minimum kz value in rad/m.
kzvec
property
kzvec
Array of kz (longitudinal wavenumber) values in rad/m.
mean_x
property
mean_x
Intensity-weighted mean x position in m.
mean_y
property
mean_y
Intensity-weighted mean y position in m.
mean_z
property
mean_z
Intensity-weighted mean z position in m.
nx
property
nx
Number of grid points in the x direction.
ny
property
ny
Number of grid points in the y direction.
nz
property
nz
Number of grid points in the z direction.
photon_energy
property
photon_energy: float
Central photon energy in eV
power
property
power
Longitudinal power profile along z in W.
P(z) = ∫∫ I(x, y, z) dx dy = ∫∫ (c ϵ0/2) |E(x, y, z)|² dx dy
1D real array with shape (nz,).
shape
property
shape
Shape of the field arrays as (nx, ny, nz).
sigma_x
property
sigma_x
RMS beam size in x in m.
σ_x = sqrt(
sigma_y
property
sigma_y
RMS beam size in y in m.
σ_y = sqrt(
sigma_z
property
sigma_z
RMS pulse length in z in m.
σ_z = sqrt(
thetaxmax
property
thetaxmax
Maximum thetax value in rad.
thetaxmin
property
thetaxmin
Minimum thetax value in rad.
thetaxvec
property
thetaxvec
Array of thetax (angular deviation) values in rad.
thetax = kx / k0
thetaymax
property
thetaymax
Maximum thetay value in rad.
thetaymin
property
thetaymin
Minimum thetay value in rad.
thetayvec
property
thetayvec
Array of thetay (angular deviation) values in rad.
thetay = ky / k0
xmax
property
xmax
Maximum x coordinate in m.
xmax = xmid + (nx-1) * dx / 2
xmin
property
xmin
Minimum x coordinate in m.
xmin = xmid - (nx-1) * dx / 2
xvec
property
xvec
Array of x coordinates in m.
ymax
property
ymax
Maximum y coordinate in m.
ymax = ymid + (ny-1) * dy / 2
ymin
property
ymin
Minimum y coordinate in m.
ymin = ymid - (ny-1) * dy / 2
yvec
property
yvec
Array of y coordinates in m.
zmax
property
zmax
Maximum z coordinate in m.
zmax = zmid + (nz-1) * dz / 2
zmin
property
zmin
Minimum z coordinate in m.
zmin = zmid - (nz-1) * dz / 2
zvec
property
zvec
Array of z coordinates in m.
__post_init__
__post_init__()
Validate inputs after dataclass initialization
Source code in beamphysics/wavefront/wavefront.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
__setattr__
__setattr__(name, value)
Keep attrs a WavefrontAttrs however it is set.
A mapping keyed by either openPMD or field names is accepted for
convenience, but the attribute itself is always the typed object. Coercing
only in __post_init__ would leave a plain assignment such as
w.attrs = {...} holding a raw dict, so that w.attrs.beamline
raises AttributeError and the mapping's contents go unvalidated until
write time.
Source code in beamphysics/wavefront/wavefront.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
auto_crop
auto_crop(threshold: float = 1e-06, apply: bool = True)
Determine symmetric crop values based on intensity profile thresholds.
Analyzes the 1D intensity projections along each axis to find regions where the signal falls below a relative threshold, then computes symmetric crop amounts for each axis.
Parameters:
-
threshold(float, default:1e-6) –Relative threshold (fraction of maximum) below which data is considered negligible and can be cropped.
-
apply(bool, default:True) –If True, apply the crop and return the cropped wavefront. If False, return only the crop amounts as a dictionary.
Returns:
-
Wavefront, WavefrontK, or dict–If apply=True: New wavefront with cropped field arrays. If apply=False: Dictionary with keys 'nx', 'ny', 'nz' containing the symmetric crop amounts for each axis.
Examples:
>>> from beamphysics.wavefront import Wavefront
>>> w = Wavefront.from_gaussian(
... shape=(64, 64, 16), dx=1e-6, dy=1e-6, dz=1e-6,
... wavelength=1e-9, sigma0=3e-6, sigma_z=2e-6,
... )
Get the crop amounts without applying them:
>>> crop_info = w.auto_crop(threshold=1e-4, apply=False)
>>> crop_info
{'nx': 19, 'ny': 19, 'nz': 0}
Apply the crop directly, removing that many elements from each end:
>>> w.auto_crop(threshold=1e-4).shape
(26, 26, 16)
The two steps are equivalent, so the amounts can be inspected or adjusted first:
>>> w.crop(**crop_info).shape
(26, 26, 16)
Source code in beamphysics/wavefront/wavefront.py
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 | |
axis_index
axis_index(key)
Returns axis index for a named axis label key.
Examples:
.axis_labels == ('x', 'y', 'z').axis_index('z')returns2
Source code in beamphysics/wavefront/wavefront.py
186 187 188 189 190 191 192 193 194 195 | |
copy
copy()
Returns a deep copy
Source code in beamphysics/wavefront/wavefront.py
692 693 694 | |
crop
crop(nx=(0, 0), ny=(0, 0), nz=(0, 0))
Crop the field arrays by removing elements from edges.
Parameters:
-
nx(int or tuple of (int, int), default:(0, 0)) –Number of elements to remove from (start, end) of first axis. If a single int, removes symmetrically from both sides.
-
ny(int or tuple of (int, int), default:(0, 0)) –Number of elements to remove from (start, end) of second axis. If a single int, removes symmetrically from both sides.
-
nz(int or tuple of (int, int), default:(0, 0)) –Number of elements to remove from (start, end) of third axis. If a single int, removes symmetrically from both sides.
Returns:
-
Wavefront or WavefrontK–New wavefront with cropped field arrays.
Raises:
-
ValueError–If crop amounts exceed array dimensions.
Notes
The surviving samples keep their physical coordinates: an asymmetric crop moves the grid origin rather than re-centering the grid.
Source code in beamphysics/wavefront/wavefront.py
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 | |
estimate_curvature
estimate_curvature(axis: str = 'x', polarization: str | None = None, ix: int | None = None, iy: int | None = None, iz: int | None = None, plot: bool = False, cutoff: float = 0.0001) -> float | tuple[float, Figure]
Estimates the wavefront curvature by looking at the phase across an axis.
The method fits a parabola to the unwrapped phase: phase = k r^2 / 2R + phi0 where R is the radius of curvature and k is the wavenumber.
Parameters:
-
axis(str, default:'x') –Axis along which to estimate curvature ('x' or 'y')
-
polarization(str, default:None) –Polarization to analyze ('x' or 'y'). If None, uses first available.
-
ix(int, default:None) –Indices for slicing. iz defaults to peak intensity slice.
-
iy(int, default:None) –Indices for slicing. iz defaults to peak intensity slice.
-
iz(int, default:None) –Indices for slicing. iz defaults to peak intensity slice.
-
plot(bool, default:False) –Whether to create a diagnostic plot
-
cutoff(float, default:1e-4) –Relative intensity cutoff for data selection
Returns:
-
float–Curvature in 1/m.
Raises:
-
ValueError–If insufficient data points or invalid parameters
Source code in beamphysics/wavefront/wavefront.py
1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 | |
from_gaussian
classmethod
from_gaussian(shape: tuple[int, int, int], dx: float = 1.0, dy: float = 1.0, dz: float = 1.0, wavelength: float = 1.0, sigma0: float | None = None, z0: float = 0.0, x0: float = 0.0, y0: float = 0.0, sigma_z: float | None = None, energy: float = 1.0, phase: float = 0.0, polarization: str = 'x') -> 'Wavefront'
Create a Wavefront with a Gaussian beam.
Parameters:
-
shape(tuple[int, int, int]) –Grid shape (nx, ny, nz)
-
dx(float, default:1.0) –Grid spacing in x direction (m)
-
dy(float, default:1.0) –Grid spacing in y direction (m)
-
dz(float, default:1.0) –Grid spacing in z direction (m)
-
wavelength(float, default:1.0) –Central wavelength (m)
-
sigma0(float, default:None) –RMS transverse beam size at the waist in meters (round beam). Related to waist size w0 via: w0 = 2·σ₀ Related to Rayleigh length via: z_R = 4π·σ₀² / λ = π·w0² / λ
-
z0(float, default:0.0) –Propagation distance from the waist (m), the same quantity
driftadvances. Sets the transverse size, curvature and Gouy phase. It does not shift the pulse along the meshzaxis (setzmid), nor set the beamline position (sets_position). -
x0(float, default:0.0) –Beam center position in x (m)
-
y0(float, default:0.0) –Beam center position in y (m)
-
sigma_z(float or None, default:None) –Longitudinal Gaussian width (m). If None, use constant longitudinal profile.
-
energy(float, default:1.0) –Total beam energy in Joules
-
phase(float, default:0.0) –Global phase offset (radians)
-
polarization(str, default:'x') –Polarization direction ('x' or 'y')
Returns:
-
Wavefront–New Wavefront instance with Gaussian beam
Raises:
-
ValueError–If sigma0 is not specified If polarization is not 'x' or 'y' If sigma_z is negative
Notes
The Gaussian beam uses the complex beam parameter formalism in the
exp(-i·ω·t + i·k·z) convention shared by drift and openPMD EXT_Wavefront:
q(z) = z - i·z_R where z_R = 4π·σ₀² / λ = π·w0² / λ
u_xy(x,y,z) = (1/q) · exp(i·k·(x² + y²)/(2q))
For sigma_z > 0: u_z(z) = exp(-z²/(4σ_z²)) / √(√(2π)·σ_z) For sigma_z = None: u_z(z) = 1 (constant profile, normalized over grid)
The field is normalized such that: ∫∫∫ |u|² dx dy dz = energy / (2·Z₀·c)
The relationship between sigma0 and common Gaussian beam parameters: - Waist size (1/e² intensity radius): w0 = 2·σ₀ - Rayleigh length: z_R = π·w0²/λ = 4π·σ₀²/λ
References
- Wikipedia: Gaussian beam, Complex beam parameter
- Siegman "Lasers" 1986, Chapter 16.3
Source code in beamphysics/wavefront/wavefront.py
2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 | |
from_genesis4
classmethod
from_genesis4(file: Union[Path, str, Group])
Create a Wavefront instance from a Genesis4 field file.
This method reads a Genesis4 field file (either from disk or an open HDF5 group)
and initializes a Wavefront instance with the extracted field data.
Parameters:
-
file(Union[Path, str, Group]) –The path to the Genesis4 HDF5 field file or an open
h5py.Group.
Returns:
-
Wavefront–A new instance of
Wavefrontinitialized with field data from the Genesis4 file.
Raises:
-
ValueError–If the provided file is not a valid path, string, or
h5py.Group.
Notes
- The field data is extracted and converted into an electric field representation.
- The grid spacing (
dxanddz) and wavelength are obtained from the file metadata. - Genesis4's
refpositionis the coordinate of the first slice, so it setszmin. The transverse grid is centered on the axis.
Source code in beamphysics/wavefront/wavefront.py
1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 | |
from_openpmd
classmethod
from_openpmd(file: Union[Path, str, Group], iteration: int | None = None)
Create a Wavefront from an openPMD file using the EXT_Wavefront extension.
Parameters:
-
file(Union[Path, str, Group]) –Path to the openPMD HDF5 file, or an open
h5py.Groupto use as the series root. -
iteration(int, default:None) –openPMD iteration to read. If None, the file must hold exactly one.
Returns:
-
Wavefront–A new instance holding the field data, with the extension's
zCoordinateins_positionand any other record attributes carried in.attrs.
Raises:
-
ValueError–If the file is not a valid path, string, or
h5py.Group; if a required attribute is missing; or if the file holds a frequency-domain or k-space field, neither of which this class can represent.
Notes
Any axisLabels permutation of (x, y, z) is honored on read, though the
writer always stores (z, y, x).
Source code in beamphysics/wavefront/wavefront.py
1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 | |
pad
pad(nx=(0, 0), ny=(0, 0), nz=(0, 0))
zero-pad the field arrays.
If only a single number is given, the array will be symmetrically padded by this
Source code in beamphysics/wavefront/wavefront.py
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
plot2
plot2(cmap='inferno', logscale=False)
Simple fluence plot
Notes
This is experimental.
Source code in beamphysics/wavefront/wavefront.py
1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 | |
plot_fluence
plot_fluence(cmap='inferno', logscale=False)
Simple fluence plot
Source code in beamphysics/wavefront/wavefront.py
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 | |
to_kspace
to_kspace(backend=numpy, *, inplace: bool = False) -> WavefrontK
Transform to k-space according to the Fourier transform convention:
Ẽ(kx,ky,kz) = 1/(2π)^(2/3) ∫∫∫ E(x,y,z) exp(-i kx x) exp(-i ky y) exp(-i kz z) dx dy dz
E(x,y,z) = 1/(2π)^(2/3) ∫∫∫ Ẽ(kx, ky, kz) exp(i kx x) exp(i ky y) exp(i kz z) dkx dky dkz
This ensures that that Plancherel's theorm applies without any addition factors ∫∫∫ |E(x, y, z)|^2 dx dy dz = ∫∫∫ |Ẽ(kx, ky, kz)|^2 dkx dky dkz
And therefore ϵ0/2 |Ẽ|^2 can be directly interpreted as the spectral energy density.
This is realized with factors so that: Ẽ = [dx sqrt(nx/(2π))][beamphysics.wavefront.wavefront] [...] fftn(E, norm = 'ortho') in units of V * m^2
E = [dkx sqrt(nx/(2π))][beamphysics.wavefront.wavefront] [...] fftn(Ẽ, norm = 'ortho') in units of V/m
Here [...] is similar for y, z, etc. We use norm='ortho' to simplify the symmetry in the code.
Source code in beamphysics/wavefront/wavefront.py
1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 | |
write_genesis4
write_genesis4(file: Path | str | Group)
Write the Wavefront field data to a Genesis4-style HDF5 file.
This method saves the wavefront field data into a Genesis4-compatible HDF5 file, either by creating a new file on disk or writing into an existing HDF5 group.
Parameters:
-
file(Union[Path, str, Group]) –The path to the output HDF5 file or an open
h5py.Groupfor writing.
Raises:
-
ValueError–If the provided file is not a valid path, string, or
h5py.Group.
Notes
- If
fileis a path or string, a new HDF5 file is created and written to. - If
fileis anh5py.Group, the data is written directly into the provided group. zminis written as Genesis4'srefposition.s_positionandattrshave nowhere to go in this format and are dropped.
Source code in beamphysics/wavefront/wavefront.py
1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 | |
write_openpmd
write_openpmd(file: Path | str | Group, iteration: int = 1, **extension_attrs)
Write the Wavefront as an openPMD file using the EXT_Wavefront extension.
Parameters:
-
file(Union[Path, str, Group]) –Path for a new HDF5 file, or an open
h5py.Groupto use as the series root. -
iteration(int, default:1) –openPMD iteration index to write.
-
**extension_attrs–WavefrontAttrsfield names (beamline,radius_of_curvature_x,radius_of_curvature_y,delta_radius_of_curvature_x,delta_radius_of_curvature_y), taking precedence over.attrs.
Raises:
-
ValueError–If the file is not a valid path, string, or
h5py.Group. -
TypeError–If an attribute name is not a
WavefrontAttrsfield.
Notes
Both transverse polarizations are written into one file as components x
and y of the electricField record; the z component is never written.
The required zCoordinate is written from s_position. There is no
write-time override: it is a coordinate the propagators maintain, so a
keyword here could put a value in the file that disagrees with the
wavefront it came from. Set s_position on the wavefront instead.
Source code in beamphysics/wavefront/wavefront.py
1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 | |
WavefrontK
dataclass
WavefrontK(Ex: ndarray | None = None, Ey: ndarray | None = None, dkx: float = 1.0, dky: float = 1.0, dkz: float = 1.0, wavelength: float = 1.0, attrs: WavefrontAttrs = WavefrontAttrs(), xmid: float = 0.0, ymid: float = 0.0, zmid: float = 0.0, s_position: float = 0.0)
Bases: WavefrontBase
flowchart TD
beamphysics.WavefrontK[WavefrontK]
beamphysics.wavefront.wavefront.WavefrontBase[WavefrontBase]
beamphysics.wavefront.wavefront.WavefrontBase --> beamphysics.WavefrontK
click beamphysics.WavefrontK href "" "beamphysics.WavefrontK"
click beamphysics.wavefront.wavefront.WavefrontBase href "" "beamphysics.wavefront.wavefront.WavefrontBase"
K-space (Fourier) representation of electromagnetic wavefront fields.
This class represents electromagnetic fields in k-space (spatial frequency domain) for spectral analysis and propagation. It stores complex electric field Fourier components Ẽx and Ẽy on a 3D reciprocal-space grid with uniform spacing.
The Fourier transform convention follows: Ẽ(kx,ky,kz) = (2π)^(-3/2) ∫∫∫ E(x,y,z) exp(-i·k·r) dx dy dz
Parameters:
-
Ex(ndarray, default:None) –x-polarized electric field Fourier component in V·m², shape (nx, ny, nz)
-
Ey(ndarray, default:None) –y-polarized electric field Fourier component in V·m², shape (nx, ny, nz)
-
dkx(float, default:1.0) –Grid spacing in kx direction (rad/m)
-
dky(float, default:1.0) –Grid spacing in ky direction (rad/m)
-
dkz(float, default:1.0) –Grid spacing in kz direction (rad/m)
-
wavelength(float, default:1.0) –Central wavelength (m)
-
attrs(WavefrontAttrs or mapping, default:WavefrontAttrs()) –openPMD EXT_Wavefront attributes carried through file I/O, such as
beamline. Not interpreted by this class. A mapping keyed by either openPMD or field names is coerced toWavefrontAttrs. -
xmid(float, default:0.0) –Midpoint of the real-space grid in m, carried through from the real-space wavefront. Not interpreted here: a real-space shift is a linear phase in k-space, not a shift of the k grid.
-
ymid(float, default:0.0) –Midpoint of the real-space grid in m, carried through from the real-space wavefront. Not interpreted here: a real-space shift is a linear phase in k-space, not a shift of the k grid.
-
zmid(float, default:0.0) –Midpoint of the real-space grid in m, carried through from the real-space wavefront. Not interpreted here: a real-space shift is a linear phase in k-space, not a shift of the k grid.
-
s_position(float, default:0.0) –Beamline position of this plane in m, carried through from the real-space wavefront.
Attributes:
-
spatial_domain(SpatialDomain) –Always returns SpatialDomain.K (k-space)
-
intensity(ndarray) –Spectral intensity |Ẽ|² (arbitrary units)
-
spectral_energy_density(ndarray) –Spectral energy density ε₀/2 |Ẽ|² in J·m³
-
energy(float) –Total energy ε₀/2 ∫∫∫ |Ẽ|² dkx dky dkz in J
-
spectral_fluence(ndarray) –K-space fluence F(kx,ky) = ε₀/2 ∫ |Ẽ|² dkz in J·m²
-
photon_energy_vec(ndarray) –Photon energy axis from kz in eV
-
photon_energy_spectrum(ndarray) –Photon spectral energy density dU/dE in J/eV
-
k0(float) –Central wavenumber 2π/λ in rad/m
-
photon_energy(float) –Central photon energy ℏck₀ in eV
Methods:
-
to_rspace–Transform to real-space representation (Wavefront)
-
plot_spectral_intensity–Plot angular spectrum intensity F(θx, θy)
-
plot_photon_energy_spectrum–Plot photon energy spectrum dU/dE
-
pad–Zero-pad the field arrays
-
crop–Crop the field arrays by removing elements from edges
-
auto_crop–Determine and optionally apply symmetric crop based on intensity thresholds
Notes
- At least one of Ex or Ey must be provided
- All spacing parameters (dkx, dky, dkz, wavelength) must be positive
- Field arrays must be complex dtype
- The spectral energy density ε₀/2|Ẽ|² preserves total energy with real space
- Derived real-space grid spacing: dx = 2π/(nx·dkx)
- Angular coordinates: θx = kx/k₀, θy = ky/k₀
- Statistical moments (mean, sigma) are intensity-weighted in k-space
dthetax
property
dthetax
Angular spacing in thetax direction in rad.
dthetax = wavelength / (nx * dx) = dkx / k0
dthetay
property
dthetay
Angular spacing in thetay direction in rad.
dthetay = wavelength / (ny * dy) = dky / k0
dx
property
dx: float
grid spacing in m dx = 2π / (nx * dkx)
dy
property
dy
grid spacing in m dy = 2π / (nx * dky)
dz
property
dz
grid spacing in m dz = 2π / (nx * dkz)
energy
property
energy
Total (time-averaged) energy in J
energy = ϵ0/2 ∫∫∫ |E|^2 dx dy dz
= ϵ0/2 ∫∫∫ |Ẽ|^2 dkx dky dkz
in_kspace
property
in_kspace
True if the wavefront is in k-space (Fourier domain).
in_rspace
property
in_rspace
True if the wavefront is in real space (position domain).
intensity
property
intensity: ndarray | float
Total spectral intensity in V²·m⁴.
|Ẽx|² + |Ẽy|²
intensity_x
property
intensity_x
x-polarization spectral intensity in V²·m⁴.
Spectral intensity |Ẽx|²
intensity_y
property
intensity_y
y-polarization spectral intensity in V²·m⁴.
Spectral intensity |Ẽy|²
k0
property
k0
Central wavenumber in rad/m.
k0 = 2π / wavelength
kxmax
property
kxmax
Maximum kx value in rad/m.
kxmin
property
kxmin
Minimum kx value in rad/m.
kxvec
property
kxvec
Array of kx (transverse wavenumber) values in rad/m.
kymax
property
kymax
Maximum ky value in rad/m.
kymin
property
kymin
Minimum ky value in rad/m.
kyvec
property
kyvec
Array of ky (transverse wavenumber) values in rad/m.
kzmax
property
kzmax
Maximum kz value in rad/m.
kzmin
property
kzmin
Minimum kz value in rad/m.
kzvec
property
kzvec
Array of kz (longitudinal wavenumber) values in rad/m.
mean_kx
property
mean_kx
Intensity-weighted mean kx in rad/m.
mean_ky
property
mean_ky
Intensity-weighted mean ky in rad/m.
mean_kz
property
mean_kz
Intensity-weighted mean kz in rad/m.
mean_thetax
property
mean_thetax
Intensity-weighted mean thetax in rad.
<θx> =
mean_thetay
property
mean_thetay
Intensity-weighted mean thetay in rad.
<θy> =
nx
property
nx
Number of grid points in the x direction.
ny
property
ny
Number of grid points in the y direction.
nz
property
nz
Number of grid points in the z direction.
photon_energy
property
photon_energy: float
Central photon energy in eV
photon_energy_spectrum
property
photon_energy_spectrum: ndarray
Photon energy spectrum dU/dE in J/eV
dU/dE = (ε0/2) ∫∫ |Ẽ|² dkx dky / (ħc/e)
See .photon_energy_vec for the corresponding photon energies in eV.
photon_energy_vec
property
photon_energy_vec: ndarray
Photon energy axis from kz in eV
shape
property
shape
Shape of the field arrays as (nx, ny, nz).
sigma_kx
property
sigma_kx
RMS width in kx in rad/m.
σ_kx = sqrt(
sigma_ky
property
sigma_ky
RMS width in ky in rad/m.
σ_ky = sqrt(
sigma_kz
property
sigma_kz
RMS width in kz in rad/m.
σ_kz = sqrt(
sigma_thetax
property
sigma_thetax
RMS angular width in thetax in rad.
σ_θx = sqrt(<θx²> - <θx>²)
sigma_thetay
property
sigma_thetay
RMS angular width in thetay in rad.
σ_θy = sqrt(<θy²> - <θy>²)
spectral_energy_density
property
spectral_energy_density
Spectral energy density ϵ0/2 |Ẽ|^2 in J * m^3
3D real array
spectral_fluence
property
spectral_fluence
K-space Fluence in the z direction:
F(kx,ky) = ϵ0/2 ∫∫∫ |Ẽ(kx,ky,kz)|^2 dkz in J * m^2
thetaxmax
property
thetaxmax
Maximum thetax value in rad.
thetaxmin
property
thetaxmin
Minimum thetax value in rad.
thetaxvec
property
thetaxvec
Array of thetax (angular deviation) values in rad.
thetax = kx / k0
thetaymax
property
thetaymax
Maximum thetay value in rad.
thetaymin
property
thetaymin
Minimum thetay value in rad.
thetayvec
property
thetayvec
Array of thetay (angular deviation) values in rad.
thetay = ky / k0
xmax
property
xmax
Maximum x coordinate in m.
xmax = xmid + (nx-1) * dx / 2
xmin
property
xmin
Minimum x coordinate in m.
xmin = xmid - (nx-1) * dx / 2
xvec
property
xvec
Array of x coordinates in m.
ymax
property
ymax
Maximum y coordinate in m.
ymax = ymid + (ny-1) * dy / 2
ymin
property
ymin
Minimum y coordinate in m.
ymin = ymid - (ny-1) * dy / 2
yvec
property
yvec
Array of y coordinates in m.
zmax
property
zmax
Maximum z coordinate in m.
zmax = zmid + (nz-1) * dz / 2
zmin
property
zmin
Minimum z coordinate in m.
zmin = zmid - (nz-1) * dz / 2
zvec
property
zvec
Array of z coordinates in m.
__post_init__
__post_init__()
Validate inputs after dataclass initialization
Source code in beamphysics/wavefront/wavefront.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
__setattr__
__setattr__(name, value)
Keep attrs a WavefrontAttrs however it is set.
A mapping keyed by either openPMD or field names is accepted for
convenience, but the attribute itself is always the typed object. Coercing
only in __post_init__ would leave a plain assignment such as
w.attrs = {...} holding a raw dict, so that w.attrs.beamline
raises AttributeError and the mapping's contents go unvalidated until
write time.
Source code in beamphysics/wavefront/wavefront.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
auto_crop
auto_crop(threshold: float = 1e-06, apply: bool = True)
Determine symmetric crop values based on intensity profile thresholds.
Analyzes the 1D intensity projections along each axis to find regions where the signal falls below a relative threshold, then computes symmetric crop amounts for each axis.
Parameters:
-
threshold(float, default:1e-6) –Relative threshold (fraction of maximum) below which data is considered negligible and can be cropped.
-
apply(bool, default:True) –If True, apply the crop and return the cropped wavefront. If False, return only the crop amounts as a dictionary.
Returns:
-
Wavefront, WavefrontK, or dict–If apply=True: New wavefront with cropped field arrays. If apply=False: Dictionary with keys 'nx', 'ny', 'nz' containing the symmetric crop amounts for each axis.
Examples:
>>> from beamphysics.wavefront import Wavefront
>>> w = Wavefront.from_gaussian(
... shape=(64, 64, 16), dx=1e-6, dy=1e-6, dz=1e-6,
... wavelength=1e-9, sigma0=3e-6, sigma_z=2e-6,
... )
Get the crop amounts without applying them:
>>> crop_info = w.auto_crop(threshold=1e-4, apply=False)
>>> crop_info
{'nx': 19, 'ny': 19, 'nz': 0}
Apply the crop directly, removing that many elements from each end:
>>> w.auto_crop(threshold=1e-4).shape
(26, 26, 16)
The two steps are equivalent, so the amounts can be inspected or adjusted first:
>>> w.crop(**crop_info).shape
(26, 26, 16)
Source code in beamphysics/wavefront/wavefront.py
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 | |
axis_index
axis_index(key)
Returns axis index for a named axis label key.
Examples:
.axis_labels == ('x', 'y', 'z').axis_index('z')returns2
Source code in beamphysics/wavefront/wavefront.py
186 187 188 189 190 191 192 193 194 195 | |
copy
copy()
Returns a deep copy
Source code in beamphysics/wavefront/wavefront.py
692 693 694 | |
crop
crop(nx=(0, 0), ny=(0, 0), nz=(0, 0))
Crop the field arrays by removing elements from edges.
Parameters:
-
nx(int or tuple of (int, int), default:(0, 0)) –Number of elements to remove from (start, end) of first axis. If a single int, removes symmetrically from both sides.
-
ny(int or tuple of (int, int), default:(0, 0)) –Number of elements to remove from (start, end) of second axis. If a single int, removes symmetrically from both sides.
-
nz(int or tuple of (int, int), default:(0, 0)) –Number of elements to remove from (start, end) of third axis. If a single int, removes symmetrically from both sides.
Returns:
-
Wavefront or WavefrontK–New wavefront with cropped field arrays.
Raises:
-
ValueError–If crop amounts exceed array dimensions.
Notes
The surviving samples keep their physical coordinates: an asymmetric crop moves the grid origin rather than re-centering the grid.
Source code in beamphysics/wavefront/wavefront.py
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 | |
pad
pad(nx=(0, 0), ny=(0, 0), nz=(0, 0))
zero-pad the field arrays.
If only a single number is given, the array will be symmetrically padded by this
Source code in beamphysics/wavefront/wavefront.py
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
plot_spectral_intensity
plot_spectral_intensity(cmap='inferno', logscale=False)
Simple projected intensity plot
Source code in beamphysics/wavefront/wavefront.py
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 | |
to_rspace
to_rspace(*, inplace: bool = False) -> Wavefront
See Wavefront.to_kspace()
Source code in beamphysics/wavefront/wavefront.py
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
openpmd
openPMD EXT_Wavefront reading and writing for the Wavefront class.
The layout below follows the Wavefront extension of the openPMD standard
(branch upcoming-2.0.0), which is authoritative::
/ openPMD "2.0.0", openPMDextension "Wavefront",
basePath "/data/%T/", meshesPath "meshes/",
iterationEncoding "groupBased"
/data/<iteration>/ one iteration per file. Slices of a single pulse are
simultaneous, so the slice axis is a *mesh* axis and
never the openPMD iteration.
.../meshes/electricField the mesh record. All required attributes live on the
record: the base standard's geometry, axisLabels,
gridSpacing, gridGlobalOffset, gridUnitSI,
gridUnitDimension, unitDimension and timeOffset, plus
the extension's photonEnergy [J], temporalDomain,
spatialDomain and zCoordinate.
.../electricField/x, y complex compound ``{r, i}`` datasets in V/m, which
h5py maps to complex dtypes natively. The ``z``
component is never written: a paraxial field has none.
Datasets are stored in (z, y, x) order -- declared by axisLabels -- so that each
transverse slice is one contiguous block in the file. The class's (nx, ny, nz)
convention is recovered by a transpose that is applied one slice at a time, keeping peak
memory at one field plus one transverse slice rather than two full copies.
Only the real-space, time-domain case is implemented; spatialDomain='k' and
temporalDomain='frequency' are refused by name.
Classes:
-
WavefrontAttrs–openPMD EXT_Wavefront attributes carried alongside a
Wavefront.
Functions:
-
load_wavefront_openpmd–Read an openPMD EXT_Wavefront series into
Wavefrontconstructor arguments. -
write_wavefront_openpmd–Write a
Wavefrontinto an open HDF5 group as an openPMD EXT_Wavefront series.
WavefrontAttrs
dataclass
WavefrontAttrs(beamline: str | None = None, radius_of_curvature_x: float | None = None, radius_of_curvature_y: float | None = None, delta_radius_of_curvature_x: float | None = None, delta_radius_of_curvature_y: float | None = None, other: dict = dict())
openPMD EXT_Wavefront attributes carried alongside a Wavefront.
Field names are Python-style; the corresponding openPMD attribute names, used in
the file, are camelCase and recorded in each field's metadata. Attributes the
class derives from its own state -- photonEnergy, temporalDomain,
spatialDomain, zCoordinate and the grid attributes -- are deliberately
absent. zCoordinate in particular is Wavefront.s_position, which is a
coordinate the propagators advance rather than provenance carried through I/O.
Parameters:
-
beamline(str, default:None) –Name of the beamline this wavefront belongs to.
-
radius_of_curvature_x(float, default:None) –Radius of curvature in x, in m.
-
radius_of_curvature_y(float, default:None) –Radius of curvature in y, in m.
-
delta_radius_of_curvature_x(float, default:None) –Uncertainty in
radius_of_curvature_x, in m. -
delta_radius_of_curvature_y(float, default:None) –Uncertainty in
radius_of_curvature_y, in m. -
other(dict, default:dict()) –Record attributes that are not part of the extension as this module knows it, keyed by their openPMD name. Populated on read and written back verbatim, so that a file using a newer revision of the extension survives a round trip. Names this module computes are refused. Named after the
otherdict thatreaders.load_field_attrsuses for the same purpose.
Raises:
-
ValueError–If
otherholds a name that has a field of its own, or one that the writer computes.
Examples:
>>> attrs = WavefrontAttrs(beamline="SXR", radius_of_curvature_x=12.5)
>>> attrs.to_pmd()["radiusOfCurvatureX"]
12.5
A misspelled attribute is a TypeError at construction rather than a silent
omission at write time:
>>> WavefrontAttrs(radius_of_curvature_z=1.0)
Traceback (most recent call last):
...
TypeError: ...
Methods:
-
copy–Return an independent copy, including
other. -
from_pmd–Build from a mapping keyed by openPMD attribute names.
-
pmd_keys–Map field names to their openPMD attribute names.
-
to_pmd–Render as a mapping keyed by openPMD attribute names.
copy
copy()
Return an independent copy, including other.
Returns:
Source code in beamphysics/wavefront/openpmd.py
273 274 275 276 277 278 279 280 281 282 283 284 | |
from_pmd
classmethod
from_pmd(attrs)
Build from a mapping keyed by openPMD attribute names.
Parameters:
-
attrs(mapping) –Attribute names to values. Field names are also accepted, so that a dict written in Python style round-trips. A nested
othermapping is merged intootherrather than nested inside it. Anything unrecognized is kept inother.
Returns:
Raises:
-
ValueError–If an attribute is given under both its openPMD name and its field name. Silently preferring one would write the other to the file as a nonstandard attribute holding a conflicting value.
Source code in beamphysics/wavefront/openpmd.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
pmd_keys
classmethod
pmd_keys()
Map field names to their openPMD attribute names.
Returns:
-
dict–{field_name: pmd_key}, excludingother.
Source code in beamphysics/wavefront/openpmd.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
to_pmd
to_pmd()
Render as a mapping keyed by openPMD attribute names.
Returns:
-
dict–Set fields plus
other. Fields left as None are omitted, since the extension treats them as absent rather than zero.
Source code in beamphysics/wavefront/openpmd.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
load_wavefront_openpmd
load_wavefront_openpmd(h5, iteration=None)
Read an openPMD EXT_Wavefront series into Wavefront constructor arguments.
Parameters:
-
h5(Group) –Series root.
-
iteration(int, default:None) –Iteration to read. If None, the file must hold exactly one.
Returns:
-
dict–Keyword arguments for
Wavefront:Ex,Ey,dx,dy,dz,wavelength,attrs(aWavefrontAttrs) and, when the file declares agridGlobalOffset,xmid,ymidandzmid.
Raises:
-
ValueError–If a required attribute is missing, or if the file holds something this class cannot represent: a frequency-domain field, a k-space field,
axisLabelsthat are not a permutation of x, y and z, or x and y components with differentpositionvalues, or a nonzero z component.
Notes
Any axisLabels permutation of (x, y, z) is honored, with gridSpacing
permuted alongside it. Scalar attributes stored as length-1 arrays and strings
stored as bytes are both tolerated. gridUnitSI, gridGlobalOffset, the
per-component position and the per-component unitSI are applied, so a file
written in non-SI units or with cell-centered samples reads correctly;
gridUnitSI is accepted either as the openPMD 2.0 per-axis array or as the 1.x
scalar. A constant component may take its shape from a sibling.
Source code in beamphysics/wavefront/openpmd.py
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 | |
write_wavefront_openpmd
write_wavefront_openpmd(wavefront, h5, iteration=1, **extension_attrs)
Write a Wavefront into an open HDF5 group as an openPMD EXT_Wavefront series.
Parameters:
-
wavefront(Wavefront) –Real-space, time-domain wavefront.
ExandEyare in V/m with shape(nx, ny, nz); an absent polarization is not written. Itss_positionis written as the extension's requiredzCoordinate. -
h5(Group) –Group to use as the openPMD series root.
-
iteration(int, default:1) –openPMD iteration index to write under
basePath. -
**extension_attrs–WavefrontAttrsfield names (beamline,radius_of_curvature_x, ...), taking precedence over the same fields inwavefront.attrs.
Raises:
-
TypeError–If an attribute name is not a
WavefrontAttrsfield.
Notes
Datasets are stored in (z, y, x) order and written one transverse slice at a
time, so no full transposed copy of the field is ever materialized.
Source code in beamphysics/wavefront/openpmd.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |