Skip to content

Commit

Permalink
pass readbids and other low-level options consistently to ft_read_header
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoostenveld committed Sep 17, 2020
1 parent f480d99 commit 2c3a17f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
6 changes: 3 additions & 3 deletions fileio/ft_read_header.m
Expand Up @@ -286,9 +286,9 @@
ft_error('dewar coordinates are not supported for %s', headerformat);
end

if readbids
if istrue(readbids)
% deal with data that is organized according to BIDS
% data in a BIDS tsv file (like physio and stim) will be explicitly dealt with in BIDS_TSV
% data in a BIDS tsv file (like physio and stim) will be explicitly dealt with in BIDS_TSV
[p, f, x] = fileparts(filename);
isbids = startsWith(f, 'sub-') && ~strcmp(x, '.tsv');
if isbids
Expand Down Expand Up @@ -2817,7 +2817,7 @@
end
end

if readbids && isbids
if istrue(readbids) && isbids
% the BIDS sidecar files overrule the information present in the file header itself
try, hdr.label = channels_tsv.name; end
try, hdr.chantype = channels_tsv.type; end
Expand Down
18 changes: 14 additions & 4 deletions ft_databrowser.m
Expand Up @@ -217,6 +217,15 @@
cfg.contournum = ft_getopt(cfg, 'contournum', 0); % topoplot contour lines
cfg.trl = ft_getopt(cfg, 'trl');

% construct the low-level options as key-value pairs, these are passed to FT_READ_HEADER
headeropt = {};
headeropt = ft_setopt(headeropt, 'headerformat', ft_getopt(cfg, 'headerformat')); % is passed to low-level function, empty implies autodetection
headeropt = ft_setopt(headeropt, 'readbids', ft_getopt(cfg, 'readbids')); % is passed to low-level function
headeropt = ft_setopt(headeropt, 'coordsys', ft_getopt(cfg, 'coordsys', 'head')); % is passed to low-level function
headeropt = ft_setopt(headeropt, 'coilaccuracy', ft_getopt(cfg, 'coilaccuracy')); % is passed to low-level function
headeropt = ft_setopt(headeropt, 'checkmaxfilter', ft_getopt(cfg, 'checkmaxfilter')); % this allows to read non-maxfiltered neuromag data recorded with internal active shielding
headeropt = ft_setopt(headeropt, 'chantype', ft_getopt(cfg, 'chantype', {})); % 2017.10.10 AB required for NeuroOmega files

if ~isfield(cfg, 'viewmode')
% butterfly, vertical, component
if hascomp
Expand Down Expand Up @@ -336,7 +345,7 @@
cfg = ft_checkconfig(cfg, 'renamed', {'datatype', 'continuous'});
cfg = ft_checkconfig(cfg, 'renamedval', {'continuous', 'continuous', 'yes'});
% read the header from file
hdr = ft_read_header(cfg.headerfile, 'headerformat', cfg.headerformat);
hdr = ft_read_header(cfg.headerfile, headeropt{:});

if isempty(cfg.continuous)
if hdr.nTrials==1
Expand Down Expand Up @@ -429,7 +438,7 @@
dat = data.trial{sel}(chansel,:);
else
% one second of data is read from file to determine the vertical scaling
dat = ft_read_data(cfg.datafile, 'header', hdr, 'begsample', 1, 'endsample', round(hdr.Fs), 'chanindx', chansel, 'checkboundary', strcmp(cfg.continuous, 'no'), 'dataformat', cfg.dataformat, 'headerformat', cfg.headerformat);
dat = ft_read_data(cfg.datafile, 'header', hdr, 'begsample', 1, 'endsample', round(hdr.Fs), 'chanindx', chansel, 'checkboundary', strcmp(cfg.continuous, 'no'), 'dataformat', cfg.dataformat, headeropt{:});
end % if hasdata
% convert the data to another numeric precision, i.e. double, single or int32
if ~isempty(cfg.precision)
Expand Down Expand Up @@ -573,7 +582,8 @@
if hasdata
opt.orgdata = data;
else
opt.orgdata = []; % this means that it will read from cfg.dataset
opt.orgdata = []; % this means that it will read from cfg.dataset
opt.headeropt = headeropt; % these are passed to FT_READ_HEADER and FT_READ_DATA
end
if strcmp(cfg.continuous, 'yes')
opt.trialviewtype = 'segment';
Expand Down Expand Up @@ -1616,7 +1626,7 @@ function redraw_cb(h, eventdata)
end

if isempty(opt.orgdata)
dat = ft_read_data(cfg.datafile, 'header', opt.hdr, 'begsample', begsample, 'endsample', endsample, 'chanindx', chanindx, 'checkboundary', ~istrue(cfg.continuous), 'dataformat', cfg.dataformat, 'headerformat', cfg.headerformat);
dat = ft_read_data(cfg.datafile, 'header', opt.hdr, 'begsample', begsample, 'endsample', endsample, 'chanindx', chanindx, 'checkboundary', ~istrue(cfg.continuous), 'dataformat', cfg.dataformat, opt.headeropt{:});
else
dat = ft_fetch_data(opt.orgdata, 'header', opt.hdr, 'begsample', begsample, 'endsample', endsample, 'chanindx', chanindx, 'allowoverlap', cfg.allowoverlap);
end
Expand Down
23 changes: 12 additions & 11 deletions ft_preprocessing.m
Expand Up @@ -215,14 +215,9 @@
cfg.precision = ft_getopt(cfg, 'precision', 'double');
cfg.padding = ft_getopt(cfg, 'padding', 0); % padding is only done when filtering
cfg.paddir = ft_getopt(cfg, 'paddir', 'both');
cfg.headerformat = ft_getopt(cfg, 'headerformat'); % is passed to low-level function, empty implies autodetection
cfg.dataformat = ft_getopt(cfg, 'dataformat'); % is passed to low-level function, empty implies autodetection
cfg.coordsys = ft_getopt(cfg, 'coordsys', 'head'); % is passed to low-level function
cfg.coilaccuracy = ft_getopt(cfg, 'coilaccuracy'); % is passed to low-level function
cfg.checkmaxfilter = ft_getopt(cfg, 'checkmaxfilter'); % this allows to read non-maxfiltered neuromag data recorded with internal active shielding
cfg.montage = ft_getopt(cfg, 'montage', 'no');
cfg.updatesens = ft_getopt(cfg, 'updatesens', 'no'); % in case a montage or rereferencing is specified
cfg.chantype = ft_getopt(cfg, 'chantype', {}); %2017.10.10 AB required for NeuroOmega files
cfg.dataformat = ft_getopt(cfg, 'dataformat'); % is passed to low-level function, empty implies autodetection

% these options relate to the actual preprocessing, it is necessary to specify here because of padding
cfg.dftfilter = ft_getopt(cfg, 'dftfilter', 'no');
Expand All @@ -239,6 +234,15 @@
cfg.refmethod = ft_getopt(cfg, 'refmethod', 'avg');
cfg.implicitref = ft_getopt(cfg, 'implicitref');

% construct the low-level options as key-value pairs, these are passed to FT_READ_HEADER and FT_READ_DATA
headeropt = {};
headeropt = ft_setopt(headeropt, 'headerformat', ft_getopt(cfg, 'headerformat')); % is passed to low-level function, empty implies autodetection
headeropt = ft_setopt(headeropt, 'readbids', ft_getopt(cfg, 'readbids')); % is passed to low-level function
headeropt = ft_setopt(headeropt, 'coordsys', ft_getopt(cfg, 'coordsys', 'head')); % is passed to low-level function
headeropt = ft_setopt(headeropt, 'coilaccuracy', ft_getopt(cfg, 'coilaccuracy')); % is passed to low-level function
headeropt = ft_setopt(headeropt, 'checkmaxfilter', ft_getopt(cfg, 'checkmaxfilter')); % this allows to read non-maxfiltered neuromag data recorded with internal active shielding
headeropt = ft_setopt(headeropt, 'chantype', ft_getopt(cfg, 'chantype', {})); % 2017.10.10 AB required for NeuroOmega files

if ~isfield(cfg, 'feedback')
if strcmp(cfg.method, 'channel')
cfg.feedback = 'none';
Expand Down Expand Up @@ -401,9 +405,7 @@
cfg = ft_checkconfig(cfg, 'renamedval', {'continuous', 'continuous', 'yes'});

% read the header
hdr = ft_read_header(cfg.headerfile, 'headerformat', cfg.headerformat,...
'coordsys', cfg.coordsys, 'coilaccuracy', cfg.coilaccuracy,...
'checkmaxfilter', cfg.checkmaxfilter, 'chantype', cfg.chantype);
hdr = ft_read_header(cfg.headerfile, headeropt{:});

% this option relates to reading over trial boundaries in a pseudo-continuous dataset
if ~isfield(cfg, 'continuous')
Expand Down Expand Up @@ -589,7 +591,7 @@

% read the raw data with padding on both sides of the trial - this
% includes datapadding
dat = ft_read_data(cfg.datafile, 'header', hdr, 'begsample', begsample, 'endsample', endsample, 'chanindx', rawindx, 'checkboundary', strcmp(cfg.continuous, 'no'), 'dataformat', cfg.dataformat);
dat = ft_read_data(cfg.datafile, 'header', hdr, 'begsample', begsample, 'endsample', endsample, 'chanindx', rawindx, 'checkboundary', strcmp(cfg.continuous, 'no'), 'dataformat', cfg.dataformat, headeropt{:});

% convert the data to another numeric precision, i.e. double, single or int32
if ~isempty(cfg.precision)
Expand Down Expand Up @@ -709,4 +711,3 @@
ft_postamble provenance data
ft_postamble history data
ft_postamble savevar data

0 comments on commit 2c3a17f

Please sign in to comment.