Batch¶
optari.batch.plan ¶
Resolve a batch preset plus a dataset folder into a concrete, checked analysis plan.
A batch preset names the per-step presets rather than copying their contents, so the presets the user tuned in the docks stay the single source of truth and the plan itself stays small enough to read, share and cite.
Everything here is headless: no Qt, no napari, no viewer. Building a plan and telling the user what is wrong with it must work before anything is loaded.
BatchJob
dataclass
¶
BatchJob(study_path, scan_path, scan_info)
One scan to process, and where its outputs belong.
BatchPlan
dataclass
¶
BatchPlan(jobs, output_dir, preset=dict(), reconstruction=None, unmixing=None, segmentation=None, roi=None, roi_from_scan=False, source=None, frame='spectral_motion', measure=MeasureScope(), outputs=OutputSpec())
A dataset, a set of resolved step settings, and where the results go.
report_path
property
¶
report_path
Where the run's per-scan status report is written (batch_report.xlsx).
roi_placement
property
¶
roi_placement
How the ROI preset asks to be placed. Owned by the preset, not the plan.
table_path
property
¶
table_path
Where the run's ROI measurements are written (batch_roi_table.xlsx).
OutputSpec
dataclass
¶
OutputSpec(xlsx=True, hdf5=False, ipasc=False, overlay_png=True, overlay_layer=None)
Which outputs a batch run writes per scan: ROI table, HDF5/IPASC export, and overlay PNG.
build_plan ¶
build_plan(*, root, batch_preset, output_dir)
Resolve batch_preset against the dataset at root.
Raises ValueError, message safe to show the user, when the preset cannot be
resolved at all. Problems that need the assembled plan to spot are reported by
:func:validate_plan instead, so the dialog can list them together.
Source code in src/optari/batch/plan.py
195 196 197 198 199 200 201 202 203 204 205 206 207 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 263 264 265 266 267 268 269 270 271 | |
describe_plan ¶
describe_plan(plan)
The resolved settings, as shown in the batch window before the run.
Source code in src/optari/batch/plan.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 | |
plan_warnings ¶
plan_warnings(plan)
Things worth saying out loud that are not reasons to refuse the run.
Source code in src/optari/batch/plan.py
299 300 301 302 303 304 305 306 307 308 | |
validate_plan ¶
validate_plan(plan)
Everything that would make this run fail or be pointless, reported together.
Only cross-checks that can be made before loading a scan live here. Per-scan failures (wavelengths not acquired, ROI outside the FOV, class absent from a frame) are the run's own business and are recorded in its report.
Source code in src/optari/batch/plan.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
optari.batch.runner ¶
Drive a :class:BatchPlan over a dataset, one scan at a time.
The whole run is a single generator. Work that has to touch the viewer (loading a
scan, placing an ROI, measuring, screenshots) happens inline on the main thread;
each heavy stage is yielded as a :class:BackgroundStep that the runner hands to a
worker thread and resumes from when it finishes. Writing it as a generator is what
makes "log this scan's failure and carry on" an ordinary try/except around
the per-scan body rather than a state machine.
Resuming happens on the worker's finished signal, not returned. superqt emits
returned first and finished second, and the task helper clears the UI gate in
its on_done; resuming any earlier would let the finishing worker tear down the
progress bar and gate that the next step has already set up.
BatchCancelled ¶
Bases: Exception
The user stopped the run. Nothing further should start.
BatchRunner ¶
BatchRunner(controller, plan, *, on_progress=None, on_finished=None)
Runs a plan against the live viewer, reporting progress as it goes.
Set up the report, ROI table writer, and progress callbacks for plan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
controller
|
OptariController
|
OptariController driving the viewer this run operates on. |
required |
plan
|
BatchPlan
|
Resolved plan to execute. |
required |
on_progress
|
Callable[[BatchJob, str], None] | None
|
optional callback(job, status), called as each scan starts and ends. |
None
|
on_finished
|
Callable[[], None] | None
|
optional callback(), called once the whole run has finished. |
None
|
Source code in src/optari/batch/runner.py
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 | |
cancel ¶
cancel()
Stop the run after the current step, and ask a running background worker to quit early.
Source code in src/optari/batch/runner.py
130 131 132 133 134 | |
start ¶
start()
Open the run's log file and begin the plan.
Source code in src/optari/batch/runner.py
117 118 119 120 121 122 123 124 125 126 127 128 | |
BatchStepError ¶
BatchStepError(message, step='')
Bases: Exception
This scan cannot be processed. Record it and move on to the next one.
Source code in src/optari/batch/runner.py
51 52 53 | |
Tick
dataclass
¶
Tick()
Hand control back to the event loop, so Cancel stays responsive between scans.
optari.batch.report ¶
Per-scan outcome record for a batch run.
Written out after every scan rather than at the end: a run over a whole study can take hours, and a crash four hours in must not take the record of the first three with it. The same reason the ROI table autosaves.
BatchReport ¶
BatchReport(destination=None, plan_source=None)
What happened to every scan in a run, mirrored to destination as it goes.
Track scan outcomes, mirroring the report to destination after each update.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
destination
|
Path | None
|
Path to write batch_report.xlsx to, or None to keep the report in memory only. |
None
|
plan_source
|
dict | None
|
The batch preset this run came from, recorded in the report's provenance sheet. |
None
|
Source code in src/optari/batch/report.py
82 83 84 85 86 87 88 89 90 91 92 93 | |
__len__ ¶
__len__()
Number of scans recorded so far, regardless of outcome.
Source code in src/optari/batch/report.py
95 96 97 | |
cancel ¶
cancel(job)
Mark job as cancelled by the user.
Source code in src/optari/batch/report.py
152 153 154 | |
counts ¶
counts()
How many scans ended in each status, for the run summary.
Source code in src/optari/batch/report.py
109 110 111 112 113 114 | |
fail ¶
fail(job, message, step='')
Mark job as failed, recording the reason and which step it failed on.
Source code in src/optari/batch/report.py
148 149 150 | |
note ¶
note(job, **fields)
Attach details to a scan still being processed (frame, output paths, row count).
Source code in src/optari/batch/report.py
133 134 135 136 137 138 139 140 141 142 | |
start ¶
start(job)
Begin tracking job, recording its start time, and mirror the report to disk.
Source code in src/optari/batch/report.py
122 123 124 125 126 127 128 129 130 131 | |
succeed ¶
succeed(job)
Mark job as completed successfully.
Source code in src/optari/batch/report.py
144 145 146 | |
summary ¶
summary()
One line for the batch window once the run ends.
Source code in src/optari/batch/report.py
196 197 198 199 200 201 202 203 204 205 206 | |