Skip to content

Commit

Permalink
Merge pull request #99 from thomas-vincent/surface_glm
Browse files Browse the repository at this point in the history
Surface glm
- add import/export of manual markings: events and bad channel tagging
- add computation of HbT after projection
- fix negative values introduced during motion correction
  • Loading branch information
thomas-vincent authored Jul 6, 2019
2 parents 893f8d4 + 37dd65e commit 3759708
Show file tree
Hide file tree
Showing 20 changed files with 1,210 additions and 177 deletions.
4 changes: 4 additions & 0 deletions bst_plugin/MANIFEST
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
nst_bst_import_channel_flags.m
nst_bst_export_channel_flags.m
nst_bst_export_events.m
nst_bst_import_events.m
nst_io_fetch_sample_data.m
nst_bst_set_template_anatomy.m
nst_core_get_available_templates.m
Expand Down
19 changes: 19 additions & 0 deletions bst_plugin/nst_bst_export_channel_flags.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function nst_bst_export_channel_flags(sFile, channel_flags_fn)
%NST_BST_EXPORT_CHANNEL_FLAGS Save channel flags from given sFile
% into given channel_flags_fn.
% TODO: also save list of channels
if ischar(sFile)
bst_chan_data = load(file_fullpath(sFile), 'ChannelFlag');
bst_chan_flags = bst_chan_data.ChannelFlag;
end
[root, bfn, ext] = fileparts(channel_flags_fn);
switch ext
case '.mat'
s.channel_flags = bst_chan_flags;
bst_save(channel_flags_fn, s, 'v7');
otherwise
error(sprintf('Unsupported extension for channel file: "%s"', ext));
end
end


20 changes: 20 additions & 0 deletions bst_plugin/nst_bst_export_events.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function nst_bst_export_events(sFile, event_fn)
% Wrapper around bst functions to export events.

if ischar(sFile)
bst_evt_data = load(file_fullpath(sFile), 'Events');
bst_events = bst_evt_data.Events;
else
bst_events = sFile.Events;
end


[root, bfn, ext] = fileparts(event_fn);
switch ext
case '.mat'
s.events = bst_events;
bst_save(event_fn, s, 'v7');
otherwise
error(sprintf('Unsupported extension for event file: "%s"', ext));
end
end
63 changes: 63 additions & 0 deletions bst_plugin/nst_bst_import_channel_flags.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
function sFileUpdated = nst_bst_import_channel_flags(sFile, channel_flags_fn)
%NST_BST_EXPORT_CHANNEL_FLAGS Save channel flags from given sFile
% into given channel_flags_fn.
% TODO: also save list of channels to always insure that chan flags array
% is aligned with channel info
%
% Inputs:
% - sFile (struct or str): data to import into.
% either a brainstorm data structure or a mat file containing
% the data structure
% - events_fn (str): channel flags file
% Channel flag information. Suported format: .mat
%
% Outputs:
% - sFile (struct or str): same type as sFile intput
%
% TODO: utest with struct input

STRUCT = 1;
FILE = 2;
if isstruct(sFile)
obj_type = STRUCT;
else
assert(ischar(sFile));

sFile_fn = sFile;
obj_type = FILE;

isRaw = ~isempty(strfind(sFile_fn, '_0raw'));
if isRaw
DataMat = in_bst_data(sFile_fn, 'F');
sFile = DataMat.F;
else
DataMat = in_fopen_bstmat(sFile_fn);
sFile = DataMat;
end
end

[root, bfn, ext] = fileparts(channel_flags_fn);
sFileUpdated = sFile;
switch ext
case '.mat'
chan_flags_data = load(channel_flags_fn);
sFileUpdated.ChannelFlag = chan_flags_data.channel_flags;
%TODO: save channel flags properly -> should be in channel header
%file, not data file!
otherwise
error(sprintf('Unsupported extension for channel file: "%s"', ext));
end

if obj_type == FILE
% Report changes in .mat structure
DataMat.ChannelFlag = sFileUpdated.ChannelFlag;
if isRaw
DataMat.F.channelflag = chan_flags_data.channel_flags;
end
% Save file definition
bst_save(file_fullpath(sFile_fn), DataMat, 'v6', 1);

sFileUpdated = sFile_fn;
end

end
59 changes: 59 additions & 0 deletions bst_plugin/nst_bst_import_events.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
function sFileUpdated = nst_bst_import_events(sFile, events_fn)
% Wrapper around bst functions to import events from given file event_fn into
% given sFile (file or struct), in a backward compatible way.
% Load according to format based on extension
%
% Inputs:
% - sFile (struct or str): data to import into.
% either a brainstorm data structure or a mat file containing
% the data structure
% - events_fn (str): event file
% Event information. Suported format: .mat
%
% Outputs:
% - sFile (struct or str): same type as sFile intput
%
% TODO: utest with struct input

STRUCT = 1;
FILE = 2;
if isstruct(sFile)
obj_type = STRUCT;
else
assert(ischar(sFile));

sFile_fn = sFile;
obj_type = FILE;

isRaw = ~isempty(strfind(sFile_fn, '_0raw'));
if isRaw
DataMat = in_bst_data(sFile_fn, 'F');
sFile = DataMat.F;
else
DataMat = in_fopen_bstmat(sFile_fn);
sFile = DataMat;
end
end

[root, bfn, ext] = fileparts(events_fn);
switch ext
case '.mat'
sFileUpdated = import_events(sFile, [], events_fn, 'BST');
otherwise
error(sprintf('Unsupported extension for event file: "%s"', ext));
end

if obj_type == FILE
% Report changes in .mat structure
if isRaw
DataMat.F = sFileUpdated;
else
DataMat.Events = sFileUpdated.events;
end
% Save file definition
bst_save(file_fullpath(sFile_fn), DataMat, 'v6', 1);

sFileUpdated = sFile_fn;
end

end
15 changes: 15 additions & 0 deletions bst_plugin/nst_bst_load_events.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function bst_events = nst_bst_load_events(event_fn)
% Wrapper around bst functions to save events in a backward compatible mode
% Save according to format based on extension
wrapper.events = [];
[root, bfn, ext] = fileparts(event_fn);
switch ext
case '.mat'
% Use dummy sampling frequency high enough so that times are not rounded
wrapper.prop.sfreq = 1e6;
wrapper = import_events(wrapper, [], event_fn, 'BST');
bst_events = wrapper.events;
otherwise
error(sprintf('Unsupported extension for event file: "%s"', ext));
end
end
15 changes: 15 additions & 0 deletions bst_plugin/nst_bst_save_events.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function nst_bst_save_events(bst_events, event_fn)
% Wrapper around bst functions to load event in a backward compatible mode
% Load according to format based on extension

[root, bfn, ext] = fileparts(event_fn);
switch ext
case '.mat'
wrapper.events = bst_events;
% Emulate sampling frequency high enough to avoid rounding of times
% wrapper.prop.sfreq = 2.0 / min(diff(sort([bst_events.times])));
export_events(wrapper, [], event_fn);
otherwise
error(sprintf('Unsupported extension for event file: "%s"', ext));
end
end
Loading

0 comments on commit 3759708

Please sign in to comment.