pyccapt.calibration.reconstructions package
Submodules
pyccapt.calibration.reconstructions.crystal_helper module
- pyccapt.calibration.reconstructions.crystal_helper.apply_noise_to_structure(structure, noise_levels=(5, 5, 2), noise_type='correlative')[source]
Applies random displacements to the atomic positions in a structure.
Parameters: structure (Structure): The pymatgen Structure object containing atom positions. noise_levels (tuple of floats): Noise levels for the x, y, and z coordinates in Ångstroms.
For example, (0.5, 0.3, 0.1) will add up to 0.5 Å noise in x, 0.3 Å noise in y, and 0.1 Å noise in z.
noise_type (str): Type of noise to apply. Options are ‘correlative’ or ‘noncorrelative’.
Returns: tuple:
Structure: A new Structure object with noise applied to each atomic position.
np.ndarray: The noise array applied to each atom (for debugging or visualization purposes).
- pyccapt.calibration.reconstructions.crystal_helper.filter_atoms_in_cone_and_hemisphere(structure, cone_r, cone_L, hemi_z_base)[source]
Filters atoms that are inside a cone and inside/below a hemisphere.
Parameters: structure (Structure): Pymatgen Structure object containing atom positions. cone_r (float): Radius of the cone’s base. cone_L (float): Height of the cone along the z-axis. hemi_z_base (float): Height of the hemisphere’s flat face along the z-axis.
Returns: Structure: Filtered Structure object containing only atoms inside the cone or inside/below the hemisphere. numpy.ndarray: Filtered array of atom coordinates.
- pyccapt.calibration.reconstructions.crystal_helper.find_phi_and_theta(sdm_param, theta_min, theta_max, phi_min, phi_max)[source]
Plots noise level based on theta and phi values.
Parameters: - sdm_param (np.ndarray): Array of parameters, where columns 2, 3, 4 represent theta, phi, and noise respectively. - theta_min (float): Minimum theta for plot limits. - theta_max (float): Maximum theta for plot limits. - phi_min (float): Minimum phi for plot limits. - phi_max (float): Maximum phi for plot limits.
Returns: - theta_value (float): Theta value with minimum noise. - phi_value (float): Phi value with minimum noise.
- pyccapt.calibration.reconstructions.crystal_helper.project_to_surface(structure)[source]
Projects all atomic positions onto the surface
Parameters: structure (Structure): A pymatgen Structure object with atomic positions.
Returns: Structure: A new Structure object with all atomic positions projected onto the hemisphere surface.
- pyccapt.calibration.reconstructions.crystal_helper.pyccapt_to_pymatgen(data, range)[source]
Converts data from pyccapt format to pymatgen format.
- Parameters:
data – the data in pyccapt format
range – the range of data IN pyccapt format to be converted
- Returns:
pymatgen Structure object
- pyccapt.calibration.reconstructions.crystal_helper.rotate_structure(structure, theta_deg, phi_deg)[source]
Rotates the atomic coordinates of a pymatgen Structure based on given angles theta (angle from the z-axis) and phi (angle from the x-axis in the xy-plane).
Parameters: - structure (Structure): Pymatgen Structure object containing atomic positions. - theta_deg (float): Angle theta in degrees (from the z-axis). - phi_deg (float): Angle phi in degrees (from the x-axis in the xy-plane).
Returns: - Structure: New pymatgen Structure with rotated atomic coordinates.
- pyccapt.calibration.reconstructions.crystal_helper.stereographic_projection(structure, d_z=0)[source]
Projects all atomic positions onto the surface
Parameters: structure (Structure): A pymatgen Structure object with atomic positions. d_z (float): The distance of the projection plane from the origin.
Returns: Structure: A new Structure object with all atomic positions projected onto the hemisphere surface.
pyccapt.calibration.reconstructions.density_map module
- pyccapt.calibration.reconstructions.density_map.plot_density_map(x, y, z_weigth=False, log=True, bins=(256, 256), frac=1.0, axis_mode='normal', figure_size=(5, 4), variables=None, composition=None, roi=None, range_sequence=[], range_mc=[], range_detx=[], range_dety=[], range_x=[], range_y=[], range_z=[], range_vol=[], data_crop=False, draw_circle=False, mode_selector='circle', axis=['x', 'y'], save=False, figname='disparity_map', cmap='plasma', normalize=False, normalize_axes=False)[source]
Plot and crop the density map with the option to select a region of interest.
- Parameters:
x – x-axis data
y – y-axis data
z_weigth – z weight data
log – Flag to choose whether to plot the log of the data
bins – Number of bins for the histogram in tuple or bin size in nm as float
frac – Fraction of the data to be plotted
axis_mode – Flag to choose whether to plot axis or scalebar: ‘normal’ or ‘scalebar’
variables – Variables object
composition – list of elements
roi – Region of interest
range_sequence – Range of sequence as list or percentage
range_mc – Range of mc
range_detx – Range of detx
range_dety – Range of dety
range_x – Range of x-axis
range_y – Range of y-axis
range_z – Range of z-axis
range_vol – Range of voltage
figure_size – Size of the plot
draw_circle – Flag to enable circular region of interest selection
mode_selector – Mode of selection (circle or ellipse)
axis – Axes to be plotted
save – Flag to choose whether to save the plot or not
data_crop – Flag to control whether only the plot is shown or cropping functionality is enabled
figname – Name of the figure
cmap – Colormap for the plot
normalize – Flag to normalize the histogram (default False).
normalize_axes – Flag to normalize the axis limits (default False).
- Returns:
None
pyccapt.calibration.reconstructions.fft module
pyccapt.calibration.reconstructions.iso_surface module
- pyccapt.calibration.reconstructions.iso_surface.bin_vectors_from_distance(dist, bin_values, mode='distance')[source]
Create a set of grid vectors to be used in nD binning. The bounds are calculated such that they don’t go beyond the size of the dataset.
- Parameters:
dist (numpy.ndarray) – The distance variable to be binned. One column per dimension. It is the generalized distance.
bin_values (list or numpy.ndarray) – The bin ‘distance’ per bin in either a distance metric or a count. Non-isometric bins are possible.
mode (str) – Mode can be ‘distance’ (constant distance) or ‘count’ (constant count). Default is ‘distance’.
- Returns:
bin_centers (list of numpy.ndarray): The bin centers of each bin.
bin_edges (list of numpy.ndarray): The edges of each bin.
- Return type:
- pyccapt.calibration.reconstructions.iso_surface.build_element_mask(variables, element_name, base_mask=None, pure_only=False)[source]
Build a boolean mask for ranged ions matching a given element selector.
- pyccapt.calibration.reconstructions.iso_surface.build_range_mask(variables, range_sequence=None, range_mc=None, range_detx=None, range_dety=None, range_x=None, range_y=None, range_z=None, range_vol=None, verbose=False)[source]
Build a boolean mask for the requested reconstruction sub-range.
- pyccapt.calibration.reconstructions.iso_surface.calculate_element_isosurface(variables, element_name, bin_values, base_mask=None, smoothing_sigma=1.0, min_atoms_per_voxel=10, min_vertices=20, fig_name=None, pure_only=False, manual_iso_value=None)[source]
Create a filtered isosurface mesh for a single interface element.
- pyccapt.calibration.reconstructions.iso_surface.calculate_iso_value(conc, save_path=None, fig_name=None)[source]
Calculate the optimal iso value from a 3D array and save the histogram plot.
- Parameters:
conc (numpy.ndarray) – 3D array of concentration values.
save_path (str) – Directory to save the histogram plot.
- Returns:
Optimal iso value.
- Return type:
- pyccapt.calibration.reconstructions.iso_surface.filter_isosurface_by_size(isosurf, min_vertices=100, largest_n=None)[source]
Remove small disconnected isosurface components.
- pyccapt.calibration.reconstructions.iso_surface.isosurface(gridVec, data, isovalue)[source]
Extract isosurface using pyvista for a custom 3D grid.
- Parameters:
- Returns:
Isosurface with faces and vertices.
- Return type:
pyvista.PolyData
- pyccapt.calibration.reconstructions.iso_surface.plotly_fig2array(fig)[source]
convert Plotly fig to an array
- Parameters:
fig (plotly.graph_objects.Figure) – The base figure.
- Returns:
The array representation of the figure.
- Return type:
array
- pyccapt.calibration.reconstructions.iso_surface.pos_to_voxel(data, grid_vec, species=None)[source]
Creates a voxelization of the data in ‘pos’ based on the bin centers in ‘grid_vec’ for the atoms/ions in the specified species.
- Args:
data (pyccapt DataFrame): The data to be voxelized. when input species is given, ranges must be allocated.
- % A decomposed DataFrame file is also possible. Use range_to_pyccapt to decompose the data.
grid_vec (list of numpy.ndarray): Grid vectors for the voxel grid. These are the bin centers. species (list, str, or numpy.ndarray, optional): The species to filter by. Can be:
List of species names (e.g., [‘Fe’, ‘Mn’]).
Boolean array matching the length of pos.
None, to include all atoms/ions.
- Returns:
numpy.ndarray: A 3D array representing the voxelized data.
- pyccapt.calibration.reconstructions.iso_surface.reconstruction_plot(variables, element_percentage, opacity, rotary_fig_save, figname, save, make_gif=False, range_sequence=[], range_mc=[], range_detx=[], range_dety=[], range_x=[], range_y=[], range_z=[], range_vol=[], ions_individually_plots=False, max_num_ions=None, min_num_ions=None, isosurface_dic=None, detailed_isotope_charge=False, only_iso=False, cluster_result=None, smoothing_sigma=1.0, min_atoms_per_voxel=10, min_isosurface_vertices=20, pure_element_only=False, manual_iso_value=None, cluster_display_mode='overlay')[source]
Generate a 3D plot for atom probe reconstruction data.
- Parameters:
variables (DataFrame) – variables object contains daraframe with the data.
element_percentage (list) – Percentage of each element to plot.
opacity (float) – Opacity of the ions.
rotary_fig_save (bool) – Whether to save the rotary figure.
figname (str) – Name of the figure.
save (bool) – Whether to save the figure.
make_gif (bool) – Whether to make a GIF.
range_sequence (list) – Sequence of the range data.
range_mc (list) – Mass-to-charge ratio of the range data.
range_detx (list) – Detector x-coordinate of the range data.
range_dety (list) – Detector y-coordinate of the range data.
range_x (list) – x-coordinate of the range data.
range_y (list) – y-coordinate of the range data.
range_z (list) – z-coordinate of the range data.
range_vol (list) – Volume of the range data.
ions_individually_plots (bool) – Whether to plot each ion individually.
max_num_ions (int) – Maximum number of ions to plot.
min_num_ions (int) – Minimum number of ions to plot.
isosurface_dic (dic) – Dictionary with the isosurface elements and their values.
detailed_isotope_charge (bool) – Whether to plot the range of each isotopes and charge state.
only_iso (bool) – Whether to plot only the isosurface.
cluster_result – Optional Min-Max precipitate segmentation overlay.
cluster_display_mode (str) – overlay or clusters-only.
- Returns:
None
- pyccapt.calibration.reconstructions.iso_surface.rotary_fig(fig, variables, rotary_fig_save, make_gif, figname)[source]
Generate a rotating figure using Plotly.
pyccapt.calibration.reconstructions.rdf module
- pyccapt.calibration.reconstructions.rdf.rdf(particles, dr, variables=None, rho=None, rcutoff=0.9, eps=1e-15, normalize=True, reference_point=None, box_dimensions=None, plot=False, save=False, figure_size=(6, 6), figname='rdf')[source]
Computes 2D or 3D radial distribution function g(r) of a set of particle coordinates of shape (N, d). Particle must be placed in a 2D or 3D cuboidal box of dimensions [width x height (x depth)].
- Parameters:
particles ((N, d) np.array) – Set of particle from which to compute the radial distribution function g(r). Must be of shape (N, 2) or (N, 3) for 2D and 3D coordinates repsectively.
dr (float) – Delta r. Determines the spacing between successive radii over which g(r) is computed.
variables (variables object)
rho (float, optional) – Number density. If left as None, box dimensions will be inferred from the particles and the number density will be calculated accordingly.
rcutoff (float) – radii cutoff value between 0 and 1. The default value of 0.9 means the independent variable (radius) over which the RDF is computed will range from 0 to 0.9*r_max. This removes the noise that occurs at r values close to r_max, due to fewer valid particles available to compute the RDF from at these r values.
eps (float, optional) – Epsilon value used to find particles less than or equal to a distance in KDTree.
normalize (bool, optional) – Option to normalize the RDF. If True, the RDF values are normalized.
reference_point ((d,) np.array or list, optional) – The center of the box. If left as None, there is no data cropping and calculate the rdf for the whole data.
box_dimensions ((d,) np.array or list, optional) – The dimensions of the box. If left as None, the box dimensions will be inferred from the particles.
plot (bool, optional) – Option to plot the RDF. If True, the RDF is plotted.
save (bool, optional) – Option to save the RDF. If True, the RDF is saved.
figure_size ((float, float), optional) – The size of the figure in inches.
figname (str, optional) – The name of the figure.
- Returns:
g_r ((n_radii) np.array) – radial distribution function values g(r).
radii ((n_radii) np.array) – radii over which g(r) is computed
pyccapt.calibration.reconstructions.reconstruction module
- pyccapt.calibration.reconstructions.reconstruction.atom_probe_recons_Bas_et_al(detx, dety, hv, flight_path_length, kf, det_eff, icf, field_evap, avg_dens)[source]
Perform atom probe reconstruction using Bas et al.’s method.
- Parameters:
detx (float) – Hit position on the detector (x-coordinate).
dety (float) – Hit position on the detector (y-coordinate).
hv (float) – High voltage.
flight_path_length (float) – Distance between detector and sample.
kf (float) – Field reduction factor.
det_eff (float) – Efficiency of the detector.
icf (float) – Image compression factor due to sample imperfections.
field_evap (float) – Evaporation field in V/nm.
avg_dens (float) – Atomic density in atoms/nm^3.
- Returns:
x-coordinates of reconstructed atom positions in nm. float: y-coordinates of reconstructed atom positions in nm. float: z-coordinates of reconstructed atom positions in nm.
- Return type:
- pyccapt.calibration.reconstructions.reconstruction.atom_probe_recons_from_detector_Geiser_et_al(detx, dety, hv, flight_path_length, kf, det_eff, icf, field_evap, avg_dens)[source]
Perform atom probe reconstruction using Geiser et al.’s method.
- Parameters:
detx (float) – Hit position on the detector (x-coordinate).
dety (float) – Hit position on the detector (y-coordinate).
hv (float) – High voltage.
flight_path_length (float) – Distance between detector and sample.
kf (float) – Field reduction factor.
det_eff (float) – Efficiency of the detector.
icf (float) – Image compression factor due to sample imperfections.
field_evap (float) – Evaporation field in V/nm.
avg_dens (float) – Atomic density in atoms/nm^3.
- Returns:
x-coordinates of reconstructed atom positions in nm. float: y-coordinates of reconstructed atom positions in nm. float: z-coordinates of reconstructed atom positions in nm.
- Return type:
- pyccapt.calibration.reconstructions.reconstruction.cart2pol(x, y)[source]
Convert Cartesian coordinates to polar coordinates.
- pyccapt.calibration.reconstructions.reconstruction.detector_animation(variables, points_per_frame, ranged, selected_area_specially, selected_area_temporally, figure_name, figure_sie, save)[source]
Generate a animated heatmap based on the provided data.
- Parameters:
variables (object) – The variables object.
points_per_frame (int) – The number of points per frame.
ranged (bool) – True if the data is ranged, False otherwise.
selected_area_specially (bool) – True if a specific area is selected, False otherwise.
selected_area_temporally (bool) – True if a specific area is selected, False otherwise.
figure_name (str) – The name of the figure.
figure_sie – The size of the figure.
save (bool) – True to save the plot, False to display it.
- Returns:
None
- pyccapt.calibration.reconstructions.reconstruction.draw_qube(fig, range, col=None, row=None)[source]
- pyccapt.calibration.reconstructions.reconstruction.heatmap(variables, element_percentage, range_sequence=[], range_mc=[], range_detx=[], range_dety=[], range_x=[], range_y=[], range_z=[], range_vol=[], figure_name='hetmap', figure_sie=(5, 5), save=False)[source]
Generate a heatmap based on the provided data.
- Parameters:
variables (object) – The variables object.
element_percentage (str) – Element percentage information.
range_sequence – Range of sequence
range_mc – Range of mc
range_detx – Range of detx
range_dety – Range of dety
range_x – Range of x-axis
range_y – Range of y-axis
range_z – Range of z-axis
range_vol – Range of volume
figure_name (str) – The name of the figure.
figure_sie – The size of the figure.
save (bool) – True to save the plot, False to display it.
- Returns:
None
- pyccapt.calibration.reconstructions.reconstruction.pol2cart(rho, phi)[source]
Convert polar coordinates to Cartesian coordinates.
- pyccapt.calibration.reconstructions.reconstruction.projection(variables, element_percentage, range_sequence=[], range_mc=[], range_detx=[], range_dety=[], range_x=[], range_y=[], range_z=[], range_vol=[], x_or_y='x', figname='projection', figure_size=(5, 5), save=False)[source]
Generate a projection plot based on the provided data.
- Parameters:
variables (object) – The variables object.
element_percentage (str) – Element percentage information.
range_sequence – Range of sequence
range_mc – Range of mc
range_detx – Range of detx
range_dety – Range of dety
range_x – Range of x-axis
range_y – Range of y-axis
range_z – Range of z-axis
range_vol – Range of volume
x_or_y (str) – Either ‘x’ or ‘y’ indicating the axis to plot.
figname (str) – The name of the figure.
- Returns:
None
- pyccapt.calibration.reconstructions.reconstruction.reconstruction_2d_histogram(variables, x, y, bins, percentage, range_sequence=[], range_mc=[], range_detx=[], range_dety=[], range_x=[], range_y=[], range_z=[], range_vol=[], xlabel='X-axis', ylabel='Y-axis', save=False, figure_name=None, figure_size=None)[source]
Generate a 2D histogram based on the provided data.
- Parameters:
variables (object) – The variables object.
x (array) – The x-axis data.
y (array) – The y-axis data.
percentage (float) – percent of data to be plotted.
range_sequence – Range of sequence
range_mc – Range of mc
range_detx – Range of detx
range_dety – Range of dety
range_x – Range of x-axis
range_y – Range of y-axis
range_z – Range of z-axis
range_vol – Range of volume
xlabel (str) – The label of the x-axis.
ylabel (str) – The label of the y-axis.
save (bool) – True to save the plot, False to display it.
figure_name (str) – The name of the figure.
figure_size (tuple) – The size of the figure.
- Returns:
None
- pyccapt.calibration.reconstructions.reconstruction.reconstruction_plot(variables, element_percentage, opacity, rotary_fig_save, figname, save, make_gif=False, make_evaporation_gif=False, range_sequence=[], range_mc=[], range_detx=[], range_dety=[], range_x=[], range_y=[], range_z=[], range_vol=[], ions_individually_plots=False, detailed_isotope_charge=False, colab=False, cluster_result=None, cluster_display_mode='overlay', cluster_opacity_override=None, element_alpha=None)[source]
Generate a 3D plot for atom probe reconstruction data.
- Parameters:
variables (object) – Variables object.
element_percentage (str) – Percentage of elements to display.
opacity (float) – Default opacity of the markers.
rotary_fig_save (bool) – Whether to save the rotary figure.
figname (str) – Name of the figure.
save (bool) – Whether to save the figure.
make_gif (bool) – Whether to make a GIF.
make_evaporation_gif (bool) – Whether to make an evaporation GIF.
range_sequence (list) – Range of sequence
range_mc – Range of mc
range_detx – Range of detx
range_dety – Range of dety
range_x – Range of x-axis
range_y – Range of y-axis
range_z – Range of z-axis
range_vol – Range of volume
ions_individually_plots (bool) – Whether to plot ions individually.
detailed_isotope_charge (bool) – Whether to plot detailed isotope and charge information.
colab (bool) – Whether to run in Google Colab.
cluster_result – Optional Min-Max segmentation result for precipitate overlays.
cluster_display_mode (str) – overlay or clusters-only.
element_alpha (list[float] | None) – Optional per-ion opacity overrides aligned with the range table order.
- Returns:
None
- pyccapt.calibration.reconstructions.reconstruction.scatter_plot(data, range_data, variables, element_percentage, selected_area, x_or_y, figname, figure_size, save=False)[source]
Generate a scatter plot based on the provided data.
- Parameters:
data (pandas.DataFrame) – The input data.
range_data (pandas.DataFrame) – Data containing range information for different elements.
variables (object) – The variables object.
element_percentage (str) – Element percentage information.
selected_area (bool) – True if a specific area is selected, False otherwise.
x_or_y (str) – Either ‘x’ or ‘y’ indicating the axis to plot.
figname (str) – The name of the figure.
- Returns:
None
- pyccapt.calibration.reconstructions.reconstruction.x_y_z_calculation_and_plot(variables, element_percentage, kf, det_eff, icf, field_evap, avg_dens, flight_path_length, rotary_fig_save, mode, opacity, figname, save, colab=False, cluster_result=None)[source]
Calculate the x, y, z coordinates of the atoms and plot them.
- Args:
variables (object): The variables object. element_percentage (str): Element percentage information. kf (float): The kinetic energy of the ions. det_eff (float): The detector efficiency. icf (float): The image compression factor. field_evap (float): The field evaporation efficiency. avg_dens (float): The average density of the atoms. flight_path_length (float): The flight path length. pulse_mode (str): rotary_fig_save (bool): True to save the rotary plot, False to display it. mode (str): The reconstruction mode. opacity (float): The opacity of the markers. figname (str): The name of the figure. save (bool): True to save the plot, False to display it. colab (bool): True if the code is running in Google Colab, False otherwise. cluster_result: Optional Min-Max precipitate segmentation overlay.
- Returns:
None
pyccapt.calibration.reconstructions.sdm module
- pyccapt.calibration.reconstructions.sdm.sdm(particles, bin_size, variables=None, roi=[0, 0, 0.5], z_cut=True, normalize=False, plot_mode='bar', plot=False, save=False, figure_size=(6, 6), figname='sdm', histogram_type='1d', axes=None, i_composition=None, j_composition=None, plot_roi=False, theta_x=0, phi_y=0, log=False, frac=1.0, range_sequence=[], range_mc=[], range_detx=[], range_dety=[], range_x=[], range_y=[], range_z=[], range_vol=[])[source]
Computes 1D or 2D histograms for a set of particle coordinates.
- particles(N, 3) np.array
Set of particle coordinates for which to compute the SDM.
- bin_sizefloat
Bin size for each histogram.
variables : variables object normalize : bool, optional
Option to normalize the histograms. If True, the histogram values are normalized.
- roilist, optional
Region of interest for the SDM. Default is [0, 0, 1].
- z_cutbool, optional
Cut the z distances over 1 nm
- plot_modestr, optional
The plot mode for the histograms. Options are ‘bar’ or ‘line’.
- plotbool, optional
Option to plot the histograms. If True, the histograms are plotted.
- savebool, optional
Option to save the histograms. If True, the histograms are saved.
- figure_size(float, float), optional
The size of the figure in inches.
- fignamestr, optional
The name of the figure.
- histogram_typestr, optional
Type of histogram. Options are ‘1D’ or ‘2D’ or ‘3D’.
- axeslist or None, optional
Specifies the axes for 1D or 2D histograms. For ‘1d’, provide a list like [‘x’], [‘y’], or [‘z’]. For ‘2d’, provide a list like [‘x’, ‘y’], [‘y’, ‘z’], or [‘x’, ‘z’] or [‘x’, ‘y’, ‘z’].
- i_compositionlist, optional
Composition of the first element in the SDM.
- j_compositionlist, optional
Composition of the second element in the SDM.
- plot_roibool, optional
Option to plot the region of interest. If True, the region of interest is plotted.
- theta_xfloat, optional
Rotation angle around the x-axis.
- phi_yfloat, optional
Rotation angle around the y-axis.
- logbool, optional
Option to plot the SDM in log scale. If True, the SDM is plotted in log scale. frac : float, optional
Fraction of the second element in the SDM.
- range_sequencelist, optional
Sequence range for the SDM.
- range_mclist, optional
Mass-to-charge range for the SDM.
- range_detxlist, optional
Detector x-coordinate range for the SDM.
- range_detylist, optional
Detector y-coordinate range for the SDM.
- range_xlist, optional
X-coordinate range for the SDM.
- range_ylist, optional
Y-coordinate range for the SDM.
- range_zlist, optional
Z-coordinate range for the SDM.
- range_vollist, optional
Volume range for the SDM.
- histogramslist of np.array
List of 1D or 2D histograms based on user preferences.
- edgeslist of np.array
Bin edges for each histogram.
Module contents
Reconstruction and visualization utilities for calibrated datasets.