[Mne_analysis] Mne_analysis Digest, Vol 99, Issue 33

Teon Brooks teon.brooks at gmail.com
Mon Apr 25 15:44:48 EDT 2016
Search archives:

Hi Peng,

If you message me directly, we can sort out what's going wrong with the mne
kit2fiff for you. We can then update the listserv once we've come to a
solution. From briefly reading the discussion, I should note that the
mne.io.read_read_kit and the mne.gui.kit2fiff functions require that the
head shape and the marker file be in the original acquisition format, which
are text file typically typically. It's supported for Polhemus Fastscan,
but it should also be supported for other formats if they share the same
coordinate system.

Best,



teon
--


Teon Brooks, PhD Candidate
NSF Fellow, Chateaubriand Fellow
Department of Psychology, New York University
Researcher | OpenBCI
Co-Chair | BraiNY, Greater NYC Chapter of Society for Neuroscience

On Mon, Apr 25, 2016 at 10:14 AM, Peng Zan <zanpeng.pz at gmail.com> wrote:

> Dear JR,
>
> I am using mne Version 2.7.3. I also tried python command
> 'mne_kit2fiff.py' which had 'from mne.io import read_raw_kit' at the
> beginning. But I encountered the error saying that mayavi version was
> outdated. The error detail is as follows.
>
> [ISRWKAVW2269A:mne-python/mne/commands] Peng% python mne_kit2fiff.py
>
> Traceback (most recent call last):
>
>   File "mne_kit2fiff.py", line 72, in <module>
>
>     run()
>
>   File "mne_kit2fiff.py", line 48, in run
>
>     mne.gui.kit2fiff()
>
>   File
> "/Users/Peng/Library/Python/2.7/lib/python/site-packages/mne-0.12.dev0-py2.7.egg/mne/gui/__init__.py",
> line 107, in kit2fiff
>
>     _check_mayavi_version()
>
>   File
> "/Users/Peng/Library/Python/2.7/lib/python/site-packages/mne-0.12.dev0-py2.7.egg/mne/utils.py",
> line 832, in _check_mayavi_version
>
>     raise RuntimeError("Need mayavi >= %s" % min_version)
> RuntimeError: Need mayavi >= 4.3.0
>
>
> I have downloaded mayavi-4.4.4 but have trouble making it work with python
> mne. Do you have any idea how this problem should be solved?
>
> Thank you very much!
>
> Sincerely,
> Peng
>
> On Sat, Apr 16, 2016 at 12:00 PM, <
> mne_analysis-request at nmr.mgh.harvard.edu> wrote:
>
>> Send Mne_analysis mailing list submissions to
>>         mne_analysis at nmr.mgh.harvard.edu
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>>         https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>> or, via email, send a message with subject or body 'help' to
>>         mne_analysis-request at nmr.mgh.harvard.edu
>>
>> You can reach the person managing the list at
>>         mne_analysis-owner at nmr.mgh.harvard.edu
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of Mne_analysis digest..."
>>
>>
>> Today's Topics:
>>
>>    1. Re: mne.save_stc_as_volume('lcmv_inverse.nii.gz', stc,
>>       fwd['src'], mri_resolution=False) (Alexandre Gramfort)
>>    2. Re: mne_kit2fiff error (JR KING)
>>
>>
>> ----------------------------------------------------------------------
>>
>> Message: 1
>> Date: Fri, 15 Apr 2016 18:34:02 +0200
>> From: Alexandre Gramfort <alexandre.gramfort at telecom-paristech.fr>
>> Subject: Re: [Mne_analysis]
>>         mne.save_stc_as_volume('lcmv_inverse.nii.gz', stc, fwd['src'],
>>         mri_resolution=False)
>> To: Discussion and support forum for the users of MNE Software
>>         <mne_analysis at nmr.mgh.harvard.edu>
>> Message-ID:
>>         <CADeotZqDD8MEQy3DyTDxPVtdnFHpEy8YVL=LT9k3f3P2=
>> c-Cfg at mail.gmail.com>
>> Content-Type: text/plain; charset=UTF-8
>>
>> please don't paste code in email but use dedicated services like:
>>
>> https://gist.github.com/
>>
>> almost if you want someone to test and replicate use an MNE dataset or
>> make your data available
>>
>> A
>>
>> On Fri, Apr 15, 2016 at 2:56 PM, parham hashemzadeh <ph442 at cam.ac.uk>
>> wrote:
>> > Dear Dan
>> >   Thank you very much for spending so much time guiding me. In this
>> > email, I have pasted the complete code from line 1 to last line of the
>> > code. It is pasted after the first bit of code where I get the error and
>> > includes the bit of code that gives the error.
>> >
>> >   I implemented your advice, which by the way was very beneficial for me
>> > for pedagogical reasons.
>> >
>> > Everything went  gone smoothly until, I get the following error:
>> > --------------------------------
>> >   99 img = mne.save_stc_as_volume('lcmv_inverse.nii.gz', stc,src,
>> > mri_resolution=False)
>> >      100
>> >      101 t1_fname = data_path + '/subjects/sample/mri/T1.mgz'
>> >
>> >
>> /home/parham/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/mne-0.12.dev0-py2.7.egg/mne/source_estimate.pyc
>> > in save_stc_as_volume(fname, stc, src, dest, mri_resolution)
>> >     2649
>> >     2650     n_times = stc.data.shape[1]
>> > -> 2651     shape = src[0]['shape']
>> >     2652     shape3d = (shape[2], shape[1], shape[0])
>> >     2653     shape = (n_times, shape[2], shape[1], shape[0])
>> >
>> > KeyError: 'shape'
>> > --------------------------------
>> > ----->>>>>>>>>>>>>The COMPLETE CODE is pasted below with some crude
>> > comments:
>> > #set up all imports
>> > import sys
>> > sys.modules[__name__].__dict__.clear()
>> >
>> > import numpy as np
>> > import matplotlib.pyplot as plt
>> > plt.close("all")
>> > import mne
>> > from mne.io import Raw
>> > from mne.beamformer import lcmv
>> > from nilearn.plotting import plot_stat_map
>> > from nilearn.image import index_img
>> > from mne import read_evokeds
>> > from mne.minimum_norm import apply_inverse, read_inverse_operator
>> >
>> >
>> > print(__doc__)
>> > # I have set it up such that the MNE-sample-data is in the home
>> > directory..
>> > data_path = '/home/parham/Desktop/MNE-sample-data'
>> > #raw data file
>> > raw_fname = data_path + '/MEG/sample/sample_audvis_raw.fif'
>> > trans = data_path + '/MEG/sample/sample_audvis_raw-trans.fif'
>> > event_fname = data_path + '/MEG/sample/sample_audvis_raw-eve.fif'
>> > subj = 'sample'
>> > subjects_dir = data_path + '/subjects'
>> > aseg_fname = subjects_dir + '/sample/mri/aseg.mgz'
>> >
>> inner_skull_surf_filename='/home/parham/Desktop/MNE-sample-data/subjects/sample/bem/inner_skull.surf'
>> > #save the solution to personal code directory.
>> >
>> dest_bem_dir='/home/parham/Desktop/python_code/sample-5120-5120-5120-bem.fif'
>> >
>> bem_sol_file='/home/parham/Desktop/python_code/sample-5120-5120-5120-bem-sol.fif'
>> >
>> >
>> fwd_sol_file='/home/parham/Desktop/python_code/sample_audvis-eeg-vol-fwd.fif'
>> >
>> >
>> inv_op_file='/home/parham/Desktop/python_code/sample_audvis-eeg-vol-inv.fif'
>> > ##################### MAke EEG inverse operator############
>> >
>> >
>> > # Setup for reading the raw data
>> > raw = Raw(raw_fname)
>> > raw.info['bads'] = ['EEG 053']  # 2 bads channels
>> > picks = mne.pick_types(raw.info, meg=False, eeg=True, stim=True,
>> > eog=True,exclude='bads')
>> > events = mne.read_events(event_fname)
>> > reject = dict(eog=150e-6)
>> > event_id, tmin, tmax = 1, -0.2, 0.5
>> > epochs = mne.Epochs(raw, events, event_id=event_id, tmin=tmin,
>> > tmax=tmax, proj=True, picks=picks, baseline=(None, 0),
>> >                       preload=True, reject=reject)
>> > evoked = epochs.average()
>> > #Make the BEM model
>> > model =
>> >
>> mne.make_bem_model('/home/parham/Desktop/MNE-sample-data/subjects/sample')
>> > mne.write_bem_surfaces(dest_bem_dir, model)
>> > #setup a volume source space in the inner_skull. Compute BEM and store
>> > result.
>> > inner_skull_surface=mne.read_surface(inner_skull_surf_filename)
>> > bem_sol = mne.make_bem_solution(model)
>> > mne.write_bem_solution(bem_sol_file, bem_sol)
>> >
>> vol=mne.setup_volume_source_space(subj,surface='/home/parham/Desktop/MNE-sample-data/subjects/sample/bem/inner_skull.surf',
>> > subjects_dir=subjects_dir)
>> >
>> > # *************************MATLAB: Some simple
>> > verification****************
>> > # USE MATLAB to check that the volume source space has been setup
>> > correctly.
>> > vertidx = np.where(vol[0]['inuse'])[0]
>> > pnts=vol[0]['rr']
>> > closed_surface=inner_skull_surface[0]
>> > pnts=pnts[vertidx]
>> > import scipy.io as sio
>> > sio.savemat('/home/parham/Desktop/python_code/src.mat',
>> > {'pnts':pnts,'surf':closed_surface})
>> >
>> > ##### Returning to building the forward model and inverse operator
>> > below:
>> > #only compute the forward problem for EEG.
>> > forward_eeg=mne.make_forward_solution(raw_fname, trans, vol,
>> > bem_sol_file, fname=fwd_sol_file, meg=False, eeg=True, mindist=0.0,
>> > ignore_ref=False,overwrite=True, n_jobs=1, verbose=None)
>> > reject = dict(eeg=80e-6, eog=150e-6)
>> > # Compute the covariance from the raw data
>> > noise_cov = mne.compute_raw_covariance(raw, picks=picks, reject=reject)
>> >
>> > info = evoked.info
>> > inverse_operator_eeg = mne.minimum_norm.make_inverse_operator(info,
>> > forward_eeg, noise_cov,loose=0.2, depth=0.8)
>> > mne.minimum_norm.write_inverse_operator(inv_op_file,
>> > inverse_operator_eeg)
>> > # Read forward model from hard drive so that you check it has been
>> > written.
>> > forward = mne.read_forward_solution(fwd_sol_file)
>> > # compute data covariance matrix from epochs.
>> > data_cov = mne.compute_covariance(epochs, tmin=0.04, tmax=0.15,
>> >                                    method='shrunk')
>> >
>> > #estimate VOLUME source
>> > stc = lcmv(evoked, forward, noise_cov, data_cov, reg=0.01,
>> > pick_ori=None)
>> >
>> > # Save result in stc files
>> > stc.save('lcmv-vol')
>> >
>> > stc.crop(0.0, 0.2)
>> > src=forward['src']
>> > # Save result in a 4D nifti file
>> > img = mne.save_stc_as_volume('lcmv_inverse.nii.gz', stc,src,
>> > mri_resolution=False)
>> >
>> > t1_fname = data_path + '/subjects/sample/mri/T1.mgz'
>> >
>> > # Plotting with nilearn
>> > ######################################################
>> > plot_stat_map(index_img(img, 61), t1_fname, threshold=0.8,
>> >                title='LCMV (t=%.1f s.)' % stc.times[61])
>> >
>> > # plot source time courses with the maximum peak amplitudes
>> > plt.figure()
>> > plt.plot(stc.times, stc.data[np.argsort(np.max(stc.data,
>> > axis=1))[-40:]].T)
>> > plt.xlabel('Time (ms)')
>> > plt.ylabel('LCMV value')
>> > plt.show()
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > On 2016-04-14 16:17, dgw wrote:
>> >> Hi Parham,
>> >>
>> >> There are a couple of problems you are running into here:
>> >>
>> >> 1. That forward solution only contains MEG sensors, you would need to
>> >> generate your own with EEG only sensors if you want to.
>> >>
>> >> 2. You didn't mention changing the picks call which would also need to
>> >> be done.
>> >>
>> >> Next time if you copy and paste all and exactly what you ran, I can
>> >> probably help you quicker.
>> >>
>> >> hth
>> >> d
>> >>
>> >
>> > _______________________________________________
>> > Mne_analysis mailing list
>> > Mne_analysis at nmr.mgh.harvard.edu
>> > https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>> >
>> >
>> > The information in this e-mail is intended only for the person to whom
>> it is
>> > addressed. If you believe this e-mail was sent to you in error and the
>> e-mail
>> > contains patient information, please contact the Partners Compliance
>> HelpLine at
>> > http://www.partners.org/complianceline . If the e-mail was sent to you
>> in error
>> > but does not contain patient information, please contact the sender and
>> properly
>> > dispose of the e-mail.
>> >
>>
>>
>> ------------------------------
>>
>> Message: 2
>> Date: Fri, 15 Apr 2016 12:48:49 -0400
>> From: JR KING <jeanremi.king at gmail.com>
>> Subject: Re: [Mne_analysis] mne_kit2fiff error
>> To: Discussion and support forum for the users of MNE Software
>>         <mne_analysis at nmr.mgh.harvard.edu>
>> Message-ID:
>>         <CAOcgdciP7PKWG6WUkjpmwkWj66o8eKhvy6_aH7w=
>> 5_cTBpr7AQ at mail.gmail.com>
>> Content-Type: text/plain; charset="utf-8"
>>
>> Dear Peng,
>>
>> Which version of mne are you using? I didn't find this error in the source
>> code.
>>
>> Also, can you try using the python command directly
>>
>> from mne.io import read_raw_kit
>>
>> ?
>>
>> Best,
>>
>> JR
>>
>> On 15 April 2016 at 11:52, Peng Zan <zanpeng.pz at gmail.com> wrote:
>>
>> > Dear mne expert,
>> >
>> > I am currently transferring sqd files to fiff files using command
>> > mne_kit2fiff, while I got the following errors.
>> >
>> > ''Writing raw dataTotal number of samples is not an even multiple of the
>> > number of channels.
>> >
>> > Sorry.''
>> >
>> > Do you have any idea why this error occurred? My detailed command is as
>> > follows,
>> >
>> > ''mne_kit2fiff --elp R2197_03.25.15.elp --hpi R2197-coregis.txt --sns
>> > R2197-channel.txt --raw R2197-coregis.txt --aligntol 15 --stim 163
>> > --stimthresh .002 --sfreq 1000 --hsp R2197_03.25.15.hsp --out
>> > R2197_Tone_raw.fif''
>> >
>> > Thank you ahead for your time and answer!
>> >
>> > Sincerely,
>> >
>> > Peng Zan
>> >
>> > _______________________________________________
>> > Mne_analysis mailing list
>> > Mne_analysis at nmr.mgh.harvard.edu
>> > https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>> >
>> >
>> > The information in this e-mail is intended only for the person to whom
>> it
>> > is
>> > addressed. If you believe this e-mail was sent to you in error and the
>> > e-mail
>> > contains patient information, please contact the Partners Compliance
>> > HelpLine at
>> > http://www.partners.org/complianceline . If the e-mail was sent to you
>> in
>> > error
>> > but does not contain patient information, please contact the sender and
>> > properly
>> > dispose of the e-mail.
>> >
>> >
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL:
>> http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20160415/d22c95b8/attachment-0001.html
>>
>> ------------------------------
>>
>> _______________________________________________
>> Mne_analysis mailing list
>> Mne_analysis at nmr.mgh.harvard.edu
>> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>>
>> End of Mne_analysis Digest, Vol 99, Issue 33
>> ********************************************
>>
>
>
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>
>
> The information in this e-mail is intended only for the person to whom it
> is
> addressed. If you believe this e-mail was sent to you in error and the
> e-mail
> contains patient information, please contact the Partners Compliance
> HelpLine at
> http://www.partners.org/complianceline . If the e-mail was sent to you in
> error
> but does not contain patient information, please contact the sender and
> properly
> dispose of the e-mail.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20160425/becac33a/attachment-0001.html 


More information about the Mne_analysis mailing list