[Mne_analysis] Filtering in MNE python

Martin Luessi mluessi at nmr.mgh.harvard.edu
Fri Feb 3 20:29:56 EST 2012
Search archives:

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['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



More information about the Mne_analysis mailing list