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 – 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.

class lvpyioTools.set.LVSet(set_path: Path | str)[source]

Bases: object

Helper 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:

  1. buffer (set[buffer_frame])

  2. frame (set[buffer_frame][frame_number])

  3. image (set[buffer_frame][frame_number].images[image_number])

>>> 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)}")
Parameters:

file – The path to the .set file.

set_file: Path

Path of the set_file.

set: Set | None

Holds the active set instance. If None, needs to be first opened with open().

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.

is_open() → bool[source]

Check if the set is currently open.

Returns:

True if the set is open, False otherwise.

open()[source]

Load the set with lvpyio.

close()[source]

Close the currently opened set. If no set is open, this method does nothing.

is_experiment() → bool[source]

Check if the set is an experiment set (.exp).

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 – If True, the folder will be created if it does not exist. Defaults to True.

Raises:
Returns:

The folder path corresponding to the set file.

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.

get_experiment(max_iteration: int = 100) → LVSet | None[source]

Retrieve the experiment set holding this current set if exists.

Parameters:

max_iteration – Maximum number of iterations to search for the experiment set. Defaults to 100.

Returns:

The experiment set if it exists, otherwise None.

get_children() → list[LVSet][source]

Retrieve all child sets of the current set.

Returns:

A list of child sets.

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 init is 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.

Parameters:

init – Whether to create the mask set if it does not exist. Defaults to False.

Returns:

The mask set if it exists or is created, otherwise None.

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.

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.

read() → str[source]

Read the set file and display its content.

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.

get_buffer(buffer_frame: int) → Buffer[source]

Get a specific buffer from the set.

Parameters:

buffer_frame – The index of the buffer frame to retrieve.

Raises:
Returns:

The requested buffer object.

get_frames(buffer_frame: int) → tuple[LVFrame, ...][source]
get_frame(buffer_frame: int, frame_number: int = 0) → LVFrame[source]

Get a specific frame from a buffer in the set.

Parameters:
  • buffer_frame – The index of the buffer frame to retrieve the frame from.

  • frame_number – The index of the frame within the buffer. Defaults to 0.

Returns:

The requested frame object.

get_image(buffer_frame: int, frame_number: int = 0, image_number: int = 0)[source]

Get a specific image from a frame in a buffer in the set.

Parameters:
  • buffer_frame – The index of the buffer frame to retrieve the image from.

  • frame_number – The index of the frame within the buffer. Defaults to 0.

  • image_number – The index of the image within the frame. Defaults to 0.

Returns:

The requested image object.

export(output_dir: Path, extension: str = '.tif')[source]