Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def labels(self):
'''
Add 3d text to show the axes.
'''
fontsize = max(self.xrang, self.yrang)/40.
tcolor = (1,1,1)
mlab.text3d(self.xrang/2,-10,self.zrang+10,'R.A.',scale=fontsize,orient_to_camera=True,color=tcolor)
mlab.text3d(-10,self.yrang/2,self.zrang+10,'Decl.',scale=fontsize,orient_to_camera=True,color=tcolor)
mlab.text3d(-10,-10,self.zrang/2-10,'V (km/s)',scale=fontsize,orient_to_camera=True,color=tcolor)
# Add scale bars
if self.leng != 0.0:
distance = self.dist * 1e3
length = self.leng
leng_pix = np.round(length/distance/np.pi*180./np.abs(self.hdr['cdelt1']))
bar_x = [self.xrang-20-leng_pix, self.xrang-20]
bar_y = [self.yrang-10, self.yrang-10]
bar_z = [0, 0]
mlab.plot3d(bar_x, bar_y, bar_z, color=tcolor, tube_radius=1.)
mlab.text3d(self.xrang-30-leng_pix,self.yrang-25,0,'{:.2f} pc'.format(length),scale=fontsize,orient_to_camera=False,color=tcolor)
if self.vsp != 0.0:
vspan = self.vsp
vspan_pix = np.round(vspan/np.abs(self.hdr['cdelt3']/1e3))
def mv_plot_pose(T_frame_world, alpha=0.5, tube_radius=0.005, center_scale=0.025):
T_world_frame = T_frame_world.inverse()
R = T_world_frame.rotation
t = T_world_frame.translation
x_axis_tf = np.array([t, t + alpha * R[:,0]])
y_axis_tf = np.array([t, t + alpha * R[:,1]])
z_axis_tf = np.array([t, t + alpha * R[:,2]])
mv.points3d(t[0], t[1], t[2], color=(1,1,1), scale_factor=center_scale)
mv.plot3d(x_axis_tf[:,0], x_axis_tf[:,1], x_axis_tf[:,2], color=(1,0,0), tube_radius=tube_radius)
mv.plot3d(y_axis_tf[:,0], y_axis_tf[:,1], y_axis_tf[:,2], color=(0,1,0), tube_radius=tube_radius)
mv.plot3d(z_axis_tf[:,0], z_axis_tf[:,1], z_axis_tf[:,2], color=(0,0,1), tube_radius=tube_radius)
mv.text3d(t[0], t[1], t[2], ' %s' %T_frame_world.to_frame.upper(), scale=0.01)
def labels(self):
'''
Add 3d text to show the axes.
'''
fontsize = max(self.xrang, self.yrang)/40.
tcolor = (1,1,1)
mlab.text3d(self.xrang/2,-10,self.zrang+10,'R.A.',scale=fontsize,orient_to_camera=True,color=tcolor)
mlab.text3d(-10,self.yrang/2,self.zrang+10,'Decl.',scale=fontsize,orient_to_camera=True,color=tcolor)
mlab.text3d(-10,-10,self.zrang/2-10,'V (km/s)',scale=fontsize,orient_to_camera=True,color=tcolor)
# Add scale bars
if self.leng != 0.0:
distance = self.dist * 1e3
length = self.leng
leng_pix = np.round(length/distance/np.pi*180./np.abs(self.hdr['cdelt1']))
bar_x = [self.xrang-20-leng_pix, self.xrang-20]
bar_y = [self.yrang-10, self.yrang-10]
bar_z = [0, 0]
mlab.plot3d(bar_x, bar_y, bar_z, color=tcolor, tube_radius=1.)
mlab.text3d(self.xrang-30-leng_pix,self.yrang-25,0,'{:.2f} pc'.format(length),scale=fontsize,orient_to_camera=False,color=tcolor)
if self.vsp != 0.0:
vspan = self.vsp
vspan_pix = np.round(vspan/np.abs(self.hdr['cdelt3']/1e3))
bar_x = [self.xrang, self.xrang]
color = rendering.color_cycle(m)
it = np.where(channels['trajectory_id'] == probe_id)[0]
xyz = channels['xyz'][it]
ins = atlas.Insertion.from_track(xyz, brain_atlas=ba)
mlapdv = ba.xyz2ccf(ins.xyz)
# display the interpolated tracks
mlab.plot3d(mlapdv[:, 1], mlapdv[:, 2], mlapdv[:, 0],
line_width=3, color=color, tube_radius=20)
# display the channels locations
mlapdv_channels = ba.xyz2ccf(xyz)
mlab.points3d(mlapdv_channels[:, 1], mlapdv_channels[:, 2], mlapdv_channels[:, 0],
color=color, scale_factor=50)
# setup the labels at the top of the trajectories
mlab.text3d(mlapdv[0, 1], mlapdv[0, 2], mlapdv[0, 0] - 500, label,
line_width=4, color=tuple(color), figure=fig, scale=150)
gt_boxes3d: numpy array (n,8,3) for XYZs of the box corners
fig: mayavi figure handler
color: RGB value tuple in range (0,1), box line color
line_width: box line width
draw_text: boolean, if true, write box indices beside boxes
text_scale: three number tuple
color_list: a list of RGB tuple, if not None, overwrite color.
Returns:
fig: updated fig
'''
num = len(gt_boxes3d)
for n in range(num):
b = gt_boxes3d[n]
if color_list is not None:
color = color_list[n]
if draw_text: mlab.text3d(b[4,0], b[4,1], b[4,2], '%d'%n, scale=text_scale, color=color, figure=fig)
for k in range(0,4):
#http://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html
i,j=k,(k+1)%4
mlab.plot3d([b[i,0], b[j,0]], [b[i,1], b[j,1]], [b[i,2], b[j,2]], color=color, tube_radius=None, line_width=line_width, figure=fig)
i,j=k+4,(k+1)%4 + 4
mlab.plot3d([b[i,0], b[j,0]], [b[i,1], b[j,1]], [b[i,2], b[j,2]], color=color, tube_radius=None, line_width=line_width, figure=fig)
i,j=k,k+4
mlab.plot3d([b[i,0], b[j,0]], [b[i,1], b[j,1]], [b[i,2], b[j,2]], color=color, tube_radius=None, line_width=line_width, figure=fig)
#mlab.show(1)
#mlab.view(azimuth=180, elevation=70, focalpoint=[ 12.0909996 , -1.04700089, -2.03249991], distance=62.0, figure=fig)
return fig
fontsize = max(self.xrang, self.yrang)/40.
tcolor = (1,1,1)
mlab.text3d(self.xrang/2,-10,self.zrang+10,'R.A.',scale=fontsize,orient_to_camera=True,color=tcolor)
mlab.text3d(-10,self.yrang/2,self.zrang+10,'Decl.',scale=fontsize,orient_to_camera=True,color=tcolor)
mlab.text3d(-10,-10,self.zrang/2-10,'V (km/s)',scale=fontsize,orient_to_camera=True,color=tcolor)
# Add scale bars
if self.leng != 0.0:
distance = self.dist * 1e3
length = self.leng
leng_pix = np.round(length/distance/np.pi*180./np.abs(self.hdr['cdelt1']))
bar_x = [self.xrang-20-leng_pix, self.xrang-20]
bar_y = [self.yrang-10, self.yrang-10]
bar_z = [0, 0]
mlab.plot3d(bar_x, bar_y, bar_z, color=tcolor, tube_radius=1.)
mlab.text3d(self.xrang-30-leng_pix,self.yrang-25,0,'{:.2f} pc'.format(length),scale=fontsize,orient_to_camera=False,color=tcolor)
if self.vsp != 0.0:
vspan = self.vsp
vspan_pix = np.round(vspan/np.abs(self.hdr['cdelt3']/1e3))
bar_x = [self.xrang, self.xrang]
bar_y = [self.yrang-10, self.yrang-10]
bar_z = np.array([5, 5+vspan_pix])*self.zscale
mlab.plot3d(bar_x, bar_y, bar_z, color=tcolor, tube_radius=1.)
mlab.text3d(self.xrang,self.yrang-25,10,'{:.1f} km/s'.format(vspan),scale=fontsize,orient_to_camera=False,color=tcolor,orientation=(0,90,0))
# Label the coordinates of the corners
# Lower left corner
ra0 = self.extent[0]; dec0 = self.extent[2]
c = SkyCoord(ra=ra0*u.degree, dec=dec0*u.degree, frame='icrs')
RA_ll = str(int(c.ra.hms.h))+'h'+str(int(c.ra.hms.m))+'m'+str(round(c.ra.hms.s,1))+'s'
mlab.text3d(0,-10,self.zrang+5,RA_ll,scale=fontsize,orient_to_camera=True,color=tcolor)
DEC_ll = str(int(c.dec.dms.d))+'d'+str(int(abs(c.dec.dms.m)))+'m'+str(round(abs(c.dec.dms.s),1))+'s'
figure = self.mayavi_view.scene.mayavi_scene)
pts.glyph.color_mode = 'color_by_scalar'
pts.mlab_source.dataset.lines = np.array(G.edges())
self.node_collection = pts
tube = mlab.pipeline.tube(pts, tube_radius=2.0) # Default tube_radius results in v. thin lines: tube.filter.radius = 0.05
self.edge_collection = mlab.pipeline.surface(tube, color=(0.8, 0.8, 0.8))
# Add object label text to the left
dx = np.diff(self.node_x_locations)[0]
first_nodes = [i[0] for i in self.connected_nodes]
x = [self.node_positions[i][0]-0.75*dx for i in first_nodes]
y = [self.node_positions[i][1] for i in first_nodes]
z = list(np.array(y)*0)
s = [str(i[0]) for i in first_nodes]
self.text_collection = [mlab.text3d(xx, yy, zz, ss,
line_width = 20,
scale = 20,
name = ss,
figure = self.mayavi_view.scene.mayavi_scene)
for xx,yy,zz,ss in zip(x,y,z,s)]
# Scale axes according to the data limits
# TODO: Figure out how scaling relates to elment coordinates for trajectory picking.
#self.axis_scaling = [1.0/(max(xy[:,0])-min(xy[:,0])), 1.0/(max(xy[:,1])-min(xy[:,1])), 0.0]
#self.node_collection.actor.actor.scale = self.axis_scaling
#self.edge_collection.actor.actor.scale = self.axis_scaling
# Text labels are not the same scale as the other graphical elements, so adjust accordingly
# TODO: Figure out how to scale the text the same as the graphical elements.
#current_text_scaling = self.text_collection[0].actor.actor.scale
#for t in self.text_collection:
#t.actor.actor.scale = current_text_scaling*self.axis_scaling
def labels(self):
'''
Add 3d text to show the axes.
'''
fontsize = max(self.xrang, self.yrang)/40.
tcolor = (1,1,1)
mlab.text3d(self.xrang/2,-10,self.zrang+10,'R.A.',scale=fontsize,orient_to_camera=True,color=tcolor)
mlab.text3d(-10,self.yrang/2,self.zrang+10,'Decl.',scale=fontsize,orient_to_camera=True,color=tcolor)
mlab.text3d(-10,-10,self.zrang/2-10,'V (km/s)',scale=fontsize,orient_to_camera=True,color=tcolor)
# Add scale bars
if self.leng != 0.0:
distance = self.dist * 1e3
length = self.leng
leng_pix = np.round(length/distance/np.pi*180./np.abs(self.hdr['cdelt1']))
bar_x = [self.xrang-20-leng_pix, self.xrang-20]
bar_y = [self.yrang-10, self.yrang-10]
bar_z = [0, 0]
mlab.plot3d(bar_x, bar_y, bar_z, color=tcolor, tube_radius=1.)
mlab.text3d(self.xrang-30-leng_pix,self.yrang-25,0,'{:.2f} pc'.format(length),scale=fontsize,orient_to_camera=False,color=tcolor)
if self.vsp != 0.0:
vspan = self.vsp
vspan_pix = np.round(vspan/np.abs(self.hdr['cdelt3']/1e3))
bar_x = [self.xrang, self.xrang]
bar_y = [self.yrang-10, self.yrang-10]
vspan = self.vsp
vspan_pix = np.round(vspan/np.abs(self.hdr['cdelt3']/1e3))
bar_x = [self.xrang, self.xrang]
bar_y = [self.yrang-10, self.yrang-10]
bar_z = np.array([5, 5+vspan_pix])*self.zscale
mlab.plot3d(bar_x, bar_y, bar_z, color=tcolor, tube_radius=1.)
mlab.text3d(self.xrang,self.yrang-25,10,'{:.1f} km/s'.format(vspan),scale=fontsize,orient_to_camera=False,color=tcolor,orientation=(0,90,0))
# Label the coordinates of the corners
# Lower left corner
ra0 = self.extent[0]; dec0 = self.extent[2]
c = SkyCoord(ra=ra0*u.degree, dec=dec0*u.degree, frame='icrs')
RA_ll = str(int(c.ra.hms.h))+'h'+str(int(c.ra.hms.m))+'m'+str(round(c.ra.hms.s,1))+'s'
mlab.text3d(0,-10,self.zrang+5,RA_ll,scale=fontsize,orient_to_camera=True,color=tcolor)
DEC_ll = str(int(c.dec.dms.d))+'d'+str(int(abs(c.dec.dms.m)))+'m'+str(round(abs(c.dec.dms.s),1))+'s'
mlab.text3d(-40,0,self.zrang+5,DEC_ll,scale=fontsize,orient_to_camera=True,color=tcolor)
# Upper right corner
ra0 = self.extent[1]; dec0 = self.extent[3]
c = SkyCoord(ra=ra0*u.degree, dec=dec0*u.degree, frame='icrs')
RA_ll = str(int(c.ra.hms.h))+'h'+str(int(c.ra.hms.m))+'m'+str(round(c.ra.hms.s,1))+'s'
mlab.text3d(self.xrang,-10,self.zrang+5,RA_ll,scale=fontsize,orient_to_camera=True,color=tcolor)
DEC_ll = str(int(c.dec.dms.d))+'d'+str(int(abs(c.dec.dms.m)))+'m'+str(round(abs(c.dec.dms.s),1))+'s'
mlab.text3d(-40,self.yrang,self.zrang+5,DEC_ll,scale=fontsize,orient_to_camera=True,color=tcolor)
# V axis
if self.extent[5] > self.extent[4]:
v0 = self.extent[4]; v1 = self.extent[5]
else:
v0 = self.extent[5]; v1 = self.extent[4]
mlab.text3d(-10,-10,self.zrang,str(round(v0,1)),scale=fontsize,orient_to_camera=True,color=tcolor)
mlab.text3d(-10,-10,0,str(round(v1,1)),scale=fontsize,orient_to_camera=True,color=tcolor)
mlab.axes(self.field, ranges=self.extent, x_axis_visibility=False, y_axis_visibility=False, z_axis_visibility=False)