gallantlab / pycortex

Pycortex is a python-based toolkit for surface visualization of fMRI data
https://gallantlab.github.io/pycortex
BSD 2-Clause "Simplified" License
581 stars 137 forks source link

cortex.webgl.make_static does not display vertex data only volume data #246

Open kwayeke opened 6 years ago

kwayeke commented 6 years ago

Hi, I am trying to create a static viewer using this example https://gallantlab.github.io/auto_examples/webgl/static.html#sphx-glr-auto-examples-webgl-static-py by using vertex data instead of volume data but it does not work. Any help will be highly appreciated.

Thanks

marklescroart commented 6 years ago

Hi, and thanks for your interest! The main branch we’ve been doing our development on is glrework-merged. (Sorry about the confusing state of the branches, we have a little pruning to do). glrework-merged is nearly ready to be merged into (or replace) the master branch, it is fully python 3 compliant, and many features work on that branch that don't work on the master branch. I would recommend you pull and use that branch.

kwayeke commented 6 years ago

@marklescroart I am using the glrework-merged branch but it still does not work. I am using pyrhon 2.7 though. Have you ever try creating a static viewer from a vertex data? The example I linked to above is a volume data which also works for me. When I convert it to vertex data it does not work. Both vertex data and volume data work when using the dynamic viewer. I only have this issue when creating a static viewer using the "cortex.webgl.make_static" function

marklescroart commented 6 years ago

It should work; works for me. When you say "it doesn't work", what error do you get? Have you pulled the latest version of glrework-merged?

marklescroart commented 6 years ago

(also, once you switched branches via git, did you remember to install the updated code? I apologize if this was obvious to you, but that one caught me all the time when I was first developing in python)

kwayeke commented 6 years ago

I did not use git. I just downloaded the zip file from github and installed it using "python setup.py install "

kwayeke commented 6 years ago

I do not get any error but I can't see the data in the browser

marklescroart commented 6 years ago

Can you post a screen shot of your browser window? And you are following the example above, creating random data (not an empty volume) right?

kwayeke commented 6 years ago

Here is how it looks like https://kwayeke.github.io/hello_world/

kwayeke commented 6 years ago

Here is the code that I used import cortex

import numpy as np np.random.seed(1234)

subject = 'S1' xfm = 'fullhead'

First create example voxel data for this subject and transform

voxel_data = np.random.randn(31, 100, 100) voxel_vol = cortex.Volume(voxel_data, subject, xfm)

Then we have to get a mapper from voxels to vertices for this transform

mapper = cortex.get_mapper(subject, xfm, 'line_nearest', recache=True)

Just pass the voxel data through the mapper to get vertex data

vertex_map = mapper(voxel_vol)

gather data Volume

volume = cortex.Volume.random(subject='S1', xfmname='fullhead') volumes = {} volumes['random_1'] = cortex.Volume.random(subject='S1', xfmname='fullhead') volumes['random_2'] = cortex.Volume.random(subject='S1', xfmname='fullhead') volumes['vertex_map'] =vertex_map volumes['voxel_vol'] =voxel_vol

print volumes

select path for static viewer on disk

viewer_path ='/home/nya/Desktop/osf/viewer' directory='/home/nya/Desktop/osf/viewer/data' if not os.path.exists(directory): os.makedirs(directory)

create viewer

cortex.webgl.make_static(outpath=viewer_path, data=volumes, recache=True) cortex.webgl.show(data=volumes)

kwayeke commented 6 years ago

I can not see "vertex_map" in the viewer

alexhuth commented 6 years ago

I can see a map, the viewer works for me: image

But it also throws an error in the console on this line: https://github.com/gallantlab/pycortex/blame/1f7670a011a35e63dc4b0f314f4490b5069132b6/cortex/webgl/resources/js/mriview.js#L658

@sslivkoff Could your recent changes have made vertex maps fail somehow here?

kwayeke commented 6 years ago

image random_1 is a volume data that's why it works. Vertex_map is a vertex data that's why it does not work

marklescroart commented 6 years ago

I get the same browser error that Alex sees in the viewer you shared for random_1 and random_2, but I don't replicate the error running your code - everything seems to work OK for me. btw, @alexhuth, there are multiple data sets in the uploaded viewer - the vertex_map data set is all black (which is the problem you are reporting, yes?)

... Yeah, that.

What operating system are you on? What type of computer?

kwayeke commented 6 years ago

Does cortex.webgl.make_static(outpath=viewer_path, data=volumes, recache=True) works for you too?

cortex.webgl.show(data=volumes) works for me but not cortex.webgl.make_static(outpath=viewer_path, data=volumes, recache=True) I am using linux mint @marklescroart

marklescroart commented 6 years ago

Yes, that all works for me. I'm not sure what to tell you, but I have to go for now. I would suggest making sure that you are on the latest version of glrework-merged by installing via git. (before you do this, uninstall the version you have - can be a bit sticky, I don't remember offhand how to do this, but google around and you should find what you need).

Once uninstalled (make sure you can't import cortex in a python session), call:

git clone http://github.com/gallantlab/pycortex cd pycortex git checkout glrework-merged python setup.py install cd ~ # or optionally add --user flag: # python setup.py install --user

... Then try again. Don't forget to change directories out of the pycortex directory before starting a python session.

btw, side note, a very simple way to convert a volume to a vertex is to use:

vertex_map = voxel_vol.map(projection='line_nearest')

alexhuth commented 6 years ago

Oops my bad. It does not function on my machine, either. I'm worried this might be vertex shader code that I broke in a recent commit..

kwayeke commented 6 years ago

I did what you suggested by reinstalling pycortex using git but it still does not work for vertex data @marklescroart. What version of html5lib are you using? Is there a simple way of converting a vertex data to a volume data

kwayeke commented 6 years ago

I tried using python 3.4 instead of 2.7 but I still get the same result

kwayeke commented 6 years ago

image

sslivkoff commented 6 years ago

I'm not sure. I tried to avoid interacting with the vertex stuff but may have missed something. I will look into this

sslivkoff commented 6 years ago

Ok I just pushed something that removes the console errors that occur when the mouseover event fires before the thing is loaded. I don't know if this was the error you were talking about @alexhuth, let me know if that one did not go away.

My static viewers suffer from this no display problem. The unique console error that I see during static viewers and not dynamic viewers is

(index):40987 Uncaught RangeError: Invalid typed array length: 304380
    at typedArrayConstructByArrayBuffer (<anonymous>)
    at new Float32Array (native)
    at NParray.update (http://0.0.0.0:8000/:40987:21)
    at Object.success (http://0.0.0.0:8000/:40978:23)
    at j (http://0.0.0.0:8000/:2650:26860)
    at Object.fireWith [as resolveWith] (http://0.0.0.0:8000/:2650:27673)
    at x (http://0.0.0.0:8000/:2652:11120)
    at XMLHttpRequest.<anonymous> (http://0.0.0.0:8000/:2652:14767)
sslivkoff commented 6 years ago

there seem to be different errors coming from different browsers. @kwayeke what browser and browser version are you using?

and is anyone running in to the Uncaught RangeError: Invalid typed array length: 304380 error when viewing the static vertex data?

kwayeke commented 6 years ago

@sslivkoff I am using Firefox on Linux mint. I created a static viewer available here https://kwayeke.github.io/hello_world/ which can be viewed in any browser. The only problem is that vertex_map displays nothing

sslivkoff commented 6 years ago

can you regenerate that viewer with the changes I pushed to glrework-merged?

kwayeke commented 6 years ago

@sslivkoff It´s still the same. Vertex data can´t be seen in static view. Only dynamic view. Does it works for you? what version of python and operating system are you using?

sslivkoff commented 6 years ago

I still don't see the vertex data. I'm running ubuntu 14.04 / latest pycortex.

It is strange that it works on @marklescroart's machine and not on mine. We both have latest chrome (v62) and similar hardware. The only difference seems to be graphics drivers. I have nvidia 361 where @marklescroart has nvidia 384. @kwayeke what drivers are you using? upgrading might fix the problem.

marklescroart commented 6 years ago

I am also running Ubuntu 16.04, which might be part of the issue. However, the fact that the vertex data IS displayed by the dynamic viewer suggests that it's not purely a graphics card problem. It might be the case that newer graphics card drivers can handle a tiny bug in the code where older drivers cannot.

Having discussed in lab, we suspect that there is a small difference in how the html template for the pycortex viewer web page is processed in the make_static() vs show() functions in cortex/webgl/view.py. There is some code duplication between those two functions, which makes it difficult to assess exactly what is different. What is probably necessary is a refactor of the code to pull out what is the same between the two functions into something like a handle_template() function, and then make any difference between the two functions more explicit. However, while this is a good idea in any case, it's somewhat complicated and not guaranteed to fix the problem, and we're all a little swamped over here trying to do our own work (all of us are just grad students / postdocs / professors trying do other things), so this will probably sit undone for a bit. If you'd like to take a stab at the code refactor I've described and put it in a github pull request, we would appreciate it. Otherwise, thanks for your patience, and I suggest you try to update your graphics card drivers and see if that helps.

marklescroart commented 6 years ago

PS this works for me on both python 2.7 and python 3.5 on Ubuntu, but breaks on my Mac laptop.

kwayeke commented 6 years ago

Thanks @marklescroart Here is my driver version @sslivkoff NVRM version: NVIDIA UNIX x86_64 Kernel Module 370.28 Thu Sep 1 19:45:04 PDT 2016 GCC version: gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
I will upgrade my driver.

kwayeke commented 6 years ago

I upgraded to NVIDIA driver version 375, 378 and 384 but none of them worked. It appears that I might have to also upgrade the operating system which I do not intend to do because this is a server shared by others in my research group. Upgrading might just break some of their already working programs.

kwayeke commented 6 years ago

@marklescroart What version of html5 are you using? I am using this version https://pypi.python.org/pypi/html5lib/0.90.