autoemx.core.em_runtime.sample_finder module
Electron Microscope Sample Finder module.
Provides utilities for locating and managing samples within the EM, particularly for detecting carbon tape position and dimensions.
Classes
- EM_Sample_Finder
Utilities for locating samples and detecting carbon tape.
Created on 2026 @author: Andrea
- class autoemx.core.em_runtime.sample_finder.EM_Sample_Finder(microscope_ID: str, center_pos: ndarray | tuple | list, sample_half_width_mm: float, substrate_width_mm: float, development_mode: bool | None = False, results_dir: str | None = None, verbose: bool = False)[source]
Bases:
objectClass for locating and managing samples in an electron microscope (EM).
Provides methods for detecting sample features (such as the center and size of a C tape) using the microscope’s navigation camera.
- Variables:
microscope_ID (str) – Identifier for the target microscope.
center_pos (np.ndarray) – Initial center position of sample as [x, y] coordinates in mm.
results_dir (Optional[str]) – Directory path to save results, or None if not set.
verbose (bool) – If True, enables detailed debug output.
development_mode (bool) – If True, enables offline testing without real-time acquisition.
Example
>>> import numpy as np >>> sample_center = np.array([0.0, 0.0]) >>> finder = EM_Sample_Finder( ... microscope_ID='MySEM', ... center_pos=sample_center, ... sample_half_width_mm=3, ... substrate_width_mm=12, ... results_dir='./results', ... verbose=True ... ) >>> ctape_result = finder.detect_Ctape() >>> if ctape_result is not None: ... center_pos, sample_hw_mm = ctape_result ... print("C tape center (mm):", center_pos) ... print("C tape half-width (mm):", sample_hw_mm)
Notes
The navigation camera image can be provided directly (for offline testing) or acquired live from the microscope.
For successful detection, the microscope calibration file must include: ‘navcam_im_w_mm’, ‘navcam_x_offset’, ‘navcam_y_offset’.
- detect_Ctape(navcam_im: ndarray | None = None) Tuple[ndarray, float] | None[source]
Detect the effective center position and radius of the C tape.
Uses the provided navigation camera image or acquires it from the microscope. Applies edge detection and circle fitting to locate the tape.
- Parameters:
navcam_im (Optional[np.ndarray]) – Navigation camera image. If None, acquires from microscope.
- Returns:
Tuple of (center_pos, sample_hw_mm) if detection successful, else None.
- Return type:
Optional[Tuple[np.ndarray, float]]