def add_task_parameters(nwbfile, task_parameters): OphysBehaviorTaskParameters = load_LabMetaData_extension(OphysBehaviorTaskParametersSchema, 'AIBS_ophys_behavior') task_parameters_clean = OphysBehaviorTaskParametersSchema().dump(task_parameters) new_task_parameters_dict = {} for key, val in task_parameters_clean.items(): if isinstance(val, list): new_task_parameters_dict[key] = np.array(val) else: new_task_parameters_dict[key] = val nwb_task_parameters = OphysBehaviorTaskParameters(name='task_parameters', **new_task_parameters_dict) nwbfile.add_lab_meta_data(nwb_task_parameters)
def add_metadata(nwbfile, metadata): OphysBehaviorMetaData = load_LabMetaData_extension(OphysBehaviorMetaDataSchema, 'AIBS_ophys_behavior') metadata_clean = OphysBehaviorMetaDataSchema().dump(metadata) new_metadata_dict = {} for key, val in metadata_clean.items(): if isinstance(val, list): new_metadata_dict[key] = np.array(val) elif isinstance(val, (datetime.datetime, uuid.UUID)): new_metadata_dict[key] = str(val) else: new_metadata_dict[key] = val nwb_metadata = OphysBehaviorMetaData(name='metadata', **new_metadata_dict) nwbfile.add_lab_meta_data(nwb_metadata)
import uuid from pandas.util.testing import assert_frame_equal import os import math import numpy as np import xarray as xr import pandas as pd from allensdk.core.lazy_property import LazyProperty from allensdk.brain_observatory.nwb.nwb_api import NwbApi from allensdk.brain_observatory.behavior.trials_processing import TRIAL_COLUMN_DESCRIPTION_DICT from allensdk.brain_observatory.behavior.schemas import OphysBehaviorMetaDataSchema, OphysBehaviorTaskParametersSchema from allensdk.brain_observatory.nwb.metadata import load_LabMetaData_extension from allensdk.brain_observatory.behavior.behavior_ophys_api import BehaviorOphysApiBase load_LabMetaData_extension(OphysBehaviorMetaDataSchema, 'AIBS_ophys_behavior') load_LabMetaData_extension(OphysBehaviorTaskParametersSchema, 'AIBS_ophys_behavior') class BehaviorOphysNwbApi(NwbApi, BehaviorOphysApiBase): def __init__(self, *args, **kwargs): self.filter_invalid_rois = kwargs.pop("filter_invalid_rois", False) super(BehaviorOphysNwbApi, self).__init__(*args, **kwargs) def save(self, session_object): nwbfile = NWBFile( session_description=str(session_object.metadata['session_type']), identifier=str(session_object.ophys_experiment_id), session_start_time=session_object.metadata['experiment_datetime'],