ClearAnatomics / ClearMap

ClearMap 2 with WobblyStitcher, TubeMap and CellMap
https://clearanatomics.github.io/ClearMapDocumentation/
GNU General Public License v3.0
105 stars 44 forks source link

Dataviewer does not work #17

Open stasys-hub opened 4 years ago

stasys-hub commented 4 years ago

Hello Christoph,

I am really interested in the project and really appreciate the efforts you took to create such a big software suite. I am currently trying to get the cellmap juypter notebook running. I used some dummy data for test purposes. Everything seems to work really fine. There were some minor bugs in naming conventions which already have been posted in the issues.

Unfortunately the Dataviewer does not seem to work for me. Disregarding the files and arguments i pass to the p3d module, I always just get an black, frozen window. Afterwards the jupyter session crashes and I have to rerstart the kernel. If I script the process in a normal python file I have the same problems. Are there any known issues regarding the dataviewer? And do you have some suggestions on how to tackle this problem?

I am currently working on Ubuntu 20.04 and I installed the stable release via the stable .yml (anaconda) file provided in the repo. I also tried it with the newest packages, but that does not change anything for me.

System: AMD Ryzen 3950X Nvidia RTX Super 2060 64 GB RAM DDR4 RAM

SaibotMagd commented 4 years ago

Thank you for this issue. I run into the same problem. CentOS 8 using the regular yml (anaconda) environment.

Intel® Xeon(R) CPU E5-1620 Quadro K620 64 GB RAM

I'm looking for this problem since last week. What I find out till now:

Update 7.7.:

SaibotMagd commented 4 years ago

I am currently working on Ubuntu 20.04 and I installed the stable release via the stable .yml (anaconda) file provided in the repo. I also tried it with the newest packages, but that does not change anything for me.

System: AMD Ryzen 3950X Nvidia RTX Super 2060 64 GB RAM DDR4 RAM

Do you use the proprietary Nvidia driver?

stasys-hub commented 4 years ago

Hello SaibotMagd, thank you for the detailed information on trying to pin down the problem! I also had no problems with openGL. Maybe it‘s PyQT, but i have Vispy under suspicion atm. I will try to check it out on the next few days and report back if I find a solution.

I am currently using the proprietary nvidia drivers. Did you find a solution while switching drivers? Nvidia Drivers seem fairly unstable on 20.04 as it seems currently.

Edit: I am currently running: Driver version 440.100 CUDA Version: 10.2

SaibotMagd commented 4 years ago

Maybe it‘s PyQT, but i have Vispy under suspicion atm. I will try to check it out on the next few days and report back if I find a solution.

Very interesting because I can't find the Vispy connection in the code at all. I think Vispy is used in the plot3d function. But I run the dataviewer class directly using the test function in the dataviewer.py file. But I will also look for that approach ;).

I am currently using the proprietary nvidia drivers. Did you find a solution while switching drivers?

I read something about proprietary nvidia drivers on centOS and because I don't have root on the pc I decide the risk will be much to high. It would be pretty nice if someone of the others, actually working with this package could post their configurations.

I will try to check it out on the next few days and report back if I find a solution.

For me it's my sole task right now for the next 3 weeks: "run this pipeline at all costs". So I will dismantle the whole code till I find a solution.

stasys-hub commented 4 years ago

Maybe it‘s PyQT, but i have Vispy under suspicion atm. I will try to check it out on the next few days and report back if I find a solution.

Very interesting because I can't find the Vispy connection in the code at all. I think Vispy is used in the plot3d function. But I run the dataviewer class directly using the test function in the dataviewer.py file. But I will also look for that approach ;).

I am currently using the proprietary nvidia drivers. Did you find a solution while switching drivers?

I read something about proprietary nvidia drivers on centOS and because I don't have root on the pc I decide the risk will be much to high. It would be pretty nice if someone of the others, actually working with this package could post their configurations.

I will try to check it out on the next few days and report back if I find a solution.

For me it's my sole task right now for the next 3 weeks: "run this pipeline at all costs". So I will dismantle the whole code till I find a solution.

Thank you very much for your efforts! I currently have a lot to do with other projects, so I just have a restricted amount of time for this. I will have a detailed look at the module on the weekend and I will immediately post it, if I find a solution.

The system specs and driver versions of a unit running the pipeline would probably help a lot.

I think the most elegant solution would be to have a docker image or some kind of other container, which would solve a lot of issues and keep also the maintenance low for the developers.

Standardizing the installation with Anaconda was a big step to reduce error potential. I really hope for a docker implementation next :).

SaibotMagd commented 4 years ago

Just awesome, a guy named: d_stranz solved the issue so easy I'm shocked. https://www.qtcentre.org/threads/71109-QApplication-Process-seems-to-hang I have no idea how to integrate the solution to the regular code but it seems pretty easy. I will do it tomorrow and post the new sourcecode.

stasys-hub commented 4 years ago

Just awesome, a guy named: d_stranz solved the issue so easy I'm shocked. https://www.qtcentre.org/threads/71109-QApplication-Process-seems-to-hang I have no idea how to integrate the solution to the regular code but it seems pretty easy. I will do it tomorrow and post the new sourcecode.

Thank you very much! You saved me a lot of work! I will look into it in the evening if I have time and implement it. I will post the solution, if I get it running!

SaibotMagd commented 4 years ago

Thank you very much! You saved me a lot of work! I will look into it in the evening if I have time and implement it. I will post the solution, if I get it running!

In the easiest possible approach I just inserted 2 lines of code into the dataviewer class from DataViewer.py:

class DataViewer(pg.QtGui.QWidget):
  def __init__(self, source, axis = None, scale = None, title = None, invertY = False, minMax = None, screen = None, parent = None, *args):
    ### Images soures
    self.initializeSources(source, axis = axis, scale = scale)
    #print('init')

    ### Gui Construction
    pg.QtGui.QWidget.__init__(self, parent, *args);
    ### this is line 1
    app = QApplication(sys.argv)
    #print('gui')    

    ...                     

    self.show();
    ### this is line 2
    sys.exit(app.exec_())

With these changes the viewer starts and works well showing a legit picture from the dataset. But it can't plot multiple pictures nether at the same time (to build the 3. Dimension; (p3d.plot(ws.filename('raw')) with ws consisting of multiple pictures, it mesh them up)) nor overlap them (show something but mess up the alignment).

I think it's because this approach allow only to build a single QApplication and it overwrite it every time you bring up a new picture or slice. So this is not a really working solution.

But there seems to be another issue. When you call "p3d.plot(ws.file_list('raw')[0:2])", it throw a "too many indices for array" error. Interesting enough if you compare the dataset from cellmap tutorial and tubemap tutorial the size of the "ws.source" shows 5 Dimensions in Tubemap and only 3 in Cellmap, for the same basic files. So I assume there's something wrong here.

ChristophKirst commented 4 years ago

Hi sorry for the late reply.

I had a similar problem at some point and it was related to the open gl drivers.

In the DataViewer.py there is a line

pg.CONFIG_OPTIONS['useOpenGL'] = False  # set to False if trouble seeing data.

You might try:

pg.CONFIG_OPTIONS['useOpenGL'] = True  # set to False if trouble seeing data.

also what does

import pyqtgraph as pg
app =  pg.mkQApp()

do on your configuration ? What QT version are you using:

import pyqtgraph as pg
pg.QtCore.PYQT_VERSION_STR

If you still have problems, how are you running ClearMap ? Through a console ? Have you tried to install spyder via andaconda and run it through spyder ? It's a QT app and works like a charm on my system.

SaibotMagd commented 4 years ago

I had a similar problem at some point and it was related to the open gl drivers. Yes I thought about it. I tried it on 2 other PCs (Nvidia 1050 Nouveau Driver; Ubuntu 18.04) and a Cluster workstation (Nvidia 2080 proprietary incl. cuda; Ubuntu 18.04) and all 3 systems (this one works with centosOS but I also tried Ubuntu 18.04 in multiBoot) show the exact same behavior.

02:00.0 VGA compatible controller: NVIDIA Corporation GM107GL [Quadro K620] (rev a2)
(base) [user@l00295 ~]$ glxinfo | grep OpenGL
OpenGL vendor string: nouveau
OpenGL renderer string: NV117
OpenGL core profile version string: 4.3 (Core Profile) Mesa 19.3.4
OpenGL core profile shading language version string: 4.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.3 (Compatibility Profile) Mesa 19.3.4
OpenGL shading language version string: 4.30
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 19.3.4
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20

In the DataViewer.py there is a line

pg.CONFIG_OPTIONS['useOpenGL'] = True  # set to False if trouble seeing data.

This was one of the first things I tried. Same result.

import pyqtgraph as pg

app =  pg.mkQApp()

Where should I include this? I tried it right after the import and also inside the DataViewer init def insteed of my command:

Because it seems really similar to the command I included for my "workaround":

app = QApplication(sys.argv)

But this command works (but creates some new issues regarding multi-file calls) yours do not.

do on your configuration ? What QT version are you using:

import pyqtgraph as pg
pg.QtCore.PYQT_VERSION_STR

5.12.3 in the updated ClearMap Environment; 5.9.2 in the ClearMap Stable Environment (I always try both)

If you still have problems, how are you running ClearMap ? Through a console ?

Nothing changed so even using my workaround I can't read multiple ws.files.

p3d.plot(ws.filename('raw'))

Works using my workaround but if it comes to a larger amount of tif-files the result is a mess. If I convert it to npy-files it works for a whole dataset just fine (beside the alignment in z-axis).

p3d.plot(ws.file_list('raw')[0:2])

Works using my workaround but the lower bars in the viewer are broken, and only for npy-files. And there's this error:

~/anaconda3/envs/ClearMap/lib/python3.7/site-packages/numpy/core/memmap.py in __getitem__(self, index)
    329 
    330     def __getitem__(self, index):
--> 331         res = super(memmap, self).__getitem__(index)
    332         if type(res) is memmap and res._mmap is None:
    333             return res.view(type=ndarray)

IndexError: too many indices for array

p3d.plot([ws.file_list('raw')[0:2]])

Works using my workaround but all viewer bars are not working and it shows only one slice and also only for npy-files. Same error message.

Have you tried to install spyder via andaconda and run it through spyder ? It's a QT app and works like a charm on my system.

I stick with your guide, so I used anaconda tried both enviornment-creating files and spyder.

SaibotMagd commented 4 years ago

Update 7/20/20: - I just found out this is not the only reason the viewer halts; it also halts when I call the for the results of the cell detection process: coordinates = np.array([ws.source('cells', postfix='filtered')[c] for c in 'xyz']).T; p = p3d.list_plot_3d(coordinates, color=(1,0,0,0.5), size=10) p3d.plot_3d(ws.filename('stitched'), view=p, cmap=p3d.grays_alpha(alpha=1)) I this "newly" problem have something to do with how the garbage collector of python works because after each RAM-consuming step the RAM isn't release so this time it could lead to a OOM. I will try that out.

Important to know: you shouldn't run the jupyter notebook files because there're just for viewing purposes right now. If you want to test the pipeline you need to run the .py files, without an activated jupyter server.

stasys-hub commented 4 years ago

Thanks for all this work Saibot! Unfortunately nothing helps in my case and i always get a black, frozen window. Even with spyder and without a jupyter server running. I am going to do a clean install on my machine or run the scripts on a virtual ubunutu 18.04 LTS. Maybe it's a problem that's OS dependent.

stasys-hub commented 4 years ago

A small update: I reinstalled Ubuntu and set it up with 18.04. Complete clean install. Only the dependecies needed for ClearMap. I used the Anaconda .yml file to create the environment. I still get the same error regarding p3d. So it is definitely not OS dependent.

SaibotMagd commented 4 years ago

For me I can run the whole pipeline right now but the Dataviewer works only for the smaller 2D-Datasets and only sometimes when I try to overlay 2 of the small ones (i.e. resample and resample_fluorescence).

There seems to be a huge RAM dependancy. If I start a fresh session the viewer runs fine most of the time (not for large and 3D files), but if I do any calculation steps the RAM will be filled and the viewer won't work properly. The gc.collect() don't do anything for me.

Did you try wayland vs xserver?

stasys-hub commented 4 years ago

For me I can run the whole pipeline right now but the Dataviewer works only for the smaller 2D-Datasets and only sometimes when I try to overlay 2 of the small ones (i.e. resample and resample_fluorescence).

There seems to be a huge RAM dependancy. If I start a fresh session the viewer runs fine most of the time (not for large and 3D files), but if I do any calculation steps the RAM will be filled and the viewer won't work properly. The gc.collect() don't do anything for me.

Did you try wayland vs xserver?

I am using Xserver. Would you mind sending me a copy of your working cellmap script? This would save me a lot of time, since I am getting different errors while aligning and cell detection.

novafae commented 4 years ago

Thank you very much! You saved me a lot of work! I will look into it in the evening if I have time and implement it. I will post the solution, if I get it running!

In the easiest possible approach I just inserted 2 lines of code into the dataviewer class from DataViewer.py:

class DataViewer(pg.QtGui.QWidget):
  def __init__(self, source, axis = None, scale = None, title = None, invertY = False, minMax = None, screen = None, parent = None, *args):
    ### Images soures
    self.initializeSources(source, axis = axis, scale = scale)
    #print('init')

    ### Gui Construction
    pg.QtGui.QWidget.__init__(self, parent, *args);
    ### this is line 1
    app = QApplication(sys.argv)
    #print('gui')    

    ...                     

    self.show();
    ### this is line 2
    sys.exit(app.exec_())

With these changes the viewer starts and works well showing a legit picture from the dataset. But it can't plot multiple pictures nether at the same time (to build the 3. Dimension; (p3d.plot(ws.filename('raw')) with ws consisting of multiple pictures, it mesh them up)) nor overlap them (show something but mess up the alignment).

I think it's because this approach allow only to build a single QApplication and it overwrite it every time you bring up a new picture or slice. So this is not a really working solution.

But there seems to be another issue. When you call "p3d.plot(ws.file_list('raw')[0:2])", it throw a "too many indices for array" error. Interesting enough if you compare the dataset from cellmap tutorial and tubemap tutorial the size of the "ws.source" shows 5 Dimensions in Tubemap and only 3 in Cellmap, for the same basic files. So I assume there's something wrong here.

Hi all, I've been following along the past few days and thought I'd join the conversation. I'm also a beginner in python, so thank you for your help so far.

This solution got the viewer running for me from what was originally a frozen window, but I'm having the same errors when trying to call multiple files. I can however open 3D files. I also am not able to see the intensity scale and slider. I found that I can edit the quick intensity setting by modifying the percentiles in this line, but it's not an ideal solution. Is anyone else having this issue or know a better solution? Thank you!

def __init__(self, image = None, color = 'red', percentiles = [[-100,0,50,75],[50,75,100,150]], parent = None, *args):
    pg.QtGui.QWidget.__init__(self, parent, *args)
SaibotMagd commented 4 years ago

Would you mind sending me a copy of your working cellmap script? This would save me a lot of time, since I am getting different errors while aligning and cell detection.

I didn't change a lot so I don't think this is neccessary but either way ;), I uploaded my Pipeline file in my fork: https://github.com/SaibotMagd/ClearMap2/blob/master/ClearMap/Scripts/CellMap_1268.py It runs thought without showing plots because it lasts for about 5 hours. It uses the 2016 Renier Slice based Dataset (haloperidol 1268er subject) because in the 2020 there're some missing files. But I did everything beside the coordinate transformation also using the 2020 Dataset.

The result file is cells.csv and it should look like:

x:y:z:size:source:xt:yt:zt:order:name
7.820000000000000000e+02:2.056000000000000000e+03:0.000000000000000000e+00:2.800000000000000000e+01:3.381900000000000000e+04:1.372974492688829855e+02:3.358635949018918154e+02:1.959590985389641205e+01:0.000000000000000000e+00:b'universe'
8.120000000000000000e+02:1.813000000000000000e+03:0.000000000000000000e+00:9.526000000000000000e+03:3.447500000000000000e+04:1.447656348742762873e+02:3.013674139355843522e+02:1.919572591822259255e+01:0.000000000000000000e+00:b'universe'
8.130000000000000000e+02:2.081000000000000000e+03:0.000000000000000000e+00:2.200000000000000000e+01:3.449800000000000000e+04:1.417861209342069913e+02:3.396934134000885024e+02:2.012660904492759784e+01:0.000000000000000000e+00:b'universe'
8.190000000000000000e+02:1.817000000000000000e+03:0.000000000000000000e+00:3.300000000000000000e+01:3.468400000000000000e+04:1.457895658101749348e+02:3.019801885356299067e+02:1.920064371831397310e+01:0.000000000000000000e+00:b'universe'

1.9GB and about 14 Million lines

Further I did a handmade csv sum all the data from all subjects:

:name:1267:1268:1269:1272:1273:1274
0:universe:969058:821239:814269:1072571:852424:874343
1:Piriform area:484316:593266:665368:633699:495248:433677
2:Secondary motor area, layer 2/3:399197:447908:496393:575714:466184:415739
3:Main olfactory bul:339871:390114:404931:377057:383525:334695
4:Entorhinal area, lateral part:288314:293662:320164:338683:287258:258580
5:Primary motor area, Layer 2/3:280118:256854:268662:289744:261392:241144
6:Caudoputamen:243137:176463:261170:286786:238850:225913
7:Secondary motor area, layer 5:157973:172362:237872:282409:238405:185871
stasys-hub commented 4 years ago

Just wanted to ask whether this is the data set you have been using:. this is the only thing I could find which was uploaded by Renier in 2016. Unfortunately I don't have much expertise on neurology and my work is to only get the pipeline running. I think it would be a lot easier to see what is happening in the code, if there would be a test dataset that people would actually see what is happening. Edit: I finally downloaded the data-set and was able to unpack it. It seems to be the same one which you were using @SaibotMagd. As a sidenote for people who are confused with the naming convention. The data is zipped two times. First time normal zip compression. Second time with 7z. To unzip 7z on linux you have to install third party software e.g. p7zip.

ywang219 commented 4 years ago

Hey, I have the same issue with spyder not able to open any dataviewer, except the 2D plots. However, it works when I run the code in iPython in terminal. Does anyone know why this is the case?

SaibotMagd commented 4 years ago

Hey, I have the same issue with spyder not able to open any dataviewer, except the 2D plots. However, it works when I run the code in iPython in terminal. Does anyone know why this is the case?

So you used iPython to run the py-file without a jupyter notebook server? Never did that but it seems promising if I think about all of the memory swallowing issues I face in spyder.

ywang219 commented 4 years ago

Hey, I have the same issue with spyder not able to open any dataviewer, except the 2D plots. However, it works when I run the code in iPython in terminal. Does anyone know why this is the case?

So you used iPython to run the py-file without a jupyter notebook server? Never did that but it seems promising if I think about all of the memory swallowing issues I face in spyder.

I am new to all those technical coding environment. I did not use jupyter. At first I only used ipython in terminal, then switched to spyder.

SaibotMagd commented 4 years ago

I stopped working on the dataviewer at all and build my own overlay-plotter to use in Fiji. Important to know: you can transform any of the npy-files back to tif-files and read it using the visual stack function in Fiji.

davidchenlee commented 4 years ago

Hi all, I had a similar problem when running the 'TubeMap' tutorial in Jupyter notebook. The visualization cells weren't doing anything. If I first run '%gui qt', then it works like a charm, even for multiple files. I don't know if this is related to your problems. I'm new to Qt.

ChristophKirst commented 4 years ago

The last step telling the notebook to use Qt for visualization is crucial to make it work in notebooks !

%gui qt

The problem is either the way jupyter / ipython consoles redirect calls to ope new windows etc or conflicts between interacting QT versions.

Does this configuration solve the issues above ?

ChristophKirst commented 4 years ago

In case you use spyder, try to go to Preferences -> IPython console -> Graphics -> Backend either choose 'Automatic' or 'Qt5'

SaibotMagd commented 3 years ago

In case you use spyder, try to go to Preferences -> IPython console -> Graphics -> Backend either choose 'Automatic' or 'Qt5'

This is actually working. But I have to set Graphics to Qt5 and force vispy to use it (command: vispy.use('PyQt5') ) Tested on Ubuntu 20 and Debian 8.

patelhe56 commented 2 years ago

Hey, I am having the same problem I have tried to implement the fixes suggested in the thread and cannot get it to work. Sometimes data viewer opens up and freezes and crashes and sometimes it just crashes without opening. I was wondering where I could put the command to "force vispy to use it". Any help would be appreciated!

crousseau commented 2 years ago

In case you use spyder, try to go to Preferences -> IPython console -> Graphics -> Backend either choose 'Automatic' or 'Qt5'

patelhe56 commented 2 years ago

Thanks!

crousseau commented 2 years ago

What's the output of conda list -n ClearMap -f spyder I'm asking as there seems to be issues with spyder >4

P.S. RAM size might indeed be an issue depending on the size of the image you are trying to plot (you can check the size on disk of that image as an indication)

patelhe56 commented 2 years ago

I, unfortunately, do not and will not have access to the System to check until next week but the version of spyder being used is 3.

So what I am trying to open is the result after the Cell detection is completed, but I will check on that when I get back onto the system.

crousseau commented 1 year ago

Using the new environemnt files for the GUI should fix that. The best way is to use the installer script