-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnirf2jbids.m
71 lines (65 loc) · 2.4 KB
/
snirf2jbids.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
function [digestdata, attachdata] = snirf2jbids(fullname, varargin)
%
% digestdata=snirf2jbids(fullname)
% or
% [digestdata, attachdata]=snirf2jbids(fullname, 'param1', value1, 'param2', value2, ...)
%
% Parse a SNIRF (for fNIRS) data file to extract lightweight metadata
% digest for easy query, along with optional organized bulk measurement
% data for saving to non-searchable attachment files in a NoSQL database
%
% author: Qianqian Fang (q.fang <at> neu.edu)
%
% input:
% fullname: the path of the snirf data file
% optional 'param'/'value' pairs: additional parameters to be passed
% to the data file parser function
%
% output:
% digestdata: a struct containing only lightweight metadata for each
% query and storage; if attachdata is not requested
% attachdata: optional output, storing a separated copy of the bulky
% binary data, can be used to lossly save the data to an
% attachment file
%
% examples:
% [snirfheader, snirfdata]= snirf2jbids('/path/bs001/subj01/nirs/subj01_test.snirf');
%
% license:
% BSD license, see LICENSE_BSD.txt files for details
%
% -- this function is part of JBIDS toolbox (https://neurojson.org/#software)
%
opt = varargin2struct(varargin{:});
pathhash = jsonopt('pathhash', fullname, opt);
attachproto = jsonopt('attachproto', 'attach:', opt);
if(~isempty(jsonopt('compression', '', opt)))
pathhash = [pathhash '-' opt.compression];
end
try
snirf = struct('SNIRFData', loadsnirf(fullname, opt));
catch
warning('encountered an error when processing %s', fullname);
digestdata = [];
attachdata = [];
return
end
if (nargout > 1)
attachdata = struct('data', snirf.SNIRFData.nirs.data);
if (isfield(snirf.SNIRFData.nirs, 'aux'))
attachdata.aux = snirf.SNIRFData.nirs.aux;
end
bytelen = length(savebj('', attachdata, 'compression','zlib'));
snirf.SNIRFData.nirs.data = struct(encodevarname('_DataLink_'), [attachproto pathhash '.jdb:$.data' '&size=' num2str(bytelen)]);
if (isfield(snirf.SNIRFData.nirs, 'aux'))
snirf.SNIRFData.nirs.aux = struct(encodevarname('_DataLink_'), [attachproto pathhash '.jdb:$.aux' '&size=' num2str(bytelen)]);
end
else
snirf.SNIRFData.nirs.data = [];
if (isfield(snirf.SNIRFData.nirs, 'aux'))
snirf.SNIRFData.nirs.aux = [];
end
end
if (nargout >= 1)
digestdata = snirf;
end