vodex.core
This module provides the core classes for loading and preprocessing imaging data.
'ImageLoader' is the core class that loads the image data and selects the appropriate loader based on the file type. It also collects information about the data type and number of frames per file.
'FileManager', 'FrameManager', and 'VolumeManager' are core classes that preprocess information about the experiment data. The 'FileManager' class contains information about the location and file type of the image files, while the 'FrameManager' class contains information about the number of frames in the experiment and the mapping of frames to files. The 'VolumeManager' class contains information about the image volumes in the experiment, including the number of frames per volume and the mapping of frames to volumes.
FileManager
The 'FileManager' class is used to collect and store information about image files, including their location, file type, and number of frames per file. It can either search for all files with a specific file extension in a provided data directory (order them alphabetically), or use a provided list of file names (in the provided order). The class initializes an 'ImageLoader' to calculate the number of frames per file if it is not provided.
The class raises an error if the data directory does not exist, no files of the specified file type are found, or if the number of frames per file is not provided or is not a list of integers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_dir |
Union[str, Path]
|
path to the folder with the files, ends with "/" or "\" |
required |
file_names |
List[str]
|
names of files relative to the data_dir |
None
|
frames_per_file |
List[int]
|
number of frames in each file. Will be used ONLY if the file_names were provided. |
None
|
file_type |
str
|
file type to search for (if files are not provided). Must be a key in the VX_SUPPORTED_TYPES dict. |
'TIFF'
|
Attributes:
Name | Type | Description |
---|---|---|
data_dir |
Path
|
the directory with all the imaging data |
file_names |
List[str]
|
names of files relative to the data_dir |
num_frames |
a number of frames per file |
|
n_files |
int
|
total number of image files |
Source code in src/vodex/core.py
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 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
__eq__(other)
Compares two FileManager instances to see if they are equal.
Source code in src/vodex/core.py
change_files_order(order)
Changes the order of the files. If you notice that files are in the wrong order, provide the new order. If you wish to exclude any files, get rid of them ( don't include their IDs into the new order ).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
order |
List[int]
|
The new order in which the files follow. Refer to file by it's position in the original list. Should be the same length as the number of files in the original list or smaller, no duplicates. |
required |
Source code in src/vodex/core.py
check_files(file_names)
Given a list of files checks that files are in the data directory. Throws an error if any of the files are missing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_names |
List[str]
|
list of filenames to check. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
If the files are all present in the directory, returns the file_names. |
Source code in src/vodex/core.py
find_files(file_extensions)
Searches for files ending with the provided file extension in the data directory. Sorts the names alphabetically in ascending order (from A to Z), sorting is case-insensitive (upper case letters are NOT prioritized).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_extensions |
Tuple[str]
|
extensions of files to search for |
required |
Returns: A sorted list of file names. File names are with the extension, relative to the data directory (names only, not full paths to files)
Source code in src/vodex/core.py
get_frames_per_file()
Get the number of frames per file.
Returns:
Type | Description |
---|---|
List[int]
|
a list with number of frames per file. |
Source code in src/vodex/core.py
FrameManager
A class containing information about the image frames in the experiment: total number of frames, and mapping of the frames to files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_manager |
FileManager
|
FileManager with the information about the files. |
required |
Attributes:
Name | Type | Description |
---|---|---|
file_manager |
FileManager
|
FileManager with the information about the files. |
n_frames |
int
|
total number of frames in the experiment (global frames). |
frame_to_file |
List[int]
|
a mapping for each global frame to a file where the frame is stored |
frame_in_file |
List[int]
|
a mapping for each global frame to a frame number relative to the beginning of the corresponding file |
Source code in src/vodex/core.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 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 |
|
from_dir(data_dir, file_type='TIFF', file_names=None, frames_per_file=None)
classmethod
Create a FrameManager object from files in directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_dir |
Union[Path, str]
|
path to the folder with the files, ends with "/" or "\" |
required |
file_type |
str
|
file type to search for (if files are not provided). Must be a key in the VX_SUPPORTED_TYPES dict. |
'TIFF'
|
file_names |
List[str]
|
names of files relative to the data_dir |
None
|
frames_per_file |
List[int]
|
number of frames in each file. Will be used ONLY if the file_names were provided. |
None
|
Returns:
Type | Description |
---|---|
FileManager
|
Initialised FileManager object. |
Source code in src/vodex/core.py
ImageLoader
The 'ImageLoader' class is responsible for choosing the appropriate loader for a given imaging file, collecting information about the data type, number of frames per file, and loading data from files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_example |
The path to a file example (one file from the whole dataset). This is used to determine the file type and initialize the corresponding data loader. |
required |
Attributes:
Name | Type | Description |
---|---|---|
supported_extensions |
List[str]
|
A list of all the supported file extensions. |
file_extension |
str
|
The file extension of the provided file example. |
loader |
Loader
|
The loader class initialized using the file example. |
Source code in src/vodex/core.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 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 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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
__eq__(other)
Compares two ImageLoader instances to see if they are equal.
Source code in src/vodex/core.py
__init__(file_example)
Initializes the ImageLoader class by determining the file extension, checking that it is a supported format, and initializing the appropriate loader class.
Source code in src/vodex/core.py
get_frame_size(file_name)
Returns the size of an individual frame in pixels (height and width).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name |
Union[str, Path]
|
the path to the file to get the size of the frame for. |
required |
Returns: ( height , width ) height and width of an individual frame in pixels.
Source code in src/vodex/core.py
get_frames_in_file(file_name)
Calculates and returns the number of frames in a given file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name |
Union[str, Path]
|
the name of the file to get the number of frames for. |
required |
Returns:
Type | Description |
---|---|
int
|
the number of frames in the file. |
Source code in src/vodex/core.py
load_frames(frames, files, show_file_names=False, show_progress=True)
Loads specified frames from specified files, and returns as a 3D array of shape (n_frames, height, width).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frames |
List[int]
|
list of frames IN FILES to load. |
required |
files |
Union[List[str], List[Path]]
|
a file for every frame |
required |
show_file_names |
bool
|
whether to print the names of the files from which the frames are loaded. Setting it to True will turn off show_progress. |
False
|
show_progress |
bool
|
whether to show the progress bar of how many frames have been loaded. Won't have effect of show_file_names is True. |
True
|
Returns: 3D array of shape (n_frames, height, width)
Source code in src/vodex/core.py
load_volumes(frame_in_file, files, volumes, show_file_names=False, show_progress=True)
Loads specific volumes of data, where a volume is defined as a set of frames. This method returns a 4D array of shape (n_volumes, n_frames_per_volume, height, width).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame_in_file |
List[int]
|
list of frames IN FILES to load (relative to the beginning of the file from which you are loading). |
required |
files |
Union[List[str], List[Path]]
|
a file for every frame |
required |
volumes |
List[int]
|
a volume for every frame where that frame belongs |
required |
show_file_names |
bool
|
whether to print the names of the files from which the frames are loaded. Setting it to True will turn off show_progress. |
False
|
show_progress |
bool
|
whether to show the progress bar of how many frames have been loaded. Won't have effect of show_file_names is True. |
True
|
Returns: 4D array of shape (number of volumes, zslices, height, width)
Source code in src/vodex/core.py
VolumeManager
A class containing information about the image volumes in the experiment: frames per volume, number of full volumes, and mapping of the frames to volumes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fpv |
int
|
frames per volume, number of frames in one volume |
required |
fgf |
int
|
first good frame, the first frame in the imaging session that is at the top of a volume. For example if you started imaging at the top of the volume, fgf = 0, but if you started somewhere in the middle, the first good frame is , for example, 23 ... |
0
|
frame_manager |
FrameManager
|
FrameManager object with the information about the frames in the experiment. |
required |
Attributes:
Name | Type | Description |
---|---|---|
fpv |
int
|
frames per volume, number of frames in one volume |
frame_manager |
FrameManager
|
FrameManager object with the information about the frames in the experiment. |
file_manager |
FileManager
|
FileManager object with the information about the files. |
n_frames |
int
|
total number of frames in the experiment |
n_head |
int
|
(same as fgf) number of frames at the beginning of the recording, that do not correspond to a full volume. If the recording starts at the top of a volume, it will be 0. |
n_tail |
int
|
number of frames at the end of the recording, that do not correspond to a full volume. |
full_volumes |
int
|
number of full volumes in the recording. |
frame_to_z |
List[int]
|
mapping of global frames to a z-slice (a slice relative to the top of the volume) |
frame_to_vol |
List[int]
|
mapping of a global frame to a full volume: -1 for head ( not full volume at the beginning ) volume number for full volumes : 0, 1, ,2 3, ..., -2 for tail (not full volume at the end ) |
Source code in src/vodex/core.py
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 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 |
|
from_dir(data_dir, fpv, fgf=0, file_type='TIFF', file_names=None, frames_per_file=None)
classmethod
Creates a VolumeManager object from directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_dir |
Union[str, Path]
|
path to the folder with the files, ends with "/" or "\" |
required |
file_type |
str
|
file type to search for (if files are not provided). Must be a key in the VX_SUPPORTED_TYPES dict. |
'TIFF'
|
fpv |
int
|
frames per volume, number of frames in one volume |
required |
fgf |
int
|
first good frame, the first frame in the imaging session that is at the top of a volume. For example if you started imaging at the top of the volume, fgf = 0, but if you started somewhere in the middle, the first good frame is , for example, 23 ... |
0
|
file_names |
List[str]
|
names of files relative to the data_dir |
None
|
frames_per_file |
List[int]
|
number of frames in each file. Will be used ONLY if the file_names were provided. |
None
|
Returns:
Type | Description |
---|---|
VolumeManager
|
Initialised VolumeManager object. |