File System Manager
This module provides a class for managing file system operations.
FileSystemManager
- class ezstitcher.core.file_system_manager.FileSystemManager
Manages file system operations for ezstitcher. Abstracts away direct file system interactions for improved testability.
- default_extensions: list = ['.tif', '.TIF', '.tiff', '.TIFF', '.jpg', '.JPG', '.jpeg', '.JPEG', '.png', '.PNG']
Default file extensions for image files.
- static ensure_directory(directory)
Ensure a directory exists, creating it if necessary.
- Parameters:
directory (str or Path) – Directory path to ensure exists
- Returns:
Path object for the directory
- Return type:
Path
- static list_image_files(directory, extensions=None, recursive=False, flatten=False)
List all image files in a directory with specified extensions.
- Parameters:
- Returns:
List of Path objects for image files
- Return type:
- static load_image(file_path)
Load an image. Only 2D images are supported.
- Parameters:
file_path (str or Path) – Path to the image file
- Returns:
2D image or None if loading fails
- Return type:
numpy.ndarray or None
- Raises:
ValueError: If the image is 3D (not supported)
- static save_image(file_path, image, compression=None)
Save an image to disk.
- Parameters:
file_path (str or Path) – Path to save the image
image (numpy.ndarray) – Image to save
compression (str, optional) – Compression method
- Returns:
True if successful, False otherwise
- Return type:
- static copy_file(source_path, dest_path)
Copy a file from source to destination, preserving metadata.
- static remove_directory(directory_path, recursive=True)
Remove a directory and optionally all its contents.
- static clean_temp_folders(parent_dir, base_name, keep_suffixes=None)
Clean up temporary folders created during processing.
- static create_output_directories(plate_path, suffixes)
Create output directories for a plate.
- static find_file_recursive(directory, filename)
Recursively search for a file by name in a directory and its subdirectories. Returns the first instance found.
- static rename_files_with_consistent_padding(directory, parser=None, width=3, force_suffixes=False)
Rename files in a directory to have consistent site number and Z-index padding. Optionally force the addition of missing optional suffixes (site, channel, z-index).
- Parameters:
- Returns:
Dictionary mapping original filenames to new filenames
- Return type:
- static find_z_stack_dirs(root_dir, pattern='ZStep_\\d+', recursive=True)
Find directories matching a pattern (default: ZStep_#) recursively.
- Parameters:
- Returns:
List of (z_index, directory) tuples where z_index is extracted from the pattern
- Return type:
- static find_image_directory(plate_folder, extensions=None)
Find the directory where images are actually located.
Handles both cases: 1. Images directly in a folder (returns that folder) 2. Images split across Z-step folders (returns parent of Z-step folders)
- static detect_zstack_folders(plate_folder, pattern=None)
Detect Z-stack folders in a plate folder.
- static organize_zstack_folders(plate_folder, filename_parser=None)
Organize Z-stack folders by moving files to the plate folder with proper naming.
- static cleanup_processed_files(processed_files, output_files)
Clean up processed files after they’ve been used to create output files.