mne-tools / mne-python

MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
https://mne.tools
BSD 3-Clause "New" or "Revised" License
2.68k stars 1.31k forks source link

Continuous wavelet transform #1177

Closed dongqunxi closed 10 years ago

dongqunxi commented 10 years ago

How to filter the MEG data using a continuous wavelet transform, is there any module can be used?

agramfort commented 10 years ago

use the morlet function to generate a morlet wavelet et the apply_function of Raw to do the convolution.

dongqunxi commented 10 years ago

Sorry, I didn't get the meaning, can you give me a sample? Thanks!

Best wishes, Qunxi Dong

2014-03-10 15:46 GMT+01:00 Alexandre Gramfort notifications@github.com:

use the morlet function to generate a morlet wavelet et the apply_function of Raw to do the convolution.

Reply to this email directly or view it on GitHubhttps://github.com/mne-tools/mne-python/issues/1177#issuecomment-37189565 .

agramfort commented 10 years ago
# Authors: Alexandre Gramfort <gramfort@nmr.mgh.harvard.edu>
# License: BSD (3-clause)

print(__doc__)

import numpy as np
import matplotlib.pyplot as plt
from  scipy import signal

import mne
from mne import fiff, read_proj, read_selection
from mne.datasets import sample

###############################################################################
# Set parameters
data_path = sample.data_path()
raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'

# Setup for reading the raw data
raw = fiff.Raw(raw_fname, preload=True)

w = mne.time_frequency.morlet(raw.info['sfreq'], freqs=[7], n_cycles=3,
                              zero_mean=True)[0]

def conv(x):
    return signal.convolve(x, w, mode='same')

dtype = np.complex
picks = mne.fiff.pick_types(raw.info, meg=True)
raw.apply_function(conv, picks, dtype=dtype, n_jobs=1)
dongqunxi commented 10 years ago

Hi @agramfort, When I run this script on my raw data

raw_cwt = raw.apply_function(conv, picks=picks, dtype=dtype, n_jobs=1)

Got an error:

ValueError                                Traceback (most recent call last)
/home/qdong/Canopy/appdata/canopy-1.3.0.1715.rh5-x86_64/lib/python2.7/site-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
    202             else:
    203                 filename = fname
--> 204             __builtin__.execfile(filename, *where)

/home/qdong/Forward and Inverse Problem Version1/MEG/ROI_time_freq.py in <module>()
     43   return signal.convolve(x, fun)
     44 dtype = np.complex
---> 45 raw_cwt = raw.apply_function(conv, picks=picks, dtype=dtype, n_jobs=1)
     46 
     47 #raw.apply_function()

/home/qdong/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/mne-0.8.git-py2.7.egg/mne/fiff/raw.pyc in apply_function(self, fun, picks, dtype, n_jobs, verbose, *args, **kwargs)

/home/qdong/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/mne-0.8.git-py2.7.egg/mne/utils.pyc in verbose(function, *args, **kwargs)
    390         return ret
    391     else:
--> 392         ret = function(*args, **kwargs)
    393         return ret
    394 

/home/qdong/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/mne-0.8.git-py2.7.egg/mne/fiff/raw.pyc in apply_function(self, fun, picks, dtype, n_jobs, verbose, *args, **kwargs)
    466             # modify data inplace to save memory
    467             for idx in picks:
--> 468                 self._data[idx, :] = fun(data_in[idx, :], *args, **kwargs)
    469         else:
    470             # use parallel function

ValueError: could not broadcast input array from shape (177240) into shape (176548) 
dengemann commented 10 years ago

@dongqunxi irrespectively of this particular error. What is the goal of your analysis? If you want to investigate task-related effects I would consider this example and in general the time-frequency section of our documentation.

dongqunxi commented 10 years ago

I want to perform a wavelet transformation of the MEG signals before peforming the MNE. Ok, I will check it.

Best wishes, Qunxi Dong

2014-03-11 10:09 GMT+01:00 Denis A. Engemann notifications@github.com:

@dongqunxi https://github.com/dongqunxi irrespectively of this particular error. What is the goal of your analysis? If you want to investigate task-related effects I would consider this examplehttp://martinos.org/mne/dev/auto_examples/time_frequency/plot_source_label_time_frequency.html#example-time-frequency-plot-source-label-time-frequency-py

and in general the time-frequency section of our documentation

Reply to this email directly or view it on GitHubhttps://github.com/mne-tools/mne-python/issues/1177#issuecomment-37275374 .

dongqunxi commented 10 years ago

I thought I lost one parameter mode='same' in

signal.convolve(x, w, mode='same')

Thanks!