Skip to content

Commit

Permalink
Merge pull request #156 from kolbylyn/hw9
Browse files Browse the repository at this point in the history
Hw9
  • Loading branch information
jakevdp committed Dec 8, 2014
2 parents f20ffdd + 8de5d8f commit 2b28dd9
Showing 1 changed file with 125 additions and 0 deletions.
125 changes: 125 additions & 0 deletions kolbylyn/HW9.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"metadata": {
"name": "",
"signature": "sha256:3260a7771f92dd49feefef577b057348707f07966e6b31d57a2e8968bba2968f"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Homework 9 - Computing Periods of Stars\n",
"#### Kolby Weisenburger"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" We can import %px magic cell to use use the parallel execute function. Here I am using the same code from lecture to determine the period."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from IPython import parallel\n",
"clients = parallel.Client()\n",
"clients.block = True # use synchronous computations\n",
"print(clients.ids)\n",
"dview = clients[:]\n",
"dview.block = True"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[0, 1, 2, 3]\n"
]
}
],
"prompt_number": 13
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%px \n",
"import numpy as np\n",
"\n",
"from astroML.time_series import lomb_scargle\n",
"periods = np.logspace(-2, 0, 10000)\n",
"\n",
"def getper(id):\n",
" time, flux, dflux = lcs[id].T\n",
" periodogram = lomb_scargle(time, flux, dflux, omega=2 * np.pi / periods, generalized=True)\n",
" idx = np.argsort(periodogram)\n",
" return periods[idx[-1]]\n"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 14
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we can use the same .execute function that was shown in lecture. The command we would like to execute goes in the quotation marks."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from astroML.datasets import fetch_LINEAR_sample\n",
"lcs = fetch_LINEAR_sample()\n",
"\n",
"dview.scatter('ids', lcs.ids)\n",
"dview.execute('allper = [getper(id) for id in lcs.ids]')\n",
"allper = dview.gather('allper')\n",
"\n",
"print allper"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"g_r = [lcs.get_target_parameter(id, 'gr') for id in lcs.ids]"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"\n",
"plt.scatter(g_r, allper, alpha=0.4)\n",
"plt.xlabel('g-r')\n",
"plt.ylabel('Period')\n",
"plt.show()"
],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}

0 comments on commit 2b28dd9

Please sign in to comment.