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

Updates for ipyvolume viewer issues #456

Merged
merged 8 commits into from
Aug 6, 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
2 changes: 1 addition & 1 deletion glue_jupyter/common/state3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
# TODO: this could be cached based on the limits, but is not urgent
aspect = np.array([1, 1, 1], dtype=float)
if self.native_aspect:
aspect[0] = 1.
aspect[0] = 1.0

Check warning on line 88 in glue_jupyter/common/state3d.py

View check run for this annotation

Codecov / codecov/patch

glue_jupyter/common/state3d.py#L88

Added line #L88 was not covered by tests
aspect[1] = (self.z_max - self.z_min) / (self.x_max - self.x_min)
aspect[2] = (self.y_max - self.y_min) / (self.x_max - self.x_min)
aspect /= aspect.max()
Expand Down
14 changes: 6 additions & 8 deletions glue_jupyter/ipyvolume/common/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ def __init__(self, *args, **kwargs):
# FIXME: hack for the movie maker to have access to the figure
self.state.figure = self.figure

# note that for ipyvolume, we use axis in the order x, z, y in order to have
# note that for ipyvolume, we use axis in the order z, x, y in order to have
# the z axis of glue pointing up
def attribute_to_label(attribute):
return 'null' if attribute is None else attribute.label

dlink((self.state, 'x_att'), (self.figure, 'xlabel'), attribute_to_label)
dlink((self.state, 'y_att'), (self.figure, 'zlabel'), attribute_to_label)
dlink((self.state, 'x_att'), (self.figure, 'zlabel'), attribute_to_label)
dlink((self.state, 'y_att'), (self.figure, 'xlabel'), attribute_to_label)
dlink((self.state, 'z_att'), (self.figure, 'ylabel'), attribute_to_label)

self.state.add_callback('x_min', self.limits_to_scales)
Expand Down Expand Up @@ -86,12 +86,10 @@ def apply_roi(self, roi, use_current=False):
self._session.command_stack.do(cmd)

def limits_to_scales(self, *args):
if self.state.x_min is not None and self.state.x_max is not None:
self.figure.xlim = self.state.x_min, self.state.x_max
if self.state.y_min is not None and self.state.y_max is not None:
self.figure.zlim = self.state.y_min, self.state.y_max
# if self.state.z_min is not None and self.state.z_max is not None:
# self.figure.zlim = self.state.z_min, self.state.z_max
self.figure.xlim = self.state.y_min, self.state.y_max
if self.state.x_min is not None and self.state.x_max is not None:
self.figure.zlim = self.state.x_min, self.state.x_max
if hasattr(self.state, 'z_min'):
if self.state.z_min is not None and self.state.z_max is not None:
self.figure.ylim = self.state.z_min, self.state.z_max
Expand Down
21 changes: 16 additions & 5 deletions glue_jupyter/ipyvolume/scatter/layer_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,25 @@ def _update_color(self, ignore=None):
def _update_xyz_att(self, *args):
self.update()

def _cast_to_float(self, arr):
if np.issubdtype(arr.dtype, np.floating):
return arr

# `itemsize` returns the byte size of the dtype
size = 8 * arr.dtype.itemsize
return arr.astype(f"float{size}")

def redraw(self):
pass

def update(self):
# we don't use layer, but layer.data to get everything
self.scatter.x = ensure_numerical(self.layer.data[self._viewer_state.x_att]).ravel()
self.scatter.z = ensure_numerical(self.layer.data[self._viewer_state.y_att]).ravel()
self.scatter.y = ensure_numerical(self.layer.data[self._viewer_state.z_att]).ravel()
self.scatter.z = self._cast_to_float(
ensure_numerical(self.layer.data[self._viewer_state.x_att]).ravel())
self.scatter.y = self._cast_to_float(
ensure_numerical(self.layer.data[self._viewer_state.z_att]).ravel())
self.scatter.x = self._cast_to_float(
ensure_numerical(self.layer.data[self._viewer_state.y_att]).ravel())
self.quiver.x = self.scatter.x
self.quiver.z = self.scatter.y
self.quiver.y = self.scatter.z
Expand All @@ -123,9 +134,9 @@ def _clear_selection(self):

def _update_quiver(self):
with self.quiver.hold_sync():
self.quiver.vx = self.layer.data[self.state.vx_att].ravel()
self.quiver.vz = self.layer.data[self.state.vy_att].ravel()
self.quiver.vz = self.layer.data[self.state.vx_att].ravel()
self.quiver.vy = self.layer.data[self.state.vz_att].ravel()
self.quiver.vx = self.layer.data[self.state.vy_att].ravel()

def _update_size(self):
size = self.state.size
Expand Down
8 changes: 4 additions & 4 deletions glue_jupyter/ipyvolume/scatter/tests/test_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def test_labels(app, dataxyz):
app.add_data(dataxyz)
scatter = app.scatter3d(data=dataxyz)
assert str(scatter.state.x_att) == 'x'
assert scatter.figure.xlabel == 'x'
assert scatter.figure.zlabel == 'x'
assert str(scatter.state.y_att) == 'y'
assert scatter.figure.zlabel == 'y'
assert scatter.figure.xlabel == 'y'
assert str(scatter.state.z_att) == 'z'
assert scatter.figure.ylabel == 'z'

scatter.state.x_att = dataxyz.id['y']
assert scatter.figure.xlabel == 'y'
assert scatter.figure.zlabel == 'y'
scatter.state.y_att = dataxyz.id['z']
assert scatter.figure.zlabel == 'z'
assert scatter.figure.xlabel == 'z'
scatter.state.z_att = dataxyz.id['x']
assert scatter.figure.ylabel == 'x'
8 changes: 4 additions & 4 deletions glue_jupyter/ipyvolume/tests/test_ipyvolume.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ def test_scatter3d(app, dataxyz, dataxz):
assert s.layers[1].layer['y'].tolist() == [4]
assert s.layers[1].layer['z'].tolist() == [7]

assert s.layers[1].scatter.x.tolist() == [1, 2, 3]
assert s.layers[1].scatter.z.tolist() == [2, 3, 4]
assert s.layers[1].scatter.z.tolist() == [1, 2, 3]
assert s.layers[1].scatter.x.tolist() == [2, 3, 4]
assert s.layers[1].scatter.y.tolist() == [5, 6, 7]
assert s.layers[1].scatter.selected == [2]

s.state.x_att = dataxyz.id['y']
s.state.y_att = dataxyz.id['z']
s.state.z_att = dataxyz.id['x']
assert s.layers[1].scatter.x.tolist() == [2, 3, 4]
assert s.layers[1].scatter.z.tolist() == [5, 6, 7]
assert s.layers[1].scatter.z.tolist() == [2, 3, 4]
assert s.layers[1].scatter.x.tolist() == [5, 6, 7]
assert s.layers[1].scatter.y.tolist() == [1, 2, 3]
assert s.layers[1].scatter.selected == [2]

Expand Down
2 changes: 2 additions & 0 deletions glue_jupyter/ipyvolume/volume/layer_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def update(self):
data *= mask
else:
data = self.layer[self.state.attribute]

data = np.transpose(data, (2, 0, 1))
finite_mask = np.isfinite(data)
finite_data = data[finite_mask]
finite_mask_normalized = finite_data - finite_data.min()
Expand Down