This is an automated email from the git hooks/post-receive script. yoh pushed a commit to tag 0.4 in repository python-mne.
commit 4e948cf1d6e6ef5589e47b0acffdf2b5ed72f2b1 Author: Alexandre Gramfort <[email protected]> Date: Wed Jul 4 16:57:13 2012 +0200 ENH : new option to have morlet be zero mean (relevant for low number of cycles) --- examples/time_frequency/plot_time_frequency.py | 2 +- mne/minimum_norm/time_frequency.py | 8 ++++--- mne/time_frequency/tfr.py | 32 ++++++++++++++++++-------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/examples/time_frequency/plot_time_frequency.py b/examples/time_frequency/plot_time_frequency.py index 66a26bd..fad28a7 100644 --- a/examples/time_frequency/plot_time_frequency.py +++ b/examples/time_frequency/plot_time_frequency.py @@ -57,7 +57,7 @@ Fs = raw.info['sfreq'] # sampling in Hz decim = 3 power, phase_lock = induced_power(data, Fs=Fs, frequencies=frequencies, n_cycles=n_cycles, n_jobs=1, use_fft=False, - decim=decim) + decim=decim, zero_mean=True) # baseline corrections with ratio power /= np.mean(power[:, :, times[::decim] < 0], axis=2)[:, :, None] diff --git a/mne/minimum_norm/time_frequency.py b/mne/minimum_norm/time_frequency.py index 18e89d5..48a903d 100644 --- a/mne/minimum_norm/time_frequency.py +++ b/mne/minimum_norm/time_frequency.py @@ -166,7 +166,7 @@ def _compute_pow_plv(data, K, sel, Ws, source_ori, use_fft, Vh, with_plv, def _source_induced_power(epochs, inverse_operator, frequencies, label=None, lambda2=1.0 / 9.0, method="dSPM", n_cycles=5, decim=1, use_fft=False, pca=True, pick_normal=True, - n_jobs=1, with_plv=True): + n_jobs=1, with_plv=True, zero_mean=False): """Aux function for source_induced_power """ parallel, my_compute_pow_plv, n_jobs = parallel_func(_compute_pow_plv, @@ -207,7 +207,7 @@ def _source_induced_power(epochs, inverse_operator, frequencies, label=None, print 'Computing source power ...' - Ws = morlet(Fs, frequencies, n_cycles=n_cycles) + Ws = morlet(Fs, frequencies, n_cycles=n_cycles, zero_mean=zero_mean) n_jobs = min(n_jobs, len(epochs_data)) out = parallel(my_compute_pow_plv(data, K, sel, Ws, @@ -234,7 +234,7 @@ def source_induced_power(epochs, inverse_operator, frequencies, label=None, lambda2=1.0 / 9.0, method="dSPM", n_cycles=5, decim=1, use_fft=False, pick_normal=False, baseline=None, baseline_mode='logratio', pca=True, n_jobs=1, - dSPM=None): + dSPM=None, zero_mean=False): """Compute induced power and phase lock Computation can optionaly be restricted in a label. @@ -282,6 +282,8 @@ def source_induced_power(epochs, inverse_operator, frequencies, label=None, e.g. with a dataset that was maxfiltered (true dim is 64) n_jobs: int Number of jobs to run in parallel + zero_mean: bool + Make sure the wavelets are zero mean. """ method = _check_method(method, dSPM) diff --git a/mne/time_frequency/tfr.py b/mne/time_frequency/tfr.py index 3587a0c..c3eb4fd 100644 --- a/mne/time_frequency/tfr.py +++ b/mne/time_frequency/tfr.py @@ -15,7 +15,7 @@ from ..baseline import rescale from ..parallel import parallel_func -def morlet(Fs, freqs, n_cycles=7, sigma=None): +def morlet(Fs, freqs, n_cycles=7, sigma=None, zero_mean=False): """Compute Wavelets for the given frequency range Parameters @@ -38,6 +38,9 @@ def morlet(Fs, freqs, n_cycles=7, sigma=None): like for the short time Fourier transform and the number of oscillations increases with the frequency. + zero_mean : bool + Make sure the wavelet is zero mean + Returns ------- Ws : list of array @@ -62,8 +65,13 @@ def morlet(Fs, freqs, n_cycles=7, sigma=None): # (sigma_t*sqrt(pi))^(-1/2); t = np.arange(0, 5 * sigma_t, 1.0 / Fs) t = np.r_[-t[::-1], t[1:]] - W = np.exp(2.0 * 1j * np.pi * f * t) - W *= np.exp(-t ** 2 / (2.0 * sigma_t ** 2)) + oscillation = np.exp(2.0 * 1j * np.pi * f * t) + gaussian_enveloppe = np.exp(-t ** 2 / (2.0 * sigma_t ** 2)) + if zero_mean: # to make it zero mean + real_offset = np.exp(- 2 * (np.pi * f * sigma_t) ** 2) + oscillation -= real_offset + W = oscillation * gaussian_enveloppe + # zero mean the wavelet (required) W /= sqrt(0.5) * linalg.norm(W.ravel()) Ws.append(W) return Ws @@ -146,7 +154,7 @@ def _cwt_convolve(X, Ws, mode='same'): yield tfr -def cwt_morlet(X, Fs, freqs, use_fft=True, n_cycles=7.0): +def cwt_morlet(X, Fs, freqs, use_fft=True, n_cycles=7.0, zero_mean=False): """Compute time freq decomposition with Morlet wavelets Parameters @@ -161,6 +169,8 @@ def cwt_morlet(X, Fs, freqs, use_fft=True, n_cycles=7.0): Compute convolution with FFT or temoral convolution. n_cycles: float | array of float Number of cycles. Fixed number or one per frequency. + zero_mean : bool + Make sure the wavelets are zero mean. Returns ------- @@ -173,7 +183,7 @@ def cwt_morlet(X, Fs, freqs, use_fft=True, n_cycles=7.0): n_frequencies = len(freqs) # Precompute wavelets for given frequency range to save time - Ws = morlet(Fs, freqs, n_cycles=n_cycles) + Ws = morlet(Fs, freqs, n_cycles=n_cycles, zero_mean=zero_mean) if use_fft: coefs = _cwt_fft(X, Ws, mode) @@ -245,7 +255,7 @@ def _time_frequency(X, Ws, use_fft): def single_trial_power(data, Fs, frequencies, use_fft=True, n_cycles=7, baseline=None, baseline_mode='ratio', times=None, - n_jobs=1): + n_jobs=1, zero_mean=False): """Compute time-frequency power on single epochs Parameters @@ -278,6 +288,8 @@ def single_trial_power(data, Fs, frequencies, use_fft=True, n_cycles=7, Required to define baseline n_jobs : int The number of epochs to process at the same time + zero_mean : bool + Make sure the wavelets are zero mean. Returns ------- @@ -289,7 +301,7 @@ def single_trial_power(data, Fs, frequencies, use_fft=True, n_cycles=7, n_epochs, n_channels, n_times = data.shape # Precompute wavelets for given frequency range to save time - Ws = morlet(Fs, frequencies, n_cycles=n_cycles) + Ws = morlet(Fs, frequencies, n_cycles=n_cycles, zero_mean=zero_mean) parallel, my_cwt, _ = parallel_func(cwt, n_jobs) @@ -313,7 +325,7 @@ def single_trial_power(data, Fs, frequencies, use_fft=True, n_cycles=7, def induced_power(data, Fs, frequencies, use_fft=True, n_cycles=7, - decim=1, n_jobs=1): + decim=1, n_jobs=1, zero_mean=False): """Compute time induced power and inter-trial phase-locking factor The time frequency decomposition is done with Morlet wavelets @@ -336,6 +348,8 @@ def induced_power(data, Fs, frequencies, use_fft=True, n_cycles=7, n_jobs : int The number of CPUs used in parallel. All CPUs are used in -1. Requires joblib package. + zero_mean : bool + Make sure the wavelets are zero mean. Returns ------- @@ -349,7 +363,7 @@ def induced_power(data, Fs, frequencies, use_fft=True, n_cycles=7, n_epochs, n_channels, n_times = data[:, :, ::decim].shape # Precompute wavelets for given frequency range to save time - Ws = morlet(Fs, frequencies, n_cycles=n_cycles) + Ws = morlet(Fs, frequencies, n_cycles=n_cycles, zero_mean=zero_mean) if n_jobs == 1: psd = np.empty((n_channels, n_frequencies, n_times)) -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-mne.git _______________________________________________ debian-med-commit mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/debian-med-commit
