qem.refine

Functions

calculate_center_of_mass(arr)

Find the center of mass of a NumPy array.

fit_gaussian(x0, y0, sigma_x, sigma_y, ...)

qem.refine.calculate_center_of_mass(arr)[source]

Find the center of mass of a NumPy array.

Find the center of mass of a single 2D array, or a list (or multidimensional array) of 2D arrays.

Parameters:

arr (Numpy 2D Array (or list/nd-array of such))

Returns:

cy, cx (array of floats (or nd-array of floats)) – Giving centre coordinates with sub-pixel accuracy

Examples

>>> import atomap.atom_finding_refining as afr
>>> arr = np.random.randint(100, size=(10, 10))
>>> data = afr.calculate_center_of_mass(arr)

Notes

This is a much simpler center of mass approach than the one from scipy. Gotten from stackoverflow: https://stackoverflow.com/questions/37519238/python-find-center-of-object-in-an-image

qem.refine.gauss2d(xy_meshgrid: numpy.ndarray, amplitude: float, x0: float, y0: float, sigma_x: float, sigma_y: float, theta: float, offset: float) numpy.ndarray

2D Gaussian function for fitting.

Parameters:
  • xy_meshgrid (tuple of np.ndarray) – Tuple containing the X and Y meshgrids

  • amplitude (float) – Peak amplitude

  • x0 (float) – Peak center coordinates

  • y0 (float) – Peak center coordinates

  • sigma_x (float) – Standard deviations in x and y directions

  • sigma_y (float) – Standard deviations in x and y directions

  • theta (float) – Rotation angle in radians

  • offset (float) – Background offset

Returns:

np.ndarray – 2D Gaussian evaluated on the meshgrid

qem.refine.fit_gaussian(x0, y0, sigma_x, sigma_y, theta, offset, data, plot=False, verbose=True)[source]