PATATO Bridge & Export¶
optari.patato_bridge ¶
patato_bridge: functions to convert between PATATO and napari data structures
acquisition_start ¶
acquisition_start(pa_data)
Wall-clock time of the first frame, or None if the scan cannot be dated.
PATATO's iThera and IPASC readers count timestamps in seconds since 0001-01-01, but an HDF5 file from another tool may use any epoch. So the timestamps are only read as wall-clock times when they match the date PATATO reads from the scan itself. A day of tolerance absorbs time zones: iThera records local time, IPASC UTC.
Source code in src/optari/patato_bridge.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
build_napari_layers ¶
build_napari_layers(pa_data)
Build napari image layers from an open pa_data handle.
Returns¶
layers : list of (data, kwargs) tuples
Ready to pass to viewer.add_image. Everything a scan holds is an image.
annotations and segmentations are layers OPTARI creates, not loads.
patato_objects : dict
Maps napari layer name → PATATO ImageSequence for later use
(e.g. FOV queries, scale derivation).
Source code in src/optari/patato_bridge.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 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 321 | |
display_data_from_patato_obj ¶
display_data_from_patato_obj(image_sequence)
Convert PATATO image data to napari's display orientation.
Source code in src/optari/patato_bridge.py
100 101 102 | |
expand_to_acquisition_frames ¶
expand_to_acquisition_frames(data, frames, n_acq_frames)
Place per-output-frame data at its frames on the acquisition frame axis.
Frames that were not processed stay zero, so every PA layer shares the frame slider with the ultrasound. Data that already spans the acquisition is returned unchanged.
Source code in src/optari/patato_bridge.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
fov_from_objects ¶
fov_from_objects(patato_objects)
Return (fov_x_m, fov_y_m) from the first object with valid FOV.
Returns None if no object exposes usable FOV metadata.
Source code in src/optari/patato_bridge.py
329 330 331 332 333 334 335 336 337 338 | |
layer_colormap ¶
layer_colormap(group)
Colormap for an HDF5 image group, whether loaded from the scan or computed.
Source code in src/optari/patato_bridge.py
143 144 145 146 147 | |
patato_roi_from_geometry ¶
patato_roi_from_geometry(geometry, fov_x_m, fov_y_m, *, z=0.0, run=0.0, rep=0.0, frame_idx=0, roi_id=None, track_id=None, roi_group_uid=None)
Convert an ROI geometry into a PATATO ROI object for the native writer.
The geometry's source becomes PATATO's roi_class, so provenance survives export.
Source code in src/optari/patato_bridge.py
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 478 479 480 481 482 483 484 485 486 | |
roi_records_from_scan_rois ¶
roi_records_from_scan_rois(pa_data, fov_x_m, fov_y_m)
Load PATATO ROIs as one frame-owned record per valid frame.
Source code in src/optari/patato_bridge.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 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 | |
scale_from_patato_obj ¶
scale_from_patato_obj(obj, fallback)
Derive a (t, y, x) napari scale in mm/pixel from a PATATO object.
Reads the object's fov ((fov_x_m, fov_y_m) in metres) and
shape_2d ((ny, nx) in pixels). Returns fallback if either
value is absent or zero.
Source code in src/optari/patato_bridge.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
segmentation_from_scan ¶
segmentation_from_scan(pa_data)
Load a previously exported segmentation mask and its class metadata.
Returns None when the scan has no segmentation, or one that has not optari compatible metadata
Source code in src/optari/patato_bridge.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
optari.io.export_pipeline ¶
HDF5 and IPASC scan export, and the ROI table XLSX round-trip.
export_scan_to_hdf5() writes the scan through PATATO's own save_hdf5(), then reopens the file to rewrite the ROI and derived-data datasets (segmentation mask, derived PA images, clinical metadata) so in-session OPTARI edits are captured, not just what was already in the source file. No controller reads a PATATO array or writes an HDF5 attribute directly outside this module and patato_bridge.py.
default_roi_table_filename ¶
default_roi_table_filename()
roi_data_<operator>_<analysis id>_<timestamp>.xlsx.
The timestamp is UTC so it matches creation_time in the provenance sheet.
Source code in src/optari/io/export_pipeline.py
51 52 53 54 55 56 57 58 59 60 | |
export_roi_table_to_xlsx ¶
export_roi_table_to_xlsx(df_saved, path=None)
Write the ROI table as an XLSX file, prompting for a path if path is None.
Source code in src/optari/io/export_pipeline.py
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 | |
export_scan_to_hdf5 ¶
export_scan_to_hdf5(controller, destination)
Export scan data and OPTARI additions (ROIs and derived images).
Source code in src/optari/io/export_pipeline.py
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 | |
export_scan_to_ipasc ¶
export_scan_to_ipasc(controller, destination)
Export the raw time series of the loaded scan as a native IPASC file.
Source code in src/optari/io/export_pipeline.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
file_origin ¶
file_origin(**extra)
origin recorded in every file OPTARI writes.
Source code in src/optari/io/export_pipeline.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
import_roi_table_from_xlsx ¶
import_roi_table_from_xlsx(path=None)
Read a previously exported ROI table, prompting for a file if path is None.
Source code in src/optari/io/export_pipeline.py
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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
ipasc_export_report ¶
ipasc_export_report(destination)
Summarise how complete the IPASC metadata of an exported file are.
Reports which of IPASC's minimal fields are present. Fields IPASC marks "report if present" are absent when the source format never recorded them, so their absence is not a failure and is not counted here.
Source code in src/optari/io/export_pipeline.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
optari.io.discovery ¶
Finding studies and scans on disk. Headless: no Qt, no napari, no viewer.
discover_scans ¶
discover_scans(folder)
Find every scan directly under folder, keyed by path and deduplicated by scan_key.
When both an HDF5 file and an iThera folder resolve to the same key, the HDF5 one wins.
Source code in src/optari/io/discovery.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
discover_studies ¶
discover_studies(root, max_depth=3)
Map each study folder under root to its scans, in folder-name order.
A study is simply any folder that holds at least one scan, so a flat folder
of scans comes back as a single study and no naming convention is imposed
beyond the Scan_* one discover_scans already relies on. A folder that
is itself a study is not descended into.
Source code in src/optari/io/discovery.py
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 126 127 128 129 130 | |
scan_key ¶
scan_key(scan_path)
Return the Scan_<n> prefix of scan_path's name, or the full name if it doesn't match.
Source code in src/optari/io/discovery.py
26 27 28 29 30 | |
scan_sort_key ¶
scan_sort_key(scan_path)
Sort key that orders Scan_<n> names numerically, ahead of any other name sorted alphabetically.
Source code in src/optari/io/discovery.py
33 34 35 36 37 38 39 | |
scan_type ¶
scan_type(path)
Identify the format of a scan on disk, or None if the path is not a scan.
Source code in src/optari/io/discovery.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |