profile module

profile.py

Functions for extracting and fitting a Gaussian profile sparse electron datasets.

profile.extract_3x3_patches(original_frames, processed_frames)[source]

Extract 3x3 patches from original frames based on hits identified in processed frames.

Parameters:
  • original_frames (ndarray) – Array of original frames (non-baseline-subtracted, non-thresholded).

  • processed_frames (ndarray) – Array of processed frames (baseline-subtracted and thresholded).

Returns:

Array of 3x3 patches centered around identified hits.

Return type:

ndarray

profile.gaussian_profile(file_path, nframes, baseline, th_single_elec, plot_results=True)[source]

Process frames to extract the average 3x3 patch of electron hits, fit it to a Gaussian, and return the optimized Gaussian parameters and patches.

Parameters:
  • file_path (str) – Path to the HDF5 file containing the frames.

  • nframes (int) – Number of frames to process.

  • baseline (float) – Baseline value to subtract from frames.

  • th_single_elec (float) – Threshold for identifying single electron hits.

  • plot_results (bool, optional) – Plot the original average patch, the optimized Gaussian, and their difference. (default: True).

Returns:

  • ndarray: Average 3x3 patch from identified hits.

  • ndarray: The 3x3 Gaussian patch after fitting to the Gaussian model.

  • float: Optimized Gaussian amplitude (A_opt).

  • float: Optimized Gaussian standard deviation (sigma_opt).

Return type:

tuple

profile.randomized_scan_order(nrows, ncols)[source]

Generate a randomized order of pixel indices for scanning.

Parameters:
  • nrows (int) – Number of rows in the frame.

  • ncols (int) – Number of columns in the frame.

Returns:

List of (row, col) tuples in randomized order, excluding edges.

Return type:

list