from IPython.parallel import Client from IPython.utils.path import get_ipython_dir ipython_dir = get_ipython_dir() PROFILE = 'parallel' rc = Client(ipython_dir+'/profile_%s/security/ipcontroller-client.json' % PROFILE) dview = rc[:] dview.block = True rc.ids %run -i load_bromo.py %px %reset # Not needed on the first excution # Send a variable containing the engine ID to each engine dview.scatter('eid', rc.ids, flatten=True) %px eid %%px import os if os.name == 'posix': BROWN_DIR = "/home/anto/Documents/ucla/src/brownian/" elif os.name == 'nt': BROWN_DIR = r"C:/Data/Antonio/software/Dropbox/brownian/" %%px %cd $BROWN_DIR %px run -i brownian.py %%px S = load_sim_id(ID=1, glob_str="*t_max10.0s*", dir_=SIM_DATA_DIR) run -i brownian.py ph_times_d, t_tot, sim_name = parallel_gen_timetag(dview, max_em_rate=1e6, bg_rate=2e3) ph_times_a, t_tot, sim_name = parallel_gen_timetag(dview, max_em_rate=5e5, bg_rate=4e3) ph_times, a_em = merge_DA_ph_times(ph_times_d, ph_times_a) (ph_times_d == ph_times[-a_em]).all() (ph_times_a == ph_times[a_em]).all() ph_times.size == ph_times_d.size+ph_times_a.size == a_em.size k = 5e5/1e6 E = k/(k+1) print "%.1f%%" % (E*100) import numpy as np EM = np.r_[10,20:201:20, 190]*1e3 #EM = np.r_[90,99,101,110]*1e3 print EM BG = np.r_[1:7,8]*1e3 print BG print EM[None,:].shape, BG.shape # Compute any possible k and E M = np.dot(EM[:,None],1/EM[None,:]) k = np.sort(M.ravel()) E = k/(k+1) M.shape %pylab inline plot(E, '.') title("Check how many E values are possible"); def gen_tot_sim_name(Sim_names): """Conatenates with '+' the ID of strings in `Sim_names`. Assumes all the string be the same except for a one-digit ID. Example: gen_tot_sim_name(['_ID0','_ID1']) returns '_ID0+1' """ IDs = [] for s in Sim_names: n = s.find('_ID') + 3 IDs.append(s[n]) name = Sim_names[0][:n] + '+'.join(IDs) + Sim_names[0][n+1:] return name gen_tot_sim_name(['pippo_ID0_pluto','pippo_ID1_pluto', 'pippo_ID2_pluto']) def gen_ph_times_name(em, bg, sim_name, t_tot): """Generate a name for a timestamp array """ EM_str = "%04d" % (em/1e3) BG_str = "%04.1f" % (bg/1e3) fname = "ph_times_{t}s_{sim}_EM{em}kHz_BG{bg}kHz.npy".format( em=EM_str, bg=BG_str, t=t_tot, sim=sim_name) return fname gen_ph_times_name(5e5, 3e3, 'pippo', 10.) #%qtconsole %%timeit -n1 -r1 IDs = [1, 2, 3, 4, 5, 6] for bg in BG: for em in EM: ph_list = [] t_tot_tot = 0 Sim_name = [] for ID in IDs: dview['ID'] = ID %px S = load_sim_id(ID=ID, glob_str="*t_max10.0s*", dir_=SIM_DATA_DIR) ph, t_tot, sim_name = parallel_gen_timetag(dview, max_em_rate=em, bg_rate=bg) ph_list.append(ph) t_tot_tot += t_tot Sim_name.append(sim_name) # Use last sim `t_tot` to set time_block ph_times = merge_ph_times(ph_list, time_block=t_tot) tot_sim_name = gen_tot_sim_name(Sim_name) fname = gen_ph_times_name(em, bg, tot_sim_name, t_tot_tot) ph_times.dump(SIM_PH_DIR+fname) del ph_times plt.hist(ph_times, bins=arange(0,0.5,1e-3), histtype='step'); d_EM_kHz = 400. d_BG_kHz = 4 a_EM_kHz = 200 a_BG_kHz = 2 FRET_val = 1.*a_EM_kHz/(a_EM_kHz+d_EM_kHz) print "Simulated FRET value: %.2f" % FRET_val # These are used for the file name ID = '0+1+2' t_tot = '0.6' # These are metadata associated to the timestamps t_step = 0.5e-6 clk_p = t_step/32. # with t_step=0.5us -> 156.25 ns d_EM_kHz_str = "%04d" % d_EM_kHz a_EM_kHz_str = "%04d" % a_EM_kHz d_BG_kHz_str = "%04.1f" % d_BG_kHz a_BG_kHz_str = "%04.1f" % d_BG_kHz print "D: EM %s BG %s "%(d_EM_kHz_str,d_BG_kHz_str) print "A: EM %s BG %s "%(a_EM_kHz_str,a_BG_kHz_str) fname_d = "ph_times_{t_tot}s_D1.2e-11_10P_21pM_step0.5us_ID{ID}_EM{em}kHz_BG{bg}kHz.npy".format(em=d_EM_kHz_str, bg=d_BG_kHz_str, t_tot=t_tot, ID=ID) fname_a = "ph_times_{t_tot}s_D1.2e-11_10P_21pM_step0.5us_ID{ID}_EM{em}kHz_BG{bg}kHz.npy".format(em=a_EM_kHz_str, bg=a_BG_kHz_str, t_tot=t_tot, ID=ID) print fname_d print fname_a SIM_PH_DIR ph_times_d = numpy.load(SIM_PH_DIR+fname_d) ph_times_a = numpy.load(SIM_PH_DIR+fname_a) ph_times, a_em = merge_DA_ph_times(ph_times_d, ph_times_a) ph_times_int = (ph_times/clk_p).astype('int64') from IPython.core.display import HTML def css_styling(): styles = open("./styles/custom2.css", "r").read() return HTML(styles) css_styling()