navigate.controller.sub_controllers.camera_view.SpooledImageLoader
- class navigate.controller.sub_controllers.camera_view.SpooledImageLoader(channels: int, size_y: int, size_x: int)
Bases:
object
A class to lazily load images from disk using a spooled temporary file.
- __init__(channels: int, size_y: int, size_x: int) → None
Initialize the SpooledImageLoader.
- Parameters:
channels (int) – The number of channels.
Methods
__init__
(channels, size_y, size_x)Initialize the SpooledImageLoader.
Get the default directory for storing temporary files.
Get the default max_size based on the total RAM.
get_indices
(slice_index)Get the indices of the images stored in the spooled files.
load_image
(channel, slice_index)Load an image from a temporary file.
save_image
(image, channel, slice_index)Save an image to a temporary file.
Attributes
The number of channels.
The number of bytes in the image.
The height of the image.
The width of the image.
The temporary files.
- static get_default_directory() → str
Get the default directory for storing temporary files.
Default directory is within the .navigate directory.
- Returns:
The default directory for storing temporary files.
- Return type:
str
- static get_default_max_size() → int
Get the default max_size based on the total RAM.
- Returns:
The default max_size in bytes. By default, half the available RAM.
- Return type:
int
- get_indices(slice_index: int) → tuple
Get the indices of the images stored in the spooled files.
- Parameters:
slice_index (int) – The slice index.
- Returns:
The start and end indices of the images.
- Return type:
tuple[int, int]
- load_image(channel: int, slice_index: int) → ndarray
Load an image from a temporary file.
- Parameters:
channel (int) – The channel of the image.
slice_index (int) – The slice index of the image.
- Returns:
The image data or None if the image could not be loaded.
- Return type:
np.ndarray or None
- save_image(image: ndarray, channel: int, slice_index: int) → None
Save an image to a temporary file.
- Parameters:
image (np.ndarray) – The image to save.
channel (int) – The channel of the image.
slice_index (int) – The slice index of the image.
- channels
The number of channels.
- Type:
int
- n_bytes
The number of bytes in the image.
- Type:
int
- size_x
The width of the image.
- Type:
int
- size_y
The height of the image.
- Type:
int
- temp_files: Dict[int, SpooledTemporaryFile]
The temporary files.
- Type:
Dict[int, tempfile.SpooledTemporaryFile]