LTEM image simulation

Simulation module

class PyLorentz.sim.sim.SimLTEM(mags: numpy.ndarray, scale: float, zscale: float, verbose: float | bool = 1, ovf_file: PathLike | None = None)[source]

Bases: MansuripurPhase, LinsupPhase, BaseSim

A class used to simulate Lorentz Transmission Electron Microscopy (LTEM) images.

__init__(mags: numpy.ndarray, scale: float, zscale: float, verbose: float | bool = 1, ovf_file: PathLike | None = None)[source]

Initialize the SimLTEM object.

Parameters:
  • mags (np.ndarray) – Magnetization array.

  • scale (float) – Scale factor for the simulation.

  • zscale (float) – Z-axis scale factor.

  • verbose (float | bool, optional) – Verbosity level. Default is 1.

  • ovf_file (os.PathLike | None, optional) – Path to OVF file. Default is None.

classmethod load_ovf(file: str | PathLike, verbose: int = 1) SimLTEM[source]

Load an OVF file and initialize a SimLTEM object.

Parameters:
  • file (str | os.PathLike) – Path to the OVF file.

  • verbose (int, optional) – Verbosity level. Default is 1.

Returns:

An instance of the SimLTEM class.

Return type:

SimLTEM

compute_phase(method: str | None = 'mansuripur', tilt_x: float | None = None, tilt_y: float | None = None, beam_energy: float | None = None, device: str = 'cpu', multiproc: bool = True, **kwargs) None[source]

Compute the phase shift for the simulation.

Parameters:
  • method (str | None, optional) – Phase computation method. Options are ‘mansuripur’ or ‘linsup’. Default is ‘mansuripur’.

  • tilt_x (float | None, optional) – Tilt angle in the x direction. Default is None.

  • tilt_y (float | None, optional) – Tilt angle in the y direction. Default is None.

  • beam_energy (float | None, optional) – Beam energy. Default is None.

  • device (str, optional) – Device to use for computation. Default is ‘cpu’.

  • multiproc (bool, optional) – Whether to use multiprocessing. Default is True.

  • **kwargs – Additional arguments for phase computation.

sim_images(defocus_values: float | List[float], scope: Microscope, flip: bool = False, filter_sigma: float = 1, amorphous_bkg: bool | float | None = None, padded_shape: tuple | None = None) DefocusedDataset[source]

Simulate images at different defocus values.

Parameters:
  • defocus_values (float | list) – Single defocus value or list of defocus values.

  • scope (Microscope) – Microscope object.

  • flip (bool, optional) – Whether to flip the phase. Default is False.

  • filter_sigma (float, optional) – Sigma value for Gaussian filter. Default is 1.

  • amorphous_bkg (bool | float | None, optional) – Amorphous background level. Default is None.

  • padded_shape (tuple | None, optional) – Shape for padding. Default is None.

Returns:

A dataset containing simulated defocused images.

Return type:

DefocusedDataset

sim_TFS(defocus_values: float | List[float], scope: Microscope, flip: bool = False, filter_sigma: float = 1, amorphous_bkg: bool | float | None = None, padded_shape: tuple | None = None) ThroughFocalSeries[source]

Simulate a Through Focal Series (TFS).

for single or set of defocus values, record a through focal series with/without flip one defocus val, flip=False -> [+-, +0, ++] one defocus val, flip=True, -> [[+-, +0, ++], [–, -0, -+]] multiple defocus vals, everything goes into a DefocusedDataset object

Parameters:
  • defocus_values (float | list) – Single defocus value or list of defocus values.

  • scope (Microscope) – Microscope object.

  • flip (bool, optional) – Whether to flip the phase. Default is False.

  • filter_sigma (float, optional) – Sigma value for Gaussian filter. Default is 1.

  • amorphous_bkg (bool | float | None, optional) – Amorphous background level. Default is None.

  • padded_shape (tuple | None, optional) – Shape for padding. Default is None.

Returns:

A series of simulated images at different focal depths.

Return type:

ThroughFocalSeries

copy()[source]

Returns a deep copy of itself.

Phase calculation

class PyLorentz.sim.comp_phase.LinsupPhase(mags: numpy.ndarray, scale: float, zscale: float, verbose: float | bool = 1)[source]

Bases: BaseSim

A class for calculating phase shifts using the linear superposition method.

class PyLorentz.sim.comp_phase.MansuripurPhase(mags: numpy.ndarray, scale: float, zscale: float, verbose: float | bool = 1)[source]

Bases: BaseSim

A class for calculating phase shifts using the Mansuripur method.

Base Sim module

class PyLorentz.sim.base_sim.BaseSim(mags: numpy.ndarray, scale: float, zscale: float, verbose: float | bool = 1)[source]

Bases: object

A base class for simulations, providing common attributes and methods.

__init__(mags: numpy.ndarray, scale: float, zscale: float, verbose: float | bool = 1)[source]

Initialize the BaseSim object.

Parameters:
  • mags (np.ndarray) – Magnetization array.

  • scale (float) – Scale factor for the simulation.

  • zscale (float) – Z-axis scale factor.

  • verbose (float | bool, optional) – Verbosity level. Default is 1.

vprint(*args, **kwargs) None[source]

Print messages if verbose is enabled.

property phase_B: numpy.ndarray

Get the B-phase.

property phase_E: numpy.ndarray

Get the E-phase.

property phase_t: numpy.ndarray

Get the total phase (B-phase + E-phase).

property phase_shape: Tuple[int, ...]

Get the shape of the B-phase array.

set_sample_params(params: dict) None[source]

Set sample parameters.

property sample_params: dict

Get the sample parameters.

property phase_method: str

Get the phase method.

property B0: float

Get the B0 parameter.

property sample_V0: float

Get the sample mean inner potential.

property sample_xip0: float

Get the sample extinction distance.

property mem_V0: float

Get the membrane mean inner potential.

property mem_xip0: float

Get the membrane extinction distance.

property mem_thickness: float

Get the membrane thickness.

property tilt_x: float

Get the tilt angle in the x direction.

property tilt_y: float

Get the tilt angle in the y direction.

property beam_energy: float

Get the beam energy.

property zscale: float

Get the z-axis scale factor.

property scale: float

Get the scale factor.

property Mz: numpy.ndarray

Get the z-component of the magnetization.

property My: numpy.ndarray

Get the y-component of the magnetization.

property Mx: numpy.ndarray

Get the x-component of the magnetization.

property shape: Tuple[int, ...]

Get the shape of the magnetization array.

property mags: numpy.ndarray

Get the magnetization array.

property shape_func: numpy.ndarray

Get the shape function.

property flat_shape_func: numpy.ndarray

Get the flattened shape function.

get_flat_shape_func(sigma: float = 0) None[source]

Get the flattened shape function.

Parameters:

sigma (float, optional) – Sigma value for Gaussian filter. Default is 0.

get_shape_func(mags: numpy.ndarray | None = None) None[source]

Return 3D shape function of the magnetization.

Parameters:

mags (np.ndarray | None, optional) – Magnetization array. Default is None.

show_mags(xy_only: bool = False, s3D: bool = False, show_scale: bool = False, **kwargs) None[source]

Visualize the magnetization.

Parameters:
  • xy_only (bool, optional) – Whether to show only the XY components. Default is False.

  • s3D (bool, optional) – Whether to show in 3D. Default is False.

  • show_scale (bool, optional) – Whether to show the scale. Default is False.

  • **kwargs – Additional arguments for visualization.

show_thickness_map(**kwargs) None[source]

Visualize the thickness map.

Parameters:

**kwargs – Additional arguments for visualization.

visualize(show_thickness_map: bool = True, xy_only: bool = False) None[source]

Visualize the magnetization and thickness map.

Parameters:
  • show_thickness_map (bool, optional) – Whether to show the thickness map. Default is True.

  • xy_only (bool, optional) – Whether to show only the XY components. Default is False.

show_phase() None[source]

Visualize the B-phase and E-phase.

show_phase_B(**kwargs) None[source]

Visualize the B-phase.

Parameters:

**kwargs – Additional arguments for visualization.

show_phase_E(**kwargs) None[source]

Visualize the E-phase.

Parameters:

**kwargs – Additional arguments for visualization.