-
Notifications
You must be signed in to change notification settings - Fork 2
/
snirfdecode.m
65 lines (60 loc) · 2.14 KB
/
snirfdecode.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
function data = snirfdecode(root, varargin)
%
% data=snirfdecode(root)
% or
% data=snirfdecode(root,type)
% data=snirfdecode(root,{'nameA','nameB',...})
%
% Processing an HDF5 based SNIRF data and group indexed datasets into a
% cell array
%
% author: Qianqian Fang (q.fang <at> neu.edu)
%
% input:
% root: the raw input snirf data structure (loaded from loadh5.m)
% type: if type is set as a cell array of strings, it restrict the
% grouping only to the subset of field names in this list;
% if type is a string as 'snirf', it is the same as setting
% type as {'aux','data','nirs','stim','measurementList'}.
%
% output:
% data: a reorganized matlab structure. Each SNIRF data chunk is
% enclosed inside a 'SNIRFData' subfield or cell array.
%
% example:
% rawdata=loadh5('mydata.snirf');
% data=snirfdecode(rawdata);
%
% this file is part of JSNIRF specification: https://github.com/NeuroJSON/jsnirf
%
% License: Apache 2.0, see https://github.com/NeuroJSON/jsnirf for details
%
if (nargin < 1)
help snirfdecode;
return
end
data = regrouph5(root, varargin{:});
issnirf = 1;
if (~isempty(varargin))
if (ischar(varargin{1}) && strcmpi(varargin{1}, 'jsnirf'))
issnirf = 0;
end
end
if (issnirf == 0 && isfield(data, 'nirs') && isfield(data, 'formatVersion') && ~isfield(data, 'SNIRFData'))
data.SNIRFData = data.nirs;
if (isfield(data.SNIRFData, 'data') && isfield(data.SNIRFData.data, 'measurementList'))
data.SNIRFData.data.measurementList = aos2soa(data.nirs.data.measurementList);
end
if (iscell(data.nirs))
for i = 1:length(data.nirs)
data.SNIRFData{i}.formatVersion = data.formatVersion;
len = length(fieldnames(data.SNIRFData{i}));
data.SNIRFData{i} = orderfields(data.SNIRFData{i}, [len, 1:len - 1]);
end
else
data.SNIRFData.formatVersion = data.formatVersion;
len = length(fieldnames(data.SNIRFData));
data.SNIRFData = orderfields(data.SNIRFData, [len, 1:len - 1]);
end
data = rmfield(data, {'nirs', 'formatVersion'});
end