erlab.analysis.mesh

Mesh analysis and removal utilities.

This module provides functions to detect and remove periodic mesh patterns from ARPES data acquired in fixed mode, using an experimental Fourier-based approach.

Functions

auto_correct_curvature(darr[, poly_deg])

Automatically correct curvature in the energy axis of ARPES data.

find_peaks(arr, *[, bins, n_peaks, ...])

Find peaks in the FFT log magnitude image.

higher_order_peaks(first_order, order, shape, *)

Generate peaks up to nth order from two first-order basis peaks.

pad_and_taper(arr, n)

Pad the input array and apply edge tapering using a Tukey window.

remove_mesh(darr, *[, first_order_peaks, ...])

Remove mesh patterns from ARPES data using notch filtering in the FFT domain.

unpad(arr, n)

Remove padding from the input array.

erlab.analysis.mesh.auto_correct_curvature(darr, poly_deg=4)[source]

Automatically correct curvature in the energy axis of ARPES data.

Some analyzers like the Scienta DA30L optionally outputs data with software corrected Fermi edge compensating for the straight analyzer slit. This also warps the mesh pattern and blurs the peaks in the FFT image, making mesh removal difficult. This function estimates the curvature by finding the energy positions where the derivative of the intensity profile changes sign along the angular axis, and fits a polynomial to this profile. The data is then shifted back to undo the effect. Then, the data is trimmed to remove edge artifacts, and padded back with edge values to the original size.

This has only been tested on data produced by the DA30L analyzer.

Parameters:
  • darr (DataArray) – Input DataArray. Must be 2D with ‘alpha’ and ‘eV’ dimensions.

  • poly_deg (int, default: 4) – Degree of the polynomial to fit to the curvature profile. By default 4.

Returns:

  • shift_arr (xr.DataArray) – Array of shifts applied to each angular position to correct the curvature.

  • corrected (xr.DataArray) – Curvature-corrected DataArray.

Return type:

tuple[DataArray, DataArray]

erlab.analysis.mesh.find_peaks(arr, *, bins=2, n_peaks=2, min_distance=None, plot=False)[source]

Find peaks in the FFT log magnitude image.

Selects the upper half of the FFT magnitude image, downsamples it by the specified binning factor, and applies a local maximum filter to find the peaks. The detected peak coordinates are then mapped back to the original image resolution.

Parameters:
  • arr (ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]) – 2D array-like input data that corresponds to the FFT log magnitude.

  • bins (int, default: 2) – Binning factor to pre-bin the image prior to peak finding.

  • n_peaks (int, default: 2) – Number of peaks to find (excluding the center).

  • min_distance (int | None, default: None) – Minimum distance between peaks. If None, defaults to 40 // bins.

  • plot (bool, default: False) – Whether to plot the detected peaks on the input data.

Returns:

peaks_array (np.ndarray of shape (n_peaks + 1, 2)) – Array of the coordinates of the detected peaks, including the center at index 0. The coordinates are in (row, column) format, and are ordered by their distance from the center.

Return type:

ndarray[tuple[Any, …], dtype[int64]]

erlab.analysis.mesh.higher_order_peaks(first_order, order, shape, *, only_upper=True, include_center=True)[source]

Generate peaks up to nth order from two first-order basis peaks.

Parameters:
  • first_order (array-like of shape (3, 2)) – Array of points, where first_order[0] is the center, and first_order[1] and first_order[2] are the two first-order peaks.

  • order (int) – Up to which order to generate peaks.

  • shape (tuple[int, int]) – Shape of the image to constrain the peaks within.

  • only_upper (bool, default: True) – Whether to only generate peaks in the upper half of the image. Since the FFT image is Hermitian, the lower half is redundant.

  • include_center (bool, default: True) – Whether to include the center point.

Returns:

peaks (np.ndarray of shape (M, 2), dtype=int) – Array of generated peak coordinates. M = 2 * order * (order + 1) + (3 if include_center else 2)

Return type:

ndarray[tuple[Any, …], dtype[int64]]

erlab.analysis.mesh.pad_and_taper(arr, n)[source]

Pad the input array and apply edge tapering using a Tukey window.

Parameters:
  • arr (np.ndarray) – 2D input array to be padded and tapered.

  • n (int) – Number of pixels to pad around the array.

Returns:

padded_tapered (np.ndarray) – Padded and tapered array.

Return type:

ndarray[tuple[Any, …], dtype[_ScalarT]]

erlab.analysis.mesh.remove_mesh(darr, *, first_order_peaks=None, order=3, n_pad=90, roi_hw=25, k=0.5, feather=3.0, undo_edge_correction=False, full_output=False, method='constant')[source]

Remove mesh patterns from ARPES data using notch filtering in the FFT domain.

This function identifies mesh patterns in the FFT log-magnitude of the input data, creates notch filters to suppress these patterns, and applies the filters to remove the mesh from the data.

This method is experimental and may not work perfectly for all cases.

Parameters:
  • darr (DataArray) – Input DataArray with ‘alpha’ and ‘eV’ dimensions. All dimensions other than these will be averaged over before extracting the mesh. The corrected data will retain all original dimensions.

  • first_order_peaks (Iterable[Iterable[int]] | None, default: None) – Coordinates of the two first-order mesh peaks in (row, column) format. If None, auto-detection will be performed. There should be three rows, where the first row is the center index of the FFT image, and the next two rows are the first-order peaks.

  • order (int, default: 3) – Up to which order of mesh peaks to remove.

  • n_pad (int, default: 90) – Number of pixels to pad around the image before FFT to reduce edge artifacts. Edge tapering is also applied.

  • roi_hw (int, default: 25) – Half-width of the region of interest around each peak for mask creation.

  • k (float, default: 0.5) – Thresholding parameter for blob extraction around each peak. Higher values result in smaller blobs.

  • feather (float, default: 3.0) – Amount of feathering to apply to the notch masks. Higher values result in smoother masks, which can help reduce ringing artifacts, but may also leave some mesh residuals.

  • undo_edge_correction (bool, default: False) – Whether to automatically correct curvature in the energy axis before mesh removal. This is useful for data from analyzers that apply software edge correction, which can warp the mesh pattern. Currently only tested with Scienta DA30L data.

  • full_output (bool, default: False) – Whether to return additional diagnostic outputs. See Returns section.

  • method (Literal['constant', 'gaussian', 'circular'], default: "constant") –

    Method for creating the notch masks. Options are:

    • ”constant”: Simple binary notch (hard cut with feathering).

    • ”gaussian”: Gaussian-shaped notch fitted to the blob shape.

    • ”circular”: Circular notch with radius based on blob size.

    It is recommended to use “constant” for most cases. Needs more testing.

Returns:

  • corrected (xr.DataArray) – Mesh-corrected DataArray with the same shape as the input.

  • mesh (xr.DataArray) – Extracted mesh DataArray with the same shape as the input.

  • shift_arr (xr.DataArray) – Array of shifts applied to correct curvature. (Returned when full_output is True.)

  • log_magnitude (np.ndarray) – Log-magnitude of the FFT before mesh removal. (Returned when full_output is True.)

  • log_magnitude_corr (np.ndarray) – Log-magnitude of the FFT after mesh removal. (Returned when full_output is True.)

  • peaks (np.ndarray) – Coordinates of all detected mesh peaks used for notch creation. Note that since the FFT image is Hermitian, to get the full set of peaks, one needs to mirror these coordinates about the center. (Returned when full_output is True.)

  • mask (np.ndarray) – Final combined notch mask applied in the FFT domain. (Returned when full_output is True.)

Return type:

tuple[DataArray, DataArray] | tuple[DataArray, DataArray, DataArray | None, ndarray[tuple[Any, …], dtype[_ScalarT]], ndarray[tuple[Any, …], dtype[_ScalarT]], ndarray[tuple[Any, …], dtype[_ScalarT]], ndarray[tuple[Any, …], dtype[_ScalarT]]]

erlab.analysis.mesh.unpad(arr, n)[source]

Remove padding from the input array.

Parameters:
  • arr (np.ndarray) – 2D input array to be unpadded.

  • n (int) – Number of pixels to remove from each side.

Returns:

unpadded (np.ndarray) – Unpadded array.

Return type:

ndarray[tuple[Any, …], dtype[_ScalarT]]