Skip to content

A2. Python Bindings

Jason Rowe edited this page Jul 27, 2016 · 2 revisions

I am slowly writing python wrappers around many of the FORTRAN tools. I haven't included the python bindings in the Makefile (yet), but it's not too hard to build them yourself.

Currently there are binds for the transitfit5 tool suite. Go into the transitfit5/utils directory and use f2py to build the python modules:

f2py3.5 --fcompiler=intelem -c tfit5.pyf transitmodel.f keplerian.f ttcor.f occultquad.f mandelagol.f rqsort.f transitdur.f  
f2py3.5 --fcompiler=intelem -c fittransitmodel3.pyf precision.f90 fittermod.f90 fittransitmodel3.f90 getrhosig.f minpack.f  

This will create two .so files that you can move into your python modules directory (or local directory). You also need to copy 'transitfit5.py' as well, which contains some simple wrappers to use the code. Here's an example to use the bindings:

import transitfit5 as tf #import transitfit5 modules
time,flux,ferr = tf.readphotometry("klc07603200.dct.dat") #read in photometry 
sol,serr=tf.readsol("n0.dat") #read in a transit solution
ntt,tobs,omc = tf.readtt('koi0314.01.tt','koi0314.02.tt','koi0314.03.tt') #read in TTVs  
#tmodel=tf.transitmodel(sol,time,ntt=ntt,tobs=tobs,omc=omc) #get the transit model
sol2=tf.fittrmodel(time,flux,ferr,sol,serr,ntt=ntt,tobs=tobs,omc=omc) #fitting a transit
tf.transitplot(time,flux,sol2,nplanetplot=1,ntt=ntt,tobs=tobs,omc=omc) #plot the phase and model

This will import some data, fit a model and then plot it. Yeap.. it's that simple. Have fun and feel free to provide feedback.

I have also place a Jupyter worksheet in the example directory to help out.