<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Contact 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).
Step1:  As always, let's do imports and initialize a logger and a new bundle.
Step2:  Model without Spots
Step3:  Adding Spots
Let's add a spot to the primary component in our binary.  Note that if you attempt to attach to the 'contact_envelope' component, an error will be raised.  Spots can only be attached to star components.
The 'colat' parameter defines the latitude 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 to spots tutorial for more details.
Step4:  Comparing Light Curves
Step5:  Spots near the "neck"
Since the spots are still defined with the coordinate system of the individual star components, this can result in spots that are distorted and even "cropped" at the neck.  Furthermore, spots with long=0 could be completely "hidden" by the neck or result in a ring around the neck.
To see this, let's plot our mesh with teff as the facecolor.
Step6:  Now if we set the long closer to the neck, we'll see it get cropped by the boundary between the two components.  If we need a spot that crosses between the two "halves" of the contact, we'd have to add separate spots to each component, with each getting cropped at the boundary.
Step7:  If we set long to zero, the spot completely disappears (as there is nowhere in the neck that is still on the surface.
Step8:  But if we increase the radius large enough, we'll get a ring.
<ASSISTANT_TASK:>
Python Code:
#!pip install -I "phoebe>=2.4,<2.5"
Explanation: Contact 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
logger = phoebe.logger()
b = phoebe.default_binary(contact_binary=True)
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,0.5,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=20, colat=90, long=-45)
b.run_compute(irrad_method='none', model='with_spot')
Explanation: Adding Spots
Let's add a spot to the primary component in our binary.  Note that if you attempt to attach to the 'contact_envelope' component, an error will be raised.  Spots can only be attached to star components.
The 'colat' parameter defines the latitude 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 to spots tutorial for more details.
End of explanation
afig, mplfig = b.plot(show=True, legend=True)
Explanation: Comparing Light Curves
End of explanation
b.remove_dataset(kind='lc')
b.remove_model(model=['with_spot', 'no_spot'])
b.add_dataset('mesh', compute_times=b.to_time(0.25), columns='teffs')
b.run_compute(irrad_method='none')
afig, mplfig = b.plot(fc='teffs', ec='face', fcmap='plasma', show=True)
Explanation: Spots near the "neck"
Since the spots are still defined with the coordinate system of the individual star components, this can result in spots that are distorted and even "cropped" at the neck.  Furthermore, spots with long=0 could be completely "hidden" by the neck or result in a ring around the neck.
To see this, let's plot our mesh with teff as the facecolor.
End of explanation
b.set_value('long', value=-30)
b.run_compute(irrad_method='none')
afig, mplfig = b.plot(fc='teffs', ec='face', fcmap='plasma', show=True)
Explanation: Now if we set the long closer to the neck, we'll see it get cropped by the boundary between the two components.  If we need a spot that crosses between the two "halves" of the contact, we'd have to add separate spots to each component, with each getting cropped at the boundary.
End of explanation
b.set_value('long', value=0.0)
b.run_compute(irrad_method='none')
afig, mplfig = b.plot(fc='teffs', ec='face', fcmap='plasma', show=True)
Explanation: If we set long to zero, the spot completely disappears (as there is nowhere in the neck that is still on the surface.
End of explanation
b.set_value('radius', value=40)
b.run_compute(irrad_method='none')
afig, mplfig = b.plot(fc='teffs', ec='face', fcmap='plasma', show=True)
Explanation: But if we increase the radius large enough, we'll get a ring.
End of explanation
<END_TASK>