Skip to content

Commit 1c534db

Browse files
authored
Merge pull request #42 from Remi-Gau/remi-refactor
Refactoring
2 parents b69e00e + 28be481 commit 1c534db

File tree

6 files changed

+357
-285
lines changed

6 files changed

+357
-285
lines changed

README.md

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,18 @@ expParameters.subjectNb = 1;
4141
expParameters.sessionNb = 1;
4242
expParameters.runNb = 1;
4343
44-
% Use the verbose switch to know where your data is being saved
45-
expParameters.verbose = true;
46-
47-
% In case you are using en eyetracker
44+
% by default we assume you are running things on a behavioral PC with no eyetracker
4845
cfg.eyeTracker = false;
46+
cfg.testingDevice = 'PC';
4947
50-
% if the device is set to 'PC' then the data will be saved
51-
% in the `beh` folder
52-
cfg.device = 'PC';
53-
54-
% if the device is set to 'scanner' then the data will be saved
55-
% in the `func` folder
56-
% cfg.device = 'scanner';
57-
58-
% check that cfg and exparameters have all the necessary information
59-
% and fill in any missing field
60-
expParameters = checkCFG(cfg, expParameters);
48+
% if the testing device is set to 'PC' then the data will be saved in the `beh` folder
49+
% if set to 'mri' then the data will be saved in the `func` folder
50+
% cfg.testingDevice = 'mri';
51+
% if set to 'eeg' then the data will be saved in the `eeg` folder
52+
% cfg.testingDevice = 'eeg';
6153
62-
% create the filenames
63-
expParameters = createFilename(cfg, expParameters);
54+
% create the filenames: this include a step to check that all the information is there (checkCFG)
55+
[cfg, expParameters] = createFilename(cfg, expParameters);
6456
6557
% initialize the events files with the typical BIDS
6658
% columns (onsets, duration, trial_type)

checkCFG.m

Lines changed: 64 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,74 @@
1-
function [expParameters, cfg] = checkCFG(cfg, expParameters)
2-
% check that we have all the fields that we need in the experiment
3-
% parameters
1+
function [cfg, expParameters] = checkCFG(cfg, expParameters)
2+
% check that we have all the fields that we need in the experiment parameters
43

5-
if ~isfield(expParameters, 'verbose') || isempty(expParameters.verbose)
6-
expParameters.verbose = 0;
7-
end
8-
9-
if ~isfield(expParameters, 'outputDir')
10-
expParameters.outputDir = fullfile( ...
4+
%% set the expParameters defaults
5+
6+
fieldsToSet.verbose = 0;
7+
fieldsToSet.outputDir = fullfile( ...
118
fileparts(mfilename('fullpath')), ...
129
'..', ...
1310
'output');
14-
end
15-
16-
% set empty values for a series of field if they have not been specified
17-
% 'ce'
18-
% 'dir' For BIDS file naming: phase encoding direction of acquisition for fMRI
19-
% 'rec' For BIDS file naming: reconstruction of fMRI images
20-
% 'echo' For BIDS file naming: echo fMRI images
21-
% 'acq' For BIDS file naming: acquisition of fMRI images
22-
% 'subjectGrp' in case no group was provided
23-
% 'sessionNb' in case no session was provided
24-
25-
fields2Check = { ...
26-
'ce', ...
27-
'dir', ...
28-
'rec', ...
29-
'echo', ...
30-
'acq', ...
31-
'subjectGrp', ...
32-
'sessionNb'};
3311

34-
for iField = 1:numel(fields2Check)
35-
if ~isfield(expParameters, fields2Check{iField})
36-
expParameters = setfield(expParameters, fields2Check{iField}, []); %#ok<SFLD>
37-
end
12+
fieldsToSet.subjectGrp = []; % in case no group was provided
13+
fieldsToSet.sessionNb = []; % in case no session was provided
14+
fieldsToSet.askGrpSess = [true true];
15+
16+
% BIDS
17+
18+
% dataset description json
19+
% required
20+
fieldsToSet.bids.datasetDescription.json.Name = '';
21+
fieldsToSet.bids.datasetDescription.json.BIDSVersion = '';
22+
% recommended
23+
fieldsToSet.bids.datasetDescription.json.License = '';
24+
fieldsToSet.bids.datasetDescription.json.Authors = {''};
25+
fieldsToSet.bids.datasetDescription.json.Acknowledgements = '';
26+
fieldsToSet.bids.datasetDescription.json.HowToAcknowledge = '';
27+
fieldsToSet.bids.datasetDescription.json.Funding = {''};
28+
fieldsToSet.bids.datasetDescription.json.ReferencesAndLinks = {''};
29+
fieldsToSet.bids.datasetDescription.json.DatasetDOI = '';
30+
31+
% mri
32+
% for json
33+
fieldsToSet.MRI.repetitionTime = [];
34+
% for file naming
35+
fieldsToSet.MRI.ce = [];
36+
fieldsToSet.MRI.dir = []; % phase encoding direction of acquisition for fMRI
37+
fieldsToSet.MRI.rec = []; % reconstruction of fMRI images
38+
fieldsToSet.MRI.echo = []; % echo fMRI images
39+
fieldsToSet.MRI.acq = []; % acquisition of fMRI images
40+
41+
%% loop through the defaults and set them in expParameters if they don't exist
42+
names = fieldnames(fieldsToSet);
43+
44+
for i = 1:numel(names)
45+
expParameters = setFieldToIfNotPresent(...
46+
expParameters, ...
47+
names{i}, ...
48+
getfield(fieldsToSet, names{i})); %#ok<GFLD>
49+
end
50+
51+
%% set the cfg defaults
52+
53+
clear fieldsToSet
54+
fieldsToSet.testingDevice = 'pc';
55+
fieldsToSet.eyeTracker = false;
56+
57+
% loop through the defaults and set them in cfg if they don't exist
58+
names = fieldnames(fieldsToSet);
59+
60+
for i = 1:numel(names)
61+
cfg = setFieldToIfNotPresent(...
62+
cfg, ...
63+
names{i}, ...
64+
getfield(fieldsToSet, names{i})); %#ok<GFLD>
3865
end
3966

40-
% set false value for a series of field if they have not been specified
41-
fields2CheckFalse = { ...
42-
'eyeTracker'
43-
};
67+
end
4468

45-
for iField = 1:numel(fields2CheckFalse)
46-
if ~isfield(cfg, fields2CheckFalse{iField})
47-
cfg = setfield(cfg, fields2CheckFalse{iField}, false); %#ok<SFLD>
48-
end
49-
end
5069

51-
% other defaults
52-
if ~isfield(expParameters, 'askGrpSess')
53-
expParameters.askGrpSess = [true true];
70+
function struct = setFieldToIfNotPresent(struct, fieldName, value)
71+
if ~isfield(struct, fieldName)
72+
struct = setfield(struct, fieldName, value); %#ok<SFLD>
5473
end
55-
56-
end
74+
end

0 commit comments

Comments
 (0)