Skip to content

nwb.py

element_lab_to_nwb_dict(lab_key=None, project_key=None, protocol_key=None)

Generate a NWB-compliant dictionary object for lab metadata

Generate a dictionary object containing all relevant lab information used when generating an NWB file at the session level. All parameters optional, but should only specify one of respective type.

Parameters:

Name Type Description Default
lab_key dict

Key specifying one entry in element_lab.lab.Lab

None
project_key dict

Key specifying one entry in element_lab.lab.Project

None
protocol_key dict

Key specifying one entry in element_lab.lab.Protocol

None

Returns:

Name Type Description
dict dict

Dictionary with NWB parameters.

Source code in element_lab/export/nwb.py
 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
106
107
108
109
110
111
112
113
114
115
116
117
118
def element_lab_to_nwb_dict(
    lab_key: dict = None, project_key: dict = None, protocol_key: dict = None
) -> dict:
    """Generate a NWB-compliant dictionary object for lab metadata

    Generate a dictionary object containing all relevant lab information used
       when generating an NWB file at the session level.
       All parameters optional, but should only specify one of respective type.

    Args:
        lab_key (dict, optional): Key specifying one entry in element_lab.lab.Lab
        project_key (dict, optional): Key specifying one entry in element_lab.lab.Project
        protocol_key (dict, optional): Key specifying one entry in element_lab.lab.Protocol

    Returns:
        dict: Dictionary with NWB parameters.
    """
    # Validate input
    assert any([lab_key, project_key, protocol_key]), "Must specify one key."
    assert (
        lab_key is None or len(lab.Lab & lab_key) == 1
    ), "Multiple labs error! The lab_key should specify only one lab."
    assert (
        project_key is None
        or len(lab.Project & project_key) == 1
        or len(project.Project & project_key) == 1
    ), "Multiple projects error! The project_key should specify only one project."
    assert (
        protocol_key is None or len(lab.Protocol & protocol_key) == 1
    ), "Multiple protocols error! The protocol_key should specify only one protocol."

    element_info = dict()
    if lab_key:
        element_info.update(_lab_to_nwb_dict(lab_key))
    if project_key:
        element_info.update(_project_to_nwb_dict(project_key))
    if protocol_key:
        element_info.update(_protocol_to_nwb_dict(protocol_key))

    return element_info