EtienneCmb / visbrain

A multi-purpose GPU-accelerated open-source suite for brain data visualization
http://visbrain.org
Other
242 stars 65 forks source link

add_topoplot function error in PYTHONNET #25

Closed STREETKILLER007 closed 5 years ago

STREETKILLER007 commented 5 years ago

I trying to implement Visbrain in a c# program, using Visual Studio 2017 Community.

Embedding python in c# by using Pythonnet.

below is my pip list

(py36) C:\Users\JamesTan\Desktop>pip list
Package         Version
--------------- ----------
certifi         2018.8.13
click           6.7
cycler          0.10.0
kiwisolver      1.0.1
matplotlib      2.2.3
mkl-fft         1.0.4
mkl-random      1.0.1
numpy           1.15.0
pandas          0.23.4
Pillow          5.2.0
pip             18.0
PyOpenGL        3.1.0
pyparsing       2.2.0
PyQt5           5.11.2
PyQt5-sip       4.19.12
python-dateutil 2.7.3
pythonnet       2.4.0.dev0
pytz            2018.5
scipy           1.1.0
setuptools      40.0.0
six             1.11.0
visbrain        0.4.2
vispy           0.5.3
wheel           0.31.1
wincertstore    0.2

Follow is the code :

using (Py.GIL())
{
                // import visbrain
                dynamic myVisbrain = Py.Import("visbrain");
                Console.WriteLine("hi visbrain");

                // import topo from Visbrain
                dynamic myTopo = myVisbrain.Topo();
                Console.WriteLine("hi topo");

                // Create a list of channels, data, title and colorbar label :
                dynamic myName = "Test";
                dynamic myTitle = "Basic topoplot illustration";
                dynamic myCblabel = "Colorbar label";
                dynamic myChannels = new List<String> { "C3", "C4", "Cz", "Fz", "Pz" };
                dynamic myData = new List<Double> { 10, 20, 30, 10, 10 };

                 // ERROR OCCURS HERE
                // Add a central topoplot :
                myTopo.add_topoplot(myName, myChannels, Py.kw("channels", myData), Py.kw("title", myTitle), Py.kw("cblabel", myCblabel));

                // show
               // myTopo.show();
}

error message :

Python.Runtime.PythonException: 'UnboundLocalError : local variable 'keeponly' referenced before assignment'

stack trace :

Python.Runtime.PythonException
  HResult=0x80131500
  Message=UnboundLocalError : local variable 'keeponly' referenced before assignment
  Source=Python.Runtime
  StackTrace:
['  File "d:\\Anaconda3\\envs\\py36\\lib\\site-packages\\visbrain\\topo\\topo.py", line 153, in add_topoplot\n    margin)\n', '  File "d:\\Anaconda3\\envs\\py36\\lib\\site-packages\\visbrain\\visuals\\TopoVisual.py", line 197, in __init__\n    auto = self._get_channel_coordinates(xyz, channels, system, unit)\n', '  File "d:\\Anaconda3\\envs\\py36\\lib\\site-packages\\visbrain\\visuals\\TopoVisual.py", line 388, in _get_channel_coordinates\n    if any(keeponly):\n']

Any idea on this issue ? Thank You.

EtienneCmb commented 5 years ago

GitMate.io thinks possibly related issues are https://github.com/EtienneCmb/visbrain/issues/18 (Topo Error), https://github.com/EtienneCmb/visbrain/issues/22 (Visbrain in Pythonnet), https://github.com/EtienneCmb/visbrain/issues/12 (Brain import error), and https://github.com/EtienneCmb/visbrain/issues/13 (Import error: cannot import _cntr).

STREETKILLER007 commented 5 years ago

Ok, i realized that this error occur because i pass in variable by wrong sequence.

wrong sequence :

myTopo.add_topoplot(myName, myChannels, Py.kw("channels", myData), Py.kw("title", myTitle), Py.kw("cblabel", myCblabel));

correct sequence :

myTopo.add_topoplot(myName, myData, Py.kw("channels", myChannels), Py.kw("title", myTitle), Py.kw("cblabel", myCblabel));

Type in correct sequence works.