NeuralEnsemble / ephyviewer

Simple viewers for ephys signals, events, video and more
https://ephyviewer.readthedocs.io
MIT License
55 stars 14 forks source link

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

Open pplenck opened 5 years ago

pplenck commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

it still does not work. even with your simple signal viewer example. I run with the same issue on my mac and my PC... To run python, I use anaconda with a specific environment for neo, elephant en ephyviewer The app executes, the window closes but the console is stuck on "saving data" could it be an anaconda/pyqt5 issue? backends did not change

On Thu, Aug 8, 2019 at 2:24 AM Jeffrey Gill notifications@github.com wrote:

I installed Spyder and tried running this example https://ephyviewer.readthedocs.io/en/latest/examples.html#simple-signal-viewer. 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?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NeuralEnsemble/ephyviewer/issues/72?email_source=notifications&email_token=ALWYDPCCQAKP2Z5QAY6TRXDQDNRTTA5CNFSM4II6KRUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD32CAWA#issuecomment-519315544, or mute the thread https://github.com/notifications/unsubscribe-auth/ALWYDPBU7RV5Z2LRQ2OTQW3QDNRTTANCNFSM4II6KRUA .

samuelgarcia commented 5 years ago

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 commented 3 years ago

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 commented 3 years ago

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