Using salter to examine the transit residuals


In [1]:
%matplotlib inline
%config InlineBackend.figure_format = "retina"

from salter import LightCurve
import matplotlib.pyplot as plt

In [2]:
# Specify a KIC number to get the light curve
# Here are some numbers to try: 4157325, 9651668, 9705459, 10386922
kic_number = 10815677#9651668
whole_lc = LightCurve.from_hdf5(kic_number)

# Plot the light curve (raw SAP flux)
whole_lc.plot()


Here's how you can quickly see what the transit parameters are:


In [3]:
for attr in dir(whole_lc.params):
    if not attr.startswith('_'):
        print("{0}: {1}".format(attr, getattr(whole_lc.params, attr)))


a: 5.082511378400465
b: 0.029
duration: 0.081875
ecc: 0
fp: None
inc: 89.67307763855406
limb_dark: quadratic
per: 1.284241817
rp: 0.011571726318920613
t0: 2454965.65223
t_secondary: None
u: (0.49869999999999998, 0.1772)
w: 90

Mask the out-of-transit portions of the light curve, normalize each transit with the "subtract-add-divide" method.


In [4]:
from salter import subtract_add_divide

extra_oot_time = 2.0 # [durations]; Extra transit durations to keep before ingress/after egress

# Mask out-of-transit portions of light curves, chop into individual transits
near_transit = LightCurve(**whole_lc.mask_out_of_transit(oot_duration_fraction=extra_oot_time))
transits = near_transit.get_transit_light_curves()

# Normalize all transits with the subtract-add-divide method, 
# using a second order polynomial
subtract_add_divide(whole_lc, transits)


/Users/bmmorris/anaconda/lib/python3.5/site-packages/astropy/time/core.py:880: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future
  jd1 = apply_method(jd1)
/Users/bmmorris/anaconda/lib/python3.5/site-packages/astropy/time/core.py:881: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future
  jd2 = apply_method(jd2)
/Users/bmmorris/git/salter/salter/lightcurve.py:347: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future
  fluxes=self.fluxes[start_ind:end_ind],
/Users/bmmorris/git/salter/salter/lightcurve.py:348: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future
  errors=self.errors[start_ind:end_ind],
/Users/bmmorris/git/salter/salter/lightcurve.py:349: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future
  quarters=self.quarters[start_ind:end_ind],
/Users/bmmorris/anaconda/lib/python3.5/site-packages/numpy/lib/polynomial.py:595: RankWarning: Polyfit may be poorly conditioned
  warnings.warn(msg, RankWarning)
/Users/bmmorris/anaconda/lib/python3.5/site-packages/numpy/lib/polynomial.py:595: RankWarning: Polyfit may be poorly conditioned
  warnings.warn(msg, RankWarning)
/Users/bmmorris/anaconda/lib/python3.5/site-packages/numpy/lib/polynomial.py:595: RankWarning: Polyfit may be poorly conditioned
  warnings.warn(msg, RankWarning)
/Users/bmmorris/anaconda/lib/python3.5/site-packages/numpy/lib/polynomial.py:595: RankWarning: Polyfit may be poorly conditioned
  warnings.warn(msg, RankWarning)
/Users/bmmorris/anaconda/lib/python3.5/site-packages/numpy/lib/polynomial.py:595: RankWarning: Polyfit may be poorly conditioned
  warnings.warn(msg, RankWarning)
/Users/bmmorris/anaconda/lib/python3.5/site-packages/numpy/lib/polynomial.py:595: RankWarning: Polyfit may be poorly conditioned
  warnings.warn(msg, RankWarning)
/Users/bmmorris/anaconda/lib/python3.5/site-packages/numpy/lib/polynomial.py:595: RankWarning: Polyfit may be poorly conditioned
  warnings.warn(msg, RankWarning)
/Users/bmmorris/anaconda/lib/python3.5/site-packages/numpy/lib/polynomial.py:595: RankWarning: Polyfit may be poorly conditioned
  warnings.warn(msg, RankWarning)
/Users/bmmorris/anaconda/lib/python3.5/site-packages/numpy/lib/polynomial.py:595: RankWarning: Polyfit may be poorly conditioned
  warnings.warn(msg, RankWarning)

In [5]:
10815677


Out[5]:
10815677

In [6]:
whole_lc.params.duration


Out[6]:
0.081875000000000003

Plot the residuals from the transit model given the parameters from the KOI catalog.


In [7]:
from salter import concatenate_transit_light_curves

normed_transits = concatenate_transit_light_curves(transits)

plt.plot(normed_transits.phases(), 
         normed_transits.fluxes - normed_transits.transit_model(), 
         'k.', alpha=0.3)
plt.xlabel('Orbital phase')
plt.ylabel('Residuals')


Out[7]:
<matplotlib.text.Text at 0x129116c18>

Solve for better $R_p/R_\star$, $u_1$, $u_2$ parameters:


In [8]:
from salter import concatenate_transit_light_curves

normed_transits = concatenate_transit_light_curves(transits)

# Solve for better parameters for: Rp/Rs, u1, u2
normed_transits.fit_lc_3param()

Store residuals in a Residuals object, which has handy methods for statistical analysis.


In [9]:
from salter import Residuals

r = Residuals(normed_transits, normed_transits.params, buffer_duration=0.3)

r.plot()


Out[9]:
(<matplotlib.figure.Figure at 0x1269ad278>,
 <matplotlib.axes._subplots.AxesSubplot at 0x129a27358>)

Out-of-transit: before vs after transit


In [10]:
# Two sample KS test: are the distributions of the two samples the same?
print(r.ks(['out_of_transit', 'before_midtransit'], 
           ['out_of_transit', 'after_midtransit']))

# k-sample Anderson test: are the distributions of the two samples the same?
print(r.anderson(['out_of_transit', 'before_midtransit'], 
                 ['out_of_transit', 'after_midtransit']))

# Independent sample T-test: are the means the two samples the same?
print(r.ttest(['out_of_transit', 'before_midtransit'], 
              ['out_of_transit', 'after_midtransit']))


0.897828273824
0.6009816536603817
0.477218216698
/Users/bmmorris/anaconda/lib/python3.5/site-packages/scipy/stats/morestats.py:1694: UserWarning: approximate p-value will be computed by extrapolation
  warnings.warn("approximate p-value will be computed by extrapolation")

In-transit: before vs after mid-transit


In [11]:
# Two sample KS test: are the distributions of the two samples the same?
print(r.ks(['in_transit', 'before_midtransit'], 
           ['in_transit', 'after_midtransit']))

# k-sample Anderson test: are the distributions of the two samples the same?
print(r.anderson(['in_transit', 'before_midtransit'], 
                 ['in_transit', 'after_midtransit']))

# Independent sample T-test: are the means the two samples the same?
print(r.ttest(['in_transit', 'before_midtransit'], 
              ['in_transit', 'after_midtransit']))


0.951418843898
1.0917391524189268
0.870784445883
/Users/bmmorris/anaconda/lib/python3.5/site-packages/scipy/stats/morestats.py:1694: UserWarning: approximate p-value will be computed by extrapolation
  warnings.warn("approximate p-value will be computed by extrapolation")

In-transit vs out-of-transit


In [12]:
# Two sample KS test: are the distributions of the two samples the same?
print(r.ks('in_transit', 'out_of_transit'))

# k-sample Anderson test: are the distributions of the two samples the same?
print(r.anderson('in_transit', 'out_of_transit'))

# Independent sample T-test: are the means the two samples the same?
print(r.ttest('in_transit', 'out_of_transit'))


1.17934980805e-28
2.9942535945440894e+50
0.373583693945
/Users/bmmorris/anaconda/lib/python3.5/site-packages/scipy/stats/morestats.py:1694: UserWarning: approximate p-value will be computed by extrapolation
  warnings.warn("approximate p-value will be computed by extrapolation")

In [ ]: