clag-agn/scripts/psdlag_4bin.py

103 lines
1.9 KiB
Python
Raw Normal View History

2017-06-22 10:19:42 +00:00
#!/usr/bin/env python
2017-06-22 10:10:46 +00:00
import numpy as np
from scipy.stats import norm
from scipy.stats import lognorm
import sys
import getopt
sys.path.insert(1,"/usr/local/science/clag-agn/data/")
import clag
import matplotlib
# %pylab inline
2017-06-22 10:19:42 +00:00
#ref_file="data/lc/1367A.lc"
#echo_file="data/lc/2246A.lc"
2017-06-22 10:10:46 +00:00
2017-06-22 10:19:42 +00:00
ref_file = str(sys.argv[1])
echo_file = str(sys.argv[2])
2017-06-22 10:10:46 +00:00
dt = 0.01
t1, l1, l1e = np.loadtxt(ref_file).T
# errorbar(t1, l1, yerr=l1e, fmt='o')
2017-06-22 12:11:27 +00:00
#A
#fqL = np.logspace(np.log10(0.005),np.log10(0.6),5)
#B
#fqL = np.array([0.0049999999, 0.018619375, 0.069336227,
# 0.10747115, 0.62032418])
2017-06-22 10:10:46 +00:00
2017-06-22 12:11:27 +00:00
#C
2017-06-22 13:28:23 +00:00
#fqL = np.array([0.0049999999, 0.044733049, 0.10747115,
# 0.22, 0.56])
#D
2017-06-22 21:09:08 +00:00
fqL = [0.0049999999] + np.logspace(np.log10(0.02999999),np.log10(0.340002000),5)
2017-06-22 10:10:46 +00:00
nfq = len(fqL) - 1
fqd = 10**(np.log10( (fqL[:-1]*fqL[1:]) )/2.)
P1 = clag.clag('psd10r', [t1], [l1], [l1e], dt, fqL)
p1 = np.ones(nfq)
p1, p1e = clag.optimize(P1, p1)
p1, p1e = clag.errors(P1, p1, p1e)
ref_psd = p1
ref_psd_err = p1e
t2, l2, l2e = np.loadtxt(echo_file).T
P2 = clag.clag('psd10r', [t2], [l2], [l2e], dt, fqL)
p2 = np.ones(nfq)
p2, p2e = clag.optimize(P2, p2)
p2, p2e = clag.errors(P2, p2, p2e)
echo_psd = p2
echo_psd_err = p2e
2017-06-22 12:11:27 +00:00
Cx = clag.clag('cxd10r',
[[t1,t2]],
[[l1,l2]],
[[l1e,l2e]],
dt, fqL, p1, p2)
# a good starting point generally
p = np.concatenate( ((p1+p2)*0.5-0.3,p1*0+0.1) )
2017-06-22 10:10:46 +00:00
p, pe = clag.optimize(Cx, p)
2017-06-22 19:50:30 +00:00
p, pe = clag.errors(Cx, p, pe)
2017-06-22 10:10:46 +00:00
phi, phie = p[nfq:], pe[nfq:]
lag, lage = phi/(2*np.pi*fqd), phie/(2*np.pi*fqd)
cx, cxe = p[:nfq], pe[:nfq]
2017-06-22 12:11:27 +00:00
crs_spectrm = cx
crs_spectrm_err = cxe
2017-06-22 10:10:46 +00:00
s, loc, scale = lognorm.fit(lag,loc=.01)
np.savetxt("freq.out",fqL.reshape((-1,len(fqL))))
np.savetxt("ref_psd.out",[ref_psd,ref_psd_err])
np.savetxt("echo_psd.out",[echo_psd,echo_psd_err])
2017-06-22 12:11:27 +00:00
np.savetxt("crsspctrm.out",[crs_spectrm,crs_spectrm_err])
np.savetxt("lag.out",[lag,lage])