Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
csv_file = "/home/olivier/Documents/MATLAB/ibllib-matlab/needles/maps/first_pass_map.csv"
# start of the code
brain_atlas = atlas.AllenAtlas(25)
brain_atlas = atlas.NeedlesAtlas(25)
df_map = pd.read_csv(csv_file)
fig = rendering.figure()
plt_trj = []
for index, rec in df_map.iterrows():
ins = atlas.Insertion.from_dict({'x': rec.ml_um, 'y': rec.ap_um, 'z': rec.dv_um,
'phi': rec.phi, 'theta': rec.theta, 'depth': rec.depth_um})
mlapdv = brain_atlas.xyz2ccf(ins.xyz)
plt = mlab.plot3d(mlapdv[:, 1], mlapdv[:, 2], mlapdv[:, 0],
line_width=3, color=(1, .6, .6), tube_radius=15)
plt_trj.append(plt)
##
rendering.rotating_video(output_video, fig, fps=24, secs=16)
def drawBonds(self):
bondx = np.zeros( 2 )
bondy = np.zeros( 2 )
bondz = np.zeros( 2 )
ones = np.array( (1.0,1.0) )
self.glyph_bonds = []
for bond in self.unit_cell.bonds:
i,j = bond
bondx[0] = self.X[i]
bondy[0] = self.Y[i]
bondz[0] = self.Z[i]
bondx[1] = self.X[j]
bondy[1] = self.Y[j]
bondz[1] = self.Z[j]
glyph = mlab.plot3d(bondx,bondy,bondz,ones,tube_radius=0.1, tube_sides=10, color=(0,0,0) )
self.glyph_bonds.append(glyph)
return
''' Draw lidar points. simplest set up. '''
fig = mlab.figure(figure=None, bgcolor=(0,0,0), fgcolor=None, engine=None, size=(1600, 1000))
if color is None: color = pc[:,2]
#draw points
mlab.points3d(pc[:,0], pc[:,1], pc[:,2], color, color=None, mode='point', colormap = 'gnuplot', scale_factor=1, figure=fig)
#draw origin
mlab.points3d(0, 0, 0, color=(1,1,1), mode='sphere', scale_factor=0.2)
#draw axis
axes=np.array([
[2.,0.,0.,0.],
[0.,2.,0.,0.],
[0.,0.,2.,0.],
],dtype=np.float64)
mlab.plot3d([0, axes[0,0]], [0, axes[0,1]], [0, axes[0,2]], color=(1,0,0), tube_radius=None, figure=fig)
mlab.plot3d([0, axes[1,0]], [0, axes[1,1]], [0, axes[1,2]], color=(0,1,0), tube_radius=None, figure=fig)
mlab.plot3d([0, axes[2,0]], [0, axes[2,1]], [0, axes[2,2]], color=(0,0,1), tube_radius=None, figure=fig)
mlab.view(azimuth=180, elevation=70, focalpoint=[ 12.0909996 , -1.04700089, -2.03249991], distance=62.0, figure=fig)
return fig
xlon, ylon, zlon,
color=colors.colorConverter.to_rgb(self.frame_color),
opacity=self.frame_alpha, tube_radius=self.frame_radius)
# add axes
axis = np.linspace(-1.0, 1.0, 10)
other = np.zeros_like(axis)
mlab.plot3d(
axis, other, other,
color=colors.colorConverter.to_rgb(self.axes_color),
tube_radius=self.axes_radius, opacity=self.axes_alpha)
mlab.plot3d(
other, axis, other,
color=colors.colorConverter.to_rgb(self.axes_color),
tube_radius=self.axes_radius, opacity=self.axes_alpha)
mlab.plot3d(
other, other, axis,
color=colors.colorConverter.to_rgb(self.axes_color),
tube_radius=self.axes_radius, opacity=self.axes_alpha)
# add data to sphere
self.plot_points()
self.plot_vectors()
# #add labels
mlab.text3d(0, 0, self.zlpos[0], self.zlabel[0],
color=colors.colorConverter.to_rgb(self.font_color),
scale=self.font_scale)
mlab.text3d(0, 0, self.zlpos[1], self.zlabel[1],
color=colors.colorConverter.to_rgb(self.font_color),
scale=self.font_scale)
mlab.text3d(self.xlpos[0], 0, 0, self.xlabel[0],
g1_tf = T_obj_world.inverse().apply(g1)
g2_tf = T_obj_world.inverse().apply(g2)
center_tf = T_obj_world.inverse().apply(center)
grasp_axis_tf = np.array([g1_tf, g2_tf])
T_gripper_obj = grasp.gripper_transform(gripper=ZEKE_GRIPPER)
palm_axis = T_gripper_obj.inverse().rotation[:,1]
axis_tf = np.array([g1_tf, g2_tf])
palm_axis_tf = T_obj_world.inverse().apply(palm_axis, direction=True)
palm_axis_tf = np.array([center_tf, center_tf + alpha * palm_axis_tf])
mv.points3d(g1_tf[0], g1_tf[1], g1_tf[2], color=endpoint_color, scale_factor=endpoint_scale)
mv.points3d(g2_tf[0], g2_tf[1], g2_tf[2], color=endpoint_color, scale_factor=endpoint_scale)
mv.plot3d(grasp_axis_tf[:,0], grasp_axis_tf[:,1], grasp_axis_tf[:,2], color=grasp_axis_color, tube_radius=tube_radius)
if plot_approach:
mv.plot3d(palm_axis_tf[:,0], palm_axis_tf[:,1], palm_axis_tf[:,2], color=palm_axis_color, tube_radius=tube_radius)
'''
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)
cr = pychemia.utils.periodic.covalent_radius(geometry_file.symbols)
if visual is None:
gs = mlab.points3d(x, y, z, cr, scale_factor=5)
else:
visual.gs.mlab_source.set(x=x, y=y, z=z)
else:
gs = None
if visual is None:
bs = []
if box:
x0, y0, z0, x1, y1, z1 = _compute_box(b)
ze = np.zeros(2)
bb1 = mlab.plot3d(x0, y0, z0, tube_radius=.15, color=(1, 1, 1))
bb2 = mlab.plot3d(ze, y1, z1, tube_radius=.15, color=(1, 1, 1))
bb3 = mlab.plot3d(x1, y1, z1, tube_radius=.15, color=(1, 1, 1))
bb4 = mlab.plot3d(x1, ze, z1, tube_radius=.15, color=(1, 1, 1))
bs = [bb1, bb2, bb3, bb4]
else:
if box:
x0, y0, z0, x1, y1, z1 = _compute_box(b)
ze = np.zeros(2)
visual.bs[0].start()
visual.bs[1].start()
visual.bs[2].start()
visual.bs[3].start()
visual.bs[0].mlab_source.set(x=x0, y=y0, z=z0, tube_radius=.15, color=(1, 1, 1))
visual.bs[1].mlab_source.set(x=ze, y=y1, z=z1, tube_radius=.15, color=(1, 1, 1))
'''
plt.plot(ground_truth[0], ground_truth[1],'r')
plt.plot(ground_truth[0], ground_truth[2],'g')
plt.plot(ground_truth[0], ground_truth[3],'b')
plt.plot(cameras[0], cameras[1],'r--')
plt.plot(cameras[0], cameras[2],'g--')
plt.plot(cameras[0], cameras[3],'b--')
plt.show()
plt.hist(np.bincount(observations['point_id']), 50, normed=1)
plt.show()
'''
mlab.points3d(points[0], points[1], points[2], mode='point', color=(1,1,1))
mlab.plot3d(cameras[1], cameras[2], cameras[3], tube_radius=None, color=(0,1,0))
#mlab.plot3d(ground_truth[1], ground_truth[2], ground_truth[3], tube_radius=None, color=(1,0,0))
'''
for i in range(camera_positions.shape[1]):
pos_item = camera_positions[:,i]
r = tf.transformations.quaternion_matrix(pos_item[4:8])
r[0:3,3] = pos_item[1:4]
mlab.quiver3d(r[0,3], r[1,3], r[2,3], r[0,0], r[1,0], r[2,0], color=(1,0,0), mode='2ddash', scale_factor=0.1)
mlab.quiver3d(r[0,3], r[1,3], r[2,3], r[0,1], r[1,1], r[2,1], color=(0,1,0), mode='2ddash', scale_factor=0.1)
mlab.quiver3d(r[0,3], r[1,3], r[2,3], r[0,2], r[1,2], r[2,2], color=(0,0,1), mode='2ddash', scale_factor=0.1)
'''
mlab.show()
# draw square region
TOP_Y_MIN=-20
TOP_Y_MAX=20
TOP_X_MIN=0
TOP_X_MAX=40
TOP_Z_MIN=-2.0
TOP_Z_MAX=0.4
x1 = TOP_X_MIN
x2 = TOP_X_MAX
y1 = TOP_Y_MIN
y2 = TOP_Y_MAX
mlab.plot3d([x1, x1], [y1, y2], [0,0], color=(0.5,0.5,0.5), tube_radius=0.1, line_width=1, figure=fig1)
mlab.plot3d([x2, x2], [y1, y2], [0,0], color=(0.5,0.5,0.5), tube_radius=0.1, line_width=1, figure=fig1)
mlab.plot3d([x1, x2], [y1, y1], [0,0], color=(0.5,0.5,0.5), tube_radius=0.1, line_width=1, figure=fig1)
mlab.plot3d([x1, x2], [y2, y2], [0,0], color=(0.5,0.5,0.5), tube_radius=0.1, line_width=1, figure=fig1)
#mlab.orientation_axes()
mlab.view(azimuth=180, elevation=70, focalpoint=[ 12.0909996 , -1.04700089, -2.03249991], distance=60.0, figure=fig1)
return fig1
def plot_correspondences(model, uv, x, pi):
y = model(uv).detach().squeeze().cpu().numpy()
from mayavi import mlab
mlab.figure(bgcolor=(1, 1, 1))
mlab.points3d(x[:, 0], x[:, 1], x[:, 2], color=(1, 0, 0), scale_factor=0.01)
mlab.points3d(y[:, 0], y[:, 1], y[:, 2], color=(0, 1, 0), scale_factor=0.01)
x = x[pi].detach().squeeze().cpu().numpy()
for i in range(x.shape[0]):
lx = [x[i, 0], y[i, 0]]
ly = [x[i, 1], y[i, 1]]
lz = [x[i, 2], y[i, 2]]
mlab.plot3d(lx, ly, lz, color=(0.1, 0.1, 0.1), tube_radius=None)
mlab.show()