def test_generate_RW(): t = np.arange(0., 1E2) tau = 300 z = 2.0 rng = np.random.RandomState(0) xmean = rng.rand(1) * 200 - 100 N = len(t) y = generate_damped_RW(t, tau=tau, z=z, xmean=xmean, random_state=rng) assert_(len(generate_damped_RW(t)) == N) assert_almost_equal(np.mean(y), xmean, 0)
def test_generate_RW(): t = np.arange(0., 1E2) tau = 300 z = 2.0 rng = np.random.RandomState(0) xmean = rng.rand(1)*200 - 100 N = len(t) y = generate_damped_RW(t, tau=tau, z=z, xmean=xmean, random_state=rng) assert_(len(generate_damped_RW(t)) == N) assert_almost_equal(np.mean(y), xmean, 0)
def generate_mock_lightcurve(self, tau, c, time, signal, z, random_state=np.random.RandomState(0)): time_res = time / (1 + z) time_res_cont = np.linspace(min(time_res), max(time_res), int(max(time_res) - min(time_res))) xmean = np.mean(signal) SFinf = np.sqrt(c * tau / 2.) lightcurve_DRW_res_cont = generate_damped_RW(time_res_cont, tau, z, xmean=xmean, SFinf=SFinf, random_state=random_state) lightcurve_DRW_res = np.interp(time_res, time_res_cont, lightcurve_DRW_res_cont) lightcurve_DRW_obs = lightcurve_DRW_res #lightcurve_DRW_obs = lightcurve_DRW_res_cont #time = time_res_cont*(1+z) return time, lightcurve_DRW_obs
# result in an error if LaTeX is not installed on your system. In that case, # you can set usetex to False. from astroML.plotting import setup_text_plots setup_text_plots(fontsize=8, usetex=True) #------------------------------------------------------------ # Generate time-series data: # we'll do 1000 days worth of magnitudes t = np.arange(0, 1E3) z = 2.0 tau = 300 tau_obs = tau / (1. + z) np.random.seed(6) y = generate_damped_RW(t, tau=tau, z=z, xmean=20) # randomly sample 100 of these ind = np.arange(len(t)) np.random.shuffle(ind) ind = ind[:100] ind.sort() t = t[ind] y = y[ind] # add errors dy = 0.1 y_obs = np.random.normal(y, dy) #------------------------------------------------------------ # compute ACF via scargle method
print('Xmean =', xmean) print('tau =', tau, 'day') print('zs =', zs) print('SFinf =', '{0:.3f}'.format(SFinf)) print('sn =', sn) #t_drive = np.arange(ti, tf, dt) t_drive = np.arange(ti, tf + dt, dt) n = 5 t_drive1 = t_drive + n t_drive2 = t_drive + n * 2 t_drive3 = t_drive + n * 3 f_drive = generate_damped_RW(t_drive, tau=tau, z=zs, SFinf=SFinf, xmean=xmean) f_drive = abs(f_drive) mean = np.mean(f_drive) std = np.std(f_drive) print('Light Curve:', 'from', ti, 'to', tf, 'days') print('mean =', '{0:.3f}'.format(mean), 'std =', '{0:.3f}'.format(std)) fn = stem_out + '/' + fn #np.savetxt(fn,np.array([t_drive, f_drive]).T,fmt='%f') plt.plot(t_drive, f_drive, color='black', label='DRW')
# you can set usetex to False. from astroML.plotting import setup_text_plots setup_text_plots(fontsize=8, usetex=True) #------------------------------------------------------------ # Generate time-series data: # we'll do 1000 days worth of magnitudes t = np.arange(0, 1E3) z = 2.0 tau = 300 tau_obs = tau / (1. + z) np.random.seed(6) y = generate_damped_RW(t, tau=tau, z=z, xmean=20) # randomly sample 100 of these ind = np.arange(len(t)) np.random.shuffle(ind) ind = ind[:100] ind.sort() t = t[ind] y = y[ind] # add errors dy = 0.1 y_obs = np.random.normal(y, dy) #------------------------------------------------------------ # compute ACF via scargle method
def gen_DRW_long_DRM(seed, real_lag=100, dmag=0.5, time_range=2000, dtime=2, mag=19.5, errmag1=0.01, errmag2=0.03, tau=400, SFinf=0.2, sampling=False, timesamp1=0.0, timesamp2=0.0): #function to generate two light curves with the same DRW model, for a given tau and sigma, and a given time lag #seed: needed to avoid problems in the random number generation when the method is used with multiprocessing #recomended values: #time_range=2000 light curve length #dtime=2 candence #mag=19.5 mean magnitude #errmag=0.03 photometric error #tau=400 tau for the DRW model #SFinf=0.2 amplitude of the variability at long time scales #sampling: True if you are using the sampling of a given light curve. False if you whant a regularly sampled light curve #timesamp: if sampling is True, timesamp is the array with the JDs of the desired light curve. tbase = 36500 dtbase = 1 t_drwbase = np.arange(0, tbase, dtbase) #t_drw=np.arange(0,time_range,dtime) np.random.seed(int((time.clock() + seed))) #np.random.seed(int(seed)) #sigma=SFinf*np.sqrt(2.0/tau) #y = mag + cm.carma_process(t_drw, sigma, np.atleast_1d(-1.0 / tau),ma_coefs=[1.0]) #generating clean light curve y = generate_damped_RW(t_drwbase, tau, z=0, SFinf=SFinf, xmean=mag) ysig = np.zeros( len(y)) #array with ceros for the clean light curve photometric errors #adding noise to the clean light curve ysig_obs1 = np.ones(len(y)) * errmag1 y_obs1 = y + np.random.normal(0., np.random.normal(errmag1, 0.005), len(y)) #np.random.normal(y, errmag) ysig_obs2 = np.ones(len(y)) * errmag2 y_obs2 = y + np.random.normal(0., np.random.normal(errmag2, 0.005), len(y)) #np.random.normal(y, errmag) #plt.plot(t_drwbase,y,'b.') #plt.xlabel('days') #plt.ylabel(r'mag') #plt.xlim(0,36500) #plt.savefig('long_lc.pdf') #plt.show() if sampling: timesamp1 = np.round(timesamp1, decimals=0).astype(np.int) tstar = np.random.randint(14600, tbase - np.int( (timesamp1[-1] - timesamp1[0])), size=1) t_drw1 = tstar + ((timesamp1 - timesamp1[0])) timesamp2 = np.round(timesamp2, decimals=0).astype(np.int) t_drw2 = tstar + ((timesamp2 - timesamp2[0])) - real_lag #print t_drw y = y[t_drw1] ysig = ysig[t_drw1] ysig_obs1 = ysig_obs1[t_drw1] y_obs1 = y_obs1[t_drw1] t_drw1 = t_drw1 - t_drw1[0] ysig_obs2 = ysig_obs2[t_drw2] y_obs2 = y_obs2[t_drw2] - dmag t_drw2 = t_drw2 - t_drw2[0] else: tstar = np.random.randint(14600, tbase - time_range, size=1) tend = tstar + time_range t_drw1 = np.arange(tstar, tend, dtime) t_drw2 = np.arange(tstar - real_lag, tend - real_lag, dtime) y = y[t_drw1] ysig = ysig[t_drw1] ysig_obs1 = ysig_obs1[t_drw1] y_obs1 = y_obs1[t_drw1] t_drw1 = t_drw1 - t_drw1[0] ysig_obs2 = ysig_obs2[t_drw2] y_obs2 = y_obs2[t_drw2] - dmag t_drw2 = t_drw2 - t_drw2[0] ''' plt.errorbar(t_drw1,y_obs1,yerr=ysig_obs1,fmt='b*') plt.errorbar(t_drw2,y_obs2,yerr=ysig_obs2,fmt='ro') plt.xlabel('days') plt.ylabel(r'mag') #plt.savefig('final_lc_noise.pdf') plt.show() ''' return (t_drw1, y_obs1, ysig_obs1, t_drw2, y_obs2, ysig_obs2)
pox = 10 # coordinates to plot the name of the light curve poy = 0.15 #conversions c = 299792458 * 100 #c in cmeters days = (60 * 60 * 24) #to transform to days lmin = -(pix / 2.0) # centerx = totalpixel/2.0 lmax = (pix / 2.0) # centery = totalpixel/2.0 SF = (fraV / np.sqrt(2.0)) # Structure funciton at infinity -> default = 0.3 #******************************** # Damped Random Walk # #******************************** t = np.arange(0, time) y = generate_damped_RW(t, tau=tau, z=zs, random_state=ranst, SFinf=SF) #******************************** # Accretion disk model # #******************************** def sb2d(lamb, Mbh, LLE, n, zs, alf, lmin, lmax, step, pa, inc, norm, size): R0 = (9.7e15 * ((1.0 / (1.0 + zs)) * (lamb))**(4.0 / 3.0) * (Mbh / 10**9)**(2.0 / 3.0) * (LLE / n)**(1.0 / 3.0)) Rcod = size * R0 R0p = (Rcod / norm) # G = 6.67e-11 #m**3 kg**-1 s-2 # c = 299792458 #m/s # Rin = ((alf * G * Mbh*1.989e30)/c**2) * 100 #1msun = 1.989e30kg # Rinp = R0p/100.0
def compute_AF(): from astroML.time_series import lomb_scargle, generate_damped_RW from astroML.time_series import ACF_scargle, ACF_EK #---------------------------------------------------------------------- # This function adjusts matplotlib settings for a uniform feel in the textbook. # Note that with usetex=True, fonts are rendered with LaTeX. This may # result in an error if LaTeX is not installed on your system. In that case, # you can set usetex to False. from astroML.plotting import setup_text_plots setup_text_plots(fontsize=8, usetex=False) #------------------------------------------------------------ # Generate time-series data: # we'll do 1000 days worth of magnitudes t = np.arange(0, 1E3) z = 2.0 tau = 300 tau_obs = tau / (1. + z) np.random.seed(6) y = generate_damped_RW(t, tau=tau, z=z, xmean=20) # randomly sample 100 of these ind = np.arange(len(t)) np.random.shuffle(ind) ind = ind[:100] ind.sort() t = t[ind] y = y[ind] # add errors dy = 0.1 y_obs = np.random.normal(y, dy) #------------------------------------------------------------ # compute ACF via scargle method C_S, t_S = ACF_scargle(t, y_obs, dy, n_omega=2 ** 12, omega_max=np.pi / 5.0) ind = (t_S >= 0) & (t_S <= 500) t_S = t_S[ind] C_S = C_S[ind] #------------------------------------------------------------ # compute ACF via E-K method C_EK, C_EK_err, bins = ACF_EK(t, y_obs, dy, bins=np.linspace(0, 500, 51)) t_EK = 0.5 * (bins[1:] + bins[:-1]) #------------------------------------------------------------ # Plot the results fig = plt.figure(figsize=(5, 5)) # plot the input data ax = fig.add_subplot(211) ax.errorbar(t, y_obs, dy, fmt='.k', lw=1) ax.set_xlabel('t (days)') ax.set_ylabel('observed flux') # plot the ACF ax = fig.add_subplot(212) ax.plot(t_S, C_S, '-', c='gray', lw=1, label='Scargle') ax.errorbar(t_EK, C_EK, C_EK_err, fmt='.k', lw=1, label='Edelson-Krolik') ax.plot(t_S, np.exp(-abs(t_S) / tau_obs), '-k', label='True') ax.legend(loc=3) ax.plot(t_S, 0 * t_S, ':', lw=1, c='gray') ax.set_xlim(0, 500) ax.set_ylim(-1.0, 1.1) ax.set_xlabel('t (days)') ax.set_ylabel('ACF(t)') plt.show()