Skip to content

Commit

Permalink
Bugfix: Export to FieldTrip works with raw data
Browse files Browse the repository at this point in the history
  • Loading branch information
rcassani committed Sep 18, 2023
1 parent 7efe712 commit be9102b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion doc/license.html
Expand Up @@ -5,7 +5,7 @@
<body alink="#fff000" link="#fff000" vlink="#fff000">
<h4><span style="font-family: Arial Black; color: #ffffff;"><strong>THERE IS NO UNDO BUTTON!<BR>SET UP A <FONT color=red>BACKUP</FONT> OF YOUR DATABASE</strong></span></h4>
<HR>
<!-- LICENCE_START -->Version: 3.230913 (13-Sep-2023)<br>
<!-- LICENCE_START -->Version: 3.230918 (18-Sep-2023)<br>
<span style="font-style: italic;">COPYRIGHT &copy; 2000-2023
USC &amp; McGill University.<br>
</span>
Expand Down
2 changes: 1 addition & 1 deletion doc/version.txt
@@ -1,2 +1,2 @@
% Brainstorm
% v. 3.230913 (13-Sep-2023)
% v. 3.230918 (18-Sep-2023)
31 changes: 26 additions & 5 deletions toolbox/io/out_fieldtrip_data.m
Expand Up @@ -60,7 +60,15 @@
% ===== LOAD INPUTS =====
% Load data file
if ~isempty(DataFile)
isRawIn = ~isempty(strfind(DataFile, '_0raw'));
DataMat = in_bst_data(DataFile);
% Get raw file structure
if isRawIn
sFileIn = DataMat.F;
if (length(sFileIn.epochs) > 1)
error('Cannot export epoched files.');
end
end
% Get ChannelFile if not provided
if isempty(ChannelFile)
ChannelFile = bst_get('ChannelFileForStudy', DataFile);
Expand Down Expand Up @@ -91,21 +99,34 @@
iChannels = 1:size(DataMat.F,1);
end

% ===== RECORDINGS =====
% Get recordings
if isRawIn
ImportOptions = db_template('ImportOptions');
ImportOptions.ImportMode = 'Time';
ImportOptions.DisplayMessages = 0;
ImportOptions.UseCtfComp = 0;
ImportOptions.UseSsp = 0;
ImportOptions.RemoveBaseline = 'no';
F = in_fread(sFileIn, ChannelMat, 1, [], iChannels, ImportOptions);
else
F = DataMat.F(iChannels,:);
end

% Convert to FieldTrip data structure
ftData = struct();
ftData.dimord = 'chan_time';

% ===== RECORDINGS =====
% Timelock structure: see ft_datatype_timelock.m
if isTimelock
ftData.avg = DataMat.F(iChannels,:);
ftData.dimord = 'chan_time';
ftData.avg = F;
ftData.time = DataMat.Time;
% if isfield(DataMat, 'Std') && ~isempty(DataMat.Std)
% ftData.var = DataMat.Std(iChannels,:);
% end
% Raw structure: see ft_datatype_raw.m
else
ftData.trial{1} = DataMat.F(iChannels,:);
ftData.time{1} = DataMat.Time;
ftData.trial{1} = F;
end

% ===== CHANNEL INFO =====
Expand Down

0 comments on commit be9102b

Please sign in to comment.