Skip to content

Instantly share code, notes, and snippets.

@hannorein
Created December 4, 2015 00:42
Show Gist options
  • Save hannorein/c370908f94042491c3ca to your computer and use it in GitHub Desktop.
Save hannorein/c370908f94042491c3ca to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Detecting Transits with REBOUND\n",
"The following code finds transits along the x-axis of a one planet system."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import rebound\n",
"import math"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"sim = rebound.Simulation()\n",
"sim.add(m=1)\n",
"sim.add(a=1,e=0.1,omega=0.25)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"6.07928466797\n",
"12.3624627686\n",
"18.6456561279\n",
"24.9288342285\n",
"31.2120275879\n"
]
}
],
"source": [
"transittimes = []\n",
"p = sim.particles\n",
"while len(transittimes)<5:\n",
" y_old = p[1].y\n",
" t_old = sim.t\n",
" DT = 1. # check for transits every DT time units. DT must be shorter than one orbit\n",
" sim.integrate(sim.t+DT) \n",
" t_new = sim.t\n",
" if y_old*p[1].y<0. and p[1].x>0.: # sign changed:\n",
" while math.fabs(p[1].y)>1e-5: # bisect until prec of 1e-5 reached\n",
" if y_old*p[1].y<0.:\n",
" t_new = sim.t\n",
" else:\n",
" t_old = sim.t\n",
" sim.integrate( (t_new+t_old)/2.)\n",
" transittimes.append(sim.t)\n",
" print sim.t\n",
" sim.integrate(sim.t+0.01) # integrate a little to be past the transit "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment