Skip to content

Commit

Permalink
update utils and tutorials
Browse files Browse the repository at this point in the history
* create_indexed_column no longer needs the path
* update ecephys tutorial to use objects instead of paths
    * generate new html
* update ophys tutorial to use objects instead of paths
    * generate new html
  • Loading branch information
bendichter committed Aug 17, 2021
1 parent 6361b50 commit 33533fd
Show file tree
Hide file tree
Showing 11 changed files with 409 additions and 772 deletions.
20 changes: 10 additions & 10 deletions +util/createElectrodeTable.m
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
function table = createElectrodeTable()
table = types.hdmf_common.DynamicTable(...
'description', 'A table of all electrodes (i.e. channels) used for recording.', ...
'colnames', {'x', 'y', 'z', 'imp', 'location', 'filtering', 'group', 'group_name'},...
'id', types.hdmf_common.ElementIdentifiers('data', []),...
'x', types.hdmf_common.VectorData('data', [],...
'description', 'the x coordinate of the channel location'),...
'description', 'the x coordinate of the channel location'),...
'y', types.hdmf_common.VectorData('data', [],...
'description', 'the y coordinate of the channel location'),...
'description', 'the y coordinate of the channel location'),...
'z', types.hdmf_common.VectorData('data', [],...
'description', 'the z coordinate of the channel location'),...
'description', 'the z coordinate of the channel location'),...
'imp', types.hdmf_common.VectorData('data', [],...
'description', 'the impedance of the channel'),...
'description', 'the impedance of the channel'),...
'location', types.hdmf_common.VectorData('data', {},...
'description', 'the location of channel within the subject e.g. brain region'),...
'description', 'the location of channel within the subject e.g. brain region'),...
'filtering', types.hdmf_common.VectorData('data', [],...
'description', 'description of hardware filtering'),...
'description', 'description of hardware filtering'),...
'group', types.hdmf_common.VectorData('data', types.untyped.ObjectView.empty,...
'description', 'a reference to the ElectrodeGroup this electrodes is a part of'),...
'description', 'a reference to the ElectrodeGroup this electrodes is a part of'),...
'group_name', types.hdmf_common.VectorData('data', {},...
'description', 'name of the ElectrodeGroup this electrode is a part of'),...
'description', 'A table of all electrodes (i.e. channels) used for recording.'...
);
'description', 'name of the ElectrodeGroup this electrode is a part of')...
);
end

18 changes: 0 additions & 18 deletions +util/createUnitTimes.m

This file was deleted.

51 changes: 26 additions & 25 deletions +util/create_indexed_column.m
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
function [data_vector, data_index] = create_indexed_column(data, path, ids, description, table)
function [data_vector, data_index] = create_indexed_column(data, description, table)
%CREATE_INDEXED_COLUMN creates the index and vector NWB objects for storing
%a vector column in an NWB DynamicTable
%
% [DATA_VECTOR, DATA_INDEX] = CREATE_INDEXED_COLUMN(DATA, PATH)
% [DATA_VECTOR, DATA_INDEX] = CREATE_INDEXED_COLUMN(DATA)
% expects DATA as a cell array where each cell is all of the data
% for a row and PATH is the path to the indexed data in the NWB file
% EXAMPLE: [data_vector, data_index] = util.create_indexed_colum({[1,2,3], [1,2,3,4]}, '/units/spike_times')
%
% [DATA_VECTOR, DATA_INDEX] = CREATE_INDEXED_COLUMN(DATA, PATH, IDS)
% expects DATA as a single array 1D of doubles and IDS as a single 1D array of ints.
% EXAMPLE: [data_vector, data_index] = util.create_indexed_colum([1,2,3,1,2,3,4], '/units/spike_times', [0,0,0,1,1,1,1])
% EXAMPLE: [data_vector, data_index] = util.create_indexed_colum({[1,2,3], [1,2,3,4]})
%
% [DATA_VECTOR, DATA_INDEX] = CREATE_INDEXED_COLUMN(DATA, PATH, IDS, DESCRIPTION)
% [DATA_VECTOR, DATA_INDEX] = CREATE_INDEXED_COLUMN(DATA, DESCRIPTION)
% adds the string DESCRIPTION in the description field of the data vector
%
% [DYNAMICTABLEREGION, DATA_INDEX] = CREATE_INDEXED_COLUMN(DATA, PATH, IDS, DESCRIPTION, TABLE)
% [DYNAMICTABLEREGION, DATA_INDEX] = CREATE_INDEXED_COLUMN(DATA, DESCRIPTION, TABLE)
% If TABLE is supplied as on ObjectView of an NWB DynamicTable, a
% DynamicTableRegion is instead output which references this table.
% DynamicTableRegions can be indexed just like DataVectors
Expand All @@ -23,27 +19,32 @@
description = 'no description';
end

if ~exist('ids', 'var') || isempty(ids)
bounds = NaN(length(data),1);
for i = 1:length(data)
bounds(i) = length(data{i});
end
bounds = int64(cumsum(bounds));
data = cell2mat(data)';
else
[sorted_ids, order] = sort(ids);
data = data(order);
bounds = int64([find(diff(sorted_ids)), length(ids)]);
bounds = NaN(length(data), 1);
for i = 1:length(data)
bounds(i) = length(data{i});
end
bounds = int64(cumsum(bounds));

data = cell2mat(data)';

if exist('table', 'var')
data_vector = types.hdmf_common.DynamicTableRegion('table', table, ...
'description', description, 'data', data);
data_vector = types.hdmf_common.DynamicTableRegion( ...
'table', table, ...
'description', description, ...
'data', data ...
);
else
data_vector = types.hdmf_common.VectorData('data', data, 'description', description);
data_vector = types.hdmf_common.VectorData( ...
'data', data, ...
'description', description ...
);
end

ov = types.untyped.ObjectView(path);
data_index = types.hdmf_common.VectorIndex('data', bounds, 'target', ov);
ov = types.untyped.ObjectView(data_vector);
data_index = types.hdmf_common.VectorIndex( ...
'data', bounds, ...
'target', ov, ...
'description', 'indexes data' ...
);


16 changes: 0 additions & 16 deletions +util/create_spike_times.m

This file was deleted.

10 changes: 3 additions & 7 deletions +util/read_indexed_column.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function data = read_indexed_column(vector_index, vector_data, row)
%READ_INDEXED_COLUMN returns the data for a specific row of an indexed vector
%
% DATA = READ_INDEXED_COLUMN(VECTOR_INDEX, ROW) takes a VectorIndex from a
% DATA = READ_INDEXED_COLUMN(VECTOR_INDEX, VECTRO_DATA, ROW) takes a VectorIndex from a
% DynamicTable and a ROW number and outputs the DATA for that row (1-indexed).

try
Expand All @@ -18,12 +18,8 @@
lower_bound = vector_index.data(row - 1) + 1;
end
end
%%
% Then select the corresponding spike_times_index element
if isa(vector_data.data,'types.untyped.DataStub')
data = vector_data.data.load(lower_bound,upper_bound);
else
data = vector_data.data(lower_bound:upper_bound);

data = vector_data.data(lower_bound:upper_bound);
end


2 changes: 1 addition & 1 deletion +util/table2nwb.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
if ~strcmp(col.Properties.VariableNames{1},'id')
nwbtable.vectordata.set(col.Properties.VariableNames{1}, ...
types.hdmf_common.VectorData('data', col.Variables',...
'description','my description'));
'description', 'my description'));
end
end
Loading

0 comments on commit 33533fd

Please sign in to comment.