diff --git a/toolbox/io/out_mne_channel.m b/toolbox/io/out_mne_channel.m index 7e7e962d4..cb5a2b59e 100644 --- a/toolbox/io/out_mne_channel.m +++ b/toolbox/io/out_mne_channel.m @@ -25,7 +25,7 @@ % For more information type "brainstorm license" at command prompt. % =============================================================================@ % -% Authors: Francois Tadel, 2021 +% Authors: Francois Tadel, 2021-2022 %% ===== PARSE INPUT ===== @@ -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 @@ -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 @@ -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 diff --git a/toolbox/io/out_mne_data.m b/toolbox/io/out_mne_data.m index 1a255346c..106900f66 100644 --- a/toolbox/io/out_mne_data.m +++ b/toolbox/io/out_mne_data.m @@ -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 ===== @@ -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 @@ -191,6 +194,8 @@ catch end end +% Locking Info object again +mneSetStatus(py.dict(pyargs('_unlocked', false))); % Object: Raw switch ObjType @@ -198,7 +203,10 @@ 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) @@ -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