forked from bladonjay/Jadhav-Lab-Codes-JHB
-
Notifications
You must be signed in to change notification settings - Fork 1
/
NWBtestPlayground.m
111 lines (96 loc) · 3.95 KB
/
NWBtestPlayground.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
106
107
108
109
110
111
% NWB file creation script
% this intializes the functions youll need to use
generateCore();
% this generates a session file
nwb = NwbFile( ...
'session_description', 'rat running OdorPlaceTask',...
'identifier', 'CS31_day1', ...
'session_start_time', datetime(2018, 4, 25, 2, 30, 3), ...
'general_experimenter', 'CS', ... % optional
'general_session_id', 'CS31_1', ... % optional
'general_institution', 'Brandeis University', ... % optional
'general_related_publications', 'DOI:10.1101/2020.06.08.140939'); % optional
% generate subject
subject = types.core.Subject( ...
'subject_id', 'CS31', ...
'age', 'unknown', ...
'description', 'CS31', ...
'species', 'Rattus norvegicus', ...
'sex', 'M');
nwb.general_subject = subject;
subject
% create SpatialSeries object
% this would be an animal going from 0 to x=10, y=8 in half a second
% so for me this would be the raw spatial coordinate data
spatial_series_ts = types.core.SpatialSeries( ...
'data', [linspace(0,10,100); linspace(0,8,100)], ...
'reference_frame', '(0,0) is bottom left corner', ...
'timestamps', linspace(0, 100)/200);
% create Position object and add SpatialSeries
Position = types.core.Position('SpatialSeries', spatial_series_ts);
% create processing module
behavior_mod = types.core.ProcessingModule( 'description', 'contains behavioral data');
% add the Position object (that holds the SpatialSeries object)
behavior_mod.nwbdatainterface.set('Position', Position);
% trial data
trials = types.core.TimeIntervals( ...
'colnames', {'start_time', 'stop_time', 'correct'}, ...
'description', 'trial data and properties', ...
'id', types.hdmf_common.ElementIdentifiers('data', 0:2), ...
'start_time', types.hdmf_common.VectorData( ...
'data', [0.1, 1.5, 2.5], ...
'description','start time of trial in seconds' ...
), ...
'stop_time', types.hdmf_common.VectorData( ...
'data', [1.0, 2.0, 3.0], ...
'description','end of each trial in seconds' ...
), ...
'correct', types.hdmf_common.VectorData( ...
'data', [false, true, false], ...
'description', 'whether the trial was correct') ...
);
nwb.intervals_trials = trials;
% neural data, extracellular
nshanks = 4;
nchannels_per_shank = 3;
variables = {'x', 'y', 'z', 'imp', 'location', 'filtering', 'group', 'label'};
tbl = cell2table(cell(0, length(variables)), 'VariableNames', variables);
device = types.core.Device(...
'description', 'the best array', ...
'manufacturer', 'Probe Company 9000');
nwb.general_devices.set('array', device);
for ishank = 1:nshanks
electrode_group = types.core.ElectrodeGroup( ...
'description', ['electrode group for shank' num2str(ishank)], ...
'location', 'brain area', ...
'device', types.untyped.SoftLink(device) ...
);
nwb.general_extracellular_ephys.set(['shank' num2str(ishank)], electrode_group);
group_object_view = types.untyped.ObjectView(electrode_group);
for ielec = 1:nchannels_per_shank
electrode_label = ['shank' num2str(ishank) 'elec' num2str(ielec)];
tbl = [...
tbl; ...
{5.3, 1.5, 8.5, NaN, 'unknown', 'unknown', group_object_view, electrode_label} ...
];
end
end
tbl
%
electrode_table = util.table2nwb(tbl, 'all electrodes');
nwb.general_extracellular_ephys_electrodes = electrode_table;
%
electrode_table_region = types.hdmf_common.DynamicTableRegion( ...
'table', types.untyped.ObjectView(electrode_table), ...
'description', 'all electrodes', ...
'data', (0:height(tbl)-1)');
% this is lfp data, i think this ends up using the electrode table regions
electrical_series = types.core.ElectricalSeries( ...
'starting_time', 0.0, ... % seconds
'starting_time_rate', 30000., ... % Hz
'data', randn(12, 3000), ...
'electrodes', electrode_table_region, ...
'data_unit', 'volts');
nwb.acquisition.set('ElectricalSeries', electrical_series);
%%
nwbExport(nwb, 'intro_tutorial.nwb')