set¶
Helper class for working with lvpyio sets.
- lvpyioTools.set.sanitize_set_path(path: Path | str) Path[source]¶
Sanitize the provided set path.
This function ensures that the provided path points to a valid .set or .exp file. If a directory is provided, it attempts to find a .set or .exp file within that directory.
- Parameters:
path (Path | str) – The path to the .set or .exp file, or a set directory.
- Raises:
FileNotFoundError – If the provided path does not exist or no .set or .exp file is found in the directory.
ValueError – If the provided file is not a .set or .exp file.
FileNotFoundError – If no .set or .exp file is found in the provided directory.
- Returns:
The sanitized path to the .set or .exp file.
- Return type:
Path
- class lvpyioTools.set.LVSet(set_path: Path | str)[source]¶
Bases:
objectHelper class for working with DaVis sets.
Set files are simple text files that contain some generic information that were saved on creation. They don’t give any information about the actual data, where it is stored, or how to read it but the folder placed in the same directory as the set file contains all the data.
This provides a simple interface to easily manipulate and read the set files.
A set of images is handled this way in DaVis:
buffer (set[buffer_frame])
frame (set[buffer_frame][frame_number])
image (set[buffer_frame][frame_number].images[image_number])
- Parameters:
(Path) (file)
Examples
from pathlib import Path from lvpyioTools.set import LVSet set_file = Path("example/example.set") with LVSet(set_file) as lvset: lvset.show() print(f"Number of frames in the set: {len(lvset)}")
- frames: tuple[LVFrame, ...] | None¶
Holds the frames of the currently opened set. If None, the set is not open.
- get_name() str[source]¶
Get the name of the set file without its extension.
- Returns:
The stem of the set file.
- Return type:
- is_open() bool[source]¶
Check if the set is currently open.
- Returns:
True if the set is open, False otherwise.
- Return type:
- get_folder(init=True) Path[source]¶
Retrieve the folder of the set file, that is the file without the suffix “.set” or “.exp”.
- Parameters:
init (bool, optional) – If True, the folder will be created if it does not exist. Defaults to True.
- Raises:
FileNotFoundError – If the folder does not exist and
initis False.NotADirectoryError – If the path exists but is not a directory.
- Returns:
The folder path corresponding to the set file.
- Return type:
Path
- get_parent() LVSet | None[source]¶
Retrieve parent set holding this current set if exists. If the current set is an experiment set, it has no parent and this method will return None.
- Returns:
The parent set if it exists, otherwise None.
- Return type:
LVSet | None
- get_experiment(max_iteration: int = 100) LVSet | None[source]¶
Retrieve the experiment set holding this current set if exists.
- get_mask(init: bool = False) LVSet | None[source]¶
Retrieve the mask set associated with the current set.
If the mask set does not exist and
initis True, a new mask set will be created.A mask is a specifically named set file “MASK.set” inside the set folder. Using some operations you can apply that mask on your current set from within DaVis.
- make_mask() LVSet[source]¶
Create a new mask set for the current set if it does not already exist.
- Returns:
The newly created or existing mask set.
- Return type:
- get_calibration() Scales | None[source]¶
Retrieve the calibration settings from the experiment set if it exists.
- Returns:
The calibration settings if they exist, otherwise None.
- Return type:
Scales | None
- get_properties() dict[SetProperty, Any][source]¶
Read the set file and return its properties as a dictionary.
- Returns:
A dictionary containing the set properties and their values.
- Return type:
dict[SetProperty, Any]
- get_buffer(buffer_frame: int) Buffer[source]¶
Get a specific buffer from the set.
- Parameters:
buffer_frame (int) – The index of the buffer frame to retrieve.
- Raises:
RuntimeError – Set is not open.
IndexError – Buffer frame index is out of range.
- Returns:
The requested buffer object.
- Return type:
Buffer
- get_frame(buffer_frame: int, frame_number: int = 0) LVFrame[source]¶
Get a specific frame from a buffer in the set.