import matplotlib.pyplot as plt

import decatur

"""
Explanation: Eclipsing Binary Variability Classification Examples
End of explanation
"""


eb_spots = decatur.eclipsing_binary.EclipsingBinary.from_kic(7129465)
eb_spots.detrend_and_normalize()

plt.figure(figsize=(12, 6))
plt.plot(eb_spots.l_curve.times, eb_spots.l_curve.fluxes, color = "black")
plt.xlim(400,450 )
plt.tick_params(labelsize=20)
plt.ylim(-0.3, 0.05)
plt.xlabel('Time (days)', fontsize = 24)
plt.ylabel('Relative Flux', fontsize = 24)
plt.savefig("SP_example.pdf")
plt.show()

"""
Explanation: EB with starspot modulations (SP)
Starspot modulations are caused by dark spots coming into and out of view as the star rotates. The hemisphere with the most spots will appear darkest. 
Starspot modulations appear wavelike, but are irregular and change over time, as different spots form, migrate across the star, and eventually dissipate.
End of explanation
"""


eb_ellip = decatur.eclipsing_binary.EclipsingBinary.from_kic(4574310)
eb_ellip.detrend_and_normalize()

plt.figure(figsize=(12, 6))
plt.plot(eb_ellip.l_curve.times, eb_ellip.l_curve.fluxes, color = "black")
plt.xlim(410, 420)
plt.tick_params(labelsize=20)
plt.ylim(-0.45, 0.1)
plt.xlabel('Time (days)', fontsize = 24)
plt.ylabel('Relative Flux', fontsize = 24)
plt.savefig("EV_example1.pdf")
plt.show()

"""
Explanation: EB with ellipsoidal variations (EV)
Ellipsoidal variations occur when the stars are distorted into ellipsoids (egg shapes) by tidal forces. The long ends of the star are further from the core, and therefore cooler and less bright. As the stars rotate, the observed brightness changes because we see different parts of the stars.
In binaries with larger orbital separations, and generally longer orbital periods, ellipsoidal variations appear m-shaped. Notice how the brightness increases at the end of an eclipse, reaches a maximum, and then decreases until the beginning of the next eclipse. Unlike the starspot modulations, elipsoidal variations are regular and repeat the same pattern over and over again.
End of explanation
"""


eb_ellip = decatur.eclipsing_binary.EclipsingBinary.from_kic(5770860)
eb_ellip.detrend_and_normalize()

plt.figure(figsize=(12, 6))
plt.plot(eb_ellip.l_curve.times, eb_ellip.l_curve.fluxes, color = 'black')
plt.xlim(420, 424)
plt.tick_params(labelsize=20)
plt.ylim(-0.1, 0.1)
plt.xlabel('Time (days)', fontsize = 24)
plt.ylabel('Relative Flux', fontsize = 24)
plt.savefig('EV_example2.pdf')
plt.show()

"""
Explanation: In binaries with small orbital separations (short orbital periods), there may not be well defined eclipses. Instead, we see a repeating, sinusoidal (wave-like) pattern.
End of explanation
"""


eb_flat = decatur.eclipsing_binary.EclipsingBinary.from_kic(1571511)
eb_flat.detrend_and_normalize()

plt.figure(figsize=(12, 6))
plt.plot(eb_flat.l_curve.times, eb_flat.l_curve.fluxes, color = 'black')
plt.xlim(450, 600)
plt.tick_params(labelsize=20)
plt.ylim(-0.025, 0.01)
plt.xlabel('Time (days)', fontsize = 24)
plt.ylabel('Relative Flux', fontsize = 24)
plt.savefig('FL_example.pdf')
plt.show()

"""
Explanation: EB with little or no out-of-eclipse variability (FL)
Some binaries have very little out-of-eclipse variability, and are essentially flat.
End of explanation
"""


eb_other = decatur.eclipsing_binary.EclipsingBinary.from_kic(2697935)
eb_other.detrend_and_normalize()

plt.figure(figsize=(8, 6))
plt.plot(eb_other.l_curve.times, eb_other.l_curve.fluxes)
plt.xlim(640, 720)
plt.ylim(-0.0025, 0.0025)
plt.xlabel('Time (days)')
plt.ylabel('Relative Flux')
plt.show()

"""
Explanation: EB with other kinds of out-of-eclipse variability (OT)
This is an example of a heartbeat star.
End of explanation
"""


eb_other = decatur.eclipsing_binary.EclipsingBinary.from_kic(8560861)
eb_other.detrend_and_normalize()

plt.figure(figsize=(8, 6))
plt.plot(eb_other.l_curve.times, eb_other.l_curve.fluxes)
plt.xlim(400, 550)
plt.ylim(-0.03, 0.004)
plt.xlabel('Time (days)')
plt.ylabel('Relative Flux')
plt.show()

"""
Explanation: Some stars show pulsations, which can be difficult to distinguish from starspot modulations. Notice how the pulsations repeat in a more regular way than the starspot modulations.
End of explanation
"""


