Accessing and Plotting Meshes

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).


In [ ]:
!pip install -I "phoebe>=2.0,<2.1"

As always, let's do imports and initialize a logger and a new Bundle. See Building a System for more details.


In [1]:
%matplotlib inline

In [2]:
import phoebe
from phoebe import u # units
import numpy as np
import matplotlib.pyplot as plt

logger = phoebe.logger()

b = phoebe.default_binary()


WARNING: Constant u'Gravitational constant' is already has a definition in the u'si' system [astropy.constants.constant]
WARNING: Constant u'Solar mass' is already has a definition in the u'si' system [astropy.constants.constant]
WARNING: Constant u'Solar radius' is already has a definition in the u'si' system [astropy.constants.constant]
WARNING: Constant u'Solar luminosity' is already has a definition in the u'si' system [astropy.constants.constant]
/usr/local/lib/python2.7/dist-packages/astropy/units/quantity.py:782: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  return super(Quantity, self).__eq__(other)

The 'protomesh'

The 'protomesh' is the mesh of each star in its own reference frame at periastron. The coordinates are defined such that the x-axis points towards the other component in the parent orbit.

To build the protomesh, set 'protomesh' to be True, either in the compute options or directly as a keyword argument when calling run_compute.


In [3]:
b.run_compute(protomesh=True)


Out[3]:
<ParameterSet: 30 parameters | components: primary, secondary>

You'll see that the resulting model has a single dataset kind ('mesh') and with a dataset tag of 'protomesh'.


In [4]:
print b['model'].kinds


['mesh']

In [5]:
print b['model'].datasets


['protomesh']

Now let's look at the parameters in the protomesh


In [6]:
b.filter(dataset='protomesh', context='model')


Out[6]:
<ParameterSet: 30 parameters | components: primary, secondary>

In [7]:
b.filter(dataset='protomesh', context='model', component='primary')


Out[7]:
<ParameterSet: 15 parameters | qualifiers: nzs, cosbetas, nxs, rs, tareas, nys, normals, vertices, teffs, loggs, xs, ys, areas, visible_centroids, zs>

In [8]:
b.get_value(dataset='protomesh', context='model', component='primary', qualifier='teffs')


Out[8]:
array([ 5978.07718064,  5978.1783501 ,  5978.07718064, ...,  5993.84913948,
        5991.5661137 ,  5990.59166869])

In [9]:
axs, artists = b.filter(dataset='protomesh', context='model', component='secondary').plot(facecolor='teffs', edgecolor=None)


/home/kyle/.local/lib/python2.7/site-packages/phoebe/frontend/plotting.py:257: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if pckwargs['edgecolors'] in ['none', 'None', None] and pckwargs['facecolors'] not in ['none', 'None', None]:
/home/kyle/.local/lib/python2.7/site-packages/phoebe/frontend/plotting.py:257: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  if pckwargs['edgecolors'] in ['none', 'None', None] and pckwargs['facecolors'] not in ['none', 'None', None]:

The 'pbmesh'

'pbmesh' is an automatically-created dataset in the returned model which stores the mesh at every time-point at which it was required to be built by other existing datasets.

Again, these will only be stored in the returned model if pbmesh=True is passed during run_compute or is True in the passed compute options.


In [10]:
b.add_dataset('lc', times=[0,1,2], dataset='lc01')


Out[10]:
<ParameterSet: 15 parameters | contexts: compute, dataset>

In [11]:
b.run_compute(pbmesh=True)


Fri, 10 Feb 2017 12:58 BUNDLE       WARNING overwriting model: latest
Out[11]:
<ParameterSet: 220 parameters | kinds: mesh, lc>

Our model now has dataset kinds for both the 'mesh' and 'lc' and has dataset tags for our newly-created 'lc01' dataset as well as the 'pbmesh' datasets in the model created only because pbmesh=True.


In [12]:
print b['model'].kinds


['mesh', 'lc']

In [13]:
print b['model'].datasets


['lc01', 'pbmesh']

This time let's look at the parameters in the 'pbmesh' dataset of the model.


In [14]:
b.filter(dataset='pbmesh', context='model')


Out[14]:
<ParameterSet: 182 parameters | components: primary, secondary>

In [15]:
b.filter(dataset='pbmesh', context='model', component='primary')


Out[15]:
<ParameterSet: 91 parameters | qualifiers: loggs, pot, xs, zs, horizon_zs, mus, rs, nys, r_projs, horizon_xs, teffs, vzs, vxs, horizon_analytic_xs, volume, rpole, horizon_analytic_ys, ys, areas, nzs, vys, cosbetas, nxs, horizon_analytic_zs, tareas, vertices, horizon_ys, times, visibilities, normals, visible_centroids>

As you can see, the intensities are not available here - their dataset tags match the dataset of the light curve. Instead let's access the mesh by dataset-kind:


In [16]:
b.filter(kind='mesh', context='model', component='primary')


Out[16]:
<ParameterSet: 109 parameters | datasets: lc01, pbmesh>

In [17]:
b.filter(dataset='lc01', kind='mesh', context='model', component='primary')


Out[17]:
<ParameterSet: 18 parameters | qualifiers: normal_intensities, abs_intensities, abs_normal_intensities, intensities, boost_factors, pblum>

To plot the intensities as color on the mesh, we can just plot the mesh and then reference the correct column by using twig access:


In [18]:
axs, artists = b.filter(kind='mesh', context='model', time=1.0).plot(facecolor='intensities@lc01', edgecolor='teffs')


The 'Mesh' Dataset Kind

If you want to force the plot itself to build at specific times but not have any observables (necessarily) computed or filled at those times, you can create a mesh dataset.

Let's create a mesh dataset that fills in the missing times from our lc dataset.


In [19]:
b.get_value('times@lc01@dataset')


Out[19]:
array([ 0.,  1.,  2.])

In [20]:
b.add_dataset('mesh', times=[0.5, 1.5], dataset='mesh01')


Out[20]:
<ParameterSet: 2 parameters | contexts: compute, dataset>

Now let's run_compute with protomesh and pbmesh set to False (these will default to the values in the compute options - which themselves are defaulted to False).


In [21]:
b.run_compute(protomesh=False, pbmesh=False)


Fri, 10 Feb 2017 12:59 BUNDLE       WARNING overwriting model: latest
Out[21]:
<ParameterSet: 148 parameters | kinds: mesh, lc>

As expected, the resulting model has dataset kinds for both mesh and lc, as well as datasets for 'mesh01' and 'lc01' - but the 'pbmesh' and 'protomesh' entries are no longer created (since protomesh and pbmesh are both False).


In [22]:
print b['model'].kinds


['mesh', 'lc']

In [23]:
print b['model'].datasets


['mesh01', 'lc01']

The meshes are only stored at the times of the mesh dataset - not at the times of the lc dataset.


In [24]:
b.filter(kind='mesh', context='model').times


Out[24]:
['1.5', '0.5']

Since there was no lc requested at these times, the 'intensities' columns will be empty.


In [25]:
b.get_value(kind='mesh', context='model', dataset='lc01', time=0.5, qualifier='intensities', component='primary')


Out[25]:
array([], dtype=float64)

But we can still plot any of the dataset-independent quantities


In [26]:
b.filter(dataset='mesh01', kind='mesh', context='model', component='primary', time=0.5)


Out[26]:
<ParameterSet: 30 parameters | qualifiers: loggs, pot, xs, zs, horizon_zs, mus, rs, nys, r_projs, horizon_xs, teffs, vzs, vxs, horizon_analytic_xs, volume, rpole, horizon_analytic_ys, ys, areas, nzs, vys, cosbetas, nxs, horizon_analytic_zs, tareas, vertices, horizon_ys, visibilities, normals, visible_centroids>

In [27]:
axs, artists = b.filter(dataset='mesh01', kind='mesh', context='model', time=0.5).plot(facecolor='teffs', edgecolor=None)


If you want the meshes stored at both the times in the 'mesh' dataset and all other datasets, simply set pbmesh to True.


In [28]:
b.run_compute(pbmesh=True)


Fri, 10 Feb 2017 12:59 BUNDLE       WARNING overwriting model: latest
Out[28]:
<ParameterSet: 366 parameters | kinds: mesh, lc>

In [29]:
b.filter(kind='mesh', context='model').times


Out[29]:
['1.5', '0.5', '2.0', '1.0', '0.0']

In [ ]: