def make_disp_sq_plots(comp_key,conn): """Takes in a comp_key for a track_stat computation and plots the square displacement histograms""" (fin,) = conn.execute("select fout from comps where function = 'track_stats' and comp_key = ?", (comp_key,)).fetchone() F = h5py.File(fin,'r') g = F[_fd('disp_sq_hist',comp_key)] cmap = color_mapper(0,len(g)) (fig,ax) = plots.set_up_plot() istatus = plots.non_i_plot_start(); for s in g: step = int(s[-7:]) val = g[s]['bin_value'][:] ax.semilogy(g[s]['bin_edges'],val,color = cmap.get_color(step)) F.close() (iden_fun,dset_key ) = conn.execute("select function,dset_key from comps where " + "comp_key in " + "(select iden_key from trk_stat_prams where "+ "comp_key = ?)",(comp_key,)).fetchone() ax.set_title("dset: " + str(dset_key) + " " + iden_fun) plots.non_i_plot_stop(istatus)
def planet_dynamics(horizon, step, make_plot=True): delta_in_sec = step * days_to_sec # define your planets here planets = [static_sun("1"), planet("2", R_sun, M_earth, D_earth_sun, 0.0, 0.0, 0.0, V_earth, 0.0)] x, y, z = [[]], [[]], [[]] set_up_positions(x, y, z, len(planets)) lines = [] if make_plot: set_up_plot(lines, x, y, z, planets) total_time = 0 # in years while total_time <= horizon: print("Time (in y): ", total_time, " --- Number of planets: ", len(planets)) for p in planets: p.report() append_positions(x, y, z, planets) if make_plot: update_plot(lines, x, y, z, planets, total_time) compute_accelerations(planets) for p in planets: p.update_velocity(delta_in_sec) p.update_position(delta_in_sec) # planets = check_for_colliding_planets(planets) total_time += step * days_to_years # in years if make_plot: plt.show() return x, y, z
def plot_tracks(tracks): """ Takes in a """ print len(tracks) # set up figure (fig,ax) = plots.set_up_plot() init_frame = np.min([t.start_frame for t in tracks]) ax.set_title(' frame: ' + str(init_frame) + ' dtime: ' + str(tracks.dtime) + 'ms') def trk_len_hash(trk): return len(trk) def trk_disp_hash(trk): return np.sqrt((np.sum(np.array(trk[-1]) - np.array(trk[0]))**2)) trk_hash = trk_len_hash t_len = [trk_hash(trk) for trk in tracks] cm = plots.color_mapper(min(t_len),max(t_len)) print (min(t_len),max(t_len)) # loop over tracks and plot [ax.plot(np.array([t[0] for t in trk.positions])*tracks.sp_scale, np.array([t[1] for t in trk.positions])*tracks.sp_scale, '-', color=cm.get_color(trk_hash(trk))) for trk in tracks] x,y,I = zip(*[trk.positions[0] for trk in tracks]) # plot the starting points ax.plot(np.array(x)*tracks.sp_scale, np.array(y)*tracks.sp_scale,'xk') ax.set_aspect('equal') plt.draw()