diff --git a/src/sim_recon/__init__.py b/src/sim_recon/__init__.py index eeb3ae1..aaf509f 100644 --- a/src/sim_recon/__init__.py +++ b/src/sim_recon/__init__.py @@ -2,8 +2,13 @@ if __name__ == "__main__": - from .main import sim_reconstruct, sim_psf_to_otf + from .main import sim_reconstruct, sim_psf_to_otf, sim_reconstruct_single - __all__ = ["__version__", "sim_reconstruct", "sim_psf_to_otf"] + __all__ = [ + "__version__", + "sim_reconstruct", + "sim_reconstruct_single", + "sim_psf_to_otf", + ] else: __all__ = ["__version__"] diff --git a/src/sim_recon/main.py b/src/sim_recon/main.py index 7f3c2cf..664c68c 100644 --- a/src/sim_recon/main.py +++ b/src/sim_recon/main.py @@ -10,13 +10,14 @@ ) from .settings import ConfigManager from .otfs import convert_psfs_to_otfs -from .recon import run_reconstructions +from .recon import run_reconstructions, run_single_reconstruction if TYPE_CHECKING: from typing import Any from os import PathLike from pathlib import Path + from multiprocessing.pool import Pool from .recon import OutputFileTypes @@ -101,9 +102,9 @@ def sim_reconstruct( overwrite: bool = False, cleanup: bool = True, stitch_channels: bool = True, - parallel_process: bool = False, allow_missing_channels: bool = False, output_file_type: OutputFileTypes = "dv", + parallel_process: bool = False, **recon_kwargs: Any, ) -> None: """ @@ -118,7 +119,7 @@ def sim_reconstruct( output_directory : str | PathLike[str] | None, optional Directory to save reconstructions in (reconstructions will be saved with the data files if not specified), by default None processing_directory : str | PathLike[str] | None, optional - The directory in which the temporary files will be stored for processing (otherwise the output directory will be used), by default None + The directory in which subdirectories of temporary files will be stored for processing (otherwise the output directory will be used), by default None otf_overrides : dict[int, Path] | None, optional A dictionary with emission wavelengths in nm as keys and paths to OTF files as values (these override configured OTFs), by default None overwrite : bool, optional @@ -144,8 +145,71 @@ def sim_reconstruct( overwrite=overwrite, cleanup=cleanup, stitch_channels=stitch_channels, + allow_partial=allow_missing_channels, + output_file_type=output_file_type, parallel_process=parallel_process, + **recon_kwargs, + ) + + +def sim_reconstruct_single( + sim_data_path: str | PathLike[str], + config_path: str | PathLike[str] | None = None, + output_directory: str | PathLike[str] | None = None, + processing_directory: str | PathLike[str] | None = None, + otf_overrides: dict[int, Path] | None = None, + overwrite: bool = False, + cleanup: bool = True, + stitch_channels: bool = True, + allow_missing_channels: bool = False, + output_file_type: OutputFileTypes = "dv", + multiprocessing_pool: Pool | None = None, + parallel_process: bool = False, + **recon_kwargs: Any, +) -> None: + """ + Top level function for reconstructing SIM data + + Parameters + ---------- + sim_data_path : str | PathLike[str] + Path to SIM data files (DV expected) + config_path : str | PathLike[str] | None, optional + Path of the top level config file, by default None + output_directory : str | PathLike[str] | None, optional + Directory to save reconstructions in (reconstructions will be saved with the data files if not specified), by default None + processing_directory : str | PathLike[str] | None, optional + The directory in which the temporary files will be stored for processing (otherwise the output directory will be used), by default None + otf_overrides : dict[int, Path] | None, optional + A dictionary with emission wavelengths in nm as keys and paths to OTF files as values (these override configured OTFs), by default None + overwrite : bool, optional + Overwrite files if they already exist, by default False + cleanup : bool, optional + Clean up temporary directory and files after reconstruction, by default True + stitch_channels : bool, optional + Stitch channels back together after processing (otherwise output will be a separate DV per channel), by default True + allow_missing_channels: bool, optional + Attempt reconstruction of other channels in a multi-channel file if one or more are not configured, by default False + output_file_type: Literal["dv", "tiff"], optional + File type that output images will be saved as, by default "dv" + multiprocessing_pool : Pool | None, optional + Multiprocessing pool to run cudasirecon in (`maxtasksperchild=1` is recommended to avoid crashes), by default None + parallel_process : bool, optional + Run reconstructions in 2 processes concurrently (ignored if multiprocessing_pool is supplied), by default False + """ + conf = load_configs(config_path, otf_overrides=otf_overrides) + logger.info("Starting reconstruction of %s", sim_data_path) + run_single_reconstruction( + conf, + sim_data_path, + output_directory=output_directory, + processing_directory=processing_directory, + overwrite=overwrite, + cleanup=cleanup, + stitch_channels=stitch_channels, allow_partial=allow_missing_channels, output_file_type=output_file_type, + multiprocessing_pool=multiprocessing_pool, + parallel_process=parallel_process, **recon_kwargs, )