Skip to content

data_mapper.helpers

get_cameras

get_cameras(
    rig_instance: Rig,
    exclude_without_video_writer: bool = True,
) -> Dict[str, CameraTypes]

Retrieves cameras from a rig instance.

Extracts camera information from camera controllers within the rig model, optionally filtering based on video writer availability.

Parameters:

Name Type Description Default
rig_instance Rig

The rig model instance containing camera controllers

required
exclude_without_video_writer bool

If True, exclude cameras without a video writer

True

Returns:

Type Description
Dict[str, CameraTypes]

A dictionary mapping camera names to their types

Source code in src/clabe/data_mapper/helpers.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def get_cameras(rig_instance: Rig, exclude_without_video_writer: bool = True) -> Dict[str, CameraTypes]:
    """
    Retrieves cameras from a rig instance.

    Extracts camera information from camera controllers within the rig model,
    optionally filtering based on video writer availability.

    Args:
        rig_instance: The rig model instance containing camera controllers
        exclude_without_video_writer: If True, exclude cameras without a video writer

    Returns:
        A dictionary mapping camera names to their types
    """
    cameras: dict[str, CameraTypes] = {}
    camera_controllers = [x[1] for x in get_fields_of_type(rig_instance, CameraController)]

    for controller in camera_controllers:
        if exclude_without_video_writer:
            these_cameras = {k: v for k, v in controller.cameras.items() if v.video_writer is not None}
        else:
            these_cameras = controller.cameras
        cameras.update(these_cameras)
    return cameras

snapshot_python_environment

snapshot_python_environment() -> Dict[str, str]

Captures a snapshot of the current Python environment.

Creates a record of all currently installed Python packages and their versions, useful for reproducibility and debugging purposes.

Returns:

Type Description
Dict[str, str]

A dictionary of package names and their versions

Source code in src/clabe/data_mapper/helpers.py
45
46
47
48
49
50
51
52
53
54
55
def snapshot_python_environment() -> Dict[str, str]:
    """
    Captures a snapshot of the current Python environment.

    Creates a record of all currently installed Python packages and their versions,
    useful for reproducibility and debugging purposes.

    Returns:
        A dictionary of package names and their versions
    """
    return {dist.name: dist.version for dist in metadata.distributions()}

snapshot_bonsai_environment

snapshot_bonsai_environment(
    config_file: PathLike = Path("./bonsai/bonsai.config"),
) -> Dict[str, str]

Captures a snapshot of the Bonsai environment from a configuration file.

Parses the Bonsai configuration file to extract information about installed packages and their versions.

Parameters:

Name Type Description Default
config_file PathLike

Path to the Bonsai configuration file

Path('./bonsai/bonsai.config')

Returns:

Type Description
Dict[str, str]

A dictionary of package IDs and their versions

Source code in src/clabe/data_mapper/helpers.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def snapshot_bonsai_environment(
    config_file: os.PathLike = Path("./bonsai/bonsai.config"),
) -> Dict[str, str]:
    """
    Captures a snapshot of the Bonsai environment from a configuration file.

    Parses the Bonsai configuration file to extract information about installed
    packages and their versions.

    Args:
        config_file: Path to the Bonsai configuration file

    Returns:
        A dictionary of package IDs and their versions
    """
    tree = ET.parse(Path(config_file))
    root = tree.getroot()
    packages = root.findall("Packages/Package")
    return {leaf.attrib["id"]: leaf.attrib["version"] for leaf in packages}