forked from fieldtrip/fieldtrip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data2bids.m
2561 lines (2309 loc) · 154 KB
/
data2bids.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function [cfg] = data2bids(cfg, varargin)
% DATA2BIDS is a helper function to convert MRI, MEG, EEG, iEEG or NIRS data to the
% Brain Imaging Data Structure. The overall idea is that you write a MATLAB script in
% which you call this function multiple times, once for each individually recorded
% data file (or data set). It will write the corresponding sidecar JSON and TSV files
% for each data file.
%
% Use as
% data2bids(cfg)
% or as
% data2bids(cfg, data)
%
% The first input argument 'cfg' is the configuration structure, which contains the
% details for the (meta)data and which specifies the sidecar files you want to write.
% The optional 'data' argument corresponds to preprocessed raw data according to
% FT_DATAYPE_RAW or an anatomical MRI according to FT_DATAYPE_VOLUME. The optional
% data input argument allows you to write preprocessed electrophysiological data
% and/or realigned and defaced anatomical MRI to disk.
%
% The configuration structure should contains
% cfg.method = string, can be 'decorate', 'copy' or 'convert', see below (default is automatic)
% cfg.dataset = string, filename of the input data
% cfg.outputfile = string, optional filename for the output data (default is automatic)
% cfg.writejson = string, 'yes', 'replace', 'merge' or 'no' (default = 'yes')
% cfg.writetsv = string, 'yes', 'replace', 'merge' or 'no' (default = 'yes')
%
% This function starts from existing data file on disk or from a FieldTrip compatible
% data structure in MATLAB memory that is passed as the second input argument.
% Depending on cfg.method it will add the sidecar files, copy the dataset and add
% sidecar files, or convert the dataset and add the sidecar files. Each of the
% methods is discussed here.
%
% DECORATE - data2bids will read the header details and events from the data and write
% the appropriate sidecar files alongside the existing dataset. You would use this to
% obtain the sidecar files for data files that are already in the BIDS organization.
%
% CONVERT - data2bids will read the input data (or use the specified input data) and
% write it to a new output file that is BIDS compliant. The output format is NIfTI
% for MRI data, and BrainVision for EEG and iEEG. Note that MEG data files are stored
% in BIDS in their native format and this function will NOT convert them for you.
%
% COPY - data2bids will copy the data from the input data file to the output data
% file, which renames it, but does not change its content. Furthermore, it will read
% the header details and events from the data and construct the appropriate sidecar
% files.
%
% Although you can explicitly specify cfg.outputfile yourself, it is recommended to
% use the following configuration options. This results in a BIDS compliant output
% directory and file name. With these options data2bids will also write, or if
% already present update the participants.tsv and scans.tsv files.
% cfg.bidsroot = string, top level directory for the BIDS output
% cfg.sub = string, subject name
% cfg.ses = string, optional session name
% cfg.run = number, optional
% cfg.task = string, task name is required for functional data
% cfg.datatype = string, can be any of 'FLAIR', 'FLASH', 'PD', 'PDT2', 'PDmap', 'T1map', 'T1rho', 'T1w', 'T2map', 'T2star', 'T2w', 'angio', 'audio', 'bold', 'bval', 'bvec', 'channels', 'coordsystem', 'defacemask', 'dwi', 'eeg', 'emg', 'epi', 'events', 'exg', 'eyetracker', 'fieldmap', 'headshape', 'ieeg', 'inplaneT1', 'inplaneT2', 'magnitude', 'magnitude1', 'magnitude2', 'meg', 'motion', 'nirs', 'phase1', 'phase2', 'phasediff', 'photo', 'physio', 'sbref', 'stim', 'video'
% cfg.acq = string
% cfg.ce = string
% cfg.rec = string
% cfg.dir = string
% cfg.mod = string
% cfg.echo = string
% cfg.proc = string
% cfg.tracksys = string
% cfg.space = string
% cfg.desc = string
%
% When specifying the output directory in cfg.bidsroot, you can also specify
% additional information to be added as extra columns in the participants.tsv and
% scans.tsv files. For example:
% cfg.participants.age = scalar
% cfg.participants.sex = string, 'm' or 'f'
% cfg.scans.acq_time = string, should be formatted according to RFC3339 as '2019-05-22T15:13:38'
% In case any of these values is specified as empty (i.e. []) or as nan, it will be
% written to the tsv file as 'n/a'.
%
% For anatomical and functional MRI data you can specify cfg.dicomfile to read the
% detailed MRI scanner and sequence details from the header of that DICOM file. This
% will be used to fill in the details of the corresponding JSON file.
% cfg.dicomfile = string, filename of a matching DICOM file for header details (default = [])
% cfg.deface = string, 'yes' or 'no' (default = 'no')
%
% You can specify cfg.events as a Nx3 matrix with the trial definition (see
% FT_DEFINETRIAL) or as a MATLAB table. When specified as table, the first three
% columns containing integer values corresponding to the begsample, endsample and
% offset, the additional colums can be of another type and have any name. If you do
% not specify the trial definition, the events will be read from the MEG/EEG/iEEG
% dataset. Events from the trial definition or from the data will be written to
% events.tsv.
% cfg.events = trial definition (see FT_DEFINETRIAL) or event structure (see FT_READ_EVENT)
%
% If NBS Presentation was used in combination with another functional data type, you
% can specify cfg.presentationfile with the name of the presentation log file, which
% will be aligned with the data based on triggers (MEG/EEG/iEEG) or based on the
% volumes (fMRI). Events from the presentation log file will also be written to
% events.tsv. To indicate how triggers (in MEG/EEG/iEEG) or volumes (in fMRI) match
% the presentation events, you should specify the mapping between them.
% cfg.presentationfile = string, optional filename for the presentation log file
% cfg.trigger.eventtype = string (default = [])
% cfg.trigger.eventvalue = string or number
% cfg.trigger.skip = 'last'/'first'/'none'
% cfg.presentation.eventtype = string (default = [])
% cfg.presentation.eventvalue = string or number
% cfg.presentation.skip = 'last'/'first'/'none'
%
% For EEG and iEEG data you can specify an electrode definition according to
% FT_DATATYPE_SENS as an "elec" field in the input data, or you can specify it as
% cfg.elec or you can specify a filename with electrode information.
% cfg.elec = structure with electrode positions or filename, see FT_READ_SENS
%
% For NIRS data you can specify an optode definition according to
% FT_DATATYPE_SENS as an "opto" field in the input data, or you can specify
% it as cfg.opto or you can specify a filename with optode information.
% cfg.opto = structure with optode positions or filename,see FT_READ_SENS
%
% General BIDS options that apply to all data types are
% cfg.InstitutionName = string
% cfg.InstitutionAddress = string
% cfg.InstitutionalDepartmentName = string
% cfg.Manufacturer = string
% cfg.ManufacturersModelName = string
% cfg.DeviceSerialNumber = string
% cfg.SoftwareVersions = string
%
% If you specify cfg.bidsroot, this function will also write the dataset_description.json
% file. You can specify the following fields
% cfg.dataset_description.writesidecar = string
% cfg.dataset_description.Name = string
% cfg.dataset_description.BIDSVersion = string
% cfg.dataset_description.License = string
% cfg.dataset_description.Authors = string or cell-array of strings
% cfg.dataset_description.Acknowledgements = string
% cfg.dataset_description.HowToAcknowledge = string
% cfg.dataset_description.Funding = string or cell-array of strings
% cfg.dataset_description.ReferencesAndLinks = string or cell-array of strings
% cfg.dataset_description.DatasetDOI = string
%
% General BIDS options that apply to all functional data types are
% cfg.TaskName = string
% cfg.TaskDescription = string
% cfg.Instructions = string
% cfg.CogAtlasID = string
% cfg.CogPOID = string
%
% There are more BIDS options for the mri/meg/eeg/ieeg data type specific sidecars.
% Rather than listing them all here, please open this function in the MATLAB editor,
% and scroll down a bit to see what those are. In general the information in the JSON
% files is specified by a field that is specified in CamelCase
% cfg.mri.SomeOption = string, please check the MATLAB code
% cfg.meg.SomeOption = string, please check the MATLAB code
% cfg.eeg.SomeOption = string, please check the MATLAB code
% cfg.ieeg.SomeOption = string, please check the MATLAB code
% cfg.nirs.SomeOption = string, please check the MATLAB code
% cfg.coordsystem.someoption = string, please check the MATLAB code
% The information for TSV files is specified with a column header in lowercase or
% snake_case and represents a list of items
% cfg.channels.someoption = cell-array, please check the MATLAB code
% cfg.events.someoption = cell-array, please check the MATLAB code
% cfg.electrodes.someoption = cell-array, please check the MATLAB code
% cfg.optodes.someoption = cell-array, please check the MATLAB code
%
% The implementation in this function aims to correspond to the latest BIDS version.
% See https://bids-specification.readthedocs.io/ for the full specification
% and http://bids.neuroimaging.io/ for further details.
%
% See also FT_DATAYPE_RAW, FT_DATAYPE_VOLUME, FT_DATATYPE_SENS, FT_DEFINETRIAL,
% FT_PREPROCESSING, FT_READ_MRI, FT_READ_EVENT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Undocumented options exist for converting some other data types to BIDS:
% - emg
% - exg
% - audio
% - video
% - eyetracking
% - motion
% - physio
% - stim
%
% Most of these data types are currently (Oct 2020) not supported in the BIDS
% specification, but this function converts them in a very similar way as the
% officially supported data types.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright (C) 2018-2020, Robert Oostenveld
%
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
% for the documentation and details.
%
% FieldTrip is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% FieldTrip is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
%
% $Id$
% these are used by the ft_preamble/ft_postamble function and scripts
ft_revision = '$Id$';
ft_nargin = nargin;
ft_nargout = nargout;
% do the general setup of the function
ft_defaults
ft_preamble init
ft_preamble debug
if ft_abort
% do not continue function execution in case the outputfile is present and the user indicated to keep it
return
end
% ensure backward compatibility
cfg = ft_checkconfig(cfg, 'renamed', {'participant', 'participants'}); % this was wrong in the documentation
cfg = ft_checkconfig(cfg, 'renamed', {'anat', 'mri'});
cfg = ft_checkconfig(cfg, 'renamedval', {'native', 'no', 'convert'});
cfg = ft_checkconfig(cfg, 'renamedval', {'native', 'yes', 'copy'});
cfg = ft_checkconfig(cfg, 'renamed', {'native', 'method'});
cfg = ft_checkconfig(cfg, 'renamed', {'mri.deface', 'deface'});
cfg = ft_checkconfig(cfg, 'renamed', {'mri.writesidecar', 'writejson'});
cfg = ft_checkconfig(cfg, 'renamed', {'meg.writesidecar', 'writejson'});
cfg = ft_checkconfig(cfg, 'renamed', {'eeg.writesidecar', 'writejson'});
cfg = ft_checkconfig(cfg, 'renamed', {'ieeg.writesidecar', 'writejson'});
cfg = ft_checkconfig(cfg, 'renamed', {'events.writesidecar', 'writejson'});
cfg = ft_checkconfig(cfg, 'renamed', {'channels.writesidecar', 'writejson'});
cfg = ft_checkconfig(cfg, 'renamed', {'electrodes.writesidecar', 'writejson'});
cfg = ft_checkconfig(cfg, 'renamed', {'coordsystem.writesidecar', 'writejson'});
cfg = ft_checkconfig(cfg, 'renamed', {'event', 'events'}); % cfg.event is used elsewhere in FieldTrip, but here it should be cfg.events with an s
% get the options and set the defaults
cfg.method = ft_getopt(cfg, 'method'); % default is handled below
cfg.dataset = ft_getopt(cfg, 'dataset');
cfg.feedback = ft_getopt(cfg, 'feedback', 'yes');
cfg.outputfile = ft_getopt(cfg, 'outputfile'); % default is handled below
cfg.presentationfile = ft_getopt(cfg, 'presentationfile'); % full path to the NBS presentation log file, it will be read and parsed using FT_READ_EVENT
cfg.presentation = ft_getopt(cfg, 'presentation');
cfg.presentation.eventtype = ft_getopt(cfg.presentation, 'eventtype');
cfg.presentation.eventvalue = ft_getopt(cfg.presentation, 'eventvalue');
cfg.presentation.skip = ft_getopt(cfg.presentation, 'skip', 'last'); % this is a sensible default for fMRI, for MEG one should probably do 'none'
cfg.trigger = ft_getopt(cfg, 'trigger');
cfg.trigger.eventtype = ft_getopt(cfg.trigger, 'eventtype');
cfg.trigger.eventvalue = ft_getopt(cfg.trigger, 'eventvalue');
cfg.trigger.skip = ft_getopt(cfg.trigger, 'skip', 'none');
% these are used to construct the directory and file name
cfg.bidsroot = ft_getopt(cfg, 'bidsroot');
cfg.sub = ft_getopt(cfg, 'sub');
cfg.ses = ft_getopt(cfg, 'ses');
cfg.task = ft_getopt(cfg, 'task');
cfg.tracksys = ft_getopt(cfg, 'tracksys');
cfg.acq = ft_getopt(cfg, 'acq');
cfg.ce = ft_getopt(cfg, 'ce');
cfg.rec = ft_getopt(cfg, 'rec');
cfg.dir = ft_getopt(cfg, 'dir');
cfg.run = ft_getopt(cfg, 'run');
cfg.mod = ft_getopt(cfg, 'mod');
cfg.echo = ft_getopt(cfg, 'echo');
cfg.proc = ft_getopt(cfg, 'proc');
cfg.space = ft_getopt(cfg, 'space');
cfg.desc = ft_getopt(cfg, 'desc');
cfg.datatype = ft_getopt(cfg, 'datatype');
% do a sanity check on the fields that form the filename as key-value pair
fn = {'sub', 'ses', 'task', 'tracksys', 'acq', 'ce', 'rec', 'dir', 'run', 'mod', 'echo', 'proc', 'space', 'desc'};
for i=1:numel(fn)
if ischar(cfg.(fn{i})) && any(cfg.(fn{i})=='-')
ft_error('the field cfg.%s cannot contain a "-"', fn{i});
end
end
if isempty(cfg.datatype)
modality = {'meg', 'eeg', 'ieeg', 'emg', 'exg', 'audio', 'video', 'eyetracker', 'physio', 'stim', 'motion', 'nirs'};
for i=1:numel(modality)
if isfield(cfg, modality{i}) && ~isempty(cfg.(modality{i}))
% the user specified modality-specific options, assume that the datatype matches
cfg.datatype = modality{i};
ft_notice('assuming that the datatype is %s', cfg.datatype);
continue
end
end % for each modality
end
cfg.dicomfile = ft_getopt(cfg, 'dicomfile'); % get header details from the specified DICOM files
cfg.deface = ft_getopt(cfg, 'deface', 'no'); % whether to deface the anatomical MRI
cfg.writejson = ft_getopt(cfg, 'writejson', 'merge'); % whether to write the json file
cfg.writetsv = ft_getopt(cfg, 'writetsv', 'merge'); % whether to write the tsv file
cfg.mri = ft_getopt(cfg, 'mri');
cfg.meg = ft_getopt(cfg, 'meg');
cfg.eeg = ft_getopt(cfg, 'eeg');
cfg.ieeg = ft_getopt(cfg, 'ieeg');
cfg.emg = ft_getopt(cfg, 'emg');
cfg.exg = ft_getopt(cfg, 'exg');
cfg.nirs = ft_getopt(cfg, 'nirs');
cfg.audio = ft_getopt(cfg, 'audio');
cfg.video = ft_getopt(cfg, 'video');
cfg.eyetracker = ft_getopt(cfg, 'eyetracker');
cfg.physio = ft_getopt(cfg, 'physio');
cfg.stim = ft_getopt(cfg, 'stim');
cfg.motion = ft_getopt(cfg, 'motion');
cfg.channels = ft_getopt(cfg, 'channels');
cfg.electrodes = ft_getopt(cfg, 'electrodes');
cfg.optodes = ft_getopt(cfg, 'optodes');
cfg.events = ft_getopt(cfg, 'events'); % this can contain the trial definition as Nx3 array, as table, or an event structure
cfg.coordsystem = ft_getopt(cfg, 'coordsystem');
%% Dataset description
cfg.dataset_description = ft_getopt(cfg, 'dataset_description' );
cfg.dataset_description.writesidecar = ft_getopt(cfg.dataset_description, 'writesidecar', 'yes' );
cfg.dataset_description.Name = ft_getopt(cfg.dataset_description, 'Name' ); % REQUIRED. Name of the dataset.
cfg.dataset_description.BIDSVersion = ft_getopt(cfg.dataset_description, 'BIDSVersion', '1.6' ); % REQUIRED. The version of the BIDS standard that was used.
cfg.dataset_description.DatasetType = ft_getopt(cfg.dataset_description, 'DatasetType', 'raw' ); % RECOMMENDED. The interpretaton of the dataset. MUST be one of "raw" or "derivative". For backwards compatibility, the default value is "raw".
cfg.dataset_description.License = ft_getopt(cfg.dataset_description, 'License' ); % RECOMMENDED. What license is this dataset distributed under? The use of license name abbreviations is suggested for specifying a license. A list of common licenses with suggested abbreviations can be found in Appendix II.
cfg.dataset_description.Authors = ft_getopt(cfg.dataset_description, 'Authors' ); % OPTIONAL. List of individuals who contributed to the creation/curation of the dataset.
cfg.dataset_description.Acknowledgements = ft_getopt(cfg.dataset_description, 'Acknowledgements' ); % OPTIONAL. Text acknowledging contributions of individuals or institutions beyond those listed in Authors or Funding.
cfg.dataset_description.HowToAcknowledge = ft_getopt(cfg.dataset_description, 'HowToAcknowledge' ); % OPTIONAL. Instructions how researchers using this dataset should acknowledge the original authors. This field can also be used to define a publication that should be cited in publications that use the dataset.
cfg.dataset_description.Funding = ft_getopt(cfg.dataset_description, 'Funding' ); % OPTIONAL. List of sources of funding (grant numbers)
cfg.dataset_description.EthicsApprovals = ft_getopt(cfg.dataset_description, 'EthicsApprovals' ); % OPTIONAL. List of ethics committee approvals of the research protocols and/or protocol identifiers.
cfg.dataset_description.ReferencesAndLinks = ft_getopt(cfg.dataset_description, 'ReferencesAndLinks' ); % OPTIONAL. List of references to publication that contain information on the dataset, or links.
cfg.dataset_description.DatasetDOI = ft_getopt(cfg.dataset_description, 'DatasetDOI' ); % OPTIONAL. The Document Object Identifier of the dataset (not the corresponding paper).
%% Generic fields for all data types
cfg.TaskName = ft_getopt(cfg, 'TaskName' ); % REQUIRED. Name of the task (for resting state use the "rest" prefix). Different Tasks SHOULD NOT have the same name. The Task label is derived from this field by removing all non alphanumeric ([a-zA-Z0-9]) characters.
cfg.TaskDescription = ft_getopt(cfg, 'TaskDescription' ); % OPTIONAL. Description of the task.
cfg.Instructions = ft_getopt(cfg, 'Instructions' ); % OPTIONAL. Text of the instructions given to participants before the scan. This is not only important for behavioral or cognitive tasks but also in resting state paradigms (e.g. to distinguish between eyes open and eyes closed).
cfg.CogAtlasID = ft_getopt(cfg, 'CogAtlasID' ); % OPTIONAL. URL of the corresponding "Cognitive Atlas term that describes the task (e.g. Resting State with eyes closed ""http://www.cognitiveatlas.org/term/id/trm_54e69c642d89b""")
cfg.CogPOID = ft_getopt(cfg, 'CogPOID' ); % OPTIONAL. URL of the corresponding "CogPO term that describes the task (e.g. Rest "http://wiki.cogpo.org/index.php?title=Rest")
cfg.Manufacturer = ft_getopt(cfg, 'Manufacturer' ); % OPTIONAL. Manufacturer of the recording system ("CTF", ""Neuromag/Elekta"", ""4D/BTi"", ""KIT/Yokogawa"", ""ITAB"", "KRISS", "Other")
cfg.ManufacturersModelName = ft_getopt(cfg, 'ManufacturersModelName' ); % OPTIONAL. Manufacturer's designation of the model (e.g. "CTF-275"). See "Appendix VII" with preferred names
cfg.DeviceSerialNumber = ft_getopt(cfg, 'DeviceSerialNumber' ); % OPTIONAL. The serial number of the equipment that produced the composite instances. A pseudonym can also be used to prevent the equipment from being identifiable, as long as each pseudonym is unique within the dataset.
cfg.SoftwareVersions = ft_getopt(cfg, 'SoftwareVersions' ); % OPTIONAL. Manufacturer's designation of the acquisition software.
cfg.InstitutionName = ft_getopt(cfg, 'InstitutionName' ); % OPTIONAL. The name of the institution in charge of the equipment that produced the composite instances.
cfg.InstitutionAddress = ft_getopt(cfg, 'InstitutionAddress' ); % OPTIONAL. The address of the institution in charge of the equipment that produced the composite instances.
cfg.InstitutionalDepartmentName = ft_getopt(cfg, 'InstitutionalDepartmentName' ); % The department in the institution in charge of the equipment that produced the composite instances. Corresponds to DICOM Tag 0008, 1040 "Institutional Department Name".
%% MR Scanner Hardware
cfg.mri.StationName = ft_getopt(cfg.mri, 'StationName' ); % Institution defined name of the machine that produced the composite instances. Corresponds to DICOM Tag 0008, 1010 "Station Name"
cfg.mri.HardcopyDeviceSoftwareVersion = ft_getopt(cfg.mri, 'HardcopyDeviceSoftwareVersion' ); % (Deprecated) Manufacturer's designation of the software of the device that created this Hardcopy Image (the printer). Corresponds to DICOM Tag 0018, 101A "Hardcopy Device Software Version".
cfg.mri.MagneticFieldStrength = ft_getopt(cfg.mri, 'MagneticFieldStrength' ); % Nominal field strength of MR magnet in Tesla. Corresponds to DICOM Tag 0018,0087 "Magnetic Field Strength" .
cfg.mri.ReceiveCoilName = ft_getopt(cfg.mri, 'ReceiveCoilName' ); % Information describing the receiver coil. Corresponds to DICOM Tag 0018, 1250 "Receive Coil Name", although not all vendors populate that DICOM Tag, in which case this field can be derived from an appropriate private DICOM field.
cfg.mri.ReceiveCoilActiveElements = ft_getopt(cfg.mri, 'ReceiveCoilActiveElements' ); % Information describing the active/selected elements of the receiver coil. This doesn't correspond to a tag in the DICOM ontology. The vendor-defined terminology for active coil elements can go in this field. As an example, for Siemens, coil channels are typically not activated/selected individually, but rather in pre-defined selectable "groups" of individual channels, and the list of the "groups" of elements that are active/selected in any given scan populates the "Coil String" entry in Siemen's private DICOM fields (e.g., "HEA;HEP" for the Siemens standard 32 ch coil when both the anterior and posterior groups are activated). This is a flexible field that can be used as most appropriate for a given vendor and coil to define the "active" coil elements. Since individual scans can sometimes not have the intended coil elements selected, it is preferable for this field to be populated directly from the DICOM for each individual scan, so that it can be used as a mechanism for checking that a given scan was collected with the intended coil elements selected.
cfg.mri.GradientSetType = ft_getopt(cfg.mri, 'GradientSetType' ); % It should be possible to infer the gradient coil from the scanner model. If not,e.g. because of a custom upgrade or use of a gradient insert set, then the specifications of the actual gradient coil should be reported independently.
cfg.mri.MRTransmitCoilSequence = ft_getopt(cfg.mri, 'MRTransmitCoilSequence' ); % This is a relevant field if a non-standard transmit coil is used. Corresponds to DICOM Tag 0018, 9049 "MR Transmit Coil Sequence".
cfg.mri.MatrixCoilMode = ft_getopt(cfg.mri, 'MatrixCoilMode' ); % (If used) A method for reducing the number of independent channels by combining in analog the signals from multiple coil elements. There are typically different default modes when using un-accelerated or accelerated (e.g. GRAPPA, SENSE) imaging.
cfg.mri.CoilCombinationMethod = ft_getopt(cfg.mri, 'CoilCombinationMethod' ); % Almost all fMRI studies using phased-array coils use root-sum-of-squares (rSOS) combination, but other methods exist. The image reconstruction is changed by the coil combination method (as for the matrix coil mode above), so anything non-standard should be reported.
%% MR Sequence Specifics
cfg.mri.PulseSequenceType = ft_getopt(cfg.mri, 'PulseSequenceType' ); % A general description of the pulse sequence used for the scan (i.e. MPRAGE, Gradient Echo EPI, Spin Echo EPI, Multiband gradient echo EPI).
cfg.mri.ScanningSequence = ft_getopt(cfg.mri, 'ScanningSequence' ); % Description of the type of data acquired. Corresponds to DICOM Tag 0018, 0020 "Sequence Sequence".
cfg.mri.SequenceVariant = ft_getopt(cfg.mri, 'SequenceVariant' ); % Variant of the ScanningSequence. Corresponds to DICOM Tag 0018, 0021 "Sequence Variant".
cfg.mri.ScanOptions = ft_getopt(cfg.mri, 'ScanOptions' ); % Parameters of ScanningSequence. Corresponds to DICOM Tag 0018, 0022 "Scan Options".
cfg.mri.SequenceName = ft_getopt(cfg.mri, 'SequenceName' ); % Manufacturer's designation of the sequence name. Corresponds to DICOM Tag 0018, 0024 "Sequence Name".
cfg.mri.PulseSequenceDetails = ft_getopt(cfg.mri, 'PulseSequenceDetails' ); % Information beyond pulse sequence type that identifies the specific pulse sequence used (i.e. "Standard Siemens Sequence distributed with the VB17 software," "Siemens WIP ### version #.##," or "Sequence written by X using a version compiled on MM/DD/YYYY").
cfg.mri.NonlinearGradientCorrection = ft_getopt(cfg.mri, 'NonlinearGradientCorrection' ); % Boolean stating if the image saved has been corrected for gradient nonlinearities by the scanner sequence.
%% MR In-Plane Spatial Encoding
cfg.mri.NumberShots = ft_getopt(cfg.mri, 'NumberShots' ); % The number of RF excitations need to reconstruct a slice or volume. Please mind that this is not the same as Echo Train Length which denotes the number of lines of k-space collected after an excitation.
cfg.mri.ParallelReductionFactorInPlan = ft_getopt(cfg.mri, 'ParallelReductionFactorInPlane' ); % The parallel imaging (e.g, GRAPPA) factor. Use the denominator of the fraction of k-space encoded for each slice. For example, 2 means half of k-space is encoded. Corresponds to DICOM Tag 0018, 9069 "Parallel Reduction Factor In-plane".
cfg.mri.ParallelAcquisitionTechnique = ft_getopt(cfg.mri, 'ParallelAcquisitionTechnique' ); % The type of parallel imaging used (e.g. GRAPPA, SENSE). Corresponds to DICOM Tag 0018, 9078 "Parallel Acquisition Technique".
cfg.mri.PartialFourier = ft_getopt(cfg.mri, 'PartialFourier' ); % The fraction of partial Fourier information collected. Corresponds to DICOM Tag 0018, 9081 "Partial Fourier".
cfg.mri.PartialFourierDirection = ft_getopt(cfg.mri, 'PartialFourierDirection' ); % The direction where only partial Fourier information was collected. Corresponds to DICOM Tag 0018, 9036 "Partial Fourier Direction".
cfg.mri.PhaseEncodingDirection = ft_getopt(cfg.mri, 'PhaseEncodingDirection' ); % Possible values = []; % "i", "j", "k", "i-", "j-", "k-". The letters "i", "j", "k" correspond to the first, second and third axis of the data in the NIfTI file. The polarity of the phase encoding is assumed to go from zero index to maximum index unless "-" sign is present (then the order is reversed - starting from the highest index instead of zero). PhaseEncodingDirection is defined as the direction along which phase is was modulated which may result in visible distortions. Note that this is not the same as the DICOM term InPlanePhaseEncodingDirection which can have "ROW" or "COL" values. This parameter is REQUIRED if corresponding fieldmap data is present or when using multiple runs with different phase encoding directions (which can be later used for field inhomogeneity correction).
cfg.mri.EffectiveEchoSpacing = ft_getopt(cfg.mri, 'EffectiveEchoSpacing' ); % The "effective" sampling interval, specified in seconds, between lines in the phase-encoding direction, defined based on the size of the reconstructed image in the phase direction. It is frequently, but incorrectly, referred to as "dwell time" (see DwellTime parameter below for actual dwell time). It is required for unwarping distortions using field maps. Note that beyond just in-plane acceleration, a variety of other manipulations to the phase encoding need to be accounted for properly, including partial fourier, phase oversampling, phase resolution, phase field-of-view and interpolation. This parameter is REQUIRED if corresponding fieldmap data is present.
cfg.mri.TotalReadoutTime = ft_getopt(cfg.mri, 'TotalReadoutTime' ); % This is actually the "effective" total readout time , defined as the readout duration, specified in seconds, that would have generated data with the given level of distortion. It is NOT the actual, physical duration of the readout train. If EffectiveEchoSpacing has been properly computed, it is just EffectiveEchoSpacing * (ReconMatrixPE - 1). . This parameter is REQUIRED if corresponding "field/distortion" maps acquired with opposing phase encoding directions are present (see 8.9.4).
%% MR Timing Parameters
cfg.mri.EchoTime = ft_getopt(cfg.mri, 'EchoTime' ); % The echo time (TE) for the acquisition, specified in seconds. This parameter is REQUIRED if corresponding fieldmap data is present or the data comes from a multi echo sequence. Corresponds to DICOM Tag 0018, 0081 "Echo Time" (please note that the DICOM term is in milliseconds not seconds).
cfg.mri.InversionTime = ft_getopt(cfg.mri, 'InversionTime' ); % The inversion time (TI) for the acquisition, specified in seconds. Inversion time is the time after the middle of inverting RF pulse to middle of excitation pulse to detect the amount of longitudinal magnetization. Corresponds to DICOM Tag 0018, 0082 "Inversion Time" (please note that the DICOM term is in milliseconds not seconds).
cfg.mri.SliceTiming = ft_getopt(cfg.mri, 'SliceTiming' ); % The time at which each slice was acquired within each volume (frame) of the acquisition. Slice timing is not slice order -- rather, it is a list of times (in JSON format) containing the time (in seconds) of each slice acquisition in relation to the beginning of volume acquisition. The list goes through the slices along the slice axis in the slice encoding dimension (see below). Note that to ensure the proper interpretation of the SliceTiming field, it is important to check if the (optional) SliceEncodingDirection exists. In particular, if SliceEncodingDirection is negative, the entries in SliceTiming are defined in reverse order with respect to the slice axis (i.e., the final entry in the SliceTiming list is the time of acquisition of slice 0). This parameter is REQUIRED for sparse sequences that do not have the DelayTime field set. In addition without this parameter slice time correction will not be possible.
cfg.mri.SliceEncodingDirection = ft_getopt(cfg.mri, 'SliceEncodingDirection' ); % Possible values "i", "j", "k", "i-", "j-", "k-" (the axis of the NIfTI data along which slices were acquired, and the direction in which SliceTiming is defined with respect to). "i", "j", "k" identifiers correspond to the first, second and third axis of the data in the NIfTI file. A "-" sign indicates that the contents of SliceTiming are defined in reverse order -- that is, the first entry corresponds to the slice with the largest index, and the final entry corresponds to slice index zero. When present ,the axis defined by SliceEncodingDirection needs to be consistent with the "slice_dim" field in the NIfTI header. When absent, the entries in SliceTiming must be in the order of increasing slice index as defined by the NIfTI header.
cfg.mri.DwellTime = ft_getopt(cfg.mri, 'DwellTime' ); % Actual dwell time (in seconds) of the receiver per point in the readout direction, including any oversampling. For Siemens, this corresponds to DICOM field (0019,1018) (in ns). This value is necessary for the (optional) readout distortion correction of anatomicals in the HCP Pipelines. It also usefully provides a handle on the readout bandwidth, which isn't captured in the other metadata tags. Not to be confused with "EffectiveEchoSpacing", and the frequent mislabeling of echo spacing (which is spacing in the phase encoding direction) as "dwell time" (which is spacing in the readout direction).
%% MR RF & Contrast
cfg.mri.FlipAngle = ft_getopt(cfg.mri, 'FlipAngle' ); % Flip angle for the acquisition, specified in degrees. Corresponds to = []; % DICOM Tag 0018, 1314 "Flip Angle".
cfg.mri.MultibandAccelerationFactor = ft_getopt(cfg.mri, 'MultibandAccelerationFactor' ); % RECOMMENDED. The multiband factor, for multiband acquisitions.
cfg.mri.NegativeContrast = ft_getopt(cfg.mri, 'NegativeContrast' ); % OPTIONAL. Boolean (true or false) value specifying whether increasing voxel intensity (within sample voxels) denotes a decreased value with respect to the contrast suffix. This is commonly the case when Cerebral Blood Volume is estimated via usage of a contrast agent in conjunction with a T2* weighted acquisition protocol.
%% MR Slice Acceleration
cfg.mri.MultibandAccelerationFactor = ft_getopt(cfg.mri, 'MultibandAccelerationFactor' ); % The multiband factor, for multiband acquisitions.
%% Anatomical landmarks, useful for multimodaltimodal co-registration with MEG, (S)HeadCoil, TMS,etc
cfg.mri.AnatomicalLandmarkCoordinates = ft_getopt(cfg.mri, 'AnatomicalLandmarkCoordinates' ); % Key:value pairs of any number of additional anatomical landmarks and their coordinates in voxel units (where first voxel has index 0,0,0) relative to the associated anatomical MRI, (e.g. {"AC" = []; % [127,119,149], "PC" = []; % [128,93,141], "IH" = []; % [131,114,206]}, or {"NAS" = []; % [127,213,139], "LPA" = []; % [52,113,96], "RPA" = []; % [202,113,91]}).
%% MR Anatomical scan information
cfg.mri.ContrastBolusIngredient = ft_getopt(cfg.mri, 'ContrastBolusIngredient' ); % OPTIONAL. Active ingredient of agent. Values MUST be one of: IODINE, GADOLINIUM, CARBON DIOXIDE, BARIUM, XENON Corresponds to DICOM Tag 0018,1048.
%% MR Functional scan information
cfg.mri.RepetitionTime = ft_getopt(cfg.mri, 'RepetitionTime' ); % REQUIRED. The time in seconds between the beginning of an acquisition of one volume and the beginning of acquisition of the volume following it (TR). Please note that this definition includes time between scans (when no data has been acquired) in case of sparse acquisition schemes. This value needs to be consistent with the pixdim[4] field (after accounting for units stored in xyzt_units field) in the NIfTI header. This field is mutually exclusive with VolumeTiming and is derived from DICOM Tag 0018, 0080 and converted to seconds.
cfg.mri.VolumeTiming = ft_getopt(cfg.mri, 'VolumeTiming' ); % REQUIRED. The time at which each volume was acquired during the acquisition. It is described using a list of times (in JSON format) referring to the onset of each volume in the BOLD series. The list must have the same length as the BOLD series, and the values must be non-negative and monotonically increasing. This field is mutually exclusive with RepetitionTime and DelayTime. If defined, this requires acquisition time (TA) be defined via either SliceTiming or AcquisitionDuration be defined.
%% MEG specific fields
% Manufacturer and ManufacturersModelName are general
cfg.meg.SamplingFrequency = ft_getopt(cfg.meg, 'SamplingFrequency' ); % REQUIRED. Sampling frequency (in Hz) of all the data in the recording, regardless of their type (e.g., 2400)
cfg.meg.PowerLineFrequency = ft_getopt(cfg.meg, 'PowerLineFrequency' ); % REQUIRED. Frequency (in Hz) of the power grid at the geographical location of the MEG instrument (i.e. 50 or 60)
cfg.meg.DewarPosition = ft_getopt(cfg.meg, 'DewarPosition' ); % REQUIRED. Position of the dewar during the MEG scan: "upright", "supine" or "degrees" of angle from vertical: for example on CTF systems, upright=15??, supine = 90??.
cfg.meg.SoftwareFilters = ft_getopt(cfg.meg, 'SoftwareFilters' ); % REQUIRED. List of temporal and/or spatial software filters applied, orideally key:valuepairsofpre-appliedsoftwarefiltersandtheir parameter values: e.g., {"SSS": {"frame": "head", "badlimit": 7}}, {"SpatialCompensation": {"GradientOrder": Order of the gradient compensation}}. Write "n/a" if no software filters applied.
cfg.meg.DigitizedLandmarks = ft_getopt(cfg.meg, 'DigitizedLandmarks' ); % REQUIRED. Boolean ("true" or "false") value indicating whether anatomical landmark points (i.e. fiducials) are contained within this recording.
cfg.meg.DigitizedHeadPoints = ft_getopt(cfg.meg, 'DigitizedHeadPoints' ); % REQUIRED. Boolean ("true" or "false") value indicating whether head points outlining the scalp/face surface are contained within this recording.
cfg.meg.MEGChannelCount = ft_getopt(cfg.meg, 'MEGChannelCount' ); % OPTIONAL. Number of MEG channels (e.g. 275)
cfg.meg.MEGREFChannelCount = ft_getopt(cfg.meg, 'MEGREFChannelCount' ); % OPTIONAL. Number of MEG reference channels (e.g. 23). For systems without such channels (e.g. Neuromag Vectorview), MEGREFChannelCount"=0
cfg.meg.EEGChannelCount = ft_getopt(cfg.meg, 'EEGChannelCount' ); % OPTIONAL. Number of EEG channels recorded simultaneously (e.g. 21)
cfg.meg.ECOGChannelCount = ft_getopt(cfg.meg, 'ECOGChannelCount' ); % OPTIONAL. Number of ECoG channels
cfg.meg.SEEGChannelCount = ft_getopt(cfg.meg, 'SEEGChannelCount' ); % OPTIONAL. Number of SEEG channels
cfg.meg.EOGChannelCount = ft_getopt(cfg.meg, 'EOGChannelCount' ); % OPTIONAL. Number of EOG channels
cfg.meg.ECGChannelCount = ft_getopt(cfg.meg, 'ECGChannelCount' ); % OPTIONAL. Number of ECG channels
cfg.meg.EMGChannelCount = ft_getopt(cfg.meg, 'EMGChannelCount' ); % OPTIONAL. Number of EMG channels
cfg.meg.MiscChannelCount = ft_getopt(cfg.meg, 'MiscChannelCount' ); % OPTIONAL. Number of miscellaneous analog channels for auxiliary signals
cfg.meg.TriggerChannelCount = ft_getopt(cfg.meg, 'TriggerChannelCount' ); % OPTIONAL. Number of channels for digital (TTL bit level) triggers
cfg.meg.RecordingDuration = ft_getopt(cfg.meg, 'RecordingDuration' ); % OPTIONAL. Length of the recording in seconds (e.g. 3600)
cfg.meg.RecordingType = ft_getopt(cfg.meg, 'RecordingType' ); % OPTIONAL. Defines whether the recording is "continuous" or "epoched"; this latter limited to time windows about events of interest (e.g., stimulus presentations, subject responses etc.)
cfg.meg.EpochLength = ft_getopt(cfg.meg, 'EpochLength' ); % OPTIONAL. Duration of individual epochs in seconds (e.g. 1) in case of epoched data
cfg.meg.ContinuousHeadLocalization = ft_getopt(cfg.meg, 'ContinuousHeadLocalization' ); % OPTIONAL. Boolean ("true" or "false") value indicating whether continuous head localisation was performed.
cfg.meg.HeadCoilFrequency = ft_getopt(cfg.meg, 'HeadCoilFrequency' ); % OPTIONAL. List of frequencies (in Hz) used by the head localisation coils ("HLC" in CTF systems, "HPI" in Neuromag/Elekta, "COH" in 4D/BTi) that track the subject's head position in the MEG helmet (e.g. [293, 307, 314, 321])
cfg.meg.MaxMovement = ft_getopt(cfg.meg, 'MaxMovement' ); % OPTIONAL. Maximum head movement (in mm) detected during the recording, as measured by the head localisation coils (e.g., 4.8)
cfg.meg.SubjectArtefactDescription = ft_getopt(cfg.meg, 'SubjectArtefactDescription' ); % OPTIONAL. Freeform description of the observed subject artefact and its possible cause (e.g. "Vagus Nerve Stimulator", "non-removable implant"). If this field is set to "n/a", it will be interpreted as absence of major source of artifacts except cardiac and blinks.
cfg.meg.AssociatedEmptyRoom = ft_getopt(cfg.meg, 'AssociatedEmptyRoom' ); % OPTIONAL. Relative path in BIDS folder structure to empty-room file associated with the subject's MEG recording. The path needs to use forward slashes instead of backward slashes (e.g. "sub-emptyroom/ses-<label>/meg/sub-emptyroom_ses-<label>_ta sk-noise_run-<label>_meg.ds").
cfg.meg.HardwareFilters = ft_getopt(cfg.meg, 'HardwareFilters' ); % RECOMMENDED. List of temporal hardware filters applied. Ideally key:value pairs of pre-applied hardware filters and their parameter values: e.g., {"HardwareFilters": {"Highpass RC filter": {"Half amplitude cutoff (Hz)": 0.0159, "Roll-off": "6dB/Octave"}}}. Write n/a if no hardware filters applied.
%% Specific EEG fields - if recorded with the MEG system
cfg.meg.EEGPlacementScheme = ft_getopt(cfg.meg, 'EEGPlacementScheme' ); % OPTIONAL. Placement scheme of EEG electrodes. Either the name of a standardised placement system (e.g., "10-20") or a list of standardised electrode names (e.g. ["Cz", "Pz"]).
cfg.meg.CapManufacturer = ft_getopt(cfg.meg, 'CapManufacturer' ); % OPTIONAL. Manufacturer of the EEG cap (e.g. EasyCap)
cfg.meg.CapManufacturersModelName = ft_getopt(cfg.meg, 'CapManufacturersModelName' ); % OPTIONAL. Manufacturerâs designation of the EEG cap model (e.g., M10)
cfg.meg.EEGReference = ft_getopt(cfg.meg, 'EEGReference' ); % OPTIONAL. Description of the type of EEG reference used (e.g., M1 for left mastoid, average, or longitudinal bipolar).
%% EEG specific fields
cfg.eeg.EEGReference = ft_getopt(cfg.eeg, 'EEGReference' ); % Description of the type of reference used (common", "average", "DRL", "bipolar" ). Any specific electrode used as reference should be indicated as such in the channels.tsv file
cfg.eeg.SamplingFrequency = ft_getopt(cfg.eeg, 'SamplingFrequency' ); % Sampling frequency (in Hz) of the EEG recording (e.g. 2400)
cfg.eeg.PowerLineFrequency = ft_getopt(cfg.eeg, 'PowerLineFrequency' ); % Frequency (in Hz) of the power grid where the EEG is installed (i.e. 50 or 60).
cfg.eeg.SoftwareFilters = ft_getopt(cfg.eeg, 'SoftwareFilters' ); % List of temporal software filters applied or ideally key:value pairs of pre-applied filters and their parameter values
cfg.eeg.CapManufacturer = ft_getopt(cfg.eeg, 'CapManufacturer' ); % name of the cap manufacturer
cfg.eeg.CapManufacturersModelName = ft_getopt(cfg.eeg, 'CapManufacturersModelName' ); % Manufacturer's designation of the EEG cap model (e.g. "CAPML128", "actiCAP 64Ch Standard-2")
% Manufacturer and ManufacturersModelName are general
cfg.eeg.EEGChannelCount = ft_getopt(cfg.eeg, 'EEGChannelCount' ); % Number of EEG channels included in the recording (e.g. 128).
cfg.eeg.ECGChannelCount = ft_getopt(cfg.eeg, 'ECGChannelCount' ); % Number of ECG channels included in the recording (e.g. 1).
cfg.eeg.EMGChannelCount = ft_getopt(cfg.eeg, 'EMGChannelCount' ); % Number of EMG channels included in the recording (e.g. 2).
cfg.eeg.EOGChannelCount = ft_getopt(cfg.eeg, 'EOGChannelCount' ); % Number of EOG channels included in the recording (e.g. 2).
cfg.eeg.MiscChannelCount = ft_getopt(cfg.eeg, 'MiscChannelCount' ); % Number of miscellaneous analog channels for auxiliary signals
cfg.eeg.TriggerChannelCount = ft_getopt(cfg.eeg, 'TriggerChannelCount' ); % Number of channels for digital and analog triggers.
cfg.eeg.RecordingDuration = ft_getopt(cfg.eeg, 'RecordingDuration' ); % Length of the recording in seconds (e.g. 3600)
cfg.eeg.RecordingType = ft_getopt(cfg.eeg, 'RecordingType' ); % "continuous", "epoched"
cfg.eeg.EpochLength = ft_getopt(cfg.eeg, 'EpochLength' ); % Duration of individual epochs in seconds (e.g. 1). If recording was continuous, set value to Inf or leave out the field.
cfg.eeg.HeadCircumference = ft_getopt(cfg.eeg, 'HeadCircumference' ); % RECOMMENDED. Circumference of the participants head, expressed in cm (e.g., 58).
cfg.eeg.EEGPlacementScheme = ft_getopt(cfg.eeg, 'EEGPlacementScheme' ); % Placement scheme of the EEG electrodes. Either the name of a placement system (e.g. "10-20", "equidistant", "geodesic") or a list of electrode positions (e.g. "Cz", "Pz").
cfg.eeg.EEGGround = ft_getopt(cfg.eeg, 'EEGGround' ); % RECOMMENDED. Description of the location of the ground electrode (e.g., "placed on right mastoid (M2)").
cfg.eeg.HardwareFilters = ft_getopt(cfg.eeg, 'HardwareFilters' ); % List of hardware (amplifier) filters applied or ideally key:value pairs of pre-applied filters and their parameter values
cfg.eeg.SubjectArtefactDescription = ft_getopt(cfg.eeg, 'SubjectArtefactDescription' ); % Freeform description of the observed subject artefact and its possible cause (e.g. "Vagus Nerve Stimulator", "non-removable implant"). If this field is left empty, it will be interpreted as absence of a source of (constantly present) artifacts.
%% iEEG specific fields
cfg.ieeg.iEEGReference = ft_getopt(cfg.ieeg, 'iEEGReference' ); % REQUIRED. General description of the reference scheme used and (when applicable) of location of the reference electrode in the raw recordings (e.g. "left mastoidâ?, âbipolarâ?, âT01â? for electrode with name T01, âintracranial electrode on top of a grid, not included with dataâ?, âupside down electrodeâ?). If different channels have a different reference, this field should have a general description and the channel specific reference should be defined in the _channels.tsv file.
cfg.ieeg.SamplingFrequency = ft_getopt(cfg.ieeg, 'SamplingFrequency' ); % REQUIRED. Sampling frequency (in Hz) of all the iEEG channels in the recording (e.g., 2400). All other channels should have frequency specified as well in the channels.tsv file.
cfg.ieeg.PowerLineFrequency = ft_getopt(cfg.ieeg, 'PowerLineFrequency' ); % REQUIRED. Frequency (in Hz) of the power grid where the iEEG recording was done (i.e. 50 or 60)
cfg.ieeg.SoftwareFilters = ft_getopt(cfg.ieeg, 'SoftwareFilters' ); % REQUIRED. List of temporal software filters applied or ideally key:value pairs of pre-applied filters and their parameter values. (n/a if none).
% cfg.ieeg.DCOffsetCorrection see https://github.com/bids-standard/bids-specification/issues/237
cfg.ieeg.HardwareFilters = ft_getopt(cfg.ieeg, 'HardwareFilters' ); % REQUIRED. List of hardware (amplifier) filters applied with key:value pairs of filter parameters and their values.
cfg.ieeg.ElectrodeManufacturer = ft_getopt(cfg.ieeg, 'ElectrodeManufacturer' ); % RECOMMENDED. can be used if all electrodes are of the same manufacturer (e.g. AD-TECH, DIXI). If electrodes of different manufacturers are used, please use the corresponding table in the _electrodes.tsv file.
cfg.ieeg.ElectrodeManufacturersModelName = ft_getopt(cfg.ieeg, 'ElectrodeManufacturersModelName'); % RECOMMENDED. If different electrode types are used, please use the corresponding table in the _electrodes.tsv file.
% Manufacturer and ManufacturersModelName are general
cfg.ieeg.ECOGChannelCount = ft_getopt(cfg.ieeg, 'ECOGChannelCount' ); % RECOMMENDED. Number of iEEG surface channels included in the recording (e.g. 120)
cfg.ieeg.SEEGChannelCount = ft_getopt(cfg.ieeg, 'SEEGChannelCount' ); % RECOMMENDED. Number of iEEG depth channels included in the recording (e.g. 8)
cfg.ieeg.EEGChannelCount = ft_getopt(cfg.ieeg, 'EEGChannelCount' ); % RECOMMENDED. Number of scalp EEG channels recorded simultaneously (e.g. 21)
cfg.ieeg.EOGChannelCount = ft_getopt(cfg.ieeg, 'EOGChannelCount' ); % RECOMMENDED. Number of EOG channels
cfg.ieeg.ECGChannelCount = ft_getopt(cfg.ieeg, 'ECGChannelCount' ); % RECOMMENDED. Number of ECG channels
cfg.ieeg.EMGChannelCount = ft_getopt(cfg.ieeg, 'EMGChannelCount' ); % RECOMMENDED. Number of EMG channels
cfg.ieeg.MiscChannelCount = ft_getopt(cfg.ieeg, 'MiscChannelCount' ); % RECOMMENDED. Number of miscellaneous analog channels for auxiliary signals
cfg.ieeg.TriggerChannelCount = ft_getopt(cfg.ieeg, 'TriggerChannelCount' ); % RECOMMENDED. Number of channels for digital (TTL bit level) triggers
cfg.ieeg.RecordingDuration = ft_getopt(cfg.ieeg, 'RecordingDuration' ); % RECOMMENDED. Length of the recording in seconds (e.g. 3600)
cfg.ieeg.RecordingType = ft_getopt(cfg.ieeg, 'RecordingType' ); % RECOMMENDED. Defines whether the recording is âcontinuousâ? or âepochedâ?; this latter limited to time windows about events of interest (e.g., stimulus presentations, subject responses etc.)
cfg.ieeg.EpochLength = ft_getopt(cfg.ieeg, 'EpochLength' ); % RECOMMENDED. Duration of individual epochs in seconds (e.g. 1) in case of epoched data
cfg.ieeg.iEEGGround = ft_getopt(cfg.ieeg, 'iEEGGround' ); % RECOMMENDED. Description of the location of the ground electrode (âplaced on right mastoid (M2)â?).
cfg.ieeg.iEEGPlacementScheme = ft_getopt(cfg.ieeg, 'iEEGPlacementScheme' ); % RECOMMENDED. Freeform description of the placement of the iEEG electrodes. Left/right/bilateral/depth/surface (e.g. âleft frontal grid and bilateral hippocampal depthâ? or âsurface strip and STN depthâ? or âclinical indication bitemporal, bilateral temporal strips and left gridâ?).
cfg.ieeg.iEEGElectrodeGroups = ft_getopt(cfg.ieeg, 'iEEGElectrodeGroups' ); % RECOMMENDED. Field to describe the way electrodes are grouped into strips, grids or depth probes e.g. {'grid1': "10x8 grid on left temporal pole", 'strip2': "1x8 electrode strip on xxx"}.
cfg.ieeg.SubjectArtefactDescription = ft_getopt(cfg.ieeg, 'SubjectArtefactDescription' ); % RECOMMENDED. Freeform description of the observed subject artefact and its possible cause (e.g. âdoor openâ?, â?nurse walked into room at 2 minâ?, â?seizure at 10 minâ?). If this field is left empty, it will be interpreted as absence of artifacts.
cfg.ieeg.ElectricalStimulation = ft_getopt(cfg.ieeg, 'ElectricalStimulation' ); % OPTIONAL. Boolean field to specify if electrical stimulation was done during the recording (options are âtrueâ? or âfalseâ?). Parameters for event-like stimulation should be specified in the _events.tsv file (see example underneath).
cfg.ieeg.ElectricalStimulationParameters = ft_getopt(cfg.ieeg, 'ElectricalStimulationParameters'); % OPTIONAL. Free form description of stimulation parameters, such as frequency, shape etc. Specific onsets can be specified in the _events.tsv file. Specific shapes can be described here in freeform text.
%% EMG is not part of the official BIDS specification
cfg.emg.SamplingFrequency = ft_getopt(cfg.emg, 'SamplingFrequency' );
cfg.emg.RecordingDuration = ft_getopt(cfg.emg, 'RecordingDuration' );
cfg.emg.RecordingType = ft_getopt(cfg.emg, 'RecordingType' );
cfg.emg.PowerLineFrequency = ft_getopt(cfg.emg, 'PowerLineFrequency' );
cfg.emg.HardwareFilters = ft_getopt(cfg.emg, 'HardwareFilters' );
cfg.emg.SoftwareFilters = ft_getopt(cfg.emg, 'SoftwareFilters' );
cfg.emg.EMGChannelCount = ft_getopt(cfg.emg, 'EMGChannelCount' );
cfg.emg.EOGChannelCount = ft_getopt(cfg.emg, 'EOGChannelCount' );
cfg.emg.ECGChannelCount = ft_getopt(cfg.emg, 'ECGChannelCount' );
cfg.emg.ElectrodeManufacturer = ft_getopt(cfg.emg, 'ElectrodeManufacturer' );
cfg.emg.ElectrodeManufacturersModelName = ft_getopt(cfg.emg, 'ElectrodeManufacturersModelName' );
cfg.emg.EMGPlacementScheme = ft_getopt(cfg.emg, 'EMGPlacementScheme' );
cfg.emg.EMGReference = ft_getopt(cfg.emg, 'EMGReference' );
cfg.emg.EMGGround = ft_getopt(cfg.emg, 'EMGGround' );
%% EXG is not part of the official BIDS specification
cfg.exg.SamplingFrequency = ft_getopt(cfg.exg, 'SamplingFrequency' );
cfg.exg.RecordingDuration = ft_getopt(cfg.exg, 'RecordingDuration' );
cfg.exg.RecordingType = ft_getopt(cfg.exg, 'RecordingType' );
%% NIRS is not part of the official BIDS specification
cfg.nirs.CapManufacturer = ft_getopt(cfg.nirs, 'CapManufacturer' );
cfg.nirs.CapManufacturersModelName = ft_getopt(cfg.nirs, 'CapManufacturersModelName' );
cfg.nirs.SamplingFrequency = ft_getopt(cfg.nirs, 'SamplingFrequency' );
cfg.nirs.NIRSChannelCount = ft_getopt(cfg.nirs, 'NIRSChannelCount' );
cfg.nirs.NIRSSourceOptodeCount = ft_getopt(cfg.nirs, 'NIRSSourceOptodeCount' );
cfg.nirs.NIRSDetectorOptodeCount = ft_getopt(cfg.nirs, 'NIRSDetectorOptodeCount' );
cfg.nirs.ACCELChannelCount = ft_getopt(cfg.nirs, 'ACCELChannelCount' );
cfg.nirs.GYROChannelCount = ft_getopt(cfg.nirs, 'GYROChannelCount' );
cfg.nirs.MAGNChannelCount = ft_getopt(cfg.nirs, 'MAGNChannelCount' );
cfg.nirs.SourceType = ft_getopt(cfg.nirs, 'SourceType' );
cfg.nirs.DetectorType = ft_getopt(cfg.nirs, 'DetectorType' );
cfg.nirs.ShortChannelCount = ft_getopt(cfg.nirs, 'ShortChannelCount' );
cfg.nirs.NIRSPlacementScheme = ft_getopt(cfg.nirs, 'NIRSPlacementScheme' );
cfg.nirs.RecordingDuration = ft_getopt(cfg.nirs, 'RecordingDuration' );
cfg.nirs.DCOffsetCorrection = ft_getopt(cfg.nirs, 'DCOffsetCorrection' );
cfg.nirs.HeadCircumference = ft_getopt(cfg.nirs, 'HeadCircumference' );
cfg.nirs.HardwareFilters = ft_getopt(cfg.nirs, 'HardwareFilters' );
cfg.nirs.SoftwareFilters = ft_getopt(cfg.nirs, 'SoftwareFilters' );
%% audio is not part of the official BIDS specification
cfg.audio.SampleRate = ft_getopt(cfg.audio, 'SampleRate' );
cfg.audio.ChannelCount = ft_getopt(cfg.audio, 'ChannelCount' );
cfg.audio.RecordingDuration = ft_getopt(cfg.audio, 'RecordingDuration' );
%% video is not part of the official BIDS specification
cfg.video.FrameRate = ft_getopt(cfg.video, 'FrameRate' );
cfg.video.Width = ft_getopt(cfg.video, 'Width' );
cfg.video.Height = ft_getopt(cfg.video, 'Height' );
cfg.video.BitsPerPixel = ft_getopt(cfg.video, 'BitsPerPixel' );
cfg.video.VideoDuration = ft_getopt(cfg.video, 'VideoDuration' );
cfg.video.AudioDuration = ft_getopt(cfg.video, 'AudioDuration' );
cfg.video.AudioSampleRate = ft_getopt(cfg.video, 'AudioSampleRate' );
cfg.video.AudioChannelCount = ft_getopt(cfg.video, 'AudioChannelCount' );
%% physio is part of the official BIDS specification and goes into 'beh' or in 'func'
cfg.physio.Columns = ft_getopt(cfg.physio, 'Columns' );
cfg.physio.StartTime = ft_getopt(cfg.physio, 'StartTime' );
cfg.physio.SamplingFrequency = ft_getopt(cfg.physio, 'SamplingFrequency' );
%% stim is part of the official BIDS specification and goes into 'beh' or in 'func'
cfg.stim.Columns = ft_getopt(cfg.stim, 'Columns' );
cfg.stim.StartTime = ft_getopt(cfg.stim, 'StartTime' );
cfg.stim.SamplingFrequency = ft_getopt(cfg.stim, 'SamplingFrequency' );
%% eyetracker is not part of the official BIDS specification
% this follows https://bids-specification.readthedocs.io/en/stable/04-modality-specific-files/06-physiological-and-other-continuous-recordings.html
cfg.eyetracker.Columns = ft_getopt(cfg.eyetracker, 'Columns' );
cfg.eyetracker.StartTime = ft_getopt(cfg.eyetracker, 'StartTime' );
cfg.eyetracker.SamplingFrequency = ft_getopt(cfg.eyetracker, 'SamplingFrequency' );
%% motion is not part of the official BIDS specification
% this follows extension proposal 029 https://bids.neuroimaging.io/bep029
cfg.motion.EpochLength = ft_getopt(cfg.motion, 'EpochLength' );
cfg.motion.RecordingType = ft_getopt(cfg.motion, 'RecordingType' );
cfg.motion.SubjectArtefactDescription = ft_getopt(cfg.motion, 'SubjectArtefactDescription');
cfg.motion.TrackingSystemName = ft_getopt(cfg.motion, 'TrackingSystemName' );
cfg.motion.DeviceSerialNumber = ft_getopt(cfg.motion, 'DeviceSerialNumber' );
cfg.motion.SoftwareVersions = ft_getopt(cfg.motion, 'SoftwareVersions' );
cfg.motion.ExternalSoftwareVersions = ft_getopt(cfg.motion, 'ExternalSoftwareVersions' );
cfg.motion.Manufacturer = ft_getopt(cfg.motion, 'Manufacturer' );
cfg.motion.ManufacturersModelName = ft_getopt(cfg.motion, 'ManufacturersModelName' );
cfg.motion.SamplingFrequency = ft_getopt(cfg.motion, 'SamplingFrequency' );
cfg.motion.SamplingFrequencyEffective = ft_getopt(cfg.motion, 'SamplingFrequencyEffective');
cfg.motion.RecordingDuration = ft_getopt(cfg.motion, 'RecordingDuration' );
cfg.motion.SpatialAxes = ft_getopt(cfg.motion, 'SpatialAxes' );
cfg.motion.RotationRule = ft_getopt(cfg.motion, 'RotationRule' );
cfg.motion.RotationOrder = ft_getopt(cfg.motion, 'RotationOrder' );
%% information for the coordsystem.json file for MEG, EEG, iEEG, and motion
cfg.coordsystem.MEGCoordinateSystem = ft_getopt(cfg.coordsystem, 'MEGCoordinateSystem' ); % REQUIRED. Defines the coordinate system for the MEG sensors. See Appendix VIII: preferred names of Coordinate systems. If "Other", provide definition of the coordinate system in [MEGCoordinateSystemDescription].
cfg.coordsystem.MEGCoordinateUnits = ft_getopt(cfg.coordsystem, 'MEGCoordinateUnits' ); % REQUIRED. Units of the coordinates of MEGCoordinateSystem. MUST be ???m???, ???cm???, or ???mm???.
cfg.coordsystem.MEGCoordinateSystemDescription = ft_getopt(cfg.coordsystem, 'MEGCoordinateSystemDescription' ); % OPTIONAL. Freeform text description or link to document describing the MEG coordinate system system in detail.
cfg.coordsystem.HeadCoilCoordinates = ft_getopt(cfg.coordsystem, 'HeadCoilCoordinates' ); % OPTIONAL. Key:value pairs describing head localization coil labels and their coordinates, interpreted following the HeadCoilCoordinateSystem, e.g., {"NAS": [12.7,21.3,13.9], "LPA": [5.2,11.3,9.6], "RPA": [20.2,11.3,9.1]}. Note that coils are not always placed at locations that have a known anatomical name (e.g. for Neuromag/Elekta, Yokogawa systems); in that case generic labels can be used (e.g. {"coil1": [122,213,123], "coil2": [67,123,86], "coil3": [219,110,81]} ).
cfg.coordsystem.HeadCoilCoordinateSystem = ft_getopt(cfg.coordsystem, 'HeadCoilCoordinateSystem' ); % OPTIONAL. Defines the coordinate system for the coils. See Appendix VIII: preferred names of Coordinate systems. If "Other", provide definition of the coordinate system in HeadCoilCoordinateSystemDescription.
cfg.coordsystem.HeadCoilCoordinateUnits = ft_getopt(cfg.coordsystem, 'HeadCoilCoordinateUnits' ); % OPTIONAL. Units of the coordinates of HeadCoilCoordinateSystem. MUST be ???m???, ???cm???, or ???mm???.
cfg.coordsystem.HeadCoilCoordinateSystemDescription = ft_getopt(cfg.coordsystem, 'HeadCoilCoordinateSystemDescription' ); % OPTIONAL. Freeform text description or link to document describing the Head Coil coordinate system system in detail.
cfg.coordsystem.DigitizedHeadPoints = ft_getopt(cfg.coordsystem, 'DigitizedHeadPoints' ); % OPTIONAL. Relative path to the file containing the locations of digitized head points collected during the session (e.g., "sub-01_headshape.pos"). RECOMMENDED for all MEG systems, especially for CTF and 4D/BTi. For Neuromag/Elekta/Megin the head points will be stored in the fif file.
cfg.coordsystem.DigitizedHeadPointsCoordinateSystem = ft_getopt(cfg.coordsystem, 'DigitizedHeadPointsCoordinateSystem' ); % OPTIONAL. Defines the coordinate system for the digitized head points. See Appendix VIII: preferred names of Coordinate systems. If "Other", provide definition of the coordinate system in DigitizedHeadPointsCoordinateSystemDescription.
cfg.coordsystem.DigitizedHeadPointsCoordinateUnits = ft_getopt(cfg.coordsystem, 'DigitizedHeadPointsCoordinateUnits' ); % OPTIONAL. Units of the coordinates of DigitizedHeadPointsCoordinateSystem. MUST be ???m???, ???cm???, or ???mm???.
cfg.coordsystem.DigitizedHeadPointsCoordinateSystemDescription = ft_getopt(cfg.coordsystem, 'DigitizedHeadPointsCoordinateSystemDescription' ); % OPTIONAL. Freeform text description or link to document describing the Digitized head Points coordinate system system in detail.
cfg.coordsystem.EEGCoordinateSystem = ft_getopt(cfg.coordsystem, 'EEGCoordinateSystem' ); % OPTIONAL. Describes how the coordinates of the EEG sensors are to be interpreted.
cfg.coordsystem.EEGCoordinateUnits = ft_getopt(cfg.coordsystem, 'EEGCoordinateUnits' ); % OPTIONAL. Units of the coordinates of EEGCoordinateSystem. MUST be ???m???, ???cm???, or ???mm???.
cfg.coordsystem.EEGCoordinateSystemDescription = ft_getopt(cfg.coordsystem, 'EEGCoordinateSystemDescription' ); % OPTIONAL. Freeform text description or link to document describing the EEG coordinate system system in detail.
cfg.coordsystem.iEEGCoordinateSystem = ft_getopt(cfg.coordsystem, 'iEEGCoordinateSystem' ); % REQUIRED. Defines the coordinate system for the iEEG electrodes. See Appendix VIII for a list of restricted keywords. If positions correspond to pixel indices in a 2D image (of either a volume-rendering, surface-rendering, operative photo, or operative drawing), this must be "Pixels". For more information, see the section on 2D coordinate systems
cfg.coordsystem.iEEGCoordinateUnits = ft_getopt(cfg.coordsystem, 'iEEGCoordinateUnits' ); % REQUIRED. Units of the _electrodes.tsv, MUST be "m", "mm", "cm" or "pixels".
cfg.coordsystem.iEEGCoordinateSystemDescription = ft_getopt(cfg.coordsystem, 'iEEGCoordinateSystemDescription' ); % RECOMMENDED. Freeform text description or link to document describing the iEEG coordinate system system in detail (e.g., "Coordinate system with the origin at anterior commissure (AC), negative y-axis going through the posterior commissure (PC), z-axis going to a mid-hemisperic point which lies superior to the AC-PC line, x-axis going to the right").
cfg.coordsystem.iEEGCoordinateProcessingDescription = ft_getopt(cfg.coordsystem, 'iEEGCoordinateProcessingDescription' ); % RECOMMENDED. Has any post-processing (such as projection) been done on the electrode positions (e.g., "surface_projection", "none").
cfg.coordsystem.iEEGCoordinateProcessingReference = ft_getopt(cfg.coordsystem, 'iEEGCoordinateProcessingReference' ); % RECOMMENDED. A reference to a paper that defines in more detail the method used to localize the electrodes and to post-process the electrode positions. .
cfg.coordsystem.NIRSCoordinateSystem = ft_getopt(cfg.coordsystem, 'NIRSCoordinateSystem' ); % REQUIRED. Defines the coordinate system for the optodes. See Appendix VIII for a list of restricted keywords. If positions correspond to pixel indices in a 2D image (of either a volume-rendering, surface-rendering, operative photo, or operative drawing), this must be "Pixels". For more information, see the section on 2D coordinate systems
cfg.coordsystem.NIRSCoordinateUnits = ft_getopt(cfg.coordsystem, 'NIRSCoordinateUnits' ); % REQUIRED. Units of the _optodes.tsv, MUST be "m", "mm", "cm" or "pixels".
cfg.coordsystem.NIRSCoordinateSystemDescription = ft_getopt(cfg.coordsystem, 'NIRSCoordinateSystemDescription' ); % RECOMMENDED. Freeform text description or link to document describing the NIRS coordinate system system in detail (e.g., "Coordinate system with the origin at anterior commissure (AC), negative y-axis going through the posterior commissure (PC), z-axis going to a mid-hemisperic point which lies superior to the AC-PC line, x-axis going to the right").
cfg.coordsystem.NIRSCoordinateProcessingDescription = ft_getopt(cfg.coordsystem, 'NIRSCoordinateProcessingDescription' ); % RECOMMENDED. Has any post-processing (such as projection) been done on the optode positions (e.g., "surface_projection", "none").
cfg.coordsystem.MotionCoordinateSystem = ft_getopt(cfg.coordsystem, 'MotionCoordinateSystem' ); % REQUIRED.
cfg.coordsystem.MotionRotationRule = ft_getopt(cfg.coordsystem, 'MotionRotationRule' ); % OPTIONAL.
cfg.coordsystem.MotionRotationOrder = ft_getopt(cfg.coordsystem, 'MotionRotationOrder' ); % OPTIONAL.
cfg.coordsystem.IntendedFor = ft_getopt(cfg.coordsystem, 'IntendedFor' ); % OPTIONAL. Path or list of path relative to the subject subfolder pointing to the structural MRI, possibly of different types if a list is specified, to be used with the MEG recording. The path(s) need(s) to use forward slashes instead of backward slashes (e.g. "ses-<label>/anat/sub-01_T1w.nii.gz").
cfg.coordsystem.AnatomicalLandmarkCoordinates = ft_getopt(cfg.coordsystem, 'AnatomicalLandmarkCoordinates' ); % OPTIONAL. Key:value pairs of the labels and 3-D digitized locations of anatomical landmarks, interpreted following the AnatomicalLandmarkCoordinateSystem, e.g., {"NAS": [12.7,21.3,13.9], "LPA": [5.2,11.3,9.6], "RPA": [20.2,11.3,9.1]}.
cfg.coordsystem.AnatomicalLandmarkCoordinateSystem = ft_getopt(cfg.coordsystem, 'AnatomicalLandmarkCoordinateSystem' ); % OPTIONAL. Defines the coordinate system for the anatomical landmarks. See Appendix VIII: preferred names of Coordinate systems. If "Other", provide definition of the coordinate system in AnatomicalLandmarkCoordinateSystemDescripti on.
cfg.coordsystem.AnatomicalLandmarkCoordinateUnits = ft_getopt(cfg.coordsystem, 'AnatomicalLandmarkCoordinateUnits' ); % OPTIONAL. Units of the coordinates of AnatomicalLandmarkCoordinateSystem. MUST be ???m???, ???cm???, or ???mm???.
cfg.coordsystem.AnatomicalLandmarkCoordinateSystemDescription = ft_getopt(cfg.coordsystem, 'AnatomicalLandmarkCoordinateSystemDescription' ); % OPTIONAL. Freeform text description or link to document describing the Head Coil coordinate system system in detail.
cfg.coordsystem.FiducialsDescription = ft_getopt(cfg.coordsystem, 'FiducialsDescription' ); % OPTIONAL. A freeform text field documenting the anatomical landmarks that were used and how the head localization coils were placed relative to these. This field can describe, for instance, whether the true anatomical locations of the left and right pre-auricular points were used and digitized, or rather whether they were defined as the intersection between the tragus and the helix (the entry of the ear canal), or any other anatomical description of selected points in the vicinity of the ears.
cfg.coordsystem.FiducialsCoordinates = ft_getopt(cfg.coordsystem, 'FiducialsCoordinates' ); % RECOMMENDED. Key:value pairs of the labels and 3-D digitized position of anatomical landmarks, interpreted following the FiducialsCoordinateSystem (e.g., {"NAS": [12.7,21.3,13.9], "LPA": [5.2,11.3,9.6], "RPA": [20.2,11.3,9.1]}).
cfg.coordsystem.FiducialsCoordinateSystem = ft_getopt(cfg.coordsystem, 'FiducialsCoordinateSystem' ); % RECOMMENDED. Refers to the coordinate space to which the landmarks positions are to be interpreted - preferably the same as the NIRSCoordinateSystem
cfg.coordsystem.FiducialsCoordinateUnits = ft_getopt(cfg.coordsystem, 'FiducialsCoordinateUnits' ); % RECOMMENDED. Units in which the coordinates that are listed in the field AnatomicalLandmarkCoordinateSystem are represented (e.g., "mm", "cm").
cfg.coordsystem.FiducialsCoordinateSystemDescription = ft_getopt(cfg.coordsystem, 'FiducialsCoordinateSystemDescription' ); % RECOMMENDED. Free-form text description of the coordinate system. May also include a link to a documentation page or paper describing the system in greater detail.
%% columns in the channels.tsv
cfg.channels.name = ft_getopt(cfg.channels, 'name' , nan); % REQUIRED. Channel name (e.g., MRT012, MEG023)
cfg.channels.type = ft_getopt(cfg.channels, 'type' , nan); % REQUIRED. Type of channel; MUST use the channel types listed below.
cfg.channels.units = ft_getopt(cfg.channels, 'units' , nan); % REQUIRED. Physical unit of the data values recorded by this channel in SI (see Appendix V: Units for allowed symbols).
% specific options for EEG/MEG/iEEG channels
cfg.channels.sampling_frequency = ft_getopt(cfg.channels, 'sampling_frequency' , nan); % OPTIONAL. Sampling rate of the channel in Hz.
cfg.channels.description = ft_getopt(cfg.channels, 'description' , nan); % OPTIONAL. Brief free-text description of the channel, or other information of interest. See examples below.
cfg.channels.low_cutoff = ft_getopt(cfg.channels, 'low_cutoff' , nan); % OPTIONAL. Frequencies used for the high-pass filter applied to the channel in Hz. If no high-pass filter applied, use n/a.
cfg.channels.high_cutoff = ft_getopt(cfg.channels, 'high_cutoff' , nan); % OPTIONAL. Frequencies used for the low-pass filter applied to the channel in Hz. If no low-pass filter applied, use n/a. Note that hardware anti-aliasing in A/D conversion of all MEG/EEG electronics applies a low-pass filter; specify its frequency here if applicable.
cfg.channels.notch = ft_getopt(cfg.channels, 'notch' , nan); % OPTIONAL. Frequencies used for the notch filter applied to the channel, in Hz. If no notch filter applied, use n/a.
cfg.channels.software_filters = ft_getopt(cfg.channels, 'software_filters' , nan); % OPTIONAL. List of temporal and/or spatial software filters applied (e.g. "SSS", "SpatialCompensation"). Note that parameters should be defined in the general MEG sidecar .json file. Indicate n/a in the absence of software filters applied.
cfg.channels.status = ft_getopt(cfg.channels, 'status' , nan); % OPTIONAL. Data quality observed on the channel (good/bad). A channel is considered bad if its data quality is compromised by excessive noise. Description of noise type SHOULD be provided in [status_description].
cfg.channels.status_description = ft_getopt(cfg.channels, 'status_description' , nan); % OPTIONAL. Freeform text description of noise or artifact affecting data quality on the channel. It is meant to explain why the channel was declared bad in [status].
% specific options for NIRS channels
cfg.channels.source = ft_getopt(cfg.channels, 'source' , nan);
cfg.channels.detector = ft_getopt(cfg.channels, 'detector' , nan);
cfg.channels.wavelength = ft_getopt(cfg.channels, 'wavelength' , nan);
cfg.channels.wavelength_nominal = ft_getopt(cfg.channels, 'wavelength_nominal' , nan);
cfg.channels.orientation_component = ft_getopt(cfg.channels, 'orientation_component' , nan);
cfg.channels.wavelength_actual = ft_getopt(cfg.channels, 'wavelength_actual' , nan);
cfg.channels.wavelength_emission_actual = ft_getopt(cfg.channels, 'wavelength_emission_actual' , nan);
cfg.channels.short_channel = ft_getopt(cfg.channels, 'short_channel' , nan);
% specific options for motion channels
cfg.channels.sampling_frequency = ft_getopt(cfg.channels, 'sampling_frequency' , nan);
cfg.channels.component = ft_getopt(cfg.channels, 'component' , nan);
cfg.channels.tracked_point = ft_getopt(cfg.channels, 'tracked_point' , nan);
%% columns in the electrodes.tsv
cfg.electrodes.name = ft_getopt(cfg.electrodes, 'name' , nan); % REQUIRED. Name of the electrode
cfg.electrodes.x = ft_getopt(cfg.electrodes, 'x' , nan); % REQUIRED. Recorded position along the x-axis
cfg.electrodes.y = ft_getopt(cfg.electrodes, 'y' , nan); % REQUIRED. Recorded position along the y-axis
cfg.electrodes.z = ft_getopt(cfg.electrodes, 'z' , nan); % REQUIRED. Recorded position along the z-axis
cfg.electrodes.type = ft_getopt(cfg.electrodes, 'type' , nan); % RECOMMENDED. Type of the electrode (e.g., cup, ring, clip-on, wire, needle)
cfg.electrodes.material = ft_getopt(cfg.electrodes, 'material' , nan); % RECOMMENDED. Material of the electrode, e.g., Tin, Ag/AgCl, Gold
cfg.electrodes.impedance = ft_getopt(cfg.electrodes, 'impedance' , nan); % RECOMMENDED. Impedance of the electrode in kOhm
%% columns in the optodes.tsv
cfg.optodes.name = ft_getopt(cfg.optodes, 'name' , nan); % REQUIRED. Name of the optode must be unique
cfg.optodes.type = ft_getopt(cfg.optodes, 'type' , nan); % REQUIRED. Either source or detector
cfg.optodes.x = ft_getopt(cfg.optodes, 'x' , nan); % REQUIRED. Recorded position along the x-axis. n/a if not available
cfg.optodes.y = ft_getopt(cfg.optodes, 'y' , nan); % REQUIRED. Recorded position along the y-axis. n/a if not available
cfg.optodes.z = ft_getopt(cfg.optodes, 'z' , nan); % REQUIRED. Recorded position along the z-axis. n/a if not available
cfg.optodes.template_x = ft_getopt(cfg.optodes, 'template_x' , nan); % OPTIONAL. Assumed or ideal position along the x axis
cfg.optodes.template_y = ft_getopt(cfg.optodes, 'template_y' , nan); % OPTIONAL. Assumed or ideal position along the x axis
cfg.optodes.template_z = ft_getopt(cfg.optodes, 'template_x' , nan); % OPTIONAL. Assumed or ideal position along the x axis
cfg.optodes.description = ft_getopt(cfg.optodes, 'description' , nan); % OPTIONAL. string Free-form text description of the optode, or other information of interest.
cfg.optodes.detector_type = ft_getopt(cfg.optodes, 'detector_type' , nan); % OPTIONAL. string The type of detector. Only to be used if the field DetectorType in *_nirs.json is set to mixed.
cfg.optodes.source_type = ft_getopt(cfg.optodes, 'source_type' , nan); % OPTIONAL. string The type of source. Only to be used if the field SourceType in *_nirs.json is set to mixed.
%% information for the participants.tsv
cfg.participants = ft_getopt(cfg, 'participants', struct());
%% information for the scans.tsv
cfg.scans = ft_getopt(cfg, 'scans', struct());
%% sanity checks and determine the default method/outputfile
% the task is both part of the file name (cfg.task) and is also one of the general JSON metadata fields (cfg.TaskName)
if isempty(cfg.task) && isempty(cfg.TaskName)
% this is fine
elseif ~isempty(cfg.task) && isempty(cfg.TaskName)
cfg.TaskName = cfg.task;
elseif isempty(cfg.task) && ~isempty(cfg.TaskName)
cfg.task = cfg.TaskName;
elseif ~isempty(cfg.task) && ~isempty(cfg.TaskName)
if ~strcmp(cfg.task, cfg.TaskName)
ft_error('cfg.task and cfg.TaskName should be identical');
end
end
% construct the output directory and file name
if isempty(cfg.outputfile)
if isempty(cfg.method) && isempty(cfg.bidsroot) && ~isempty(cfg.dataset)
cfg.outputfile = cfg.dataset;
cfg.method = 'decorate';
ft_notice('using cfg.outputfile=''%s'' and cfg.method=''%s''', cfg.outputfile, cfg.method);
elseif isempty(cfg.bidsroot)
ft_error('cfg.bidsroot is required to construct BIDS output directory and file');
elseif isempty(cfg.sub)
ft_error('cfg.sub is required to construct BIDS output directory and file');
elseif isempty(cfg.datatype)
ft_error('cfg.datatype is required to construct BIDS output directory and file');
else
dirname = datatype2dirname(cfg.datatype);
filename = ['sub-' cfg.sub];
filename = add_entity(filename, 'ses', cfg.ses);
filename = add_entity(filename, 'task', cfg.task);
filename = add_entity(filename, 'tracksys', cfg.tracksys);
filename = add_entity(filename, 'acq', cfg.acq);
filename = add_entity(filename, 'ce', cfg.ce);
filename = add_entity(filename, 'rec', cfg.rec);
filename = add_entity(filename, 'dir', cfg.dir);
filename = add_entity(filename, 'run', cfg.run);
filename = add_entity(filename, 'mod', cfg.mod);
filename = add_entity(filename, 'echo', cfg.echo);
filename = add_entity(filename, 'proc', cfg.proc);
filename = add_entity(filename, 'desc', cfg.desc);
filename = add_datatype(filename, cfg.datatype);
if ~isempty(cfg.ses)
% construct the output filename, with session directory
cfg.outputfile = fullfile(cfg.bidsroot, ['sub-' cfg.sub], ['ses-' cfg.ses], dirname, filename);
else
% construct the output filename, without session directory
cfg.outputfile = fullfile(cfg.bidsroot, ['sub-' cfg.sub], dirname, filename);
end
if strcmp(cfg.method, 'copy') && ~isempty(cfg.dataset)
% copy the file extension from the input dataset
[p, f, x] = fileparts(cfg.dataset);
cfg.outputfile = [cfg.outputfile x];
end
end
end
% set the default method
if isempty(cfg.method)
if ~isempty(cfg.dataset) && ~isequal(cfg.dataset, cfg.outputfile)
cfg.method = 'convert';
elseif isempty(cfg.dataset) && ~isempty(varargin)
cfg.method = 'convert';
else
cfg.method = 'decorate';
end
ft_notice('using cfg.method=''%s''', cfg.method);
end
% do some sanity checks on the input and the method
if istrue(cfg.deface) && ~strcmp(cfg.method, 'convert')
ft_error('defacing only works in combination with cfg.method=''convert''');
elseif ft_nargin>1 && ~strcmp(cfg.method, 'convert')
ft_error('input data only works in combination with cfg.method=''convert''');
end
% do some more sanity checks on the input and the method
switch cfg.method
case 'decorate'
if ~isempty(cfg.outputfile) && ~isempty(cfg.dataset) && ~isequal(cfg.dataset, cfg.outputfile)
ft_error('cfg.dataset and cfg.outputfile should be the same');
end
case 'convert'
if ~isempty(cfg.outputfile) && isequal(cfg.dataset, cfg.outputfile)
ft_error('cfg.dataset and cfg.outputfile should not be the same');
end
case 'copy'
if ~isempty(cfg.outputfile) && isequal(cfg.dataset, cfg.outputfile)
ft_error('cfg.dataset and cfg.outputfile should not be the same');
end
otherwise
ft_error('unsupported value for cfg.method')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% read the information from the dataset
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% convert dataset to headerfile and datafile
if nargin>1
% input data was specified
varargin{1} = ft_checkdata(varargin{1}, 'datatype', {'raw', 'volume'});
typ = ft_datatype(varargin{1});
elseif ~isempty(cfg.dataset)
% data should be read from disk
cfg = ft_checkconfig(cfg, 'dataset2files', 'yes');
if isfield(cfg, 'headerfile')
typ = ft_filetype(cfg.headerfile);
else
typ = ft_filetype(cfg.presentationfile);
end
else
typ = 'unknown';
end
% determine the json files that are required
need_mri_json = false;
need_meg_json = false;
need_eeg_json = false;
need_ieeg_json = false;
need_emg_json = false;
need_exg_json = false;
need_nirs_json = false;
need_audio_json = false;
need_video_json = false;
need_physio_json = false;
need_stim_json = false;
need_eyetracker_json = false;
need_motion_json = false;
need_coordsystem_json = false;
% determine the tsv files that are required
need_events_tsv = false; % for functional and behavioral experiments
need_channels_tsv = false; % only needed for MEG/EEG/iEEG/EMG/NIRS/motion
need_electrodes_tsv = false; % only needed when actually present as cfg.electrodes, data.elec or as cfg.elec
need_optodes_tsv = false; % only needed when actually present as cfg.optodes, data.opto or as cfg.opto
switch typ
case {'nifti', 'nifti2', 'nifti_gz'}
mri = ft_read_mri(cfg.dataset);
if ~isempty(cfg.dicomfile)
% read the header details from the matching DICOM file specified by the user
dcm = dicominfo(cfg.dicomfile);
else
dcm = [];
end
need_mri_json = true;
case 'dicom'
mri = ft_read_mri(cfg.dataset);
dcm = dicominfo(cfg.dataset);
need_mri_json = true;
case 'volume'
% the input data structure represents imaging data
mri = varargin{1};
if ~isempty(cfg.dicomfile)
% read the header details from the dicom matching file that was specified by the user
dcm = dicominfo(cfg.dicomfile);
elseif isfield(mri, 'hdr') && numel(mri.hdr)>1
% it looks like an MRI read in using FT_READ_MRI using the FreeSurfer code
% take the DICOM details from the first slice
dcm = mri.hdr(1);
else
dcm = [];
end
need_mri_json = true;
case {'ctf_ds', 'ctf_meg4', 'ctf_res4', 'ctf151', 'ctf275', 'neuromag_fif', 'neuromag122', 'neuromag306'}
% it is MEG data from disk and in a supported format
hdr = ft_read_header(cfg.headerfile, 'checkmaxfilter', false, 'readbids', false);
if strcmp(cfg.method, 'convert')
% the data should be converted and written to disk
dat = ft_read_data(cfg.datafile, 'header', hdr, 'checkboundary', false, 'begsample', 1, 'endsample', hdr.nSamples*hdr.nTrials);
end
% read the triggers from disk
trigger = ft_read_event(cfg.datafile, 'header', hdr, 'readbids', false);
need_meg_json = true;
case {'brainvision_vhdr', 'edf', 'eeglab_set', 'biosemi_bdf'}
% the file on disk contains ExG data in a BIDS compiant format
hdr = ft_read_header(cfg.headerfile, 'checkmaxfilter', false, 'readbids', false);
if strcmp(cfg.method, 'convert')
% the data should be converted and written to disk
dat = ft_read_data(cfg.datafile, 'header', hdr, 'checkboundary', false, 'begsample', 1, 'endsample', hdr.nSamples*hdr.nTrials);
end
% read the triggers from disk
trigger = ft_read_event(cfg.datafile, 'header', hdr, 'readbids', false);
if isequal(cfg.datatype, 'eeg')
need_eeg_json = true;
elseif isequal(cfg.datatype, 'ieeg')
need_ieeg_json = true;
elseif isequal(cfg.datatype, 'emg')
need_emg_json = true;
elseif isequal(cfg.datatype, 'exg')
need_exg_json = true;
else
ft_warning('assuming that the dataset represents EEG');
need_eeg_json = true;
end
case 'presentation_log'
trigger = ft_read_event(cfg.dataset);
need_events_tsv = true;
case {'audio_wav', 'audio_ogg', 'audio_flac', 'audio_au', 'audio_aiff', 'audio_aif', 'audio_aifc', 'audio_mp3', 'audio_m4a', 'audio_mp4'}
% the file on disk contains audio
need_audio_json = true;
try
audio = audioinfo(cfg.dataset);
catch
ft_warning('audio format is unsupported on this MATLAB version and/or operating system');
audio = struct('SampleRate', nan, 'Duration', nan, 'NumChannels', nan);
end
case 'video'
% the file on disk contains not only video, but also audio
need_video_json = true;
try
video = VideoReader(cfg.dataset);
catch
ft_warning('video format is unsupported on this MATLAB version and/or operating system');
video = struct('FrameRate', nan, 'Width', nan, 'Height', nan, 'Duration', nan);
end
try
audio = audioinfo(cfg.dataset);
catch
ft_warning('audio format is unsupported on this MATLAB version and/or operating system');
audio = struct('SampleRate', nan, 'Duration', nan, 'NumChannels', nan);
end
case 'raw'
% the input data structure contains raw timeseries data
if isequal(cfg.datatype, 'meg')
need_meg_json = true;
elseif isequal(cfg.datatype, 'eeg')
need_eeg_json = true;
elseif isequal(cfg.datatype, 'ieeg')
need_ieeg_json = true;
elseif isequal(cfg.datatype, 'emg')
need_emg_json = true;
elseif isequal(cfg.datatype, 'exg')
need_exg_json = true;
elseif isequal(cfg.datatype, 'nirs')
need_nirs_json = true;
elseif isequal(cfg.datatype, 'physio')
need_physio_json = true;
elseif isequal(cfg.datatype, 'stim')
need_stim_json = true;
elseif isequal(cfg.datatype, 'eyetracker')
need_eyetracker_json = true;
elseif isequal(cfg.datatype, 'motion')
need_motion_json = true;
else
ft_error('cannot determine the type of the data, please specify cfg.dataype');
end
hdr = ft_fetch_header(varargin{1});
if strcmp(cfg.method, 'convert')
% the data should be written to disk
dat = ft_fetch_data(varargin{1}, 'checkboundary', false, 'begsample', 1, 'endsample', hdr.nSamples*hdr.nTrials);
% the events should be writen to disk
trigger = ft_fetch_event(varargin{1});
end
if ft_senstype(varargin{1}, 'ctf') || ft_senstype(varargin{1}, 'neuromag')
% use the subsequent MEG-specific metadata handling for the JSON and TSV sidecar files
typ = ft_senstype(varargin{1});
end
otherwise
% assume that the file on disk contains raw timeseries data that can be read by FieldTrip
if isequal(cfg.datatype, 'meg')
need_meg_json = true;
elseif isequal(cfg.datatype, 'eeg')
need_eeg_json = true;
elseif isequal(cfg.datatype, 'ieeg')
need_ieeg_json = true;
elseif isequal(cfg.datatype, 'emg')
need_emg_json = true;
elseif isequal(cfg.datatype, 'exg')
need_exg_json = true;
elseif isequal(cfg.datatype, 'nirs')
need_nirs_json = true;
elseif isequal(cfg.datatype, 'physio')
need_physio_json = true;
elseif isequal(cfg.datatype, 'stim')
need_stim_json = true;
elseif isequal(cfg.datatype, 'eyetracker')
need_eyetracker_json = true;
elseif isequal(cfg.datatype, 'motion')
need_motion_json = true;
elseif isequal(cfg.datatype, 'events')
need_events_tsv = true;
else
ft_error('cannot determine the type of the data, please specify cfg.datatype');
end
% construct the low-level options as key-value pairs, these are passed to FT_READ_HEADER, FT_READ_DATA and FT_READ_EVENT
headeropt = {};
headeropt = ft_setopt(headeropt, 'headerformat', ft_getopt(cfg, 'headerformat')); % is passed to low-level function, empty implies autodetection
headeropt = ft_setopt(headeropt, 'chantype', ft_getopt(cfg, 'chantype', {})); % 2017.10.10 AB required for NeuroOmega files
headeropt = ft_setopt(headeropt, 'checkmaxfilter', false);
headeropt = ft_setopt(headeropt, 'readbids', false);
dataopt = {};
dataopt = ft_setopt(dataopt, 'checkboundary', false);
dataopt = ft_setopt(dataopt, 'dataformat', ft_getopt(cfg, 'dataformat')); % is passed to low-level function, empty implies autodetection
eventopt = {};
eventopt = ft_setopt(eventopt, 'readbids', false);
eventopt = ft_setopt(eventopt, 'eventformat', ft_getopt(cfg, 'eventformat')); % is passed to low-level function, empty implies autodetection
if ~isempty(cfg.dataset)
hdr = ft_read_header(cfg.headerfile, headeropt{:});
if strcmp(cfg.method, 'convert')
% the data should be converted and written to disk
dat = ft_read_data(cfg.datafile, 'header', hdr, 'begsample', 1, 'endsample', hdr.nSamples*hdr.nTrials, dataopt{:});
trigger = ft_read_event(cfg.datafile, 'header', hdr, eventopt{:});
end
end
end % switch typ
if need_meg_json || need_eeg_json || need_ieeg_json
% determine whether an electrode definition is available
if isfield(cfg, 'elec') && ~isempty(cfg.elec)
need_electrodes_tsv = true;
elseif exist('hdr', 'var') && isfield(hdr, 'elec')
need_electrodes_tsv = true;
elseif ~isempty(varargin) && isfield(varargin{1}, 'elec') && ~isempty(varargin{1}.elec)