[Mne_analysis] Filtering in MNE python

Martin Luessi mluessi at nmr.mgh.harvard.edu
Mon Mar 5 18:50:43 EST 2012
Search archives:

Jon,

I'm glad you got it working. With the latest version of mne-python from 
github you can now filter Raw objects directly.

Assuming you would like to apply a band-pass from 1 to 50Hz with a 
filter length of 2048 to all MEG channels, you would use:

raw = fiff.Raw(raw_fname, preload=True)
picks = mne.fiff.pick_types(raw.info, meg=True)

raw.band_pass_filter(picks, 1.0, 50.0, filter_length=2048)

This will apply the band-pass to all channels in "picks". If you have a 
fast computer with enough RAM and you can use

raw.band_pass_filter(picks, 1.0, 50.0, filter_length=2048, n_jobs=8)

which will run the filtering in parallel on 8 CPUs.

I hope this is helpful to you.

Best,

Martin

On 02/08/12 14:56, Jon Houck wrote:
> Martin,
>
> This was helpful, thanks.  On the first pass I got a new error message,
> "AttributeError: 'module' object has no attribute 'firwin2'.".
>   Updating from scipy 0.7.2 to numpy 1.6.1 and scipy 0.10.0 fixed this,
> and it works perfectly now.
>
>
>
>
> Regards,
>
> Jon
>
>
>
>
>
>
>
> On Fri, Feb 3, 2012 at 6:29 PM, Martin Luessi
> <mluessi at nmr.mgh.harvard.edu <mailto:mluessi at nmr.mgh.harvard.edu>> wrote:
>
>
>     On 02/03/12 17:44, Jon Houck wrote:
>      > Hi all,
>      >
>      > I've been trying to filter raw data in MNE python and am getting the
>      > error message: AttributeError: 'Raw' object has no attribute 'ndim'.
>      >  The tutorial exercises have run perfectly  for me, using both the
>      > sample data and my own data, so the most likely cause is user error.
>      >  The commands in ipython are:
>      >
>      >     import numpy as np
>      >     from mne import fiff
>      >     from mne import filter
>      >     data_path =
>      >
>     '/usr/lib/python2.6/site-packages/mne-0.2.git-py2.6.egg/mne/datasets/sample/MNE-sample-data'
>      >     raw_fname = data_path + '/MEG/sample/sample_audvis_raw.fif'
>      >     raw = fiff.Raw(raw_fname)
>      >     raw = filter.band_pass_filter(raw, 1000, 50, 1,
>     filter_length=2048)
>      >
>      > What's the correct way to do this?  From the error, I'd guess
>     that I'm
>      > either passing the wrong part the array to the filter, or
>     skipping some
>      > important step.  I'm using mne-tools-mne-python-v0.2-70-g9a72ede in
>      > python 2.6, on a machine running 64-bit CentOS 6.  The complete error
>      > message is below.
>
>     Jon,
>
>     mne-python currently doesn't support direct filtering operations on Raw
>     objects; the filtering operations only support 1D ndarrays i.e., a
>     single time series, as input.
>
>     Using the latest mne-python version from github, you could do what you
>     want as follows:
>
>     raw = fiff.Raw(raw_fname, preload=True)
>     data, times = raw[:, :]
>     sfreq = float(raw.info <http://raw.info>['sfreq'])
>     data_filtered = numpy.array([filter.band_pass_filter(x, sfreq, 50, 1,
>     filter_length=2048) for x in data])
>     raw[:, :] = data_filtered
>
>     Note that for band_pass you need Fp1 < Fp2, so the above still won't
>     work (I assume it should be 1, 50, 1..50Hz).
>
>     Best,
>
>     Martin
>
>     --
>     Martin Luessi, Ph.D.
>
>     Research Fellow
>
>     Department of Radiology
>     Athinoula A. Martinos Center for Biomedical Imaging
>     Massachusetts General Hospital
>     Harvard Medical School
>     149 13th Street
>     Charlestown, MA 02129
>
>     Fax: +1 617 726-7422 <tel:%2B1%20617%20726-7422>
>
>
>     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.
>
>
>
>


-- 
Martin Luessi, Ph.D.

Research Fellow

Department of Radiology
Athinoula A. Martinos Center for Biomedical Imaging
Massachusetts General Hospital
Harvard Medical School
149 13th Street
Charlestown, MA 02129

Fax: +1 617 726-7422



More information about the Mne_analysis mailing list