|
10 | 10 | from types import UnionType |
11 | 11 | from typing import Literal, TypeGuard, TypeVar, Union, get_args, get_origin |
12 | 12 |
|
13 | | -from pydantic import BaseModel, Field |
| 13 | +from pydantic import BaseModel |
14 | 14 | from pydantic.fields import FieldInfo |
15 | 15 | from pydantic_core import PydanticUndefined |
16 | 16 |
|
17 | | -from .types import Compression |
| 17 | +from .configurations import InputConfig, OutputConfig, ReductionConfig, WorkflowConfig |
18 | 18 |
|
19 | 19 |
|
20 | 20 | def _validate_annotation(annotation) -> TypeGuard[type]: |
@@ -140,148 +140,6 @@ def add_args_from_pydantic_model( |
140 | 140 | return parser |
141 | 141 |
|
142 | 142 |
|
143 | | -class InputConfig(BaseModel): |
144 | | - # Add title of the basemodel |
145 | | - model_config = {"title": "Input Configuration"} |
146 | | - # File IO |
147 | | - input_file: list[str] = Field( |
148 | | - title="Input File", |
149 | | - description="Path to the input file. If multiple file paths are given," |
150 | | - " the output(histogram) will be merged(summed) " |
151 | | - "and will not save individual outputs per input file. ", |
152 | | - ) |
153 | | - swmr: bool = Field( |
154 | | - title="SWMR Mode", |
155 | | - description="Open the input file in SWMR mode", |
156 | | - default=False, |
157 | | - ) |
158 | | - # Detector selection |
159 | | - detector_ids: list[int] = Field( |
160 | | - title="Detector IDs", |
161 | | - description="Detector indices to process", |
162 | | - default=[0, 1, 2], |
163 | | - ) |
164 | | - # Chunking options |
165 | | - iter_chunk: bool = Field( |
166 | | - title="Iterate in Chunks", |
167 | | - description="Whether to process the input file in chunks " |
168 | | - " based on the hdf5 dataset chunk size. " |
169 | | - "It is ignored if hdf5 dataset is not chunked. " |
170 | | - "If True, it overrides chunk-size-pulse and chunk-size-events options.", |
171 | | - default=False, |
172 | | - ) |
173 | | - chunk_size_pulse: int = Field( |
174 | | - title="Chunk Size Pulse", |
175 | | - description="Number of pulses to process in each chunk. " |
176 | | - "If 0 or negative, process all pulses at once.", |
177 | | - default=0, |
178 | | - ) |
179 | | - chunk_size_events: int = Field( |
180 | | - title="Chunk Size Events", |
181 | | - description="Number of events to process in each chunk. " |
182 | | - "If 0 or negative, process all events at once." |
183 | | - "If both chunk-size-pulse and chunk-size-events are set, " |
184 | | - "chunk-size-pulse is preferred.", |
185 | | - default=0, |
186 | | - ) |
187 | | - |
188 | | - |
189 | | -class TimeBinUnit(enum.StrEnum): |
190 | | - ms = 'ms' |
191 | | - us = 'us' |
192 | | - ns = 'ns' |
193 | | - |
194 | | - |
195 | | -class TimeBinCoordinate(enum.StrEnum): |
196 | | - event_time_offset = 'event_time_offset' |
197 | | - time_of_flight = 'time_of_flight' |
198 | | - |
199 | | - |
200 | | -class WorkflowConfig(BaseModel): |
201 | | - # Add title of the basemodel |
202 | | - model_config = {"title": "Workflow Configuration"} |
203 | | - time_bin_coordinate: TimeBinCoordinate = Field( |
204 | | - title="Time Bin Coordinate", |
205 | | - description="Coordinate to bin the time data.", |
206 | | - default=TimeBinCoordinate.event_time_offset, |
207 | | - ) |
208 | | - nbins: int = Field( |
209 | | - title="Number of Time Bins", |
210 | | - description="Number of Time bins", |
211 | | - default=50, |
212 | | - ) |
213 | | - min_time_bin: int | None = Field( |
214 | | - title="Minimum Time Bin", |
215 | | - description="Minimum time edge of [time_bin_coordinate] in [time_bin_unit].", |
216 | | - default=None, |
217 | | - ) |
218 | | - max_time_bin: int | None = Field( |
219 | | - title="Maximum Time Bin", |
220 | | - description="Maximum time edge of [time_bin_coordinate] in [time_bin_unit].", |
221 | | - default=None, |
222 | | - ) |
223 | | - time_bin_unit: TimeBinUnit = Field( |
224 | | - title="Unit of Time Bins", |
225 | | - description="Unit of time bins.", |
226 | | - default=TimeBinUnit.ms, |
227 | | - ) |
228 | | - tof_lookup_table_file_path: str | None = Field( |
229 | | - title="TOF Lookup Table File Path", |
230 | | - description="Path to the TOF lookup table file. " |
231 | | - "If None, the lookup table will be computed on-the-fly.", |
232 | | - default=None, |
233 | | - ) |
234 | | - tof_simulation_min_wavelength: float = Field( |
235 | | - title="TOF Simulation Minimum Wavelength", |
236 | | - description="Minimum wavelength for TOF simulation in Angstrom.", |
237 | | - default=1.8, |
238 | | - ) |
239 | | - tof_simulation_max_wavelength: float = Field( |
240 | | - title="TOF Simulation Maximum Wavelength", |
241 | | - description="Maximum wavelength for TOF simulation in Angstrom.", |
242 | | - default=3.6, |
243 | | - ) |
244 | | - tof_simulation_seed: int = Field( |
245 | | - title="TOF Simulation Seed", |
246 | | - description="Random seed for TOF simulation.", |
247 | | - default=42, # No reason. |
248 | | - ) |
249 | | - |
250 | | - |
251 | | -class OutputConfig(BaseModel): |
252 | | - # Add title of the basemodel |
253 | | - model_config = {"title": "Output Configuration"} |
254 | | - # Log verbosity |
255 | | - verbose: bool = Field( |
256 | | - title="Verbose Logging", |
257 | | - description="Increase output verbosity.", |
258 | | - default=False, |
259 | | - ) |
260 | | - # File output |
261 | | - output_file: str = Field( |
262 | | - title="Output File", |
263 | | - description="Path to the output file.", |
264 | | - default="scipp_output.h5", |
265 | | - ) |
266 | | - compression: Compression = Field( |
267 | | - title="Compression", |
268 | | - description="Compress option of reduced output file.", |
269 | | - default=Compression.BITSHUFFLE_LZ4, |
270 | | - ) |
271 | | - |
272 | | - |
273 | | -class ReductionConfig(BaseModel): |
274 | | - """Container for all reduction configurations.""" |
275 | | - |
276 | | - inputs: InputConfig |
277 | | - workflow: WorkflowConfig = Field(default_factory=WorkflowConfig) |
278 | | - output: OutputConfig = Field(default_factory=OutputConfig) |
279 | | - |
280 | | - @property |
281 | | - def _children(self) -> list[BaseModel]: |
282 | | - return [self.inputs, self.workflow, self.output] |
283 | | - |
284 | | - |
285 | 143 | T = TypeVar('T', bound=BaseModel) |
286 | 144 |
|
287 | 145 |
|
|
0 commit comments