Coverage for ezstitcher/core/pipeline_base.py: 81%

37 statements  

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

1""" 

2Core interfaces and types for the EZStitcher pipeline system. 

3 

4This module provides the foundational abstractions that define the pipeline architecture. 

5It contains no implementation details, only interfaces and type definitions. 

6""" 

7 

8from abc import ABC, abstractmethod 

9from typing import Optional, Union, List, Dict, Any, TYPE_CHECKING 

10from pathlib import Path 

11 

12# Use string literal for type annotations to avoid circular imports 

13# The actual ProcessingContext class is defined in pipeline.py 

14 

15class StepInterface(ABC): 

16 """Base interface for all pipeline steps.""" 

17 

18 @abstractmethod 

19 def __init__( 

20 self, 

21 name: Optional[str] = None, 

22 input_dir: Optional[Union[str, Path]] = None, 

23 output_dir: Optional[Union[str, Path]] = None, 

24 variable_components: Optional[List[str]] = None 

25 ) -> None: 

26 """ 

27 Initialize a pipeline step. 

28 

29 Args: 

30 name: Human-readable name for the step 

31 input_dir: Input directory for this step 

32 output_dir: Output directory for this step 

33 variable_components: List of components that vary in processing 

34 """ 

35 pass 

36 

37 @abstractmethod 

38 def process(self, context: 'ProcessingContext') -> 'ProcessingContext': 

39 """ 

40 Process data according to the step's functionality. 

41 

42 Args: 

43 context: Processing context containing input data and metadata 

44 

45 Returns: 

46 Updated context with processing results 

47 """ 

48 pass 

49 

50class PipelineInterface(ABC): 

51 """Base interface for pipeline implementations.""" 

52 

53 @abstractmethod 

54 def __init__( 

55 self, 

56 steps: Optional[List[StepInterface]] = None, 

57 input_dir: Optional[Union[str, Path]] = None, 

58 output_dir: Optional[Union[str, Path]] = None, 

59 name: Optional[str] = None, 

60 well_filter: Optional[List[str]] = None 

61 ) -> None: 

62 """ 

63 Initialize a pipeline. 

64 

65 Args: 

66 steps: List of processing steps 

67 input_dir: Pipeline input directory 

68 output_dir: Pipeline output directory 

69 name: Human-readable name 

70 well_filter: List of wells to process 

71 """ 

72 pass 

73 

74 @abstractmethod 

75 def add_step(self, step: StepInterface) -> 'PipelineInterface': 

76 """ 

77 Add a processing step to the pipeline. 

78 

79 Args: 

80 step: Step to add 

81 

82 Returns: 

83 Self for method chaining 

84 """ 

85 pass 

86 

87 @abstractmethod 

88 def run( 

89 self, 

90 orchestrator: Optional[Any] = None, 

91 input_dir: Optional[Union[str, Path]] = None, 

92 output_dir: Optional[Union[str, Path]] = None, 

93 well_filter: Optional[List[str]] = None 

94 ) -> 'ProcessingContext': 

95 """ 

96 Execute the pipeline. 

97 

98 Args: 

99 orchestrator: Pipeline orchestrator instance 

100 input_dir: Override input directory 

101 output_dir: Override output directory 

102 well_filter: Override well filter 

103 

104 Returns: 

105 Processing results in context 

106 """ 

107 pass 

108 

109class PipelineFactoryInterface(ABC): 

110 """Base interface for pipeline factories.""" 

111 

112 @abstractmethod 

113 def __init__( 

114 self, 

115 input_dir: Union[str, Path], 

116 output_dir: Optional[Union[str, Path]] = None, 

117 normalize: bool = True, 

118 normalization_params: Optional[Dict[str, Any]] = None, 

119 preprocessing_steps: Optional[List[StepInterface]] = None, 

120 well_filter: Optional[List[str]] = None 

121 ) -> None: 

122 """ 

123 Initialize a pipeline factory. 

124 

125 Args: 

126 input_dir: Input directory for created pipelines 

127 output_dir: Output directory for created pipelines 

128 normalize: Whether to apply normalization 

129 normalization_params: Parameters for normalization 

130 preprocessing_steps: Steps to add before main processing 

131 well_filter: Wells to process 

132 """ 

133 pass 

134 

135 @abstractmethod 

136 def create_pipelines(self) -> List[PipelineInterface]: 

137 """ 

138 Create configured pipelines. 

139 

140 Returns: 

141 List of configured pipeline instances 

142 """ 

143 pass 

144 

145# Common enums and constants 

146class ProcessingMode: 

147 """Available processing modes.""" 

148 BASIC = "basic" 

149 MULTICHANNEL = "multichannel" 

150 ZSTACK = "zstack" 

151 FOCUS = "focus" 

152 

153class StepType: 

154 """Common step types.""" 

155 PREPROCESSING = "preprocessing" 

156 POSITION_GENERATION = "position_generation" 

157 STITCHING = "stitching" 

158 COMPOSITE = "composite"