A straightforward example

This is a simple example of how to generate a model for spiderman, here, we will generate a model that was fit to WASP-43

First, import the module


In [2]:
import spiderman as sp

Now we need to generate a parameter instance and choose a brightness model for the planet surface. In this example we will use the analytical formula given in Zhang and Showman 2016


In [3]:
spider_params = sp.ModelParams(brightness_model='zhang')

All the model parameters are stored in this class. First, choose the resolution of the model. Resolutions of 5 are sufficient for typical data quality, but higher resolutions do not take much longer to calculate and look much nicer :)


In [4]:
spider_params.n_layers= 20

The next set of parameters are the system parameters these can often be well constrained from other measurements, their definitions are given. (Note, these definitions are compatible with Batman)


In [5]:
spider_params.t0= 200               # Central time of PRIMARY transit [days]
spider_params.per= 0.81347753       # Period [days]
spider_params.a_abs= 0.01526        # The absolute value of the semi-major axis [AU]
spider_params.inc= 82.33            # Inclination [degrees]
spider_params.ecc= 0.0              # Eccentricity
spider_params.w= 90                 # Argument of periastron
spider_params.rp= 0.1594            # Planet to star radius ratio
spider_params.a= 4.855              # Semi-major axis scaled by stellar radius
spider_params.p_u1= 0               # Planetary limb darkening parameter
spider_params.p_u2= 0               # Planetary limb darkening parameter

Now set the parameters specific to the brightness model that we defined earlier


In [6]:
spider_params.xi= 0.3       # Ratio of radiative to advective timescale             
spider_params.T_n= 1128     # Temperature of nightside
spider_params.delta_T= 942  # Day-night temperature contrast
spider_params.T_s = 4500    # Temperature of the star

Since this particular model specifies temperature, not brightness, we need to know the wavelength region in order to transform Temperature contrast to the observable brightness contrast - these are typically fixed parameters, not model parameters


In [7]:
spider_params.l1 = 1.1e-6   # Lower wavelength bound (m)
spider_params.l2 = 1.7e-6   # upper wavelength bound (m)

SPIDERMAN makes it easy to plot this model at a given time, let's first display how the planet would appear at primary transit


In [8]:
% matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

In [9]:
t = spider_params.t0

spider_params.plot_planet(t)

fname = 'f1'
plt.savefig('../docs/images/'+fname+'.png',bbox_inches='tight')
plt.savefig('../docs/images/'+fname+'.pdf',bbox_inches='tight')

plt.show()


And at secondary:


In [10]:
t = spider_params.t0 + spider_params.per/2.0

spider_params.plot_planet(t)

fname = 'f2'
plt.savefig('../docs/images/'+fname+'.png',bbox_inches='tight')
plt.savefig('../docs/images/'+fname+'.pdf',bbox_inches='tight')

plt.show()


For some models, such as the zhang model, temperature and brightness are calculated. Both can be plotted


In [11]:
spider_params.plot_planet(t,temp_map=True)

fname = 'f3'
plt.savefig('../docs/images/'+fname+'.png',bbox_inches='tight')
plt.savefig('../docs/images/'+fname+'.pdf',bbox_inches='tight')

plt.show()


Since the brightness will approximately be proportional to the 4th power of temperature, the contrast on the hotspot is lower in this instance.

It is also possible to create a system plot, to see the planet in context


In [12]:
t = spider_params.t0 + spider_params.per/4.0

spider_params.plot_system(t)

fname = 'f4'
plt.savefig('../docs/images/'+fname+'.png',bbox_inches='tight')
plt.savefig('../docs/images/'+fname+'.pdf',bbox_inches='tight')

plt.show()


You can also specify in phase instead


In [13]:
p = 0.0

spider_params.plot_system(p,use_phase=True,show_cax=False)

fname = 'f5'
plt.savefig('../docs/images/'+fname+'.png',bbox_inches='tight')
plt.savefig('../docs/images/'+fname+'.pdf',bbox_inches='tight')

plt.show()


This image is to scale. It's easy to make some neat visualisations of the orbit by combining saved output from this function with something like mencoder.

NOTE: SPIDERMAN does not compute primary transits. To do this, you have to combine with a separate code, such as Batman (kriedberg et al 2015)

Now let's actually recover a lightcurve


In [14]:
t= spider_params.t0 + np.linspace(0, + spider_params.per*3,100)

lc = spider_params.lightcurve(t)
plt.plot(t,lc)

plt.set_ylabel('Relative flux')
plt.set_xlabel('Time (days)')

fname = 'f6'
plt.savefig('../docs/images/'+fname+'.png',bbox_inches='tight')
plt.savefig('../docs/images/'+fname+'.pdf',bbox_inches='tight')

plt.show()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-14-b14b1bedda44> in <module>()
      4 plt.plot(t,lc)
      5 
----> 6 plt.set_ylabel('Relative flux')
      7 plt.set_xlabel('Time (days)')
      8 

AttributeError: 'module' object has no attribute 'set_ylabel'

In [ ]:
t= spider_params.t0 + np.linspace(0, + spider_params.per,100)

wvls = [[0.9e-6,1.0e-6],[1e-6,1.1e-6],[1.1e-6,1.2e-6]]

for i in range(0,len(wvls)):
    spider_params.l1 = wvls[i][0]   # Lower wavelength bound (m)
    spider_params.l2 = wvls[i][1]   # upper wavelength bound (m)    
    lc = spider_params.lightcurve(t)
    plt.plot(t,lc)

fname = 'f7'
plt.savefig('../docs/images/'+fname+'.png',bbox_inches='tight')
plt.savefig('../docs/images/'+fname+'.pdf',bbox_inches='tight')

plt.show()

In [ ]: