def add_ragged_data_to_dynamic_table(table, data, column_name, column_description=""): """ Builds the index and data vectors required for writing ragged array data to a pynwb dynamic table Parameters ---------- table : pynwb.core.DynamicTable table to which data will be added (as VectorData / VectorIndex) data : dict each key-value pair describes some grouping of data column_name : str used to set the name of this column column_description : str, optional used to set the description of this column Returns ------- nwbfile : pynwb.NWBFile """ idx, values = dict_to_indexed_array(data, table.id.data) del data table.add_column(name=column_name, description=column_description, data=values, index=idx)
def add_trials(nwbfile, trials, description_dict={}): order = list(trials.index) for _, row in trials[['start_time', 'stop_time']].iterrows(): row_dict = row.to_dict() nwbfile.add_trial(**row_dict) for c in trials.columns: if c in ['start_time', 'stop_time']: continue index, data = dict_to_indexed_array(trials[c].to_dict(), order) if data.dtype == '<U1': # data type is composed of unicode characters data = trials[c].tolist() if not len(data) == len(order): if len(data) == 0: data = [''] nwbfile.add_trial_column(name=c, description=description_dict.get( c, 'NOT IMPLEMENTED: %s' % c), data=data, index=index) else: nwbfile.add_trial_column(name=c, description=description_dict.get( c, 'NOT IMPLEMENTED: %s' % c), data=data)
def to_nwb(self, nwbfile: NWBFile) -> NWBFile: trials = self.value order = list(trials.index) for _, row in trials[['start_time', 'stop_time']].iterrows(): row_dict = row.to_dict() nwbfile.add_trial(**row_dict) for c in trials.columns: if c in ['start_time', 'stop_time']: continue index, data = dict_to_indexed_array(trials[c].to_dict(), order) if data.dtype == '<U1': # data type is composed of unicode # characters data = trials[c].tolist() if not len(data) == len(order): if len(data) == 0: data = [''] nwbfile.add_trial_column(name=c, description='NOT IMPLEMENTED: %s' % c, data=data, index=index) else: nwbfile.add_trial_column(name=c, description='NOT IMPLEMENTED: %s' % c, data=data) return nwbfile