santex.ebsd package#

Submodules#

santex.ebsd.calcGrainBoundary module#

santex.ebsd.calcGrainBoundary.assign_to_grains_parallel(df, threshold)#

Assign grains to rows in a DataFrame based on misorientation angle threshold.

Parameters:

df (pd.DataFrame): Input DataFrame containing Euler angles for each row. threshold (float): Misorientation angle threshold in degrees.

Returns:

dict: A dictionary mapping row indices to assigned grain indices.

santex.ebsd.calcGrainBoundary.euler_to_quaternion(phi, theta, psi)#

Convert Euler angles (in radians) to a quaternion.

Parameters:

phi (float): Euler angle phi in radians. theta (float): Euler angle theta in radians. psi (float): Euler angle psi in radians.

Returns:

np.ndarray: A quaternion representing the input Euler angles.

santex.ebsd.calcGrainBoundary.misorientation_angle(euler1, euler2)#

Calculate the misorientation angle between two sets of Euler angles.

Parameters:

euler1 (list or np.ndarray): First set of Euler angles in radians. euler2 (list or np.ndarray): Second set of Euler angles in radians.

Returns:

float: The misorientation angle between the two sets of Euler angles in degrees.

santex.ebsd.calcGrainBoundary.quaternion_to_angle(q1, q2)#

Calculate the misorientation angle between two quaternions.

Parameters:

q1 (np.ndarray): First quaternion. q2 (np.ndarray): Second quaternion.

Returns:

float: The misorientation angle between the two quaternions in degrees.

santex.ebsd.ebsd module#

class santex.ebsd.ebsd.EBSD(filename)#

Bases: object

Class for handling Electron Backscatter Diffraction (EBSD) data.

calc_grains(df, phase_names, threshold=10, downsampling_factor=20)#

Calculated the grains in the ebsd data

Parameters: - df: EBSD dataframe, this is the df we get from from df = ebsdfile.get_ebsd_data(), - threshold: float, threshold will be the threshold angle in degrees, threshold mean orientation angle, by default threshold is set to 10 degrees, but can be modified as threshold = 20 and so on and so forth - phase_names: list, phase_name will be a list of phases present and that can be obtained from self.phases_names - downsampling factor: int, specify downsampling factor for faster computation, default is 20

Returns: - df: EBSD dataframe with grains calculated

downsample_EBSD(factor=10, df=None)#

Downsamples EBSD data.

Parameters:

factor (int, optional): Downsampling factor. Defaults to 10. df (pandas.DataFrame, optional): DataFrame containing EBSD data. Defaults to None.

Returns:

pandas.DataFrame: Downsampled DataFrame.

euler_to_quaternion(phi, phi1, phi2)#

Convert Euler angles (Bunge angles) to quaternion.

Parameters: phi : float

First Euler angle (in radians).

phi1float

Second Euler angle (in radians).

phi2float

Third Euler angle (in radians).

Returns: quaternion : numpy.ndarray

Quaternion as [w, x, y, z].

filter_MAD(df, value=0.7)#

Filters the ebsd dataframe with MAD greater than a certain threshold

Parameters: - df: pandas EBSD dataframe - value: value of the threshold for MAD (default is 0.7)

Returns: - df: EBSD filtered dataframe

filter_by_grain_size(df, phases_names, min_grain_size=100)#

Filters ebsd by grain size

Parameters: - df: EBSD dataframe, which is the input from calcGrainsdf, with grain column appended - min_grain_size: int, desired minimum grain size, default is 100

Returns: - df_filtered: Filtered EBSD dataframe

filter_by_phase(phase_list, data=None)#

Filters EBSD data by phase.

Parameters:

phase_list (list): List of phase names. data (pandas.DataFrame, optional): DataFrame containing EBSD data. Defaults to None.

Returns:

pandas.DataFrame: Filtered DataFrame.

filter_by_phase_number_list(phase_list, df=None)#

Filters the EBSD dataframe given a list of phases

Parameters: - df: pandas EBSD dataframe - phase_list: list of the index of phases, eg: phase_list = [4, 5, 6, 7]

get_anisotropy_for_ebsd(cij, euler_angles, density, method=0, melt=0, density_melt=2100)#

Calculates average density and tensor for EBSD data

Parameters: cij: array, stiffness tensor of phase, 2D array euler_angles: list, euler angles of phases in list density: float, density of phases melt: float, percentage of melt available density_melt: float, in g/cm3 method: 0 for voigt, 1 for voigt, 2 for reuss, 3 for hill

Returns: - average_tensor: array, average tensor calculated - density: float, average density

get_ebsd_data()#

Retrieves EBSD data.

Returns:

pandas.DataFrame: DataFrame containing EBSD data.

get_ebsd_data_header()#

Retrieves EBSD data and header information.

Returns:

tuple: Tuple containing EBSD data and header information.

get_euler_angles(phase, data=None)#

Retrieves Euler angles for a specified phase.

Parameters:

phase (int): Integer representing the phase number. data (pandas.DataFrame, optional): DataFrame containing EBSD data. If not provided, uses stored data.

Returns:

pandas.DataFrame: DataFrame containing Euler angles (Euler1, Euler2, Euler3).

get_euler_angles_by_phase(phase)#

Retrieves Euler angles by phase names.

Parameters:

phase (str): Phase name.

Returns:

pandas.dataframe: euler angles of phase by name

get_index_of_phases(phases_list)#

Get the index of phases based on their names.

Parameters:

phases_list (list): A list of phase names.

Returns:

list: A list containing the indexes of the specified phases.

get_phases_numbers()#

Retrieves phase numbers.

Returns:

list: List containing phase numbers.

get_voigt_reuss_hill(cij, euler_angles, density, melt=0, density_melt=2100, method='voigt')#

Calculate average density and tensor using Voigt, Reuss, and Hill averages.

Parameters: cij: list of arrays, stiffness tensors (Voigt notation) for each phase euler_angles: list of pandas DataFrames, each containing Euler angles for the phases density: array, density of each phase melt: float, percentage of melt density_melt: float, density of melt

Returns: dict: Voigt, Reuss, Hill averaged tensors and density

ipf(df, phase=1, vector_sample=[0, 0, 1], random_val=True, vector_title='Z', crystal_symmetry='D2')#

Generate and visualize an Inverse Pole Figure (IPF) from EBSD data.

Parameters: - df: pandas DataFrame

The DataFrame containing EBSD (Electron Backscatter Diffraction) data.

  • phase: int, optional

    The phase number for which IPF needs to be generated (default is 1).

  • vector_sample: list of int, optional

    The sample vector used for IPF generation (default is [0, 0, 1]).

  • random_val: bool, optional

    If True, randomly select orientation values for IPF generation (default is True).

  • vector_title: str, optional

    The title for the vector used in IPF visualization (default is ‘Z’).

  • projection: str, optional

    The type of projection for IPF visualization (default is ‘ipf’).

  • crystal_symmetry: str, optional

    The crystal symmetry of the material (default is ‘D2’).

Returns: - fig: matplotlib Figure

The generated matplotlib Figure object containing the IPF visualization.

WARNING:

MTEX and SAnTex (via Orix) do not necessarily use the same point group symmetry operation conventions. MTEX has different default crystal axes alignments for different crystal systems, while Orix always assumes X || a, Z || c*. Users should verify conventions and expectations before trusting the results.

ipf_colorkey(df, phase=1, crystal_symmetry='D2')#
WARNING:

MTEX and SAnTex (via Orix) do not necessarily use the same point group symmetry operation conventions. MTEX has different default crystal axes alignments for different crystal systems, while Orix always assumes X || a, Z || c*. Users should verify conventions and expectations before trusting the results.

pdf(df, phase=1, crystal_symmetry='D2', random_val=True, uvw=[0, 1, 0], hemisphere='both', sigma=4, axes_labels=['Xs', 'Ys'], figure=None, show_hemisphere_label=None, grid=None, grid_resolution=None, return_figure=None, log=False, colorbar=True, weights=None)#

Calculate the Pole density function (PDF) for a given EBSD dataset and optionally visualize it.

Parameters: - df: pandas DataFrame

The DataFrame containing EBSD (Electron Backscatter Diffraction) data.

  • phase: int, optional

    The phase number for which PDF needs to be calculated (default is 1).

  • crystal_symmetry: str, optional

    The crystal symmetry of the material, e.g., ‘D2’ for cubic symmetry (default is ‘D2’).

  • random_val: bool, optional

    If True, randomly generate orientation values for incomplete data (default is True).

  • miller: list of int, optional

    The Miller indices representing the crystallographic plane to calculate PDF for (default is [1, 0, 0]).

  • projection: str, optional

    The type of projection to use for visualization (default is ‘stereographic’).

  • figure: matplotlib Figure or None, optional

    If provided, the PDF plot will be added to this Figure; otherwise, a new Figure will be created.

  • axes_labels: list of str or None, optional

    Labels for the X and Y axes of the PDF plot (default is None).

  • vector_labels: list of str or None, optional

    Labels for the vectors in the PDF plot (default is None, which results in auto-generated labels).

  • hemisphere: str, upper or lower or both, optional

    Specify the hemisphere for PDF calculation and visualization (default is None).

  • reproject: bool, optional

    If True, reproject data into a specified coordinate system (default is False).

  • show_hemisphere_label: bool or None, optional

    Specify whether to show the hemisphere label on the plot (default is None).

  • grid: bool or None, optional

    Specify whether to display a grid on the PDF plot (default is None).

  • grid_resolution: tuple of float or None, optional

    Resolution of the grid (default is None).

  • figure_kwargs: dict or None, optional

    Additional keyword arguments for configuring the matplotlib Figure (default is None).

  • reproject_scatter_kwargs: dict or None, optional

    Additional keyword arguments for configuring scatter plot during reprojection (default is None).

  • text_kwargs: dict or None, optional

    Additional keyword arguments for configuring text elements in the plot (default is None).

  • return_figure: bool, optional

    If True, return the matplotlib Figure object along with the PDF data (default is False).

Returns: - odf_result: pandas DataFrame

DataFrame containing the calculated Orientation Distribution Function (PDF) values.

  • figure: matplotlib Figure or None

    If return_figure is True, the Figure object containing the PDF plot; otherwise, None.

WARNING:

MTEX and SAnTex (via Orix) do not necessarily use the same point group symmetry operation conventions. MTEX has different default crystal axes alignments for different crystal systems, while Orix always assumes X || a, Z || c*. Users should verify conventions and expectations before trusting the results.

pf(df, phase=1, crystal_symmetry='D2', random_val=True, uvw=[1, 0, 0], hemisphere='both', axes_labels=['Xs', 'Ys'], alpha=0.01, figure=None, vector_labels=None, reproject=False, show_hemisphere_label=None, grid=None, grid_resolution=None, return_figure=None)#

Calculate the Pole Figure (PF) for a given EBSD dataset and optionally visualize it.

Parameters: - df: pandas EBSD DataFrame

The DataFrame containing EBSD (Electron Backscatter Diffraction) data.

  • phase: int, optional

    The phase number for which PF needs to be calculated (default is 1).

  • crystal_symmetry: str, optional

    The crystal symmetry of the material, e.g., ‘D2’ for cubic symmetry (default is ‘D2’).

  • random_val: bool, optional

    If True, randomly generate orientation values for incomplete data (default is True).

  • miller: list of int, optional

    The Miller indices representing the crystallographic plane to calculate PF for (default is [1, 0, 0]).

  • projection: str, optional

    The type of projection to use for visualization (default is ‘stereographic’).

  • figure: matplotlib Figure or None, optional

    If provided, the PF plot will be added to this Figure; otherwise, a new Figure will be created.

  • axes_labels: list of str or None, optional

    Labels for the X and Y axes of the PF plot (default is None).

  • vector_labels: list of str or None, optional

    Labels for the vectors in the PF plot (default is None, which results in auto-generated labels).

  • hemisphere: str, upper or lower or both, optional

    Specify the hemisphere for PF calculation and visualization (default is None).

  • reproject: bool, optional

    If True, reproject data into a specified coordinate system (default is False).

  • show_hemisphere_label: bool or None, optional

    Specify whether to show the hemisphere label on the plot (default is None).

  • grid: bool or None, optional

    Specify whether to display a grid on the PF plot (default is None).

  • grid_resolution: tuple of float or None, optional

    Resolution of the grid (default is None).

  • figure_kwargs: dict or None, optional

    Additional keyword arguments for configuring the matplotlib Figure (default is None).

  • reproject_scatter_kwargs: dict or None, optional

    Additional keyword arguments for configuring scatter plot during reprojection (default is None).

  • text_kwargs: dict or None, optional

    Additional keyword arguments for configuring text elements in the plot (default is None).

  • return_figure: bool, optional

    If True, return the matplotlib Figure object along with the PF data (default is False).

Returns: - pf_result: pandas DataFrame

DataFrame containing the calculated Pole Figure (PF) values.

  • figure: matplotlib Figure or None

    If return_figure is True, the Figure object containing the pf plot; otherwise, None.

WARNING:

MTEX and SAnTex (via Orix) do not necessarily use the same point group symmetry operation conventions. MTEX has different default crystal axes alignments for different crystal systems, while Orix always assumes X || a, Z || c*. Users should verify conventions and expectations before trusting the results.

phases(df_phases=None)#

Retrieves phase percentages.

Parameters:

df_phases (pandas.DataFrame, optional): DataFrame containing phase information. Defaults to None.

Returns:

str: Tabulated representation of phase percentages.

phases_df()#

Retrieves DataFrame containing phase counts and percentages.

Returns:

pandas.DataFrame: DataFrame containing phase counts and percentages.

phases_info()#

Retrieves phase information.

Returns:

pandas.DataFrame: DataFrame containing phase information.

phases_names()#

Retrieves phase names.

Returns:

pandas.DataFrame: DataFrame containing phase names.

plot(data=None, rotation_angle=0, inside_plane=True, mirror=False, save_image=False, image_filename=None, dpi=300, cmap='viridis', legend_location='upper right', phase_colors=None)#
plot_grains(df, color_continuous_scale='viridis', save_name=None, dpi=None)#

Create a 2D scatter plot with phase coloring.

Parameters: - df (DataFrame): The EBSD DataFrame containing the data to plot. - color_continuous_scale (str): The color scale to use for continuous colors, default is viridis. - save_name (str): The name to use when saving the figure as a PNG file. If None, the figure will be displayed but not saved. - dpi (int): The DPI (dots per inch) to use when saving the figure. If None, the default DPI will be used.

Returns: - None

plot_rotate_ebsd(sample_ref=['x2east', 'zOutOfPlane'], ebsd_df=None, keepXY=False)#

Plots the rotated ebsd and returns the rotated ebsd dataframe

Parameters: - sample_ref: sample reference, eg: [“x2east”, “zOutOfPlane”], [“x2west”, “zOutOfPlane”], [“x2north”, “zOutOfPlane”], [“x2south”, “zOutOfPlane”], [“x2east”, “zIntoPlane”], default is [“x2east”, “zOutOfPlane”] - ebsd_df: the ebsd pandas dataframe - keepXY: bool, Specify if you want to keep X and Y constant. Default is False

Returns: - rotated_ebsd_df : rotated ebsd dataframe

rotate_ebsd(ebsd_df, angles, keepXY=True)#

Rotate EBSD with a certain angles

Parameters: - ebsd_df: ebsd pandas dataframe - angles: angles to be rotated (phi1, phi2, phi3), eg: [20, 30, 40] - keepXY: bool, Specify if you want to keep X and Y constant. Default is True

Returns: - Rotated EBSD dataframe

santex.ebsd.melt_tensor module#

santex.ebsd.melt_tensor.calc_melt_tensor()#

Returns the melt stiffness tensor.

Parameters: - None

Returns: - np.ndarray - melt stifness tensor

Reference Lee, A. L., Walker, A. M., Lloyd, G. E., & Torvela, T. (2017). Modeling the impact of melt on seismic properties during mountain building. Geochemistry, Geophysics, Geosystems, 18(3), 1090–1110. https://doi.org/10.1002/2016GC006705

santex.ebsd.odf module#

santex.ebsd.rotateEBSD module#

santex.ebsd.rotateEBSD.apply_custom_rotation_to_dataframe(euler_df, angles)#

Applies a custom rotation to each row of a DataFrame containing Bunge Euler angles.

Args:

euler_df (pd.DataFrame): DataFrame containing Bunge Euler angles. angles (tuple): Custom rotation angles in degrees (alpha, beta, gamma).

Returns:

pd.DataFrame: DataFrame with updated Bunge Euler angles after rotation.

santex.ebsd.rotateEBSD.apply_custom_rotation_to_dataframe_noxy(df, angles)#

Applies a custom rotation to each row of a DataFrame containing Bunge Euler angles, X, and Y coordinates.

Args:

df (pd.DataFrame): DataFrame containing Bunge Euler angles, X, and Y coordinates. angles (tuple): Custom rotation angles in degrees (alpha, beta, gamma).

Returns:

pd.DataFrame: DataFrame with updated Bunge Euler angles, X, and Y coordinates after rotation.

santex.ebsd.rotateEBSD.bunge_euler_rotation(phi1, Phi, phi2, angles)#

Calculates the resultant Bunge Euler angles after applying a custom rotation.

Args:

phi1 (float): Initial Bunge Euler angle phi1 in degrees. Phi (float): Initial Bunge Euler angle Phi in degrees. phi2 (float): Initial Bunge Euler angle phi2 in degrees. angles (tuple): Custom rotation angles in degrees (alpha, beta, gamma).

Returns:

tuple: Resultant Bunge Euler angles (phi1, Phi, phi2) in degrees in the range [0, 360).

santex.ebsd.saveEBSD module#

santex.ebsd.saveEBSD.load_ebsd_df(file_path)#

Load a DataFrame from a file.

santex.ebsd.saveEBSD.load_phase_name(file_path)#

Load a list from a file using pickle.

santex.ebsd.saveEBSD.save_ebsd_df(dataframe, file_path)#

Save a DataFrame to a file.

santex.ebsd.saveEBSD.save_phase_name(lst, file_path)#

Save a list to a file using pickle.

Module contents#