forked from open-ephys/analysis-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSelectOEChannels.m
More file actions
98 lines (76 loc) · 3.92 KB
/
SelectOEChannels.m
File metadata and controls
98 lines (76 loc) · 3.92 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
function data_OE = SelectOEChannels(data_OE,chanType,chanNum)
% Subsample your Open Ephys data structure down into a subset of prefered
% channels. There are multiple ways of doing this currently implemented.
% These are:
%
% Data by Name: Find the data channel by its given number/name
% Data by Idx: Find the data by total count (only counts data)
%
% IO by Name: Find the IO board channel by its given number/name
% IO by Idx: Find the IO channel by total count (only counts IO)
%
% Raw Idx: Selects the raw indx count ignoring all other factors
%
% Note that any duplicates will only be included once so redundant
% selection of channels of interest is fine.
% GWDiehl July 2024
dataPrefix = {'CH' 'AI'}; % Possible prefixes for raw data signals
IOPrefix = {'ADC'}; % Possible prefixes for IO board inputs
selectChan = [];
nTypes = length(chanType);
% Grab all of the channel names
allNames = arrayfun(@(x) x.channel_name,data_OE.Header.channels,'un',0);
for iT = 1:nTypes
switch chanType{iT}
% Go through and find the appropraite channels for each grouping of
% data
case {'DataNumber'}
for iC = 1:length(chanNum{iT})
candidateChan = find(any(cell2mat(cellfun(@(x) ismember(allNames,[x,num2str(chanNum{iT}(iC))]),dataPrefix,'un',0)),2));
assert(~isempty(candidateChan),'One of your requested channels does not exist: %s - %d',chanType{iT},chanNum{iT}(iC))
selectChan = [selectChan,candidateChan];
end
case {'DataName'}
for iC = 1:length(chanNum{iT})
candidateChan = find(any(cell2mat(cellfun(@(x) ismember(allNames,[x,chanNum{iT}{iC}]),dataPrefix,'un',0)),2));
assert(~isempty(candidateChan),'One of your requested channels does not exist: %s - %d',chanType{iT},chanNum{iT}{iC})
selectChan = [selectChan,candidateChan];
end
case {'DataIdx'}
candidateChan = find(cellfun(@(x) any(cellfun(@(y) contains(x,y),dataPrefix)),allNames))';
assert(length(candidateChan) >= max(chanNum{iT}), 'One of your requested channels does not exist')
selectChan = [selectChan,candidateChan(chanNum{iT})];
case {'IONumber'}
for iC = 1:length(chanNum{iT})
candidateChan = find(any(cell2mat(cellfun(@(x) ismember(allNames,[x,num2str(chanNum{iT}(iC))]),IOPrefix,'un',0)),2));
assert(~isempty(candidateChan),'One of your requested channels does not exist: %s - %d',chanType{iT},chanNum{iT}(iC))
selectChan = [selectChan,candidateChan];
end
case {'IOName'}
for iC = 1:length(chanNum{iT})
candidateChan = find(any(cell2mat(cellfun(@(x) ismember(allNames,[x,chanNum{iT}{iC}]),IOPrefix,'un',0)),2));
assert(~isempty(candidateChan),'One of your requested channels does not exist: %s - %d',chanType{iT},chanNum{iT}{iC})
selectChan = [selectChan,candidateChan];
end
case {'IOIdx'}
candidateChan = find(cellfun(@(x) any(cellfun(@(y) contains(x,y),IOPrefix)),allNames))';
assert(length(candidateChan) <= max(chanNum{iT}), 'One of your requested channels does not exist')
selectChan = [selectChan,candidateChan(chanNum{iT})];
case {'RawIdx'}
selectChan = [selectChan,chanNum{iT}];
end
end
% Boil down to the unique set of channels and extract out the data of
% interest
selectChan = unique(selectChan);
data_OE.Header.channels = data_OE.Header.channels(selectChan);
if isa(data_OE.Data,'memmapfile')
tempData = data_OE.Data.Data;
dataName = fieldnames(tempData);
assert(length(dataName)==1,'Your map data does not have a single field')
data_OE.Data = double(tempData.(dataName{1})(selectChan,:));
else
data_OE.Data = data_OE.Data(selectChan,:);
end
% Note that the Channel Number in the header is remaining unchanged from
% the original total of data.