#!pip install -I "phoebe>=2.4,<2.5"

"""
Explanation: Binary with Spots
Setup
Let's first make sure we have the latest version of PHOEBE 2.4 installed (uncomment this line if running in an online notebook session such as colab).
End of explanation
"""


import phoebe
from phoebe import u # units
import numpy as np
import matplotlib.pyplot as plt

logger = phoebe.logger()

b = phoebe.default_binary()

b.set_value(qualifier='pitch', component='primary', value=30)

"""
Explanation: As always, let's do imports and initialize a logger and a new bundle.
End of explanation
"""


b.add_dataset('lc', times=phoebe.linspace(0,1,101))

b.run_compute(irrad_method='none', model='no_spot')

"""
Explanation: Model without Spots
End of explanation
"""


b.add_feature('spot', component='primary', feature='spot01', relteff=0.9, radius=15, colat=180, long=0)

"""
Explanation: Adding Spots
Let's add a spot to the primary component in our binary, which we have already misaligned by 30 degrees in pitch.
The 'colat' parameter defines the colatitude on the star measured from its North (spin) Pole.  The 'long' parameter measures the longitude of the spot - with longitude = 0 being defined as pointing towards the other star at t0.  See the spots tutorial for more details.
We'll place this spot at the South Pole, which should be pointing towards the observer because we pitched the north pole away from the observer.
End of explanation
"""


b.add_dataset('mesh', compute_times=[0.75], columns=['teffs'])

b.run_compute(irrad_method='none', model='with_spot')

"""
Explanation: We'll also add a mesh dataset so that we can see the positioning of the spot with respect to the misaligned component.
End of explanation
"""


afig, mplfig = b.plot(kind='mesh', fc='teffs', fcmap='plasma', ec='face', show=True)

"""
Explanation: Location of Spot
End of explanation
"""


afig, mplfig = b.plot(kind='lc', show=True, legend=True)

"""
Explanation: Comparing Light Curves
Note that the pitch means the polar spot is always facing towards the observer slightly, and so is always visible (unless eclipsed).
End of explanation
"""


