-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from thomas-vincent/surface_glm
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
Showing
20 changed files
with
1,210 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.