<div dir="ltr">Hi Maria,<div><br></div><div>regarding the error, I couldn&#39;t replicate it myself and I don&#39;t see any problems with your code (except that <font face="monospace, monospace">indices</font> does not include 0 and 160). My hunch is however, that the problem is that the allocation fails to recognize the relevant channels. You could try dropping the irrelevant channels from the epochs before concatenating the data to see if it works (probably something like<font face="monospace, monospace"> epochs.pick_types(meg=True)</font>).</div><div><br></div><div>-Jaakko</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 16, 2017 at 7:19 AM, Maria Hakonen <span dir="ltr">&lt;<a href="mailto:maria.hakonen@gmail.com" target="_blank">maria.hakonen@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><p class="MsoNormal"><span lang="EN-US">Hi Eric,<span></span></span></p><p class="MsoNormal"><span lang="EN-US"><br></span></p>

<p class="MsoNormal"><span lang="EN-US">Many thanks
for your answer!<span></span></span></p><p class="MsoNormal"><span lang="EN-US"><br></span></p>

<p class="MsoNormal"><span lang="EN-US">I managed
to combine the data as follows:<span></span></span></p><p class="MsoNormal"><span lang="EN-US"><br></span></p>

<p class="MsoNormal"><span lang="EN-US">data=np.concatenate((epochs_1.<wbr>get_data(),epochs_2.get_data()<wbr>),axis=0)<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">data.shape<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">Out[28]:
(320, 308, 3721)<span></span></span></p><p class="MsoNormal"><span lang="EN-US"><br></span></p>

<p class="MsoNormal"><span lang="EN-US">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:<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">indices=(np.arange(1,160),np.<wbr>arange(161,320))
(i.e. 160 epochs in each file).<span></span></span></p><p class="MsoNormal"><span lang="EN-US"><br></span></p>

<p class="MsoNormal"><span lang="EN-US">However,
this doesn’t seem to work:<span></span></span></p><p class="MsoNormal"><span lang="EN-US"><br></span></p>

<p class="MsoNormal"><span lang="EN-US">“Connectivity
computation...<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">    computing connectivity for 159 connections<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">    using t=0.000s..3.100s for estimation (3721
points)<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">    computing connectivity for the bands:<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">     band 1: 8.1Hz..12.9Hz (16 points)<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">     band 2: 13.2Hz..30.0Hz (53 points)<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">    connectivity scores will be averaged for
each band<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">    using FFT with a Hanning window to estimate
spectra<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">    the following metrics will be computed:
Coherence<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">    computing connectivity for epoch 1<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">------------------------------<wbr>------------------------------<wbr>---------------<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">ValueError                    <wbr>            Traceback (most
recent call last)<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">&lt;ipython-input-13-<wbr>fa5b026adea8&gt;
in &lt;module&gt;()<span></span></span></p><span class="">

<p class="MsoNormal"><span lang="EN-US">      1 coh, freqs, times, n_epochs, n_tapers =
spectral_connectivity(<span></span></span></p>

</span><p class="MsoNormal"><span lang="EN-US">      2    
data, indices = indices, method=&#39;coh&#39;, mode=&#39;fourier&#39;,<span></span></span></p><span class="">

<p class="MsoNormal"><span lang="EN-US">----&gt;
3     sfreq=sfreq, fmin=fmin, fmax=fmax,
faverage=True, n_jobs=1)<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US"> </span></p>

<p class="MsoNormal"><span lang="EN-US">/share/apps/mne/mne-python/<wbr>python2.7/lib/python2.7/site-<wbr>packages/mne-0.11.dev0-py2.7.<wbr>egg/mne/connectivity/spectral.<wbr>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)<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US"> </span></p>

<p class="MsoNormal"><span lang="EN-US">/share/apps/mne/mne-python/<wbr>python2.7/lib/python2.7/site-<wbr>packages/mne-0.11.dev0-py2.7.<wbr>egg/mne/utils.pyc
in verbose(function, *args, **kwargs)<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">    549        
finally:<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">    550             set_log_level(old_level)<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">--&gt;
551     return function(*args, **kwargs)<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">    552<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">    553<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US"> </span></p>

<p class="MsoNormal"><span lang="EN-US">/share/apps/mne/mne-python/<wbr>python2.7/lib/python2.7/site-<wbr>packages/mne-0.11.dev0-py2.7.<wbr>egg/mne/connectivity/spectral.<wbr>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)<span></span></span></p>

</span><p class="MsoNormal"><span lang="EN-US">    977                     freq_mask, mt_adaptive,
idx_map, block_size, psd,<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">    978                     accumulate_psd,
con_method_types, con_methods,<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">--&gt;
979                     n_signals,
n_times, accumulate_inplace=True)<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">    980                 epoch_idx += 1<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">    981        
else:<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US"> </span></p>

<p class="MsoNormal"><span lang="EN-US">/share/apps/mne/mne-python/<wbr>python2.7/lib/python2.7/site-<wbr>packages/mne-0.11.dev0-py2.7.<wbr>egg/mne/connectivity/spectral.<wbr>pyc
in _epoch_spectral_connectivity(<wbr>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)<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">    408    
if accumulate_psd:<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">    409        
if accumulate_inplace:<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">--&gt;
410             psd += this_psd<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">    411        
else:<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">    412         
   psd = this_psd<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US"> </span></p>

<p class="MsoNormal"><span lang="EN-US">ValueError:
operands could not be broadcast together with shapes (318,69) (306,69) (318,69)”<span></span></span></p><p class="MsoNormal"><span lang="EN-US"><br></span></p>

<p class="MsoNormal"><span lang="EN-US">Also, the
documentation of mne.connectivity.spectral_<wbr>connectivity says:<span></span></span></p><p class="MsoNormal"><span lang="EN-US"><br></span></p>

<p class="MsoNormal"><span lang="EN-US">“<b>data</b> :
array-like, shape=(n_epochs, n_signals, n_times) | Epochs<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">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.”<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US"><br></span></p><p class="MsoNormal"><span lang="EN-US">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. <span></span></span></p><p class="MsoNormal"><span lang="EN-US"><br></span></p>

<p class="MsoNormal"><span lang="EN-US">Many thanks
already in advance if you could help!<span></span></span></p><p class="MsoNormal"><span lang="EN-US"><br></span></p>

<p class="MsoNormal"><span lang="EN-US">Best,<span></span></span></p>

<p class="MsoNormal"><span lang="EN-US">Maria<span></span></span></p></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">2017-06-15 20:37 GMT+03:00 Eric Larson <span dir="ltr">&lt;<a href="mailto:larson.eric.d@gmail.com" target="_blank">larson.eric.d@gmail.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">After this line:<div></div><div class="m_-8378352228173582017m_-577459959364891733markdown-here-wrapper"><pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important">stcs=np.concatenate((stc_1.dat<wbr>a,stc_2.data),axis=0)
</code></pre><div title="MDH:PGRpdj5gYGA8L2Rpdj48ZGl2PjxzcGFuIHN0eWxlPSJmb250LXNpemU6IDEyLjhweDsiPnN0Y3M9
bnAuY29uY2F0ZW5hdGUoKHN0Y18xLjwvc3Bhbj48d2JyIHN0eWxlPSJmb250LXNpemU6IDEyLjhw
eDsiPjxzcGFuIHN0eWxlPSJmb250LXNpemU6IDEyLjhweDsiPmRhdGEsc3RjXzIuZGF0YSksYXhp
cz0wKTwvc3Bhbj48YnI+PC9kaXY+PGRpdj48c3BhbiBzdHlsZT0iZm9udC1zaXplOiAxMi44cHg7
Ij5gYGA8L3NwYW4+PC9kaXY+PGRpdj48L2Rpdj4=" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0">​</div></div><div><span style="font-size:12.8px">You will have stcs.shape == (</span><span style="font-size:12.8px">40968, n_times).</span><br></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">However, for `spectral_connectivity`, the `data` argument needs to be of shape </span><span style="white-space:pre-wrap">(n_epochs, n_signals, n_times), i.e. you need multiple epochs/trials. Here you appear to only have 1.</span></div><div><br></div><div><span style="white-space:pre-wrap">HTH,</span></div><div><span style="white-space:pre-wrap">Eric</span></div><div><span style="white-space:pre-wrap"><br></span></div>
</div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_-8378352228173582017h5">On Thu, Jun 15, 2017 at 11:53 AM, Maria Hakonen <span dir="ltr">&lt;<a href="mailto:maria.hakonen@gmail.com" target="_blank">maria.hakonen@gmail.com</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_-8378352228173582017h5"><div dir="ltr"><div>Dear mne experts,</div><div><br></div><div>In an example “Compute coherence in source space using a MNE inverse solution” mne.connectivity.spectral_conn<wbr>ectivity 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_conn<wbr>ectivity to compute the coherence between two stc files measured in two different conditions. </div><div><br></div><div>I have tried to do this as follows:</div><div>stcs=np.concatenate((stc_1.dat<wbr>a,stc_2.data),axis=0)</div><div>stcs=stcs.tolist()</div><div>indices=(np.arange(1,20484),np<wbr>.arange(20485,40968)) (I would like to get the coherence between each vertex in stc1 and the corresponding vertices in stc2)</div><div>coh, freqs, times, n_epochs, n_tapers = spectral_connectivity(</div><div>    stcs, method=&#39;coh&#39;, mode=&#39;fourier&#39;, indices=indices,</div><div>    sfreq=sfreq, fmin=fmin, fmax=fmax, faverage=True, n_jobs=1)</div><div><br></div><div>However, I get:</div><div><br></div><div>Connectivity computation...</div><div>------------------------------<wbr>------------------------------<wbr>---------------</div><div>AttributeError                            Traceback (most recent call last)</div><div>&lt;ipython-input-40-139613d5f602<wbr>&gt; in &lt;module&gt;()</div><div>      1 coh, freqs, times, n_epochs, n_tapers = spectral_connectivity(</div><div>      2     stcs, method=&#39;coh&#39;, mode=&#39;fourier&#39;, indices=indices,</div><div>----&gt; 3     sfreq=sfreq, fmin=fmin, fmax=fmax, faverage=True, n_jobs=1)</div><div><br></div><div>/share/apps/mne/mne-python/pyt<wbr>hon2.7/lib/python2.7/site-pack<wbr>ages/mne-0.11.dev0-py2.7.egg/m<wbr>ne/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)</div><div><br></div><div>/share/apps/mne/mne-python/pyt<wbr>hon2.7/lib/python2.7/site-pack<wbr>ages/mne-0.11.dev0-py2.7.egg/m<wbr>ne/utils.pyc in verbose(function, *args, **kwargs)</div><div>    549         finally:</div><div>    550             set_log_level(old_level)</div><div>--&gt; 551     return function(*args, **kwargs)</div><div>    552</div><div>    553</div><div><br></div><div>/share/apps/mne/mne-python/pyt<wbr>hon2.7/lib/python2.7/site-pack<wbr>ages/mne-0.11.dev0-py2.7.egg/m<wbr>ne/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)</div><div>    772             # get the data size and time scale</div><div>    773             n_signals, n_times_in, times_in = \</div><div>--&gt; 774                 _get_and_verify_data_sizes(fir<wbr>st_epoch)</div><div>    775</div><div>    776             if times_in is None:</div><div><br></div><div>/share/apps/mne/mne-python/pyt<wbr>hon2.7/lib/python2.7/site-pack<wbr>ages/mne-0.11.dev0-py2.7.egg/m<wbr>ne/connectivity/spectral.pyc in _get_and_verify_data_sizes(dat<wbr>a, n_signals, n_times, times)</div><div>    479     n_signals_tot = 0</div><div>    480     for this_data in data:</div><div>--&gt; 481         this_n_signals, this_n_times = this_data.shape</div><div>    482         if n_times is not None:</div><div>    483             if this_n_times != n_times:</div><div><br></div><div>AttributeError: &#39;float&#39; object has no attribute &#39;shape&#39;</div><div><br></div><div>Could someone please let me know what I am doing wrong?</div><div><br></div><div>Best,</div><div>Maria</div><div><br></div></div>
<br></div></div>______________________________<wbr>_________________<br>
Mne_analysis mailing list<br>
<a href="mailto:Mne_analysis@nmr.mgh.harvard.edu" target="_blank">Mne_analysis@nmr.mgh.harvard.e<wbr>du</a><br>
<a href="https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis" rel="noreferrer" target="_blank">https://mail.nmr.mgh.harvard.e<wbr>du/mailman/listinfo/mne_analys<wbr>is</a><br>
<br>
<br>
The information in this e-mail is intended only for the person to whom it is<br>
addressed. If you believe this e-mail was sent to you in error and the e-mail<br>
contains patient information, please contact the Partners Compliance HelpLine at<br>
<a href="http://www.partners.org/complianceline" rel="noreferrer" target="_blank">http://www.partners.org/compli<wbr>anceline</a> . If the e-mail was sent to you in error<br>
but does not contain patient information, please contact the sender and properly<br>
dispose of the e-mail.<br>
<br></blockquote></div><br></div>
<br>______________________________<wbr>_________________<br>
Mne_analysis mailing list<br>
<a href="mailto:Mne_analysis@nmr.mgh.harvard.edu" target="_blank">Mne_analysis@nmr.mgh.harvard.e<wbr>du</a><br>
<a href="https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis" rel="noreferrer" target="_blank">https://mail.nmr.mgh.harvard.e<wbr>du/mailman/listinfo/mne_analys<wbr>is</a><br>
<br>
<br>
The information in this e-mail is intended only for the person to whom it is<br>
addressed. If you believe this e-mail was sent to you in error and the e-mail<br>
contains patient information, please contact the Partners Compliance HelpLine at<br>
<a href="http://www.partners.org/complianceline" rel="noreferrer" target="_blank">http://www.partners.org/compli<wbr>anceline</a> . If the e-mail was sent to you in error<br>
but does not contain patient information, please contact the sender and properly<br>
dispose of the e-mail.<br>
<br></blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<br>
Mne_analysis mailing list<br>
<a href="mailto:Mne_analysis@nmr.mgh.harvard.edu">Mne_analysis@nmr.mgh.harvard.<wbr>edu</a><br>
<a href="https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis" rel="noreferrer" target="_blank">https://mail.nmr.mgh.harvard.<wbr>edu/mailman/listinfo/mne_<wbr>analysis</a><br>
<br>
<br>
The information in this e-mail is intended only for the person to whom it is<br>
addressed. If you believe this e-mail was sent to you in error and the e-mail<br>
contains patient information, please contact the Partners Compliance HelpLine at<br>
<a href="http://www.partners.org/complianceline" rel="noreferrer" target="_blank">http://www.partners.org/<wbr>complianceline</a> . If the e-mail was sent to you in error<br>
but does not contain patient information, please contact the sender and properly<br>
dispose of the e-mail.<br>
<br></blockquote></div><br></div>