TIE_reconstruct module¶
Module containing TIE and SITIE reconstruction routines.
Routines for solving the transport of intensity equation; for use with Lorentz TEM through focal series (tfs) to reconstruct B field magnetization of the sample.
Known Bugs:
- Longitudinal derivative gives a magnetization scaling error for some experimental datasets.
Author: Arthur McCray, ANL, Summer 2019.
-
TIE_reconstruct.SITIE(image=None, defval=None, scale=1, E=200000.0, ptie=None, i=-1, flipstack=False, pscope=None, data_loc='', dataname='', sym=False, qc=None, save=False, v=1)[source]¶ Uses a modified derivative to get the magnetic phase shift with TIE from a single image.
This technique is only applicable to uniformly thin samples from which the only source of contrast is magnetic Fresnel contrast. All other sources of contrast including sample contamination, thickness variation, and diffraction contrast will give false magnetic inductions. For more information please refer to: Chess, J. J. et al. Ultramicroscopy 177, 78–83 (2018).
This function has two ways of picking which image to use. First, if an image is given directly along with a defocus value, it will use that. You should also be sure to specify the scale of the image and accelerating voltage of the microscope (default 200kV).
You can also choose to pass it an image from a
TIE_paramsobject, in which case you need specify only whether to choose from the imstack or flipstack and the index of the image to use. It’s possible that in the future this method of selecting an image will be removed or moved to a separate function.Parameters: - image (2D array) – Input image to reconstruct.
- defval (float) – Defocus value corresponding to
image. - scale (float) – Scale (nm/pixel) corresponding to
image. - E (float) – Accelerating voltage of microscope that produced
image. - ptie (
TIE_paramsobject) – Object containing the image. From TIE_params.py - i (int) – Index of the ptie.imstack or ptie.flipstack to reconstruct. This is not the defocus index like in TIE. Default value is -1 which corresponds to the most overfocused image.
- flipstack (bool) – (optional) Whether to pull the image from ptie.imstack[i] or ptie.flipstack[i]. Default is False, calls image from imstack.
- pscope (
Microscopeobject) – Should have same accelerating voltage as the microscope that took the images. - dataname (str) – The output filename to be used for saving the images.
- sym (bool) – (optional) Fourier edge effects are marginally improved by symmetrizing the images before reconstructing. Default False.
- qc (float/str) – (optional) The Tikhonov frequency to use as filter. Default None. If you use a Tikhonov filter the resulting phase shift and induction is no longer quantitative.
- save (bool/str) –
Whether you want to save the output.
input value saved images True All images ’b’ bx, by, and color image ’color’ Color image False None Files will be saved as ptie.data_loc/images/dataname_<defval>_<key>.tiff, where <key> is the key for the returned dictionary that corresponds to the image.
- v (int) –
(optional) Verbosity.
v print output 0 No output 1 Default output 2 Extended output for debugging.
Returns: A dictionary of image arrays
key value ’byt’ y-component of integrated magnetic induction ’bxt’ x-component of integrated magnetic induction ’bbt’ Magnitude of integrated magnetic induction ’phase_m’ Magnetic phase shift (radians) ’color_b’ RGB image of magnetization Return type: dict
-
TIE_reconstruct.TIE(i=-1, ptie=None, pscope=None, dataname='', sym=False, qc=None, save=False, hsv=True, long_deriv=False, v=1)[source]¶ Sets up the TIE reconstruction and calls phase_reconstruct.
This function calculates the necessary arrays, derivatives, etc. and then passes them to phase_reconstruct which solve the TIE.
Parameters: - i (int) – Index of ptie.defvals to use for reconstruction. Default value is -1 which corresponds to the most defocused images for a central difference method derivative. i is ignored if using a longitudinal derivative.
- ptie (
TIE_paramsobject) – Object containing the images and other data parameters. From TIE_params.py - pscope (
Microscopeobject) – Should have same accelerating voltage as the microscope that took the images. - dataname (str) – The output filename to be used for saving the images.
- sym (bool) – (optional) Fourier edge effects are marginally improved by symmetrizing the images before reconstructing. Default False.
- qc (float/str) – (optional) The Tikhonov frequency to use as filter. Default None. If you use a Tikhonov filter the resulting phase shift and induction is no longer quantitative.
- save (bool/str) –
Whether you want to save the output.
input value saved images True All images ’b’ bx, by, and color image ’color’ Color image False None Files will be saved as ptie.data_loc/images/dataname_<defval>_<key>.tiff, where <key> is the key for the results dictionary that corresponds to the image.
- hsv (bool) – Whether to use the hsv colorwheel (True) or the 4-fold colorwheel (False).
- long_deriv (bool) – Whether to use the longitudinal derivative (True) or central difference method (False). Default False.
- v (int) –
(optional) Verbosity.
v print output 0 No output 1 Default output 2 Extended output for debugging.
Returns: A dictionary of image arrays
key value ’byt’ y-component of integrated magnetic induction ’bxt’ x-component of integrated magnetic induction ’bbt’ Magnitude of integrated magnetic induction ’phase_m’ Magnetic phase shift (radians) ’phase_e’ Electrostatic phase shift (if using flip stack) (radians) ’dIdZ_m’ Intensity derivative for calculating phase_m ’dIdZ_e’ Intensity derivative for calculating phase_e (if using flip stack) ’color_b’ RGB image of magnetization ’inf_im’ In-focus image Return type: dict
-
TIE_reconstruct.phase_reconstruct(ptie, infocus, dIdZ, pscope, defval, sym=False, long_deriv=False)[source]¶ The function that actually solves the TIE.
This function takes all the necessary inputs from TIE or SITIE and solves the TIE using the inverse Laplacian method.
Parameters: - ptie (
TIE_paramsobject) – Reconstruction parameters. - infocus (2D array) – The infocus image. Should not have any zeros as we divide by it.
- dIdZ (2D array) – The intensity derivative array.
- pscope (
Microscopeobject) – Should have same accelerating voltage as the microscope that took the images. - defval (float) – The defocus value for the reconstruction. Not used if long_deriv == True.
- sym (bool) – Fourier edge effects are marginally improved by symmetrizing the images before reconstructing. Default False.
- long_deriv (bool) – Whether or not the longitudinal derivative was used. Only affects the prefactor.
Returns: A dictionary of image arrays
key value ’ind_y’ y-component of integrated induction ’ind_x’ x-component of integrated induction ’phase’ Phase shift (radians) Return type: dict
- ptie (
-
TIE_reconstruct.save_results(defval, results, ptie, dataname, sym, qc, save, v, directory=None, long_deriv=False, filenames=None)[source]¶ Save the contents of results dictionary as 32 bit tiffs.
This function saves the contents of the supplied dictionary (either all or a portion) to ptie.data_loc with the appropriate tags from results. It also creates a recon_params.txt file containing the reconstruction parameters.
The images are formatted as 32 bit tiffs with the resolution included so they can be opened as-is by ImageJ with the scale set.
Parameters: - defval (float) – The defocus value for the reconstruction. Not used if long_deriv == True.
- results (dict) – Dictionary containing the 2D numpy arrays.
- ptie (
TIE_paramsobject) – Reconstruction parameters. - dataname (str) – Name attached to the saved images.
- sym (bool) – If the symmetrized method was used. Only relevant as its included in the recon_params.txt file.
- qc (float) – Same as sym, included in the text file.
- save (bool/str) –
How much of the results dictionary to save.
input value saved images True All images ’b’ bx, by, and color image ’color’ Color image Files will be saved as ptie.data_loc/images/dataname_<defval>_<key>.tiff, where <key> is the key for the results dictionary that corresponds to the image.
- v (int) –
(optional) Verbosity.
v print output 0 No output 1 Default output 2 Extended output, prints filenames as saving. - directory (str) – An override directory name to store the saved files. If None (default), saves to ptie.data_loc/Images/
- long_deriv (bool) – Same as qc. Included in text file.
- filenames (list[str]) – The list of filenames to save. Defaults to None, this is for manual file saving.
Returns: None