bcdi.graph
: Templates for plotting and saving data¶
colormap¶
This module provides the class ColormapFactory.
API Reference¶
Implementation of the colormap class.
New colormaps can be added to the method generate_colormap.
- class bcdi.graph.colormap.ColormapFactory(bad_color: str = '0.7', colormap: str = 'turbo')¶
Class to define a colormap.
- Parameters:
colormap – a colormap string. Available choices: ‘turbo’, ‘custom’
bad_color – a string which defines the grey level for nan pixels, e.g. ‘0.7’
- property bad_color¶
Color for masked values.
- generate_cmap() None ¶
Build and return the colormap.
graph_utils¶
This module provides methods to plot 2D and 3D data using templates, and to save it as a .vti file.
API Reference¶
Functions related to visualization.
- bcdi.graph.graph_utils.close_event(event)¶
Handle closing events on plots.
- bcdi.graph.graph_utils.colorbar(mappable, scale='linear', numticks=10, label=None, pad=0.05)¶
Generate a colorbar whose height (or width) in sync with the master axes.
- Parameters:
mappable – the image where to put the colorbar
scale – ‘linear’ or ‘log’, used for tick location
numticks – number of ticks for the colorbar
label – label for the colorbar
pad – float (default 0.05). Fraction of original axes between colorbar and new image axes.
- Returns:
the colorbar instance
- bcdi.graph.graph_utils.combined_plots(tuple_array, tuple_sum_frames, tuple_colorbar, tuple_title, tuple_scale, tuple_sum_axis=None, cmap=matplotlib.colors.ListedColormap, tick_direction='out', tick_width=1, tick_length=4, pixel_spacing=None, tuple_width_v=None, tuple_width_h=None, tuple_vmin=numpy.nan, tuple_vmax=numpy.nan, is_orthogonal=False, reciprocal_space=False, **kwargs)¶
Subplots of a 1D, 2D or 3D datasets using user-defined parameters.
- Parameters:
tuple_array – tuple of 1D, 2D or 3D arrays of real numbers
tuple_sum_frames – boolean or tuple of boolean values. If True, will sum the data along sum_axis
tuple_sum_axis – tuple of axis along which to sum or to take the middle slice
tuple_width_v – int or tuple of user-defined zoom vertical width, should be smaller than the actual data size. Set it to None if you do not need it.
tuple_width_h – int or tuple of user-defined zoom horizontal width, should be smaller than the actual data size. Set it to None if you do not need it.
tuple_colorbar – boolean or tuple of boolean values. Set it to True in order to plot the colorbar
tuple_vmin – float or tuple of lower boundaries for the colorbar, set to np.nan if you do not need it
tuple_vmax – float or tuple of higher boundaries for the colorbar, set to np.nan if you do not need it
tuple_title – string or tuple of strings, set to ‘’ if you do not need it
tuple_scale – string ot tuple of strings with value ‘linear’ or ‘log’
cmap – colormap to be used
tick_direction – ‘out’, ‘in’, ‘inout’
tick_width – width of tickes in plots
tick_length – length of tickes in plots
pixel_spacing – pixel_spacing = desired tick_spacing (in nm) / voxel_size of the reconstruction(in nm). It can be a positive number or a tuple of array.ndim positive numbers
is_orthogonal – set to True is the frame is orthogonal, False otherwise (detector frame) Used for plot labels.
reciprocal_space – True if the data is in reciprocal space, False otherwise. Used for plot labels.
kwargs –
‘xlabel’ , label of the horizontal axis for plots: string or tuple of strings
’ylabel’ , label of the vertical axis for plots: string or tuple of strings
’position’ , tuple of subplot positions in the format 231 (2 rows, 3 columns, first subplot)
’invert_y’: boolean, True to invert the vertical axis of the plot. Will overwrite the default behavior.
- Returns:
the figure instance
- bcdi.graph.graph_utils.contour_slices(array, q_coordinates, sum_frames=False, slice_position=None, levels=150, width_z=None, width_y=None, width_x=None, plot_colorbar=False, cmap=matplotlib.colors.ListedColormap, title='', scale='linear', is_orthogonal=False, reciprocal_space=True)¶
Create a figure with three 2D contour plots from a 3D dataset.
- Parameters:
array – 3D array of real numbers
q_coordinates – a tuple of (qx, qz, qy) 1D-coordinates corresponding to the (Z, Y, X) of the cxi convention
sum_frames – if True, will sum the data along the 3rd axis
slice_position – tuple of three integers where to slice the 3D array
levels – int n, will use n data intervals and draw n+1 contour lines
width_z – user-defined zoom width along axis 0 (rocking angle), should be smaller than the actual data size
width_y – user-defined zoom width along axis 1 (vertical), should be smaller than the actual data size
width_x – user-defined zoom width along axis 2 (horizontal), should be smaller than the actual data size
plot_colorbar – set it to True in order to plot the colorbar
cmap – colormap to be used
title – string to include in the plot
scale – ‘linear’ or ‘log’
is_orthogonal – set to True is the frame is orthogonal, False otherwise (detector frame) Used for plot labels.
reciprocal_space – True if the data is in reciprocal space, False otherwise. Used for plot labels.
- Returns:
fig, (ax0, ax1, ax2, ax3), (plt0, plt1, plt2) instances
- bcdi.graph.graph_utils.contour_stereographic(euclidian_u, euclidian_v, color, radius_mean, planes=None, title='', plot_planes=True, contour_range=None, max_angle=95, cmap=matplotlib.colors.ListedColormap, uv_labels=('', ''), hide_axis=False, scale='linear', debugging=False)¶
Plot the stereographic projection with some cosmetics.
- Parameters:
euclidian_u – flattened array, normalized Euclidian metric coordinates (points can be not on a regular grid)
euclidian_v – flattened array, normalized Euclidian metric coordinates (points can be not on a regular grid)
color – flattened array, intensity of density kernel estimation at radius_mean
radius_mean – radius of the sphere in reciprocal space from which the projection is done
planes – dictionnary of crystallographic planes, e.g. {‘111’:angle_with_reflection}
title – title for the stereographic plot
plot_planes – if True, will draw circle corresponding to crystallographic planes in the pole figure
contour_range – range for the plot contours
max_angle – maximum angle in degrees of the stereographic projection (should be larger than 90)
cmap – colormap to be used
uv_labels – tuple of strings, labels for the u axis and the v axis, respectively
hide_axis – hide the axis frame, ticks and ticks labels
scale – ‘linear’ or ‘log’, scale for the colorbar of the plot
debugging – True to see the scatter plot of euclidian coordinates
- Returns:
figure and axe instances
- bcdi.graph.graph_utils.define_labels(reciprocal_space, is_orthogonal, sum_frames, labels=None)¶
Define default labels for plots.
- Parameters:
reciprocal_space – True if the data is in reciprocal space, False otherwise
is_orthogonal – True is the frame is orthogonal, False otherwise (detector frame)
sum_frames – True if the the data is summed along some axis
labels – tuple of two strings (vertical label, horizontal label)
- Returns:
three tuples of three elements: slice_names, vertical labels, horizontal labels. The first element in the tuple corresponds to the first subplot and so on.
- bcdi.graph.graph_utils.imshow_plot(array, sum_frames=False, sum_axis=0, width_v=None, width_h=None, plot_colorbar=False, vmin=numpy.nan, vmax=numpy.nan, cmap=matplotlib.colors.ListedColormap, title='', labels=None, scale='linear', tick_direction='out', tick_width=1, tick_length=4, pixel_spacing=None, is_orthogonal=False, reciprocal_space=False, **kwargs)¶
2D imshow plot of a 2D or 3D dataset using user-defined parameters.
- Parameters:
array – 2D or 3D array of real numbers
sum_frames – if True, will sum the data along sum_axis
sum_axis – axis along which to sum
width_v – user-defined zoom vertical width, should be smaller than the actual data size
width_h – user-defined zoom horizontal width, should be smaller than the actual data size
plot_colorbar – set it to True in order to plot the colorbar
vmin – lower boundary for the colorbar
vmax – higher boundary for the colorbar
cmap – colormap to be used
title – string to include in the plot
labels – tuple of two strings (vertical label, horizontal label)
scale – ‘linear’ or ‘log’
tick_direction – ‘out’, ‘in’, ‘inout’
tick_width – width of tickes in plots
tick_length – length of tickes in plots
pixel_spacing – pixel_spacing = desired tick_spacing (in nm) / voxel_size of the reconstruction(in nm). It can be a positive number or a tuple of array.ndim positive numbers
is_orthogonal – True is the array is in an orthogonal basis, False otherwise (detector frame). Used for plot labels.
reciprocal_space – True if the data is in reciprocal space, False otherwise. Used for plot labels.
kwargs –
‘invert_y’: boolean, True to invert the vertical axis of the plot. Will overwrite the default behavior.
- Returns:
fig, axis, plot instances
- bcdi.graph.graph_utils.loop_thru_scan(key, array, figure, scale, dim, idx, savedir, cmap=matplotlib.colors.ListedColormap, vmin=None, vmax=None)¶
Update the plot while removing the parasitic diffraction intensity in 3D dataset.
- Parameters:
key – the keyboard key which was pressed
array – the 3D data array
figure – the figure instance
scale – ‘linear’ or ‘log’
dim – the axis over which the loop is performed (axis 0, 1 or 2)
idx – the frame index in the current axis
savedir – path of the directory for saving images
cmap – colormap to be used
vmin – the lower boundary for the colorbar
vmax – the higher boundary for the colorbar
- Returns:
updated controls
- bcdi.graph.graph_utils.multislices_plot(array, sum_frames=False, slice_position=None, width_z=None, width_y=None, width_x=None, plot_colorbar=False, cmap=matplotlib.colors.ListedColormap, title='', scale='linear', vmin=numpy.nan, vmax=numpy.nan, tick_direction='out', tick_width=1, tick_length=4, pixel_spacing=None, is_orthogonal=False, reciprocal_space=False, ipynb_layout=False, save_as: str | None = None, **kwargs)¶
Create a figure with three 2D imshow plots from a 3D dataset.
- Parameters:
array – 3D array of real numbers
sum_frames – if True, will sum the data along the 3rd axis
slice_position – tuple of three integers where to slice the 3D array
width_z – zoom width along axis 0 (rocking angle), should be smaller than the actual data size
width_y – zoom width along axis 1 (vertical), should be smaller than the actual data size
width_x – zoom width along axis 2 (horizontal), should be smaller than the actual data size
plot_colorbar – set it to True in,der to plot the colorbar
cmap – colormap to be used
title – string to include in the plot
scale – ‘linear’, ‘log’
tick_direction – ‘out’, ‘in’, ‘inout’
tick_width – width of tickes in plots
tick_length – length of tickes in plots
pixel_spacing – pixel_spacing=desired tick_spacing (in nm)/voxel_size of the reconstruction(in nm). It can be a positive number or a tuple of 3 positive numbers
is_orthogonal – set to True is the frame is orthogonal, False otherwise (detector frame) Used for plot labels.
reciprocal_space – True if the data is in reciprocal space, False otherwise. Used for plot labels.
vmin – lower boundary for the colorbar. Float or tuple of 3 floats
vmax – higher boundary for the colorbar. Float or tuple of 3 floats
ipynb_layout – toggle for 3 plots in a row, cleaner in an Jupyter Notebook
save_as – if string, saves figure at this path
kwargs –
‘invert_y’: boolean, True to invert the vertical axis of the plot. Will overwrite the default behavior.
- Returns:
fig, (ax0, ax1, ax2, ax3), (plt0, plt1, plt2) instances
- bcdi.graph.graph_utils.plot_3dmesh(vertices, faces, data_shape, title='Mesh - z axis flipped because of CXI convention')¶
Plot a 3D mesh defined by its vertices and faces.
- Parameters:
vertices – n*3 ndarray of n vertices defined by 3 positions
faces – m*3 ndarray of m faces defined by 3 indices of vertices
data_shape – tuple corresponding to the 3d data shape
title – title for the plot
- Returns:
figure and axe instances
- bcdi.graph.graph_utils.save_to_vti(filename, voxel_size, tuple_array, tuple_fieldnames, origin=(0, 0, 0), amplitude_threshold=0.01, **kwargs)¶
Save arrays defined by their name in a single vti file.
Paraview expects data in an orthonormal basis (x,y,z). For BCDI data in the .cxi convention (hence: z, y,x) it is necessary to flip the last axis. The data sent to Paraview will be in the orthonormal frame (z,y,-x), therefore Paraview_x is z (downstream), Paraview_y is y (vertical up), Paraview_z is -x (inboard) of the .cxi convention.
- Parameters:
filename – the file name of the vti file
voxel_size – tuple (voxel_size_axis0, voxel_size_axis1, voxel_size_axis2)
tuple_array – tuple of arrays of the same dimension
tuple_fieldnames – tuple of strings for the field names, same number of elements as tuple_array
origin – tuple of points for vtk SetOrigin()
amplitude_threshold – lower threshold for saving the reconstruction modulus (save memory space)
kwargs –
‘logger’: an optional logger
- Returns:
nothing
- bcdi.graph.graph_utils.savefig(savedir, figure, axes, xlabels='', ylabels='', titles='', filename='', tick_direction='out', tick_width=2, tick_length=10, tick_labelsize=16, legend_labelsize=16, label_size=20, title_size=20, only_labels=False, **kwargs)¶
Save a template figures for publication, without and with labels.
- Parameters:
savedir – str, the directory where to save the figures
figure – a matplotlib figure instance
axes – a matplotlib axis or a tuple of axes
xlabels – str, horizontal labels (one per axis)
ylabels – str, vertical labels (one per axis)
titles – str, title (one per axis)
filename – name of the file for saving the figure
tick_direction – ‘in’, ‘out’ or ‘inout’
tick_width – tick width in points
tick_length – tick length in points
tick_labelsize – label size in points of tick labels
legend_labelsize – label size in points of the legend
label_size – label size in points of axis labels
title_size – label size in points of titles
only_labels – bool, if True only the figure with all labels will be saved
kwargs –
‘bottom’, ‘top’, ‘left’, ‘right’: bool, whether to draw the respective ticks.
’labelbottom’, ‘labeltop’, ‘labelleft’, ‘labelright’: bool, whether to draw the respective tick labels.
’legend’: bool, wheter to show the legend or not
’text’: dict, a dictionnary of dictionnaries containing the parameters for matplotlib.pyplot.text function e.g. {0: {‘x’: 0.4, ‘y’: 0.4, ‘s’: ‘test’, ‘fontsize’: 12}, 1:{‘x’: 0.4, ‘y’: 0.5, ‘s’: ‘res’, ‘fontsize’: 12}}
- bcdi.graph.graph_utils.scatter_plot(array, labels, markersize=4, markercolor='b', title='')¶
2D or 3D Scatter plot of a 2D ndarray.
- Parameters:
array – 2D ndarray, the number of columns is the number of dimensions of the scatter plot (2 or 3)
labels – tuple of string labels (length = number of columns in array)
markersize – number corresponding to the marker size
markercolor – string corresponding to the marker color
title – string, title for the scatter plot
- Returns:
figure, axes instances
- bcdi.graph.graph_utils.scatter_plot_overlaid(arrays, markersizes, markercolors, labels, title='')¶
Overlaid scatter plot of 2D ndarrays having the same number of columns.
- Parameters:
arrays – tuple of 2D ndarrays, the number of columns is the number of dimensions of the scatter plot (2 or 3)
markersizes – tuple of numbers corresponding to the marker sizes (length = number of arrays)
markercolors – tuple of strings corresponding to the marker color (length = number of arrays)
labels – tuple of string labels (length = number of columns in arrays)
title – string, title for the scatter plot
- Returns:
figure, axes instances
- bcdi.graph.graph_utils.scatter_stereographic(euclidian_u, euclidian_v, color, title='', max_angle=95, cmap=matplotlib.colors.ListedColormap, uv_labels=('', ''))¶
Plot the stereographic projection of the real scattered positions of data points.
- Parameters:
euclidian_u – flattened array, normalized Euclidian metric coordinates (points can be not on a regular grid)
euclidian_v – flattened array, normalized Euclidian metric coordinates (points can be not on a regular grid)
color – flattened array, intensity of density kernel estimation at radius_mean
title – title for the stereographic plot
max_angle – maximum angle in degrees of the stereographic projection (should be larger than 90)
cmap – colormap to be used
uv_labels – tuple of strings, labels for the u axis and the v axis, respectively
- Returns:
figure and axe instances
- bcdi.graph.graph_utils.update_aliens(key, pix, piy, original_data, original_mask, updated_data, updated_mask, figure, width, dim, idx, vmax, vmin=0, invert_yaxis=False)¶
Update the plot while removing the parasitic diffraction intensity in 3D dataset.
- Parameters:
key – the keyboard key which was pressed
pix – the x value of the mouse pointer
piy – the y value of the mouse pointer
original_data – the 3D data array before masking aliens
original_mask – the 3D mask array before masking aliens
updated_data – the current 3D data array
updated_mask – the current 3D mask array
figure – the figure instance
width – the half_width of the masking window
dim – the axis currently under review (axis 0, 1 or 2)
idx – the frame index in the current axis
vmax – the higher boundary for the colorbar
vmin – the lower boundary for the colorbar
invert_yaxis – True to invert the y axis of imshow plots
- Returns:
updated data, mask and controls
- bcdi.graph.graph_utils.update_aliens_2d(key, pix, piy, original_data, original_mask, updated_data, updated_mask, figure, width, vmax, vmin=0, invert_yaxis=False)¶
Update the plot while removing the parasitic diffraction intensity in 2D dataset.
- Parameters:
key – the keyboard key which was pressed
pix – the x value of the mouse pointer
piy – the y value of the mouse pointer
original_data – the 2D data array before masking aliens
original_mask – the 2D mask array before masking aliens
updated_data – the current 2D data array
updated_mask – the current 2D mask array
figure – the figure instance
width – the half_width of the masking window
vmax – the higher boundary for the colorbar
vmin – the lower boundary for the colorbar
invert_yaxis – True to invert the y axis of imshow plots
- Returns:
updated data, mask and controls
- bcdi.graph.graph_utils.update_aliens_combined(key, pix, piy, original_data, original_mask, updated_data, updated_mask, axes, width, dim, frame_index, vmax, vmin=0, cmap=matplotlib.colors.ListedColormap, invert_yaxis=False)¶
Update the plot while removing the parasitic diffraction intensity in 3D dataset.
- Parameters:
key – the keyboard key which was pressed
pix – the x value of the mouse pointer
piy – the y value of the mouse pointer
original_data – the 3D data array before masking aliens
original_mask – the 3D mask array before masking aliens
updated_data – the current 3D data array
updated_mask – the current 3D mask array
axes – tuple of the 4 axes instances in a plt.subplots(nrows=2, ncols=2)
width – the half_width of the masking window
dim – the axis currently under review (axis 0, 1 or 2)
frame_index – list of 3 frame indices (one per axis)
vmax – the higher boundary for the colorbar
vmin – the lower boundary for the colorbar
cmap – colormap to be used
invert_yaxis – True to invert the y axis of imshow plots
- Returns:
updated data, mask (-1 filled, 0 non masked, 1 masked voxel) and controls
- bcdi.graph.graph_utils.update_background(key, distances, data, figure, flag_pause, xy, scale='log', xlim=None, ylim=None)¶
Define the background for a 1D reciprocal space dataset.
- Parameters:
key – the keyboard key which was pressed
distances – x axis for data
data – the 1D data before background subtraction
figure – the figure instance
flag_pause – set to 1 to stop registering vertices using mouse clicks
xy – the list of vertices which defines a polygon to be masked
scale – scale of data, ‘linear’ or ‘log’
xlim – x axis plot limits
ylim – y axis plot limits
- Returns:
updated background and controls
- bcdi.graph.graph_utils.update_mask(key, pix, piy, original_data, original_mask, updated_data, updated_mask, figure, flag_pause, points, xy, width, dim, vmax, vmin=0, masked_color=0.1, invert_yaxis=False)¶
Update the mask corresponding to parasitic intensities in a 3D dataset.
The GUI contains one 2D projection of the mask, the projection axis is determined by the parameter “dim”.
- Parameters:
key – the keyboard key which was pressed
pix – the x value of the mouse pointer
piy – the y value of the mouse pointer
original_data – the 3D data array before masking
original_mask – the 3D mask array before masking
updated_data – the current 3D data array
updated_mask – the temporary 2D mask array with updated points
figure – the figure instance
flag_pause – set to 1 to stop registering vertices using mouse clicks
points – list of all point coordinates: points=np.stack((x, y), axis=0).T with x=x.flatten() , y = y.flatten() given x,y=np.meshgrid(np.arange(nx), np.arange(ny))
xy – the list of vertices which defines a polygon to be masked
width – the half_width of the masking window
dim – the axis currently under review (axis 0, 1 or 2)
vmax – the higher boundary for the colorbar
vmin – the lower boundary for the colorbar
masked_color – the value that detector gaps should have in plots
invert_yaxis – True to invert the y axis of imshow plots
- Returns:
updated data, mask and controls
- bcdi.graph.graph_utils.update_mask_2d(key, pix, piy, original_data, original_mask, updated_data, updated_mask, figure, flag_pause, points, xy, width, vmax, vmin=0, masked_color=0.1, invert_yaxis=False)¶
Update the mask corresponding to parasitic intensities in a 2D dataset.
- Parameters:
key – the keyboard key which was pressed
pix – the x value of the mouse pointer
piy – the y value of the mouse pointer
original_data – the 2D data array before masking
original_mask – the 2D mask array before masking
updated_data – the current 2D data array
updated_mask – the temporary 2D mask array with updated points
figure – the figure instance
flag_pause – set to 1 to stop registering vertices using mouse clicks
points – list of all point coordinates: points=np.stack((x, y), axis=0).T with x=x.flatten() , y = y.flatten() given x,y=np.meshgrid(np.arange(nx), np.arange(ny))
xy – the list of vertices which defines a polygon to be masked
width – the half_width of the masking window
vmax – the higher boundary for the colorbar
vmin – the lower boundary for the colorbar
masked_color – the value that detector gaps should have in plots
invert_yaxis – True to invert the y axis of imshow plots
- Returns:
updated data, mask and controls
- bcdi.graph.graph_utils.update_mask_combined(key, pix, piy, original_data, original_mask, updated_data, updated_mask, axes, flag_pause, points, xy, width, dim, click_dim, info_text, vmax, vmin=0, cmap=matplotlib.colors.ListedColormap, invert_yaxis=False)¶
Update the mask to remove parasitic intensities in a 3D dataset.
The GUI contains the three 2D projections of the mask, the axis being modified is determined by the parameter “dim”.
- Parameters:
key – the keyboard key which was pressed
pix – the x value of the mouse pointer
piy – the y value of the mouse pointer
original_data – the 3D data array before masking
original_mask – the 3D mask array before masking
updated_data – the current 3D data array
updated_mask – the temporary 3D mask array with updated points
axes – tuple of the 4 axes instances in a plt.subplots(nrows=2, ncols=2)
flag_pause – set to 1 to stop registering vertices using mouse clicks
points – list of all point coordinates: points=np.stack((x, y), axis=0).T with x=x.flatten() , y = y.flatten() given x,y=np.meshgrid(np.arange(nx), np.arange(ny))
xy – the list of vertices which defines a polygon to be masked
width – the half_width of the masking window
dim – the axis currently under review (axis 0, 1 or 2)
click_dim – the dimension (0, 1 or 2) where the selection of mask polygon vertices by clicking was performed
info_text – text instance in the figure
vmax – the higher boundary for the colorbar
vmin – the lower boundary for the colorbar
cmap – colormap to be used
invert_yaxis – True to invert the y axis of imshow plots
- Returns:
updated data, mask (-1 filled, 0 non masked, 1 masked voxel) and controls
linecut¶
This module provides a class and functions to generate linecuts through an array, perform some fitting on it (e.g. to estimate the resolution of a reconstruction) and plot it.
API Reference¶
Class and functions related to the generation of linecuts through an array.
- class bcdi.graph.linecut.LinecutGenerator(array: numpy.ndarray, indices: List[List[Tuple[int, int]]] | None = None, filename: str | None = None, fit_derivative: bool = False, voxel_sizes: List[float] | None = None, support_threshold: float = 0.25, label: str = 'linecut', **kwargs)¶
Generate linecuts of an array, including fitting and plotting methods.
- Parameters:
array – a 2D or 3D array, typically the modulus of a real space object after phase retrieval
indices – a list of ndim lists of ndim tuples (start, stop), ndim being the number of dimensions of the array (one list per linecut)
fit_derivative – True to fit the gradient of the linecut with a gaussian line shape
support_threshold – float, threshold used to define the support, for the determination of the location of crystal boundaries
voxel_sizes – list of voxels sizes, in each dimension of the array
filename – name for saving plots
label – labels for the vertical axis of plots
kwargs –
‘logger’: an optional logger
- property filename¶
File name for saving plots.
- find_boundaries() None ¶
Localize coarsely the position of the jumps in the modulus of the array.
For a cristal reconstructed after phase retrieval, these position correspond to the cristal boundaries.
- fit_boundaries() None ¶
Fit the array with gaussians at the location of the detected boundaries.
- generate_linecut() None ¶
Generate a linecut along a given axis.
- generate_linecuts()¶
Generate a linecut for each dimension of the array.
- property indices¶
List of indices for the linecut.
- plot_fits() None ¶
Plot fits to the derivatives of the linecuts.
Expected structure for linecuts:
linecuts = { 'dimension_0': { 'linecut': np.ndarray (2, M), 'derivative_0': np.ndarray (2, N), 'derivative_1': np.ndarray (2, O), 'fit_0': np.ndarray (2, P), 'fit_1': np.ndarray (2, P), 'param_0': {'amp': float, 'sig': float, 'cen': float}, 'param_1': {'amp': float, 'sig': float, 'cen': float}, }, 'dimension_1': {...} ... }
- property plot_labels¶
Axis labels used in plots.
- plot_linecuts() None ¶
Plot the generated linecuts and optionally save the figure.
Expected structure for linecuts:
linecuts = { 'dimension_0': { 'linecut': np.ndarray (2, M), 'derivative_0': np.ndarray (2, N), 'derivative_1': np.ndarray (2, O), 'fit_0': np.ndarray (2, P), 'fit_1': np.ndarray (2, P), 'param_0': {'amp': float, 'sig': float, 'cen': float}, 'param_1': {'amp': float, 'sig': float, 'cen': float}, }, 'dimension_1': {...} ... }
- property unit¶
Define the unit length for the array pixel.
- property voxel_sizes¶
Voxel sizes of the array in each dimension.
- bcdi.graph.linecut.fit_linecut(array: numpy.ndarray, indices: List[List[Tuple[int, int]]] | None = None, fit_derivative: bool = False, support_threshold: float = 0.25, voxel_sizes: List[float] | None = None, filename: str | None = None, label: str = 'linecut', **kwargs) Dict ¶
Perform a linecut on an array and optionally fit its gradient.
- Parameters:
array – a 2D or 3D array, typically the modulus of a real space object after phase retrieval
indices – a list of ndim lists of ndim tuples (start, stop), ndim being the number of dimensions of the array (one list per linecut)
fit_derivative – True to fit the gradient of the linecut with a gaussian line shape
support_threshold – float, threshold used to define the support, for the determination of the location of crystal boundaries
voxel_sizes – list of voxels sizes, in each dimension of the array
filename – name for saving plots
label – labels for the vertical axis of plots
kwargs –
‘logger’: an optional logger
- Returns:
a dictionary containing linecuts, fits and fitted parameters
- bcdi.graph.linecut.linecut(array: numpy.ndarray, indices: List[Tuple[int, int]], interp_order: int = 1) numpy.ndarray ¶
Linecut through a 2D or 3D array.
The user must input indices of the starting voxel and of the end voxel.
- Parameters:
array – a numpy array
indices – list of tuples of (start, stop) indices, one tuple for each dimension of the array. e.g [(start0, stop0), (start1, stop1)] for a 2D array
interp_order – order of the spline interpolation, default is 3. The order has to be in the range 0-5.
- Returns:
a 1D array interpolated between the start and stop indices