Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

viewer does not free console when closed (I use spyder) #72

Open
pplenck opened this issue Aug 2, 2019 · 7 comments
Open

viewer does not free console when closed (I use spyder) #72

pplenck opened this issue Aug 2, 2019 · 7 comments

Comments

@pplenck
Copy link

pplenck commented Aug 2, 2019

Hi Guys
thanks for this cool library,
I am trying to use it throroughly and make my own viewer with it but it does not want to close properly when I run it and close the main window. I use Spyder and the commandline seems to try to "save_all_setting" and gets stuck there.
here is my code:

import matplotlib.pyplot as plt
from scipy import signal
import numpy as np
import ephyviewer
from ephyviewer import mkQApp, MainViewer, TraceViewer, TimeFreqViewer
from ephyviewer import InMemoryAnalogSignalSource

FilePth=(r"D:\SALOME\gad_cre_vir_hr2P8_Bis20190204\2019-02-04_18-16-17\Klusta")
FileNm=r'2019-02-04_18-16-17.dat'

get to the folder

os.chdir(str(FilePth))

SF=30000

reader=RawBinarySignalRawIO (filename=FileNm, dtype=u'int16', sampling_rate=SF, nb_channel=32)
reader.parse_header()
print (reader)
T1=0;
Tend=200;

data=reader.get_analogsignal_chunk(i_start = T1, i_stop = Tend*SF)
T=np.linspace(T1, Tend, len(data))
app = ephyviewer.mkQApp()

create a window

win = ephyviewer.MainViewer(debug=True, show_auto_scale = True)

source = InMemoryAnalogSignalSource(data, SF, T1) # why use a source by the way?

view1 = TraceViewer(source=source, name='trace')

#Parameters can be set in script
view1.params['scale_mode'] = 'same_for_all'
view1.params['display_labels'] = True
#view1.params['color'] = '#FFFEED'

view1.auto_scale()

win.add_view(view1)
win.show()

launch the app

app.exec_()

@jpgill86
Copy link
Collaborator

jpgill86 commented Aug 2, 2019

Hi @pplenck, thanks for trying ephyviewer!

It sounds like you are having success with launching ephyviewer and loading your data into it, and the problem only arises when you close the window.

I don't use Spyder, and I haven't experienced this issue before with ephyviewer in the contexts I use it (standalone, neurotic, Jupyter notebooks). If I had more time, I'd try it in Spyder, but today I don't.

However, what you describe reminds me of something I reported for tridesclous in Jupyter notebooks (tridesclous/tridesclous#117). In that report I described how, after closing a tridesclous GUI window, control of the kernel was not returned to the notebook, and I was forced to restart the kernel.

That issue has not been completely solved, and since there are some similarities between tridesclous's and ephyviewer's use of Qt for GUI creation, I wonder if they might be linked.

In that other report, I suggested that a particular matplotlib backend might be the cause of the tridesclous hangup. ephyviewer doesn't have an analogous matplotlib backend setting, but maybe Spyder is automatically setting it to something that causes problems in that context?

It's a shot in the dark, but you could try running this at the very top of your script, before import matplotlib.pyplot as plt:

import matplotlib
matplotlib.use('Qt5agg')  # I'm assuming you are using Qt5

If that doesn't help, maybe a different backend would work.

Let me know if that makes any difference!

As for your other question:

source = InMemoryAnalogSignalSource(data, SF, T1) # why use a source by the way?

I presume you mean, "Why not use the RawIO reader directly as the TraceViewer's source?"

Firstly, you should check out AnalogSignalFromNeoRawIOSource and its cousins in neosource.py. I'm realizing now that they are not represented by the example for using Neo with ephyviewer, which showcases only some of ephyviewer's Neo integrations (non-raw objects, specifically). We'll have to remedy that (#73).

Secondly, to answer your question. ephyviewer doesn't strictly depend on Neo. I think @samuelgarcia designed it to be as lightweight as possible with few dependencies. The "InMemory" sources are intended for lightweight numpy arrays, to handle the simplest cases. If you are already using Neo, you probably want to try the sources provided in neosource.py.

@pplenck
Copy link
Author

pplenck commented Aug 5, 2019

Qt5agg does not solve the issue. (Although I have to say it solved another issue I had with spyking-circus)
I had installed pyQt5 (and also neo) on the current environment.
it is strange because your standalone ephyviewer is working properly.
is there a "quit command?"

If you have time, can you show us how we could plot on the same trace both the raw lfp and the spike waveform? Like it's done on tridesclous?
Bests

@jpgill86
Copy link
Collaborator

jpgill86 commented Aug 8, 2019

I installed Spyder and tried running this example. It ran correctly and exited correctly, both when I pasted the example code into the console and ran it from there, and when I pasted it into the script editor and ran the script within Spyder. So, I'm currently unable to reproduce the problem you described. 😕

There is no "quit command", but that question did make me think of something. Try adding this line of code immediately after you instantiate the MainWindow:

win.setAttribute(ephyviewer.QT.WA_DeleteOnClose, True)

I don't know if it will make a difference, but it's worth a shot. If this works for you, I can probably add it to ephyviewer so that this attribute is set automatically for all MainWindows. Please let me know if you have success with it.

As for your last question,

If you have time, can you show us how we could plot on the same trace both the raw lfp and the spike waveform? Like it's done on tridesclous?

If I understand you correctly, you'd like to see both a continuous signal (possibly seconds, minutes, or hours long) as well as the waveform of an isolated spike (milliseconds long). Presently, ephyviewer links all viewers to a common timeline, which means that if you loaded your LFP signal in one TraceViewer and your spike waveform in another, the waveform would go off-screen if you scrolled away from t=0. I'm sure that's not what you want!

This sounds like a useful feature for ephyviewer to have. Would you like to open a new issue with a feature request? This will make sure the idea isn't forgotten even after this issue is closed. I don't think I'll have time to work on a feature like that anytime soon, but maybe a volunteer (or you!) would be interested in building it.

If I misunderstood the plots your were describing, could you show me a screenshot from tridesclous of what you want?

@pplenck
Copy link
Author

pplenck commented Aug 8, 2019 via email

@samuelgarcia
Copy link
Collaborator

Hi @pplenck and @jpgill86

I must admit that I investigate very few this QT problem.

A main source is that matplotlib try to hack/catch the QApp (when have a QT backend).
And spyder do the same because spyder is QT based.
And pyqtgraph (in a sens) do also the same try to catch the QApp.

note that the feature "save_all_setting" is not very stable sometimes. (but usefull)

@munrokrulle
Copy link

I get a similar problem. I'm launching the stand-alone version of ephyviewer in an environment set up using Anaconda. I'm able to launch the viewer and look at data sets, but whenever I try to open a new file when a file is already open I get the following error:

Traceback (most recent call last):
File "/opt/anaconda3/envs/TSA-Anaconda/lib/python3.8/site-packages/ephyviewer/standalone.py", line 63, in open_dialog
self.load_dataset(**dia.final_params)
File "/opt/anaconda3/envs/TSA-Anaconda/lib/python3.8/site-packages/ephyviewer/standalone.py", line 87, in load_dataset
compose_mainviewer_from_sources(sources, mainviewer=self)
File "/opt/anaconda3/envs/TSA-Anaconda/lib/python3.8/site-packages/ephyviewer/mainviewer.py", line 221, in compose_mainviewer_from_sources
mainviewer.add_view(view)
File "/opt/anaconda3/envs/TSA-Anaconda/lib/python3.8/site-packages/ephyviewer/mainviewer.py", line 73, in add_view
assert name not in self.viewers, 'Viewer already in MainViewer'
AssertionError: Viewer already in MainViewer

Is there a fix for this?
Thanks!

@jpgill86
Copy link
Collaborator

Hi @munrokrulle! This is a bug, though I don't think it's related to this issue. I have opened a new issue here: #122

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants