forked from rbiswas4/FeatureRobustness
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ipython notebook to generate mock data from 3 simulations
- Loading branch information
Showing
1 changed file
with
366 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,366 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Neural networks not available in this version of scikit-learn. Neural networks are available from development version 0.18.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%load_ext autoreload\n", | ||
"%autoreload #Use this to reload modules if they are changed on disk while the notebook is running\n", | ||
"from __future__ import division\n", | ||
"from snmachine import sndata, snfeatures, snclassifier, tsne_plot\n", | ||
"import numpy as np\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import time, os, pywt,subprocess\n", | ||
"from sklearn.decomposition import PCA\n", | ||
"from astropy.table import Table,join,vstack\n", | ||
"from astropy.io import fits\n", | ||
"import sklearn.metrics \n", | ||
"import sncosmo\n", | ||
"%matplotlib nbagg\n", | ||
"from astropy.table import Column" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## SN numbers with classification code\n", | ||
"SN001695 - 33\n", | ||
"\n", | ||
"2457 - 33\n", | ||
"\n", | ||
"2542 - 1\n", | ||
"\n", | ||
"5399 - 2\n", | ||
"\n", | ||
"13481 - 2\n", | ||
"\n", | ||
"13866 - 1 \n", | ||
"\n", | ||
"16742 - 21\n", | ||
"\n", | ||
"17270 - 32\n", | ||
"\n", | ||
"27266 -32\n", | ||
"\n", | ||
"64968 - 23\n", | ||
"\n", | ||
"149147 -21" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"dataset='spcc'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"1" | ||
] | ||
}, | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"# WARNING...\n", | ||
"#Multinest uses a hardcoded character limit for the output file names. I believe it's a limit of 100 characters\n", | ||
"#so avoid making this file path to lengthy if using nested sampling or multinest output file names will be truncated\n", | ||
"\n", | ||
"#Change outdir to somewhere on your computer if you like\n", | ||
"outdir=os.path.join('output_%s_no_z' %dataset,'')\n", | ||
"out_features=os.path.join(outdir,'features') #Where we save the extracted features to\n", | ||
"out_class=os.path.join(outdir,'classifications') #Where we save the classification probabilities and ROC curves\n", | ||
"out_int=os.path.join(outdir,'int') #Any intermediate files (such as multinest chains or GP fits)\n", | ||
"\n", | ||
"subprocess.call(['mkdir',outdir])\n", | ||
"subprocess.call(['mkdir',out_features])\n", | ||
"subprocess.call(['mkdir',out_class])\n", | ||
"subprocess.call(['mkdir',out_int])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"#Data root\n", | ||
"rt=os.path.join('SPCC_SUBSET','')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Reading data...\n", | ||
"11 objects read into memory.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"dat=sndata.Dataset(rt)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"read_from_file=True #We can use this flag to quickly rerun from saved features\n", | ||
"run_name=os.path.join(out_features,'%s_all' %dataset)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 14, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"'DES_SN001695.DAT'" | ||
] | ||
}, | ||
"execution_count": 14, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"dat.object_names[0]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 15, | ||
"metadata": { | ||
"collapsed": false, | ||
"scrolled": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"test_table = dat.data['DES_SN001695.DAT'] #get_lightcurve" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 16, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"type_II = []\n", | ||
"for i in range(len(dat.data['DES_SN001695.DAT']['flux'])):\n", | ||
" type_II.append(np.random.normal(dat.data['DES_SN001695.DAT']['flux'][i], dat.data['DES_SN001695.DAT']['flux_error'][i], 1000))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 19, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"type_Ia = []\n", | ||
"for i in range(len(dat.data['DES_SN002542.DAT']['flux'])):\n", | ||
" type_Ia.append(np.random.normal(dat.data['DES_SN002542.DAT']['flux'][i], dat.data['DES_SN002542.DAT']['flux_error'][i], 1000))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 20, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"type_Ibc = []\n", | ||
"for i in range(len(dat.data['DES_SN005399.DAT']['flux'])):\n", | ||
" type_Ia.append(np.random.normal(dat.data['DES_SN005399.DAT']['flux'][i], dat.data['DES_SN005399.DAT']['flux_error'][i], 1000))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 21, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"type_Ia = np.array(type_Ia)\n", | ||
"type_Ibc = np.array(type_Ibc)\n", | ||
"type_II = np.array(type_II)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 25, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"test_table.replace_column('flux', type_II[:,0])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 28, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"#test_table.write('testing.dat',format = 'ascii')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 24, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<Table length=128>\n", | ||
"<table id=\"table4357163664\">\n", | ||
"<thead><tr><th>mjd</th><th>filter</th><th>flux</th><th>flux_error</th><th>zp</th><th>zpsys</th></tr></thead>\n", | ||
"<thead><tr><th>float64</th><th>str4</th><th>float64</th><th>float64</th><th>float64</th><th>str2</th></tr></thead>\n", | ||
"<tr><td>0.0</td><td>desg</td><td>3.874</td><td>4.787</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>0.0160000000033</td><td>desr</td><td>-5.456</td><td>5.335</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>0.0310000000027</td><td>desi</td><td>-10.3</td><td>5.439</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>0.0619999999981</td><td>desz</td><td>1.439</td><td>4.691</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>2.0</td><td>desg</td><td>-0.7297</td><td>2.238</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>2.14</td><td>desr</td><td>-2.837</td><td>3.03</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>2.156</td><td>desi</td><td>-4.236</td><td>4.2</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>2.187</td><td>desz</td><td>-5.086</td><td>3.518</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>9.984</td><td>desg</td><td>0.03404</td><td>1.702</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>10.0</td><td>desr</td><td>0.8236</td><td>1.251</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>...</td><td>...</td><td>...</td><td>...</td><td>...</td><td>...</td></tr>\n", | ||
"<tr><td>135.918</td><td>desi</td><td>4.008</td><td>3.081</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>139.894</td><td>desz</td><td>8.095</td><td>4.252</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>143.863</td><td>desg</td><td>4.442</td><td>2.914</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>143.871</td><td>desr</td><td>0.7718</td><td>1.365</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>143.894</td><td>desi</td><td>3.976</td><td>3.218</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>148.867</td><td>desz</td><td>5.982</td><td>2.609</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>155.871</td><td>desg</td><td>-0.109</td><td>1.816</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>155.879</td><td>desr</td><td>0.3982</td><td>1.383</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>156.871</td><td>desi</td><td>1.149</td><td>2.177</td><td>27.5</td><td>ab</td></tr>\n", | ||
"<tr><td>157.871</td><td>desz</td><td>16.46</td><td>3.394</td><td>27.5</td><td>ab</td></tr>\n", | ||
"</table>" | ||
], | ||
"text/plain": [ | ||
"<Table length=128>\n", | ||
" mjd filter flux flux_error zp zpsys\n", | ||
" float64 str4 float64 float64 float64 str2\n", | ||
"--------------- ------ ------- ---------- ------- -----\n", | ||
" 0.0 desg 3.874 4.787 27.5 ab\n", | ||
"0.0160000000033 desr -5.456 5.335 27.5 ab\n", | ||
"0.0310000000027 desi -10.3 5.439 27.5 ab\n", | ||
"0.0619999999981 desz 1.439 4.691 27.5 ab\n", | ||
" 2.0 desg -0.7297 2.238 27.5 ab\n", | ||
" 2.14 desr -2.837 3.03 27.5 ab\n", | ||
" 2.156 desi -4.236 4.2 27.5 ab\n", | ||
" 2.187 desz -5.086 3.518 27.5 ab\n", | ||
" 9.984 desg 0.03404 1.702 27.5 ab\n", | ||
" 10.0 desr 0.8236 1.251 27.5 ab\n", | ||
" ... ... ... ... ... ...\n", | ||
" 135.918 desi 4.008 3.081 27.5 ab\n", | ||
" 139.894 desz 8.095 4.252 27.5 ab\n", | ||
" 143.863 desg 4.442 2.914 27.5 ab\n", | ||
" 143.871 desr 0.7718 1.365 27.5 ab\n", | ||
" 143.894 desi 3.976 3.218 27.5 ab\n", | ||
" 148.867 desz 5.982 2.609 27.5 ab\n", | ||
" 155.871 desg -0.109 1.816 27.5 ab\n", | ||
" 155.879 desr 0.3982 1.383 27.5 ab\n", | ||
" 156.871 desi 1.149 2.177 27.5 ab\n", | ||
" 157.871 desz 16.46 3.394 27.5 ab" | ||
] | ||
}, | ||
"execution_count": 24, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"#dat.data['DES_SN001695.DAT']" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"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.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |