示例#1
0
       coord=(1, 2),
       f=3,
       comment_char='%',
       weather='clear and sunny')
print(d)
# note that the coord_unit is left empty as none was specified
# in the attributes when calling load
d.annotations('coord_unit', 'pxl')

d.time(0.1045, 's')
# print some elements of the trajectory
print(d.t(0, 1, len(d) - 1))
print(d.start())
print(d.end())

print(d.coord(range(0, 10)))

# the trajectory lifetime
print(d.lifetime())

#fill the missing frames
print(max([d.frames(i) - d.frames(i - 1) for i in range(1, len(d))]))
# there are some missing frames, let's fill them:
d.fill()
print(max([d.frames(i) - d.frames(i - 1) for i in range(1, len(d))]))

d.save('my_first_trajectory')  #save our trajectory, as a .txt file:

# move the trajectory to its center of mass
d.translate(-d.center_mass())
示例#2
0
#plot the average saved in 'median.txt' and all the trajectories
#saved in 'median' folder.

trj = Traj()
trj.load('median.txt')

files = os.listdir('median')

plt.figure(1, figsize=(10, 8))

for f in files:
    t = Traj()
    t.load('median/' + f)

    plt.plot(t.t() - trj.start(), t.coord()[0], '-')

plt.plot(trj.t() - trj.start(), trj.coord()[0], 'w-', linewidth=5.5)
plt.plot(trj.t() - trj.start(),
         trj.coord()[0],
         'k-',
         linewidth=3,
         label='Average trajectory')

plt.xlim([-0.5, trj.end() - trj.start() + 0.5])
plt.ylim([-1, 3.2])

plt.ylabel('Inward movement (' + trj.annotations('coord_unit') + ')',
           fontsize=24)
plt.xlabel('Time (' + trj.annotations('t_unit') + ')', fontsize=24)
plt.title(str(len(files)) +