I am working on the file "2.0/tutorials/t0s.ipynb".
The first task is:
't0_perpass' defines the time at which both components in our orbit is at periastron passage.  By default this parameter is constrained by 't0_supconj'.  For more details or information on how to change which parameter is editable, see the Constraints Tutorial.
Can you write Python code for it?

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

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


I am working on the file "2.0/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?

%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.0/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.0/tutorials/t0s.ipynb".
The first task is:
Influence on Phasing
All computations in PHOEBE 2 are done in the time-domain.  Times can be translated to phases using any ephemeris available, as well as any of the t0s.
By default (if not passing any options), times will be phased using the outer-most orbit in the system and using 't0_supconj'.
Can you write Python code for it?

b.to_phase(0.0)

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

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

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


I am working on the file "2.0/tutorials/t0s.ipynb".
The first task is:
There are three t0 parameters that are available to define an orbit (but only one of which is editable at any given time), as well as a t0 parameter for the entire system.  Let's first access the three t0 parameters for our binary orbit.
't0_supconj' defines the time at which the primary component in our orbit is at superior conjunction.  For a binary system in which there are eclipses, this is defined as the primary eclipse.  By default this parameter is editable.
Can you write Python code for it?


I am working on the file "2.0/tutorials/t0s.ipynb".
The first task is:
To visualize where these times are with respect to the orbits, we can plot the model orbit and highlight the positions of each star at the times defined by these parameters.  Note here that the observer is in the positive z-direction.
Can you write Python code for it?

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

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

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


I am working on the file "2.0/tutorials/t0s.ipynb".
The first task is:
t0 Parameters
IMPORTANT NOTE: the definition of the constraint between 't0_supconj' and 't0_perpass' was fixed in the 2.0.3 hotfix release.  Earlier versions may give different results in some cases.  Please make sure to update to at least 2.0.3.  To check your installed version of phoebe, you can do the following:
Can you write Python code for it?


I am working on the file "2.0/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 z 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 vz 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('vzs', time=0.0)[:5]

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

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


I am working on the file "2.0/tutorials/vgamma.ipynb".
The first task is:
Changing Systemic Velocity and LTTE
IMPORTANT NOTE: the definition of vgamma in the 2.0.x releases is to be in the direction of positive vz, and therefore negative RV.  This is inconsistent with the classical definition used in PHOEBE legacy.  The 2.0.4 bugfix release addresses this by converting when importing or exporting legacy files.  Note that starting in the 2.1 release, the definition within PHOEBE 2 will be changed such that vgamma will be in the direction of positive RV and negative vz.
By default, vgamma is initially set to 0.0
Can you write Python code for it?


I am working on the file "2.0/tutorials/vgamma.ipynb".
The first task is:
However, once ltte is enabled, the time between two eclipses (ie the observed period of the system) changes.  This occurs because the path between the system and observer has changed.  This is an important effect to note - the period parameter sets the TRUE period of the system, not necessarily the observed period between two successive eclipses.
Can you write Python code for it?

fig = plt.figure(figsize=(10,6))
ax1, ax2 = fig.add_subplot(121), fig.add_subplot(122)

axs, artists = b['lc1@100_false'].plot(color='r', ax=ax1)
axs, artists = b['lc1@100_true'].plot(color='g', ax=ax1)

axs, artists = b['lc2@100_false'].plot(color='r', ax=ax2)
axs, artists = b['lc2@100_true'].plot(color='g', ax=ax2)


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

fig = plt.figure(figsize=(10,6))
ax1, ax2 = fig.add_subplot(121), fig.add_subplot(122)

axs, artists = b['mesh1@0_false'].plot(time=0.0, x='xs', y='zs', ax=ax1)
axs, artists = b['mesh1@100_false'].plot(time=0.0, x='xs', y='zs', ax=ax1)
ax1.set_xlim(-10,10)
ax1.set_ylim(-10,10)

axs, artists = b['mesh2@0_false'].plot(time=900.0, x='xs', y='zs', ax=ax2)
axs, artists = b['mesh2@100_false'].plot(time=900.0, x='xs', y='zs', ax=ax2)
ax2.set_xlim(-10,10)
ax2.set_ylim(-10,10)

fig = plt.figure(figsize=(10,6))
ax1, ax2 = fig.add_subplot(121), fig.add_subplot(122)

axs, artists = b['mesh1@100_false'].plot(time=0.0, x='xs', y='zs', ax=ax1)
axs, artists = b['mesh1@100_true'].plot(time=0.0, x='xs', y='zs', ax=ax1)
ax1.set_xlim(-10,10)
ax1.set_ylim(-10,10)

axs, artists = b['mesh2@100_false'].plot(time=900.0, x='xs', y='zs', ax=ax2)
axs, artists = b['mesh2@100_true'].plot(time=900.0, x='xs', y='zs', ax=ax2)
ax2.set_xlim(-10,10)
ax2.set_ylim(11170,11200)


I am working on the file "2.0/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 (x-z plane) we can see see orbit spiral in the z-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?

fig = plt.figure(figsize=(10,6))
ax1, ax2 = fig.add_subplot(121), fig.add_subplot(122)

axs, artists = b['orb1@0_false'].plot(x='xs', y='zs', color='b', ax=ax1)
axs, artists = b['orb1@100_false'].plot(x='xs', y='zs', color='r', ax=ax1)

axs, artists = b['orb2@0_false'].plot(x='xs', y='zs', color='b', ax=ax2)
axs, artists = b['orb2@100_false'].plot(x='xs', y='zs', color='r', ax=ax2)


I am working on the file "2.0/tutorials/vgamma.ipynb".
The first task is:
Lastly, let's leave this value of vgamma, but enable light-time effects.
Can you write Python code for it?


I am working on the file "2.0/tutorials/vgamma.ipynb".
The first task is:
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?

fig = plt.figure(figsize=(10,6))
ax1, ax2 = fig.add_subplot(121), fig.add_subplot(122)

axs, artists = b['rv1@100_false'].plot(color='r', ax=ax1)
axs, artists = b['rv1@100_true'].plot(color='g', ax=ax1)

axs, artists = b['rv2@100_false'].plot(color='r', ax=ax2)
axs, artists = b['rv2@100_true'].plot(color='g', ax=ax2)


I am working on the file "2.0/tutorials/vgamma.ipynb".
The first task is:
Plotting the z-velocities with respect to time would show the same as the RVs, except without any Rossiter-McLaughlin like effects.  Note however the flip in z-convention between vz and radial velocities (+z is defined as towards the observer to make a right-handed system, but by convention +rv is a red shift).
Can you write Python code for it?

fig = plt.figure(figsize=(10,6))
ax1, ax2 = fig.add_subplot(121), fig.add_subplot(122)

axs, artists = b['orb1@0_false'].plot(x='times', y='vzs', color='b', ax=ax1)
axs, artists = b['orb1@100_false'].plot(x='times', y='vzs', color='r', ax=ax1)

axs, artists = b['orb2@0_false'].plot(x='times', y='vzs', color='b', ax=ax2)
axs, artists = b['orb2@100_false'].plot(x='times', y='vzs', color='r', ax=ax2)


I am working on the file "2.0/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.0/tutorials/vgamma.ipynb".
The first task is:
We'll leave it set at 0.0 for now, and then change vgamma to see how that affects the observables.
The other relevant parameter here is t0 - that is the time at which all quantities are provided, the time at which nbody integration would start (if applicable), and the time at which the center-of-mass of the system is defined to be at (0,0,0).  Unless you have a reason to do otherwise, it makes sense to have this value near the start of your time data... so if we don't have any other changing quantities defined in our system and are using BJDs, we would want to set this to be non-zero.  In this case, our times all start at 0, so we'll leave t0 at 0 as well.
Can you write Python code for it?


I am working on the file "2.0_Functions.ipynb".
The first task is:
filter(function, sequence): return a list contains items from sequence for which function(item) is true
Can you write Python code for it?

print range(-5, 5)
print filter(lambda x: x > 0, range(-5, 5))


I am working on the file "2.0_Functions.ipynb".
The first task is:
reduce(function, sequence): return a single value constructed by calling the binary function function on the first two items of the sequence, then on the result and the item, and so on.
reduce(function, sequence, init_value): when init_value is provide, the binary function function will be called on the init_value and the first item of the sequence, then on the result and the next item, and so on.

This is the picture describe the reduce process
Can you write Python code for it?


I am working on the file "2.0_Functions.ipynb".
The first task is:
Arbitrary arguments

Way to specify a function can be called with an arbitrary number of arguments
Can you write Python code for it?

def sum_square(*args):
    total = 0
    for no in args:
        total += no ** 2
    return total

print sum_square()
print sum_square(1, 2)
print sum_square(1, 2, 3)


I am working on the file "2.0_Functions.ipynb".
The first task is:
Exercise
Calculate matrix vector product between A and x. You should to use function concept.
A = [
    [-3, -2, -1],
    [2, 3, 0],
    [1, 4, 5],
    [6, 7, 8]
]
x = [7, 3, 1]
Hint: define function which calculates dot product between vector
Can you write Python code for it?

A = [
    [-3, -2, -1],
    [2, 3, 0],
    [1, 4, 5],
    [6, 7, 8]
]
x = [7, 3, 1]

def dot(x, y):
    res = 0
    for i in xrange(len(x)):
        res += x[i] * y[i]

    return res

result = []
for i in xrange(len(A)):
    result.append(dot(A[i], x))

print result


I am working on the file "2.0_Functions.ipynb".
The first task is:
Functional programming tools
3 built-in functions that are very useful when used with sequence type: map, filter, reduce

map(function,sequence): call function(item) for each of the sequence's items and returns a list of the return values.
Can you write Python code for it?

print map(lambda x: x ** 2, range(0, 5))


I am working on the file "2.0_Functions.ipynb".
The first task is:
Important: the default value is evaluated only once, which means the default value is shared between subsequent calls
Can you write Python code for it?

def append2list(value, array=[]):
    array.append(value)
    return array

print append2list(1)
# get [1, 2] instead of [1] because the default value is shared between first call
print append2list(2)


I am working on the file "2.0_Functions.ipynb".
The first task is:
Keyword arguments

function can be called using keyword arguments of the form key_word_argument=value
Can you write Python code for it?

def pet_color(dog, cat='black', pig='pink'):
    print 'Dog color:', dog, '. Cat color:', cat, '. Pig color:', pig

pet_color('yellow')

pet_color(dog='white')

pet_color('white', pig='blue')

pet_color(cat='blue', dog='white')


I am working on the file "2.0_Functions.ipynb".
The first task is:
Lambda expression

define small anonymous function using lambda keyword
Can you write Python code for it?

prod = lambda a, b: a * b

print prod(5, 2)

def compute(a, b, operator):
    return operator(a, b)

print compute(5, 2, lambda a, b: a + b)
print compute(5, 2, lambda a, b: a * b)


I am working on the file "2.0_Functions.ipynb".
The first task is:
Unpacking arguments

When the arguments are already in a list or tuple, use <code>*</code> to unpack arguments
Can you write Python code for it?

range(3, 6)

args = [3, 6]
print range(*args)


I am working on the file "2.0_Functions.ipynb".
The first task is:
dictionaries can deliever keyword arguments with <code>**</code> operator
Can you write Python code for it?

d = {'cat': 'white', 'pig': 'blackwhite'}
print pet_color('brown', **d)


I am working on the file "2.0_Functions.ipynb".
The first task is:
function name is a variable
Can you write Python code for it?

print square

power2 = square
print power2(10)


I am working on the file "2.0_Functions.ipynb".
The first task is:
non-default argument cannot follow after default argument
Can you write Python code for it?

def exp(base=2, x):
    return exponential(x, base)


I am working on the file "2.0_Functions.ipynb".
The first task is:
when calling a function, keyword value cannot be precedent non-keyword (positional) value
Can you write Python code for it?


I am working on the file "2.1. Co-citation networks/2.1. Co-citation analysis.ipynb".
The first task is:
2.1. Co-citation Analysis
In this workbook we will conduct a co-citation analysis using the approach outlined in Chen (2009). If you have used the Java-based desktop application CiteSpace II, this should be familiar: this is the same methodology that is implemented in that application.
Co-citation analysis gained popularity in the 1970s as a technique for “mapping” scientific literatures, and for finding latent semantic relationships among technical publications.
Two papers are co-cited if they are both cited by the same, third, paper. The standard approach to co-citation analysis is to generate a sample of bibliographic records from a particular field by using certain keywords or journal names, and then build a co-citation graph describing relationships among their cited references. Thus the majority of papers that are represented as nodes in the co-citation graph are not papers that responded to the selection criteria used to build the dataset.

Our objective in this tutorial is to identify papers that bridge the gap between otherwise disparate areas of knowledge in the scientific literature. In this tutorial, we rely on the theoretical framework described in Chen (2006) and Chen et al. (2009).
According to Chen, we can detect potentially transformative changes in scientific knowledge by looking for cited references that both (a) rapidly accrue citations, and (b) have high betweenness-centrality in a co-citation network. It helps if we think of each scientific paper as representing a “concept” (its core knowledge claim, perhaps), and a co-citation event as representing a proposition connecting two concepts in the knowledge-base of a scientific field. If a new paper emerges that is highly co-cited with two otherwise-distinct clusters of concepts, then that might mean that the field is adopting new concepts and propositions in a way that is structurally radical for their conceptual framework.
Chen (2009) introduces sigma ($\Sigma$) as a metric for potentially transformative cited references:
$$
\Sigma(v) =...
Can you write Python code for it?

metadata = wos.read('../data/Baldwin/PlantPhysiology',
                    streaming=True, index_fields=['date', 'abstract'], index_features=['citations'])

len(metadata)


I am working on the file "2.1. Co-citation networks/2.1. Co-citation analysis.ipynb".
The first task is:
Before calculating $\Sigma$ we will select a subset of the rows in our dataframe, to reduce the computational burden. Here we create a smaller DataFrame with only those rows in which both Centrality and Delta are not zero -- it should be obvious that these will have negligible $\Sigma$.
Can you write Python code for it?

# Note the ``.copy()`` at the end -- this means that the new DataFrame will be a
#  stand-alone copy, and not just a "view" of the existing ``node_data`` DataFrame.
#  The practical effect is that we can add new data to the new ``candidates``
#  DataFrame without creating problems in the larger ``node_data`` DataFrame.
candidates = node_data[node_data.Centrality*node_data.Delta > 0.].copy()


I am working on the file "2.1. Co-citation networks/2.1. Co-citation analysis.ipynb".
The first task is:
Cluster labeling
Can you write Python code for it?

clusters = pd.read_csv('clusters.dat', sep='\t', skiprows=9)

clusters

clusters['Node IDs'][0].split(', ')

citations = metadata.features['citations']

citing = Counter()
for reference in clusters['Node IDs'][0].split(', '):
    for idx in citations.papers_containing(reference):
        citing[idx] += 1.
chunk = [idx for idx, value in citing.items() if value > 2.]


I am working on the file "2.1. Co-citation networks/2.1. Co-citation analysis.ipynb".
The first task is:
Co-citation graph
Tethne provides a function called cocitation that creates co-citation graphs.
Can you write Python code for it?


I am working on the file "2.1. Co-citation networks/2.1. Co-citation analysis.ipynb".
The first task is:
Co-citation graphs can get enormous quickly, and so it is important to set a threshold number of times that a paper must be cited to be included in the graph (min_weight). It's better to start high, and bring the threshold down as needed.
Note that edge_attrs should be set to whatever was the value of index_fields when we used read() (above).
Can you write Python code for it?

graph = cocitation(metadata, min_weight=6., edge_attrs=['date'])

graph.order(), graph.size(), nx.number_connected_components(graph)


I am working on the file "2.1. Co-citation networks/2.1. Co-citation analysis.ipynb".
The first task is:
Organize our data
In order to calculate $\Sigma$ more efficiently, we'll organize our data about the graph in a DataFrame. Our DataFrame will have the following columns:

ID - The GraphCollection gives each node an integer ID. We'll need this to identify nodes in Cytoscape, later.
Node - This is the Author Year Journal label from the WoS data for a cited reference.
Citations - The number of citations.
Centrality - Betweenness centrality.
Delta - The year-over-year increase/decrease in citations.

This may take a bit, depending on the size of the graphs.
Can you write Python code for it?

node_data = pd.DataFrame(columns=['ID', 'Node', 'Year', 'Citations', 'Centrality', 'Delta'])

i = 0
for n in G.node_index.keys():
    if n < 0:
        continue

    # node_history() gets the values of a node attribute over
    #  all of te graphs in the GraphCollection.
    g_n = G.node_history(n, 'betweenness_centrality')
    N_n = G.node_history(n, 'count')

    # Skip nodes whose g(v) never gets above 0.
    if max(g_n.values()) == 0:
        continue

    years = sorted(G.keys())   # Graphs are keyed by year.
    for year in years:
        g_nt = g_n.get(year, 0.0)    # Centrality for this year.
        N_nt = float(N_n.get(year, 0.0))    # Citations for this year.
        # For the second year and beyond, calculate Delta.
        if year > years[0]:
            N_nlast = N_n.get(year-1, 0.0)
            delta = (N_nt - N_nlast)/max(N_nlast, 1.)
        else:
            delta = 0.0

        # We will add one row per node per year.
        node_data.loc[i] = [n, G.node_index[n], year, N_nt, g_nt, delta]
        i += 1


I am working on the file "2.1. Co-citation networks/2.1. Co-citation analysis.ipynb".
The first task is:
Serialize
We can visualize our graph in Cytoscape to get a sense of its structure.
Can you write Python code for it?


I am working on the file "2.1. Co-citation networks/2.1. Co-citation analysis.ipynb".
The first task is:
Sigma, $\Sigma$
Chen (2009) proposed sigma ($\Sigma$) as a metric for potentially transformations in a scientific literature.
$$
\Sigma(v) = (g(v) + 1)^{burstness(v)}
$$

Note: In this notebook we will not use burstness, but rather the relative increase/decrease in citations from one year to the next. Burstness is helpful when we are dealing with higher-resolution time-frames, and/or we want to monitor a long stream of citation data. Since we will smooth our data with a multi-year time-window, burstness becomes a bit less informative, and the year-over-year change in citations (we'll call this Delta $\Delta(v)$) is an intuitive alternative. So:
$$
\Sigma(v) = (g(v) + 1)^{\Delta(v)}
$$
$$
\Delta(v) = \frac{N_t(v) - N_{t-1} }{max(1, N_{t-1})}
$$

GraphCollection
Since we are interested in the evolution of the co-citation graph over time, we need to create a series of sequential graphs. Tethne provides a class called GraphCollection that will do this for us.
We pass metadata (or Corpus object), the cotation function, and then some configuration information:
* slice_kwargs controls how the sequential time-slices are generated. The default is to use 1-year slices, and advance 1 year per slice. We are stating here that we want to extract only the citations feature from each slice (for performance).
* method_kwargs controls the graph-building function. Here we pass our min_weight, and we also say that we don't want any attributes on the edges (for performance).
Can you write Python code for it?

from tethne import GraphCollection
G = GraphCollection(metadata, cocitation,
                    slice_kwargs={'feature_name': 'citations'},
                    method_kwargs={'min_weight': 3, 'edge_attrs': []})

for year, graph in G.iteritems():
    print graph.order(), graph.size(), nx.number_connected_components(graph)
    nx.write_graphml(graph, 'cocitation_%i.graphml' % year)


I am working on the file "2.1. Co-citation networks/2.1. Co-citation analysis.ipynb".
The first task is:
That was fairly computationally expensive. We should save the results so that we don't have to do that again.
Can you write Python code for it?


I am working on the file "2.1. Co-citation networks/2.1. Co-citation analysis.ipynb".
The first task is:
This step can take a few minutes.
Can you write Python code for it?

abstracts = {}
for abstract, wosid in metadata.indices['abstract'].iteritems():
    print '\r', wosid[0],
    abstracts[wosid[0]] = abstract

abstracts.items()[5]

document_token_counts = nltk.ConditionalFreqDist([
    (wosid, normalize_token(token))
    for wosid, abstract in abstracts.items()
    for token in nltk.word_tokenize(abstract)
    if filter_token(token)
])

extract_keywords(document_token_counts, lambda k: k in chunk)

cluster_keywords = {}
for i, row in clusters.iterrows():
    citing = Counter()
    for reference in row['Node IDs'].split(', '):
        for idx in citations.papers_containing(reference):
            citing[idx] += 1.
    chunk = [idx for idx, value in citing.items() if value > 2.]

    cluster_keywords[row.Cluster] = extract_keywords(document_token_counts, lambda k: k in chunk)

cluster_keywords


I am working on the file "2.1.Discretizing-Hamiltonians-computing-spectra.ipynb".
The first task is:
Building a kwant system means defining the Hamiltonian! We can get it from the finalized kwant system:
Can you write Python code for it?

ham = sys.hamiltonian_submatrix()
plt.matshow(ham==0, cmap="gray", interpolation=None)


I am working on the file "2.1.Discretizing-Hamiltonians-computing-spectra.ipynb".
The first task is:
But now we can start doing nice things! For example, we can now compute the eigenvalues and eigefunctions of this system very easily.
Can you write Python code for it?

eval, evec = la.eigh(ham)

kwant.plotter.map(sys, abs(evec[:,0])**2);


I am working on the file "2.1.Discretizing-Hamiltonians-computing-spectra.ipynb".
The first task is:
Let's use some ipython magic and make an interactive plot showing the first 30 wave functions
Can you write Python code for it?

from ipywidgets import interact

def plot_wf(i=0):
    print("Plotting wave function with index", i)
    print("energy:", eval[i],"x t")
    kwant.plotter.map(sys, abs(evec[:, i])**2)

interact(plot_wf, i=(0, 30))


I am working on the file "2.1.Discretizing-Hamiltonians-computing-spectra.ipynb".
The first task is:
Once we are finished building the kwant system, we "finalize" it: this means the system will be brought into a format better suited for doing calculations, and it's shape cannot
be changed any more (its values still can - see later tutorial)
Can you write Python code for it?


I am working on the file "2.1.Discretizing-Hamiltonians-computing-spectra.ipynb".
The first task is:
We want to confine the electrons in a finite region. Here, we choose a circle
Can you write Python code for it?

t = 1
r = 15

def circle(pos):
    x, y = pos
    return x**2 + y**2 < r**2

sys = kwant.Builder()
sys[lat.shape(circle, (0,0))] = 4 * t
sys[lat.neighbors()] = -t

kwant.plot(sys);


I am working on the file "2.1.Discretizing-Hamiltonians-computing-spectra.ipynb".
The first task is:
We will describe a particle in 2D with the Hamiltonian $H= -\frac{\hbar^2}{2m^} \nabla^2$. The finite difference approach thus yields a square lattice* with lattice constant $a$ (which we will set to 1). So in kwant we do:
Can you write Python code for it?


I am working on the file "2.1.Discretizing-Hamiltonians-computing-spectra.ipynb".
The first task is:
Yes it's as easy as that!
We'll do some more import of things we need later
Can you write Python code for it?

%run matplotlib_setup.ipy

import scipy.linalg as la


I am working on the file "2.1/examples/animation_binary_complete.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.1/examples/animation_binary_complete.ipynb".
The first task is:
Plotting
See the Animations Tutorial for more examples and details.
Here we'll create a figure with multiple subplots.  The top row will be the light curve and RV curve.  The bottom three subplots will be various representations of the mesh (intensities, rvs, and visibilities).
We'll do this by making separate calls to plot, passing the matplotlib subplot location for each axes we want to create.  We can then call b.show(animate=True) or b.save('anim.gif', animate=True).
Can you write Python code for it?

b['lc01@model'].plot(axpos=221)
b['rv01@model'].plot(c={'primary': 'blue', 'secondary': 'red'}, linestyle='solid', axpos=222)
b['mesh@model'].plot(fc='intensities@lc01', ec='None', axpos=425)
b['mesh@model'].plot(fc='rvs@rv01', ec='None', axpos=427)
b['mesh@model'].plot(fc='visibilities', ec='None', y='ws', axpos=224)

fig = plt.figure(figsize=(11,4))
b.savefig('animation_binary_complete.gif', fig=fig, tight_layouot=True, draw_sidebars=False, animate=True, save_kwargs={'writer': 'imagemagick'})


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


I am working on the file "2.1/examples/binary_misaligned_spots.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()

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


I am working on the file "2.1/examples/binary_misaligned_spots.ipynb".
The first task is:
Location of Spot
Can you write Python code for it?

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


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


I am working on the file "2.1/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.1/examples/contact_spots.ipynb".
The first task is:
But if we increase the radius large enough, we'll get a ring.
Can you write Python code for it?

b.set_value('radius', value=40)

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

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


I am working on the file "2.1/examples/contact_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.1/examples/contact_spots.ipynb".
The first task is:
Spots near the "neck"
Since the spots are still defined with the coordinate system of the individual star components, this can result in spots that are distorted and even "cropped" at the neck.  Furthermore, spots with long=0 could be completely "hidden" by the neck or result in a ring around the neck.
To see this, let's plot our mesh with teff as the facecolor.
Can you write Python code for it?

b.remove_dataset(kind='lc')

b.add_dataset('mesh', times=b.to_time(0.25), columns='teffs')

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

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


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


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

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

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


I am working on the file "2.1/examples/legacy.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='rvdyn')
b.add_dataset('rv', times=np.linspace(0,1,101), dataset='rvnum')


I am working on the file "2.1/examples/legacy.ipynb".
The first task is:
And set the two RV datasets to use the correct methods (for both compute options)
Can you write Python code for it?

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

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


I am working on the file "2.1/examples/legacy.ipynb".
The first task is:
Dynamical RVs
Since the dynamical RVs don't depend on the mesh, there should be no difference between the 'phoebe2marching' and 'phoebe2wd' synthetic models.  Here we'll just choose one to plot.
Can you write Python code for it?

afig, mplfig = b.filter(dataset='rvdyn', model=['phoebe2wdmodel', 'phoebe1model']).plot(c=colors, legend=True, show=True)


I am working on the file "2.1/examples/legacy.ipynb".
The first task is:
Let's also disable other special effect such as heating, gravity, and light-time effects.
Can you write Python code for it?

b.set_value_all('ld_func', 'logarithmic')
b.set_value_all('ld_coeffs', [0.,0.])

b.set_value_all('rv_grav', False)

b.set_value_all('ltte', False)


I am working on the file "2.1/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.1/examples/legacy.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@phoebe2marchingmodel') - b.get_value('fluxes@lc01@phoebe1model'), 'g-')
artist, = plt.plot(b.get_value('fluxes@lc01@phoebe2wdmodel') - b.get_value('fluxes@lc01@phoebe1model'), 'b-')
artist = plt.axhline(0.0, linestyle='dashed', color='k')
ylim = plt.ylim(-0.003, 0.003)


I am working on the file "2.1/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.1/examples/legacy_contact_binary.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
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.1/examples/legacy_contact_binary.ipynb".
The first task is:
Finally, let's compute our models
Can you write Python code for it?

b.run_compute(kind='phoebe', model='phoebe2model', irrad_method='none')

b.run_compute(kind='legacy', model='phoebe1model', irrad_method='none')


I am working on the file "2.1/examples/legacy_contact_binary.ipynb".
The first task is:
Let's also disable other special effect such as heating, gravity, and light-time effects.
Can you write Python code for it?

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

b.set_value_all('rv_grav', False)
b.set_value_all('ltte', False)


I am working on the file "2.1/examples/legacy_contact_binary.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.1/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.1/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.1/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.1/examples/legacy_contact_binary.ipynb".
The first task is:
Set value of gridsize for the trapezoidal (WD) mesh.
Can you write Python code for it?


I am working on the file "2.1/examples/legacy_spots.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.1/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_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.1/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.1/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', times=np.linspace(0,10,6), dataset='mesh01', columns=['visibilities'])


I am working on the file "2.1/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.1/examples/mesh_wd.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

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.1/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.1/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.1/examples/mesh_wd.ipynb".
The first task is:
Running Compute
Can you write Python code for it?


I am working on the file "2.1/examples/minimal_contact_binary.ipynb".
The first task is:
And because of this, the potential and requiv@secondary constraints cannot be computed
Can you write Python code for it?


I am working on the file "2.1/examples/minimal_contact_binary.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()


I am working on the file "2.1/examples/minimal_contact_binary.ipynb".
The first task is:
For comparison, we'll do the same to our detached system
Can you write Python code for it?

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

b_detached.add_dataset('orb', times=np.linspace(0,1,201), dataset='orb01')

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

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


I am working on the file "2.1/examples/minimal_contact_binary.ipynb".
The first task is:
Hierarchy
Let's first look at the hierarchy of the default detached binary, and then compare that to the hierarchy of the overcontact system
Can you write Python code for it?

print b_detached.hierarchy

print b_cb.hierarchy


I am working on the file "2.1/examples/minimal_contact_binary.ipynb".
The first task is:
However, since our system was detached, the system is not overflowing, and therefore doesn't pass system checks
Can you write Python code for it?


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

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

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


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

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

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


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

afig, mplfig = b_cb['rv01@model'].plot(show=True)

afig, mplfig = b_detached['rv01@model'].plot(show=True)


I am working on the file "2.1/examples/minimal_contact_binary.ipynb".
The first task is:
Synthetics
To ensure compatibility with computing synthetics in detached and semi-detached systems in Phoebe, the synthetic meshes for our overcontact system are attached to each component separetely, instead of the contact envelope.
Can you write Python code for it?

print b_cb['mesh01@model'].components

print b_detached['mesh01@model'].components


I am working on the file "2.1/examples/minimal_contact_binary.ipynb".
The first task is:
We'll compare this to the default detached binary
Can you write Python code for it?


I am working on the file "2.1/examples/minimal_synthetic.ipynb".
The first task is:
Adding Datasets
Now we'll create an empty lc dataset:
Can you write Python code for it?


I am working on the file "2.1/examples/minimal_synthetic.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.1/examples/minimal_synthetic.ipynb".
The first task is:
Plotting
Now we can simply plot the resulting synthetic light curve.
Can you write Python code for it?

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

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


I am working on the file "2.1/examples/rossiter_mclaughlin.ipynb".
The first task is:
Let's make a significant mass ratio and radius ratio...
Can you write Python code for it?

b['q'] = 0.7

b['requiv@primary'] = 1.0

b['requiv@secondary'] = 0.5

b['teff@secondary@component'] = 5000


I am working on the file "2.1/examples/rossiter_mclaughlin.ipynb".
The first task is:
Make sure the primary star is spinning quickly...
Can you write Python code for it?


I am working on the file "2.1/examples/rossiter_mclaughlin.ipynb".
The first task is:
Plotting
Now let's plot the radial velocities.
First we'll plot the dynamical RVs.  Note that dynamical RVs show the true radial velocity of the center of mass of each star, and so we do not see the Rossiter McLaughlin effect.
Can you write Python code for it?

afig, mplfig = b['dynamicalrvs@model'].plot(c={'primary': 'b', 'secondary': 'r'}, show=True)


I am working on the file "2.1/examples/rossiter_mclaughlin.ipynb".
The first task is:
Storing the mesh at every timestep is overkill, and will be both computationally and memory intensive.  So let's just sample at the times we care about.
Can you write Python code for it?

times = b.get_value('times@primary@numericalrvs@dataset')
times = times[times<0.1]
print times

b.add_dataset('mesh', dataset='mesh01', times=times, columns=['vws', 'rvs*'])


I am working on the file "2.1/examples/single_spots.ipynb".
The first task is:
And if we change the inclination to 0, we'll be looking at the north pole of the star.  This clearly illustrates the right-handed rotation of the star.  At time=t0=5 the spot will now be pointing in the negative y-direction.
Can you write Python code for it?

b.set_value('incl', 0)

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

afig, mplfig = b.plot(x='us', y='vs', fc='teffs',
                     animate=True, save='single_spots_3.gif', save_kwargs={'writer': 'imagemagick'})


I am working on the file "2.1/examples/single_spots.ipynb".
The first task is:
If we set t0 to 5 instead of zero, then the spot will cross the line-of-sight at t=5 (since the spot's longitude is 0).
Can you write Python code for it?

b.set_value('t0', 5)

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

afig, mplfig = b.plot(x='us', y='vs', fc='teffs',
                     animate=True, save='single_spots_2.gif', save_kwargs={'writer': 'imagemagick'})


I am working on the file "2.1/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.1/examples/single_spots.ipynb".
The first task is:
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 observer at t0 for a single star.  See the spots tutorial for more details.
Can you write Python code for it?

times = np.linspace(0, 10, 11)
b.set_value('period', 10)
b.add_dataset('mesh', times=times, columns=['teffs'])

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

afig, mplfig = b.plot(x='us', y='vs', fc='teffs',
                      animate=True, save='single_spots_1.gif', save_kwargs={'writer': 'imagemagick'})


I am working on the file "2.1/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.1/examples/sun.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_star(starA='sun')


I am working on the file "2.1/examples/sun.ipynb".
The first task is:
Checking on the set values, we can see the values were converted correctly to PHOEBE's internal units.
Can you write Python code for it?

print b.get_quantity('teff')
print b.get_quantity('requiv')
print b.get_quantity('mass')
print b.get_quantity('period')
print b.get_quantity('incl')
print b.get_quantity('distance')


I am working on the file "2.1/examples/sun.ipynb".
The first task is:
Let's set all the values of the sun based on the nominal solar values provided in the units package.
Can you write Python code for it?

b.set_value('teff', 1.0*u.solTeff)
b.set_value('requiv', 1.0*u.solRad)
b.set_value('mass', 1.0*u.solMass)
b.set_value('period', 24.47*u.d)


I am working on the file "2.1/examples/sun.ipynb".
The first task is:
Running Compute
Let's add a light curve so that we can compute the flux at a single time and compare it to the expected value.  We'll set the passband luminosity to be the nominal value for the sun. We'll also add a mesh dataset so that we can plot the temperature distributions and test the size of the sun verse known values.
Can you write Python code for it?

b.add_dataset('lc', times=[0.], pblum=1*u.solLum)
b.add_dataset('mesh', times=[0.], columns=['teffs', 'loggs', 'rs'])

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


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


I am working on the file "2.1/tutorials/20_21_meshes.ipynb".
The first task is:
In this tutorial we will review the changes in the PHOEBE mesh structures. We will first explain the changes and then demonstrate them in code. As usual, let us import phoebe and create a default binary bundle:
Can you write Python code for it?

import phoebe
b = phoebe.default_binary()


I am working on the file "2.1/tutorials/20_21_meshes.ipynb".
The first task is:
PHOEBE 2.0 had a mesh dataset along with pbmesh and protomesh options you could send to b.run_compute().  These options were quite convenient, but had a few inherit problems:

The protomesh was exposed at only t0 and was in Roche coordinates, despite using the same qualifiers 'x', 'y', 'z'.
Passband-dependent parameters were exposed in the mesh if pbmesh=True, but only if the times matched exactly with the passband (lc, rv, etc) dataset.
Storing more than a few meshes become very memory intensive due to their large size and the large number of columns.

Addressing these shortcomings required a complete redesign of the mesh dataset.  The most important changes are:

pbmesh and protomesh are no longer valid options to b.run_compute().  Everything is done through the mesh dataset itself, i.e. b.add_dataset('mesh').
The default columns that are computed for each mesh include the elements in both Roche and plane-of-sky coordinate systems. These columns cannot be disabled.
The columns parameter in the mesh dataset lists additional columns to be exposed in the model mesh when calling b.run_compute().  See the section on columns below for more details.
You can choose whether to expose coordinates in the Roche coordinate system ('xs', 'ys', 'zs') or the plane-of-sky coordinate system ('us', 'vs', 'ws').
When plotting, the default is the plane-of-sky coordinate system, and the axes will be correctly labeled as uvw, whereas in PHOEBE 2.0.x these were still labeled xyz. Note that this also applies to velocities ('vxs', 'vys', 'vzs' vs 'vus', 'vvs', 'vws').
The include_times parameter allows for importing timestamps from other datasets. It also provides support for important orbital times: 't0' (zero-point), 't0_perpass' (periastron passage), 't0_supconj' (superior conjunction) and 't0_ref' (zero-phase reference point).
By default, the times parameter is empty. If you do not set times or include_times before calling b.run_compute(), your model will be empty.

The 'columns' parameter
This parameter is a SelectParameter (a...
Can you write Python code for it?

b.add_dataset('mesh')
print b.get_parameter('columns').get_choices()

b.add_dataset('lc')
print b.get_parameter('columns').get_choices()

b['columns'] = ['*@lc01', 'teffs']
b.get_parameter('columns').get_value()

b.get_parameter('columns').expand_value()


I am working on the file "2.1/tutorials/20_21_nparray.ipynb".
The first task is:
By setting a PHOEBE parameter to this value, you can then later edit any of the properties.
Can you write Python code for it?

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

print b.get_parameter('times')


I am working on the file "2.1/tutorials/20_21_nparray.ipynb".
The first task is:
You can now "edit" the properties of this array without re-building it.
Can you write Python code for it?

b.get_parameter('times').set_property(stop=2)

print b.get_parameter('times')

print b.get_value('times')


I am working on the file "2.1/tutorials/20_21_xyz_uvw.ipynb".
The first task is:
In PHOEBE 2.0, the protomesh was exposed with x, y, z signifying roche coordinates, but the mesh dataset or pbmesh with x, y, z signifying plane-of-sky coordinates.  Now in PHOEBE 2.1, this distinction is gone, with 'xyz' always signifying Roche coordinates and 'uvw' always plane-of-sky.  Note that the concept of the protomesh and pbmesh have also been removed and replaced with a more flexible mesh dataset.
Can you write Python code for it?


I am working on the file "2.1/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?


I am working on the file "2.1/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?


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


I am working on the file "2.1/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['mesh01@model'].plot(fc='intensities', ec='None', show=True)


I am working on the file "2.1/tutorials/LC.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.1/tutorials/LC.ipynb".
The first task is:
Compute Options
Let's look at the compute options (for the default PHOEBE 2 backend) that relate to computing fluxes and the LC dataset.
Other compute options are covered elsewhere:
* parameters related to dynamics are explained in the section on the orb dataset
* parameters related to meshing, eclipse detection, and subdivision are explained in the section on the mesh dataset
Can you write Python code for it?


I am working on the file "2.1/tutorials/LC.ipynb".
The first task is:
Dataset Parameters
Let's add a lightcurve dataset to the Bundle.
Can you write Python code for it?

b.add_dataset('lc')
print b.filter(kind='lc')

print b.filter(kind='lc_dep')


I am working on the file "2.1/tutorials/LC.ipynb".
The first task is:
For more details on boosting, see the Beaming and Boosting example script
atm
Can you write Python code for it?


I am working on the file "2.1/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['columns'].choices

b['columns'] = ['intensities@lc01', 'abs_intensities@lc01', 'normal_intensities@lc01', 'abs_normal_intensities@lc01', 'pblum@lc01', 'boost_factors@lc01']

b.run_compute()

print b['model'].datasets


I am working on the file "2.1/tutorials/LC.ipynb".
The first task is:
Now let's look at each of the available fields.
pblum
For more details, see the tutorial on Passband Luminosities
Can you write Python code for it?


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

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


I am working on the file "2.1/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.1/tutorials/LC.ipynb".
The first task is:
intens_weighting
See the Intensity Weighting tutorial
Can you write Python code for it?


I am working on the file "2.1/tutorials/LC.ipynb".
The first task is:
irrad_method
Can you write Python code for it?


I am working on the file "2.1/tutorials/LC.ipynb".
The first task is:
l3
See the "Third" Light tutorial
Can you write Python code for it?


I am working on the file "2.1/tutorials/LC.ipynb".
The first task is:
ld_coeffs
ld_coeffs will only be available if ld_func is not interp, so let's set it to logarithmic
Can you write Python code for it?

b['ld_func@primary'] = 'logarithmic'

print b['ld_coeffs@primary']


I am working on the file "2.1/tutorials/LC.ipynb".
The first task is:
sigmas
Can you write Python code for it?


I am working on the file "2.1/tutorials/LC.ipynb".
The first task is:
times
Can you write Python code for it?


I am working on the file "2.1/tutorials/LP.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.1/tutorials/LP.ipynb".
The first task is:
Dataset Parameters
Let's create the ParameterSets which would be added to the Bundle when calling add_dataset. Later we'll call add_dataset, which will create and attach both these ParameterSets for us.
components
Line profiles will be computed for each component in which the wavelengths are provided.  If we wanted to expose the line profile for the binary as a whole, we'd set the wavelenghts for wavelengths@binary.  If instead we wanted to expose per-star line profiles, we could set the wavelengths for both wavelengths@primary and wavelengths@secondary.
If you're passing wavelengths to the b.add_dataset call, it will default to filling the wavelengths at the system-level.  To override this, pass components=['primary', 'secondary'], as well.  For example: b.add_dataset('lp', wavelengths=np.linspace(549,551,101), components=['primary', 'secondary']).
times
Line profiles have an extra dimension than LC and RV datasets which have times as their independent variable.  For that reason, the parameters in the LP dataset are tagged with individual times instead of having a separate times array.  This allows the flux_densities and sigmas to be per-time.  Because of this, times is not a variable, but instead must be passed when you call b.add_dataset.  At that point, in order to change the times you would need to remove and re-add the dataset.
Can you write Python code for it?

b.add_dataset('lp', times=[0,1,2], wavelengths=np.linspace(549, 551, 101))
print b.filter(kind='lp')


I am working on the file "2.1/tutorials/LP.ipynb".
The first task is:
For information on the passband-dependent parameters, see the section on the lc dataset (these are used only to compute fluxes when rv_method=='flux-weighted')
wavelengths
Can you write Python code for it?

print b.filter('wavelengths')

print b.get_parameter('wavelengths', component='binary')


I am working on the file "2.1/tutorials/LP.ipynb".
The first task is:
Here we see that there are three wavelengths Parameters, with the wavelengths@primary being filled with the input array (since we didn't override the components or manually pass a dictionary).  Because of this, the flux_densities and sigmas are only visible for the binary component as well. (If we were to fill either of the two other arrays, the corresponding Parameters would become visible as well).  We can see, however, that there is an entry for flux_densities and sigmas for each of the times we passed.
In addition, there are some Parameters in the dataset not related directly to observations.  These include information about the line profile, as well as passband-dependent parameters.
Can you write Python code for it?


I am working on the file "2.1/tutorials/LP.ipynb".
The first task is:
Mesh Fields
Let's add a single mesh and see which columns from the line profile dataset are available to expose as a column in the mesh.
Can you write Python code for it?

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

print b['columns'].choices


I am working on the file "2.1/tutorials/LP.ipynb".
The first task is:
Synthetics
Can you write Python code for it?


I am working on the file "2.1/tutorials/LP.ipynb".
The first task is:
The model for a line profile dataset will expose flux-densities at each time and for each component where the corresponding wavelengths Parameter was not empty.  Here since we used the default and exposed line-profiles for the entire system, we have a single entry per-time.
Can you write Python code for it?

print b.filter('flux_densities', context='model')

print b.get_parameter('flux_densities', context='model', time=0)


I am working on the file "2.1/tutorials/LP.ipynb".
The first task is:
profile_func
Can you write Python code for it?


I am working on the file "2.1/tutorials/LP.ipynb".
The first task is:
profile_sv
Can you write Python code for it?


I am working on the file "2.1/tutorials/LP.ipynb".
The first task is:
sigmas
Can you write Python code for it?

print b.filter('sigmas')

print b.get_parameter('sigmas', time=0)


I am working on the file "2.1/tutorials/MESH.ipynb".
The first task is:
Alternatively, if you provide simple 1-D fields to plot, a 2D x-y plot will be created using the values from each element (always for a single time - if meshes exist for multiple times in the model, you should provide a single time either in the twig or as a filter).
NOTE: providing z=0 will override the default of z-ordering the points by there "w" (line-of-sight distance) value, which can be expensive and take a while to draw.
Can you write Python code for it?

afig, mplfig = b['mesh@model'].plot(x='mus', y='teffs', z=0, show=True)


I am working on the file "2.1/tutorials/MESH.ipynb".
The first task is:
Any of the 1-D fields (ie not vertices or normals) or matplotlib-recognized colornames can be used to color either the faces or edges of the triangles.  Passing none for edgecolor or facecolor turns off the coloring (you may want to set edgecolor=None if setting facecolor to disable the black outline).
Can you write Python code for it?

afig, mplfig = b['mesh@model'].plot(fc='teffs', ec='None', show=True)


I am working on the file "2.1/tutorials/MESH.ipynb".
The first task is:
Compute Options
Let's look at the compute options (for the default PHOEBE 2 backend) that relate to meshes
Can you write Python code for it?


I am working on the file "2.1/tutorials/MESH.ipynb".
The first task is:
Per-Element Parameters
Can you write Python code for it?

print b['uvw_elements@primary@mesh01@model']

print b['xyz_elements@primary@mesh01@model']

print b['us@primary@mesh01@model']

print b['rs@primary@mesh01@model']

print b['rprojs@primary@mesh01@model']

print b['nxs@primary@mesh01@model']

print b['mus@primary@mesh01@model']

print b['vxs@primary@mesh01@model']

print b['areas@primary@mesh01@model']

print b['loggs@primary@mesh01@model']

print b['teffs@primary@mesh01@model']

print b['visibilities@primary@mesh01@model']


I am working on the file "2.1/tutorials/MESH.ipynb".
The first task is:
Per-Mesh Parameters
Can you write Python code for it?


I am working on the file "2.1/tutorials/MESH.ipynb".
The first task is:
Synthetics
Can you write Python code for it?

b.set_value('times', [0])

b['columns'] = '*'

b.run_compute()

b['mesh@model'].twigs


I am working on the file "2.1/tutorials/MESH.ipynb".
The first task is:
The 'mesh_method' parameter determines how each component in the system is discretized into its mesh, and has several options:
 * marching (default): this is the new method introduced in PHOEBE 2.  The star is discretized into triangles, with the attempt to make them each of equal-area and nearly equilateral.  Although not as fast as 'wd', this method is more robust and will always form a closed surface (when possible).
 * wd: this is a re-implementation of the Wilson-Devinney style meshing used in PHOEBE 1.0 (legacy), with the stars discretized into trapezoids in strips of latitude (we then split each trapezoid into two triangles).  This is faster, but suffers from gaps between the surface elements, and is mainly meant for testing and comparison with legacy.  See the WD-Style Meshing Example Script for more details.
ntriangles
The 'ntriangles' parameter is only relevenat if mesh_method=='marching' (so will not be available unless that is the case).
Can you write Python code for it?


I am working on the file "2.1/tutorials/MESH.ipynb".
The first task is:
The exception to needing to provide a time is for the per-time parameters mentioned above.  For these, time can be the x-array (not very exciting in this case with only a single time).
For more examples see the following:
- Passband Luminosity Tutorial
Can you write Python code for it?

afig, mplfig = b['mesh@model'].plot(x='times', y='volume', marker='s', show=True)


I am working on the file "2.1/tutorials/MESH.ipynb".
The first task is:
columns
Can you write Python code for it?


I am working on the file "2.1/tutorials/MESH.ipynb".
The first task is:
gridsize
The 'gridsize' parameter is only relevant if mesh_method=='wd' (so will not be available unless that is the case).
Can you write Python code for it?


I am working on the file "2.1/tutorials/MESH.ipynb".
The first task is:
mesh_method
Can you write Python code for it?


I am working on the file "2.1/tutorials/ORB.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.1/tutorials/ORB.ipynb".
The first task is:
As always, you have access to any of the arrays for either axes, so if you want to plot 'vus' vs 'times'
Can you write Python code for it?

afig, mplfig = b['orb@model'].plot(x='times', y='vus', show=True)


I am working on the file "2.1/tutorials/ORB.ipynb".
The first task is:
Compute Options
Let's look at the compute options (for the default PHOEBE 2 backend) that relate to dynamics and the ORB dataset
Can you write Python code for it?


I am working on the file "2.1/tutorials/ORB.ipynb".
The first task is:
Dataset Parameters
Let's create the and orb dataset and attach it to the Bundle
Can you write Python code for it?


I am working on the file "2.1/tutorials/ORB.ipynb".
The first task is:
Plotting
By default, orb datasets plot as 'vs' vx 'us' (plane of sky coordinates).  Notice the y-scale here with inclination set to 90.
Can you write Python code for it?

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


I am working on the file "2.1/tutorials/ORB.ipynb".
The first task is:
The 'dynamics_method' parameter controls how stars and components are placed in the coordinate system as a function of time and has several choices:
 * keplerian (default): Use Kepler's laws to determine positions.  If the system has more than two components, then each orbit is treated independently and nested (ie there are no dynamical/tidal effects - the inner orbit is treated as a single point mass in the outer orbit).
 * nbody: Use an n-body integrator to determine positions.  Here the initial conditions (positions and velocities) are still defined by the orbit's Keplerian parameters at 't0@system'.  Closed orbits and orbital stability are not guaranteed and ejections can occur.
ltte
Can you write Python code for it?


I am working on the file "2.1/tutorials/ORB.ipynb".
The first task is:
The 'ltte' parameter sets whether light travel time effects (Roemer delay) are included.  If set to False, the positions and velocities are returned as they actually are for that given object at that given time.  If set to True, they are instead returned as they were or will be when their light reaches the origin of the coordinate system.
See the Systemic Velocity Example Script for an example of how 'ltte' and 'vgamma' (systemic velocity) interplay.
Synthetics
Can you write Python code for it?

b.set_value_all('times', np.linspace(0,3,201))

b.run_compute()

b['orb@model'].twigs

print b['times@primary@orb01@orb@model']

print b['us@primary@orb01@orb@model']

print b['vus@primary@orb01@orb@model']


I am working on the file "2.1/tutorials/ORB.ipynb".
The first task is:
We can also plot the orbit in 3D.
Can you write Python code for it?

afig, mplfig = b['orb@model'].plot(projection='3d', xlim=(-4,4), ylim=(-4,4), zlim=(-4,4), show=True)


I am working on the file "2.1/tutorials/ORB.ipynb".
The first task is:
times
Can you write Python code for it?


I am working on the file "2.1/tutorials/RV.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['mesh01@model'].plot(fc='rvs', ec='None', show=True)


I am working on the file "2.1/tutorials/RV.ipynb".
The first task is:
Compute Options
Let's look at the compute options (for the default PHOEBE 2 backend) that relate to the RV dataset.
Other compute options are covered elsewhere:
* parameters related to dynamics are explained in the section on the orb dataset
* parameters related to meshing, eclipse detection, and subdivision (used if rv_method=='flux-weighted') are explained in the section on the mesh dataset
* parameters related to computing fluxes (used if rv_method=='flux-weighted') are explained in the section on the lc dataset
Can you write Python code for it?


I am working on the file "2.1/tutorials/RV.ipynb".
The first task is:
If rv_method is set to 'dynamical' then the computed radial velocities are simply the z-velocities of the centers of mass of each component.  In this case, only the dynamical options are relevant.  For more details on these, see the section on the orb dataset.
If rv_method is set to 'flux-weighted' then radial velocities are determined by the z-velocity of each visible surface element of the mesh, weighted by their respective intensities.  Since the stars are placed in their orbits by the dynamic options, the section on the orb dataset is still applicable.  So are the meshing options described in mesh dataset and the options for computing fluxes in lc dataset.
rv_grav
Can you write Python code for it?


I am working on the file "2.1/tutorials/RV.ipynb".
The first task is:
Plotting
By default, RV datasets plot as 'rvs' vs 'times'.
Can you write Python code for it?

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


I am working on the file "2.1/tutorials/RV.ipynb".
The first task is:
See the Gravitational Redshift Example Script for more details on the influence this parameter has on radial velocities.
Synthetics
Can you write Python code for it?

b.set_value_all('times', np.linspace(0,1,101))

b.run_compute(irrad_method='none')

b['rv@model'].twigs

print b['times@primary@rv@model']

print b['rvs@primary@rv@model']


I am working on the file "2.1/tutorials/RV.ipynb".
The first task is:
Since these are the only two columns available in the synthetic model, the only other options is to plot in phase instead of time.
Can you write Python code for it?

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


I am working on the file "2.1/tutorials/RV.ipynb".
The first task is:
rv_method
Can you write Python code for it?


I am working on the file "2.1/tutorials/RV.ipynb".
The first task is:
sigmas
Can you write Python code for it?


I am working on the file "2.1/tutorials/alternate_backends.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', times=np.linspace(0,10,1000), dataset='orb01', component=['primary', 'secondary'])

b.add_dataset('lc', times=np.linspace(0,10,1000), dataset='lc01')


I am working on the file "2.1/tutorials/alternate_backends.ipynb".
The first task is:
Running Multiple Backends Simultaneously
Running multiple backends simultaneously is just as simple as running the PHOEBE backend with multiple sets of compute options (see Compute).
We just need to make sure that each dataset is only enabled for one (or none) of the backends that we want to use, and then send a list of the compute tags to run_compute.  Here we'll use the PHOEBE backend to compute orbits and the legacy backend to compute light curves.
Can you write Python code for it?

b.set_value_all('enabled@lc01@phoebebackend', False)
#b.set_value_all('enabled@orb01@legacybackend', False)  # don't need this since legacy NEVER computes orbits
print b['enabled']

b.run_compute(['phoebebackend', 'legacybackend'], model='mixedresults')


I am working on the file "2.1/tutorials/alternate_backends.ipynb".
The first task is:
Using Alternate Backends
Adding Compute Options
Adding a set of compute options, via b.add_compute for an alternate backend is just as easy as for the PHOEBE backend.  Simply provide the function or name of the function in phoebe.parameters.compute that points to the parameters for that backend.
Here we'll add the default PHOEBE backend as well as the PHOEBE 1.0 (legacy) backend.  Note that in order to use an alternate backend, that backend must be installed on your machine.
Can you write Python code for it?

b.add_compute('phoebe', compute='phoebebackend')

print b['phoebebackend']


I am working on the file "2.1/tutorials/animations.ipynb".
The first task is:

Can you write Python code for it?

b['mesh01@model'].plot(times=times[:-1], fc='teffs', ec='None',
                       animate=True, save='animations_4.gif', save_kwargs={'writer': 'imagemagick'})


I am working on the file "2.1/tutorials/animations.ipynb".
The first task is:
3D axes
Plotting to 3D axes are supported.  In addition to the options for static plots, animations also support passing a list for the range of elevation/azimuth (in degrees) throughout the animation.
Can you write Python code for it?

b['orb01@model'].plot(times=times[:-1], projection='3d', azim=[0, 360], elev=[-20,20],
                      animate=True, save='animations_6.gif', save_kwargs={'writer': 'imagemagick'})


I am working on the file "2.1/tutorials/animations.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()

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

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

b.add_dataset('orb', times=times, dataset='orb01')

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

b.run_compute(irrad_method='none')


I am working on the file "2.1/tutorials/animations.ipynb".
The first task is:
Default Animations
By passing animate=True to b.show(), b.savefig(), or the final call to b.plot() along with save=filename or show=True will create an animation instead of a static plot.
Alternatively, you can call afig.animate() on the returned afig object returned by b.plot().
Can you write Python code for it?

afig, mplanim = b.plot(y={'orb': 'ws'},
                       animate=True, save='animations_1.gif', save_kwargs={'writer': 'imagemagick'})


I am working on the file "2.1/tutorials/animations.ipynb".
The first task is:
Disabling Fixed Limits
By default, as can be seen above in the mesh animation, the limits of the axes are automatically set so that they are fixed throughout the animation.
Sometimes this may not be desired.  By setting xlim='frame' (and/or ylim='frame'), the axes limits are determined automatically per-frame instead of fixed throughout the animation.
For more information and other options see the autofig tutorial on limits
Can you write Python code for it?

b['lc01@model'].plot(times=times[:-1], uncover=True, xlim='frame',
                    animate=True, save='animations_5.gif', save_kwargs={'writer': 'imagemagick'})


I am working on the file "2.1/tutorials/animations.ipynb".
The first task is:
Note that like the rest of the examples below, this is simply the animated version of the exact same call to plot
Providing Times
To override the default times explained above, pass a list or array to the times keyword.  For synthetic models, highlight mode will be enabled by default and the provided time does not need to be one that is computed - the value will be interpolated if it is not.  However, for plotting meshes, the exact time must be stored in the synthetic meshes or they will not be drawn.
This is especially usefully in cases where you may not want to repeat the first and last frame for a looping gif, or where you want a smoother animation by interpolation.  In this example we'll plot all but the last time so that the loop doesn't have a repeated frame.
In this example, times[:-1:2] means skip the last time and only use every-other time.
This option is not available from run_compute - a frame will be drawn for each computed time.
Can you write Python code for it?

afig, mplanim = b.plot(y={'orb': 'ws'},
                       times=times[:-1:2], animate=True, save='animations_2.gif', save_kwargs={'writer': 'imagemagick'})


I am working on the file "2.1/tutorials/animations.ipynb".
The first task is:
Plotting Options
By default, time highlighting is turned on.  See the plotting tutorial for details on 'highlight' and 'uncover' options.
Any additional arguments (colors, linestyle, etc) are passed to the plot call for EACH frame and for EVERY plotting call.
Can you write Python code for it?

afig, mplanim = b['lc01@model'].plot(times=times[:-1], uncover=True,\
                                     c='r', linestyle=':',\
                                     highlight_marker='s', highlight_color='g',
                                     animate=True, save='animations_3.gif', save_kwargs={'writer': 'imagemagick'})


I am working on the file "2.1/tutorials/apsidal_motion.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.1/tutorials/apsidal_motion.ipynb".
The first task is:
In order for apsidal motion to be apparent, we need an eccentric system that is precessing.
Can you write Python code for it?


I am working on the file "2.1/tutorials/apsidal_motion.ipynb".
The first task is:
Let's set a very noticeable rate of precession.
Can you write Python code for it?


I am working on the file "2.1/tutorials/atm_passbands.ipynb".
The first task is:
A 'passband' parameter exists for each passband-dependent-dataset (i.e. not meshes or orbits, but light curves and radial velocities).  This parameter dictates which passband should be used for the computation of all intensities.
Can you write Python code for it?


I am working on the file "2.1/tutorials/atm_passbands.ipynb".
The first task is:
And we'll add a single light curve dataset to expose all the passband-dependent options.
Can you write Python code for it?


I am working on the file "2.1/tutorials/atm_passbands.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.1/tutorials/atm_passbands.ipynb".
The first task is:
Lastly, to manually download and install one of these online passbands, you can do so explicitly via phoebe.download_passband.
Note that this isn't necessary unless you want to explicitly download passbands before needed by run_compute (perhaps if you're expecting to have unreliable network connection in the future and want to ensure you have all needed passbands).
Can you write Python code for it?


I am working on the file "2.1/tutorials/atm_passbands.ipynb".
The first task is:
Note that if you change the value of 'atm' to anything other than 'ck2004', the corresponding 'ld_func' will need to be changed to something other than 'interp' (warnings and errors will be raised to remind you of this).
Can you write Python code for it?

b['ld_func@primary']

b['atm@primary'] = 'blackbody'

print(b.run_checks())

b['ld_func@primary'] = 'logarithmic'

print(b.run_checks())


I am working on the file "2.1/tutorials/atm_passbands.ipynb".
The first task is:
Relevant Parameters
An 'atm' parameter exists for each of the components in the system (for each set of compute options) and defines which atmosphere table should be used.
By default, these are set to 'ck2004' (Castelli-Kurucz) but can be set to 'blackbody' as well as 'extern_atmx' and 'extern_planckint' (which are included primarily for direct comparison with PHOEBE legacy).
Can you write Python code for it?

b['atm']

b['atm@primary']

b['atm@primary'].description

b['atm@primary'].choices


I am working on the file "2.1/tutorials/atm_passbands.ipynb".
The first task is:
To see the passbands available from the online repository, call phoebe.list_online_passbands().
Can you write Python code for it?


I am working on the file "2.1/tutorials/atm_passbands.ipynb".
The first task is:
To see your current locally-installed passbands, call phoebe.list_installed_passbands().
Can you write Python code for it?


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

afig, mplfig = b['mesh@boosting_none'].plot(time=0.6, fc='boost_factors', ec='none', show=True)

afig, mplfig = b['mesh@boosting_linear'].plot(time=0.6, fc='boost_factors', ec='none', show=True)


I am working on the file "2.1/tutorials/beaming_boosting.ipynb".
The first task is:
Influence on Radial Velocities
Can you write Python code for it?

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


I am working on the file "2.1/tutorials/building_a_system.ipynb".
The first task is:
And request the parent, children, child, or sibling of any item in the hierarchy via get_parent_of, get_children_of, or get_sibling_of.
Can you write Python code for it?

print b.hierarchy.get_parent_of('primary')

print b.hierarchy.get_children_of('binary')

print b.hierarchy.get_child_of('binary', 0)  # here 0 means primary component, 1 means secondary

print b.hierarchy.get_sibling_of('primary')


I am working on the file "2.1/tutorials/building_a_system.ipynb".
The first task is:
Default Systems
Although the default empty Bundle doesn't include a system, there are available
constructors that create default systems.  To create a simple binary with component tags
'binary', 'primary', and 'secondary' (as above), you could call default_binary:
Can you write Python code for it?


I am working on the file "2.1/tutorials/building_a_system.ipynb".
The first task is:
For more details on dealing with contact binary systems, see the Contact Binary Example Script
Adding Components Manually
By default, an empty Bundle does not contain any information about our system.
So, let's first start by adding a few stars.  Here we'll call the generic add_component method.  This method works for any type of component in the system - stars, orbits, planets, disks, rings, spots, etc.  The first argument needs to be a callable or the name of a callable in phoebe.parameters.component which include the following options:

orbit
star
envelope

add_component also takes a keyword argument for the 'component' tag.  Here we'll give them component tags 'primary' and 'secondary' - but note that these are merely convenience labels and do not hold any special roles.  Some tags, however, are forbidden if they clash with other tags or reserved values - so if you get error stating the component tag is forbidden, try using a different string.
Can you write Python code for it?

b = phoebe.Bundle()

b.add_component(phoebe.component.star, component='primary')
b.add_component('star', component='secondary')


I am working on the file "2.1/tutorials/building_a_system.ipynb".
The first task is:
From now on, we'll just quickly do common setup at the beginning of each tutorial.
For full gory details on the general concepts here, make sure to read General Concepts.
We'll always start by doing our basic imports, setting up a logger, and initializing
an empty 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.Bundle()


I am working on the file "2.1/tutorials/building_a_system.ipynb".
The first task is:
Here we call the add_component method of the bundle with several arguments:

a function (or the name of a function) in phoebe.parameters.component.  This
  function tells the bundle what parameters need to be added.
component: the tag that we want to give this component for future reference.
any additional keyword arguments: you can also provide initial values for Parameters
  that you know will be created.  In the last example you can see that the
  effective temperature will already be set to 6000 (in default units which is K).

and then we'll do the same to add an orbit:
Can you write Python code for it?


I am working on the file "2.1/tutorials/building_a_system.ipynb".
The first task is:
If at any point we want to flip the primary and secondary components or make
this binary a triple, its seriously as easy as changing this hierarchy and
everything else will adjust as needed (including cross-ParameterSet constraints,
and datasets)
The Hierarchy Parameter
Setting the hierarchy just sets the value of a single parameter (although it may take some time because it also does a lot of paperwork and manages constraints between components in the system).  You can access that parameter as usual:
Can you write Python code for it?


I am working on the file "2.1/tutorials/building_a_system.ipynb".
The first task is:
Or you can ask for the component tag of the top-level item in the hierarchy via get_top.
Can you write Python code for it?


I am working on the file "2.1/tutorials/building_a_system.ipynb".
The first task is:
This HierarchyParameter then has several methods unique to itself.  You can, for instance, list the component tags of all the stars or orbits in the hierarchy via get_stars or get_orbits, respectively:
Can you write Python code for it?

print b.hierarchy.get_stars()

print b.hierarchy.get_orbits()


I am working on the file "2.1/tutorials/building_a_system.ipynb".
The first task is:
We can also check whether a given component (by component tag) is the primary or secondary component in its parent orbit via get_primary_or_secondary.  Note that here its just a coincidence (although on purpose) that the component tag is also 'secondary'.
Can you write Python code for it?


I am working on the file "2.1/tutorials/building_a_system.ipynb".
The first task is:
We could just as easily have used this string to set the hierarchy:
Can you write Python code for it?


I am working on the file "2.1/tutorials/building_a_system.ipynb".
The first task is:
or
Can you write Python code for it?


I am working on the file "2.1/tutorials/building_a_system.ipynb".
The first task is:
or through any of these shortcuts:
Can you write Python code for it?


I am working on the file "2.1/tutorials/compute.ipynb".
The first task is:
Accessing Synthetics from Models
The synthetics can be accessed by their dataset and model tags.
Can you write Python code for it?

b['run_with_incl_90']

b['primary@run_with_incl_90']

b['us@primary@run_with_incl_90']


I am working on the file "2.1/tutorials/compute.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(phoebe.dataset.orb, times=np.linspace(0,10,10), dataset='orb01', component=['primary', 'secondary'])

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

# test.lc.in has 1000 datapoints... let's use every 10 just for brevity
times, fluxes, sigmas = times[:10], fluxes[:10], sigmas[:10]

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


I am working on the file "2.1/tutorials/compute.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.1/tutorials/compute.ipynb".
The first task is:
Default Compute Options
Any default Bundle already has a set of default compute options to run the backend for PHOEBE 2.  In most cases, you can just edit the options in this default set of compte options.
Can you write Python code for it?

print b.computes

print b.filter(context='compute')

b.set_value('irrad_method', 'none')


I am working on the file "2.1/tutorials/compute.ipynb".
The first task is:
Storing Models
Now let's compute models for three different 'versions' of parameters.  By providing a model tag, we can keep the synthetics for each of these different runs in the bundle - which will be handy later on for plotting and comparing models.
Can you write Python code for it?

b.set_value('incl@orbit', 90)
b.run_compute(compute='preview', model='run_with_incl_90')

b.set_value('incl@orbit', 85)
b.run_compute(compute='preview', model='run_with_incl_85')

b.set_value('incl@orbit', 80)
b.run_compute(compute='preview', model='run_with_incl_80')


I am working on the file "2.1/tutorials/compute.ipynb".
The first task is:
We probably have the same problem with 'lc01', but just didn't get far enough to raise the error.  So let's fix that as well
Can you write Python code for it?

print b['enabled@lc01']

b.set_value_all('enabled@lc01@detailed', True)
b.set_value_all('enabled@lc01@preview', False)
print b['enabled@lc01']


I am working on the file "2.1/tutorials/compute.ipynb".
The first task is:
as you can see, there is a copy for both of our compute options ('preview' and 'detailed').
If we know which set of compute options we'll be using, or only want to enable/disable for a given set, then we can do that:
Can you write Python code for it?

b['enabled@lc01@preview'] = False
print b['enabled@lc01']


I am working on the file "2.1/tutorials/compute.ipynb".
The first task is:
or of course through method access:
Can you write Python code for it?

print b.get_value(qualifier='us', dataset='orb01', component='primary', model='run_with_incl_90')[:10]


I am working on the file "2.1/tutorials/constraints.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.1/tutorials/constraints.ipynb".
The first task is:
Even though under-the-hood the constraints are being rebuilt from scratch, they will remember if you have flipped them to solve for some other parameter.
To show this, let's flip the constraint for the secondary mass to solve for 'period' and then change the hierarchy back to its original value.
Can you write Python code for it?

print "M1: {}, M2: {}, period: {}, q: {}".format(b.get_value('mass@primary@component'),
                                                 b.get_value('mass@secondary@component'),
                                                 b.get_value('period@binary@component'),
                                                 b.get_value('q@binary@component'))

b.flip_constraint('mass@secondary@constraint', 'period')

print "M1: {}, M2: {}, period: {}, q: {}".format(b.get_value('mass@primary@component'),
                                                 b.get_value('mass@secondary@component'),
                                                 b.get_value('period@binary@component'),
                                                 b.get_value('q@binary@component'))

b.set_value('mass@secondary@component', 1.0)

print "M1: {}, M2: {}, period: {}, q: {}".format(b.get_value('mass@primary@component'),
                                                 b.get_value('mass@secondary@component'),
                                                 b.get_value('period@binary@component'),
                                                 b.get_value('q@binary@component'))


I am working on the file "2.1/tutorials/constraints.ipynb".
The first task is:
Here we see the equation used to derive the mass of the primary star
from its orbit, as well as the current value
If we access the Parameter that it is constraining we can see that it
is automatically kept up-to-date.
Can you write Python code for it?


I am working on the file "2.1/tutorials/constraints.ipynb".
The first task is:
If you change the hierarchy, built-in cross-object constraints (like mass
that depends on its parent orbit), will be adjusted to reflect the new hierarchy.  See the 'Changing Hierarchies' section below for more details.
Built-in Constraints
There are a number of built-in constraints that can be applied to our system.  Those added by default are all listed below:
asini
This constraint handles computing the projected semi-major axis along the line of sight and can be automatically inverted to solve for either 'asini', 'sma', or 'incl'.
Can you write Python code for it?


I am working on the file "2.1/tutorials/constraints.ipynb".
The first task is:
Re-Parameterizing
NOTE: this is an experimental feature.  When re-parameterizing, please be
careful and make sure all results and parameters make sense.
As we've just seen, the mass is a constrained (ie derived) parameter.  But
let's say that you would rather provide masses for some reason (perhaps
that was what was provided in a paper).  You can choose to provide mass
and instead have one of its related parameters constrained by calling flip_constraint.
Can you write Python code for it?

print b['mass@primary@component'].constrained_by

print b['value@mass@primary@component'], b['value@mass@secondary@component'], b['value@period@orbit@component']

b.flip_constraint('mass@primary', 'period')

b['mass@primary@component'] = 1.0

print b['value@mass@primary@component'], b['value@mass@secondary@component'], b['value@period@orbit@component']


I am working on the file "2.1/tutorials/constraints.ipynb".
The first task is:
The parameter is aware that it's being
constrained and all the relevant linking parameters.
Can you write Python code for it?


I am working on the file "2.1/tutorials/constraints.ipynb".
The first task is:
You'll see that when we set the primary mass, the secondary mass has also changed (because the masses are related through q) and the period has changed (based on resolving the Kepler's third law constraint).
Note that the tags for the constraint are based on those of the constrained parameter, so to switch the parameterization back, we'll have to use a slightly different twig.
Can you write Python code for it?

print b['constraint']

b['period@constraint@binary']

b['period@constraint@binary'].meta


I am working on the file "2.1/tutorials/constraints.ipynb".
The first task is:
freq
This constraint handles the simple conversion to frequency from period - whether that be rotational or orbital - and does support inversion to solve for 'period'.
Can you write Python code for it?

b['freq@constraint']

b['freq@binary@constraint']

b['freq@primary@constraint']


I am working on the file "2.1/tutorials/constraints.ipynb".
The first task is:
mass
This constraint handles solving for the mass of a component by obeying Kepler's third law within the parent orbit.
It can be inverted to solve for 'sma' or 'period' (in addition to 'mass'), but not 'q'.
Can you write Python code for it?