polyTEM.crystal_peaks.crystal_stack.CrystalStack

class polyTEM.crystal_peaks.crystal_stack.CrystalStack(img, datacube, hkl=100, type_='Donor', peak_threshold_function=<function _threshold_1sigma>)

Bases: object

FFT peaks from HRTEM Image

Variables:
  • q (float) – 1/A

  • resolution (float) – nm/pxel

  • outdir (str) – save directory

  • hkl (int) – 100, 010, 001 for lamellar, pi-pi, or backbone information

  • datacube (np.ndarray) – sliding fft scan intensities

  • type (str) – default ‘Donor’

  • sparse_peaks_mat (sparse) – one-hot matrix of location and orientation

  • conditional_probability (ConditionalProbability) – class containing Probability of orientation difference given distance

  • ks_distmat (array) – Kolmogorov-Smirnov distance matrix

  • ks_dlist (list) – Kolmogorov-Smirnov D-value list

  • ks_thetas (list) – List of theta with max difference for each distance

  • peaks_df (pd.Dataframe) – DataFrame containing peak information

  • _threshold_function (function) – Function for thresholding peaks (default: _threshold_1sigma)

  • _plot_frequency (int) – Frequency of plotting (default: 20000)

  • _peak_width_threshold (int) – Threshold for peak width (default: 5)

__init__(img, datacube, hkl=100, type_='Donor', peak_threshold_function=<function _threshold_1sigma>)

Methods

__init__(img, datacube[, hkl, type_, ...])

apply_mask(mask[, inplace])

Apply (x,y) mask

compare_to_random([reference, rand_stack, plot])

conditional_prob([threads, num_slices, ...])

Calculate and/or plot Conditional Probability of misorientation given spatial distance R

get_clusters([min_cluster_size, ...])

Cluster fft peaks to find crystalline domains using HDBSCAN

get_orientation_correlation_length([...])

Calculates the orientation correlation length given by the exponential decay fit of the expected value <2cos^2(Delta heta(r))-1>

load(filename)

Load saved crystalstack

peaks_from_datacube([save, ...])

Find fft peaks in datacube and records peak location,

plot_clusters([confidence_threshold, ...])

Attention

DEPRECATE IN THE FUTURE. PREFERENCE FOR spatial.plot_polygons_df

plot_flow_field([perpendicular, ...])

Plot Flow Fields

plot_overlap_angles()

random(n, dim, img)

Generates a crystal stack with randomized peaks matrix, effectively generates a crystal stack with random orientation

save([prefix, json])

param prefix:

save file "[prefix]crystal_stack"

apply_mask(mask, inplace=True)

Apply (x,y) mask

conditional_prob(threads=8, num_slices=16, calculate=False, plot=True, **kwargs)

Calculate and/or plot Conditional Probability of misorientation given spatial distance R

Parameters:
  • threads – int, number of multiprocessing cores to use

  • plot – bool, whether to plot

  • **kwargs – optional plotting keyword-arguments

  • plot_color – string

  • plot_dist_max – int

  • plot_th_max – int

get_clusters(min_cluster_size=10, min_samples=5, cluster_selection_epsilon=10, match_reference_implementation=False, plot=True)

Cluster fft peaks to find crystalline domains using HDBSCAN

Saves cluster information as peaks_df attribute. see HDBSCAN documentation for more description on parameters.

Parameters:
  • min_cluster_size (int) –

  • min_samples (int) – in order to be considered a cluster

  • cluster_selection_epsilon

  • match_reference_implementation (bool) –

  • plot (bool) –

get_orientation_correlation_length(min_dist=0, max_dist=20, plot=True)

Calculates the orientation correlation length given by the exponential decay fit of the expected value <2cos^2(Delta heta(r))-1>

Returns:

Length in nanometers model (named tuple): LinRegressModel(model.slope,model.intercept,model.rvalue)

Return type:

Ld (float)

classmethod load(filename)

Load saved crystalstack

Parameters:

filename (str) – ends in extension .str or .pkl

Returns:

CrystalStack object

peaks_from_datacube(save=False, plot_overlap_angles=True, show_figures=True, verbose=False, plot_freq=100)

Find fft peaks in datacube and records peak location,

saved to CrystalStack.sparse_peaks_mat as a sparse one-hot matrix of (x,y,theta)

plot_clusters(confidence_threshold=0.75, probabilities=False, orientations=True, color=None)

Attention

DEPRECATE IN THE FUTURE. PREFERENCE FOR spatial.plot_polygons_df

plot_flow_field(perpendicular=True, seed_density=2, min_length=5, bend_tolerance=5, curve_resolution=1, preview_sparsity=20, line_spacing=1, line_width_scale=2, spacing_resolution=5, angle_spacing_degrees=10, max_overlap_fraction=0.5, inverse_colors=True, contrast=1, gamma=0.1, show_preview=False, show_figures=True, save_results=False, output_folder='')

Plot Flow Fields

classmethod random(n, dim, img)

Generates a crystal stack with randomized peaks matrix, effectively generates a crystal stack with random orientation

save(prefix='', json=False)
Parameters:
  • prefix (str) – save file “[prefix]crystal_stack”

  • json (bool) – if True, save as .json, else save as .pkl