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, units=None, **kwargs)[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 (2-tuple) – The pixel size in both directions as a 2-tuple.
unit (2-tuple) – The name of the unit as a string for each pixel along each dimension. (nm or nanometer)
- Returns:
The figure containing the plot
- Return type:
pyplot.figure
- ncempy.viz.imfft(im, d=1.0, ax=None, **kwargs)[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 Figure that contains the image displayed.
- Return type:
matplotlib.image.Figure
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, **kwargs)[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.Figure
- 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.
- ncempy.viz.plot(dd)[source]¶
Easy plot of data structure returned by ncempy.read(). This only works for 2D images currently. Calls im_calibrated with proper inputs.
- Parameters:
dd (dict) – The dictionary returned by ncempy.read()
- Returns:
The handle to the created Figure
- Return type:
matplotlb.pyplot.Figure
- ncempy.viz.plot_distpolar(points, dims, dists, ns, show=False)[source]¶
Plot the results of distortion fitting in polar coordinates.
- Parameters:
- 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_ringpolar(points, dims, show=False)[source]¶
Plot points in polar coordinate system.
- Parameters:
- Returns:
Image of the plot.
- Return type:
- class ncempy.viz.stack_view(stack, **kwargs)[source]¶
Bases:
objectClass 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()