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

import phoebe
from phoebe import u,c

logger = phoebe.logger(clevel='WARNING')

b = phoebe.default_binary()

"""
Explanation: Advanced: Parameter Units
In this tutorial we will learn about how units are handled in the frontend and how to translate between different units.
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
"""


b.get_parameter(qualifier='sma', component='binary', context='component')

"""
Explanation: Units
Each FloatParameter or FloatArrayParameter has an associated unit.   Let's look at the 'sma' Parameter for the binary orbit.
End of explanation
"""


b.get_parameter(qualifier='sma', component='binary', context='component').get_default_unit()

"""
Explanation: From the representation above, we can already see that the units are in solar radii.  We can access the units directly via get_default_unit.
End of explanation
"""


b.get_parameter(qualifier='sma', component='binary', context='component').get_value()

"""
Explanation: Calling get_value returns only the float of the value in these units.
End of explanation
"""


b.get_parameter(qualifier='sma', component='binary', context='component').get_quantity()

"""
Explanation: Alternatively, you can access an astropy quantity object that contains the value and unit by calling get_quantity.
End of explanation
"""


b.get_parameter(qualifier='sma', component='binary', context='component').get_value(unit=u.km)

b.get_parameter(qualifier='sma', component='binary', context='component').get_quantity(unit='km')

"""
Explanation: Both get_value and get_quantity also accept a unit argument which will return the value or quantity in the requested units (if able to convert).  This unit argument takes either a unit object (we imported a forked version of astropy units from within PHOEBE) or a string representation that can be parsed.
End of explanation
"""


b.get_parameter(qualifier='sma', component='binary', context='component').set_value(3800000*u.km)

b.get_parameter(qualifier='sma', component='binary', context='component').get_quantity()

b.get_parameter(qualifier='sma', component='binary', context='component').set_value(3900000, unit='km')

b.get_parameter(qualifier='sma', component='binary', context='component').get_quantity()

"""
Explanation: Similarly when setting the value, you can provide either a Quantity object or a value and unit.  These will still be stored within PHOEBE according to the default_unit of the Parameter object.
End of explanation
"""


b.get_parameter(qualifier='sma', component='binary', context='component').set_default_unit('mm')

b.get_parameter(qualifier='sma', component='binary', context='component').get_quantity()

b.get_parameter(qualifier='sma', component='binary', context='component').get_quantity(unit='solRad')

"""
Explanation: If for some reason you want to change the default units, you can, but just be careful that this could cause some float-point precision issues.
End of explanation
"""


