TIE_helper module¶
Helper functions for TIE.
An assortment of helper functions that load images, pass data, and generally are used in the reconstruction. Additionally, a couple of functions used for displaying images and stacks.
Author: Arthur McCray, ANL, Summer 2019.
-
TIE_helper.dist(ny, nx, shift=False)[source]¶ Creates a frequency array for Fourier processing.
Parameters: - ny (int) – Height of array
- nx (int) – Width of array
- shift (bool) –
Whether to center the frequency spectrum.
- False: (default) smallest values are at the corners.
- True: smallest values at center of array.
Returns: Numpy array of shape (ny, nx).
Return type: ndarray
-
TIE_helper.load_data(path=None, fls_file='', al_file='', flip=None, flip_fls_file=None, filtersize=3)[source]¶ Load files in a directory (from a .fls file) using hyperspy.
For more information on how to organize the directory and load the data, as well as how to setup the .fls file please refer to the README or the TIE_template.ipynb notebook.
Parameters: - path (str) – Location of data directory.
- fls_file (str) – Name of the .fls file which contains the image names and defocus values.
- al_file (str) – Name of the aligned stack image file.
- flip (Bool) – True if using a flip stack, False otherwise. Uniformly thick films can be reconstructed without a flip stack. The electrostatic phase shift will not be reconstructed.
- flip_fls_file (str) – Name of the .fls file for the flip images if they are not named the same as the unflip files. Will only be applied to the /flip/ directory.
- filtersize (int) – (optional) The images are processed with a median filter to remove hot pixels which occur in experimental data. This should be set to 0 for simulated data, though generally one would only use this function for experimental data.
Returns: List of length 3, containing the following items:
- imstack: array of hyperspy signal2D objects (one per image)
- flipstack: array of hyperspy signal2D objects, empty array if flip == False
- ptie: TIE_params object holding a reference to the imstack and many other parameters.
Return type: list
-
TIE_helper.load_data_GUI(path, fls_file1, fls_file2, al_file='', single=False, filtersize=3)[source]¶ Load files in a directory (from a .fls file) using hyperspy.
For more information on how to organize the directory and load the data, as well as how to setup the .fls file please refer to the README or the TIE_template.ipynb notebook.
Parameters: - path (str) – Location of data directory.
- fls_file1 (str) – Name of the .fls file which contains the image names and defocus values.
- fls_file2 (str) – Name of the .fls file for the flip images if they are not named the same as the unflip files. Will only be applied to the /flip/ directory.
- al_file (str) – Name of the aligned stack image file.
- single (Bool) – True if using a single stack, False otherwise. Uniformly thick films can be reconstructed with a single stack. The electrostatic phase shift will not be reconstructed.
- filtersize (int) – (optional) The images are processed with a median filter to remove hot pixels which occur in experimental data. This should be set to 0 for simulated data, though generally one would only use this function for experimental data.
Returns: List of length 3, containing the following items:
- imstack: array of hyperspy signal2D objects (one per image)
- flipstack: array of hyperspy signal2D objects, empty array if flip == False
- ptie: TIE_params object holding a reference to the imstack and many other parameters.
Return type: list
-
TIE_helper.scale_stack(imstack)[source]¶ Scale a stack of images so all have the same total intensity.
Parameters: imstack (list) – List of 2D arrays. Returns: List of same shape as imstack Return type: list
-
TIE_helper.select_tifs(i, ptie, long_deriv=False)[source]¶ Returns a list of the images which will be used in TIE() or SITIE().
Uses copy.deepcopy() as the data will be modified in the reconstruction process, and we don’t want to change the original data. This method is likely not best practice. In the future this might get moved to the TIE_params class.
Parameters: - i (int) – Index of defvals for which to select the tifs.
- ptie (
TIE_paramsobject) – Parameters for reconstruction, holds the images.
Returns: List of np arrays, return depends on parameters:
if long_deriv == False:
- if ptie.flip == True: returns [ +- , – , 0 , ++ , -+ ]
- elif ptie.flip == False: returns [+-, 0, ++]
- where first +/- is unflip/flip, second +/- is over/underfocus. E.g. -+ is the flipped overfocused image. 0 is the averaged infocus image.
elif long_deriv == True: returns all images in imstack followed by all images in flipstack.
Return type: list
-
TIE_helper.show_2D(mag_x, mag_y, mag_z=None, a=15, l=None, w=None, title=None, color=False, hsv=True, origin='upper', save=None, GUI_handle=False, GUI_color_array=None)[source]¶ Display a 2D vector arrow plot.
Displays an an arrow plot of a vector field, with arrow length scaling with vector magnitude. If color=True, a colormap will be displayed under the arrow plot.
If mag_z is included and color=True, a spherical colormap will be used with color corresponding to in-plane and white/black to out-of-plane vector orientation.
Parameters: - mag_x (2D array) – x-component of magnetization.
- mag_y (2D array) – y-component of magnetization.
- mag_z (2D array) – optional z-component of magnetization.
- a (int) – Number of arrows to plot along the x and y axes. Default 15.
- l (float) – Scale factor of arrows. Larger l -> shorter arrows. Default None guesses at a good value. None uses matplotlib default.
- w (float) – Width scaling of arrows. None uses matplotlib default.
- title (str) – (optional) Title for plot. Default None.
- color (bool) – (optional) Whether or not to show a colormap underneath the arrow plot. Color image is made from colorwheel.color_im().
- hsv (bool) – (optional) Only relevant if color == True. Whether to use an hsv or 4-fold color-wheel in the color image.
- origin (str) – (optional) Control image orientation.
- save (str) – (optional) Path to save the figure.
- GUI_handle (bool) – (‘optional’) Handle for indicating if using GUI. Default is False.
- GUI_color_array (2D array) – (‘optional’) The colored image array passed from the GUI, it is for creating the overlaying the arrows without using color_im().
Returns: Returns the figure handle.
Return type: fig
-
TIE_helper.show_im(image, title=None, simple=False, origin='upper', cbar=True, cbar_title='', scale=None, **kwargs)[source]¶ Display an image on a new axis.
Takes a 2D array and displays the image in grayscale with optional title on a new axis. In general it’s nice to have things on their own axes, but if too many are open it’s a good idea to close with plt.close(‘all’).
Parameters: - image (2D array) – Image to be displayed.
- title (str) – (optional) Title of plot.
- simple (bool) –
(optional) Default output or additional labels.
- True, will just show image.
- False, (default) will show a colorbar with axes labels, and will adjust the contrast range for images with a very small range of values (<1e-12).
- origin (str) –
(optional) Control image orientation.
- ’upper’: (default) (0,0) in upper left corner, y-axis goes down.
- ’lower’: (0,0) in lower left corner, y-axis goes up.
- cbar (bool) – (optional) Choose to display the colorbar or not. Only matters when simple = False.
- cbar_title (str) – (optional) Title attached to the colorbar (indicating the units or significance of the values).
- scale (float) – Scale of image in nm/pixel. Axis markers will be given in units of nanometers.
Returns: None
-
TIE_helper.show_stack(images, ptie=None, origin='upper', title=False)[source]¶ Shows a stack of dm3s or np images with a slider to navigate slice axis.
Uses ipywidgets.interact to allow user to view multiple images on the same axis using a slider. There is likely a better way to do this, but this was the first one I found that works…
If a TIE_params object is given, only the regions corresponding to ptie.crop will be shown.
Parameters: - images (list) – List of 2D arrays. Stack of images to be shown.
- ptie (
TIE_paramsobject) – Will use ptie.crop to show only the region that will remain after being cropped. - origin (str) – (optional) Control image orientation.
- title (bool) – (optional) Try and pull a title from the signal objects.
Returns: None