Commit b6db3394 authored by James Desjardins's avatar James Desjardins
Browse files

Initial commit of bids compliant lossless EEG pipline.

parents
This data was user for "Deconstructing the early visual electrocortical responses to face and house stimuli" 2013: http://jov.arvojournals.org/article.aspx?articleid=2121634
The study was conducted at Brock University.
Experimental paradigm and Procedure:
Subjects viewed stimuli presented for 300ms with an inster-stimulus-interval of about 1 second. Stimulus images were either faces (upright or inverted), houses (upright or inverted) or half-circle checkerboards (left or right). The subjects were asked to respond as quickly as possible by pressing buttons with their left and right index fingers corresponding to the side of the checkerboard at onset.
Data aquisition:
EEG data acquired using 128 channel BioSemi ActiveTwo system with a custom cap montage.
function [string] = cell2tsv(fname,cell_in,format_str)
% '%s %d %2.1f %s\n'
fid = fopen(fname,'w');
[nrows,ncols] = size(cell_in);
for row = 1:nrows
if row==1
for col=1:ncols;
if col==1;
if ncols==1;
head_format_str=['%s','\n'];
else
head_format_str=['%s','\t'];
end
elseif col<ncols;
head_format_str=[head_format_str,'%s','\t'];
else
head_format_str=[head_format_str,'%s','\n'];
end
end
fprintf(fid,[head_format_str],cell_in{row,:});
else
fprintf(fid,[format_str],cell_in{row,:});
end
end
end
mk_dataset_description;
savejson('',dataset_description,'bids/dataset_description.json');
mk_participants;
cell2tsv('bids/participants.tsv',participants,'%s\t%d\n');
function init_bids_sub(rootfname)
sidecar_eeg=mk_sidecar_eeg([rootfname,'_eeg.set']);
savejson('',sidecar_eeg,[rootfname,'_eeg.json']);
channels=mk_channels([rootfname,'_eeg.set']);
cell2tsv([rootfname,'_channels.tsv'],channels,'%s\t%s\t%s\n');
electrodes=mk_electrodes([rootfname,'_eeg.set']);
cell2tsv([rootfname,'_electrodes.tsv'],electrodes,'%s\t%5.3f\t%5.3f\t%5.3f\t%s\t%s\n');
events=mk_events([rootfname,'_eeg.set']);
cell2tsv([rootfname,'_events.tsv'],events,'%5.3f\t%5.3f\t%s\n');
# Created by .ignore support plugin (hsz.mobi)
.idea
.DS_store
Thumbs.db
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pids
*.pid
*.seed
*.pid.lock
lib-cov
coverage
.nyc_output
.grunt
bower_components
.lock-wscript
build/Release
node_modules/
jspm_packages/
typings/
.npm
.eslintcache
.node_repl_history
*.tgz
.yarn-integrity
.env
*.asv
*.m~
*.mex*
slprj/
octave-workspace
.autosave
The author of "jsonlab" toolbox is Qianqian Fang. Qianqian
is currently an Assistant Professor in the Department of Bioengineering,
Northeastern University.
Address: Qianqian Fang
Department of Bioengineering
Northeastern University
212A Lake Hall
360 Huntington Ave, Boston, MA 02115, USA
Office: 503 Holmes Hall
Phone[O]: 617-373-3829
URL: http://fanglab.org
Email: <q.fang at neu.edu> and <fangqq at gmail.com>
The script loadjson.m was built upon previous works by
- Nedialko Krouchev: http://www.mathworks.com/matlabcentral/fileexchange/25713
date: 2009/11/02
- François Glineur: http://www.mathworks.com/matlabcentral/fileexchange/23393
date: 2009/03/22
- Joel Feenstra: http://www.mathworks.com/matlabcentral/fileexchange/20565
date: 2008/07/03
This toolbox contains patches submitted by the following contributors:
- Blake Johnson <bjohnso at bbn.com>
part of revision 341
- Niclas Borlin <Niclas.Borlin at cs.umu.se>
various fixes in revision 394, including
- loadjson crashes for all-zero sparse matrix.
- loadjson crashes for empty sparse matrix.
- Non-zero size of 0-by-N and N-by-0 empty matrices is lost after savejson/loadjson.
- loadjson crashes for sparse real column vector.
- loadjson crashes for sparse complex column vector.
- Data is corrupted by savejson for sparse real row vector.
- savejson crashes for sparse complex row vector.
- Yul Kang <yul.kang.on at gmail.com>
patches for svn revision 415.
- savejson saves an empty cell array as [] instead of null
- loadjson differentiates an empty struct from an empty array
- Mykhailo Bratukha <bratukha.m at gmail.com>
(Pull#14) Bug fix: File path is wrongly inerpreted as JSON string
- Insik Kim <insik92 at gmail.com>
(Pull#12) Bug fix: Resolving bug that cell type is converted to json with transposed data
- Sertan Senturk <contact at sertansenturk.com>
(Pull#10,#11) Feature: Added matlab object saving to savejson and saveubjson
============================================================================
JSONlab - a toolbox to encode/decode JSON/UBJSON files in MATLAB/Octave
----------------------------------------------------------------------------
JSONlab ChangeLog (key features marked by *):
== JSONlab 1.5 (codename: Nominus - alpha), FangQ <q.fang <at> neu.edu> ==
2017/01/02 *use Big-endian format to store floating points (d/D) in saveubjson (Issue #25)
2017/01/02 *speedup parsing large unstructured data by 2x (Issue #9)
2017/01/01 make parsing independent of white space (Issue #30)
2016/08/27 allow to parse array of homogeneous elements (Issue 5)
2016/08/22 permit [] inside file names in savejson
2016/01/06 fix a bug that prevents saving to a file in savejson
== JSONlab 1.2 (codename: Optimus - Update 2), FangQ <q.fang <at> neu.edu> ==
2015/12/16 replacing string concatenation by str cells to gain 2x speed in savejson (Issue#17)
2015/12/11 fix FileName option case bug (SVN rev#495)
2015/12/11 add SingletCell option, add SingletArray to replace NoRowBracket (Issue#15,#8)
2015/11/10 fix bug for inerpreting file names as JSON string - by Mykhailo Bratukha (Pull#14)
2015/10/16 fix bug for cell with transposed data - by Insik Kim (Pull#12)
2015/09/25 support exporting matlab object to JSON - by Sertan Senturk (Pull#10, #11)
== JSONlab 1.1 (codename: Optimus - Update 1), FangQ <q.fang <at> neu.edu> ==
2015/05/05 *massively accelerating loadjson for parsing large collection of unstructured small objects
2015/05/05 force array bracket in 1x1 struct to maintain depth (Issue#1)
2015/05/05 parse logicals in loadjson
2015/05/05 make options case insensitive
2015/05/01 reading unicode encoded json files (thanks to Sertan Senturk,Issue#3)
2015/04/30 allow \uXXXX to represent a unicode in a string (Issue#2)
2015/03/30 save a 0x0 solid real empty array as null and handel empty struct array
2015/03/30 properly handle escape characters in a string
2015/01/24 *implement the UBJSON Draft12 new name format
2015/01/13 correct cell array indentation inconsistency
== JSONlab 1.0 (codename: Optimus - Final), FangQ <q.fang <at> neu.edu> ==
2015/01/02 polish help info for all major functions, update examples, finalize 1.0
2014/12/19 fix a bug to strictly respect NoRowBracket in savejson
== JSONlab 1.0.0-RC2 (codename: Optimus - RC2), FangQ <q.fang <at> neu.edu> ==
2014/11/22 show progress bar in loadjson ('ShowProgress')
2014/11/17 *add Compact option in savejson to output compact JSON format ('Compact')
2014/11/17 add FastArrayParser in loadjson to specify fast parser applicable levels
2014/09/18 *start official github mirror: https://github.com/fangq/jsonlab
== JSONlab 1.0.0-RC1 (codename: Optimus - RC1), FangQ <q.fang <at> neu.edu> ==
2014/09/17 fix several compatibility issues when running on octave versions 3.2-3.8
2014/09/17 *support 2D cell and struct arrays in both savejson and saveubjson
2014/08/04 escape special characters in a JSON string
2014/02/16 fix a bug when saving ubjson files
== JSONlab 0.9.9 (codename: Optimus - beta), FangQ <q.fang <at> neu.edu> ==
2014/01/22 use binary read and write in saveubjson and loadubjson
== JSONlab 0.9.8-1 (codename: Optimus - alpha update 1), FangQ <q.fang <at> neu.edu> ==
2013/10/07 better round-trip conservation for empty arrays and structs (patch submitted by Yul Kang)
== JSONlab 0.9.8 (codename: Optimus - alpha), FangQ <q.fang <at> neu.edu> ==
2013/08/23 *universal Binary JSON (UBJSON) support, including both saveubjson and loadubjson
== JSONlab 0.9.1 (codename: Rodimus, update 1), FangQ <q.fang <at> neu.edu> ==
2012/12/18 *handling of various empty and sparse matrices (fixes submitted by Niclas Borlin)
== JSONlab 0.9.0 (codename: Rodimus), FangQ <q.fang <at> neu.edu> ==
2012/06/17 *new format for an invalid leading char, unpacking hex code in savejson
2012/06/01 support JSONP in savejson
2012/05/25 fix the empty cell bug (reported by Cyril Davin)
2012/04/05 savejson can save to a file (suggested by Patrick Rapin)
== JSONlab 0.8.1 (codename: Sentiel, Update 1), FangQ <q.fang <at> neu.edu> ==
2012/02/28 loadjson quotation mark escape bug, see http://bit.ly/yyk1nS
2012/01/25 patch to handle root-less objects, contributed by Blake Johnson
== JSONlab 0.8.0 (codename: Sentiel), FangQ <q.fang <at> neu.edu> ==
2012/01/13 *speed up loadjson by 20 fold when parsing large data arrays in matlab
2012/01/11 remove row bracket if an array has 1 element, suggested by Mykel Kochenderfer
2011/12/22 *accept sequence of 'param',value input in savejson and loadjson
2011/11/18 fix struct array bug reported by Mykel Kochenderfer
== JSONlab 0.5.1 (codename: Nexus Update 1), FangQ <q.fang <at> neu.edu> ==
2011/10/21 fix a bug in loadjson, previous code does not use any of the acceleration
2011/10/20 loadjson supports JSON collections - concatenated JSON objects
== JSONlab 0.5.0 (codename: Nexus), FangQ <q.fang <at> neu.edu> ==
2011/10/16 package and release jsonlab 0.5.0
2011/10/15 *add json demo and regression test, support cpx numbers, fix double quote bug
2011/10/11 *speed up readjson dramatically, interpret _Array* tags, show data in root level
2011/10/10 create jsonlab project, start jsonlab website, add online documentation
2011/10/07 *speed up savejson by 25x using sprintf instead of mat2str, add options support
2011/10/06 *savejson works for structs, cells and arrays
2011/09/09 derive loadjson from JSON parser from MATLAB Central, draft savejson.m
Copyright 2011-2017 Qianqian Fang <q.fang <at> neu.edu>. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those of the
authors and should not be interpreted as representing official policies, either expressed
or implied, of the copyright holders.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Demonstration of Basic Utilities of JSONlab
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rngstate = rand ('state');
randseed=hex2dec('623F9A9E');
clear data2json json2data
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a simple scalar value \n')
fprintf(1,'%%=================================================\n\n')
data2json=pi
savejson('',data2json)
json2data=loadjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a complex number\n')
fprintf(1,'%%=================================================\n\n')
clear i;
data2json=1+2*i
savejson('',data2json)
json2data=loadjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a complex matrix\n')
fprintf(1,'%%=================================================\n\n')
data2json=magic(6);
data2json=data2json(:,1:3)+data2json(:,4:6)*i
savejson('',data2json)
json2data=loadjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% MATLAB special constants\n')
fprintf(1,'%%=================================================\n\n')
data2json=[NaN Inf -Inf]
savejson('specials',data2json)
json2data=loadjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a real sparse matrix\n')
fprintf(1,'%%=================================================\n\n')
data2json=sprand(10,10,0.1)
savejson('sparse',data2json)
json2data=loadjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a complex sparse matrix\n')
fprintf(1,'%%=================================================\n\n')
data2json=data2json-data2json*i
savejson('complex_sparse',data2json)
json2data=loadjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% an all-zero sparse matrix\n')
fprintf(1,'%%=================================================\n\n')
data2json=sparse(2,3);
savejson('all_zero_sparse',data2json)
json2data=loadjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% an empty sparse matrix\n')
fprintf(1,'%%=================================================\n\n')
data2json=sparse([]);
savejson('empty_sparse',data2json)
json2data=loadjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% an empty 0-by-0 real matrix\n')
fprintf(1,'%%=================================================\n\n')
data2json=[];
savejson('empty_0by0_real',data2json)
json2data=loadjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% an empty 0-by-3 real matrix\n')
fprintf(1,'%%=================================================\n\n')
data2json=zeros(0,3);
savejson('empty_0by3_real',data2json)
json2data=loadjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a sparse real column vector\n')
fprintf(1,'%%=================================================\n\n')
data2json=sparse([0,3,0,1,4]');
savejson('sparse_column_vector',data2json)
json2data=loadjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a sparse complex column vector\n')
fprintf(1,'%%=================================================\n\n')
data2json=data2json-1i*data2json;
savejson('complex_sparse_column_vector',data2json)
json2data=loadjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a sparse real row vector\n')
fprintf(1,'%%=================================================\n\n')
data2json=sparse([0,3,0,1,4]);
savejson('sparse_row_vector',data2json)
json2data=loadjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a sparse complex row vector\n')
fprintf(1,'%%=================================================\n\n')
data2json=data2json-1i*data2json;
savejson('complex_sparse_row_vector',data2json)
json2data=loadjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a structure\n')
fprintf(1,'%%=================================================\n\n')
data2json=struct('name','Think Different','year',1997,'magic',magic(3),...
'misfits',[Inf,NaN],'embedded',struct('left',true,'right',false))
savejson('astruct',data2json,struct('ParseLogical',1))
json2data=loadjson(ans)
class(json2data.astruct.embedded.left)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a structure array\n')
fprintf(1,'%%=================================================\n\n')
data2json=struct('name','Nexus Prime','rank',9);
data2json(2)=struct('name','Sentinel Prime','rank',9);
data2json(3)=struct('name','Optimus Prime','rank',9);
savejson('Supreme Commander',data2json)
json2data=loadjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a cell array\n')
fprintf(1,'%%=================================================\n\n')
data2json=cell(3,1);
data2json{1}=struct('buzz',1.1,'rex',1.2,'bo',1.3,'hamm',2.0,'slink',2.1,'potato',2.2,...
'woody',3.0,'sarge',3.1,'etch',4.0,'lenny',5.0,'squeeze',6.0,'wheezy',7.0);
data2json{2}=struct('Ubuntu',['Kubuntu';'Xubuntu';'Lubuntu']);
data2json{3}=[10.04,10.10,11.04,11.10]
savejson('debian',data2json,struct('FloatFormat','%.2f'))
json2data=loadjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% invalid field-name handling\n')
fprintf(1,'%%=================================================\n\n')
json2data=loadjson('{"ValidName":1, "_InvalidName":2, ":Field:":3, "项目":"绝密"}')
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a 2D cell array\n')
fprintf(1,'%%=================================================\n\n')
data2json={{1,{2,3}},{4,5},{6};{7},{8,9},{10}};
savejson('data2json',data2json)
json2data=loadjson(ans) % only savejson works for cell arrays, loadjson has issues
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a 2D struct array\n')
fprintf(1,'%%=================================================\n\n')
data2json=repmat(struct('idx',0,'data','structs'),[2,3])
for i=1:6
data2json(i).idx=i;
end
savejson('data2json',data2json)
json2data=loadjson(ans)
rand ('state',rngstate);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Demonstration of Basic Utilities of JSONlab
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rngstate = rand ('state');
randseed=hex2dec('623F9A9E');
clear data2json json2data
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a simple scalar value \n')
fprintf(1,'%%=================================================\n\n')
data2json=pi
saveubjson('',data2json)
json2data=loadubjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a complex number\n')
fprintf(1,'%%=================================================\n\n')
clear i;
data2json=1+2*i
saveubjson('',data2json)
json2data=loadubjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a complex matrix\n')
fprintf(1,'%%=================================================\n\n')
data2json=magic(6);
data2json=data2json(:,1:3)+data2json(:,4:6)*i
saveubjson('',data2json)
json2data=loadubjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% MATLAB special constants\n')
fprintf(1,'%%=================================================\n\n')
data2json=[NaN Inf -Inf]
saveubjson('specials',data2json)
json2data=loadubjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a real sparse matrix\n')
fprintf(1,'%%=================================================\n\n')
data2json=sprand(10,10,0.1)
saveubjson('sparse',data2json)
json2data=loadubjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a complex sparse matrix\n')
fprintf(1,'%%=================================================\n\n')
data2json=data2json-data2json*i
saveubjson('complex_sparse',data2json)
json2data=loadubjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% an all-zero sparse matrix\n')
fprintf(1,'%%=================================================\n\n')
data2json=sparse(2,3);
saveubjson('all_zero_sparse',data2json)
json2data=loadubjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% an empty sparse matrix\n')
fprintf(1,'%%=================================================\n\n')
data2json=sparse([]);
saveubjson('empty_sparse',data2json)
json2data=loadubjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% an empty 0-by-0 real matrix\n')
fprintf(1,'%%=================================================\n\n')
data2json=[];
saveubjson('empty_0by0_real',data2json)
json2data=loadubjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% an empty 0-by-3 real matrix\n')
fprintf(1,'%%=================================================\n\n')
data2json=zeros(0,3);
saveubjson('empty_0by3_real',data2json)
json2data=loadubjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a sparse real column vector\n')
fprintf(1,'%%=================================================\n\n')
data2json=sparse([0,3,0,1,4]');
saveubjson('sparse_column_vector',data2json)
json2data=loadubjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a sparse complex column vector\n')
fprintf(1,'%%=================================================\n\n')
data2json=data2json-1i*data2json;
saveubjson('complex_sparse_column_vector',data2json)
json2data=loadubjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a sparse real row vector\n')
fprintf(1,'%%=================================================\n\n')
data2json=sparse([0,3,0,1,4]);
saveubjson('sparse_row_vector',data2json)
json2data=loadubjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a sparse complex row vector\n')
fprintf(1,'%%=================================================\n\n')
data2json=data2json-1i*data2json;
saveubjson('complex_sparse_row_vector',data2json)
json2data=loadubjson(ans)
fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a structure\n')
fprintf(1,'%%=================================================\n\n')
data2json=struct('name','Think Different','year',1997,'magic',magic(3),...
'misfits',[Inf,NaN],'embedded',struct('left',true,'right',false))
saveubjson('astruct',data2json,struct('ParseLogical',1))