opticstream.utils
Filename parsing and manipulation utilities.
These are regular Python functions (not Prefect tasks) for filename operations used across multiple tasks.
complex_to_complex_filename(complex_file, complex_path)
Normalize complex filename and construct full path.
Normalizes image index to 4 digits and ensures filename ends with _complex.nii.
Converts mosaic_001_image_000_complex.nii → mosaic_001_image_0000_complex.nii
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
complex_file
|
str
|
Path to complex file |
required |
complex_path
|
Path
|
Path to complex directory |
required |
Returns:
| Type | Description |
|---|---|
str
|
Full path to normalized complex file |
Source code in opticstream/utils/filename_utils.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
extract_processed_index_from_filename(file_path)
Extract the numeric index after processed_ in the basename.
Used for mosaics_per_slice == 3 spectral paths such as
.../spectral/processed_0123*.nii.
Source code in opticstream/utils/filename_utils.py
136 137 138 139 140 141 142 143 144 145 146 147 | |
extract_spectral_index_from_filename(file_path)
Extract the numeric index after spectral_ in the basename.
Used for mosaics_per_slice == 3 processed paths such as
.../processed/processed_0123*.nii.
Source code in opticstream/utils/filename_utils.py
123 124 125 126 127 128 129 130 131 132 133 134 | |
extract_tile_number_from_filename(file_path)
Extract tile number from an image_{number} token in filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to file (full path or basename) |
required |
Returns:
| Type | Description |
|---|---|
int
|
Tile number parsed from |
Raises:
| Type | Description |
|---|---|
ValueError
|
If filename does not contain an |
Source code in opticstream/utils/filename_utils.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
normalize_image_index(filename)
Normalize image index in filename to 4-digit padding.
Handles mosaic_(\d{3})_image_(\d{3,4}) → mosaic_(\d{3})_image_(\d{4})
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Filename to normalize (can be full path or just basename) |
required |
Returns:
| Type | Description |
|---|---|
str
|
Normalized filename with 4-digit image index (basename only) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If filename doesn't match expected pattern |
Source code in opticstream/utils/filename_utils.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
parse_lsm_run_folder_name(folder_name)
Parse an LSM run folder name into run_index, strip_index, and channel_index.
Folder names follow the format:
- → run_index=N, strip_index=s+1, channel_index=1
- → run_index=N, strip_index=s+1, channel_index=2
Where <prefix> is any single word composed of letters (e.g. "Run", "Scan",
"Acq"). The prefix is case-insensitive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder_name
|
str
|
Folder name or path (e.g. "Run1", "Run1_2", "Scan3_C2", "Acq1_C2_3"). Trailing slashes and parent path are ignored; only the basename is parsed. |
required |
Returns:
| Type | Description |
|---|---|
tuple of (int, int, int)
|
(run_index, strip_index, channel_index) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If folder_name does not match the expected pattern. |
Examples:
>>> parse_lsm_run_folder_name("Run1")
(1, 1, 1)
>>> parse_lsm_run_folder_name("Run1_1")
(1, 2, 1)
>>> parse_lsm_run_folder_name("Run1_4")
(1, 5, 1)
>>> parse_lsm_run_folder_name("Run1_C2")
(1, 1, 2)
>>> parse_lsm_run_folder_name("Run1_C2_3")
(1, 4, 2)
>>> parse_lsm_run_folder_name("Scan2_C2_1")
(2, 2, 2)
Source code in opticstream/utils/filename_utils.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
parse_lsm_strip_index(strip_index, channel_index, strips_per_slice)
Parse an LSM strip index into a slice index, strip index, and channel index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strip_index
|
int
|
1-based strip index within the entire acquisition. |
required |
channel_index
|
int
|
Channel index (e.g. 1 or 2). |
required |
strips_per_slice
|
int
|
Number of strips acquired per slice. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[int, int, int]
|
(slice_index, strip_index_within_slice, channel_index) |
Source code in opticstream/utils/filename_utils.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
parse_lsm_strip_index_from_filename(folder_name, strips_per_slice=1)
Parse LSM slice/strip/channel indices from a run folder name.
This combines parse_lsm_run_folder_name and parse_lsm_strip_index:
- First, the folder name is interpreted as an LSM run folder, e.g.:
Run1,Run1_2,Run1_C2,Run1_C2_3.- Then the resulting strip index is split into a slice index and a strip index
within that slice using
strips_per_slice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder_name
|
str
|
Folder name or path; only the basename is parsed. |
required |
strips_per_slice
|
int
|
Number of strips acquired per slice. Defaults to 1. |
1
|
Returns:
| Type | Description |
|---|---|
Tuple[int, int, int]
|
(slice_index, strip_index_within_slice, channel_index) |
Source code in opticstream/utils/filename_utils.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
replace_spectral_with_complex_in_path(file_path)
Replace 'spectral' with 'complex' in file path.
Simple string replacement for complex→processed conversion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
File path containing 'spectral' |
required |
Returns:
| Type | Description |
|---|---|
str
|
File path with 'spectral' replaced by 'complex' |
Source code in opticstream/utils/filename_utils.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
spectral_to_complex_filename(spectral_file, complex_path)
Convert spectral filename to complex filename.
Converts mosaic_001_image_0000_spectral_0000.nii → mosaic_001_image_0000_complex.nii
Handles spectral→complex replacement and image index normalization to 4 digits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spectral_file
|
str
|
Path to spectral file |
required |
complex_path
|
Path
|
Path to complex directory |
required |
Returns:
| Type | Description |
|---|---|
str
|
Full path to complex file |
Source code in opticstream/utils/filename_utils.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
Deployment utilities for Prefect event-driven flows.
This module provides helper functions to create standardized deployment configurations for event-driven flows, reducing boilerplate code.
create_event_deployment(flow, name, event_name, tags=None, concurrency_limit=None)
Create a standard event-driven deployment for a flow.
This helper creates a deployment configuration for a flow that is triggered by a single event. It standardizes the deployment setup and reduces boilerplate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow
|
Flow
|
The Prefect flow to create a deployment for |
required |
name
|
str
|
Deployment name |
required |
event_name
|
str
|
Event name to trigger on |
required |
tags
|
List[str]
|
Tags for the deployment |
None
|
concurrency_limit
|
int
|
Concurrency limit for the deployment |
None
|
Returns:
| Type | Description |
|---|---|
Flow
|
The flow with deployment configuration (for use with to_deployment()) |
Examples:
>>> deployment = create_event_deployment(
... process_tile_batch_event_flow,
... name="process_tile_batch_event_flow",
... event_name=BATCH_READY,
... tags=["event-driven", "tile-batch"],
... )
Source code in opticstream/utils/deployment_utils.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
create_unified_deployment(flow, name, event_names, tags=None, concurrency_limit=None)
Create a unified deployment for a flow that handles multiple events.
This helper creates a deployment configuration for flows that need to handle multiple event types (like unified_state_management_event_flow).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow
|
Flow
|
The Prefect flow to create a deployment for |
required |
name
|
str
|
Deployment name |
required |
event_names
|
List[str]
|
List of event names to trigger on |
required |
tags
|
List[str]
|
Tags for the deployment |
None
|
concurrency_limit
|
int
|
Concurrency limit for the deployment |
None
|
Returns:
| Type | Description |
|---|---|
Flow
|
The flow with deployment configuration (for use with to_deployment()) |
Examples:
>>> deployment = create_unified_deployment(
... unified_state_management_event_flow,
... name="unified_state_management_event_flow",
... event_names=[BATCH_PROCESSED, BATCH_ARCHIVED, MOSAIC_ENFACE_STITCHED],
... tags=["event-driven", "state-management", "unified"],
... concurrency_limit=1,
... )
Source code in opticstream/utils/deployment_utils.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |