Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 3D VisPy viewers #453

Merged
merged 4 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions glue_jupyter/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@
view.layers[0].state.update_from_dict(layer_state)
return view

def scatter3d(self, *, data=None, x=None, y=None, z=None, show=True):
def scatter3d(self, *, data=None, x=None, y=None, z=None, widget='ipyvolume', show=True):
"""
Open an interactive 3d scatter plot viewer.

Expand All @@ -387,17 +387,26 @@
The attribute to show on the y axis.
z : str or `~glue.core.component_id.ComponentID`, optional
The attribute to show on the z axis.
widget : {'ipyvolume', 'vispy'}
Whether to use ipyvolume or VisPy as the front-end.
show : bool, optional
Whether to show the view immediately (`True`) or whether to only
show it later if the ``show()`` method is called explicitly
(`False`).
"""

from .ipyvolume import IpyvolumeScatterView
if widget == 'ipyvolume':
from .ipyvolume import IpyvolumeScatterView
viewer_cls = IpyvolumeScatterView
elif widget == 'vispy':
from glue_vispy_viewers.scatter.jupyter import JupyterVispyScatterViewer
viewer_cls = JupyterVispyScatterViewer

Check warning on line 403 in glue_jupyter/app.py

View check run for this annotation

Codecov / codecov/patch

glue_jupyter/app.py#L401-L403

Added lines #L401 - L403 were not covered by tests
else:
raise ValueError("widget= should be 'ipyvolume' or 'vispy'")

Check warning on line 405 in glue_jupyter/app.py

View check run for this annotation

Codecov / codecov/patch

glue_jupyter/app.py#L405

Added line #L405 was not covered by tests

data = validate_data_argument(self.data_collection, data)

view = self.new_data_viewer(IpyvolumeScatterView, data=data, show=show)
view = self.new_data_viewer(viewer_cls, data=data, show=show)
if x is not None:
x = data.id[x]
view.state.x_att = x
Expand Down Expand Up @@ -500,7 +509,7 @@

return view

def volshow(self, *, data=None, x=None, y=None, z=None, show=True):
def volshow(self, *, data=None, x=None, y=None, z=None, widget='ipyvolume', show=True):
"""
Open an interactive volume viewer.

Expand All @@ -519,16 +528,26 @@
z : str or `~glue.core.component_id.ComponentID`, optional
The attribute to show on the z axis. This should be one of the
pixel axis attributes.
widget : {'ipyvolume', 'vispy'}
Whether to use ipyvolume or VisPy as the front-end.
show : bool, optional
Whether to show the view immediately (`True`) or whether to only
show it later if the ``show()`` method is called explicitly
(`False`).
"""
from .ipyvolume import IpyvolumeVolumeView

if widget == 'ipyvolume':
from .ipyvolume import IpyvolumeVolumeView
viewer_cls = IpyvolumeVolumeView
elif widget == 'vispy':
from glue_vispy_viewers.volume.jupyter import JupyterVispyVolumeViewer
viewer_cls = JupyterVispyVolumeViewer

Check warning on line 544 in glue_jupyter/app.py

View check run for this annotation

Codecov / codecov/patch

glue_jupyter/app.py#L542-L544

Added lines #L542 - L544 were not covered by tests
else:
raise ValueError("widget= should be 'ipyvolume' or 'vispy'")

Check warning on line 546 in glue_jupyter/app.py

View check run for this annotation

Codecov / codecov/patch

glue_jupyter/app.py#L546

Added line #L546 was not covered by tests

data = validate_data_argument(self.data_collection, data)

view = self.new_data_viewer(IpyvolumeVolumeView, data=data, show=show)
view = self.new_data_viewer(viewer_cls, data=data, show=show)

if x is not None:
x = data.id[x]
Expand Down
3 changes: 3 additions & 0 deletions glue_jupyter/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def app(dataxyz, datax, dataxz, data_volume, data_image):
SOLARA_INSTALLED = True


import vispy # noqa
vispy.use('jupyter_rfb')

# Tweak IPython's display to not print out lots of __repr__s for widgets to
# standard output. However, if we are using solara, we shouldn't do this as
# it seems to cause issues.
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ setup_requires =
setuptools_scm
install_requires =
glue-core>=1.20.0
glue-vispy-viewers>=1.0
glue-vispy-viewers[jupyter]>=1.2.1
notebook>=4.0
ipympl>=0.3.0
ipyvolume>=0.5.0
Expand Down Expand Up @@ -87,8 +87,8 @@ filterwarnings =
ignore::FutureWarning:traitlets.*:
# numpy/linalg/linalg.py:2514 (1.21) or numpy/core/_asarray.py:83 (1.19):
# `x = asarray(x)` - triggered by `example_volume` from `ipv.examples.ball()
ignore:Creating an ndarray from ragged nested sequences:numpy.VisibleDeprecationWarning:numpy.core.*:
ignore:Creating an ndarray from ragged nested sequences:numpy.VisibleDeprecationWarning:numpy.linalg.*:
ignore:Creating an ndarray from ragged nested sequences::numpy.core.*:
ignore:Creating an ndarray from ragged nested sequences::numpy.linalg.*:
ignore:'contextfilter' is renamed to 'pass_context':DeprecationWarning:
# potentially more serious, but possibly also only erratic - report them, but don't raise
# ignore:numpy.ndarray size changed:RuntimeWarning:astropy.*:
Expand Down