nipy / PySurfer

Cortical neuroimaging visualization in Python
https://pysurfer.github.io/
BSD 3-Clause "New" or "Revised" License
243 stars 97 forks source link

MRG: Fix label colors #229

Closed larsoner closed 6 years ago

larsoner commented 6 years ago

@nfoti can you see if this fixes your label problem?

On my system, all labels were blue. There is probably an upstream bug that needs to be fixed, but this is a workaround in the meantime.

nfoti commented 6 years ago

@larsoner Unfortunately now I can only draw a single label and the resulting color is wrong. When i specify the color of the label to 'steelblue' the label is drawn as a violet color. If I specify the color to be 'darkred' the label ends up being gray.

larsoner commented 6 years ago

Yes CircleCI agrees this is an incorrect fix :)

https://83-1551431-gh.circle-artifacts.com/0/tmp/circle-artifacts.1i0lof4/html/auto_examples/plot_parcellation.html#sphx-glr-auto-examples-plot-parcellation-py

Clearly some work still to do, but if you're on a time crunch, this gives you some indication of the lines of code you could try tweaking.

mwaskom commented 6 years ago

Is there an issue describing the problem to link?

larsoner commented 6 years ago

No, this can serve as the issue. All labels are blue, here is plot_label.py on my system with master:

screenshot from 2018-03-20 11-00-38

This happens independent of Mayavi version (at least back to the commit where PyQt5 support was added) and VTK version (at least 7.1 and 8), likely due to an update in NumPy breaking some Mayavi assumption or check. I haven't isolated the problem so haven't opened an upstream bug or tried to fix it. We might need both an upstream fix and a workaround here.

mwaskom commented 6 years ago

Huh, those labels look black and gold to me :)

nfoti commented 6 years ago

Thank @larsoner. I will take a look at the link you sent later today. I realized that I may have been getting weird results from changing which version of mayavi I was using.

Also, I am using the mne conda environment, but I had to make the default channel conda-forge rather that defaults because of a problem with the mkl numpy that the environment wants to load and another package wanting openblas. Thus, I'm getting numpy 1.14 instead of 1.13 which could also be causing the weirdness.

larsoner commented 6 years ago

@nfoti I recommend this one actually, it uses VTK from pip which is version 8 (works for HiDPI screens):

https://github.com/mne-tools/mne-python/pull/5012

mwaskom commented 6 years ago

FWIW i set up a new environment with mayavi over the weekend and am not seeing this problem. Here's what I am working with:

apptools                  4.4.0                    py36_0    conda-forge
attrs                     17.4.0                     py_0    conda-forge
backports                 1.0                      py36_1    conda-forge
backports.functools_lru_cache 1.5                      py36_0    conda-forge
blas                      1.1                    openblas    conda-forge
bleach                    2.1.3                      py_0    conda-forge
bzip2                     1.0.6                         1    conda-forge
ca-certificates           2018.1.18                     0    conda-forge
cairo                     1.14.6                        5    conda-forge
certifi                   2018.1.18                py36_0    conda-forge
click                     6.7                        py_1    conda-forge
configobj                 5.0.6                    py36_0  
curl                      7.59.0                        0    conda-forge
cycler                    0.10.0                   py36_0    conda-forge
dask-core                 0.17.1                     py_0    conda-forge
dbus                      1.10.22                       0    conda-forge
decorator                 4.2.1                    py36_0    conda-forge
entrypoints               0.2.3                    py36_1    conda-forge
envisage                  4.5.1                    py36_0    conda-forge
expat                     2.2.5                         0    conda-forge
fontconfig                2.12.1                        6    conda-forge
freetype                  2.7                           2    conda-forge
funcsigs                  1.0.2                      py_2    conda-forge
future                    0.16.0                   py36_0    conda-forge
gettext                   0.19.8.1                      0    conda-forge
glib                      2.51.4                        0    conda-forge
gmp                       6.1.2                         0    conda-forge
graphite2                 1.3.11                        0    conda-forge
gsl                       2.4             blas_openblas_0  [blas_openblas]  conda-forge
gst-plugins-base          1.8.0                         0    conda-forge
gstreamer                 1.8.0                         1    conda-forge
h5py                      2.7.1                    py36_1    conda-forge
harfbuzz                  1.4.3                         0    conda-forge
hdf5                      1.8.18                        3    conda-forge
html5lib                  1.0.1                      py_0    conda-forge
icu                       58.2                          0    conda-forge
imageio                   2.2.0                    py36_0    conda-forge
ipykernel                 4.8.2                    py36_0    conda-forge
ipython                   6.2.1                    py36_1    conda-forge
ipython_genutils          0.2.0                    py36_0    conda-forge
ipywidgets                7.1.2                    py36_0    conda-forge
isodate                   0.6.0                      py_0    conda-forge
jedi                      0.11.1                   py36_0    conda-forge
jinja2                    2.10                     py36_0    conda-forge
jpeg                      9b                            2    conda-forge
jsoncpp                   0.10.6                        1    conda-forge
jsonschema                2.6.0                    py36_1    conda-forge
jupyter                   1.0.0                    py36_0    conda-forge
jupyter_client            5.2.3                    py36_0    conda-forge
jupyter_console           5.2.0                    py36_0    conda-forge
jupyter_core              4.4.0                      py_0    conda-forge
keepalive                 0.5                      py36_0    conda-forge
kiwisolver                1.0.1                    py36_1    conda-forge
krb5                      1.14.2                        0    conda-forge
libffi                    3.2.1                         3    conda-forge
libgcc                    7.2.0                h69d50b8_2  
libgcc-ng                 7.2.0                hdf63c60_3  
libgfortran               3.0.0                         1  
libiconv                  1.15                          0    conda-forge
libpng                    1.6.28                        2    conda-forge
libsodium                 1.0.15                        1    conda-forge
libssh2                   1.8.0                         2    conda-forge
libstdcxx-ng              7.2.0                hdf63c60_3  
libtiff                   4.0.7                         1    conda-forge
libxcb                    1.13                          0    conda-forge
libxml2                   2.9.8                         0    conda-forge
libxslt                   1.1.32                        0    conda-forge
lxml                      4.2.0                    py36_0    conda-forge
lyman                     1.0                       
markupsafe                1.0                      py36_0    conda-forge
matplotlib                2.0.0               np112py36_2    conda-forge
mayavi                    4.5.0                    py36_3    conda-forge
mistune                   0.8.3                      py_0    conda-forge
mock                      2.0.0                    py36_0    conda-forge
moss                      0.5                       
nbconvert                 5.3.1                      py_1    conda-forge
nbformat                  4.4.0                    py36_0    conda-forge
ncurses                   5.9                          10    conda-forge
networkx                  2.1                      py36_0    conda-forge
nibabel                   2.2.1                    py36_0    conda-forge
nibabel                   2.2.1                     
nipype                    1.0.1                    py36_0    conda-forge
notebook                  5.4.1                    py36_0    conda-forge
numpy                     1.12.1          py36_blas_openblas_201  [blas_openblas]  conda-forge
olefile                   0.45.1                   py36_0    conda-forge
openblas                  0.2.20                        7    conda-forge
openssl                   1.0.2n                        0    conda-forge
packaging                 17.1                       py_0    conda-forge
pandas                    0.22.0                   py36_0    conda-forge
pandoc                    2.1.2                         0    conda-forge
pandocfilters             1.4.1                    py36_0    conda-forge
pango                     1.40.4                        0    conda-forge
parso                     0.1.1                      py_0    conda-forge
patsy                     0.5.0                    py36_0    conda-forge
pbr                       3.1.1                    py36_0    conda-forge
pcre                      8.39                          0    conda-forge
pexpect                   4.4.0                    py36_0    conda-forge
pickleshare               0.7.4                    py36_0    conda-forge
pillow                    4.3.0                    py36_1    conda-forge
pip                       9.0.2                    py36_0    conda-forge
pixman                    0.34.0                        1    conda-forge
pluggy                    0.6.0                      py_0    conda-forge
prompt_toolkit            1.0.15                   py36_0    conda-forge
prov                      1.5.0                    py36_0    conda-forge
psutil                    5.4.3                    py36_0    conda-forge
ptyprocess                0.5.2                    py36_0    conda-forge
py                        1.5.2                      py_0    conda-forge
pydicom                   1.0.2                      py_0    conda-forge
pydotplus                 2.0.2                    py36_0    conda-forge
pyface                    5.1.0                    py36_1    conda-forge
pygments                  2.2.0                    py36_0    conda-forge
pyparsing                 2.2.0                    py36_0    conda-forge
pyqt                      4.11.4                   py36_3    conda-forge
pysurfer                  0.8.0                     
pytest                    3.4.2                    py36_0    conda-forge
python                    3.6.3                         1    conda-forge
python-dateutil           2.7.0                      py_0    conda-forge
pytz                      2018.3                     py_0    conda-forge
pywavelets                0.5.2                    py36_1    conda-forge
pyzmq                     17.0.0                   py36_3    conda-forge
qt                        4.8.7                         7    conda-forge
qtconsole                 4.3.1                    py36_0    conda-forge
r-assertthat              0.2.0                  r3.4.1_0    conda-forge
r-base                    3.4.1                         2    conda-forge
r-bh                      1.66.0_1               r3.4.1_0    conda-forge
r-bindr                   0.1.1                  r3.4.1_0    conda-forge
r-bindrcpp                0.2                    r3.4.1_0    conda-forge
r-bit                     1.1_12                 r3.4.1_0    conda-forge
r-bit64                   0.9_5                  r3.4.1_0    conda-forge
r-blob                    1.1.0                  r3.4.1_0    conda-forge
r-cli                     1.0.0                  r3.4.1_0    conda-forge
r-crayon                  1.3.4                  r3.4.1_0    conda-forge
r-dbi                     0.8                    r3.4.1_0    conda-forge
r-dbplyr                  1.1.0                  r3.4.1_0    conda-forge
r-digest                  0.6.12                 r3.4.1_0    conda-forge
r-dplyr                   0.7.4                  r3.4.1_0    conda-forge
r-glue                    1.2.0                  r3.4.1_0    conda-forge
r-magrittr                1.5                    r3.4.1_0    conda-forge
r-memoise                 1.1.0                  r3.4.1_0    conda-forge
r-pillar                  1.2.1                  r3.4.1_0    conda-forge
r-pkgconfig               2.0.1                  r3.4.1_0    conda-forge
r-plogr                   0.1_1                  r3.4.1_0    conda-forge
r-purrr                   0.2.4                  r3.4.1_0    conda-forge
r-r6                      2.2.2                  r3.4.1_0    conda-forge
r-rcpp                    0.12.15                r3.4.1_0    conda-forge
r-rlang                   0.2.0                  r3.4.1_0    conda-forge
r-rsqlite                 2.0                    r3.4.1_0    conda-forge
r-tibble                  1.4.2                  r3.4.1_0    conda-forge
r-utf8                    1.1.3                  r3.4.1_0    conda-forge
rdflib                    4.2.2                    py36_0    conda-forge
readline                  6.2                           0    conda-forge
rpy2                      2.8.5              py36r3.4.1_0    conda-forge
scikit-image              0.13.1                   py36_0    conda-forge
scikit-learn              0.19.1          py36_blas_openblas_201  [blas_openblas]  conda-forge
scipy                     1.0.0           py36_blas_openblas_201  [blas_openblas]  conda-forge
seaborn                   0.8.1                    py36_0    conda-forge
send2trash                1.5.0                      py_0    conda-forge
setuptools                39.0.0                   py36_0    conda-forge
simplegeneric             0.8.1                    py36_0    conda-forge
simplejson                3.13.2                   py36_0    conda-forge
singledispatch            3.4.0.3                  py36_0    conda-forge
sip                       4.18                     py36_1    conda-forge
six                       1.11.0                   py36_1    conda-forge
sparqlwrapper             1.8.0                    py36_0    conda-forge
sqlite                    3.13.0                        1    conda-forge
statsmodels               0.8.0                    py36_0    conda-forge
tbb                       2018_20171205                 0    conda-forge
terminado                 0.8.1                    py36_0    conda-forge
testpath                  0.3.1                    py36_0    conda-forge
tk                        8.5.19                        2    conda-forge
toolz                     0.9.0                      py_0    conda-forge
tornado                   4.5.3                    py36_0    conda-forge
traitlets                 4.3.2                    py36_0    conda-forge
traits                    4.6.0                    py36_1    conda-forge
traitsui                  5.1.0                    py36_0    conda-forge
vtk                       7.1.1                  py36_202    conda-forge
wcwidth                   0.1.7                    py36_0    conda-forge
webencodings              0.5                      py36_0    conda-forge
wheel                     0.30.0                   py36_2    conda-forge
widgetsnbextension        3.1.4                    py36_0    conda-forge
xorg-libxau               1.0.8                         3    conda-forge
xorg-libxdmcp             1.1.2                         3    conda-forge
xvfbwrapper               0.2.9                    py36_0    conda-forge
xz                        5.2.3                         0    conda-forge
zeromq                    4.2.3                         2    conda-forge
zlib                      1.2.11                        0    conda-forge
larsoner commented 6 years ago

NumPy 1.12 adds evidence of a NumPy-related Mayavi bug

nfoti commented 6 years ago

I didn't end up fixing the problem, but I did end up finding out that surf.module_manager.scalar_lut_manager.lut.table stores values in [0, 255] rather than [0., 1.], so I udpated like 3260 in surfer/viz.py to l_m.lut.table.from_array((cmap * 255).astype(np.uint8)). That lets me draw labels in different colors, but not the colors I specify. I also read that updating the lookup table directly may not register with VTK so I explicitly called surf.update_pipeline() right after line 3260 however, that didn't seem to help.

I'm happy to keep trying out potential fixes, but I don't think I know VTK or mayavi well enough to figure out the bug on my own right now.

EDIT: I don't think the [0, 255] thing is entirely true as I also got similar results form sending [0., 1.] values into the lut too. I ended up playing with this for a while after posting this and I'm wondering if the problem is that the array in the VTK object is storing floating point values which are then used as indices which I don't think numpy supports anymore. I didn't have time to figure out how to put ints in the VTK array, but that may be a good thing to try.

larsoner commented 6 years ago

Okay @nfoti I have another iteration for you to try

larsoner commented 6 years ago

Fixed for real this time on CircleCI

https://84-1551431-gh.circle-artifacts.com/0/tmp/circle-artifacts.68Ioe1O/html/auto_examples/plot_parcellation.html

codecov-io commented 6 years ago

Codecov Report

Merging #229 into master will increase coverage by 0.04%. The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #229      +/-   ##
==========================================
+ Coverage   74.25%   74.29%   +0.04%     
==========================================
  Files           7        7              
  Lines        2435     2439       +4     
  Branches      485      487       +2     
==========================================
+ Hits         1808     1812       +4     
  Misses        454      454              
  Partials      173      173
larsoner commented 6 years ago

Still all good:

https://85-1551431-gh.circle-artifacts.com/0/tmp/circle-artifacts.gvYgVff/html/auto_examples/plot_parcellation.html

nfoti commented 6 years ago

This PR fixes the issue for me.

Thanks.

larsoner commented 6 years ago

Upstream bug:

https://github.com/enthought/mayavi/issues/622

larsoner commented 6 years ago

Updated to latest vtk and skipped the image-saving tests that were failing on Travis OSX, probably due to an updated image (?). Ready for review/merge from my end.

larsoner commented 6 years ago

Since this fixes things for @nfoti and there are no other complaints, I'll go ahead and merge. If people look and find other problems let me know