widgetti / ipyvolume

3d plotting for Python in the Jupyter notebook based on IPython widgets using WebGL
MIT License
1.94k stars 234 forks source link

"invalid value encountered in true_divide" i.e. divide by zero error #3

Closed drewm1980 closed 7 years ago

drewm1980 commented 7 years ago

I am trying out ipyvolume for the first time. I'm using a conda python 3 environment. I tried the pip installation instructions first, had trouble then tried the conda installation instructions. When I run the code example:

import numpy as np
import ipyvolume
V = np.zeros((128,128,128)) # our 3d array
# outer box
V[30:-30,30:-30,30:-30] = 0.75
V[35:-35,35:-35,35:-35] = 0.0
# inner box
V[50:-50,50:-50,50:-50] = 0.25
V[55:-55,55:-55,55:-55] = 0.0
ipyvolume.quickvolshow(V, level=[0.25, 0.75], opacity=0.03, level_width=0.1, data_min=0, data_max=1)

I get:

/home/awagner/src/anaconda3/lib/python3.5/site-packages/ipyvolume/serialize.py:21: RuntimeWarning: invalid value encountered in true_divide gradient = gradient / np.sqrt(gradient[0]2 + gradient[1]2 + gradient[2]**2)

In the "cube_to_png" function in serialize.py, the gradient vector may be zero, and therefore cannot be normalized to unit length. But I don't even understand why a serialization function should be getting called when you're just doing a live render...

maartenbreddels commented 7 years ago

Hi,

do you recall the pip installation issues? the warning isn't really an issue I think, the gradient is not defined in emtpy regions, and nothing will be drawn there. I could try to avoid that msg from showing up. The serialization is happening, since the 3d numpy array needs to do to the browser, this is done via a png image.

Do you get a rendering, of nothing?

maartenbreddels commented 7 years ago

aa3c0c1 should fix the warning, I didn't get a reaction for the pip issue, so consider this closed.

victortxa commented 7 years ago

@maartenbreddels the same error happened to me. I installed via conda. I tried 2 options: 1) install ipyvolume in a environment with python 2.7 and a others packages I use; 2)in my default environment with python 3. In both the same error as above and other examples of ipyvolume hasn't worked. So, I created a separated environment with python 2, then I installed ipyvolume (it asked to install the dependencies, which I accepted). This worked to run the examples. Below are the packages in the environments I mentioned above. 1)

_nb_ext_conf              0.3.0                    py27_0  
alabaster                 0.7.9                    py27_0  
anaconda-client           1.5.1                    py27_0  
apptools                  4.4.0                    py27_0  
babel                     2.3.4                    py27_0  
backports                 1.0                      py27_0  
backports_abc             0.4                      py27_0  
basemap                   1.0.7                np19py27_0  
cairo                     1.12.18                       6  
clyent                    1.2.2                    py27_0  
configobj                 5.0.6                    py27_0  
configparser              3.5.0                    py27_0  
coverage                  4.2                      py27_0  
cython                    0.24.1                   py27_0  
decorator                 4.0.10                   py27_0  
docutils                  0.12                     py27_2  
entrypoints               0.2.2                    py27_0  
enum34                    1.1.6                    py27_0  
envisage                  4.5.1                    py27_0  
fontconfig                2.11.1                        6  
freetype                  2.5.5                         1  
funcsigs                  1.0.2                    py27_0  
functools32               3.2.3.2                  py27_0  
future                    0.15.2                   py27_0  
geos                      3.3.3                         0  
get_terminal_size         1.0.0                    py27_0  
glib                      2.43.0                        1  
harfbuzz                  0.9.39                        1  
imagesize                 0.7.1                    py27_0  
ipykernel                 4.5.0                    py27_0  
ipython                   5.1.0                    py27_0  
ipython_genutils          0.1.0                    py27_0  
ipyvolume                 0.3.0                    py27_1    conda-forge
ipywidgets                5.2.2                    py27_0  
jbig                      2.1                           0  
jinja2                    2.8                      py27_1  
jpeg                      8d                            1  
jsonschema                2.5.1                    py27_0  
jupyter                   1.0.0                    py27_3  
jupyter_client            4.4.0                    py27_0  
jupyter_console           5.0.0                    py27_0  
jupyter_core              4.2.0                    py27_0  
libffi                    3.2.1                         0  
libgfortran               3.0.0                         1  
libpng                    1.6.17                        0  
libsodium                 1.0.10                        0  
libtiff                   4.0.6                         2  
libxml2                   2.9.2                         0  
llvmlite                  0.11.0                   py27_0  
markupsafe                0.23                     py27_2  
matplotlib                1.4.3                np19py27_2  
mayavi                    4.5.0                    py27_0  
mistune                   0.7.3                    py27_0  
mkl                       11.3.3                        0  
nb_anacondacloud          1.2.0                    py27_0  
nb_conda                  2.0.0                    py27_0  
nb_conda_kernels          2.0.0                    py27_0  
nbconvert                 4.2.0                    py27_0  
nbformat                  4.1.0                    py27_0  
nbpresent                 3.0.2                    py27_0  
notebook                  4.2.3                    py27_0  
numba                     0.26.0               np19py27_0  
numpy                     1.9.3                    py27_3  
openssl                   1.0.2h                        1  
pango                     1.39.0                        1  
path.py                   8.2.1                    py27_0  
pathlib2                  2.1.0                    py27_0  
pep8                      1.6.2                    py27_0  
pexpect                   4.0.1                    py27_0  
pickleshare               0.7.4                    py27_0  
pillow                    3.3.1                    py27_0  
pip                       9.0.1                    py27_1  
pixman                    0.32.6                        0  
prompt_toolkit            1.0.3                    py27_0  
ptyprocess                0.5.1                    py27_0  
py                        1.4.31                   py27_0  
py2cairo                  1.10.0                   py27_2  
pyface                    5.1.0                    py27_0  
pyface                    5.1.0                     <pip>
pygments                  2.1.3                    py27_0  
pyparsing                 2.0.3                    py27_0  
pyqt                      4.11.4                   py27_4    anaconda
pytest                    2.9.2                    py27_0  
pytest-cov                2.3.1                    py27_0  
python                    2.7.12                        1  
python-dateutil           2.5.3                    py27_0  
pytz                      2016.6.1                 py27_0  
pyyaml                    3.12                     py27_0  
pyzmq                     15.4.0                   py27_0  
qt                        4.8.7                         4  
qtconsole                 4.2.1                    py27_0  
readline                  6.2                           2  
requests                  2.11.1                   py27_0  
scipy                     0.17.1               np19py27_1  
setuptools                27.2.0                   py27_0  
simplegeneric             0.8.1                    py27_1  
singledispatch            3.4.0.3                  py27_0  
sip                       4.18                     py27_0  
six                       1.10.0                   py27_0  
snowballstemmer           1.2.1                    py27_0  
sphinx                    1.4.6                    py27_0  
sphinx-bootstrap-theme    0.4.5                     <pip>
sphinx-gallery            0.1.4                     <pip>
sqlite                    3.13.0                        0  
ssl_match_hostname        3.4.0.2                  py27_1  
terminado                 0.6                      py27_0  
tk                        8.5.18                        0  
tornado                   4.4.1                    py27_0  
traitlets                 4.3.0                    py27_0  
traits                    4.5.0                     <pip>
traits                    4.6.0                    py27_0  
traitsui                  5.1.0                    py27_0  
traittypes                0.0.5                    py27_0    conda-forge
vtk                       5.10.1                   py27_1  
wcwidth                   0.1.7                    py27_0  
wheel                     0.29.0                   py27_0  
widgetsnbextension        1.2.6                    py27_0  
xz                        5.2.2                         0  
yaml                      0.1.6                         0  
zeromq                    4.1.4                         0  
zlib                      1.2.8                         3 

2)

_license                  1.1                      py35_1  
_nb_ext_conf              0.2.0                    py35_0  
alabaster                 0.7.8                    py35_0  
anaconda                  custom                   py35_0  
anaconda-client           1.4.0                    py35_0  
anaconda-navigator        1.3.1                    py35_0  
appdirs                   1.4.0                     <pip>
argcomplete               1.0.0                    py35_1  
astroid                   1.4.7                    py35_0  
astropy                   1.2.1               np111py35_0  
babel                     2.3.3                    py35_0  
backports                 1.0                      py35_0  
beautifulsoup4            4.4.1                    py35_0  
bitarray                  0.8.1                    py35_0  
blaze                     0.10.1                   py35_0  
bokeh                     0.12.0                   py35_0  
boto                      2.40.0                   py35_0  
bottleneck                1.1.0               np111py35_0  
cffi                      1.6.0                    py35_0  
chest                     0.2.3                    py35_0  
click                     6.6                      py35_0  
cloudpickle               0.2.1                    py35_0  
clyent                    1.2.2                    py35_0  
colorama                  0.3.7                    py35_0  
conda                     4.2.13                   py35_0    conda-forge
conda-build               1.21.3                   py35_0  
conda-env                 2.6.0                         0    conda-forge
configobj                 5.0.6                    py35_0  
contextlib2               0.5.3                    py35_0  
cryptography              1.4                      py35_0  
curl                      7.49.0                        0  
cycler                    0.10.0                   py35_0  
cython                    0.24                     py35_0  
cytoolz                   0.8.0                    py35_0  
dask                      0.10.0                   py35_0  
datashape                 0.5.2                    py35_0  
dbus                      1.10.10                       0  
decorator                 4.0.10                   py35_0  
dill                      0.2.5                    py35_0  
docopt                    0.6.2                     <pip>
docutils                  0.12                     py35_2  
dynd-python               0.7.2                    py35_0  
entrypoints               0.2.2                    py35_0  
et_xmlfile                1.0.1                    py35_0  
expat                     2.1.0                         0  
ez-setup                  0.9                       <pip>
fastcache                 1.0.2                    py35_1  
flask                     0.11.1                   py35_0  
flask-cors                2.1.2                    py35_0  
fontconfig                2.11.1                        6  
freetype                  2.5.5                         1  
get_terminal_size         1.0.0                    py35_0  
gevent                    1.1.1                    py35_0  
glib                      2.43.0                        1  
greenlet                  0.4.10                   py35_0  
gst-plugins-base          1.8.0                         0  
gstreamer                 1.8.0                         0  
h5py                      2.6.0               np111py35_1  
hdf5                      1.8.16                        0  
heapdict                  1.0.0                    py35_1  
icu                       54.1                          0  
idna                      2.1                      py35_0  
imagesize                 0.7.1                    py35_0  
ipykernel                 4.3.1                    py35_0  
ipython                   4.2.0                    py35_0  
ipython_genutils          0.1.0                    py35_0  
ipyvolume                 0.3.0                    py35_1    conda-forge
ipywidgets                4.1.1                    py35_0  
itsdangerous              0.24                     py35_0  
jbig                      2.1                           0  
jdcal                     1.2                      py35_1  
jedi                      0.9.0                    py35_1  
jinja2                    2.8                      py35_1  
jpeg                      8d                            1  
jsonschema                2.5.1                    py35_0  
jupyter                   1.0.0                    py35_3  
jupyter_client            4.3.0                    py35_0  
jupyter_console           4.1.1                    py35_0  
jupyter_core              4.1.0                    py35_0  
lazy-object-proxy         1.2.1                    py35_0  
libdynd                   0.7.2                         0  
libffi                    3.2.1                         0  
libgcc                    5.2.0                         0  
libgfortran               3.0.0                         1  
libpng                    1.6.22                        0  
libprotobuf               3.0.0                         0  
libsodium                 1.0.10                        0  
libtiff                   4.0.6                         2  
libxcb                    1.12                          0  
libxml2                   2.9.2                         0  
libxslt                   1.1.28                        0  
llvmlite                  0.11.0                   py35_0  
locket                    0.2.0                    py35_1  
lxml                      3.6.0                    py35_0  
markupsafe                0.23                     py35_2  
matplotlib                1.5.3               np111py35_0  
mistune                   0.7.2                    py35_0  
mkl                       11.3.3                        0  
mkl-service               1.1.2                    py35_2  
mock                      2.0.0                    py35_0  
mpmath                    0.19                     py35_1  
multipledispatch          0.4.8                    py35_0  
nb_anacondacloud          1.1.0                    py35_0  
nb_conda                  1.1.0                    py35_0  
nb_conda_kernels          1.0.3                    py35_0  
nbconvert                 4.2.0                    py35_0  
nbformat                  4.0.1                    py35_0  
nbpresent                 3.0.2                    py35_0  
netaddr                   0.7.19                    <pip>
netifaces                 0.10.5                    <pip>
networkx                  1.11                     py35_0  
nltk                      3.2.1                    py35_0  
nose                      1.3.7                    py35_1  
notebook                  4.2.1                    py35_0  
numba                     0.26.0              np111py35_0  
numexpr                   2.6.0               np111py35_0  
numpy                     1.11.1                   py35_0  
odo                       0.5.0                    py35_1  
openpyxl                  2.3.2                    py35_0  
openssl                   1.0.2h                        1  
packaging                 16.8                      <pip>
pandas                    0.18.1              np111py35_0  
partd                     0.3.4                    py35_0  
patchelf                  0.9                           0  
path.py                   8.2.1                    py35_0  
pathlib2                  2.1.0                    py35_0  
patsy                     0.4.1                    py35_0  
pbr                       1.10.0                   py35_0  
pep8                      1.7.0                    py35_0  
pexpect                   4.0.1                    py35_0  
pickleshare               0.7.2                    py35_0  
pillow                    3.2.0                    py35_1  
pip                       9.0.1                     <pip>
pip                       8.1.2                    py35_0  
ply                       3.8                      py35_0  
protobuf                  3.0.0                    py35_1  
psutil                    4.3.0                    py35_0  
ptyprocess                0.5.1                    py35_0  
py                        1.4.31                   py35_0  
pyasn1                    0.1.9                    py35_0  
pycosat                   0.6.1                    py35_1  
pycparser                 2.14                     py35_1  
pycrypto                  2.6.1                    py35_4  
pycurl                    7.43.0                   py35_0  
pyflakes                  1.2.3                    py35_0  
pygments                  2.1.3                    py35_0  
pylint                    1.5.4                    py35_1  
pyopenssl                 0.16.0                   py35_0  
pyparsing                 2.1.4                    py35_0  
pyparsing                 2.1.10                    <pip>
pyqt                      5.6.0                    py35_0  
pytables                  3.2.2               np111py35_4  
pytest                    2.9.2                    py35_0  
python                    3.5.2                         0  
python-dateutil           2.5.3                    py35_0  
pytz                      2016.4                   py35_0  
pyyaml                    3.11                     py35_4  
pyzmq                     15.2.0                   py35_1  
qt                        5.6.0                         0  
qtawesome                 0.3.3                    py35_0  
qtconsole                 4.2.1                    py35_1  
qtpy                      1.1.2                    py35_0  
readline                  6.2                           2  
redis                     3.2.0                         0  
redis-py                  2.10.5                   py35_0  
requests                  2.10.0                   py35_0  
rope                      0.9.4                    py35_1  
ruamel_yaml               0.11.14                  py35_0  
scikit-image              0.12.3              np111py35_1  
scikit-learn              0.17.1              np111py35_2  
scipy                     0.17.1              np111py35_1  
setuptools                23.0.0                   py35_0  
simplegeneric             0.8.1                    py35_1  
singledispatch            3.4.0.3                  py35_0  
sip                       4.18                     py35_0  
six                       1.10.0                   py35_0  
snowballstemmer           1.2.1                    py35_0  
sockjs-tornado            1.0.3                    py35_0  
sphinx                    1.4.1                    py35_0  
sphinx_rtd_theme          0.1.9                    py35_0  
SpoofMAC                  2.1.1                     <pip>
spyder                    3.0.0                    py35_0  
sqlalchemy                1.0.13                   py35_0  
sqlite                    3.13.0                        0  
statsmodels               0.6.1               np111py35_1  
sympy                     1.0                      py35_0  
tensorflow                0.10.0rc0           np111py35_0  
terminado                 0.6                      py35_0  
tk                        8.5.18                        0  
toolz                     0.8.0                    py35_0  
tornado                   4.3                      py35_1  
tqdm                      4.11.2                    <pip>
traitlets                 4.3.2                    py35_0    conda-forge
traittypes                0.0.6                    py35_0    conda-forge
unicodecsv                0.14.1                   py35_0  
werkzeug                  0.11.10                  py35_0  
wheel                     0.29.0                   py35_0  
wrapt                     1.10.8                   py35_0  
xlrd                      1.0.0                    py35_0  
xlsxwriter                0.9.2                    py35_0  
xlwt                      1.1.2                    py35_0  
xz                        5.2.2                         0  
yaml                      0.1.6                         0  
zeromq                    4.1.4                         0  
zlib                      1.2.8                         3
maartenbreddels commented 7 years ago

Hi, I see the issue, (the error had nothing to do with it). You need ipywidget version 6.This is a bug in the dependency list for the conda recipe, I'll fix it for the next release! Thanks for reporting this, and let me know if this fixed it.

victortxa commented 7 years ago

Thank you! It worked perfectly now in both environments (python 3 without any warning, python 2 with the warning mentioned above); before updating to ipywidget version 6 there was no image.

maartenbreddels commented 7 years ago

Thanks for letting me know!