-
Notifications
You must be signed in to change notification settings - Fork 589
/
ipyvolume.py
90 lines (79 loc) 路 3.3 KB
/
ipyvolume.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from .bqplot import PlotBase
import ipyvolume.pylab as p3
import ipyvolume.examples
import traitlets
import vaex.dataset
import ipywidgets as widgets
from IPython.display import HTML, display_html, display_javascript, display
import numpy as np
class PlotDefault(PlotBase):
z = traitlets.Unicode(allow_none=False)
def _update_image(self):
with self.output:
grid = self.get_grid()
if self.smooth_pre:
for i in range(grid.shape[0]):
grid[i] = vaex.grids.gf(grid[i], self.smooth_pre)
f = vaex.dataset._parse_f(self.f)
fgrid = f(grid)
if self.smooth_post:
for i in range(grid.shape[0]):
fgrid[i] = vaex.grids.gf(fgrid[i], self.smooth_post)
ngrid, fmin, fmax = self.normalise(fgrid)
print(ngrid.shape)
if len(ngrid.shape) == 4:
#if ngrid.shape[0] == 1:
ngrid = ngrid[-1]
p3.volshow(ngrid.T, controls=self._first_time)
vx, vy, vz = self.vgrids[:3]
vcount = self.vcount
if vx is not None and vy is not None and vz is not None and vcount is not None:
vcount = vcount[-1] # no multivolume render, just take the last selection
vx = vx[-1]
vy = vy[-1]
vz = vz[-1]
print(vx.shape)
ok = np.isfinite(vx) & np.isfinite(vy) & np.isfinite(vz)
vcount_min = None
vcount_max = None
if self.vcount_limits is not None:
try:
vcount_min, vcount_max = self.vcount_limits
except:
vcount_min = self.vcount_limits
if vcount_min is not None:
ok &= (vcount > vcount_min)
if vcount_max is not None:
ok &= (vcount < vcount_max)
x, y, z = ipyvolume.examples.xyz(self.get_vshape()[0], limits=self.limits, sparse=False, centers=True)
v1d = [k[ok] for k in [x, y, z, vx, vy, vz]]
vsize = 5
vcolor = "grey"
if self._first_time:
self.quiver = p3.quiver(*v1d, size=vsize, color=vcolor)
else:
self.quiver.x = x[ok]
self.quiver.y = y[ok]
self.quiver.z = z[ok]
self.quiver.vx = vx[ok]
self.quiver.vy = vy[ok]
self.quiver.vz = vz[ok]
p3.xlim(*self.limits[0])
p3.ylim(*self.limits[1])
p3.zlim(*self.limits[2])
self._first_time = False
def create_plot(self):
self._first_time = True
self.figure = p3.figure()
def show(self):
container = p3.gcc()
vbox = widgets.VBox([container, self.progress, widgets.VBox(self.tools), self.output])
display(vbox)
def create_tools(self):
self.tools = []
callback = self.dataset.signal_selection_changed.connect(lambda *x: self.update_grid())
def cleanup(callback=callback):
self.dataset.signal_selection_changed.disconnect(callback=callback)
self._cleanups.append(cleanup)
def get_binby(self):
return [self.x, self.y, self.z]