Coverage for ezstitcher/ez/utils.py: 42%

19 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2025-04-30 13:20 +0000

1""" 

2Utility functions for the EZ module. 

3 

4This module provides helper functions for the EZ module. 

5""" 

6 

7from pathlib import Path 

8from typing import List, Optional, Union, Dict, Any 

9 

10def detect_wells(plate_path: Union[str, Path]) -> List[str]: 

11 """ 

12 Detect available wells in a plate. 

13  

14 Args: 

15 plate_path: Path to the plate folder 

16  

17 Returns: 

18 List[str]: List of well identifiers 

19 """ 

20 # Implementation using microscope handler 

21 from ezstitcher.core.pipeline_orchestrator import PipelineOrchestrator 

22 orchestrator = PipelineOrchestrator(plate_path=plate_path) 

23 return orchestrator._get_wells_to_process() 

24 

25def suggest_channel_weights(plate_path: Union[str, Path]) -> Optional[List[float]]: 

26 """ 

27 Suggest channel weights based on plate content. 

28  

29 Args: 

30 plate_path: Path to the plate folder 

31  

32 Returns: 

33 List[float] or None: Suggested channel weights 

34 """ 

35 # Implementation using EZStitcher's detection 

36 from .core import EZStitcher 

37 stitcher = EZStitcher(plate_path) 

38 return stitcher.channel_weights 

39 

40def create_config(input_path: Union[str, Path], **kwargs) -> Dict[str, Any]: 

41 """ 

42 Create a configuration dictionary for stitching based on input data. 

43  

44 Analyzes the input data and suggests appropriate configuration. 

45  

46 Args: 

47 input_path: Path to the plate folder 

48 **kwargs: User overrides for auto-detected settings 

49  

50 Returns: 

51 dict: Configuration dictionary 

52 """ 

53 # Convert to Path 

54 input_path = Path(input_path) 

55 

56 # Create base configuration 

57 config = { 

58 "input_path": input_path, 

59 "output_path": input_path.parent / f"{input_path.name}_stitched", 

60 "normalize": True, 

61 "flatten_z": None, # Will be auto-detected 

62 "z_method": "max", 

63 "channel_weights": None, # Will be auto-detected 

64 "well_filter": None 

65 } 

66 

67 # Create temporary EZStitcher to detect parameters 

68 from .core import EZStitcher 

69 temp_stitcher = EZStitcher(input_path) 

70 

71 # Update with auto-detected values 

72 config["flatten_z"] = temp_stitcher.flatten_z 

73 config["channel_weights"] = temp_stitcher.channel_weights 

74 

75 # Override with user-provided values 

76 config.update(kwargs) 

77 

78 return config