Closed pasadesh closed 1 year ago
Have you tried downloading the example and running it with the latest version?
I tried and wasn't able to reproduce the problem.
I downloaded your data and ran the code, it worked but again I ran only the following line of the codes with your data and got the same error...
local variable 'con_methods' referenced before assignment
What do you mean by running only that one line of code?
All code in the script should be run to assign values for the arguments to spectral_connectivity_epochs
.
I mean after running the entire code, (and watching the nice plot) I run only this line >
con_methods = ['pli', 'wpli2_debiased', 'ciplv']
con = spectral_connectivity_epochs(label_ts, method=con_methods, mode='multitaper', sfreq=sfreq, fmin=fmin, fmax=fmax,
faverage=True, mt_adaptive=True, n_jobs=1)
It should work, because no argument is changed... but I got the error (I checked with mine and with your data too)
What is the output for mne.sys_info?
function mne.utils.config.sys_info(fid=None, show_paths=False, *, dependencies='user')
What is the output of running it?
Platform: Windows-10-10.0.19044-SP0 Python: 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)] Executable: e:\ZNZ\eeg_resting-state.venv\python.exe CPU: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel: 8 cores Memory: 7.9 GB
Output exceeds the size limit. Open the full output data in a text editor Platform: Windows-10-10.0.19044-SP0 Python: 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)] Executable: e:\ZNZ\eeg_resting-state.venv\python.exe CPU: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel: 8 cores Memory: 7.9 GB
mne: 1.2.1 numpy: 1.21.6 {OpenBLAS 0.3.17 with 8 threads} scipy: 1.9.1 matplotlib: 3.6.2 {backend=module://matplotlib_inline.backend_inline}
sklearn: 1.1.2 numba: 0.55.0 nibabel: 4.0.2 nilearn: 0.9.2 dipy: 1.5.0 openmeeg: Not found cupy: Not found pandas: 1.4.4 pyvista: 0.36.1 {OpenGL 4.3.0 - Build 20.19.15.4835 via Intel(R) HD Graphics 4600} pyvistaqt: 0.9.0 ipyvtklink: 0.2.3 vtk: 9.2.2 qtpy: 2.2.0 {PyQt5=5.15.2} ipympl: Not found ... mne_features: Not found mne_qt_browser: 0.4.0 mne_connectivity: 0.5.0.dev0 mne_icalabel: Not found
Hi @pasadesh!
The problem is that label_ts
is a generator, which gets exhausted when spectral_connectivity_epochs
is called for the first time.
If you want to run spectral_connectivity_epochs
multiple times, you should replace this:
label_ts = mne.extract_label_time_course(
stcs, labels, src, mode='mean_flip', return_generator=True)
with this:
label_ts = mne.extract_label_time_course(
stcs, labels, src, mode='mean_flip', return_generator=False)
This is not a bug in the code but rather a Python feature.
Closing as this is not a bug. Feel free to re-open if you disagree @pasadesh
Describe the bug
local variable 'con_methods' referenced before assignment (line 1120 in the spectral_connectivity_epochs function).
Steps to reproduce
Here I run the following code:
as it is in the example (https://mne.tools/mne-connectivity/dev/auto_examples/mne_inverse_label_connectivity.html) and I get the following error...
local variable 'con_methods' referenced before assignment (line 1120 in the spectral_connectivity_epochs function)
.Expected results
Actual results
Additional information