kemstem.atomic

Submodules

kemstem.atomic.columnfind module

kemstem.atomic.columnfind.find_columns(image, distance=10, threshold=0.1)

Find column positions in an image with skimage.feature.peak_local_max.

Parameters:
  • image (ndarray) – Real valued 2D image.

  • distance (int, optional) – Minimum distance between peaks (default is 10), passed to peak_local_max.

  • threshold (float, optional) – Intensity used for thresholding (default is 0.1).

Returns:

Array of peak positions (N, 2).

Return type:

ndarray

Notes

This function normalizes the input image, applies thresholding, and uses skimage.feature.peak_local_max for peak detection. Implementation is based off stemtool.

kemstem.atomic.columnfind.refine_columns(image, columns0, window_dimension=5, remove_unfit=True, verbose=True)

Refine column positions with 2D Gaussian fits. Currently wraps util.general.gaussian_fit_peaks

kemstem.atomic.neighborhood module

kemstem.atomic.neighborhood.cluster_neighbors(neighborhood, n_clusters=40)

Cluster the neighborhood points using sklearn.cluster.KMeans.

Parameters:
  • neighborhood (ndarray, shape (n,2)) – Vectors to local neighborhoods (pair correlation function), (y,x).

  • n_clusters (int, optional) – Number of clusters to form (default is 40).

Returns:

Array of cluster centers (n_clusters, 2).

Return type:

ndarray

kemstem.atomic.neighborhood.get_connected_columns(columns, origin, vector, tolerance, bidirectional=True)

Find a chain of columns connected by a vector within a tolerance.

Starting from an origin point, iteratively finds the nearest column in the direction of the specified vector. Can search in both directions.

Parameters:
  • columns (ndarray, shape (n,2)) – Array of all column positions (y,x).

  • origin (ndarray, shape (2,)) – Starting point coordinates (y,x).

  • vector (ndarray, shape (2,)) – Vector defining the direction to search for connected columns.

  • tolerance (float) – Maximum allowed distance between expected and actual column positions.

  • bidirectional (bool, optional) – If True, search in both positive and negative vector directions (default is True).

Returns:

  • ndarray: Array of connected column positions

  • int: Index of the origin point in the chain

Return type:

tuple

kemstem.atomic.neighborhood.get_neighborhood(columns, centerpoints, k=20)

Get the neighborhoods of columns around specified center points.

Parameters:
  • columns (ndarray, shape (n,2)) – Array of all column positions (y,x).

  • centerpoints (ndarray, shape (m,2)) – Array of center point positions (y,x).

  • k (int, optional) – Number of nearest neighbors to consider (default is 20).

Returns:

Array of vectors from neighbors to center points (m*k, 2).

Return type:

ndarray

kemstem.atomic.neighborhood.get_vector_to_neighbors(columns, origins, guess_vector, threshold=5, handle_nan=False)

Find the vectors from origin points to the column closest to the guess_vector.

E.g., for an origin o, column c and guess_vector g, will return c-o for the c nearest to o+g.

Parameters:
  • columns (ndarray, shape (n,2)) – Coordinates of columns of interest (y,x)

  • origins (ndarray, shape (n,2)) – Coordinates of origin points (y,x)

  • guess_vector (ndarray) – Guess vector from which the nearest column is found (2,).

  • threshold (float, optional) – Maximum norm of found vs. guessed vector (default is 5).

Returns:

Array of vectors from origins to their nearest neighbors (M, 2). NaN values indicate no neighbor found within the threshold.

Return type:

ndarray

kemstem.atomic.neighborhood.index_lattice(columns, origin, v1, v2, tolerance=1, max_n1=20, max_n2=20, cumulative_adjust=False)

Index atomic columns in a 2D lattice defined by two vectors.

Maps columns to lattice coordinates defined by two basis vectors v1 and v2, starting from an origin point. Can either use fixed vectors or adjust them cumulatively along chains of atoms.

Parameters:
  • columns (ndarray, shape (n,2)) – Array of all column positions (y,x).

  • origin (ndarray, shape (2,)) – Origin point of the lattice (y,x).

  • v1 (ndarray, shape (2,)) – Basis vectors defining the lattice.

  • v2 (ndarray, shape (2,)) – Basis vectors defining the lattice.

  • tolerance (float, optional) – Maximum allowed distance for matching columns to lattice points (default is 1).

  • max_n1 (int, optional) – Maximum number of lattice points to consider in each direction (default is 20).

  • max_n2 (int, optional) – Maximum number of lattice points to consider in each direction (default is 20).

  • cumulative_adjust (bool, optional) – If True, adjust vectors by following chains of atoms. If False, use fixed vectors from the origin (default is False).

Returns:

If cumulative_adjust is True:
  • ndarray: Array of lattice indices

  • ndarray: Array of indexed column positions

If cumulative_adjust is False:
  • ndarray: Array of lattice indices

  • ndarray: Array of indexed column positions

  • ndarray: Array of ideal lattice positions

Return type:

tuple

kemstem.atomic.periodicdistortion module

kemstem.atomic.periodicdistortion.measure_displacements(reference_columns, distorted_columns, threshold=2)

Measure displacements between reference and distorted column positions.

Parameters:
  • reference_columns (ndarray, shape (n,2)) – Array of reference column positions.

  • distorted_columns (ndarray, shape (n,2)) – Array of distorted column positions.

  • threshold (float, optional) – Maximum distance to consider a match between reference and distorted columns (default is 2).

Returns:

disps – Array of displacement vectors. NaN values indicate no match found within the threshold.

Return type:

ndarray, shape (n,2)

Notes

This function finds the nearest distorted column for each reference column and calculates the displacement vector. Displacements larger than the threshold are set to NaN.

Module contents