Microscope Interfaces
This module provides abstract base classes for handling microscope-specific functionality, including filename parsing and metadata handling.
For conceptual explanation, see Architecture Overview. For information about extending EZStitcher with support for new microscope types, see Adding a New Microscope Type in the Extending EZStitcher guide.
MicroscopeHandler
- class ezstitcher.core.microscope_interfaces.MicroscopeHandler(plate_folder=None, parser=None, metadata_handler=None, microscope_type='auto')
Composed class for handling microscope-specific functionality.
- Parameters:
plate_folder (str or Path, optional) – Path to the plate folder
parser (FilenameParser, optional) – Parser for microscopy filenames
metadata_handler (MetadataHandler, optional) – Handler for microscope metadata
microscope_type (str, optional) – Type of microscope (‘auto’, ‘ImageXpress’, ‘OperaPhenix’, etc.)
- parse_filename(filename)
Delegate to parser.
- construct_filename(well, site=None, channel=None, z_index=None, extension='.tif', site_padding=3, z_padding=3)
Delegate to parser.
- Parameters:
well (str) – Well ID (e.g., ‘A01’)
site (int or str, optional) – Site number or placeholder string (e.g., ‘{iii}’)
channel (int, optional) – Channel/wavelength number
z_index (int or str, optional) – Z-index or placeholder string (e.g., ‘{zzz}’)
extension (str, optional) – File extension
site_padding (int, optional) – Width to pad site numbers to
z_padding (int, optional) – Width to pad Z-index numbers to
- Returns:
Constructed filename
- Return type:
- auto_detect_patterns(folder_path, well_filter=None, extensions=None, group_by='channel', variable_components=None)
Delegate to parser.
- Parameters:
folder_path (str or Path) – Path to the folder
well_filter (list, optional) – Optional list of wells to include
extensions (list, optional) – Optional list of file extensions to include
group_by (str, optional) – How to group patterns (‘channel’ or ‘z_index’)
variable_components (list, optional) – List of components to make variable (e.g., [‘site’, ‘z_index’])
- Returns:
Dictionary mapping wells to patterns grouped by channel or z-index
- Return type:
- path_list_from_pattern(directory, pattern)
Delegate to parser.
- find_metadata_file(plate_path)
Delegate to metadata handler.
- Parameters:
plate_path (str or Path) – Path to the plate folder
- Returns:
Path to the metadata file, or None if not found
- Return type:
Path or None
- get_grid_dimensions(plate_path)
Delegate to metadata handler.
FilenameParser
- class ezstitcher.core.microscope_interfaces.FilenameParser
Abstract base class for parsing microscopy image filenames.
- FILENAME_COMPONENTS: list = ['well', 'site', 'channel', 'z_index', 'extension']
List of components that can be extracted from filenames.
- classmethod can_parse(cls, filename)
Check if this parser can parse the given filename.
- parse_filename(filename)
Parse a microscopy image filename to extract all components.
- construct_filename(well, site=None, channel=None, z_index=None, extension='.tif', site_padding=3, z_padding=3)
Construct a filename from components.
- Parameters:
well (str) – Well ID (e.g., ‘A01’)
site (int or str, optional) – Site number or placeholder string (e.g., ‘{iii}’)
channel (int, optional) – Channel/wavelength number
z_index (int or str, optional) – Z-index or placeholder string (e.g., ‘{zzz}’)
extension (str, optional) – File extension
site_padding (int, optional) – Width to pad site numbers to
z_padding (int, optional) – Width to pad Z-index numbers to
- Returns:
Constructed filename
- Return type:
- path_list_from_pattern(directory, pattern)
Get a list of filenames matching a pattern in a directory.
- group_patterns_by_component(patterns, component='channel', default_value='1')
Group patterns by a specific component (channel, z_index, site, well, etc.)
- Parameters:
- Returns:
Dictionary mapping component values to patterns
- Return type:
- auto_detect_patterns(folder_path, well_filter=None, extensions=None, group_by='channel', variable_components=None)
Automatically detect image patterns in a folder.
- Parameters:
folder_path (str or Path) – Path to the folder
well_filter (list, optional) – Optional list of wells to include
extensions (list, optional) – Optional list of file extensions to include
group_by (str, optional) – How to group patterns (‘channel’ or ‘z_index’)
variable_components (list, optional) – List of components to make variable (e.g., [‘site’, ‘z_index’])
- Returns:
Dictionary mapping wells to patterns grouped by channel or z-index
- Return type:
MetadataHandler
- class ezstitcher.core.microscope_interfaces.MetadataHandler
Abstract base class for handling microscope metadata.
- find_metadata_file(plate_path)
Find the metadata file for a plate.
- Parameters:
plate_path (str or Path) – Path to the plate folder
- Returns:
Path to the metadata file, or None if not found
- Return type:
Path or None
- get_grid_dimensions(plate_path)
Get grid dimensions for stitching from metadata.
Functions
- ezstitcher.core.microscope_interfaces.create_microscope_handler(microscope_type='auto', **kwargs)
Create the appropriate microscope handler.
- Parameters:
- Returns:
Microscope handler
- Return type: