I am working on the file "2.2/tutorials/passbands.ipynb".
The first task is:
The first argument, ptf, is the passband transmission file we just created. Of course, you would provide an actual passband transmission function that comes from a respectable source rather than this silly tutorial.
The next two arguments, pbset and pbname, should be taken in unison. The way PHOEBE refers to passbands is a pbset:pbname string, for example Johnson:V, Cousins:Rc, etc. Thus, our fake passband will be Custom:mypb.
The following two arguments, effwl and wlunits, also come as a pair. PHOEBE uses effective wavelength to apply zero-level passband corrections when better options (such as model atmospheres) are unavailable. Effective wavelength is a transmission-weighted average wavelength in the units given by wlunits.
The calibrated parameter instructs PHOEBE whether to take the transmission function as calibrated, i.e. the flux through the passband is absolutely calibrated. If set to True, PHOEBE will assume that absolute intensities computed using the passband transmission function do not need further calibration. If False, the intensities are considered as scaled rather than absolute, i.e. correct to a scaling constant. Most modern passbands provided in the recent literature are calibrated.
The reference parameter holds a reference string to the literature from which the transmission function was taken from. It is common that updated transmission functions become available, which is the point of the version parameter. If there are multiple versions of the transmission function, PHOEBE will by default take the largest value, or the value that is explicitly requested in the filter string, i.e. Johnson:V:1.0 or Johnson:V:2.0.
Finally, the comments parameter is a convenience parameter to store any additional pertinent information.
Computing blackbody response
To significantly speed up calculations, passband intensities are stored in lookup tables instead of computing them over and over again on the fly. Computed passband tables are tagged in the content property of the class:
Can you write Python code for it?


I am working on the file "2.2/tutorials/passbands.ipynb".
The first task is:
There is one extra step that we need to do for phoenix atmospheres: because there are gaps in the coverage of atmospheric parameters, we need to impute those values in order to allow for seamless interpolation. This is achieved by the call to impute_atmosphere_grid(). It is a computationally intensive step that can take 10+ minutes.
Can you write Python code for it?

pb.impute_atmosphere_grid(pb._phoenix_energy_grid)
pb.impute_atmosphere_grid(pb._phoenix_photon_grid)
pb.impute_atmosphere_grid(pb._phoenix_ld_energy_grid)
pb.impute_atmosphere_grid(pb._phoenix_ld_photon_grid)
pb.impute_atmosphere_grid(pb._phoenix_ldint_energy_grid)
pb.impute_atmosphere_grid(pb._phoenix_ldint_photon_grid)
for i in range(len(pb._phoenix_intensity_axes[3])):
    pb.impute_atmosphere_grid(pb._phoenix_Imu_energy_grid[:,:,:,i,:])
    pb.impute_atmosphere_grid(pb._phoenix_Imu_photon_grid[:,:,:,i,:])


I am working on the file "2.2/tutorials/passbands.ipynb".
The first task is:
We can consult the content attribute to see the entire set of supported tables, and plot different atmosphere models for comparison purposes:
Can you write Python code for it?

pb.content

plt.xlabel('Temperature [K]')
plt.ylabel('Inorm [W/m^3]')
plt.plot(teffs, pb.Inorm(teffs,               atm='blackbody',   ldatm='ck2004',  ld_func='linear', ld_coeffs=[0.0]), label='blackbody')
plt.plot(teffs, pb.Inorm(teffs, loggs, abuns, atm='ck2004',      ldatm='ck2004',  ld_func='linear', ld_coeffs=[0.0]), label='ck2004')
plt.plot(teffs, pb.Inorm(teffs, loggs, abuns, atm='phoenix',     ldatm='phoenix', ld_func='linear', ld_coeffs=[0.0]), label='phoenix')
plt.plot(teffs, pb.Inorm(teffs, loggs, abuns, atm='extern_atmx', ldatm='phoenix', ld_func='linear', ld_coeffs=[0.0]), label='wd_atmx')
plt.legend(loc='lower right')
plt.show()


I am working on the file "2.2/tutorials/passbands.ipynb".
The first task is:
We can now test-drive the blackbody lookup table we just created. For this we will use a low-level class method that computes normal emergent passband intensity, Inorm(). For the sake of simplicity, we will turn off limb darkening by setting ld_func to 'linear' and ld_coeffs to '[0.0]':
Can you write Python code for it?

pb.Inorm(Teff=5772, atm='blackbody', ld_func='linear', ld_coeffs=[0.0])


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
'abs_normal_intensities' are the intensities per triangle in absolute units, i.e. W/m^3.
Can you write Python code for it?


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
'normal_intensities' are scaled from 'abs_normal_intensities' so that the computed luminosity matches the prescribed luminosity (pblum).
Here we compute the luminosity by summing over each triangle's intensity in the normal direction, and multiply it by pi to account for blackbody intensity emitted in all directions in the solid angle, and by the area of that triangle.
Can you write Python code for it?

pblum = b.get_value(qualifier='pblum', component='primary', context='dataset')
print(np.sum(normal_intensities * ldint * np.pi * areas) * ptfarea, pblum)


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
Accessing Model Luminosities
Passband luminosities at t0@system per-star (including following all coupling logic) can be computed and exposed on the fly by calling compute_pblums.
Can you write Python code for it?


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
And if we halve the temperature of the secondary star - the resulting light curve changes to the new sum of fluxes, where the primary star dominates since the secondary star flux is reduced by a factor of 16, so we expect a total out-of-eclipse flux of ~0.5 + ~0.5/16 = ~0.53.
Can you write Python code for it?

b.set_value('teff', component='secondary', value=0.5 * b.get_value('teff', component='primary'))

print(b.filter(qualifier='teff'))

print(b.compute_pblums())

b.run_compute()

afig, mplfig = b.plot(show=True)


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
And lastly, if we re-enable irradiation, we'll see that the extrinsic luminosities do not match the prescribed value of pblum (an intrinsic luminosity).
Can you write Python code for it?

print(b['ld_mode'])

print(b['atm'])

b.run_compute(irrad_method='horvat')

print(b.get_value(qualifier='pblum_ext', time=t0, component='primary', kind='mesh', context='model'))

print(b.get_value('pblum@primary@dataset'))

print(b.compute_pblums(dataset='lc01', irrad_method='horvat'))


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
Before moving on, let's remove our fake data (and reset pblum_mode or else PHOEBE will complain about the lack of data).
Can you write Python code for it?

b.set_value('pblum_mode', 'component-coupled')

b.set_value('fluxes', context='dataset', value=[])


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
By default this exposes 'pblum' and 'pblum_ext' for all component-dataset pairs in the form of a dictionary.  Alternatively, you can pass a label or list of labels to component and/or dataset.
Can you write Python code for it?


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
For any of these modes, you can expose the intrinsic (excluding extrinsic effects such as spots and irradiation) and extrinsic computed luminosities of each star (in each dataset) by calling b.compute_pblums.
Note that as its an aspect-dependent effect, boosting is ignored in all of these output values.
Can you write Python code for it?


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
For more details, see the section below on "Accessing Model Luminosities" as well as the b.compute_pblums API docs
pblum_mode = 'component-coupled'
pblum_mode='component-coupled' is the default option and maintains the default behavior from previous releases.  Here the user provides passband luminosities for a single star in the system for the given dataset/passband, and all other stars are scaled accordingly.
By default, the value of pblum is set for the primary star in the system, but we can instead provide pblum for the secondary star by changing the value of pblum_component.
Can you write Python code for it?

print(b.filter(qualifier='pblum'))

print(b.get_parameter(qualifier='pblum_component'))

b.set_value('pblum_component', 'secondary')

print(b.filter(qualifier='pblum'))


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
For more options, see the b.compute_pblums API docs.
Note that this same logic is applied (at t0) to initialize all passband luminosities within the backend, so there is no need to call compute_pblums before run_compute.
In order to access passband luminosities at times other than t0, you can add a mesh dataset and request the pblum_ext column to be exposed.  For stars that have pblum defined (as opposed to coupled to another star or dataset), this value should be equivalent to the value of the parameter (at t0 if no features or irradiation are present, and in simple circular cases will probably be equivalent at all times).
Let's create a mesh dataset at a few times and then access the synthetic luminosities.
Can you write Python code for it?

b.add_dataset('mesh', times=np.linspace(0,1,5), dataset='mesh01', columns=['areas', 'pblum_ext@lc01', 'ldint@lc01', 'ptfarea@lc01', 'abs_normal_intensities@lc01', 'normal_intensities@lc01'])

b.run_compute()


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
If we now set pblum to be only 2 pi, we should expect the luminosities as well as entire light curve to be scaled in half.
Can you write Python code for it?

b.set_value('pblum', component='primary', value=2*np.pi)

print(b.compute_pblums())

b.run_compute()

afig, mplfig = b.plot(show=True)


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
If we set these to 4pi, then we'd expect each star to contribute 1.0 in flux units, meaning the baseline of the light curve should be at approximately 2.0
Can you write Python code for it?

b.set_value_all('pblum', 4*np.pi)

print(b.compute_pblums())

b.run_compute()

afig, mplfig = b.plot(show=True)


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
In most cases you will not want decoupled luminosities as they can easily break the self-consistency of your model.
Now we'll just undo our changes before we look at accessing model luminosities.
Can you write Python code for it?

b.set_value_all('teff', 6000)
b.set_value_all('pblum', 4*np.pi)


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
Let us undo our changes before we look at decoupled luminosities.
Can you write Python code for it?


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
Let's see how changing the value of pblum affects the computed light curve.  By default, pblum is set to be 4 pi, giving a total flux for the primary star of ~1.
Since the secondary star in the default binary is identical to the primary star, we'd expect an out-of-eclipse flux of the binary to be ~2.
Can you write Python code for it?

b.run_compute()

afig, mplfig = b.plot(show=True)


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
NOTE: other parameters also affect flux-levels, including limb darkening, third light, boosting, irradiation, and distance
If we call b.compute_pblums, we'll see that the computed intrinsic luminosity of the primary star (pblum@primary@lc01) matches the value of the parameter above.
Can you write Python code for it?


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
Note that in general (for the case of a spherical star), a pblum of 4pi will result in an out-of-eclipse flux of ~1.
Now let's just reset to the default case where the primary star has a provided (default) pblum of 4pi.
Can you write Python code for it?

b.set_value('pblum_component', 'primary')
print(b.get_parameter(qualifier='pblum', component='primary'))


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
Now if we set pblum_mode to 'dataset-scaled', the resulting model will be scaled to best fit the data.  Note that in this mode we cannot access computed luminosities via b.compute_pblums (which would raise an error if we attempted to do so), nor can we access scaled intensities from the mesh.
Can you write Python code for it?

b.set_value('pblum_mode', 'dataset-scaled')

print(b.compute_pblums())

b.run_compute()

afig, mplfig = b.plot(show=True)


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
Now let's compare the value of the synthetic luminosities to those of the input pblum
Can you write Python code for it?

t0 = b.get_value('t0@system')

print(b.get_value(qualifier='pblum_ext', time=t0, component='primary', kind='mesh', context='model'))

print(b.get_value('pblum@primary@dataset'))

print(b.compute_pblums(component='primary', dataset='lc01'))


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
Now we see that both pblum parameters are available and can have different values.
Can you write Python code for it?


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
Now, we'll just undo our changes before continuing
Can you write Python code for it?


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
Relevant Parameters & Methods
NEW in PHOEBE 2.2: A pblum_mode parameter exists for each LC dataset in the bundle.  This parameter defines how passband luminosities are handled.  The subsections below describe the use and parameters exposed depening on the value of this parameter.
Can you write Python code for it?


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
Role of Pblum
Let's now look at the intensities in the mesh to see how they're being scaled under-the-hood.  First we'll recompute our model with the equal temperatures and irradiation disabled (to ignore the difference between pblum and pblum_ext).
Can you write Python code for it?

b.run_compute()

areas = b.get_value(qualifier='areas', dataset='mesh01', time=t0, component='primary', unit='m^2')
ldint = b.get_value(qualifier='ldint', component='primary', time=t0)
ptfarea = b.get_value(qualifier='ptfarea', component='primary', time=t0)

abs_normal_intensities = b.get_value(qualifier='abs_normal_intensities', dataset='lc01', time=t0, component='primary')
normal_intensities = b.get_value(qualifier='normal_intensities', dataset='lc01', time=t0, component='primary')


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
Since the luminosities are passband-dependent, they are stored with the same dataset as the light curve (or RV), but with the mesh method, and are available at each of the times at which a mesh was stored.
Can you write Python code for it?


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
The values of 'normal_intensities', however, are significantly samller (in this case).  These are the intensities in relative units which will eventually be integrated to give us flux for a light curve.
Can you write Python code for it?


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
pblum_mode = 'absolute'
By setting pblum_mode to 'absolute', luminosities and fluxes will be returned in absolute units and not rescaled.  Note that third light and distance will still affect the resulting flux levels.
Can you write Python code for it?


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
pblum_mode = 'dataset-coupled'
Setting pblum_mode to 'dataset-coupled' allows for the same scaling factor to be applied to two different datasets.  In order to see this in action, we'll add another LC dataset in a different passband.
Can you write Python code for it?

b.add_dataset('lc', times=phoebe.linspace(0,1,101),
              ld_mode='manual', ld_func='linear', ld_coeffs=[0],
              passband='Johnson:B', dataset='lc02')

b.set_value('pblum_mode', dataset='lc02', value='dataset-coupled')


I am working on the file "2.2/tutorials/pblum.ipynb".
The first task is:
pblum_mode = 'decoupled'
The luminosities are decoupled when pblums are provided for the individual components.  To accomplish this, set pblum_mode to 'decoupled'.
Can you write Python code for it?


I am working on the file "2.2/tutorials/pitch_yaw.ipynb".
The first task is:
And if we set the yaw to be non-zero, we'll see the rotation axis rotate on the plane of the sky.
Can you write Python code for it?

b['pitch@secondary@component'] = 0
b['yaw@secondary@component'] = 30

b.run_compute(irrad_method='none')

afig, mplfig = b.plot(time=0.0, fc='teffs', ec='none', x='us', y='vs', show=True)

afig, mplfig = b.plot(time=0.0, fc='teffs', ec='none', x='ws', y='vs', show=True)


I am working on the file "2.2/tutorials/pitch_yaw.ipynb".
The first task is:
Relevant Parameters
The 'pitch' parameter defines the misalignment of a given star in the same direction as the inclination.  We can see how it is defined relative to the inclination by accessing the constraint.
Note that, by default, it is the inclination of the component that is constrained with the inclination of the orbit and the pitch as free parameters.
Can you write Python code for it?


I am working on the file "2.2/tutorials/pitch_yaw.ipynb".
The first task is:
The long_an of a star is a bit of an odd concept, and really is just meant to be analogous to the inclination case.  In reality, it is the angle of the "equator" of the star on the sky.
Can you write Python code for it?


I am working on the file "2.2/tutorials/pitch_yaw.ipynb".
The first task is:
We'll plot the mesh as it would be seen on the plane of the sky.
Can you write Python code for it?

afig, mplfig = b.plot(time=0.0, fc='teffs', ec='none', x='us', y='vs', show=True)


I am working on the file "2.2/tutorials/pitch_yaw.ipynb".
The first task is:
and also with the line-of-sight along the x-axis.
Can you write Python code for it?

afig, mplfig = b.plot(time=0.0, fc='teffs', ec='none', x='ws', y='vs', show=True)


I am working on the file "2.2/tutorials/plotting.ipynb".
The first task is:
And we'll attach some dummy datasets.  See Datasets for more details.
Can you write Python code for it?

b.add_dataset('orb', compute_times=np.linspace(0,4,1000), dataset='orb01', component=['primary', 'secondary'])

times, fluxes, sigmas = np.loadtxt('test.lc.in', unpack=True)

b.add_dataset('lc', times=times, fluxes=fluxes, sigmas=sigmas, dataset='lc01')


I am working on the file "2.2/tutorials/plotting.ipynb".
The first task is:
Axes Limits
Axes limits are determined by the data automatically.  To set custom axes limits, either use matplotlib methods on the returned axes objects, or pass limits as a list or tuple.
Can you write Python code for it?

afig, mplfig = b['orb01@primary@run_with_incl_80'].plot(xlim=(-2,2), show=True)


I am working on the file "2.2/tutorials/plotting.ipynb".
The first task is:
Choosing colors works slightly differently for meshes (ie you can set fc for facecolor and ec for edgecolor).  For more details, see the tutorial on the MESH dataset.
Colormaps
The colormaps is determined automatically based on the parameter used for coloring (ie RVs will be a red-blue colormap).  To override this, pass a matplotlib recognized colormap to the cmap keyword.
Can you write Python code for it?

afig, mplfig = b['orb01@primary@run_with_incl_80'].plot(x='times', c='vws', cmap='spring', show=True)


I am working on the file "2.2/tutorials/plotting.ipynb".
The first task is:
Colors
Colors of points and lines, by default, cycle according to matplotlib's color policy.  To manually set the color, simply pass a matplotlib recognized color to the 'c' keyword.
Can you write Python code for it?

afig, mplfig = b['orb01@primary@run_with_incl_80'].plot(c='r', show=True)


I am working on the file "2.2/tutorials/plotting.ipynb".
The first task is:
Errorbars
In the cases of observational data, errorbars can be added by passing the name of the column.
Can you write Python code for it?

afig, mplfig = b['lc01@dataset'].plot(yerror='sigmas', show=True)


I am working on the file "2.2/tutorials/plotting.ipynb".
The first task is:
For more information on each of the available arrays, see the relevant tutorial on that dataset method:

ORB dataset
MESH dataset
LC dataset
RV dataset
LP dataset

Selecting Phase
And to plot in phase we just send x='phases' or x='phases:binary'.
Setting x='phases' will use the ephemeris from the top-level of the hierarchy
(as if you called b.get_ephemeris()), whereas passing a string after the colon,
will use the ephemeris of that component.
Can you write Python code for it?

afig, mplfig = b.plot(dataset='lc01', x='phases', z=0, show=True)


I am working on the file "2.2/tutorials/plotting.ipynb".
The first task is:
Labels and Legends
To add a legend, include legend=True.
For details on placement and formatting of the legend see matplotlib's documentation.
Can you write Python code for it?

afig, mplfig = b['orb@run_with_incl_80'].plot(show=True, legend=True)


I am working on the file "2.2/tutorials/plotting.ipynb".
The first task is:
Note that when plotting in phase, PHOEBE will automatically sort and connect points in phase-order when plotting against phase if the system is not time-dependent (see b.hierarchy.is_time_dependent).  Otherwise, the points will be sorted and conencted in time-order - with breaks automatically applied to handle intelligent phase-wrapping.  In the vast majority of cases, this default behavior should make sense, but can always be overridden by passing 'times' or 'phases' to i (see the plot API docs for more details).
Units
Likewise, each array that is plotted is automatically plotted in its default units. To override these defaults, simply provide the unit (as a string or as a astropy units object) for a given axis.
Can you write Python code for it?

afig, mplfig = b['orb01@primary@run_with_incl_80'].plot(xunit='AU', yunit='AU', show=True)


I am working on the file "2.2/tutorials/plotting.ipynb".
The first task is:
Other Plotting Options
Valid plotting options that are directly passed to matplotlib include:
- linestyle
- marker
Note that sizes (markersize, linewidth) should be handled by passing the size to 's' and attempting to set markersize or linewidth directly will raise an error.  See also the autofig documention on size scales.
Can you write Python code for it?

afig, mplfig = b['orb01@primary@run_with_incl_80'].plot(linestyle=':', s=0.1, show=True)


I am working on the file "2.2/tutorials/plotting.ipynb".
The first task is:
Selecting Datasets
In addition to filtering and calling plot on the resulting ParameterSet, plot can accept a twig or filter on any of the available parameter tags.
For this reason, any of the following give identical results:
Can you write Python code for it?

afig, mplfig = b['primary@orb@run_with_incl_80'].plot(show=True)

afig, mplfig = b.plot(component='primary', kind='orb', model='run_with_incl_80', show=True)

afig, mplfig = b.plot('primary@orb@run_with_incl_80', show=True)


I am working on the file "2.2/tutorials/plotting.ipynb".
The first task is:
Showing and Saving
NOTE: in IPython notebooks calling plot will display directly below the call to plot.  When not in IPython you have several options for viewing the figure:

call b.show or b.savefig after calling plot.
use the returned autofig and matplotlib figures however you'd like
pass show=True to the plot method.
pass save='myfilename' to the plot method, which is the same as calling plt.savefig('myfilename').

Default Plots
To see the options for plotting that are dataset-dependent see the tutorials on that dataset method:

ORB dataset
MESH dataset
LC dataset
RV dataset
LP dataset

By calling the plot method on the bundle (or any ParameterSet) without any arguments, a plot or series of subplots will be built based on the contents of that ParameterSet.
Can you write Python code for it?


I am working on the file "2.2/tutorials/plotting.ipynb".
The first task is:
The legend labels are generated automatically, but can be overriden by passing a string to the label keyword.
Can you write Python code for it?

afig, mplfig = b['primary@orb@run_with_incl_80'].plot(label='primary')
afig, mplfig = b['secondary@orb@run_with_incl_80'].plot(label='secondary', legend=True, show=True)


I am working on the file "2.2/tutorials/plotting.ipynb".
The first task is:
This first line is only necessary for ipython noteboooks - it allows the plots to be shown on this page instead of in interactive mode
Can you write Python code for it?


I am working on the file "2.2/tutorials/plotting.ipynb".
The first task is:
To change the style of the "highlighted" points, you can pass matplotlib recognized markers, colors, and markersizes to the highlight_marker, highlight_color, and highlight_ms keywords, respectively.
Can you write Python code for it?

afig, mplfig = b['orb@run_with_incl_80'].plot(time=1.0, highlight_marker='s', highlight_color='g', highlight_ms=20, show=True)


I am working on the file "2.2/tutorials/plotting.ipynb".
The first task is:
To disable the errorbars, simply set yerror=None.
Can you write Python code for it?

afig, mplfig = b['lc01@dataset'].plot(yerror=None, show=True)


I am working on the file "2.2/tutorials/plotting.ipynb".
The first task is:
To see the list of available qualifiers that could be passed for x or y, call the qualifiers (or twigs) property on the ParameterSet.
Can you write Python code for it?


I am working on the file "2.2/tutorials/plotting.ipynb".
The first task is:
WARNING: when plotting two arrays with the same dimensions, PHOEBE attempts to set the aspect ratio to equal, but overriding to use two different units will result in undesired results.  This may be fixed in the future, but for now can be avoided by using consistent units for the x and y axes when they have the same dimensions.
Axes Labels
Axes labels are automatically generated from the qualifier of the array and the plotted units.  To override these defaults, simply pass a string for the label of a given axis.
Can you write Python code for it?

afig, mplfig = b['orb01@primary@run_with_incl_80'].plot(xlabel='X POS', ylabel='Z POS', show=True)


I am working on the file "2.2/tutorials/reflection_heating.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new bundle.  See Building a System for more details.
Can you write Python code for it?

%matplotlib inline

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

logger = phoebe.logger('error')

b = phoebe.default_binary()


I am working on the file "2.2/tutorials/reflection_heating.ipynb".
The first task is:
In order to see the effect of reflection, let's set "irrad_frac_refl_bol" of both of our stars to 0.9 - that is 90% of the incident flux will go towards reflection and 10% will be ignored.
Can you write Python code for it?


I am working on the file "2.2/tutorials/reflection_heating.ipynb".
The first task is:
Influence on Light Curves (fluxes)
Can you write Python code for it?


I am working on the file "2.2/tutorials/reflection_heating.ipynb".
The first task is:
Influence on Meshes (Intensities)
Can you write Python code for it?

b.add_dataset('mesh', times=[0.2], columns=['intensities@lc01'])

b.run_compute(irrad_method='none', ntriangles=700, model='refl_false', overwrite=True)

b.run_compute(irrad_method='wilson', ntriangles=700, model='refl_true', overwrite=True)

afig, mplfig = b.plot(component='secondary', kind='mesh', model='refl_false', fc='intensities', ec='face', show=True)

afig, mplfig = b.plot(component='secondary', kind='mesh', model='refl_true', fc='intensities', ec='face', show=True)


I am working on the file "2.2/tutorials/reflection_heating.ipynb".
The first task is:
Let's run models with the reflection switch both turned on and off so that we can compare the two results.  We'll also override delta to be a larger number since the computation time required by delta depends largely on the number of surface elements.
Can you write Python code for it?

b.run_compute(irrad_method='none', ntriangles=700, model='refl_false')

b.run_compute(irrad_method='wilson', ntriangles=700, model='refl_true')

afig, mplfig = b.plot(show=True, legend=True)

artists = plt.plot(b['value@times@refl_false'], b['value@fluxes@refl_true']-b['value@fluxes@refl_false'], 'r-')


I am working on the file "2.2/tutorials/reflection_heating.ipynb".
The first task is:
Reflection has the most noticeable effect when the two stars are close to each other and have a large temperature ratio.
Can you write Python code for it?

b['sma@orbit'] = 4.0

b['teff@primary'] = 10000

b['teff@secondary'] = 5000


I am working on the file "2.2/tutorials/reflection_heating.ipynb".
The first task is:
Since reflection can be a computationally expensive process and in most cases is a low-order effect, there is a switch in the compute options that needs to be enabled in order for reflection to be taken into account.  If this switch is False (which it is by default), the albedos are completely ignored and will be treated as if all incident light is lost/ignored.
Can you write Python code for it?


I am working on the file "2.2/tutorials/requiv.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new Bundle.  See Building a System for more details.
Can you write Python code for it?

%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()


I am working on the file "2.2/tutorials/requiv.ipynb".
The first task is:
At this time, if you were to call run_compute, an error would be thrown.  An error isn't immediately thrown when setting requiv, however, since the overflow can be recitified by changing any of the other relevant parameters.  For instance, let's change sma to be large enough to account for this value of rpole and you'll see that the error does not occur again.
Can you write Python code for it?


I am working on the file "2.2/tutorials/requiv.ipynb".
The first task is:
Now let's add a mesh dataset at a few different times so that we can see how the potentials affect the surfaces of the stars.
Can you write Python code for it?


I am working on the file "2.2/tutorials/requiv.ipynb".
The first task is:
These logger warnings are handy when running phoebe interactively, but in a script its also handy to be able to check whether the system is currently computable /before/ running run_compute.
This can be done by calling run_checks which returns a boolean (whether the system passes all checks) and a message (a string describing the first failed check).
Can you write Python code for it?

print(b.run_checks())

b.set_value('sma@binary@component', 5)

print(b.run_checks())


I am working on the file "2.2/tutorials/requiv_crit_contact.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new Bundle.  See Building a System for more details.
Can you write Python code for it?

%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(contact_binary=True)


I am working on the file "2.2/tutorials/requiv_crit_contact.ipynb".
The first task is:
Changing Parameterization
It is possible to change this parameterization to allow any one of the four parameters (requiv@primary, requiv@secondary, pot@contact_envelope, fillout_factor@contact_envelope) to be adjustable and the other two to be constrained.  Doing so requires flipping one or two constraints via b.flip_constraint().
Let's first flip the  constraints so that we can provide the potential of the envelope.
Can you write Python code for it?

b.flip_constraint('pot', solve_for='requiv@primary')

print(b.filter(qualifier=['requiv', 'pot', 'fillout_factor']))


I am working on the file "2.2/tutorials/requiv_crit_contact.ipynb".
The first task is:
Or we could instead flip two constraints to have fillout factor of the envelope as the adjustable parameter (we'll start with a fresh bundle just to avoid confusion with the flipping we just did):
Can you write Python code for it?

b = phoebe.default_binary(contact_binary=True)
b.flip_constraint('pot', solve_for='requiv@primary')
b.flip_constraint('fillout_factor', solve_for='pot')

print(b.filter(qualifier=['requiv', 'pot', 'fillout_factor']))


I am working on the file "2.2/tutorials/requiv_crit_detached.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new Bundle.  See Building a System for more details.
Can you write Python code for it?


I am working on the file "2.2/tutorials/requiv_crit_detached.ipynb".
The first task is:
Detached Systems
Detached systems are the default case for default_binary.  The requiv_max parameter is constrained to show the maximum value for requiv before the system will begin overflowing at periastron.
Can you write Python code for it?


I am working on the file "2.2/tutorials/requiv_crit_detached.ipynb".
The first task is:
If we increase 'requiv' past the critical point, we'll receive a warning from the logger and would get an error if attempting to call b.run_compute().
Can you write Python code for it?

b['requiv@primary'] = 2.2

print(b.run_checks())


I am working on the file "2.2/tutorials/requiv_crit_detached.ipynb".
The first task is:
We can see that the default system is well within this critical value by printing all radii and critical radii.
Can you write Python code for it?


I am working on the file "2.2/tutorials/requiv_crit_semidetached.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new Bundle.  See Building a System for more details.
Can you write Python code for it?


I am working on the file "2.2/tutorials/requiv_crit_semidetached.ipynb".
The first task is:
Now whenever any of the relevant parameters (q, ecc, syncpar, sma) are changed, the value of requiv will change to match the critical value as defined by requiv_max.
Can you write Python code for it?


I am working on the file "2.2/tutorials/settings.ipynb".
The first task is:
Accessing Settings
Settings are found with their own context in the Bundle and can be accessed through the get_setting method
Can you write Python code for it?


I am working on the file "2.2/tutorials/settings.ipynb".
The first task is:
If you want dictionary access to use set_value_all instead of set_value, you can enable this parameter
Can you write Python code for it?

b['dict_set_all@setting'] = True
b['teff@component'] = 8000
print(b['value@teff@primary@component'], b['value@teff@secondary@component'])


I am working on the file "2.2/tutorials/settings.ipynb".
The first task is:
In our default binary there are temperatures ('teff') parameters for each of the components ('primary' and 'secondary').  If we were to do:
b['teff@component'] = 6000
this would raise an error.  Under-the-hood, this is simply calling:
b.set_value('teff@component', 6000)
which of course would also raise an error.
In order to set both temperatures to 6000, you would either have to loop over the components or call the set_value_all method:
Can you write Python code for it?

b.set_value_all('teff@component', 4000)
print(b['value@teff@primary@component'], b['value@teff@secondary@component'])


I am working on the file "2.2/tutorials/settings.ipynb".
The first task is:
In our default binary, there are several inclination parameters - one for each component ('primary', 'secondary', 'binary') and one with the constraint context (to keep the inclinations aligned).
This can be inconvenient... if you want to set the value of the binary's inclination, you must always provide extra information (like '@component').
Instead, we can always have the dictionary access search in the component context by doing the following
Can you write Python code for it?

b['dict_filter@setting'] = {'context': 'component'}

b['incl']


I am working on the file "2.2/tutorials/settings.ipynb".
The first task is:
Now let's disable this so it doesn't confuse us while looking at the other options
Can you write Python code for it?

b.set_value_all('teff@component', 6000)
b['dict_set_all@setting'] = False


I am working on the file "2.2/tutorials/settings.ipynb".
The first task is:
Now let's reset this option... keeping in mind that we no longer have access to the 'setting' context through twig access, we'll have to use methods to clear the dict_filter
Can you write Python code for it?


I am working on the file "2.2/tutorials/settings.ipynb".
The first task is:
Now we no longer see the constraint parameters.
All parameters are always accessible with method access:
Can you write Python code for it?


I am working on the file "2.2/tutorials/settings.ipynb".
The first task is:
and can be set as any other Parameter in the Bundle
Available Settings
Now let's look at each of the available settings and what they do
log_history
log_history is a BooleanParameter (defaults to False) that controls whether undo/redo ability is enabled.
Can you write Python code for it?


I am working on the file "2.2/tutorials/settings.ipynb".
The first task is:
dict_filter
dict_filter is a Parameter that accepts a dictionary.  This dictionary will then always be sent to the filter call which is done under-the-hood during dictionary access.
Can you write Python code for it?


I am working on the file "2.2/tutorials/settings.ipynb".
The first task is:
dict_set_all
dict_set_all is a BooleanParameter (defaults to False) that controls whether attempting to set a value to a ParameterSet via dictionary access will set all the values in that ParameterSet (if True) or raise an error (if False)
Can you write Python code for it?


I am working on the file "2.2/tutorials/spots.ipynb".
The first task is:
Adding Spots
Let's add one spot to each of our stars in the binary.
A spot is a feature, and needs to be attached directly to a component upon creation.  Providing a tag for 'feature' is entirely optional - if one is not provided it will be created automatically.
Can you write Python code for it?


I am working on the file "2.2/tutorials/spots.ipynb".
The first task is:
At a later time, the spot is still technically at the same coordinates, but longitude of 0 no longer corresponds to pointing to the companion star.  The coordinate system has rotated along with the asyncronous rotation of the star.
Can you write Python code for it?

afig, mplfig = b.plot(time=0.25, y='ws', fc='teffs', facecmap='YlOrRd', ec='None', show=True)

afig, mplfig = b.plot(time=0.5, y='ws', fc='teffs', facecmap='YlOrRd', ec='None', show=True)

ax, artists = b.plot(time=0.75, y='ws', fc='teffs', facecmap='YlOrRd', ec='None', show=True)


I am working on the file "2.2/tutorials/spots.ipynb".
The first task is:
Relevant Parameters
A spot is defined by the colatitude (where 0 is defined as the North (spin) Pole) and longitude (where 0 is defined as pointing towards the other star for a binary, or to the observer for a single star) of its center, its angular radius, and the ratio of temperature of the spot to the local intrinsic value.
Can you write Python code for it?

print(b['spot01'])

b.set_value(qualifier='relteff', feature='spot01', value=0.9)

b.set_value(qualifier='radius', feature='spot01', value=30)

b.set_value(qualifier='colat', feature='spot01', value=45)

b.set_value(qualifier='long', feature='spot01', value=90)


I am working on the file "2.2/tutorials/spots.ipynb".
The first task is:
Since the syncpar was set to 1.5, one full orbit later the star (and the spot) has made an extra half-rotation.
Can you write Python code for it?

ax, artists = b.plot(time=1.0, y='ws', fc='teffs', facecmap='YlOrRd', ec='None', show=True)


I am working on the file "2.2/tutorials/spots.ipynb".
The first task is:
Spot Corotation
The positions (colat, long) of a spot are defined at t0 (note: t0@system, not necessarily t0_perpass or t0_supconj).  If the stars are not synchronous, then the spots will corotate with the star.  To illustrate this, let's set the syncpar > 1 and plot the mesh at three different phases from above.
Can you write Python code for it?

b.set_value('syncpar@primary', 1.5)

b.run_compute(irrad_method='none')


I am working on the file "2.2/tutorials/t0s.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new Bundle.  See Building a System for more details.
Can you write Python code for it?


I am working on the file "2.2/tutorials/t0s.ipynb".
The first task is:
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).
Can you write Python code for it?


I am working on the file "2.2/tutorials/t0s.ipynb".
The first task is:
Influence on Oribits (positions)
Can you write Python code for it?

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

b.run_compute(ltte=False)


I am working on the file "2.2/tutorials/t0s.ipynb".
The first task is:
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.
Can you write Python code for it?

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

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

afig, mplfig = b['lc01@model'].plot(x='phases', t0='t0_supconj', xlim=(-0.3,0.3), show=True)

afig, mplfig = b['lc01@model'].plot(x='phases', t0='t0_perpass', xlim=(-0.3,0.3), show=True)

afig, mplfig = b['lc01@model'].plot(x='phases', t0='t0_ref', xlim=(-0.3,0.3), show=True)


I am working on the file "2.2/tutorials/t0s.ipynb".
The first task is:
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.
Can you write Python code for it?

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

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


I am working on the file "2.2/tutorials/vgamma.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new Bundle.  See Building a System for more details.
Can you write Python code for it?

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

logger = phoebe.logger()

b = phoebe.default_binary()


I am working on the file "2.2/tutorials/vgamma.ipynb".
The first task is:
As you can see, since the center of mass of the system was at 0,0,0 at t0 - including systemic velocity actually shows the system spiraling towards or away from the observer (who is in the positive w direction).  In other words - the positions of the meshes are affected in the same way as the orbits (note the offset on the ylimit scales).
In addition, the actual values of vw and rv in the meshes are adjusted to include the systemic velocity.
Can you write Python code for it?

b['primary@mesh1@0_false'].get_value('vws', time=0.0)[:5]

b['primary@mesh1@100_false'].get_value('vws', time=0.0)[:5]

b['primary@mesh1@100_true'].get_value('vws', time=0.0)[:5]


I am working on the file "2.2/tutorials/vgamma.ipynb".
The first task is:
Changing Systemic Velocity and LTTE
By default, vgamma is initially set to 0.0
Can you write Python code for it?


I am working on the file "2.2/tutorials/vgamma.ipynb".
The first task is:
Influence on Light Curves (fluxes)
Now let's compare the various models across all our different datasets.
Let's set the colors so that all figures will have systemic velocity shown in blue, systemic velocity with ltte=False in red, and systemic velocity with ltte=True in green.
Can you write Python code for it?


I am working on the file "2.2/tutorials/vgamma.ipynb".
The first task is:
Influence on Meshes
Can you write Python code for it?

afig, mplfig = b.filter(kind='mesh', model=['0_false', '100_false']).plot(x='us', y='ws',
                                                                          axorder={'mesh1': 0, 'mesh2': 1},
                                                                          subplot_grid=(1,2), tight_layout=True, show=True)

afig, mplfig = b.filter(kind='mesh', model=['100_false', '100_true']).plot(x='us', y='ws',
                                                                          axorder={'mesh1': 0, 'mesh2': 1},
                                                                          subplot_grid=(1,2), tight_layout=True, show=True)


I am working on the file "2.2/tutorials/vgamma.ipynb".
The first task is:
Influence on Orbits (positions, velocities)
In the orbit, the addition of a systemic velocity affects both the positions and velocities.  So if we plot the orbits from above (u-w plane) we can see see orbit spiral in the w-direction.  Note that this actually shows the barycenter of the orbit moving - and it was only at 0,0,0 at t0.  This also stresses the importance of using a reasonable t0 - here 900 days later, the barycenter has moved significantly from the center of the coordinate system.
Can you write Python code for it?

afig, mplfig = b.filter(kind='orb', model=['0_false', '100_false']).plot(x='us', y='ws',
                             c=colors, linestyle='solid',
                             axorder={'orb1': 0, 'orb2': 1},
                             subplot_grid=(1,2), tight_layout=True, show=True)


I am working on the file "2.2/tutorials/vgamma.ipynb".
The first task is:
Influence on Radial Velocities
Radial velocities are perhaps the most logical observable in the case of systemic velocities.  Introducing a non-zero value for vgamma simply offsets the observed values.
Light-time will have a similar affect on RVs as it does on LCs - it simply changes the observed period.
Can you write Python code for it?

afig, mplfig = b['rv'].plot(c=colors, linestyle='solid',
                            axorder={'rv1': 0, 'rv2': 1},
                            subplot_grid=(1,2), tight_layout=True, show=True)


I am working on the file "2.2/tutorials/vgamma.ipynb".
The first task is:
Now we'll create empty lc, rv, orb, and mesh datasets.  We'll then look to see how the systemic velocity (vgamma) affects the observables in each of these datasets, and how those are also affected by light-time effects (ltte).
To see the effects over long times, we'll compute one cycle starting at t=0, and another in the distant future.
Can you write Python code for it?

times1 = np.linspace(0,1,201)
times2 = np.linspace(90,91,201)

b.add_dataset('lc', times=times1, dataset='lc1')
b.add_dataset('lc', times=times2, dataset='lc2')

b.add_dataset('rv', times=times1, dataset='rv1')
b.add_dataset('rv', times=times2, dataset='rv2')

b.add_dataset('orb', times=times1, dataset='orb1')
b.add_dataset('orb', times=times2, dataset='orb2')

b.add_dataset('mesh', times=[0], dataset='mesh1', columns=['vws'])
b.add_dataset('mesh', times=[90], dataset='mesh2', columns=['vws'])


I am working on the file "2.2/tutorials/vgamma.ipynb".
The first task is:
The option to enable or disable LTTE are in the compute options, we can either set ltte or we can just temporarily pass a value when we call run_compute.
Can you write Python code for it?


I am working on the file "2.3 Deep Convolutional Neural Networks.ipynb".
The first task is:
<img src="imgs/imagenet/apricot_696.jpeg" >
Can you write Python code for it?

img_path = os.path.join(IMAGENET_FOLDER, 'apricot_696.jpeg')
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
print('Input image shape:', x.shape)

preds = vgg16.predict(x)
print('Predicted:', decode_predictions(preds))


I am working on the file "2.3 Deep Convolutional Neural Networks.ipynb".
The first task is:
<img src="imgs/imagenet/strawberry_1157.jpeg" >
Can you write Python code for it?

from keras.preprocessing import image
import numpy as np

img_path = os.path.join(IMAGENET_FOLDER, 'strawberry_1157.jpeg')
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
print('Input image shape:', x.shape)

preds = vgg16.predict(x)
print('Predicted:', decode_predictions(preds))


I am working on the file "2.3 Deep Convolutional Neural Networks.ipynb".
The first task is:
Hands On:
Try to do the same with VGG19 Model
Can you write Python code for it?


I am working on the file "2.3 Deep Convolutional Neural Networks.ipynb".
The first task is:
If you're wondering where this HDF5 files with weights is stored, please take a look at ~/.keras/models/
HandsOn VGG16 - Pre-trained Weights
Can you write Python code for it?

IMAGENET_FOLDER = 'imgs/imagenet'  #in the repo

!ls imgs/imagenet


I am working on the file "2.3 Deep Convolutional Neural Networks.ipynb".
The first task is:
Residual Networks

ResNet 50

Can you write Python code for it?


I am working on the file "2.3.transport_through_barrier.ipynb".
The first task is:
"MOSFET" toy model
Let's construct a system like the wire of the previous notebook, except that the scattering region will have a higher (but still flat) potential.
The leads are unchanged, so we take the following function directly from the previous notebook.
Can you write Python code for it?

def make_lead_x(W=10, t=1):
    syst = kwant.Builder(kwant.TranslationalSymmetry([-1, 0]))
    syst[(lat(0, y) for y in range(W))] = 4 * t
    syst[lat.neighbors()] = -t
    return syst


I am working on the file "2.3.transport_through_barrier.ipynb".
The first task is:
Let's put the above functions to some use:
Can you write Python code for it?

_syst = make_wire_with_flat_potential()
kwant.plot(_syst)
_syst = _syst.finalized()
kwant.plotter.bands(_syst.leads[0])
plot_transmission(_syst, 1, np.linspace(-2, 0, 51))


I am working on the file "2.3.transport_through_barrier.ipynb".
The first task is:
The following function also needs to be modified slightly: instead of plotting transmission as a function of energy, it plots transmission as the function of the Hamiltonian parameter, for a fixed energy.
Observe how args=[param] is used to pass the user-specified Hamiltonian parameters to kwant.smatrix.  args must be a sequence of parameters, even if it's only a single one in this case.
Can you write Python code for it?

def plot_transmission(syst, energy, params):
    # Compute conductance
    trans = []
    for param in params:
        smatrix = kwant.smatrix(syst, energy, args=[param])
        trans.append(smatrix.transmission(1, 0))
    pyplot.plot(params, trans)


I am working on the file "2.3.transport_through_barrier.ipynb".
The first task is:
The function below is almost like make_wire_with_flat_potential.  The difference is that it can be tuned to use a general potential using its first parameter.
Can you write Python code for it?

def make_barrier(pot, W=40, L=70, t=1):
    def onsite(*args):
        return 4 * t - pot(*args)

    # Construct the scattering region.
    sr = kwant.Builder()
    sr[(lat(x, y) for x in range(L) for y in range(W))] = onsite
    sr[lat.neighbors()] = -t

    # Build and attach lead from both sides.
    lead = make_lead_x(W, t)
    sr.attach_lead(lead)
    sr.attach_lead(lead.reversed())

    return sr


I am working on the file "2.3.transport_through_barrier.ipynb".
The first task is:
The next one is slightly modified: the onsite value is now no longer a constant but a value function.
Kwant’s value functions are used when there are parameters to the Hamiltonian.  Kwant will call them only when a calculation is requested, at the last possible moment.  The onsite function always take one arguments (the site), and an arbitrary number of parameters that are supplied by the user.  Here, there is only one such parameter: V.
Can you write Python code for it?

def make_wire_with_flat_potential(W=10, L=2, t=1):
    def onsite(s, V):
        return (4 - V) * t

    # Construct the scattering region.
    sr = kwant.Builder()
    sr[(lat(x, y) for x in range(L) for y in range(W))] = onsite
    sr[lat.neighbors()] = -t

    # Build and attach lead from both sides.
    lead = make_lead_x(W, t)
    sr.attach_lead(lead)
    sr.attach_lead(lead.reversed())

    return sr


I am working on the file "2.3/examples/animation_binary_complete.ipynb".
The first task is:
Adding Datasets
Can you write Python code for it?

times = np.linspace(0,1,21)

b.add_dataset('lc', times=times, dataset='lc01')

b.add_dataset('rv', times=times, dataset='rv01')

b.add_dataset('mesh', times=times, columns=['visibilities', 'intensities@lc01', 'rvs@rv01'], dataset='mesh01')


I am working on the file "2.3/examples/animation_binary_complete.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new bundle.
Can you write Python code for it?


I am working on the file "2.3/examples/backends_compare_legacy_jktebop_ellc.ipynb".
The first task is:
Next we'll import matplotlib and set some figure options before importing phoebe
Can you write Python code for it?

import matplotlib.pyplot as plt

plt.rc('font', family='serif', size=14, serif='STIXGeneral')
plt.rc('mathtext', fontset='stix')

import phoebe

def run_comparison_models(b):
    b.add_compute('legacy')
    b.add_compute('ellc', rv_method='flux-weighted')
    # for jktebop, we'll use requiv_max_limit=1.0 to allow the semi-detached case to run
    b.add_compute('jktebop', requiv_max_limit=1.0)

    b.add_dataset('lc', compute_phases=phoebe.linspace(0,1,1001))
    b.add_dataset('rv', compute_phases=phoebe.linspace(0,1,1001))

    if True:
        b.set_value_all('irrad_method', 'none')  # if not using this, then we need to use dynamical RVs for ellc
    else:
        b.set_value_all('rv_method', kind='ellc', value='dynamical')

    b.set_value_all('pblum_method', 'phoebe')

    b.set_value_all('ld_mode', 'lookup')
    b.set_value_all('ld_func', 'linear')

    b.run_compute(kind='phoebe', model='phoebe2_model', ntriangles=3000)
    b.run_compute(kind='legacy', model='phoebe1_model', gridsize=60)
    b.run_compute(kind='ellc', model='ellc_model')
    b.run_compute(kind='jktebop', model='jktebop_model')
    return b


I am working on the file "2.3/examples/backends_compare_legacy_jktebop_ellc.ipynb".
The first task is:
Semi-Detached Case
Can you write Python code for it?

b = phoebe.default_binary(semidetached='secondary')

b.set_value('period@binary', 3.0633292)
b.set_value('q@binary@component',0.24700)
b.set_value('ecc@binary@orbit', 0.0 )
b.set_value('requiv@primary@component', 2.8)
b.set_value('incl@orbit', 83.500)
b.set_value('sma@orbit', 15.9)

b.set_value('teff@primary', 12900.000000)
b.set_value('teff@secondary', 5500.000000)
b.set_value('gravb_bol@primary',1.0)
b.set_value('gravb_bol@secondary',0.32)
b.set_value('irrad_frac_refl_bol@primary',1.0)
b.set_value('irrad_frac_refl_bol@secondary',0.75)
b.set_value('per0@binary@orbit',0.0)

b = run_comparison_models(b)

afig, mplfig = b.plot(x='phase', context='model',
                      compute=['phoebe01', 'legacy01', 'ellc01'],
                      c={'phoebe2_model': 'blue', 'phoebe1_model': 'green', 'ellc_model': 'orange', 'jktebop_model': 'purple'},
                      ls={'phoebe2_model': 'solid', 'phoebe1_model': 'dashed', 'ellc_model': 'dotted', 'jktebop_model': '-.'},
                      legend={'lc': True},
                      show=True, save='figure_backends_compare_semidetached.pdf')


I am working on the file "2.3/examples/binary_misaligned_spots.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new bundle.
Can you write Python code for it?

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

logger = phoebe.logger()

b = phoebe.default_binary()

b.set_value(qualifier='pitch', component='primary', value=30)


I am working on the file "2.3/examples/binary_misaligned_spots.ipynb".
The first task is:
Comparing Light Curves
Note that the pitch means the polar spot is always facing towards the observer slightly, and so is always visible (unless eclipsed).
Can you write Python code for it?

afig, mplfig = b.plot(kind='lc', show=True, legend=True)


I am working on the file "2.3/examples/binary_misaligned_spots.ipynb".
The first task is:
Model without Spots
Can you write Python code for it?

b.add_dataset('lc', times=phoebe.linspace(0,1,101))

b.run_compute(irrad_method='none', model='no_spot')


I am working on the file "2.3/examples/binary_spots.ipynb".
The first task is:
Adding Spots
Let's add a spot to the primary component in our binary.
The 'colat' parameter defines the colatitude 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 the spots tutorial for more details.
Can you write Python code for it?

b.add_feature('spot', component='primary', feature='spot01', relteff=0.9, radius=30, colat=45, long=90)

b.run_compute(irrad_method='none', model='with_spot')


I am working on the file "2.3/examples/binary_spots.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new bundle.
Can you write Python code for it?

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

logger = phoebe.logger()

b = phoebe.default_binary()


I am working on the file "2.3/examples/binary_spots.ipynb".
The first task is:
Comparing Light Curves
Can you write Python code for it?

afig, mplfig = b.plot(show=True, legend=True)


I am working on the file "2.3/examples/contact_spots.ipynb".
The first task is:
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.
Can you write Python code for it?

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


I am working on the file "2.3/examples/contact_spots.ipynb".
The first task is:
If we set long to zero, the spot completely disappears (as there is nowhere in the neck that is still on the surface.
Can you write Python code for it?

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)


I am working on the file "2.3/examples/contact_spots.ipynb".
The first task is:
Model without Spots
Can you write Python code for it?

b.add_dataset('lc', times=phoebe.linspace(0,0.5,101))

b.run_compute(irrad_method='none', model='no_spot')


I am working on the file "2.3/examples/contact_spots.ipynb".
The first task is:
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.
Can you write Python code for it?

b.set_value('long', value=-30)

b.run_compute(irrad_method='none')

afig, mplfig = b.plot(fc='teffs', ec='face', fcmap='plasma', show=True)


I am working on the file "2.3/examples/detached_rotstar.ipynb".
The first task is:
Adding Datasets
Now we'll create an empty mesh dataset at quarter-phase so we can compare the difference between using roche and rotstar for deformation potentials:
Can you write Python code for it?


I am working on the file "2.3/examples/detached_rotstar.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new bundle.
Can you write Python code for it?


I am working on the file "2.3/examples/detached_rotstar.ipynb".
The first task is:
Now we'll compute synthetics at the times provided using the default options
Can you write Python code for it?

b.run_compute(irrad_method='none', distortion_method='roche', model='rochemodel')

b.run_compute(irrad_method='none', distortion_method='rotstar', model='rotstarmodel')


I am working on the file "2.3/examples/detached_rotstar.ipynb".
The first task is:
Plotting
Can you write Python code for it?

afig, mplfig = b.plot(model='rochemodel',show=True)

afig, mplfig = b.plot(model='rotstarmodel',show=True)


I am working on the file "2.3/examples/detached_rotstar.ipynb".
The first task is:
Running Compute
Let's set the radius of the primary component to be large enough to start to show some distortion when using the roche potentials.
Can you write Python code for it?


I am working on the file "2.3/examples/diher_misaligned.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new bundle.
Can you write Python code for it?

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

logger = phoebe.logger('error')

b = phoebe.default_binary()


I am working on the file "2.3/examples/diher_misaligned.ipynb".
The first task is:
Compute
Can you write Python code for it?


I am working on the file "2.3/examples/diher_misaligned.ipynb".
The first task is:
Datasets
Let's compute an LC and RV dataset sampled at 200 points in phase (with some aliasing).
Can you write Python code for it?

n = 200
times = b.to_time(np.linspace(-0.05, 1.05, n))

b.add_dataset('lc', times=times, dataset='lc01', ld_mode='manual', ld_func='logarithmic', ld_coeffs = [0.5,0.5])
b.add_dataset('rv', times=times, dataset='rv01', ld_mode='manual', ld_func='logarithmic', ld_coeffs = [0.5,0.5])


I am working on the file "2.3/examples/distortion_method_none.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new bundle.
Can you write Python code for it?


I am working on the file "2.3/examples/distortion_method_none.ipynb".
The first task is:
IMPORTANT NOTE: this can affect passband-luminosity scaling.  By default, PHOEBE will scale to the set pblum of the primary star, so if setting distortion_method of the 'primary' component to 'none', then everything will scale to a flux of zero.  In this case, you will want to provide the pblum of the secondary star instead by switching pblum_component or using pblum_mode='absolute'.
Can you write Python code for it?


I am working on the file "2.3/examples/distortion_method_none.ipynb".
The first task is:
Plotting
If we plot both models (with the secondary star meshed and without), we can see that we lost half of the flux (since the stars had the same luminosity) and are only left with the ellipsoidal variations of the primary component.
Can you write Python code for it?

_ = b.plot(kind='lc', legend=True, show=True)

_ = b.plot(kind='lc', model='distortion_method_none', show=True)


I am working on the file "2.3/examples/eccentric_ellipsoidal.ipynb".
The first task is:
Adding Datasets
We'll add light curve, orbit, and mesh datasets.
Can you write Python code for it?

b.add_dataset('lc',
              compute_times=phoebe.linspace(-2, 2, 201),
              dataset='lc01')

b.add_dataset('orb', compute_times=phoebe.linspace(-2, 2, 201))

anim_times = phoebe.linspace(-2, 2, 101)

b.add_dataset('mesh',
              compute_times=anim_times,
              coordinates='uvw',
              dataset='mesh01')


I am working on the file "2.3/examples/eccentric_ellipsoidal.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new bundle.
Can you write Python code for it?

import phoebe
import numpy as np

b = phoebe.default_binary()


I am working on the file "2.3/examples/eccentric_ellipsoidal.ipynb".
The first task is:
Now let's make a nice figure.
Let's go through these options:
* time: make the plot at this single time
* z: by default, orbits plot in 2d, but since we're overplotting with a mesh, we want the z-ordering to be correct, so we'll have them plot with w-coordinates in the z-direction.
* c: (will be ignored by the mesh): set the color to blue for the primary and red for the secondary (will only affect the orbits as the light curve is not tagged with any component).
* fc: (will be ignored by everything but the mesh): set the facecolor to be blue for the primary and red for the secondary.
* ec: disable drawing the edges of the triangles in a separate color.  We could also set this to 'none', but then we'd be able to "see-through" the triangle edges.
* uncover: for the orbit, uncover based on the current time.
* trail: for the orbit, let's show a "trail" behind the current position.
* highlight: disable highlighting for the orbit, since the mesh will be in the same position.
* tight_layout: use matplotlib's tight layout to ensure we have enough padding between axes to see the labels.
Can you write Python code for it?

afig, mplfig = b.plot(time=0.0,
                      z={'orb': 'ws'},
                      c={'primary': 'blue', 'secondary': 'red'},
                      fc={'primary': 'blue', 'secondary': 'red'},
                      ec='face',
                      uncover={'orb': True},
                      trail={'orb': 0.1},
                      highlight={'orb': False},
                      tight_layout=True,
                      show=True)


I am working on the file "2.3/examples/eccentric_ellipsoidal.ipynb".
The first task is:
Now we need a highly eccentric system that nearly overflows at periastron and is slightly eclipsing.
Can you write Python code for it?

b.set_value('q', value=0.7)
b.set_value('period', component='binary', value=10)
b.set_value('sma', component='binary', value=25)
b.set_value('incl', component='binary', value=0)
b.set_value('ecc', component='binary', value=0.9)

print(b.filter(qualifier='requiv*', context='component'))

b.set_value('requiv', component='primary', value=1.1)
b.set_value('requiv', component='secondary', value=0.9)


I am working on the file "2.3/examples/eccentric_ellipsoidal.ipynb".
The first task is:
Running Compute
Can you write Python code for it?


I am working on the file "2.3/examples/extinction_BK_binary.ipynb".
The first task is:
And flip the extinction constraint so we can provide E(B-V).
Can you write Python code for it?


I am working on the file "2.3/examples/extinction_BK_binary.ipynb".
The first task is:
And then create three light curve datasets at the same times, but in different passbands
Can you write Python code for it?

times = phoebe.linspace(-20, 20, 101)
b.add_dataset('lc', times=times, dataset='B', passband="Johnson:B")
b.add_dataset('lc', times=times, dataset='R', passband="Cousins:R")
b.add_dataset('lc', times=times, dataset='KEP', passband="Kepler:mean")


I am working on the file "2.3/examples/extinction_BK_binary.ipynb".
The first task is:
Lastly, we'll convert the model fluxes into magnitudes and format the figures.
Can you write Python code for it?

Bextmags=-2.5*np.log10(b['value@fluxes@B@ext@model'])
Bnoextmags=-2.5*np.log10(b['value@fluxes@B@noext@model'])
Bextmags_norm=Bextmags-Bextmags.min()+1
Bnoextmags_norm=Bnoextmags-Bnoextmags.min()+1
Bresid=Bextmags_norm-Bnoextmags_norm

Rextmags=-2.5*np.log10(b['value@fluxes@R@ext@model'])
Rnoextmags=-2.5*np.log10(b['value@fluxes@R@noext@model'])
Rextmags_norm=Rextmags-Rextmags.min()+1
Rnoextmags_norm=Rnoextmags-Rnoextmags.min()+1
Rresid=Rextmags_norm-Rnoextmags_norm

fig=plt.figure(figsize=(12,6))
gs=gridspec.GridSpec(2,2,height_ratios=[4,1],width_ratios=[1,1])

ax=plt.subplot(gs[0,0])
ax.plot(b['value@times@B@noext@model']/1000,Bnoextmags_norm,color='k',linestyle="--")
ax.plot(b['value@times@B@ext@model']/1000,Bextmags_norm,color='k',linestyle="-")
ax.set_ylabel('Magnitude')
ax.set_xticklabels([])
ax.set_xlim([-0.02,0.02])
ax.set_ylim([3.5,0.8])
ax.set_title('(a) Johnson B')

ax2=plt.subplot(gs[0,1])
ax2.plot(b['value@times@R@noext@model']/1000,Rnoextmags_norm,color='k',linestyle="--")
ax2.plot(b['value@times@R@ext@model']/1000,Rextmags_norm,color='k',linestyle="-")
ax2.set_ylabel('Magnitude')
ax2.set_xticklabels([])
ax2.set_xlim([-0.02,0.02])
ax2.set_ylim([3.5,0.8])
ax2.set_title('(b) Cousins Rc')

ax_1=plt.subplot(gs[1,0])
ax_1.plot(b['value@times@B@noext@model']/1000,Bresid,color='k',linestyle='-')
ax_1.set_ylabel(r'$\Delta m$')
ax_1.set_xlabel('Phase')
ax_1.set_xlim([-0.02,0.02])
ax_1.set_ylim([0.05,-0.3])
ax_1.axhline(y=0., linestyle='dashed',color='k',linewidth=0.5)

ax2_1=plt.subplot(gs[1,1])
ax2_1.plot(b['value@times@R@noext@model']/1000,Rresid,color='k',linestyle='-')
ax2_1.set_ylabel(r'$\Delta m$')
ax2_1.set_xlabel('Phase')
ax2_1.set_xlim([-0.02,0.02])
ax2_1.set_ylim([0.05,-0.3])
ax2_1.axhline(y=0.,...


I am working on the file "2.3/examples/extinction_eclipse_depth_v_teff.ipynb".
The first task is:
And flip the extinction constraint so we can provide E(B-V).
Can you write Python code for it?


I am working on the file "2.3/examples/extinction_eclipse_depth_v_teff.ipynb".
The first task is:
And then create three light curve datasets at the same times, but in different passbands
Can you write Python code for it?

times = phoebe.linspace(0, 10, 301)
b.add_dataset('lc', times=times, dataset='B', passband="Johnson:B")
b.add_dataset('lc', times=times, dataset='R', passband="Cousins:R")


I am working on the file "2.3/examples/extinction_eclipse_depth_v_teff.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new bundle.
Can you write Python code for it?

import matplotlib
matplotlib.rcParams['text.usetex'] = True
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42
matplotlib.rcParams['mathtext.fontset'] = 'stix'
matplotlib.rcParams['font.family'] = 'STIXGeneral'
from matplotlib import gridspec

%matplotlib inline

from astropy.table import Table

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

logger = phoebe.logger('error')

b = phoebe.default_binary()


I am working on the file "2.3/examples/extinction_eclipse_depth_v_teff.ipynb".
The first task is:
First we'll define the system parameters
Can you write Python code for it?

b['period@orbit']=10*u.d
b['teff@secondary']=5780.*u.K
b['requiv@secondary']=1.0*u.solRad
b.flip_constraint('mass@primary', solve_for='sma@binary')
b.flip_constraint('mass@secondary', solve_for='q')


I am working on the file "2.3/examples/extinction_eclipse_depth_v_teff.ipynb".
The first task is:
Now we'll set some atmosphere and limb-darkening options
Can you write Python code for it?

b.set_value_all('gravb_bol', 0.0)
b.set_value_all('ld_mode', 'manual')
b.set_value_all('ld_func', 'linear')
b.set_value_all('ld_coeffs', [0.0])


I am working on the file "2.3/examples/extinction_wd_subdwarf.ipynb".
The first task is:
And then a second model with extinction.
Can you write Python code for it?


I am working on the file "2.3/examples/legacy.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new bundle.
Can you write Python code for it?

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

phoebe.devel_on()  # needed to use WD-style meshing, which isn't fully supported yet

logger = phoebe.logger()

b = phoebe.default_binary()
b['q'] = 0.7
b['requiv@secondary'] = 0.7


I am working on the file "2.3/examples/legacy.ipynb".
The first task is:
Let's add compute options for phoebe using both the new (marching) method for creating meshes as well as the WD method which imitates the format of the mesh used within legacy.
Can you write Python code for it?

b.add_compute(compute='phoebe2marching', irrad_method='none', mesh_method='marching')

b.add_compute(compute='phoebe2wd', irrad_method='none', mesh_method='wd', eclipse_method='graham')


I am working on the file "2.3/examples/legacy.ipynb".
The first task is:
Let's make sure both 'phoebe1' and 'phoebe2wd' use the same value for gridsize
Can you write Python code for it?


I am working on the file "2.3/examples/legacy.ipynb".
The first task is:
Let's use the external atmospheres available for both phoebe1 and phoebe2
Can you write Python code for it?


I am working on the file "2.3/examples/legacy_contact_binary.ipynb".
The first task is:
Adding Datasets and Compute Options
Can you write Python code for it?

b.add_dataset('lc', times=np.linspace(0,1,101), dataset='lc01')
b.add_dataset('rv', times=np.linspace(0,1,101), dataset='rv01')


I am working on the file "2.3/examples/legacy_contact_binary.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new bundle.
Can you write Python code for it?

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

logger = phoebe.logger()

b = phoebe.default_binary(contact_binary=True)
b['q'] = 0.7


I am working on the file "2.3/examples/legacy_contact_binary.ipynb".
The first task is:
Now let's plot the residuals between these two models
Can you write Python code for it?

artist, = plt.plot(b.get_value('fluxes@lc01@phoebe2model') - b.get_value('fluxes@lc01@phoebe1model'), 'g-')
artist = plt.axhline(0.0, linestyle='dashed', color='k')


I am working on the file "2.3/examples/legacy_contact_binary.ipynb".
The first task is:
Now we add compute options for the 'legacy' backend.
Can you write Python code for it?


I am working on the file "2.3/examples/legacy_contact_binary.ipynb".
The first task is:
Plotting
Light Curve
Can you write Python code for it?

afig, mplfig = b.filter(dataset='lc01').plot(c={'phoebe2model': 'g', 'phoebe1model': 'r'}, linestyle='solid',
                                             legend=True, show=True)


I am working on the file "2.3/examples/legacy_contact_binary.ipynb".
The first task is:
RVs
Can you write Python code for it?

afig, mplfig = b['rv01'].plot(c={'phoebe2model': 'g', 'phoebe1model': 'r'}, linestyle='solid',
                              legend=True, show=True)

artist, = plt.plot(b.get_value('rvs@primary@phoebe2model', ) - b.get_value('rvs@primary@phoebe1model'), color='g', ls=':')
artist, = plt.plot(b.get_value('rvs@secondary@phoebe2model') - b.get_value('rvs@secondary@phoebe1model'), color='g', ls='-.')
artist = plt.axhline(0.0, linestyle='dashed', color='k')
ylim = plt.ylim(-0.3, 0.3)


I am working on the file "2.3/examples/legacy_spots.ipynb".
The first task is:
Adding Spots and Compute Options
Can you write Python code for it?

b.add_spot(component='primary', relteff=0.8, radius=20, colat=45, colon=90, feature='spot01')

b.add_dataset('lc', times=np.linspace(0,1,101))

b.add_compute('phoebe', irrad_method='none', compute='phoebe2')

b.add_compute('legacy', irrad_method='none', compute='phoebe1')


I am working on the file "2.3/examples/legacy_spots.ipynb".
The first task is:
Let's use the external atmospheres available for both phoebe1 and phoebe2
Can you write Python code for it?

b.set_value_all('atm', 'extern_planckint')

b.set_value_all('ld_mode', 'manual')
b.set_value_all('ld_func', 'logarithmic')
b.set_value_all('ld_coeffs', [0.0, 0.0])

b.run_compute('phoebe2', model='phoebe2model')

b.run_compute('phoebe1', model='phoebe1model')


I am working on the file "2.3/examples/legacy_spots.ipynb".
The first task is:
Plotting
Can you write Python code for it?

afig, mplfig = b.plot(legend=True, ylim=(1.95, 2.05), show=True)


I am working on the file "2.3/examples/mesh_wd.ipynb".
The first task is:
Adding Datasets
Next let's add a mesh dataset so that we can plot our Wilson-Devinney style meshes
Can you write Python code for it?

b.add_dataset('mesh', compute_times=[0, 0.5], dataset='mesh01', columns=['visibilities'])


I am working on the file "2.3/examples/mesh_wd.ipynb".
The first task is:
And now looking down from above.  Here you can see the gaps between the surface elements (and you can also see some of the subdivision that's taking place along the limb).
Can you write Python code for it?

afig, mplfig = b['primary@mesh01@model'].plot(time=0.0, x='us', y='ws',
                                              ec='blue', fc='gray',
                                              xlim=(-0.1,0.1), ylim=(-2.75,-2.55),
                                              show=True)


I am working on the file "2.3/examples/mesh_wd.ipynb".
The first task is:
And see which elements are visible at the current time.  This defaults to use the 'RdYlGn' colormap which will make visible elements green, partially hidden elements yellow, and hidden elements red.  Note that the observer is in the positive w-direction.
Can you write Python code for it?

afig, mplfig = b['secondary@mesh01@model'].plot(time=0.0, x='us', y='ws',
                                                ec='face', fc='visibilities',
                                                show=True)


I am working on the file "2.3/examples/mesh_wd.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new bundle.
Can you write Python code for it?

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

phoebe.devel_on() # CURRENTLY REQUIRED FOR WD-STYLE MESHING (WHICH IS EXPERIMENTAL)

logger = phoebe.logger()

b = phoebe.default_binary()


I am working on the file "2.3/examples/mesh_wd.ipynb".
The first task is:
Changing Meshing Options
Next we need to add compute options and change the mesh_style for all stars from 'marching' to 'wd'
Can you write Python code for it?

b.set_value_all('mesh_method', 'wd')
b.set_value_all('eclipse_method', 'graham')


I am working on the file "2.3/examples/mesh_wd.ipynb".
The first task is:
Now let's zoom in so we can see the layout of the triangles.  Note that Wilson-Devinney uses trapezoids, but since PHOEBE uses triangles, we take each of the trapezoids and split it into two triangles.
Can you write Python code for it?

afig, mplfig = b['primary@mesh01@model'].plot(time=0.0,  x='us', y='vs',
                                              ec='blue', fc='gray',
                                              xlim=(-0.2,0.2), ylim=(-0.2,0.2),
                                              show=True)


I am working on the file "2.3/examples/mesh_wd.ipynb".
The first task is:
Plotting
Can you write Python code for it?

afig, mplfig = b['mesh01@model'].plot(time=0.5, x='us', y='vs',
                                      show=True)


I am working on the file "2.3/examples/mesh_wd.ipynb".
The first task is:
Running Compute
Can you write Python code for it?


I am working on the file "2.3/examples/minimal_GPs.ipynb".
The first task is:
Add GPs
See the API docs for b.add_gaussian_process and gaussian_process.
Can you write Python code for it?

b.add_gaussian_process(dataset='lc01', kernel='sho')

b.add_gaussian_process(dataset='lc01', kernel='matern32')

print(b.get_gaussian_process())


I am working on the file "2.3/examples/minimal_GPs.ipynb".
The first task is:
Create a New System
Can you write Python code for it?

b = phoebe.default_binary()

b.add_dataset('lc', times=times, fluxes=fluxes, sigmas=sigmas)

afig, mplfig = b.plot(show=True)

afig, mplfig = b.plot(x='phases', show=True)

b.run_compute(model='withoutGPs')


I am working on the file "2.3/examples/minimal_GPs.ipynb".
The first task is:
Create fake "observations"
Can you write Python code for it?

b = phoebe.default_binary()

b.add_dataset('lc', compute_times=phoebe.linspace(0,5,501))

b.run_compute()

times = b.get_value(qualifier='times', context='model')
fluxes = b.get_value(qualifier='fluxes', context='model') + np.random.normal(size=times.shape) * 0.07 + 0.2*np.sin(times)
sigmas = np.ones_like(fluxes) * 0.05


I am working on the file "2.3/examples/minimal_GPs.ipynb".
The first task is:
Run Forward Model
Since the system itself is still time-independent, the model is computed for one cycle according to compute_phases, but is then interpolated at the phases of the times in the dataset to compute and expose the fluxes including gaussian processes at the dataset times.
If the model were time-dependent, then using compute_times or compute_phases without covering a sufficient time-span will raise an error.
Can you write Python code for it?

print(b.run_checks_compute())

b.flip_constraint('compute_phases', solve_for='compute_times')
b.set_value('compute_phases', phoebe.linspace(0,1,101))

print(b.run_checks_compute())

b.run_compute(model='withGPs')

afig, mplfig = b.plot(c={'withoutGPs': 'red', 'withGPs': 'green'},
                      ls={'withoutGPs': 'dashed', 'withGPs': 'solid'},
                      s={'model': 0.03},
                      save='figure_GPs_times.pdf',
                      show=True)

afig, mplfig = b.plot(c={'withoutGPs': 'red', 'withGPs': 'green'},
                      ls={'withoutGPs': 'dashed', 'withGPs': 'solid'},
                      s={'model': 0.03},
                      x='phases',
                      save='figure_GPs_phases.pdf', show=True)


I am working on the file "2.3/examples/minimal_contact_binary.ipynb".
The first task is:
Adding Datasets
Can you write Python code for it?

b.add_dataset('mesh', compute_times=[0], dataset='mesh01')

b.add_dataset('orb', compute_times=np.linspace(0,1,201), dataset='orb01')

b.add_dataset('lc', times=np.linspace(0,1,21), dataset='lc01')

b.add_dataset('rv', times=np.linspace(0,1,21), dataset='rv01')


I am working on the file "2.3/examples/minimal_contact_binary.ipynb".
The first task is:
Light Curves
Can you write Python code for it?

afig, mplfig = b['lc01@model'].plot(show=True)


I am working on the file "2.3/examples/minimal_contact_binary.ipynb".
The first task is:
Plotting
Meshes
Can you write Python code for it?

afig, mplfig = b['mesh01@model'].plot(x='ws', show=True)


I am working on the file "2.3/examples/minimal_synthetic.ipynb".
The first task is:
Running Compute
Now we'll compute synthetics at the times provided using the default options
Can you write Python code for it?


I am working on the file "2.3/examples/pblum_method_compare.ipynb".
The first task is:
And to avoid any issues with falling outside the atmosphere grids, we'll set a simple flat limb-darkening model and disable irradiation.
Can you write Python code for it?

b.set_value_all('ld_mode', 'manual')
b.set_value_all('ld_func', 'linear')
b.set_value_all('ld_coeffs', [0.5])
b.set_value_all('irrad_method', 'none')

b.set_value_all('atm', 'ck2004')

requiv_max = b.get_value('requiv_max', component='primary', context='component')
requiv_max_factors = np.arange(0.3,1.0,0.05)
sb_pblum_abs = np.zeros_like(requiv_max_factors)
ph_pblum_abs = np.zeros_like(requiv_max_factors)

for i,requiv_max_factor in enumerate(requiv_max_factors):
    b.set_value('requiv', component='primary', value=requiv_max_factor*requiv_max)

    sb_pblum_abs[i] = b.compute_pblums(compute='ellc01', pblum_method='stefan-boltzmann', pblum_abs=True)['pblum_abs@primary@lc01'].value
    ph_pblum_abs[i] = b.compute_pblums(compute='ellc01', pblum_method='phoebe', pblum_abs=True)['pblum_abs@primary@lc01'].value


I am working on the file "2.3/examples/pblum_method_compare.ipynb".
The first task is:
Here we can see that Stefan-Boltzmann (which assumes spherical stars) is an increasingly bad approximation as the distortion of the star increase (as expected).  But even in the quite detached case, the luminosities are not in great agreement.  For this reason it is important to not trust absolute pblum values when using pblum_method='stefan-boltzmann', but rather just use them as a nuisance parameter or original estimate to adjust the light-levels.
Can you write Python code for it?

_ = plt.plot(requiv_max_factors, sb_pblum_abs, 'k-', label='Stefan-Boltzmann')
_ = plt.plot(requiv_max_factors, ph_pblum_abs, 'b-', label='PHOEBE mesh')
_ = plt.xlabel('requiv / requiv_max')
_ = plt.ylabel('L (W)')
_ = plt.legend()


I am working on the file "2.3/examples/requiv_max_limit.ipynb".
The first task is:
And to avoid any issues with falling outside the atmosphere grids, we'll set a simple flat limb-darkening model and disable irradiation.
Can you write Python code for it?

b.set_value_all('ld_mode', 'manual')
b.set_value_all('ld_func', 'linear')
b.set_value_all('ld_coeffs', [0.5])
b.set_value_all('irrad_method', 'none')


I am working on the file "2.3/examples/requiv_max_limit.ipynb".
The first task is:
In order to allow jktebop to compute models, we'll set requiv_max_limit=1.0, effectively disabling the error that would otherwise be raised at a default factor of 0.5 by b.run_checks_compute.
Can you write Python code for it?


I am working on the file "2.3/examples/rossiter_mclaughlin.ipynb".
The first task is:
Adding Datasets
We'll add radial velocity, line profile, and mesh datasets.  We'll compute the rvs through the whole orbit, but the mesh and line profiles right around the eclipse - just at the times that we want to plot for an animation.
Can you write Python code for it?

anim_times = phoebe.arange(0.44, 0.56, 0.002)


I am working on the file "2.3/examples/rossiter_mclaughlin.ipynb".
The first task is:
And for the line-profile, we'll expose the line-profile for both of our stars separately, instead of for the entire system.
Can you write Python code for it?

b.add_dataset('lp',
              compute_times=anim_times,
              component=['primary', 'secondary'],
              wavelengths=phoebe.linspace(549.5,550.5,101),
              profile_rest=550)


I am working on the file "2.3/examples/rossiter_mclaughlin.ipynb".
The first task is:
First let's compare between the dynamical and numerical RVs.
The dynamical RVs show the velocity of the center of each star along the line of sight.  But the numerical method integrates over the visible surface elements, giving us what we'd observe if deriving RVs from observed spectra of the binary.  Here we do see the Rossiter McLaughlin effect.  You'll also notice that RVs are not available for the secondary star when its completely occulted (they're nans in the array).
Can you write Python code for it?

afig, mplfig = b.plot(kind='rv',
                      c=colors,
                      ls={'numericalrvs': 'solid', 'dynamicalrvs': 'dotted'},
                      show=True)


I am working on the file "2.3/examples/rossiter_mclaughlin.ipynb".
The first task is:
Here we can see that star in front (green) is eclipsing more of the blue-shifted part of the back star (magenta), distorting the line profile, causing the apparent center of the line profile to be shifted to the right/red, and therefore the radial velocities to be articially increased as compared to the dynamical RVs.
Now let's animate the same figure in time.  We'll use the same arguments as the static plot above, with the following exceptions:

times: pass our array of times that we want the animation to loop over.
pad_aspect: pad_aspect doesn't work with animations, so we'll disable to avoid the warning messages.
animate: self-explanatory.
save: we could use show=True, but that doesn't always play nice with jupyter notebooks
save_kwargs: may need to change these for your setup, to create a gif, passing {'writer': 'imagemagick'} is often useful.
Can you write Python code for it?

afig, mplanim = b.plot(times=anim_times,
                       fc='rvs@numericalrvs', ec='face',
                       c=colors,
                       ls={'numericalrvs': 'solid', 'dynamicalrvs': 'dotted'},
                       highlight={'numericalrvs': True, 'dynamicalrvs': False},
                       pad_aspect=False,
                       axpos={'mesh': 211, 'rv': 223, 'lp': 224},
                       xlim={'rv': (0.4, 0.6)}, ylim={'rv': (-80, 80)},
                       animate=True,
                       save='rossiter_mclaughlin.gif',
                       save_kwargs={'writer': 'imagemagick'})


I am working on the file "2.3/examples/rossiter_mclaughlin.ipynb".
The first task is:
Plotting
Throughout all of these plots, we'll color the components green and magenta (to differentiate them from the red and blue of the RV mapping).
Can you write Python code for it?

colors = {'primary': 'green', 'secondary': 'magenta'}


I am working on the file "2.3/examples/rossiter_mclaughlin.ipynb".
The first task is:
Running Compute
Can you write Python code for it?


I am working on the file "2.3/examples/rossiter_mclaughlin.ipynb".
The first task is:
We'll add two identical datasets, one where we compute only dynamical RVs (won't include Rossiter-McLaughlin) and another where we compute flux-weighted RVs (will include Rossiter-McLaughlin).
Can you write Python code for it?

b.add_dataset('rv',
              times=phoebe.linspace(0,1,201),
              dataset='dynamicalrvs')

b.set_value_all('rv_method', dataset='dynamicalrvs', value='dynamical')

b.add_dataset('rv',
              times=phoebe.linspace(0,1,201),
              dataset='numericalrvs')

b.set_value_all('rv_method', dataset='numericalrvs', value='flux-weighted')


I am working on the file "2.3/examples/single_spots.ipynb".
The first task is:
Adding Spots
Let's add one spot to our star.  Since there is only one star, the spot will automatically attach without needing to provide component (as is needed in the binary with spots example
Can you write Python code for it?

b.add_spot(radius=30, colat=80, long=0, relteff=0.9)


I am working on the file "2.3/examples/single_spots.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new bundle.
Can you write Python code for it?

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

logger = phoebe.logger()

b = phoebe.default_star()


I am working on the file "2.3/examples/single_spots.ipynb".
The first task is:
Spot Parameters
A spot is defined by the colatitude and longitude of its center, its angular radius, and the ratio of temperature of the spot to the local intrinsic value.
Can you write Python code for it?


I am working on the file "2.3/examples/spot_transit.ipynb".
The first task is:
Adding Datasets
Can you write Python code for it?

b.add_dataset('lc', compute_times=phoebe.linspace(-0.1, 0.1, 201))


I am working on the file "2.3/examples/spot_transit.ipynb".
The first task is:
Because we have such a cool transiting object, we'll have to use blackbody atmospheres and manually provide limb-darkening.
Can you write Python code for it?

b.set_value(qualifier='atm', component='secondary', value='blackbody')
b.set_value(qualifier='ld_mode', component='secondary', value='manual')

anim_times = phoebe.linspace(-0.1, 0.1, 101)

b.add_dataset('mesh', compute_times=anim_times, coordinates='uvw', columns='teffs')


I am working on the file "2.3/examples/spot_transit.ipynb".
The first task is:
Let's set reasonable (although not necessarily physical) values for the secondary component.
Can you write Python code for it?

b.flip_constraint('mass@secondary', solve_for='q')
b.set_value(qualifier='mass', component='secondary', value=0.2)
b.set_value(qualifier='requiv', component='secondary', value=0.2)
b.set_value(qualifier='teff', component='secondary', value=300)


I am working on the file "2.3/examples/spot_transit.ipynb".
The first task is:
Now let's animate the same figure in time.  We'll use the same arguments as the static plot above, with the following exceptions:

times: pass our array of times that we want the animation to loop over.
consider_for_limits: for the mesh panel, keep the primary star centered and allow the transiting object to move in and out of the frame.
pad_aspect: pad_aspect doesn't work with animations, so we'll disable to avoid the warning messages.
animate: self-explanatory.
save: we could use show=True, but that doesn't always play nice with jupyter notebooks
save_kwargs: may need to change these for your setup, to create a gif, passing {'writer': 'imagemagick'} is often useful.
Can you write Python code for it?

afig, mplfig = b.plot(times=anim_times,
                      fc='teffs', fcmap='plasma', fclim=(5000, 6000),
                      ec='face',
                      consider_for_limits={'primary': True, 'secondary': False},
                      tight_layout=True, pad_aspect=False,
                      animate=True,
                      save='spot_transit.gif',
                      save_kwargs={'writer': 'imagemagick'})


I am working on the file "2.3/examples/spot_transit.ipynb".
The first task is:
Running Compute
Can you write Python code for it?


I am working on the file "2.3/examples/sun.ipynb".
The first task is:
And so that we can compare with measured/expected values, we'll observe the sun from the earth - with an inclination of 23.5 degrees and at a distance of 1 AU.
Can you write Python code for it?

b.set_value('incl', 23.5*u.deg)
b.set_value('distance', 1.0*u.AU)


I am working on the file "2.3/examples/sun.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new bundle.
Can you write Python code for it?

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

logger = phoebe.logger()

b = phoebe.default_star(starA='sun')


I am working on the file "2.3/examples/sun.ipynb".
The first task is:
For a rotating sphere, the minimum radius should occur at the pole and the maximum should occur at the equator.
Can you write Python code for it?

print("rmin (pole): {} ({})".format(b.get_value('rs').min(),
                             b.get_value('requiv', context='component')))

print("rmax (equator): {} (>{})".format(b.get_value('rs').max(),
                              b.get_value('requiv', context='component')))

print("logg: {}".format(b.get_value('loggs').mean()))

print("flux: {}".format(b.get_quantity('fluxes@model')[0]))


I am working on the file "2.3/examples/sun.ipynb".
The first task is:
Setting Parameters
Can you write Python code for it?


I am working on the file "2.3/examples/sun_earth.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new bundle.
Can you write Python code for it?

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

logger = phoebe.logger()

b = phoebe.default_binary(starA='sun', starB='earth', orbit='earthorbit')


I am working on the file "2.3/examples/sun_earth.ipynb".
The first task is:
Setting Parameters
Can you write Python code for it?

b.set_value('teff@sun', 1.0*u.solTeff)
b.set_value('requiv@sun', 1.0*u.solRad)

b.flip_constraint('period@sun', solve_for='syncpar')
b.set_value('period@sun', 24.47*u.d)
#b.set_value('incl', 23.5*u.deg)

b.set_value('teff@earth', 252*u.K)
b.set_value('requiv@earth', 1.0*c.R_earth)

b.flip_constraint('period@earth', solve_for='syncpar')
b.set_value('period@earth', 1*u.d)

b.set_value('sma@earthorbit', 1*u.AU)
b.set_value('period@earthorbit', 1*u.yr)
b.set_value('q@earthorbit', c.M_earth/c.M_sun)

#b.set_value('ecc@earthorbit')

print("Msun: {}".format(b.get_quantity('mass@sun@component', unit=u.solMass)))
print("Mearth: {}".format(b.get_quantity('mass@earth@component', unit=u.solMass)))


I am working on the file "2.3/tutorials/LC.ipynb".
The first task is:
Any of these columns are then available to use as edge or facecolors when plotting the mesh (see the section on the mesh dataset).
Can you write Python code for it?

afig, mplfig = b.filter(kind='mesh').plot(fc='intensities', ec='None', show=True)


I am working on the file "2.3/tutorials/LC.ipynb".
The first task is:
As always, let's do imports and initialize a logger and a new Bundle.
Can you write Python code for it?

import phoebe
from phoebe import u # units

logger = phoebe.logger()

b = phoebe.default_binary()


I am working on the file "2.3/tutorials/LC.ipynb".
The first task is:
For more details on atmospheres, see the Atmospheres & Passbands tutorial
Synthetics
Can you write Python code for it?

b.set_value('times', phoebe.linspace(0,1,101))

b.run_compute()

print(b.filter(context='model').twigs)

print(b.get_parameter(qualifier='times', kind='lc', context='model'))

print(b.get_parameter(qualifier='fluxes', kind='lc', context='model'))


I am working on the file "2.3/tutorials/LC.ipynb".
The first task is:
For more details on irradiation, see the Irradiation tutorial
boosting_method
Can you write Python code for it?


I am working on the file "2.3/tutorials/LC.ipynb".
The first task is:
Mesh Fields
By adding a mesh dataset and setting the columns parameter, light-curve (i.e. passband-dependent) per-element quantities can be exposed and plotted.
Let's add a single mesh at the first time of the light-curve and re-call run_compute
Can you write Python code for it?

b.add_dataset('mesh', times=[0], dataset='mesh01')

print(b.get_parameter(qualifier='columns').choices)

b.set_value('columns', value=['intensities@lc01',
                              'abs_intensities@lc01',
                              'normal_intensities@lc01',
                              'abs_normal_intensities@lc01',
                              'pblum_ext@lc01',
                              'boost_factors@lc01'])

b.run_compute()

print(b.get_model().datasets)


I am working on the file "2.3/tutorials/LC.ipynb".
The first task is:
NOTE: phases_t0 was called compute_phases_t0 before the 2.3 release.
Can you write Python code for it?


I am working on the file "2.3/tutorials/LC.ipynb".
The first task is:
Plotting
By default, LC datasets plot as flux vs time.
Can you write Python code for it?


I am working on the file "2.3/tutorials/LC.ipynb".
The first task is:
These new columns are stored with the lc's dataset tag, but with the 'mesh' dataset-kind.
Can you write Python code for it?


I am working on the file "2.3/tutorials/LC.ipynb".
The first task is:
abs_intensities are the projected absolute intensities (towards the observer) per-element.
intensities
Can you write Python code for it?

print(b.get_parameter(qualifier='intensities',
                      component='primary',
                      dataset='lc01',
                      kind='mesh',
                      context='model'))


I am working on the file "2.3/tutorials/LC.ipynb".
The first task is:
abs_normal_intensities are the absolute normal intensities per-element.
normal_intensities
Can you write Python code for it?

print(b.get_parameter(qualifier='normal_intensities',
                      component='primary',
                      dataset='lc01',
                      kind='mesh',
                      context='model'))


I am working on the file "2.3/tutorials/LC.ipynb".
The first task is:
compute_times / compute_phases
See the Compute Times & Phases tutorial.
Can you write Python code for it?

print(b.get_parameter(qualifier='compute_times'))

print(b.get_parameter(qualifier='compute_phases', context='dataset'))


I am working on the file "2.3/tutorials/LC.ipynb".
The first task is:
intens_weighting
See the Intensity Weighting tutorial
Can you write Python code for it?