Skip to content

Instantly share code, notes, and snippets.

@simonrw
Created December 19, 2014 14:33
Show Gist options
  • Select an option

  • Save simonrw/3092760b73c8f59cb8cc to your computer and use it in GitHub Desktop.

Select an option

Save simonrw/3092760b73c8f59cb8cc to your computer and use it in GitHub Desktop.
{
"metadata": {
"name": "",
"signature": "sha256:5fddeb641c99360902951f4e05e71fa0f22d867941f2dd43429f5ebb3d5b3fca"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"North/South efficiency"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We want to roughly see how much more efficient Super-WASP is compared to WASP South. We see how many planets that have been discovered (using the [exoplanet.eu](http://exoplanet.eu) database) are north, south or within a configurable distance to the equator, and named equatorial planets.\n",
"\n",
"We then take the stellar distribution defined by our sample cuts, [assume the sensitivity of the instrument and analysis is the same between the two projects](#Sensitivity), and compare the [detection efficiency](#Efficiency)."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%load_ext watermark\n",
"%watermark -a \"Simon Walker\" -n -u -v -h -m"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The watermark extension is already loaded. To reload it, use:\n",
" %reload_ext watermark\n",
"Simon Walker \n",
"Last updated: Fri Dec 19 2014 \n",
"\n",
"CPython 2.7.9\n",
"IPython 2.3.1\n",
"\n",
"compiler : GCC 4.2.1 (Apple Inc. build 5577)\n",
"system : Darwin\n",
"release : 13.4.0\n",
"machine : x86_64\n",
"processor : i386\n",
"CPU cores : 8\n",
"interpreter: 64bit\n",
"host name : mbp15.local\n"
]
}
],
"prompt_number": 52
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%matplotlib inline\n",
"from __future__ import print_function, division\n",
"import matplotlib.pyplot as plt\n",
"import requests\n",
"import vcr\n",
"import csv\n",
"from collections import namedtuple\n",
"import sqlite3"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 53
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We define the exclusion zone around the equator at 20 degrees."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"equatorial_exclusion = 20"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 26
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"class SampleObject(namedtuple('SampleObject', ['name', 'ra', 'dec'])):\n",
" def is_north(self):\n",
" return dec > equatorial_exclusion\n",
" \n",
" def is_south(self):\n",
" return dec < -equatorial_exclusion "
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 95
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Planet sample"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Download the exoplanet.eu database. Use vcr to cache the response."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"with vcr.use_cassette('exoplanet.eu.cassette'):\n",
" response = requests.get('http://exoplanet.eu/catalog/csv/')\n",
" assert response.status_code == 200"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 119
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Parse the response csv text and create collections of north, south and equatorial planets"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"lines = response.text.split('\\n')\n",
"reader = csv.DictReader(lines)\n",
"north_planets, south_planets, equatorial_planets = [], [], []\n",
"for line in reader:\n",
" planet_name = line['# name']\n",
" if 'WASP-' in planet_name:\n",
" ra, dec = map(float, [line[' ra'], line[' dec']])\n",
" sample_object = SampleObject(planet_name, ra, dec)\n",
" \n",
" if sample_object.is_north():\n",
" north_planets.append(sample_object)\n",
" elif sample_object.is_south():\n",
" south_planets.append(sample_object)\n",
" else:\n",
" equatorial_planets.append(sample_object)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 97
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's look at the numbers"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print('North planets:', len(north_planets))\n",
"print('South planets:', len(south_planets))\n",
"print('Equatorial planets:', len(equatorial_planets))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"North planets: 12\n",
"South planets: 41\n",
"Equatorial planets: 47\n"
]
}
],
"prompt_number": 98
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Stellar sample"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we fetch the stellar sample from the sample `sqlite3` database. First some units conversions to get the object coordinates from the obj_id."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def to_degrees(a, b, c):\n",
" return a + b / 60. + c / 3600.\n",
"\n",
"ra_to_degrees = lambda *args: to_degrees(*args) * 15.\n",
"\n",
"dec_to_degrees = lambda a, b, c, sign: to_degrees(a, b, c) if sign == '+' else -to_degrees(a, b, c)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 82
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now the code to get the coordinates as floating point numbers."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def obj_id_to_coordinates(obj_id):\n",
" coord_part = obj_id.split()[1].replace('J', '')\n",
" ra_part, dec_part = coord_part[:9], coord_part[9:]\n",
" ra = ra_to_degrees(*map(float, [\n",
" ra_part[:2], ra_part[2:4], ra_part[4:]\n",
" ]))\n",
" dec = dec_to_degrees(float(dec_part[1:3]),\n",
" float(dec_part[3:5]),\n",
" float(dec_part[5:]),\n",
" dec_part[0])\n",
" \n",
" return ra, dec"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"An example to test the conversion"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(obj_id_to_coordinates('1SWASP J090256.69+053135.2'))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"(135.73620833333334, 5.5264444444444445)\n"
]
}
],
"prompt_number": 123
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Extract the coordinates from the sqlite database"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"north_stars, south_stars, equatorial_stars = [], [], []\n",
"with sqlite3.connect('./included_stellar_sample.sqlite') as connection:\n",
" cursor = connection.cursor()\n",
" cursor.execute('select obj_id from selected')\n",
" \n",
" for obj_id, in cursor:\n",
" ra, dec = obj_id_to_coordinates(obj_id)\n",
" star = SampleObject(obj_id, ra, dec)\n",
" \n",
" if star.is_north():\n",
" north_stars.append(star)\n",
" elif star.is_south():\n",
" south_stars.append(star)\n",
" else:\n",
" equatorial_stars.append(star)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 124
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print('North stars:', len(north_stars))\n",
"print('South stars:', len(south_stars))\n",
"print('Equatorial stars:', len(equatorial_stars))\n",
"print('Total stars:', sum([len(north_stars), len(south_stars), len(equatorial_stars)]))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"North stars: 308923\n",
"South stars: 359946\n",
"Equatorial stars: 373306\n",
"Total stars: 1042175\n"
]
}
],
"prompt_number": 125
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Efficiency"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As stated above, we assume the sensitivity of the two projects is the same so therefore the number of planets detected over the number of stars in the sample should be proportional to the occurrence rates measured."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"efficiency = lambda planets, stars: len(planets) * 1E6 / len(stars)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 126
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print('North efficiency: {:.3f} per million'.format(efficiency(north_planets, north_stars)))\n",
"print('South efficiency: {:.3f} per million'.format(efficiency(south_planets, south_stars)))\n",
"print('Equatorial efficiency: {:.3f} per million'.format(efficiency(equatorial_planets, equatorial_stars)))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"North efficiency: 38.845 per million\n",
"South efficiency: 113.906 per million\n",
"Equatorial efficiency: 125.902 per million\n"
]
}
],
"prompt_number": 117
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The north is clearly more efficient than the south, but interestingly the equatorial efficiency is higher also. This is likely the same reason the south is more efficient: more available follow up."
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Sensitivity"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We say we assume the sensitivity of the two projects is equal. This can be tested by computing the sensitivity map for the two/three groups separately."
]
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment