wofry.propagator.wavefront1D package

Submodules

wofry.propagator.wavefront1D.generic_wavefront module

1D generic wavefront: complex amplitude on a scaled array with propagation utilities.

class wofry.propagator.wavefront1D.generic_wavefront.GenericWavefront1D(wavelength=1e-10, electric_field_array=None, electric_field_array_pi=None)[source]

Bases: Wavefront

1D wavefront storing a complex electric-field amplitude on a uniformly-spaced grid.

Supports sigma (and optionally pi) polarisation components, photon-energy setting, common initialisers, interpolated accessors, phase/amplitude modifiers, and HDF5 serialisation.

All spatial coordinates are in metres; photon energy in eV; wavelength in metres.

add_phase_shift(phase_shift, polarization=0)[source]

Multiply the complex amplitude by exp(i·phase_shift) (scalar).

Parameters:
  • phase_shift (float) – Phase to add in radians.

  • polarization (int, optional) – Polarization.SIGMA (default) or PI.

add_phase_shifts(phase_shifts, polarization=0)[source]

Multiply the complex amplitude element-wise by exp(i·phase_shifts).

Parameters:
  • phase_shifts (numpy.ndarray) – Phase array in radians (must match grid size).

  • polarization (int, optional) – Polarization.SIGMA (default) or PI.

clip(x_min, x_max, negative=False)[source]

Apply a rectangular aperture or stop.

Parameters:
  • x_min (float) – Aperture edges in metres.

  • x_max (float) – Aperture edges in metres.

  • negative (bool, optional) – If True, apply a beam stop (zero inside) instead of an aperture.

delta()[source]

Return the grid spacing in metres.

Return type:

float

duplicate()[source]

Return a deep copy of this wavefront.

Return type:

GenericWavefront1D

get_abscissas()[source]

Return the coordinate array in metres.

Return type:

numpy.ndarray

get_amplitude(polarization=0)[source]

Return the amplitude |E| array.

Parameters:

polarization (int, optional) – Polarization.SIGMA (default) or Polarization.PI.

Return type:

numpy.ndarray

get_complex_amplitude(polarization=0)[source]

Return the complex electric-field amplitude array.

Parameters:

polarization (int, optional) – Polarization.SIGMA (default) or Polarization.PI.

Return type:

numpy.ndarray of complex

get_dimension()[source]

Return WavefrontDimension.ONE.

get_integrated_intensity(polarization=0)[source]

Return the intensity integrated over the grid (Σ I·Δx).

Parameters:

polarization (int, optional) – Polarisation component.

Return type:

float

get_intensity(polarization=0)[source]

Return the intensity |E|² array.

Parameters:

polarization (int, optional) – Polarization.SIGMA (default), PI, or TOTAL (sigma² + pi² for polarised wavefronts).

Return type:

numpy.ndarray

get_interpolated_amplitude(abscissa_value, polarization=0)[source]

Return the amplitude interpolated at a single coordinate.

get_interpolated_amplitudes(abscissa_values, polarization=0)[source]

Return the amplitude interpolated at multiple coordinates.

get_interpolated_complex_amplitude(abscissa_value, polarization=0)[source]

Return the complex amplitude interpolated at a single coordinate.

Parameters:
  • abscissa_value (float) – Coordinate in metres.

  • polarization (int, optional) – Polarization.SIGMA or PI.

Return type:

complex

get_interpolated_complex_amplitudes(abscissa_values, polarization=0)[source]

Return the complex amplitude interpolated at multiple coordinates.

Parameters:
  • abscissa_values (numpy.ndarray) – Coordinate array in metres.

  • polarization (int, optional) – Polarization.SIGMA or PI.

Return type:

numpy.ndarray of complex

get_interpolated_intensities(abscissa_values, polarization=0)[source]

Return the intensity interpolated at multiple coordinates.

get_interpolated_intensity(abscissa_value, polarization=0)[source]

Return the intensity interpolated at a single coordinate.

get_interpolated_phase(abscissa_value, polarization=0)[source]

Return the phase (rad) interpolated at a single coordinate.

get_interpolated_phases(abscissa_values, polarization=0)[source]

Return the phase (rad) interpolated at multiple coordinates.

get_mesh_x()[source]

Alias for get_abscissas(); return coordinate array in metres.

get_phase(from_minimum_intensity=0.0, unwrap=0, polarization=0)[source]

Return the phase array in radians.

Parameters:
  • from_minimum_intensity (float, optional) – Set phase to zero where intensity / max_intensity < this threshold.

  • unwrap (int, optional) – 0=no unwrap (default), 1=unwrap.

  • polarization (int, optional) – Polarization.SIGMA (default) or Polarization.PI.

Return type:

numpy.ndarray

get_photon_energy()[source]

Return the photon energy in eV.

Return type:

float

get_wavelength()[source]

Return the photon wavelength in metres.

get_wavenumber()[source]

Return the wavenumber k = 2π/λ in rad/m.

guess_wavefront_curvature(rmin=-10000.0, rmax=10000.0, rpoints=100)[source]

Estimate the radius of curvature of the wavefront by optimisation.

Parameters:
  • rmin (float, optional) – Search range in metres.

  • rmax (float, optional) – Search range in metres.

  • rpoints (int, optional) – Initial scan resolution.

Returns:

Estimated radius of curvature in metres.

Return type:

float

classmethod initialize_wavefront(wavelength=1e-10, number_of_points=1000, polarization=0)[source]

Create a unit-amplitude plane wavefront on an unscaled grid.

Parameters:
  • wavelength (float, optional) – Photon wavelength in metres.

  • number_of_points (int, optional) – Number of grid points.

  • polarization (int, optional) – Polarization.SIGMA (default), PI, or TOTAL.

Return type:

GenericWavefront1D

classmethod initialize_wavefront_from_arrays(x_array, y_array, y_array_pi=None, wavelength=1e-10)[source]

Create a wavefront from coordinate and complex-amplitude arrays.

Parameters:
  • x_array (numpy.ndarray) – Uniformly-spaced coordinate array in metres.

  • y_array (numpy.ndarray) – Complex sigma-polarisation amplitude (same size as x_array).

  • y_array_pi (numpy.ndarray, optional) – Complex pi-polarisation amplitude.

  • wavelength (float, optional) – Photon wavelength in metres.

Return type:

GenericWavefront1D

classmethod initialize_wavefront_from_range(x_min=0.0, x_max=0.0, number_of_points=1000, wavelength=1e-10, polarization=0)[source]

Create a unit-amplitude plane wavefront spanning [x_min, x_max].

Parameters:
  • x_min (float) – Grid extent in metres.

  • x_max (float) – Grid extent in metres.

  • number_of_points (int, optional) – Number of grid points.

  • wavelength (float, optional) – Photon wavelength in metres.

  • polarization (int, optional) – Polarization.SIGMA (default), PI, or TOTAL.

Return type:

GenericWavefront1D

classmethod initialize_wavefront_from_steps(x_start=-1.0, x_step=0.002, number_of_points=1000, wavelength=1e-10, polarization=0)[source]

Create a unit-amplitude plane wavefront from a start position and step size.

Parameters:
  • x_start (float, optional) – First grid coordinate in metres.

  • x_step (float, optional) – Grid spacing in metres.

  • number_of_points (int, optional) – Number of grid points.

  • wavelength (float, optional) – Photon wavelength in metres.

  • polarization (int, optional) – Polarization.SIGMA (default), PI, or TOTAL.

Return type:

GenericWavefront1D

is_identical(wfr, decimal=7)[source]

Return True if this wavefront equals wfr to decimal places.

Parameters:
  • wfr (GenericWavefront1D) – Wavefront to compare against.

  • decimal (int, optional) – Number of decimal places for comparison. Default 7.

Return type:

bool

is_polarized()[source]

Return True if this wavefront carries a pi-polarisation component.

classmethod load_h5_file(filename, filepath='wfr')[source]

Load a 1D wavefront from an HDF5 file written by save_h5_file().

Parameters:
  • filename (str) – Path to the HDF5 file.

  • filepath (str, optional) – HDF5 group path. Default "wfr".

Return type:

GenericWavefront1D

offset()[source]

Return the first grid coordinate in metres.

Return type:

float

rescale_amplitude(factor, polarization=0)[source]

Multiply the complex amplitude by a scalar factor.

Parameters:
  • factor (float or complex) – Scaling factor.

  • polarization (int, optional) – Polarization.SIGMA (default), PI, or TOTAL.

rescale_amplitudes(factors, polarization=0)[source]

Multiply the complex amplitude element-wise by a factor array.

Parameters:
  • factors (numpy.ndarray) – Array of scaling factors (must match grid size).

  • polarization (int, optional) – Polarization.SIGMA (default), PI, or TOTAL.

save_h5_file(filename, subgroupname='wfr', intensity=True, phase=False, overwrite=True, verbose=False)[source]

Auxiliary function to write wavefront data into a hdf5 generic file. When using the append mode to write h5 files, overwriting does not work and makes the code crash. To avoid this issue, try/except is used. If by any chance a file should be overwritten, it is firstly deleted and re-written. :param self: input / output resulting Wavefront structure (instance of GenericWavefront2D); :param filename: path to file for saving the wavefront :param subgroupname: container mechanism by which HDF5 files are organised :param intensity: writes intensity for sigma and pi polarisation (default=True) :param amplitude: :param phase: :param overwrite: flag that should always be set to True to avoid infinity loop on the recursive part of the function. :param verbose: if True, print some file i/o messages

scan_wavefront_curvature(rmin=-10000.0, rmax=10000.0, rpoints=100)[source]

Scan the figure-of-merit for wavefront curvature over a range of radii.

Parameters:
  • rmin (float, optional) – Radius range in metres.

  • rmax (float, optional) – Radius range in metres.

  • rpoints (int, optional) – Number of radii to evaluate.

Returns:

  • radii (numpy.ndarray)

  • fig_of_mer (numpy.ndarray)

set_complex_amplitude(complex_amplitude, complex_amplitude_pi=None)[source]

Replace the complex amplitude array(s).

Parameters:
  • complex_amplitude (numpy.ndarray of complex) – New sigma-polarisation amplitude (must match current grid size).

  • complex_amplitude_pi (numpy.ndarray of complex, optional) – New pi-polarisation amplitude for polarised wavefronts.

set_gaussian(sigma_x, amplitude=1.0, shift=0.0)[source]

Set a Gaussian beam (zeroth Gaussian-Hermite mode).

Parameters:
  • sigma_x (float) – RMS beam size in metres.

  • amplitude (float, optional) – Peak amplitude (not intensity). Default 1.

  • shift (float, optional) – Centre shift in metres. Default 0.

set_gaussian_hermite_mode(sigma_x, mode_x, amplitude=1.0, shift=0.0, beta=100.0)[source]

Set a Gaussian-Hermite coherent mode.

Parameters:
  • sigma_x (float) – RMS beam size in metres.

  • mode_x (int) – Mode order.

  • amplitude (float, optional) – Peak amplitude. Default 1.

  • shift (float, optional) – Centre shift in metres. Default 0.

  • beta (float, optional) – Coherence ratio σ_g / σ_s. Default 100.

set_photon_energy(photon_energy)[source]

Set the wavelength via the photon energy in eV.

set_pi_complex_amplitude_to_zero()[source]

Zero out the pi-polarisation component (no-op for unpolarised wavefronts).

set_plane_wave_from_amplitude_and_phase(amplitude=1.0, phase=0.0, inclination=0.0)[source]

Set a uniform plane wave from amplitude and phase.

Parameters:
  • amplitude (float, optional) – Real amplitude. Default 1.

  • phase (float, optional) – Phase in radians. Default 0.

  • inclination (float, optional) – Tilt angle in radians. Default 0.

set_plane_wave_from_complex_amplitude(complex_amplitude=1 + 0j, inclination=0.0)[source]

Set a uniform plane wave from a complex amplitude.

Parameters:
  • complex_amplitude (complex, optional) – Amplitude value. Default 1+0j.

  • inclination (float, optional) – Tilt angle in radians. Default 0.

set_spherical_wave(radius=1.0, center=0.0, complex_amplitude=1.0)[source]

Set a spherical (quadratic-phase) wave.

Parameters:
  • radius (float, optional) – Radius of curvature in metres (positive=diverging, negative=converging).

  • center (float, optional) – Centre position in metres.

  • complex_amplitude (complex, optional) – Overall complex amplitude. Default 1.

set_wavelength(wavelength)[source]

Set the photon wavelength in metres.

set_wavenumber(wavenumber)[source]

Set the wavelength via the wavenumber k = 2π/λ (rad/m).

size()[source]

Return the number of grid points.

Return type:

int

Module contents