Skip to content

Commit

Permalink
Added support for MNE-Python 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ftadel committed Jun 21, 2022
1 parent b8907f7 commit 8c886e2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
33 changes: 16 additions & 17 deletions toolbox/io/out_mne_channel.m
Expand Up @@ -25,7 +25,7 @@
% For more information type "brainstorm license" at command prompt.
% =============================================================================@
%
% Authors: Francois Tadel, 2021
% Authors: Francois Tadel, 2021-2022


%% ===== PARSE INPUT =====
Expand Down Expand Up @@ -78,8 +78,6 @@
ChannelMat.SCS.NAS = cs_convert(sMri, 'mri', 'scs', sMri.SCS.NAS ./ 1000);
ChannelMat.SCS.LPA = cs_convert(sMri, 'mri', 'scs', sMri.SCS.LPA ./ 1000);
ChannelMat.SCS.RPA = cs_convert(sMri, 'mri', 'scs', sMri.SCS.RPA ./ 1000);
else

end
end

Expand Down Expand Up @@ -113,10 +111,9 @@
% Unlocking Info object
mneSetStatus = py.getattr(mneInfo, '__setstate__');
mneSetStatus(py.dict(pyargs('_unlocked', true)));
% Add Brainstorm version
bstver = bst_get('Version');
mneInfo{'hpi_meas'} = py.list(py.dict(pyargs('creator', ['Brainstorm ', bstver.Version, ' (', bstver.Date ')'])));

% % Add Brainstorm version
% bstver = bst_get('Version');
% mneInfo{'hpi_meas'} = py.list(py.dict(pyargs('creator', ['Brainstorm ', bstver.Version, ' (', bstver.Date ')'])));

% ===== TRANSFORMATIONS =====
% Get existing transformation
Expand Down Expand Up @@ -355,17 +352,19 @@
for iComp = 1:length(selComp)
% Find channels that are used in this projector
iChannels = find(any(ChannelMat.Projector(iProj).Components,2));
% Create data dictionnary
projData = py.dict(pyargs(...
'nrow', py.int(1), ...
'ncol', py.int(length(iChannels)), ...
'row_names', py.None, ...
'col_names', py.list({ChannelMat.Channel(iChannels).Name}), ...
'data', py.numpy.array(ChannelMat.Projector(iProj).Components(iChannels,selComp(iComp))', pyargs('ndmin', py.int(2)))));
% Create Projection object
pyProj = py.mne.Projection();
pyProj{'kind'} = FIFF.FIFFV_PROJ_ITEM_FIELD;
pyProj{'desc'} = py.str(ChannelMat.Projector(iProj).Comment);
pyProj{'active'} = py.bool(ChannelMat.Projector(iProj).Status == 2);
pyProj{'data'} = py.dict();
pyProj{'data'}{'nrow'} = py.int(1);
pyProj{'data'}{'ncol'} = py.int(length(iChannels));
pyProj{'data'}{'row_names'} = py.None;
pyProj{'data'}{'col_names'} = py.list({ChannelMat.Channel(iChannels).Name});
pyProj{'data'}{'data'} = py.numpy.array(ChannelMat.Projector(iProj).Components(iChannels,selComp(iComp))', pyargs('ndmin', py.int(2)));
pyProj = py.mne.Projection(pyargs(...
'data', projData, ...
'kind', FIFF.FIFFV_PROJ_ITEM_FIELD, ...
'desc', py.str(ChannelMat.Projector(iProj).Comment), ...
'active', py.bool(ChannelMat.Projector(iProj).Status == 2)));
% Add to list of projectors
mneInfo{'projs'}.append(pyProj);
end
Expand Down
28 changes: 22 additions & 6 deletions toolbox/io/out_mne_data.m
Expand Up @@ -31,7 +31,7 @@
% For more information type "brainstorm license" at command prompt.
% =============================================================================@
%
% Authors: Francois Tadel, 2019-2020
% Authors: Francois Tadel, 2019-2022


%% ===== PARSE INPUTS =====
Expand Down Expand Up @@ -165,6 +165,9 @@
%% ===== CREATE INFO OBJECT =====
% Create info object
mneInfo = out_mne_channel(ChannelFile, iChannels);
% Unlocking Info object
mneSetStatus = py.getattr(mneInfo, '__setstate__');
mneSetStatus(py.dict(pyargs('_unlocked', true)));
% Sampling frequency
mneInfo{'sfreq'} = 1 ./ (DataMat.Time(2) - DataMat.Time(1));
% Description
Expand All @@ -191,14 +194,19 @@
catch
end
end
% Locking Info object again
mneSetStatus(py.dict(pyargs('_unlocked', false)));

% Object: Raw
switch ObjType
% RAW: https://www.nmr.mgh.harvard.edu/mne/stable/generated/mne.io.Raw.html
case 'Raw'
% Create Raw object
first_samp = round(DataMat.Time(1) .* mneInfo{'sfreq'});
mneObj = py.mne.io.RawArray(bst_mat2py(DataMat.F), mneInfo, first_samp);
mneObj = py.mne.io.RawArray(pyargs(...
'data', bst_mat2py(DataMat.F), ...
'info', mneInfo, ...
'first_samp', first_samp));

% Add events
for iEvt = 1:length(DataMat.Events)
Expand Down Expand Up @@ -230,13 +238,21 @@
end
end
% Create Epoched object from concatenated trials
% mneObj = py.mne.EpochsArray(bst_mat2py(DataMat.F), mneInfo, bst_mat2py(events), DataMat.Time(1), event_id);
mneObj = py.mne.EpochsArray(DataMat.F, mneInfo, bst_mat2py(evts, 1), DataMat.Time(1), event_id);
mneObj = py.mne.EpochsArray(pyargs(...
'data', DataMat.F, ...
'info', mneInfo, ...
'events', bst_mat2py(evts, 1), ...
'tmin', DataMat.Time(1), ...
'event_id', event_id));

case 'Evoked'
% Create Evoked object
% mneObj = py.mne.EvokedArray(bst_mat2py(DataMat.F), mneInfo, DataMat.Time(1), DataMat.Comment, uint32(DataMat.nAvg));
mneObj = py.mne.EvokedArray(DataMat.F, mneInfo, DataMat.Time(1), DataMat.Comment, uint32(DataMat.nAvg));
mneObj = py.mne.EvokedArray(pyargs(...
'data', DataMat.F, ...
'info', mneInfo, ...
'tmin', DataMat.Time(1), ...
'comment', DataMat.Comment, ...
'nave', uint32(DataMat.nAvg)));
end


Expand Down

0 comments on commit 8c886e2

Please sign in to comment.