Last active
March 21, 2016 09:50
-
-
Save OrkoHunter/c87d0306e8bf2606a723 to your computer and use it in GitHub Desktop.
Prototype functions for my GSoC 16 project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division | |
import numpy as np | |
import stingray.lightcurve as lightcurve | |
def cross_covariance(lc1, lc2): | |
""" | |
Compute the cross covariance of two lightcurves. | |
Parameters | |
---------- | |
lc1 : Lightcurve object | |
First light curve involved in the computation of cross covariance. | |
lc2 : Lightcurve object | |
Second light curve involved in the computation of cross covariance. | |
Attributes | |
---------- | |
N : int | |
Number of data points in the light curves. | |
mean1 : float | |
Mean of the count values of ``lc1``. | |
mean2 : float | |
Mean of the count values of ``lc2``. | |
sigma : float | |
Sum of the products of the difference of individual counts and their mean. | |
""" | |
assert lc1.ncounts == lc2.ncounts, "Both lightcurves should have equal " \ | |
"number of data points." | |
N = len(lc1.counts) | |
mean1 = np.mean(lc1.counts) | |
mean2 = np.mean(lc2.counts) | |
sigma = np.sum([(lc1.counts[i] - mean1) * (lc2.counts[i] - mean2) | |
for i in range(N)]) | |
return sigma / (N - 1) | |
def _variance(lc): | |
""" | |
Internal function to compute the variance of a lightcurve. | |
""" | |
return np.var(lc.counts) | |
def cross_correlation(lc1, lc2): | |
""" | |
Compute the cross-correlation of two lightcurves. | |
Parameters | |
---------- | |
lc1 : Lightcurve object | |
First light curve involved in the computation of cross covariance. | |
lc2 : Lightcurve object | |
Second light curve involved in the computation of cross covariance. | |
Attributes | |
---------- | |
covar : float | |
Cross-covaration of ``lc1`` and ``lc2``. | |
norm_factor : float | |
Square root of the product of variances of both lightcurve. | |
""" | |
var1 = _variance(lc1) | |
var2 = _variance(lc2) | |
covar = cross_covariance(lc1, lc2) | |
norm_factor = (var1 * var2)**0.5 | |
return covar / norm_factor | |
def auto_correlation(lc): | |
""" | |
Compute the cross-autocorrelation of a lightcurve. | |
""" | |
return cross_correlation(lc1, lc1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment