Created
June 2, 2017 20:49
-
-
Save nudomarinero/5821f255c9c5b184ddf7d828ad315804 to your computer and use it in GitHub Desktop.
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
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Download the table" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"import urllib.request" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"url = \"http://iopscience.iop.org/0004-637X/820/1/67/suppdata/apj522884t2_ascii.txt\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"raw_response = urllib.request.urlopen(url).read()\n", | |
"txt = raw_response.decode('utf-8')" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Clean and save the data" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"clean_txt = txt.replace(\"\\t\\n\", \"\\n\").replace(\"\\t\",\",\").replace(\"(\",\",\").replace(\")\",\"\").replace(\"cdots\", \",\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"new_txt = \"\\n\".join(t for t in clean_txt.split(\"\\n\")[7:-4])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"with open(\"test.txt\", \"w\") as out:\n", | |
" out.write(new_txt)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Load the data with astropy" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"columns = [\"JD\", \"Phase\", \"U\", \"Uerr\", \"B\", \"Berr\", \"V\", \"Verr\", \"R\", \"Rerr\", \"I\", \"Ierr\", \"Telescope\"]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"from astropy.table import Table" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<Table masked=True length=118>\n", | |
"<table id=\"table139683061232640\" class=\"table-striped table-bordered table-condensed\">\n", | |
"<thead><tr><th>JD</th><th>Phase</th><th>U</th><th>Uerr</th><th>B</th><th>Berr</th><th>V</th><th>Verr</th><th>R</th><th>Rerr</th><th>I</th><th>Ierr</th><th>Telescope</th></tr></thead>\n", | |
"<thead><tr><th>float64</th><th>float64</th><th>float64</th><th>int64</th><th>float64</th><th>int64</th><th>float64</th><th>int64</th><th>float64</th><th>int64</th><th>float64</th><th>int64</th><th>str4</th></tr></thead>\n", | |
"<tr><td>5798.53</td><td>-15.95</td><td>14.534</td><td>14</td><td>14.743</td><td>13</td><td>14.325</td><td>19</td><td>14.26</td><td>24</td><td>14.248</td><td>52</td><td>LJT</td></tr>\n", | |
"<tr><td>5799.16</td><td>-15.32</td><td>13.894</td><td>44</td><td>14.027</td><td>30</td><td>13.685</td><td>20</td><td>13.641</td><td>20</td><td>13.745</td><td>30</td><td>KAIT</td></tr>\n", | |
"<tr><td>5799.53</td><td>-14.95</td><td>13.572</td><td>36</td><td>13.687</td><td>19</td><td>13.41</td><td>20</td><td>13.367</td><td>25</td><td>13.333</td><td>40</td><td>LJT</td></tr>\n", | |
"<tr><td>5800.17</td><td>-14.31</td><td>13.138</td><td>84</td><td>13.225</td><td>30</td><td>12.943</td><td>20</td><td>12.921</td><td>20</td><td>12.991</td><td>30</td><td>KAIT</td></tr>\n", | |
"<tr><td>5800.53</td><td>-13.95</td><td>12.855</td><td>17</td><td>12.94</td><td>19</td><td>12.768</td><td>20</td><td>12.71</td><td>25</td><td>12.645</td><td>41</td><td>LJT</td></tr>\n", | |
"<tr><td>5801.5</td><td>-12.98</td><td>--</td><td>--</td><td>12.47</td><td>12</td><td>12.37</td><td>11</td><td>12.266</td><td>17</td><td>12.221</td><td>23</td><td>TNT</td></tr>\n", | |
"<tr><td>5801.52</td><td>-12.96</td><td>12.201</td><td>17</td><td>12.41</td><td>17</td><td>12.242</td><td>21</td><td>12.183</td><td>25</td><td>12.121</td><td>46</td><td>LJT</td></tr>\n", | |
"<tr><td>5802.15</td><td>-12.33</td><td>11.951</td><td>72</td><td>12.022</td><td>30</td><td>11.996</td><td>20</td><td>11.938</td><td>20</td><td>11.914</td><td>30</td><td>KAIT</td></tr>\n", | |
"<tr><td>5802.52</td><td>-11.96</td><td>11.621</td><td>19</td><td>11.89</td><td>17</td><td>11.837</td><td>22</td><td>11.748</td><td>24</td><td>11.678</td><td>51</td><td>LJT</td></tr>\n", | |
"<tr><td>5803.15</td><td>-11.33</td><td>11.371</td><td>46</td><td>11.624</td><td>30</td><td>11.59</td><td>20</td><td>11.464</td><td>20</td><td>11.5</td><td>30</td><td>KAIT</td></tr>\n", | |
"<tr><td>...</td><td>...</td><td>...</td><td>...</td><td>...</td><td>...</td><td>...</td><td>...</td><td>...</td><td>...</td><td>...</td><td>...</td><td>...</td></tr>\n", | |
"<tr><td>6050.62</td><td>236.14</td><td>18.052</td><td>278</td><td>16.094</td><td>33</td><td>16.102</td><td>35</td><td>16.909</td><td>66</td><td>16.363</td><td>51</td><td>TNT</td></tr>\n", | |
"<tr><td>6062.55</td><td>248.07</td><td>19.014</td><td>159</td><td>16.242</td><td>18</td><td>16.281</td><td>18</td><td>17.105</td><td>27</td><td>16.505</td><td>32</td><td>TNT</td></tr>\n", | |
"<tr><td>6069.62</td><td>255.14</td><td>--</td><td>--</td><td>16.304</td><td>38</td><td>16.374</td><td>19</td><td>16.968</td><td>77</td><td>--</td><td>--</td><td>TNT</td></tr>\n", | |
"<tr><td>6071.61</td><td>257.13</td><td>--</td><td>--</td><td>16.357</td><td>13</td><td>16.419</td><td>13</td><td>17.247</td><td>28</td><td>16.529</td><td>38</td><td>TNT</td></tr>\n", | |
"<tr><td>6077.52</td><td>263.04</td><td>--</td><td>--</td><td>16.588</td><td>114</td><td>16.443</td><td>43</td><td>17.325</td><td>65</td><td>16.855</td><td>87</td><td>TNT</td></tr>\n", | |
"<tr><td>6090.72</td><td>276.24</td><td>--</td><td>--</td><td>16.588</td><td>34</td><td>16.673</td><td>33</td><td>17.399</td><td>77</td><td>16.709</td><td>88</td><td>TNT</td></tr>\n", | |
"<tr><td>6108.53</td><td>294.05</td><td>--</td><td>--</td><td>17.318</td><td>139</td><td>17.234</td><td>82</td><td>17.85</td><td>117</td><td>16.937</td><td>61</td><td>TNT</td></tr>\n", | |
"<tr><td>6137.54</td><td>323.06</td><td>--</td><td>--</td><td>17.651</td><td>101</td><td>17.43</td><td>71</td><td>18.258</td><td>90</td><td>17.145</td><td>59</td><td>TNT</td></tr>\n", | |
"<tr><td>6160.59</td><td>346.11</td><td>--</td><td>--</td><td>17.918</td><td>140</td><td>17.814</td><td>107</td><td>18.051</td><td>155</td><td>18.096</td><td>260</td><td>TNT</td></tr>\n", | |
"<tr><td>6277.56</td><td>463.08</td><td>--</td><td>--</td><td>--</td><td>--</td><td>19.36</td><td>40</td><td>20.1</td><td>60</td><td>18.93</td><td>30</td><td>LJT</td></tr>\n", | |
"</table>" | |
], | |
"text/plain": [ | |
"<Table masked=True length=118>\n", | |
" JD Phase U Uerr B ... R Rerr I Ierr Telescope\n", | |
"float64 float64 float64 int64 float64 ... float64 int64 float64 int64 str4 \n", | |
"------- ------- ------- ----- ------- ... ------- ----- ------- ----- ---------\n", | |
"5798.53 -15.95 14.534 14 14.743 ... 14.26 24 14.248 52 LJT\n", | |
"5799.16 -15.32 13.894 44 14.027 ... 13.641 20 13.745 30 KAIT\n", | |
"5799.53 -14.95 13.572 36 13.687 ... 13.367 25 13.333 40 LJT\n", | |
"5800.17 -14.31 13.138 84 13.225 ... 12.921 20 12.991 30 KAIT\n", | |
"5800.53 -13.95 12.855 17 12.94 ... 12.71 25 12.645 41 LJT\n", | |
" 5801.5 -12.98 -- -- 12.47 ... 12.266 17 12.221 23 TNT\n", | |
"5801.52 -12.96 12.201 17 12.41 ... 12.183 25 12.121 46 LJT\n", | |
"5802.15 -12.33 11.951 72 12.022 ... 11.938 20 11.914 30 KAIT\n", | |
"5802.52 -11.96 11.621 19 11.89 ... 11.748 24 11.678 51 LJT\n", | |
"5803.15 -11.33 11.371 46 11.624 ... 11.464 20 11.5 30 KAIT\n", | |
" ... ... ... ... ... ... ... ... ... ... ...\n", | |
"6050.62 236.14 18.052 278 16.094 ... 16.909 66 16.363 51 TNT\n", | |
"6062.55 248.07 19.014 159 16.242 ... 17.105 27 16.505 32 TNT\n", | |
"6069.62 255.14 -- -- 16.304 ... 16.968 77 -- -- TNT\n", | |
"6071.61 257.13 -- -- 16.357 ... 17.247 28 16.529 38 TNT\n", | |
"6077.52 263.04 -- -- 16.588 ... 17.325 65 16.855 87 TNT\n", | |
"6090.72 276.24 -- -- 16.588 ... 17.399 77 16.709 88 TNT\n", | |
"6108.53 294.05 -- -- 17.318 ... 17.85 117 16.937 61 TNT\n", | |
"6137.54 323.06 -- -- 17.651 ... 18.258 90 17.145 59 TNT\n", | |
"6160.59 346.11 -- -- 17.918 ... 18.051 155 18.096 260 TNT\n", | |
"6277.56 463.08 -- -- -- ... 20.1 60 18.93 30 LJT" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"Table.read(\"test.txt\", format=\"ascii.csv\", names=columns)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (py36)", | |
"language": "python", | |
"name": "py36" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.0" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment