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

import phoebe

logger = phoebe.logger()

b = phoebe.default_binary()

"""
Explanation: Advanced: Accessing and Plotting Meshes
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.add_dataset('lc', times=phoebe.linspace(0,1,6))

b.add_dataset('mesh')

"""
Explanation: The 'Mesh' Dataset
You must create a mesh dataset and specify the times and columns which you'd like exposed.  For more information, see the tutorial on the MESH dataset.
The mesh will be exposed at the times specified by the compute_times Parameter, as well as any times referenced by the include_times SelectParameter.
So let's add an LC and MESH datasets.
End of explanation
"""


print(b.get_parameter(qualifier='compute_times', kind='mesh'))

print(b.get_parameter(qualifier='include_times', kind='mesh'))

"""
Explanation: Unlike other datasets, the mesh dataset cannot accept actual observations, so there is no times parameter, only the compute_times and compute_phases parameters.  For more details on these, see the Advanced: Compute Times & Phases tutorial.
End of explanation
"""


b.set_value('compute_times', kind='mesh', value=[10])

b.set_value('include_times', kind='mesh', value=['lc01'])

b.run_compute()

print(b.filter(kind='mesh', context='model').times)

"""
Explanation: Note that we can manually set the times of the mesh AND/OR reference the times for existing non-mesh datasets (such as the light curve we just added) as well as any of the various t0s in the system.
End of explanation
"""


print(b.filter(kind='mesh', context='model').qualifiers)

"""
Explanation: By default, the mesh only exposes the geometric columns of the triangles, in both plane-of-sky and roche coordinates.
End of explanation
"""


print(b.get_parameter(qualifier='columns', kind='mesh', context='dataset'))

b.set_value('columns', value=['teffs'])

b.run_compute()

print(b.filter(kind='mesh', context='model').qualifiers)

print(b.get_value('teffs', time=0.0, component='primary'))

"""
Explanation: But we can also specify other columns to be included (by setting the columns SelectParameter before calling run_compute)
End of explanation
"""


afig, mplfig = b.plot(kind='mesh', time=0.2, fc='teffs', ec='none', show=True)

"""
Explanation: Any of the exposed columns are then available for plotting the mesh, via b.plot.
End of explanation
"""


print(b.get_parameter(qualifier='coordinates', kind='mesh', context='dataset'))

b.set_value('coordinates', value=['uvw'])

b.run_compute()

print(b.filter(kind='mesh', context='model').qualifiers)

"""
Explanation: Additionally, if we know that we only want to expose (and plot) the mesh in plane-of-sky, we can save some computation time by ommitting roche coordinates when computing the model.  This is done via the coordinates SelectParameter.
End of explanation
"""


