[Mne_analysis] How to get coherence between stc files?
Maria Hakonen
maria.hakonen at gmail.com
Fri Jun 16 01:19:12 EDT 2017
Hi Eric,
Many thanks for your answer!
I managed to combine the data as follows:
data=np.concatenate((epochs_1.get_data(),epochs_2.get_data()),axis=0)
data.shape
Out[28]: (320, 308, 3721)
I am not sure how the parameter “indices” should be set in my case. I would
like to calculate the coherence between each data point in the file 1 and
the corresponding data points in the file 2. Since I have 320 epochs after
concatenation, I tried:
indices=(np.arange(1,160),np.arange(161,320)) (i.e. 160 epochs in each
file).
However, this doesn’t seem to work:
“Connectivity computation...
computing connectivity for 159 connections
using t=0.000s..3.100s for estimation (3721 points)
computing connectivity for the bands:
band 1: 8.1Hz..12.9Hz (16 points)
band 2: 13.2Hz..30.0Hz (53 points)
connectivity scores will be averaged for each band
using FFT with a Hanning window to estimate spectra
the following metrics will be computed: Coherence
computing connectivity for epoch 1
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-13-fa5b026adea8> in <module>()
1 coh, freqs, times, n_epochs, n_tapers = spectral_connectivity(
2 data, indices = indices, method='coh', mode='fourier',
----> 3 sfreq=sfreq, fmin=fmin, fmax=fmax, faverage=True, n_jobs=1)
/share/apps/mne/mne-python/python2.7/lib/python2.7/site-packages/mne-0.11.dev0-py2.7.egg/mne/connectivity/spectral.pyc
in spectral_connectivity(data, method, indices, sfreq, mode, fmin, fmax,
fskip, faverage, tmin, tmax, mt_bandwidth, mt_adaptive, mt_low_bias,
cwt_frequencies, cwt_n_cycles, block_size, n_jobs, verbose)
/share/apps/mne/mne-python/python2.7/lib/python2.7/site-packages/mne-0.11.dev0-py2.7.egg/mne/utils.pyc
in verbose(function, *args, **kwargs)
549 finally:
550 set_log_level(old_level)
--> 551 return function(*args, **kwargs)
552
553
/share/apps/mne/mne-python/python2.7/lib/python2.7/site-packages/mne-0.11.dev0-py2.7.egg/mne/connectivity/spectral.pyc
in spectral_connectivity(data, method, indices, sfreq, mode, fmin, fmax,
fskip, faverage, tmin, tmax, mt_bandwidth, mt_adaptive, mt_low_bias,
cwt_frequencies, cwt_n_cycles, block_size, n_jobs, verbose)
977 freq_mask, mt_adaptive, idx_map, block_size,
psd,
978 accumulate_psd, con_method_types, con_methods,
--> 979 n_signals, n_times, accumulate_inplace=True)
980 epoch_idx += 1
981 else:
/share/apps/mne/mne-python/python2.7/lib/python2.7/site-packages/mne-0.11.dev0-py2.7.egg/mne/connectivity/spectral.pyc
in _epoch_spectral_connectivity(data, sig_idx, tmin_idx, tmax_idx, sfreq,
mode, window_fun, eigvals, wavelets, freq_mask, mt_adaptive, idx_map,
block_size, psd, accumulate_psd, con_method_types, con_methods, n_signals,
n_times, accumulate_inplace)
408 if accumulate_psd:
409 if accumulate_inplace:
--> 410 psd += this_psd
411 else:
412 psd = this_psd
ValueError: operands could not be broadcast together with shapes (318,69)
(306,69) (318,69)”
Also, the documentation of mne.connectivity.spectral_connectivity says:
“*data* : array-like, shape=(n_epochs, n_signals, n_times) | Epochs
The data from which to compute connectivity. Note that it is also possible
to combine multiple signals by providing a list of tuples, e.g., data =
[(arr_0, stc_0), (arr_1, stc_1), (arr_2, stc_2)], corresponds to 3 epochs,
and arr_* could be an array with the same number of time points as stc_*.
The array-like object can also be a list/generator of array, shape
=(n_signals, n_times), or a list/generator of SourceEstimate or
VolSourceEstimate objects.”
Does this mean that I should use tuples and stc files if I want to compute
the coherence between two data files measured in two different condition?
Unfortunately, I haven’t managed to figure out what arr_0, arr1 and arr2
would be in my case.
Many thanks already in advance if you could help!
Best,
Maria
2017-06-15 20:37 GMT+03:00 Eric Larson <larson.eric.d at gmail.com>:
> After this line:
>
> stcs=np.concatenate((stc_1.data,stc_2.data),axis=0)
>
>
> You will have stcs.shape == (40968, n_times).
>
> However, for `spectral_connectivity`, the `data` argument needs to be of
> shape (n_epochs, n_signals, n_times), i.e. you need multiple
> epochs/trials. Here you appear to only have 1.
>
> HTH,
> Eric
>
>
> On Thu, Jun 15, 2017 at 11:53 AM, Maria Hakonen <maria.hakonen at gmail.com>
> wrote:
>
>> Dear mne experts,
>>
>> In an example “Compute coherence in source space using a MNE inverse
>> solution” mne.connectivity.spectral_connectivity is used to compute the
>> coherence between a seed in the left auditory cortex and the rest of the
>> brain based on single-trial MNE-dSPM inverse solutions. However, I would
>> like to use mne.connectivity.spectral_connectivity to compute the
>> coherence between two stc files measured in two different conditions.
>>
>> I have tried to do this as follows:
>> stcs=np.concatenate((stc_1.data,stc_2.data),axis=0)
>> stcs=stcs.tolist()
>> indices=(np.arange(1,20484),np.arange(20485,40968)) (I would like to get
>> the coherence between each vertex in stc1 and the corresponding vertices in
>> stc2)
>> coh, freqs, times, n_epochs, n_tapers = spectral_connectivity(
>> stcs, method='coh', mode='fourier', indices=indices,
>> sfreq=sfreq, fmin=fmin, fmax=fmax, faverage=True, n_jobs=1)
>>
>> However, I get:
>>
>> Connectivity computation...
>> ------------------------------------------------------------
>> ---------------
>> AttributeError Traceback (most recent call
>> last)
>> <ipython-input-40-139613d5f602> in <module>()
>> 1 coh, freqs, times, n_epochs, n_tapers = spectral_connectivity(
>> 2 stcs, method='coh', mode='fourier', indices=indices,
>> ----> 3 sfreq=sfreq, fmin=fmin, fmax=fmax, faverage=True, n_jobs=1)
>>
>> /share/apps/mne/mne-python/python2.7/lib/python2.7/site-pack
>> ages/mne-0.11.dev0-py2.7.egg/mne/connectivity/spectral.pyc in
>> spectral_connectivity(data, method, indices, sfreq, mode, fmin, fmax,
>> fskip, faverage, tmin, tmax, mt_bandwidth, mt_adaptive, mt_low_bias,
>> cwt_frequencies, cwt_n_cycles, block_size, n_jobs, verbose)
>>
>> /share/apps/mne/mne-python/python2.7/lib/python2.7/site-pack
>> ages/mne-0.11.dev0-py2.7.egg/mne/utils.pyc in verbose(function, *args,
>> **kwargs)
>> 549 finally:
>> 550 set_log_level(old_level)
>> --> 551 return function(*args, **kwargs)
>> 552
>> 553
>>
>> /share/apps/mne/mne-python/python2.7/lib/python2.7/site-pack
>> ages/mne-0.11.dev0-py2.7.egg/mne/connectivity/spectral.pyc in
>> spectral_connectivity(data, method, indices, sfreq, mode, fmin, fmax,
>> fskip, faverage, tmin, tmax, mt_bandwidth, mt_adaptive, mt_low_bias,
>> cwt_frequencies, cwt_n_cycles, block_size, n_jobs, verbose)
>> 772 # get the data size and time scale
>> 773 n_signals, n_times_in, times_in = \
>> --> 774 _get_and_verify_data_sizes(first_epoch)
>> 775
>> 776 if times_in is None:
>>
>> /share/apps/mne/mne-python/python2.7/lib/python2.7/site-pack
>> ages/mne-0.11.dev0-py2.7.egg/mne/connectivity/spectral.pyc in
>> _get_and_verify_data_sizes(data, n_signals, n_times, times)
>> 479 n_signals_tot = 0
>> 480 for this_data in data:
>> --> 481 this_n_signals, this_n_times = this_data.shape
>> 482 if n_times is not None:
>> 483 if this_n_times != n_times:
>>
>> AttributeError: 'float' object has no attribute 'shape'
>>
>> Could someone please let me know what I am doing wrong?
>>
>> Best,
>> Maria
>>
>>
>> _______________________________________________
>> 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.
>>
>>
>
> _______________________________________________
> 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/20170616/ca6f43ae/attachment-0001.html
More information about the Mne_analysis
mailing list