Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,18 @@ expParameters.subjectNb = 1;
expParameters.sessionNb = 1;
expParameters.runNb = 1;

% Use the verbose switch to know where your data is being saved
expParameters.verbose = true;

% In case you are using en eyetracker
% by default we assume you are running things on a behavioral PC with no eyetracker
cfg.eyeTracker = false;
cfg.testingDevice = 'PC';

% if the device is set to 'PC' then the data will be saved
% in the `beh` folder
cfg.device = 'PC';

% if the device is set to 'scanner' then the data will be saved
% in the `func` folder
% cfg.device = 'scanner';

% check that cfg and exparameters have all the necessary information
% and fill in any missing field
expParameters = checkCFG(cfg, expParameters);
% if the testing device is set to 'PC' then the data will be saved in the `beh` folder
% if set to 'mri' then the data will be saved in the `func` folder
% cfg.testingDevice = 'mri';
% if set to 'eeg' then the data will be saved in the `eeg` folder
% cfg.testingDevice = 'eeg';

% create the filenames
expParameters = createFilename(cfg, expParameters);
% create the filenames: this include a step to check that all the information is there (checkCFG)
[cfg, expParameters] = createFilename(cfg, expParameters);

% initialize the events files with the typical BIDS
% columns (onsets, duration, trial_type)
Expand Down
110 changes: 64 additions & 46 deletions checkCFG.m
Original file line number Diff line number Diff line change
@@ -1,56 +1,74 @@
function [expParameters, cfg] = checkCFG(cfg, expParameters)
% check that we have all the fields that we need in the experiment
% parameters
function [cfg, expParameters] = checkCFG(cfg, expParameters)
% check that we have all the fields that we need in the experiment parameters

if ~isfield(expParameters, 'verbose') || isempty(expParameters.verbose)
expParameters.verbose = 0;
end

if ~isfield(expParameters, 'outputDir')
expParameters.outputDir = fullfile( ...
%% set the expParameters defaults

fieldsToSet.verbose = 0;
fieldsToSet.outputDir = fullfile( ...
fileparts(mfilename('fullpath')), ...
'..', ...
'output');
end

% set empty values for a series of field if they have not been specified
% 'ce'
% 'dir' For BIDS file naming: phase encoding direction of acquisition for fMRI
% 'rec' For BIDS file naming: reconstruction of fMRI images
% 'echo' For BIDS file naming: echo fMRI images
% 'acq' For BIDS file naming: acquisition of fMRI images
% 'subjectGrp' in case no group was provided
% 'sessionNb' in case no session was provided

fields2Check = { ...
'ce', ...
'dir', ...
'rec', ...
'echo', ...
'acq', ...
'subjectGrp', ...
'sessionNb'};

for iField = 1:numel(fields2Check)
if ~isfield(expParameters, fields2Check{iField})
expParameters = setfield(expParameters, fields2Check{iField}, []); %#ok<SFLD>
end
fieldsToSet.subjectGrp = []; % in case no group was provided
fieldsToSet.sessionNb = []; % in case no session was provided
fieldsToSet.askGrpSess = [true true];

% BIDS

% dataset description json
% required
fieldsToSet.bids.datasetDescription.json.Name = '';
fieldsToSet.bids.datasetDescription.json.BIDSVersion = '';
% recommended
fieldsToSet.bids.datasetDescription.json.License = '';
fieldsToSet.bids.datasetDescription.json.Authors = {''};
fieldsToSet.bids.datasetDescription.json.Acknowledgements = '';
fieldsToSet.bids.datasetDescription.json.HowToAcknowledge = '';
fieldsToSet.bids.datasetDescription.json.Funding = {''};
fieldsToSet.bids.datasetDescription.json.ReferencesAndLinks = {''};
fieldsToSet.bids.datasetDescription.json.DatasetDOI = '';

% mri
% for json
fieldsToSet.MRI.repetitionTime = [];
% for file naming
fieldsToSet.MRI.ce = [];
fieldsToSet.MRI.dir = []; % phase encoding direction of acquisition for fMRI
fieldsToSet.MRI.rec = []; % reconstruction of fMRI images
fieldsToSet.MRI.echo = []; % echo fMRI images
fieldsToSet.MRI.acq = []; % acquisition of fMRI images

%% loop through the defaults and set them in expParameters if they don't exist
names = fieldnames(fieldsToSet);

for i = 1:numel(names)
expParameters = setFieldToIfNotPresent(...
expParameters, ...
names{i}, ...
getfield(fieldsToSet, names{i})); %#ok<GFLD>
end

%% set the cfg defaults

clear fieldsToSet
fieldsToSet.testingDevice = 'pc';
fieldsToSet.eyeTracker = false;

% loop through the defaults and set them in cfg if they don't exist
names = fieldnames(fieldsToSet);

for i = 1:numel(names)
cfg = setFieldToIfNotPresent(...
cfg, ...
names{i}, ...
getfield(fieldsToSet, names{i})); %#ok<GFLD>
end

% set false value for a series of field if they have not been specified
fields2CheckFalse = { ...
'eyeTracker'
};
end

for iField = 1:numel(fields2CheckFalse)
if ~isfield(cfg, fields2CheckFalse{iField})
cfg = setfield(cfg, fields2CheckFalse{iField}, false); %#ok<SFLD>
end
end

% other defaults
if ~isfield(expParameters, 'askGrpSess')
expParameters.askGrpSess = [true true];
function struct = setFieldToIfNotPresent(struct, fieldName, value)
if ~isfield(struct, fieldName)
struct = setfield(struct, fieldName, value); %#ok<SFLD>
end

end
end
Loading