-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from kolbylyn/hw9
Hw9
- Loading branch information
Showing
1 changed file
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {} | ||
} | ||
] | ||
} |