Skip to content

data_mapper.helpers

get_cameras

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

Retrieves a dictionary of cameras from the given 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 AindBehaviorRigModel

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]

Dict[str, CameraTypes]: A dictionary mapping camera names to their types

Source code in src/clabe/data_mapper/helpers.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def get_cameras(
    rig_instance: AindBehaviorRigModel, exclude_without_video_writer: bool = True
) -> Dict[str, CameraTypes]:
    """
    Retrieves a dictionary of cameras from the given 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:
        Dict[str, CameraTypes]: 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, including installed packages.

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

Returns:

Type Description
Dict[str, str]

Dict[str, str]: A dictionary of package names and their versions

Example
# Capture the current Python environment:
env_snapshot = snapshot_python_environment()
# Returns: {'numpy': '1.24.3', 'pandas': '2.0.1', 'aind-data-schema': '0.15.0', ...}

# Use for debugging package versions:
packages = snapshot_python_environment()
print(f"NumPy version: {packages.get('numpy', 'Not installed')}")
# Prints: NumPy version: 1.24.3
Source code in src/clabe/data_mapper/helpers.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def snapshot_python_environment() -> Dict[str, str]:
    """
    Captures a snapshot of the current Python environment, including installed packages.

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

    Returns:
        Dict[str, str]: A dictionary of package names and their versions

    Example:
        ```python
        # Capture the current Python environment:
        env_snapshot = snapshot_python_environment()
        # Returns: {'numpy': '1.24.3', 'pandas': '2.0.1', 'aind-data-schema': '0.15.0', ...}

        # Use for debugging package versions:
        packages = snapshot_python_environment()
        print(f"NumPy version: {packages.get('numpy', 'Not installed')}")
        # Prints: NumPy version: 1.24.3
        ```
    """
    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 the given configuration file.

Parses the Bonsai configuration file to extract information about installed packages and their versions, creating a snapshot of the Bonsai environment.

Parameters:

Name Type Description Default
config_file PathLike

Path to the Bonsai configuration file

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

Returns:

Type Description
Dict[str, str]

Dict[str, str]: A dictionary of package IDs and their versions

Example
# Capture Bonsai environment from default config:
bonsai_env = snapshot_bonsai_environment()
# Returns: {'Bonsai.Core': '2.7.0', 'Bonsai.Vision': '2.8.0', 'Bonsai.Spinnaker': '0.3.0', ...}

# Capture from custom config file:
custom_env = snapshot_bonsai_environment("./custom/bonsai.config")
# Returns: {'Bonsai.Core': '2.6.0', 'Bonsai.Arduino': '2.7.0', ...}
Source code in src/clabe/data_mapper/helpers.py
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def snapshot_bonsai_environment(
    config_file: os.PathLike = Path("./bonsai/bonsai.config"),
) -> Dict[str, str]:
    """
    Captures a snapshot of the Bonsai environment from the given configuration file.

    Parses the Bonsai configuration file to extract information about installed
    packages and their versions, creating a snapshot of the Bonsai environment.

    Args:
        config_file: Path to the Bonsai configuration file

    Returns:
        Dict[str, str]: A dictionary of package IDs and their versions

    Example:
        ```python
        # Capture Bonsai environment from default config:
        bonsai_env = snapshot_bonsai_environment()
        # Returns: {'Bonsai.Core': '2.7.0', 'Bonsai.Vision': '2.8.0', 'Bonsai.Spinnaker': '0.3.0', ...}

        # Capture from custom config file:
        custom_env = snapshot_bonsai_environment("./custom/bonsai.config")
        # Returns: {'Bonsai.Core': '2.6.0', 'Bonsai.Arduino': '2.7.0', ...}
        ```
    """
    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}