vodex.loaders module
This module contains classes for loading and collecting information from various file types.
It includes:
'Loader' - A generic class for loading files. Can be subclassed to create custom loaders for different file types.
'TiffLoader' - A class for working with TIFF image files. A subclass of Loader, it can be used to determine the data type of the images, the number of frames in each TIFF file, and load frames from TIFF files.
Additional loaders can be created to work with other file types. See Contributions for details.
Loader
Bases: ABC
The Loader class is a generic class that serves as a template for loading image data from specific file types. The class contains basic methods that need to be overwritten to create a custom loader for a specific file type.
Any loader must be initialised by providing an example file from the dataset.
Args: file_example: an example file from the dataset to infer the frame size and data type.
Attributes:
Name | Type | Description |
---|---|---|
frame_size |
Tuple[int, int]
|
a tuple containing the individual frame size (height, width) |
data_type |
dtype
|
the datatype of the image frames. |
Source code in src/vodex/loaders.py
__eq__(other)
get_frame_dtype(file)
abstractmethod
staticmethod
Returns the datatype of the image frames.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file |
Union[str, Path]
|
the path to the file to get the datatype of the frame for. |
required |
Returns: datatype of the frame.
Source code in src/vodex/loaders.py
get_frame_size(file)
abstractmethod
staticmethod
Returns the size of an individual frame (height, width) in pixels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file |
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/loaders.py
get_frames_in_file(file)
abstractmethod
staticmethod
Computes and returns the number of frames in a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file |
Union[str, Path]
|
the path to the file to get the number of frames for. |
required |
Returns: the number of frames in the file.
Source code in src/vodex/loaders.py
load_frames(frames, files, show_file_names=False, show_progress=True)
abstractmethod
Loads the specified frames from the given files and returns them as a 3D array (frame, y, x).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frames |
List[int]
|
list of frames inside corresponding files to load |
required |
files |
Union[List[str], List[Path]]
|
list of files corresponding to each frame |
required |
show_file_names |
bool
|
whether to print the file from which the frames are loaded on the screen. |
False
|
show_progress |
bool
|
whether to show the progress bar of how many frames have been loaded. |
True
|
Returns: 3D array of requested frames (frame, y, x)
Source code in src/vodex/loaders.py
TiffLoader
Bases: Loader
A class to work with tiff image files. It is used to get the datatype of the images, get the number of frames in each tiff file and load frames from tiff files. You can create your own loaders to work with other file types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_example |
Union[str, Path]
|
An example tif file from the dataset to infer the frame size and data type. |
required |
Attributes:
Name | Type | Description |
---|---|---|
frame_size |
individual frame size (hight, width). |
|
data_type |
datatype. |
Source code in src/vodex/loaders.py
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 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 |
|
get_frame_dtype(file)
staticmethod
Gets the datatype of the frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file |
Union[str, Path]
|
the path to the file to get the datatype of the frame for. |
required |
Returns: datatype of the frame.
Source code in src/vodex/loaders.py
get_frame_size(file)
staticmethod
Gets frame size ( height , width ) from a tiff file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file |
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/loaders.py
get_frames_in_file(file)
staticmethod
Compute and return the number of frames in a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file |
Union[str, Path]
|
the name of a file relative to data_dir to get the number of frames for. |
required |
Returns: the number of frames in the file.
Source code in src/vodex/loaders.py
load_frames(frames, files, show_file_names=False, show_progress=True)
Load frames from files and return as an array (frame, y, x).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frames |
List[int]
|
list of frames inside corresponding files to load |
required |
files |
Union[List[str], List[Path]]
|
list of files corresponding to each frame |
required |
show_file_names |
bool
|
whether to print the file from which the frames are loaded on the screen. |
False
|
show_progress |
bool
|
whether to show the progress bar of how many frames have been loaded. |
True
|
Returns: 3D array of requested frames (frame, y, x)