!pip install -I "phoebe>=2.0,<2.1"

"""
Explanation: Various t0s
Setup
Let's first make sure we have the latest version of PHOEBE 2.0 installed. (You can comment out this line if you don't use pip for your installation or don't want to update to the latest release).
End of explanation
"""


%matplotlib inline

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

logger = phoebe.logger()

b = phoebe.default_binary()

"""
Explanation: As always, let's do imports and initialize a logger and a new Bundle.  See Building a System for more details.
End of explanation
"""


b.set_value('sma@binary', 20)
b.set_value('q', 0.8)
b.set_value('ecc', 0.8)
b.set_value('per0', 45)

"""
Explanation: And let's make our system a little more interesting so that we can discriminate between the various t0s
End of explanation
"""


print phoebe.__version__

"""
Explanation: t0 Parameters
IMPORTANT NOTE: the definition of the constraint between 't0_supconj' and 't0_perpass' was fixed in the 2.0.3 hotfix release.  Earlier versions may give different results in some cases.  Please make sure to update to at least 2.0.3.  To check your installed version of phoebe, you can do the following:
End of explanation
"""


b.get_parameter('t0_supconj', context='component')

"""
Explanation: There are three t0 parameters that are available to define an orbit (but only one of which is editable at any given time), as well as a t0 parameter for the entire system.  Let's first access the three t0 parameters for our binary orbit.
't0_supconj' defines the time at which the primary component in our orbit is at superior conjunction.  For a binary system in which there are eclipses, this is defined as the primary eclipse.  By default this parameter is editable.
End of explanation
"""


b.get_parameter('t0_perpass', context='component')

b.get_parameter('t0_perpass', context='constraint')

"""
Explanation: 't0_perpass' defines the time at which both components in our orbit is at periastron passage.  By default this parameter is constrained by 't0_supconj'.  For more details or information on how to change which parameter is editable, see the Constraints Tutorial.
End of explanation
"""


b.get_parameter('t0_ref', context='component')

b.get_parameter('t0_ref', context='constraint')

"""
Explanation: The 't0_ref' defines the time at which the primary component in our orbit passes an arbitrary reference point.  This 't0_ref' is defined in the same way as PHOEBE legacy's 'HJD0' parameter, so is included for convenience translating between the two.
End of explanation
"""


b.get_parameter('t0', context='system')

"""
Explanation: In addition, there is a single 't0' parameter that is system-wide.  This parameter simply defines the time at which all parameters are defined and therefore at which all computations start.  The value of this parameter begins to play an important role if any parameter is given a time-derivative (see apsidal motion for an example) or when using N-body instead of Keplerian dynamics (coming in a future release).
End of explanation
"""


b.add_dataset('orb', times=np.linspace(-1,1,1001))

b.run_compute(ltte=False)

"""
Explanation: Influence on Oribits (positions)
End of explanation
"""


axs, artists = b.plot(x='xs', y='zs', time='t0_supconj')

axs, artists = b.plot(x='xs', y='zs', time='t0_perpass')

axs, artists = b.plot(x='xs', y='zs', time='t0_ref')

"""
Explanation: To visualize where these times are with respect to the orbits, we can plot the model orbit and highlight the positions of each star at the times defined by these parameters.  Note here that the observer is in the positive z-direction.
End of explanation
"""


b.to_phase(0.0)

b.to_phase(0.0, component='binary', t0='t0_supconj')

b.to_phase(0.0, component='binary', t0='t0_perpass')

b.to_phase(0.0, component='binary', t0='t0_ref')

"""
Explanation: Influence on Phasing
All computations in PHOEBE 2 are done in the time-domain.  Times can be translated to phases using any ephemeris available, as well as any of the t0s.
By default (if not passing any options), times will be phased using the outer-most orbit in the system and using 't0_supconj'.
End of explanation
"""


b.add_dataset('lc', times=np.linspace(0,1,51), ld_func='linear', ld_coeffs=[0.0])

b.run_compute(ltte=False, irrad_method='none', atm='blackbody')

axs, artists = b['lc01@model'].plot(x='phases', t0='t0_supconj', xlim=(-0.3,0.3))

axs, artists = b['lc01@model'].plot(x='phases', t0='t0_perpass', xlim=(-0.3,0.3))

axs, artists = b['lc01@model'].plot(x='phases', t0='t0_ref', xlim=(-0.3,0.3))

"""
Explanation: Similarly, if plotting phases on any axis, passing the 't0' keyword will set the zero-phase accordingly.  To see this, let's compute a light curve and phase it with the various t0s shown in the orbits above.
End of explanation
"""


