%run -i load_bromo.py %run brownian.py # Initialize the random seed to a fixed value (for notebook reproducibility) np.random.seed(6) # Simulation time step t_step = 0.5e-6 # seconds # Time duration of the simulation t_max = .2 # seconds # Particles definition P = gen_particles(2, box) # Particle simulation definition S = ParticlesSimulation(D=D, t_step=t_step, t_max=t_max, particles=P, box=box, psf=psf) S S.print_RAM() S.sim_motion_em(total_emission=True, delete_pos=False) # This requires delete_pos=False in .sim_motion_em() plot_tracks(S) plot_emission(S) S.sim_timetrace(max_em_rate=3e5, bg_rate=2e3) plot_timetrace(S, scroll_gui=False) plt.legend(['Emission rate', 'Emitted photons + BG']) S.gen_ph_times() print S.ph_times[:10], '...' plt.hist(S.ph_times, bins=np.r_[:200]*1e-3, histtype='step'); # Binning of timestamps timestamps_hist = np.histogram(S.ph_times, bins=np.r_[:201]*1e-3) # Rebinning of timetrace rebin = 2000 rebinned_timetrace = S.tt.reshape(-1, rebin).sum(axis=1) rebinned_time = (np.arange(rebinned_timetrace.size)+1)*(S.t_step*rebin) # Comparison plot plt.plot(timestamps_hist[1][1:], timestamps_hist[0]) plt.plot(rebinned_time, rebinned_timetrace) # Rigorous check assert ((timestamps_hist[0] - rebinned_timetrace) == 0).all() S.dump(dir_=SIM_DATA_DIR) S2 = load_sim_id(ID=0, EID=0, glob_str='*0.2s*', dir_=SIM_DATA_DIR) S2 S2.em print id(S2.em), id(S.em) (S.em == S2.em).all() from IPython.core.display import HTML def css_styling(): styles = open("./styles/custom2.css", "r").read() return HTML(styles) css_styling()