diff --git a/zoghbi_jupyter.html b/zoghbi_jupyter.html new file mode 100644 index 0000000..7dfac28 --- /dev/null +++ b/zoghbi_jupyter.html @@ -0,0 +1,1860 @@ + + + +example + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+
+
+
+
    +
  • First, we load numpy as the clag package. pylab is for plotting
  • +
+ +
+
+
+
+
+
In [10]:
+
+
+
import numpy as np
+import clag
+%pylab inline
+
+ +
+
+
+ +
+
+ + +
+
+
Populating the interactive namespace from numpy and matplotlib
+
+
+
+ +
+
+ +
+
+
+
+
+
+
    +
  • Now, we read the first light curve. e.g. 1367A.dat, and plot it
  • +
+ +
+
+
+
+
+
In [2]:
+
+
+
dt = 0.01
+t1, l1, l1e = np.loadtxt('1367A.dat').T
+errorbar(t1, l1, yerr=l1e, fmt='o')
+
+ +
+
+
+ +
+
+ + +
Out[2]:
+ + +
+
<Container object of 3 artists>
+
+ +
+ +
+ + +
+ +
+ +
+ +
+
+ +
+
+
+
+
+
+
    +
  • Here, we define the frequency bins in fqL. Here, I use the ones that Ed sent.
  • +
  • A general rules for fqL is as follows:

    +
      +
    • define $f_1$, $f_2$ as the two extreme frequencies allowed by the data. i.e. $f_{1} = 1/T$ with $T$ being the length of observation in time units, and $f_{2} = 0.5/\Delta t$
    • +
    • The frequency limits where the psd/lag can be constrained are about ~$0.9f_1 - 0.5f_2$. The 0.9 factor doesn't depend on the data much, but values in the range ~[0.9-1.1] are ok. The factor in front of $f_2$ depends on the quality of the data, for low qualily data, use ~0.1--0.2, and for high quality data, increase it up to $0.9--1$.
    • +
    • Always include two dummy bins at the low and high frequencies and ignore them. The first and last bins are generally biased, So I suggest using the first bin as $0.5f_1 - 0.9 f_1$ (or whatever value you use instead of $0.9 f_1$, see second point above), and the last bin should be $0.5f_2-2*f_2$ (or whatever value instead of $0.5f_2$, see second point above). So the frequency bins should be something like: $[0.5f_1, 0.9f_1, ..., 0.5f_2, 2f_2]$, the bins in between can be devided as desired.
    • +
    +
  • +
  • fqd is the bin center

    +
  • +
+ +
+
+
+
+
+
In [5]:
+
+
+
fqL = np.array([0.0049999999, 0.018619375, 0.044733049, 0.069336227, 0.10747115, 0.16658029, 
+                0.25819945, 0.40020915, 0.62032418])
+nfq = len(fqL) - 1
+fqd = 10**(np.log10( (fqL[:-1]*fqL[1:]) )/2.)
+
+ +
+
+
+ +
+
+
+
+
+
+
    +
  • We create a psd class of type psd10r (i.e. psd in log10 units using the rms normalization, see tutorial of clag for more). Other paramters are given as a list of: time, light curve, error. If you want to fit more than one light curve together, give them as elements of that list.
  • +
  • p1 is an array of the starting parameters
  • +
  • We then call clag.optimize to find the best fit. It takes as parameters, the class of psd or lag, the starting paramters, plus some other parameters whose default values work in most cases. The function returns a tuple of two arrays: the best fit values, and the estimated errors from the Fisher matrix (i.e. approximate errors).
  • +
  • As the fit starts, progress is printed, where for every line, we print: num_of_iteration, max change in parameter values, maximum gradient, change in loglikelihood -- loglikelihood -- list of parameters.
  • +
  • The fit stops when either of the three numbers after iter_number is close to zero.
  • +
  • At the end, the function prints the best fit values, their estimated error and the gradient of the loglikelihood at the those values. For the fit to be valid, the gradient values need to be all close to zero
  • +
+ +
+
+
+
+
+
In [6]:
+
+
+
P1 = clag.clag('psd10r', [t1], [l1], [l1e], dt, fqL)
+p1 = np.ones(nfq)
+p1, p1e = clag.optimize(P1, p1)
+
+ +
+
+
+ +
+
+ + +
+
+
   1 4.342e-01 5.106e+01 inf -- 4.956e+03 -- 1 1 1 1 1 1 1 1
+   2 7.673e-01 5.094e+01 8.346e+01 -- 5.040e+03 -- 0.652988 0.587584 0.568433 0.567574 0.566292 0.566106 0.565781 0.566166
+   3 3.298e+00 5.072e+01 8.117e+01 -- 5.121e+03 -- 0.414769 0.211226 0.141674 0.138242 0.133442 0.132793 0.131633 0.132768
+   4 1.606e+00 5.040e+01 7.791e+01 -- 5.199e+03 -- 0.322796 -0.0775344 -0.271946 -0.283286 -0.297439 -0.299306 -0.302453 -0.300418
+   5 5.910e-01 4.995e+01 7.424e+01 -- 5.273e+03 -- 0.303931 -0.202072 -0.653233 -0.686827 -0.723408 -0.72915 -0.736445 -0.733984
+   6 3.715e-01 4.907e+01 6.996e+01 -- 5.343e+03 -- 0.288563 -0.184901 -0.963027 -1.05215 -1.1374 -1.1547 -1.17045 -1.16777
+   7 2.711e-01 4.699e+01 6.310e+01 -- 5.406e+03 -- 0.283941 -0.171583 -1.13016 -1.33783 -1.52092 -1.56818 -1.60449 -1.60156
+   8 2.136e-01 4.393e+01 5.315e+01 -- 5.459e+03 -- 0.284478 -0.172961 -1.16497 -1.49243 -1.8324 -1.94693 -2.03753 -2.03567
+   9 1.766e-01 3.793e+01 4.044e+01 -- 5.500e+03 -- 0.290936 -0.172461 -1.18193 -1.52814 -2.02019 -2.2443 -2.46546 -2.47059
+  10 1.511e-01 2.754e+01 2.660e+01 -- 5.526e+03 -- 0.299556 -0.170594 -1.19171 -1.52653 -2.09181 -2.40938 -2.87374 -2.90691
+  11 1.353e-01 1.473e+01 1.395e+01 -- 5.540e+03 -- 0.304466 -0.168829 -1.1936 -1.52541 -2.11411 -2.46428 -3.22352 -3.34602
+  12 1.365e-01 5.346e+00 5.391e+00 -- 5.546e+03 -- 0.306641 -0.168375 -1.1943 -1.52526 -2.12385 -2.4831 -3.45563 -3.7987
+  13 1.885e-01 1.315e+00 1.631e+00 -- 5.547e+03 -- 0.308259 -0.168765 -1.19466 -1.52395 -2.12898 -2.49063 -3.54795 -4.31734
+  14 6.419e-01 2.826e-01 4.459e-01 -- 5.548e+03 -- 0.309635 -0.169217 -1.19466 -1.52209 -2.1316 -2.49271 -3.56156 -5.13117
+  15 3.621e+02 2.692e-01 6.760e-02 -- 5.548e+03 -- 0.310493 -0.16946 -1.19426 -1.52073 -2.13283 -2.49296 -3.55956 -8.13117
+  16 6.745e-03 2.804e-01 2.200e-04 -- 5.548e+03 -- 0.310716 -0.169438 -1.1942 -1.52027 -2.1332 -2.49291 -3.55848 -11.1312
+  17 9.379e-04 3.668e-02 3.808e-03 -- 5.548e+03 -- 0.310697 -0.169463 -1.19426 -1.52034 -2.13364 -2.49379 -3.58248 -11.1312
+  18 1.196e-04 4.629e-03 7.714e-05 -- 5.548e+03 -- 0.310559 -0.169401 -1.1944 -1.52053 -2.13373 -2.49422 -3.58584 -11.1312
+********************
+0.310559 -0.169401 -1.1944 -1.52053 -2.13373 -2.49422 -3.58584 -11.1312
+0.23823 0.201724 0.232207 0.17655 10 0.132676 0.306008 10
+-0.000242823 -0.000294102 -0.000203858 -0.0012519 -1.17839e-06 -0.00320256 -0.00462885 -1.49854e-07
+********************
+
+
+
+ +
+
+ +
+
+
+
+
+
+
    +
  • We then call clag.errors to obtain the errors on the parameters. This steps over the parameters, allowing others to change, until the loglikelihood function changes by 1. This gives the 1-sigma error.
  • +
  • The errors can also be obtained using mcmc, though not directly implemeted in clag code, one can use other mcmc packages like emcee, and call the p1.loglikelihood function directly.
  • +
+ +
+
+
+
+
+
In [14]:
+
+
+
p1, p1e = clag.errors(P1, p1, p1e)
+
+ +
+
+
+ +
+
+ + +
+
+
	### errors for param 0 ###
++++ 5.548e+03 5.547e+03 3.105e-01 5.488e-01 0.876 +++
++++ 5.548e+03 5.547e+03 3.105e-01 6.679e-01 1.84 +++
++++ 5.548e+03 5.547e+03 3.105e-01 6.083e-01 1.32 +++
++++ 5.548e+03 5.547e+03 3.105e-01 5.786e-01 1.09 +++
++++ 5.548e+03 5.547e+03 3.105e-01 5.637e-01 0.981 +++
++++ 5.548e+03 5.547e+03 3.105e-01 5.711e-01 1.03 +++
++++ 5.548e+03 5.547e+03 3.105e-01 5.674e-01 1.01 +++
+	### errors for param 1 ###
++++ 5.548e+03 5.547e+03 -1.694e-01 3.231e-02 0.969 +++
++++ 5.548e+03 5.547e+03 -1.694e-01 1.332e-01 2.06 +++
++++ 5.548e+03 5.547e+03 -1.694e-01 8.274e-02 1.47 +++
++++ 5.548e+03 5.547e+03 -1.694e-01 5.753e-02 1.21 +++
++++ 5.548e+03 5.547e+03 -1.694e-01 4.492e-02 1.09 +++
++++ 5.548e+03 5.547e+03 -1.694e-01 3.862e-02 1.03 +++
++++ 5.548e+03 5.547e+03 -1.694e-01 3.546e-02 0.998 +++
+	### errors for param 2 ###
++++ 5.548e+03 5.547e+03 -1.194e+00 -9.622e-01 1.03 +++
++++ 5.548e+03 5.548e+03 -1.194e+00 -1.078e+00 0.277 +++
++++ 5.548e+03 5.548e+03 -1.194e+00 -1.020e+00 0.602 +++
++++ 5.548e+03 5.547e+03 -1.194e+00 -9.912e-01 0.805 +++
++++ 5.548e+03 5.547e+03 -1.194e+00 -9.767e-01 0.917 +++
++++ 5.548e+03 5.547e+03 -1.194e+00 -9.695e-01 0.975 +++
++++ 5.548e+03 5.547e+03 -1.194e+00 -9.658e-01   1 +++
+	### errors for param 3 ###
++++ 5.548e+03 5.547e+03 -1.521e+00 -1.344e+00 0.862 +++
++++ 5.548e+03 5.547e+03 -1.521e+00 -1.256e+00 1.85 +++
++++ 5.548e+03 5.547e+03 -1.521e+00 -1.300e+00 1.32 +++
++++ 5.548e+03 5.547e+03 -1.521e+00 -1.322e+00 1.08 +++
++++ 5.548e+03 5.547e+03 -1.521e+00 -1.333e+00 0.967 +++
++++ 5.548e+03 5.547e+03 -1.521e+00 -1.327e+00 1.02 +++
++++ 5.548e+03 5.547e+03 -1.521e+00 -1.330e+00 0.994 +++
+	### errors for param 4 ###
++++ 5.548e+03 5.547e+03 -2.134e+00 -1.981e+00 0.868 +++
++++ 5.548e+03 5.547e+03 -2.134e+00 -1.905e+00 1.9 +++
++++ 5.548e+03 5.547e+03 -2.134e+00 -1.943e+00 1.34 +++
++++ 5.548e+03 5.547e+03 -2.134e+00 -1.962e+00 1.09 +++
++++ 5.548e+03 5.547e+03 -2.134e+00 -1.971e+00 0.977 +++
++++ 5.548e+03 5.547e+03 -2.134e+00 -1.967e+00 1.03 +++
++++ 5.548e+03 5.547e+03 -2.134e+00 -1.969e+00 1.01 +++
+	### errors for param 5 ###
++++ 5.548e+03 5.547e+03 -2.494e+00 -2.362e+00 0.994 +++
+	### errors for param 6 ###
++++ 5.548e+03 5.547e+03 -3.586e+00 -3.280e+00 1.33 +++
++++ 5.548e+03 5.548e+03 -3.586e+00 -3.433e+00 0.275 +++
++++ 5.548e+03 5.547e+03 -3.586e+00 -3.357e+00 0.683 +++
++++ 5.548e+03 5.547e+03 -3.586e+00 -3.318e+00 0.974 +++
++++ 5.548e+03 5.547e+03 -3.586e+00 -3.299e+00 1.14 +++
++++ 5.548e+03 5.547e+03 -3.586e+00 -3.309e+00 1.06 +++
++++ 5.548e+03 5.547e+03 -3.586e+00 -3.314e+00 1.01 +++
++++ 5.548e+03 5.547e+03 -3.586e+00 -3.316e+00 0.994 +++
+	### errors for param 7 ###
++++ 5.548e+03 5.548e+03 -1.113e+01 -7.131e+00 0.0013 +++
++++ 5.548e+03 5.548e+03 -1.113e+01 -5.131e+00 0.134 +++
++++ 5.548e+03 5.547e+03 -1.113e+01 -4.131e+00 1.63 +++
++++ 5.548e+03 5.548e+03 -1.113e+01 -4.631e+00 0.451 +++
++++ 5.548e+03 5.547e+03 -1.113e+01 -4.381e+00 0.847 +++
++++ 5.548e+03 5.547e+03 -1.113e+01 -4.256e+00 1.17 +++
++++ 5.548e+03 5.547e+03 -1.113e+01 -4.319e+00 0.995 +++
+********************
+0.310547 -0.169411 -1.19441 -1.52057 -2.13373 -2.49427 -3.58627 -11.1312
+0.256842 0.204876 0.228579 0.190434 0.164654 0.132714 0.270338 6.8125
+********************
+
+
+
+ +
+
+ +
+
+
+
+
+
+
    +
  • Next we plot the results
  • +
+ +
+
+
+
+
+
In [76]:
+
+
+
xscale('log'); ylim(-4,2)
+errorbar(fqd, p1, yerr=p1e, fmt='o', ms=10)
+
+ +
+
+
+ +
+
+ + +
Out[76]:
+ + +
+
<Container object of 3 artists>
+
+ +
+ +
+ + +
+ +
+ +
+ +
+
+ +
+
+
+
In [ ]:
+
+
+
 
+
+ +
+
+
+ +
+
+
+
+
+
+
    +
  • Now, we load the second light curve and repeat the process for the second psd
  • +
+ +
+
+
+
+
+
In [15]:
+
+
+
t2, l2, l2e = np.loadtxt('3465A.dat').T
+errorbar(t1, l1, yerr=l1e, fmt='o')
+errorbar(t2, l2, yerr=l2e, fmt='o')
+
+ +
+
+
+ +
+
+ + +
Out[15]:
+ + +
+
<Container object of 3 artists>
+
+ +
+ +
+ + +
+ +
+ +
+ +
+
+ +
+
+
+
In [16]:
+
+
+
P2 = clag.clag('psd10r', [t2], [l2], [l2e], dt, fqL)
+p2 = np.ones(nfq)
+p2, p2e = clag.optimize(P2, p2)
+
+ +
+
+
+ +
+
+ + +
+
+
   1 4.365e-01 6.884e+01 inf -- 8.449e+03 -- 1 1 1 1 1 1 1 1
+   2 7.732e-01 6.807e+01 7.998e+01 -- 8.529e+03 -- 0.596599 0.573944 0.565249 0.565 0.564474 0.564973 0.565061 0.563513
+   3 3.405e+00 6.725e+01 7.864e+01 -- 8.607e+03 -- 0.244013 0.162113 0.130209 0.130066 0.128738 0.12957 0.129649 0.12783
+   4 3.360e+01 6.630e+01 7.669e+01 -- 8.684e+03 -- -0.00316365 -0.215478 -0.306172 -0.305067 -0.307606 -0.306662 -0.306644 -0.307445
+   5 5.927e-01 6.489e+01 7.427e+01 -- 8.758e+03 -- -0.109447 -0.516884 -0.745492 -0.740106 -0.744696 -0.743873 -0.743899 -0.742873
+   6 3.725e-01 6.264e+01 7.143e+01 -- 8.830e+03 -- -0.143959 -0.685712 -1.18731 -1.17268 -1.18226 -1.18223 -1.18216 -1.17875
+   7 2.746e-01 5.898e+01 6.767e+01 -- 8.897e+03 -- -0.172747 -0.736257 -1.61838 -1.59549 -1.61983 -1.6226 -1.62219 -1.61642
+   8 2.229e-01 5.247e+01 6.144e+01 -- 8.959e+03 -- -0.196816 -0.752482 -1.99672 -1.9902 -2.05709 -2.06672 -2.06649 -2.06028
+   9 1.956e-01 4.085e+01 5.100e+01 -- 9.010e+03 -- -0.215738 -0.754987 -2.24985 -2.31629 -2.49299 -2.51725 -2.52319 -2.51952
+  10 1.984e-01 2.411e+01 3.583e+01 -- 9.046e+03 -- -0.227795 -0.74941 -2.34289 -2.51344 -2.9179 -2.97306 -3.0163 -3.01235
+  11 2.720e-01 8.629e+00 1.877e+01 -- 9.064e+03 -- -0.232745 -0.745804 -2.36419 -2.5762 -3.29011 -3.40817 -3.61486 -3.58767
+  12 1.101e+00 1.216e+00 6.309e+00 -- 9.071e+03 -- -0.23497 -0.744449 -2.37685 -2.59225 -3.51955 -3.73121 -4.59808 -4.44993
+  13 5.958e+02 2.028e-01 8.420e-01 -- 9.072e+03 -- -0.236431 -0.743626 -2.38453 -2.60022 -3.56793 -3.8266 -7.59808 -7.44993
+  14 3.292e-02 2.270e-01 1.932e-03 -- 9.072e+03 -- -0.236741 -0.743691 -2.38524 -2.60077 -3.56246 -3.81667 -10.5981 -10.4499
+  15 2.277e-03 2.223e-02 1.569e-02 -- 9.072e+03 -- -0.237254 -0.744315 -2.3903 -2.60854 -3.6113 -3.94232 -10.5981 -10.4499
+  16 6.863e-04 3.008e-03 1.056e-04 -- 9.072e+03 -- -0.237548 -0.744546 -2.38911 -2.60708 -3.60308 -3.93728 -10.5981 -10.4499
+  17 1.050e-04 8.493e-04 4.548e-06 -- 9.072e+03 -- -0.237471 -0.744501 -2.3894 -2.60727 -3.60273 -3.93998 -10.5981 -10.4499
+********************
+-0.237471 -0.744501 -2.3894 -2.60727 -3.60273 -3.93998 -10.5981 -10.4499
+0.264343 0.221316 0.350826 0.274708 0.679297 0.951247 10 10
+-0.000202502 2.37574e-05 0.000349669 0.000703071 0.000849318 0.000211385 -6.22057e-07 -1.19394e-06
+********************
+
+
+
+ +
+
+ +
+
+
+
In [79]:
+
+
+
xscale('log'); ylim(-6,2)
+errorbar(fqd, p1, yerr=p1e, fmt='o', ms=10)
+errorbar(fqd, p2, yerr=p2e, fmt='o', ms=10)
+
+ +
+
+
+ +
+
+ + +
Out[79]:
+ + +
+
<Container object of 3 artists>
+
+ +
+ +
+ + +
+ +
+ +
+ +
+
+ +
+
+
+
In [17]:
+
+
+
p2, p2e = clag.errors(P2, p2, p2e)
+
+ +
+
+
+ +
+
+ + +
+
+
	### errors for param 0 ###
++++ 9.072e+03 9.071e+03 -2.375e-01 2.686e-02 0.913 +++
++++ 9.072e+03 9.071e+03 -2.375e-01 1.590e-01 1.9 +++
++++ 9.072e+03 9.071e+03 -2.375e-01 9.294e-02 1.37 +++
++++ 9.072e+03 9.071e+03 -2.375e-01 5.990e-02 1.13 +++
++++ 9.072e+03 9.071e+03 -2.375e-01 4.338e-02 1.02 +++
++++ 9.072e+03 9.071e+03 -2.375e-01 3.512e-02 0.966 +++
++++ 9.072e+03 9.071e+03 -2.375e-01 3.925e-02 0.993 +++
+	### errors for param 1 ###
++++ 9.072e+03 9.071e+03 -7.445e-01 -5.232e-01 0.914 +++
++++ 9.072e+03 9.071e+03 -7.445e-01 -4.125e-01 1.94 +++
++++ 9.072e+03 9.071e+03 -7.445e-01 -4.679e-01 1.39 +++
++++ 9.072e+03 9.071e+03 -7.445e-01 -4.955e-01 1.14 +++
++++ 9.072e+03 9.071e+03 -7.445e-01 -5.094e-01 1.02 +++
++++ 9.072e+03 9.071e+03 -7.445e-01 -5.163e-01 0.969 +++
++++ 9.072e+03 9.071e+03 -7.445e-01 -5.128e-01 0.997 +++
+	### errors for param 2 ###
++++ 9.072e+03 9.071e+03 -2.389e+00 -2.039e+00 1.13 +++
++++ 9.072e+03 9.071e+03 -2.389e+00 -2.214e+00 0.291 +++
++++ 9.072e+03 9.071e+03 -2.389e+00 -2.126e+00 0.647 +++
++++ 9.072e+03 9.071e+03 -2.389e+00 -2.082e+00 0.875 +++
++++ 9.072e+03 9.071e+03 -2.389e+00 -2.060e+00   1 +++
+	### errors for param 3 ###
++++ 9.072e+03 9.071e+03 -2.607e+00 -2.333e+00 1.17 +++
++++ 9.072e+03 9.071e+03 -2.607e+00 -2.470e+00 0.296 +++
++++ 9.072e+03 9.071e+03 -2.607e+00 -2.401e+00 0.664 +++
++++ 9.072e+03 9.071e+03 -2.607e+00 -2.367e+00 0.901 +++
++++ 9.072e+03 9.071e+03 -2.607e+00 -2.350e+00 1.03 +++
++++ 9.072e+03 9.071e+03 -2.607e+00 -2.358e+00 0.966 +++
++++ 9.072e+03 9.071e+03 -2.607e+00 -2.354e+00 0.999 +++
+	### errors for param 4 ###
++++ 9.072e+03 9.071e+03 -3.602e+00 -2.923e+00 2.16 +++
++++ 9.072e+03 9.071e+03 -3.602e+00 -3.263e+00 0.353 +++
++++ 9.072e+03 9.071e+03 -3.602e+00 -3.093e+00 0.996 +++
+	### errors for param 5 ###
++++ 9.072e+03 9.069e+03 -3.940e+00 -2.989e+00 4.49 +++
++++ 9.072e+03 9.071e+03 -3.940e+00 -3.464e+00 0.589 +++
++++ 9.072e+03 9.071e+03 -3.940e+00 -3.227e+00 1.88 +++
++++ 9.072e+03 9.071e+03 -3.940e+00 -3.345e+00 1.1 +++
++++ 9.072e+03 9.071e+03 -3.940e+00 -3.405e+00 0.818 +++
++++ 9.072e+03 9.071e+03 -3.940e+00 -3.375e+00 0.953 +++
++++ 9.072e+03 9.071e+03 -3.940e+00 -3.360e+00 1.03 +++
++++ 9.072e+03 9.071e+03 -3.940e+00 -3.368e+00 0.99 +++
++++ 9.072e+03 9.071e+03 -3.940e+00 -3.364e+00 1.01 +++
+	### errors for param 6 ###
++++ 9.072e+03 9.072e+03 -1.060e+01 -6.598e+00 0.0054 +++
++++ 9.072e+03 9.071e+03 -1.060e+01 -4.598e+00 0.542 +++
++++ 9.072e+03 9.069e+03 -1.060e+01 -3.598e+00 5.36 +++
++++ 9.072e+03 9.071e+03 -1.060e+01 -4.098e+00 1.72 +++
++++ 9.072e+03 9.071e+03 -1.060e+01 -4.348e+00 0.966 +++
++++ 9.072e+03 9.071e+03 -1.060e+01 -4.223e+00 1.29 +++
++++ 9.072e+03 9.071e+03 -1.060e+01 -4.286e+00 1.12 +++
++++ 9.072e+03 9.071e+03 -1.060e+01 -4.317e+00 1.04 +++
++++ 9.072e+03 9.071e+03 -1.060e+01 -4.332e+00   1 +++
+	### errors for param 7 ###
++++ 9.072e+03 9.072e+03 -1.045e+01 -7.450e+00 0.00104 +++
++++ 9.072e+03 9.072e+03 -1.045e+01 -5.950e+00 0.0328 +++
++++ 9.072e+03 9.071e+03 -1.045e+01 -5.200e+00 0.185 +++
++++ 9.072e+03 9.071e+03 -1.045e+01 -4.825e+00 0.439 +++
++++ 9.072e+03 9.071e+03 -1.045e+01 -4.637e+00 0.678 +++
++++ 9.072e+03 9.071e+03 -1.045e+01 -4.544e+00 0.842 +++
++++ 9.072e+03 9.071e+03 -1.045e+01 -4.497e+00 0.939 +++
++++ 9.072e+03 9.071e+03 -1.045e+01 -4.473e+00 0.992 +++
+********************
+-0.237486 -0.744501 -2.38936 -2.60722 -3.60235 -3.93982 -10.5981 -10.4499
+0.276735 0.231691 0.328894 0.253241 0.509151 0.575777 2 5.97656
+********************
+
+
+
+ +
+
+ +
+
+
+
In [ ]:
+
+
+
 
+
+ +
+
+
+ +
+
+
+
+
+
+
    +
  • Next we creat a lag object similar to the psd case. Now we use both light curves and the psd values obtained earlier.
  • +
  • We use cxd10r, becasue we used psd10r above, if that changes, this should change too. Though generally, there is no need to change these.
  • +
  • The light curves, time and error are passed as lists of lists. The outer list contains how many light curve sets we want to fit together, and the inner list contrain the first and second light curves whose lag is to be calculated
  • +
  • p is an array of starting parameters. A start like that should using works fine. Sometimes this need to be tweaked to make sure the fit converges.
  • +
+ +
+
+
+
+
+
In [52]:
+
+
+
Cx = clag.clag('cxd10r', [[t1,t2]], [[l1,l2]], [[l1e,l2e]], dt, fqL, p1, p2)
+p  = np.concatenate( ((p1+p2)*0.5-0.3,p1*0+0.1) ) # a  good starting point generally
+p, pe = clag.optimize(Cx, p)
+
+ +
+
+
+ +
+
+ + +
+
+
   1 1.507e+04 9.353e+00 inf -- 1.463e+04 -- -0.263469 -0.756956 -2.09189 -2.3639 -3.16804 -3.51705 -7.39217 -11.0905 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
+   3 1.162e+04 1.111e+01 2.207e+00 -- 1.464e+04 -- -0.222515 -0.71868 -2.05195 -2.3255 -3.13814 -3.44569 -7.69217 -11.0905 0.0540223 0.146385 0.211107 0.120928 0.22451 0.352806 0.225787 0.1
+   5 2.572e+03 1.301e+01 1.993e+00 -- 1.464e+04 -- -0.188623 -0.686392 -2.01542 -2.29378 -3.10648 -3.3727 -7.99217 -11.0905 0.0208945 0.18077 0.291002 0.136385 0.324159 0.504178 1.71174 0.1
+   7 5.499e+03 1.506e+01 1.809e+00 -- 1.464e+04 -- -0.160312 -0.658983 -1.98347 -2.26721 -3.07548 -3.31147 -8.29217 -11.0905 -0.0038816 0.207073 0.349667 0.148222 0.403652 0.596551 2.11801 0.1
+   9 1.265e+03 1.727e+01 1.655e+00 -- 1.464e+04 -- -0.136444 -0.63555 -1.95597 -2.2447 -3.04632 -3.26203 -8.59217 -11.0905 -0.0229558 0.227707 0.393817 0.157539 0.467517 0.657355 -1.76354 0.1
+  11 6.386e+02 1.966e+01 1.525e+00 -- 1.464e+04 -- -0.116154 -0.615387 -1.9324 -2.22548 -3.01944 -3.22204 -8.29217 -11.0905 -0.0379751 0.244228 0.427807 0.165034 0.519417 0.700307 -1.76354 0.1
+  13 3.235e+02 2.224e+01 1.412e+00 -- 1.464e+04 -- -0.0987795 -0.597934 -1.91218 -2.20896 -2.99492 -3.18933 -7.99217 -11.0905 -0.0500122 0.25768 0.454482 0.171164 0.562133 0.732293 -1.76354 0.1
+  15 1.644e+02 2.500e+01 1.312e+00 -- 1.464e+04 -- -0.0838109 -0.58275 -1.89479 -2.19468 -2.97268 -3.16229 -7.69217 -11.0905 -0.0597936 0.268786 0.475751 0.176246 0.597724 0.757149 -1.76354 0.1
+  17 8.384e+01 2.795e+01 1.223e+00 -- 1.465e+04 -- -0.0708471 -0.569482 -1.87979 -2.18229 -2.95253 -3.13972 -7.39217 -11.0905 -0.0678276 0.278065 0.492929 0.180509 0.627711 0.777132 -1.76354 0.1
+  19 4.288e+01 3.109e+01 1.141e+00 -- 1.465e+04 -- -0.059569 -0.557845 -1.86681 -2.17151 -2.93431 -3.12075 -7.09217 -11.0905 -0.0744802 0.285897 0.506948 0.184119 0.653232 0.793647 -1.76354 0.1
+  21 2.200e+01 3.443e+01 1.066e+00 -- 1.465e+04 -- -0.0497196 -0.547603 -1.85555 -2.1621 -2.91781 -3.1047 -6.79217 -11.0905 -0.0800213 0.292565 0.518486 0.187201 0.675142 0.807615 -1.76354 0.1
+  23 1.132e+01 3.796e+01 9.959e-01 -- 1.465e+04 -- -0.0410891 -0.538564 -1.84575 -2.15388 -2.90286 -3.09105 -6.49217 -11.0905 -0.084654 0.298288 0.528046 0.189851 0.694098 0.819659 -1.76354 0.1
+  24 5.898e-01 3.584e+03 1.376e+00 -- 1.465e+04 -- 0.034754 -0.4586 -1.76026 -2.08192 -2.76728 -2.97456 -3.49217 -11.0905 -0.123455 0.34774 0.60772 0.212743 0.859212 0.925291 -2.01201 0.1
+  25 8.154e-01 5.087e+01 1.095e+01 -- 1.466e+04 -- 0.0315381 -0.463316 -1.78861 -2.14119 -2.7032 -3.06487 -3.50786 -11.0905 -0.080452 0.354068 0.642389 0.0872582 0.929788 0.925607 -1.87766 0.1
+  26 8.474e-02 4.125e+01 1.295e+00 -- 1.466e+04 -- 0.0313567 -0.462364 -1.77246 -2.09785 -2.72914 -3.01339 -3.63657 -11.0905 -0.0903589 0.346492 0.695621 0.158407 0.937946 1.04186 -1.81 0.1
+  27 1.402e-01 8.842e+00 5.049e-01 -- 1.466e+04 -- 0.0307976 -0.462048 -1.78087 -2.11005 -2.73093 -3.02079 -3.77705 -11.0905 -0.0859431 0.34971 0.6455 0.156108 0.93052 1.00707 -1.65662 0.1
+  28 1.151e-01 7.210e+00 1.569e-01 -- 1.466e+04 -- 0.0307692 -0.462203 -1.77706 -2.10191 -2.73633 -3.01355 -3.90775 -11.0905 -0.085448 0.345468 0.669565 0.177991 0.929605 0.996167 -1.50215 0.1
+  29 8.198e-02 5.268e+00 4.450e-02 -- 1.466e+04 -- 0.0307085 -0.462133 -1.77941 -2.10487 -2.7354 -3.01527 -3.97788 -11.0905 -0.0852619 0.347439 0.650051 0.180002 0.931237 0.991797 -1.32927 0.1
+  30 4.907e-02 1.673e+00 1.011e-02 -- 1.466e+04 -- 0.0307433 -0.46222 -1.77843 -2.10279 -2.73529 -3.01313 -4.0139 -11.0905 -0.0848026 0.3465 0.657076 0.186301 0.932779 0.989877 -1.2203 0.1
+  31 2.218e-02 1.737e+00 2.283e-03 -- 1.466e+04 -- 0.0307595 -0.462214 -1.77904 -2.10366 -2.73433 -3.01368 -4.02131 -11.0905 -0.0847916 0.347141 0.651721 0.186854 0.934547 0.990363 -1.16042 0.1
+  32 1.049e-02 6.278e-01 5.116e-04 -- 1.466e+04 -- 0.0307847 -0.462244 -1.77877 -2.10315 -2.73397 -3.01308 -4.02614 -11.0905 -0.0846378 0.346933 0.653892 0.188201 0.935705 0.990726 -1.13468 0.1
+  33 4.768e-03 5.593e-01 1.303e-04 -- 1.466e+04 -- 0.0307977 -0.462243 -1.77893 -2.10342 -2.73358 -3.01326 -4.02629 -11.0905 -0.0846303 0.347124 0.652557 0.188172 0.936534 0.991266 -1.12279 0.1
+  34 2.366e-03 2.813e-01 3.574e-05 -- 1.466e+04 -- 0.0308087 -0.462251 -1.77885 -2.10329 -2.73343 -3.0131 -4.02705 -11.0905 -0.0845834 0.347075 0.653209 0.188435 0.937018 0.991526 -1.11743 0.1
+********************
+0.0308087 -0.462251 -1.77885 -2.10329 -2.73343 -3.0131 -4.02705 -11.0905 -0.0845834 0.347075 0.653209 0.188435 0.937018 0.991526 -1.11743 0.1
+0.00444687 0.00391368 0.0195472 0.0522199 0.0692273 0.0931011 0.600907 10 0.0791371 0.0681671 0.171256 0.248503 0.290782 0.317185 1.41333 10
+0.281266 0.00261966 -0.113352 -0.0304571 0.0248402 -0.00516435 0.000469769 2.53754e-07 0.00150497 0.0106824 -0.0107165 -0.00105737 0.003675 0.00209301 0.00132737 2.87086e-08
+********************
+
+
+
+ +
+
+ +
+
+
+
+
+
+
    +
  • We get the errors for the cross spectrum and phase lags
  • +
+ +
+
+
+
+
+
In [96]:
+
+
+
%autoreload
+p, pe = clag.errors(Cx, p, pe)
+
+ +
+
+
+ +
+
+ + +
+
+
	### errors for param 0 ###
++++ 1.466e+04 1.466e+04 3.066e-02 3.294e-02 0.176 +++
++++ 1.466e+04 1.466e+04 3.066e-02 3.407e-02 0.514 +++
++++ 1.466e+04 1.466e+04 3.066e-02 3.464e-02 0.828 +++
++++ 1.466e+04 1.466e+04 3.066e-02 3.492e-02 1.05 +++
++++ 1.466e+04 1.466e+04 3.066e-02 3.478e-02 0.932 +++
++++ 1.466e+04 1.466e+04 3.066e-02 3.485e-02 0.989 +++
++++ 1.466e+04 1.466e+04 3.066e-02 3.489e-02 1.02 +++
++++ 1.466e+04 1.466e+04 3.066e-02 3.487e-02   1 +++
+	### errors for param 1 ###
++++ 1.466e+04 1.466e+04 -4.624e-01 -4.604e-01 0.268 +++
++++ 1.466e+04 1.466e+04 -4.624e-01 -4.594e-01 0.767 +++
++++ 1.466e+04 1.466e+04 -4.624e-01 -4.589e-01 1.2 +++
++++ 1.466e+04 1.466e+04 -4.624e-01 -4.592e-01 0.962 +++
++++ 1.466e+04 1.466e+04 -4.624e-01 -4.590e-01 1.07 +++
++++ 1.466e+04 1.466e+04 -4.624e-01 -4.591e-01 1.02 +++
++++ 1.466e+04 1.466e+04 -4.624e-01 -4.591e-01 0.989 +++
++++ 1.466e+04 1.466e+04 -4.624e-01 -4.591e-01   1 +++
+	### errors for param 2 ###
++++ 1.466e+04 1.466e+04 -1.780e+00 -1.770e+00 0.503 +++
++++ 1.466e+04 1.466e+04 -1.780e+00 -1.765e+00 1.74 +++
++++ 1.466e+04 1.466e+04 -1.780e+00 -1.767e+00 0.957 +++
++++ 1.466e+04 1.466e+04 -1.780e+00 -1.766e+00 1.3 +++
++++ 1.466e+04 1.466e+04 -1.780e+00 -1.767e+00 1.11 +++
++++ 1.466e+04 1.466e+04 -1.780e+00 -1.767e+00 1.03 +++
++++ 1.466e+04 1.466e+04 -1.780e+00 -1.767e+00 0.995 +++
+	### errors for param 3 ###
++++ 1.466e+04 1.466e+04 -2.100e+00 -2.075e+00 0.424 +++
++++ 1.466e+04 1.466e+04 -2.100e+00 -2.062e+00 1.24 +++
++++ 1.466e+04 1.466e+04 -2.100e+00 -2.068e+00 0.753 +++
++++ 1.466e+04 1.466e+04 -2.100e+00 -2.065e+00 0.975 +++
++++ 1.466e+04 1.466e+04 -2.100e+00 -2.064e+00 1.1 +++
++++ 1.466e+04 1.466e+04 -2.100e+00 -2.064e+00 1.03 +++
++++ 1.466e+04 1.466e+04 -2.100e+00 -2.065e+00   1 +++
+	### errors for param 4 ###
++++ 1.466e+04 1.466e+04 -2.728e+00 -2.696e+00 0.209 +++
++++ 1.466e+04 1.466e+04 -2.728e+00 -2.680e+00 0.593 +++
++++ 1.466e+04 1.466e+04 -2.728e+00 -2.672e+00 0.932 +++
++++ 1.466e+04 1.466e+04 -2.728e+00 -2.668e+00 1.17 +++
++++ 1.466e+04 1.466e+04 -2.728e+00 -2.670e+00 1.05 +++
++++ 1.466e+04 1.466e+04 -2.728e+00 -2.671e+00 0.987 +++
++++ 1.466e+04 1.466e+04 -2.728e+00 -2.670e+00 1.02 +++
++++ 1.466e+04 1.466e+04 -2.728e+00 -2.671e+00   1 +++
+	### errors for param 5 ###
++++ 1.466e+04 1.466e+04 -3.007e+00 -2.964e+00 0.386 +++
++++ 1.466e+04 1.466e+04 -3.007e+00 -2.942e+00 1.12 +++
++++ 1.466e+04 1.466e+04 -3.007e+00 -2.953e+00 0.68 +++
++++ 1.466e+04 1.466e+04 -3.007e+00 -2.947e+00 0.877 +++
++++ 1.466e+04 1.466e+04 -3.007e+00 -2.945e+00 0.991 +++
+	### errors for param 6 ###
++++ 1.466e+04 1.466e+04 -4.051e+00 -3.738e+00 0.336 +++
++++ 1.466e+04 1.466e+04 -4.051e+00 -3.582e+00 1.27 +++
++++ 1.466e+04 1.466e+04 -4.051e+00 -3.660e+00 0.674 +++
++++ 1.466e+04 1.466e+04 -4.051e+00 -3.621e+00 0.927 +++
++++ 1.466e+04 1.466e+04 -4.051e+00 -3.602e+00 1.09 +++
++++ 1.466e+04 1.466e+04 -4.051e+00 -3.611e+00   1 +++
+	### errors for param 7 ###
++++ 1.466e+04 1.466e+04 -3.804e+00 -3.719e+00 0.667 +++
++++ 1.466e+04 1.466e+04 -3.804e+00 -3.676e+00 2.74 +++
++++ 1.466e+04 1.466e+04 -3.804e+00 -3.697e+00 1.36 +++
++++ 1.466e+04 1.466e+04 -3.804e+00 -3.708e+00 0.962 +++
++++ 1.466e+04 1.466e+04 -3.804e+00 -3.703e+00 1.14 +++
++++ 1.466e+04 1.466e+04 -3.804e+00 -3.705e+00 1.05 +++
++++ 1.466e+04 1.466e+04 -3.804e+00 -3.707e+00 1.01 +++
+	### errors for param 8 ###
++++ 1.466e+04 1.466e+04 -8.599e-02 -6.017e-03   1 +++
+	### errors for param 9 ###
++++ 1.466e+04 1.466e+04 3.480e-01 4.170e-01 0.968 +++
++++ 1.466e+04 1.466e+04 3.480e-01 4.515e-01 1.95 +++
++++ 1.466e+04 1.466e+04 3.480e-01 4.342e-01 1.43 +++
++++ 1.466e+04 1.466e+04 3.480e-01 4.256e-01 1.19 +++
++++ 1.466e+04 1.466e+04 3.480e-01 4.213e-01 1.08 +++
++++ 1.466e+04 1.466e+04 3.480e-01 4.191e-01 1.02 +++
++++ 1.466e+04 1.466e+04 3.480e-01 4.181e-01 0.996 +++
+	### errors for param 10 ###
++++ 1.466e+04 1.466e+04 6.487e-01 8.233e-01 0.85 +++
++++ 1.466e+04 1.466e+04 6.487e-01 9.105e-01 1.66 +++
++++ 1.466e+04 1.466e+04 6.487e-01 8.669e-01 1.24 +++
++++ 1.466e+04 1.466e+04 6.487e-01 8.451e-01 1.04 +++
++++ 1.466e+04 1.466e+04 6.487e-01 8.342e-01 0.944 +++
++++ 1.466e+04 1.466e+04 6.487e-01 8.396e-01 0.992 +++
+	### errors for param 11 ###
++++ 1.466e+04 1.466e+04 1.842e-01 4.266e-01 0.925 +++
++++ 1.466e+04 1.466e+04 1.842e-01 5.478e-01 1.96 +++
++++ 1.466e+04 1.466e+04 1.842e-01 4.872e-01 1.41 +++
++++ 1.466e+04 1.466e+04 1.842e-01 4.569e-01 1.16 +++
++++ 1.466e+04 1.466e+04 1.842e-01 4.417e-01 1.04 +++
++++ 1.466e+04 1.466e+04 1.842e-01 4.342e-01 0.98 +++
++++ 1.466e+04 1.466e+04 1.842e-01 4.380e-01 1.01 +++
+	### errors for param 12 ###
++++ 1.466e+04 1.466e+04 9.450e-01 1.226e+00 0.62 +++
++++ 1.466e+04 1.466e+04 9.450e-01 1.367e+00 1.36 +++
++++ 1.466e+04 1.466e+04 9.450e-01 1.297e+00 0.96 +++
++++ 1.466e+04 1.466e+04 9.450e-01 1.332e+00 1.15 +++
++++ 1.466e+04 1.466e+04 9.450e-01 1.314e+00 1.06 +++
++++ 1.466e+04 1.466e+04 9.450e-01 1.305e+00 1.01 +++
+	### errors for param 13 ###
++++ 1.466e+04 1.466e+04 1.013e+00 1.320e+00 0.825 +++
++++ 1.466e+04 1.466e+04 1.013e+00 1.474e+00 1.81 +++
++++ 1.466e+04 1.466e+04 1.013e+00 1.397e+00 1.28 +++
++++ 1.466e+04 1.466e+04 1.013e+00 1.358e+00 1.04 +++
++++ 1.466e+04 1.466e+04 1.013e+00 1.339e+00 0.93 +++
++++ 1.466e+04 1.466e+04 1.013e+00 1.349e+00 0.984 +++
++++ 1.466e+04 1.466e+04 1.013e+00 1.354e+00 1.01 +++
++++ 1.466e+04 1.466e+04 1.013e+00 1.351e+00 0.998 +++
+	### errors for param 14 ###
+	### errors for param 15 ###
++++ 1.466e+04 1.466e+04 6.767e-01 1.187e+00 0.535 +++
++++ 1.466e+04 1.466e+04 6.767e-01 1.442e+00 1.32 +++
++++ 1.466e+04 1.466e+04 6.767e-01 1.314e+00 0.875 +++
++++ 1.466e+04 1.466e+04 6.767e-01 1.378e+00 1.08 +++
++++ 1.466e+04 1.466e+04 6.767e-01 1.346e+00 0.974 +++
++++ 1.466e+04 1.466e+04 6.767e-01 1.362e+00 1.03 +++
++++ 1.466e+04 1.466e+04 6.767e-01 1.354e+00   1 +++
+********************
+0.030665 -0.46243 -1.78021 -2.09957 -2.72838 -3.0075 -4.05118 -3.80382 -0.0859876 0.347974 0.648709 0.184157 0.945002 1.01285 -1.02557 0.67675
+0.00420635 0.00330811 0.0128812 0.0346945 0.0578177 0.0629875 0.439838 0.0971903 0.0799706 0.0700847 0.190914 0.253798 0.360451 0.338322 2 0.677385
+********************
+
+
+
+ +
+
+ +
+
+
+
In [99]:
+
+
+
phi, phie = p[nfq:], pe[nfq:]
+lag, lage = phi/(2*np.pi*fqd), phie/(2*np.pi*fqd)    
+cx, cxe   = p[:nfq], pe[:nfq]
+
+ +
+
+
+ +
+
+
+
In [100]:
+
+
+
xscale('log'); ylim(-10,10)
+errorbar(fqd, lag, yerr=lage, fmt='o', ms=10)
+
+ +
+
+
+ +
+
+ + +
Out[100]:
+ + +
+
<Container object of 3 artists>
+
+ +
+ +
+ + +
+ +
+ +
+ +
+
+ +
+
+
+
In [ ]:
+
+
+
 
+
+ +
+
+
+ +
+
+
+ +