ncempy.viz package¶
A set of visualization functions based on matplotlib.pyplot which are generally useful for S/TEM data visualization.
-
ncempy.viz.
im_and_fft
(im, d=1.0, fft=None)[source]¶ Show the image and its fft side by side. Uses imfft to show the fft.
Parameters: - im (np.ndarray) – The image to show in both real and FFT space
- d (float) – The pixel spacing
- fft (np.ndarray, optional) – The FFT to display. If not provided then np.fft.fft2 is used.
Returns: The matplotlib.pyplot figure
Return type: plt.figure
-
ncempy.viz.
im_calibrated
(im, d)[source]¶ Plot an image calibrated using the pixel size d. The centers of the pixels will be the the center of each measurement. So, if you plot positions in real coordinates the points will be plotted in the center of the pixel.
Parameters: - im (np.ndarray) – The image to show using imshow
- d (float) – The pixel size in both directions. The pixel size must be isotropic.
Returns: The figure containing the plot
Return type: pyplot.figure
-
ncempy.viz.
imfft
(im, d=1.0, ax=None)[source]¶ Show a 2D FFT as a diffractogram with log scaling applied and zero frequency fftshifted tp the center. A new figure is created or an axis can be specified.
The diffracotgram is calculated from the original intensities (I) as
\[1 + 0.001 * I ^2\]Parameters: - im (np.ndarray) – The 2D fft of the diffraction pattern to display as a diffractogram
- d (float, optional, default = 1.0) – The real space pixel size of the image used to get the FFT
- ax (pyplot axis, optional) – An axis to plot into.
Returns: The AxesImage that contains the image displayed.
Return type: matplotlib.image.AxesImage
Example
This example shows how to display a 2D ndarray (image) as a diffractogram. The image has a real space pixel size of 0.1 nanometer.
>> imageFFT = np.fft.fft2(im) >> ncempy.viz.imfft(imageFFT, d = 0.1)
-
ncempy.viz.
imrfft
(im, d=1.0, ax=None)[source]¶ Show a 2D rFFT (real FFT) as a diffractogram with log scaling applied and fftshift-ed along axis 0. See imfft for full details.
Parameters: - im (ndarray) – The 2D fft of the diffraction pattern to display as a diffractogram
- d (float, optional, default = 1.0) – The real space pixel size of the image used to get the FFT
- ax (pyplot axis, optional) – An axis to plot into.
Returns: The AxesImage that contains the image displayed.
Return type: matplotlib.image.AxesImage
-
ncempy.viz.
imsd
(im, vmin=-2, vmax=2, **kwargs)[source]¶ Show an array as an image with intensities compared to the standard deviation of the data. Other keyword args are passed to pyplot.imshow(). vmin and vmax are by default set to -2 and 2 respectively which are usually good values to set for S/TEM data.
Parameters: - im (np.ndarray) – The image to show.
- vmax (vmin,) – The vmin and vmax values to pass to imshow.
Returns: The handle to the created figure
Return type: matplotlib.pyplot.Figure
-
ncempy.viz.
plot_distpolar
(points, dims, dists, ns, show=False)[source]¶ Plot the results of distortion fitting in polar coordinates.
Parameters: - points (np.ndarray) – Points in polar coords.
- dims (tuple) – Dimensions, necessary to have unit information.
- dists (np.ndarray) – Results of dist fitting, length according to ns.
- ns (list) – List of used orders.
- show (bool) – Set to directly show the plot in interactive mode.
Returns: Image of the plot.
Return type: np.ndarray
-
ncempy.viz.
plot_fit
(r, intens, dims, funcs, param, show=False)[source]¶ Plot the fit results to the radial profile.
Parameters: - r (np.ndarray) – r-axis of radial profile.
- intens (np.ndarray) – Intensity-axis of radial profile.
- dims (tuple) – Dimensions of original image to read out units.
- funcs (tuple) – List of functions.
- param (np.ndarray) – Parameters for functions in funcs.
- show (bool) – Set to directly show plot interactively.
Returns: Image of the plot.
Return type: np.ndarray
-
ncempy.viz.
plot_points
(img, points, vminmax=(0, 1), dims=None, invert=False, show=False)[source]¶ Plot the detected points on the input image for checking.
Parameters: - img (np.ndarray) – Image.
- points (np.ndarray) – Array containing the points.
- vminmax (tuple) – Tuple of two values for relative lower and upper cut off to display image.
- dims (tuple) – Tuple of dims to plot in dimensions.
- invert (bool) – Set to invert the image.
- show (bool) – Set to directly show the plot interactively.
Returns: Image of the plot.
Return type: np.ndarray
-
ncempy.viz.
plot_radialprofile
(r, intens, dims, show=False)[source]¶ Plot radial profile.
Parameters: - r (np.ndarray) – r-axis of radial profile.
- intens (np.ndarray) – Intensity-axis of radial profile.
- dims (tuple) – Dimensions of original image to read out units.
- show (bool) – Set to directly show plot interactively.
Returns: Image of the plot.
Return type: np.ndarray
-
ncempy.viz.
plot_ringpolar
(points, dims, show=False)[source]¶ Plot points in polar coordinate system.
Parameters: - points (np.ndarray) – Positions in polar coords.
- dims (tuple) – Dimension information to plot labels.
- show (bool) – Set to directly show plot in interactive mode.
Returns: Image of the plot.
Return type: numpy.ndarray
-
class
ncempy.viz.
stack_view
(stack, **kwargs)[source]¶ Bases:
object
Class to allow a volume to be scrubbed through with a matplotlib slider widget. The first axis of the volume is the slicing axis. Other keyword args are passed directly to imshow upon the figure creation.
Parameters: - stack (numpy.ndarray, 3D stack) – The stack of to show as images
- **kwargs – Passed directly to pyplot.imshow()