Repository navigation
Expand file tree
/
Copy pathTrialDataInterface.m
More file actions
143 lines (120 loc) · 5.54 KB
/
Copy pathTrialDataInterface.m
File metadata and controls
143 lines (120 loc) · 5.54 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
classdef TrialDataInterface < handle & matlab.mixin.Copyable
% TrialDataInterface is an AbstractImplementor class which acts as a wrapper
% around a set of trials. Subclasses must provide a list of ChannelDescriptors
% for each data channel within, and provide an accessor for channels by name
methods(Abstract)
% return a string describing the data set wrapped by this TDI
datasetName = getDatasetName(tdi, varargin);
% return a scalar struct containing any arbitrary metadata
datasetMeta = getDatasetMeta(tdi, varargin);
% return the number of trials wrapped by this interface
nTrials = getTrialCount(tdi, varargin);
% return the name of the time unit used by this interface
timeUnitName = getTimeUnitName(tdi, varargin);
% Describe the channels present in the dataset
% channelDescriptors: scalar struct. fields are channel names, values are ChannelDescriptor
channelDescriptors = getChannelDescriptors(tdi, varargin);
% return a nTrials x 1 struct with all the data for each specified channel
% in channelNames cellstr array
%
% the fields of this struct are determined as:
% .channelName for the primary data associated with that channel
% .channelName_extraData for extra data fields associated with that channel
% e.g. for an AnalogChannel, .channelName_time
% e.g. for an EventChannel, .channelName_tags
%
% channelNames may include any of the channels returned by getChannelDescriptors()
% as well as any of the following "special" channels used by TrialData:
%
% subject : string, subject from whom the data were collected
% protocol : string, protocol in which the data were collected
% protocolVersion: numeric version identifier for that protocol
% trialId : a unique numeric identifier for this trial
% trialIdStr: a unique string describing this trial
% saveTag : a numeric identifier for the containing block of trials
% duration : time length of each trial in tUnits
% tStartWallclock : wallclock datenum indicating when this trial began
% tStopWallclock : wallclock datenum indicating when this trial ended
%
channelData = getChannelData(tdi, channelNames, varargin);
end
methods % optional support for appending new trials with new channels on the fly
% The equivalent of getChannelDescriptors, except only new channels that do not exist
% need be added
function channelDescriptors = getNewChannelDescriptors(tdi, varargin)
channelDescriptors = [];
end
function channelData = getNewChannelData(tdi, channelNames, varargin)
channelData = struct([]);
end
function markNewChannelDataAsReceived(tdi)
end
end
methods
% return the time conversion factor, i.e. number of time units in 1 second
function N = getTimeUnitsPerSecond(tdi, varargin)
timeUnitName = tdi.getTimeUnitName();
N = TrialDataInterface.lookupTimeUnitsPerSecond(timeUnitName);
end
end
methods(Static)
function N = lookupTimeUnitsPerSecond(timeUnitName)
switch(timeUnitName)
case 'ms'
N = 1000;
case 's'
N = 1;
otherwise
error('Unrecognized timeUnits %s', timeUnitName);
end
end
end
methods(Sealed)
% build ParamChannelDescriptors around each of the special param names
% .special will be marked as true
function cds = getSpecialParamChannelDescriptors(tdi)
tUnits = tdi.getTimeUnitName();
cd = ParamChannelDescriptor.buildStringParam('subject');
cd.special = true;
cd.required = false;
cd.displayGroup = 'special';
cds = cd;
cd = ParamChannelDescriptor.buildStringParam('protocol');
cd.special = true;
cd.required = false;
cd.displayGroup = 'special';
cds(end+1) = cd;
cd = ParamChannelDescriptor.buildScalarParam('protocolVersion');
cd.special = true;
cd.required = false;
cd.displayGroup = 'special';
cds(end+1) = cd;
cd = ParamChannelDescriptor.buildScalarParam('trialId');
cd.special = true;
cd.required = false;
cd.displayGroup = 'special';
cds(end+1) = cd;
cd = ParamChannelDescriptor.buildScalarParam('saveTag');
cd.special = true;
cd.required = false;
cd.displayGroup = 'special';
cds(end+1) = cd;
cd = ParamChannelDescriptor.buildDatenumParam('timeStartWallclock');
cd.special = true;
cd.required = false;
cd.displayGroup = 'special';
cds(end+1) = cd;
% these two are required to do time alignment
cd = EventChannelDescriptor.buildSingleEvent('TrialStart', tUnits);
cd.special = true;
cd.required = true;
cd.displayGroup = 'special';
cds(end+1) = cd;
cd = EventChannelDescriptor.buildSingleEvent('TrialEnd', tUnits);
cd.special = true;
cd.required = true;
cd.displayGroup = 'special';
cds(end+1) = cd;
end
end
end