Updating notebooks

This commit is contained in:
Allen Downey
2020-10-15 14:35:03 -04:00
parent 2e16d77bc2
commit caa032e8b2
10 changed files with 573 additions and 514 deletions

View File

@@ -4,11 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Astronomical Data in Python\n",
"\n",
"Copyright 2020 [Allen B. Downey](https://allendowney.com)\n",
"\n",
"[MIT License](https://opensource.org/licenses/MIT)"
"# Lesson 1"
]
},
{

View File

@@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Introduction\n",
"# Lesson 2\n",
"\n",
"This is the second in a series of lessons related to astronomy data.\n",
"\n",
@@ -19,8 +19,6 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lesson 2\n",
"\n",
"We'll start with an example that does a \"cone search\"; that is, it selects stars that appear in a circular region of the sky.\n",
"\n",
"Then, to select stars in the vicinity of GD-1, we'll:\n",
@@ -150,7 +148,7 @@
"data": {
"text/html": [
"<i>Table length=10</i>\n",
"<table id=\"table140683453947328\" class=\"table-striped table-bordered table-condensed\">\n",
"<table id=\"table140502273708144\" class=\"table-striped table-bordered table-condensed\">\n",
"<thead><tr><th>source_id</th></tr></thead>\n",
"<thead><tr><th>int64</th></tr></thead>\n",
"<tr><td>4057468321929794432</td></tr>\n",
@@ -1806,10 +1804,10 @@
" parallax float64 mas Parallax 0\n",
" parallax_error float64 mas Standard error of parallax 0\n",
"radial_velocity float64 km / s Radial velocity 139374\n",
"Jobid: 1601903357321O\n",
"Jobid: 1602708843725O\n",
"Phase: COMPLETED\n",
"Owner: None\n",
"Output file: async_20201005090917.vot\n",
"Output file: async_20201014165403.vot\n",
"Results: None\n"
]
}
@@ -1897,7 +1895,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"-rw-rw-r-- 1 downey downey 8.6M Oct 5 09:09 gd1_results.fits\r\n"
"-rw-rw-r-- 1 downey downey 8.6M Oct 14 16:54 gd1_results.fits\r\n"
]
}
],
@@ -1909,7 +1907,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The file is about 8.6 MB."
"The file is about 8.6 MB. If you are using Windows, `ls` might not work; in that case, try:\n",
"\n",
"```\n",
"!dir gd1_results.fits\n",
"```"
]
},
{

View File

@@ -65,7 +65,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
@@ -75,7 +75,7 @@
"IN_COLAB = 'google.colab' in sys.modules\n",
"\n",
"if IN_COLAB:\n",
" !pip install astroquery astro-gala pyia"
" !pip install astroquery astro-gala pyia python-wget"
]
},
{
@@ -93,16 +93,18 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from wget import download\n",
"\n",
"filename = 'gd1_results.fits'\n",
"path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'\n",
"\n",
"if not os.path.exists(filename):\n",
" !wget https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_results.fits"
" print(download(path+filename))"
]
},
{
@@ -114,7 +116,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
@@ -134,7 +136,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"metadata": {},
"outputs": [
{
@@ -153,7 +155,7 @@
"radial_velocity float64 km / s Radial velocity"
]
},
"execution_count": 6,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
@@ -175,7 +177,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 5,
"metadata": {},
"outputs": [
{
@@ -191,7 +193,7 @@
" 'radial_velocity']"
]
},
"execution_count": 7,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
@@ -209,7 +211,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 6,
"metadata": {},
"outputs": [
{
@@ -273,7 +275,7 @@
" 143.7702681295401"
]
},
"execution_count": 8,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
@@ -291,7 +293,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 7,
"metadata": {},
"outputs": [
{
@@ -300,7 +302,7 @@
"astropy.table.column.Column"
]
},
"execution_count": 9,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
@@ -318,14 +320,14 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<i>Row index=0</i>\n",
"<table id=\"table140262505510464\">\n",
"<table id=\"table140510732444000\">\n",
"<thead><tr><th>source_id</th><th>ra</th><th>dec</th><th>pmra</th><th>pmdec</th><th>parallax</th><th>parallax_error</th><th>radial_velocity</th></tr></thead>\n",
"<thead><tr><th></th><th>deg</th><th>deg</th><th>mas / yr</th><th>mas / yr</th><th>mas</th><th>mas</th><th>km / s</th></tr></thead>\n",
"<thead><tr><th>int64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th></tr></thead>\n",
@@ -341,7 +343,7 @@
"637987125186749568 142.48301935991023 21.75771616932985 -2.5168384683875766 2.941813096629439 -0.2573448962333354 0.823720794509811 1e+20"
]
},
"execution_count": 10,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
@@ -359,7 +361,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 9,
"metadata": {},
"outputs": [
{
@@ -368,7 +370,7 @@
"astropy.table.row.Row"
]
},
"execution_count": 11,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
@@ -390,7 +392,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 10,
"metadata": {},
"outputs": [
{
@@ -399,7 +401,7 @@
"142.48301935991023"
]
},
"execution_count": 12,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
@@ -417,7 +419,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 11,
"metadata": {},
"outputs": [
{
@@ -426,7 +428,7 @@
"142.48301935991023"
]
},
"execution_count": 13,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
@@ -457,7 +459,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
@@ -485,7 +487,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 13,
"metadata": {},
"outputs": [
{
@@ -547,7 +549,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 14,
"metadata": {},
"outputs": [
{
@@ -556,7 +558,7 @@
"pyia.data.GaiaData"
]
},
"execution_count": 17,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
@@ -577,7 +579,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 15,
"metadata": {},
"outputs": [
{
@@ -586,7 +588,7 @@
"astropy.coordinates.sky_coordinate.SkyCoord"
]
},
"execution_count": 18,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
@@ -629,7 +631,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 16,
"metadata": {},
"outputs": [
{
@@ -642,7 +644,7 @@
" 8.61768705e+03, 1.70849584e+03, 1.04578649e+03] pc>"
]
},
"execution_count": 19,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
@@ -657,7 +659,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
@@ -675,7 +677,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
@@ -695,7 +697,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 19,
"metadata": {},
"outputs": [
{
@@ -704,7 +706,7 @@
"astropy.coordinates.sky_coordinate.SkyCoord"
]
},
"execution_count": 22,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
@@ -726,7 +728,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 20,
"metadata": {
"scrolled": true
},
@@ -745,7 +747,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 21,
"metadata": {},
"outputs": [
{
@@ -786,7 +788,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 22,
"metadata": {},
"outputs": [
{
@@ -795,7 +797,7 @@
"astropy.table.table.Table"
]
},
"execution_count": 25,
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
@@ -806,7 +808,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 23,
"metadata": {},
"outputs": [
{
@@ -815,7 +817,7 @@
"pyia.data.GaiaData"
]
},
"execution_count": 26,
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
@@ -826,7 +828,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 24,
"metadata": {},
"outputs": [
{
@@ -835,7 +837,7 @@
"astropy.coordinates.sky_coordinate.SkyCoord"
]
},
"execution_count": 27,
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
@@ -868,7 +870,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 25,
"metadata": {},
"outputs": [
{
@@ -877,7 +879,7 @@
"(140340, 8)"
]
},
"execution_count": 28,
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
@@ -900,7 +902,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 26,
"metadata": {},
"outputs": [
{
@@ -1010,7 +1012,7 @@
"4 0.486224 1.000000e+20 "
]
},
"execution_count": 29,
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
@@ -1035,7 +1037,7 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 27,
"metadata": {},
"outputs": [
{
@@ -1044,7 +1046,7 @@
"(140340, 10)"
]
},
"execution_count": 30,
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
@@ -1064,7 +1066,7 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 28,
"metadata": {},
"outputs": [
{
@@ -1073,7 +1075,7 @@
"(140340, 12)"
]
},
"execution_count": 31,
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
@@ -1125,7 +1127,7 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 29,
"metadata": {},
"outputs": [
{
@@ -1134,7 +1136,7 @@
"pandas.core.series.Series"
]
},
"execution_count": 32,
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
@@ -1155,7 +1157,7 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 30,
"metadata": {},
"outputs": [
{
@@ -1164,7 +1166,7 @@
"pandas.core.series.Series"
]
},
"execution_count": 33,
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
@@ -1179,7 +1181,7 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 31,
"metadata": {},
"outputs": [
{
@@ -1188,7 +1190,7 @@
"dtype('bool')"
]
},
"execution_count": 34,
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
@@ -1206,7 +1208,7 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": 32,
"metadata": {},
"outputs": [
{
@@ -1220,7 +1222,7 @@
"Name: phi2, dtype: bool"
]
},
"execution_count": 35,
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
@@ -1238,7 +1240,7 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 33,
"metadata": {},
"outputs": [
{
@@ -1247,7 +1249,7 @@
"pandas.core.frame.DataFrame"
]
},
"execution_count": 36,
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
@@ -1268,21 +1270,9 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 34,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'df' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-1-54c499b1f8d4>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m phi_mask = ((df['phi2'] > phi2_min) & \n\u001b[0m\u001b[1;32m 2\u001b[0m (df['phi2'] < phi2_max))\n",
"\u001b[0;31mNameError\u001b[0m: name 'df' is not defined"
]
}
],
"outputs": [],
"source": [
"phi_mask = ((df['phi2'] > phi2_min) & \n",
" (df['phi2'] < phi2_max))"
@@ -1299,7 +1289,7 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": 35,
"metadata": {},
"outputs": [
{
@@ -1308,7 +1298,7 @@
"25084"
]
},
"execution_count": 38,
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
@@ -1326,7 +1316,7 @@
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 36,
"metadata": {},
"outputs": [
{
@@ -1335,7 +1325,7 @@
"25084"
]
},
"execution_count": 39,
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
@@ -1354,7 +1344,7 @@
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": 37,
"metadata": {},
"outputs": [
{
@@ -1413,7 +1403,7 @@
},
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
@@ -1432,7 +1422,7 @@
},
{
"cell_type": "code",
"execution_count": 42,
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
@@ -1449,7 +1439,7 @@
},
{
"cell_type": "code",
"execution_count": 43,
"execution_count": 40,
"metadata": {},
"outputs": [
{
@@ -1485,7 +1475,7 @@
},
{
"cell_type": "code",
"execution_count": 44,
"execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
@@ -1510,7 +1500,7 @@
},
{
"cell_type": "code",
"execution_count": 45,
"execution_count": 42,
"metadata": {},
"outputs": [],
"source": [
@@ -1527,7 +1517,7 @@
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": 43,
"metadata": {},
"outputs": [
{
@@ -1536,7 +1526,7 @@
"1049"
]
},
"execution_count": 46,
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
@@ -1554,7 +1544,7 @@
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": 44,
"metadata": {},
"outputs": [
{
@@ -1563,7 +1553,7 @@
"1049"
]
},
"execution_count": 47,
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
@@ -1582,7 +1572,7 @@
},
{
"cell_type": "code",
"execution_count": 48,
"execution_count": 45,
"metadata": {},
"outputs": [
{
@@ -1628,7 +1618,7 @@
},
{
"cell_type": "code",
"execution_count": 49,
"execution_count": 46,
"metadata": {},
"outputs": [
{
@@ -1637,7 +1627,7 @@
"astropy.table.table.Table"
]
},
"execution_count": 49,
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
@@ -1675,7 +1665,7 @@
},
{
"cell_type": "code",
"execution_count": 50,
"execution_count": 47,
"metadata": {},
"outputs": [],
"source": [
@@ -1691,7 +1681,7 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": 48,
"metadata": {},
"outputs": [],
"source": [
@@ -1713,7 +1703,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Exercise:** We're going to need `centerline` later as well. Write a line or two of code to add it as a second Dataset in the HDF5 file."
"**Exercise:** We're going to need `centerline` and `selected` later as well. Write a line or two of code to add it as a second Dataset in the HDF5 file."
]
},
{
@@ -1724,7 +1714,8 @@
"source": [
"# Solution\n",
"\n",
"centerline.to_hdf(filename, 'centerline')"
"centerline.to_hdf(filename, 'centerline')\n",
"selected.to_hdf(filename, 'selected')"
]
},
{
@@ -1753,14 +1744,14 @@
},
{
"cell_type": "code",
"execution_count": 53,
"execution_count": 50,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-rw-rw-r-- 1 downey downey 17M Oct 5 09:17 gd1_dataframe.hdf5\r\n"
"-rw-rw-r-- 1 downey downey 17M Oct 14 16:54 gd1_dataframe.hdf5\r\n"
]
}
],
@@ -1772,12 +1763,18 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"And we can read it back like this:"
"If you are using Windows, `ls` might not work; in that case, try:\n",
"\n",
"```\n",
"!dir gd1_dataframe.hdf5\n",
"```\n",
"\n",
"We can read the file back like this:"
]
},
{
"cell_type": "code",
"execution_count": 54,
"execution_count": 51,
"metadata": {},
"outputs": [
{
@@ -1786,7 +1783,7 @@
"(140340, 12)"
]
},
"execution_count": 54,
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}

File diff suppressed because one or more lines are too long

View File

@@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Introduction\n",
"## Lesson 5\n",
"\n",
"This is the fifth in a series of lessons related to astronomy data.\n",
"\n",
@@ -23,8 +23,6 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lesson 5\n",
"\n",
"Here are the steps in this notebook:\n",
"\n",
"1. We'll reload the candidate stars we identified in the previous notebook.\n",
@@ -67,8 +65,7 @@
"IN_COLAB = 'google.colab' in sys.modules\n",
"\n",
"if IN_COLAB:\n",
" !pip install astroquery astro-gala pyia\n",
" !mkdir data"
" !pip install astroquery astro-gala pyia python-wget"
]
},
{
@@ -89,32 +86,19 @@
"name": "stdout",
"output_type": "stream",
"text": [
"--2020-10-05 09:20:34-- https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_candidates.hdf5\n",
"Resolving github.com (github.com)... 140.82.112.4\n",
"Connecting to github.com (github.com)|140.82.112.4|:443... connected.\n",
"HTTP request sent, awaiting response... 302 Found\n",
"Location: https://raw.githubusercontent.com/AllenDowney/AstronomicalData/main/data/gd1_candidates.hdf5 [following]\n",
"--2020-10-05 09:20:35-- https://raw.githubusercontent.com/AllenDowney/AstronomicalData/main/data/gd1_candidates.hdf5\n",
"Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.116.133\n",
"Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.116.133|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 1462792 (1.4M) [application/octet-stream]\n",
"Saving to: gd1_candidates.hdf5\n",
"\n",
"gd1_candidates.hdf5 100%[===================>] 1.39M 2.37MB/s in 0.6s \n",
"\n",
"2020-10-05 09:20:36 (2.37 MB/s) - gd1_candidates.hdf5 saved [1462792/1462792]\n",
"\n"
"gd1_candidates.hdf5\n"
]
}
],
"source": [
"import os\n",
"from wget import download\n",
"\n",
"filename = 'gd1_candidates.hdf5'\n",
"path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'\n",
"\n",
"if not os.path.exists(filename):\n",
" !wget https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_candidates.hdf5"
" print(download(path+filename))"
]
},
{
@@ -376,6 +360,17 @@
"!ls -lh candidate_df.xml"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you are using Windows, `ls` might not work; in that case, try:\n",
"\n",
"```\n",
"!dir candidate_df.xml\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -1250,7 +1245,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"At around 175 KB, it is smaller than some of the other files we've been working with."
"At around 175 KB, it is smaller than some of the other files we've been working with.\n",
"\n",
"If you are using Windows, `ls` might not work; in that case, try:\n",
"\n",
"```\n",
"!dir gd1_photo.fits\n",
"```"
]
},
{

View File

@@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Introduction\n",
"## Lesson 6\n",
"\n",
"This is the sixth in a series of lessons related to astronomy data.\n",
"\n",
@@ -25,8 +25,6 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lesson 6\n",
"\n",
"Here are the steps in this notebook:\n",
"\n",
"1. We'll reload the data from the previous notebook and make a color-magnitude diagram.\n",
@@ -69,8 +67,7 @@
"IN_COLAB = 'google.colab' in sys.modules\n",
"\n",
"if IN_COLAB:\n",
" !pip install astroquery astro-gala pyia\n",
" !mkdir data"
" !pip install astroquery astro-gala pyia python-wget"
]
},
{
@@ -84,39 +81,26 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--2020-10-05 09:33:14-- https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_photo.fits\n",
"Resolving github.com (github.com)... 140.82.113.4\n",
"Connecting to github.com (github.com)|140.82.113.4|:443... connected.\n",
"HTTP request sent, awaiting response... 302 Found\n",
"Location: https://raw.githubusercontent.com/AllenDowney/AstronomicalData/main/data/gd1_photo.fits [following]\n",
"--2020-10-05 09:33:14-- https://raw.githubusercontent.com/AllenDowney/AstronomicalData/main/data/gd1_photo.fits\n",
"Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.116.133\n",
"Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.116.133|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 178560 (174K) [application/octet-stream]\n",
"Saving to: gd1_photo.fits\n",
"\n",
"gd1_photo.fits 100%[===================>] 174.38K --.-KB/s in 0.04s \n",
"\n",
"2020-10-05 09:33:15 (3.98 MB/s) - gd1_photo.fits saved [178560/178560]\n",
"\n"
"gd1_photo.fits\n"
]
}
],
"source": [
"import os\n",
"from wget import download\n",
"\n",
"filename = 'gd1_photo.fits'\n",
"path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'\n",
"\n",
"if not os.path.exists(filename):\n",
" !wget https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_photo.fits"
" print(download(path+filename))"
]
},
{
@@ -267,8 +251,6 @@
"metadata": {},
"outputs": [],
"source": [
"import matplotlib as mpl\n",
"\n",
"if IN_COLAB:\n",
" coords = [(0.2, 17.5), \n",
" (0.2, 19.5), \n",
@@ -277,10 +259,10 @@
" (0.4, 19),\n",
" (0.4, 17.5)] \n",
"else:\n",
" mpl.use('TkAgg')\n",
" plt.use('TkAgg')\n",
" plot_cmd(photo_table)\n",
" coords = plt.ginput(10)\n",
" mpl.use('agg')"
" plt.use('agg')"
]
},
{
@@ -522,21 +504,23 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from wget import download\n",
"\n",
"filename = 'gd1_candidates.hdf5'\n",
"path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'\n",
"\n",
"if not os.path.exists(filename):\n",
" !wget https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_candidates.hdf5"
" print(download(path+filename))"
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
@@ -1240,6 +1224,17 @@
"!ls -lh gd1_merged.hdf5"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you are using Windows, `ls` might not work; in that case, try:\n",
"\n",
"```\n",
"!dir gd1_merged.hdf5\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},

View File

@@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Introduction\n",
"## Lesson 7\n",
"\n",
"This is the seventh in a series of lessons related to astronomy data.\n",
"\n",
@@ -19,8 +19,6 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lesson 7\n",
"\n",
"Here are the steps in this notebook:\n",
"\n",
"1. Starting with the figure from the previous notebook, we'll add annotations to present the results more clearly.\n",
@@ -55,7 +53,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -65,8 +63,7 @@
"IN_COLAB = 'google.colab' in sys.modules\n",
"\n",
"if IN_COLAB:\n",
" !pip install astroquery astro-gala pyia\n",
" !mkdir data"
" !pip install astroquery astro-gala pyia python-wget"
]
},
{
@@ -131,56 +128,36 @@
"source": [
"## Plotting GD-1\n",
"\n",
"Let's focus on the figure in the lower left..."
"Let's start with the panel in the lower left. The following cell reloads the data."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--2020-10-05 10:24:55-- https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_merged.hdf5\n",
"Resolving github.com (github.com)... 140.82.112.4\n",
"Connecting to github.com (github.com)|140.82.112.4|:443... connected.\n",
"HTTP request sent, awaiting response... 302 Found\n",
"Location: https://raw.githubusercontent.com/AllenDowney/AstronomicalData/main/data/gd1_merged.hdf5 [following]\n",
"--2020-10-05 10:24:56-- https://raw.githubusercontent.com/AllenDowney/AstronomicalData/main/data/gd1_merged.hdf5\n",
"Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.116.133\n",
"Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.116.133|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 2006352 (1.9M) [application/octet-stream]\n",
"Saving to: gd1_merged.hdf5\n",
"\n",
"gd1_merged.hdf5 100%[===================>] 1.91M 6.14MB/s in 0.3s \n",
"\n",
"2020-10-05 10:24:56 (6.14 MB/s) - gd1_merged.hdf5 saved [2006352/2006352]\n",
"\n"
"gd1_merged.hdf5\n"
]
}
],
"source": [
"import os\n",
"from wget import download\n",
"\n",
"filename = 'gd1_merged.hdf5'\n",
"path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'\n",
"\n",
"if not os.path.exists(filename):\n",
" !wget https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_merged.hdf5"
" print(download(path+filename))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
@@ -191,7 +168,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
@@ -219,7 +196,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 9,
"metadata": {},
"outputs": [
{
@@ -267,7 +244,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
@@ -326,7 +303,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
@@ -348,7 +325,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 12,
"metadata": {},
"outputs": [
{
@@ -357,15 +334,13 @@
"10.0"
]
},
"execution_count": 10,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import matplotlib as mpl\n",
"\n",
"mpl.rcParams['font.size']"
"plt.rcParams['font.size']"
]
},
{
@@ -377,11 +352,11 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"mpl.rcParams['font.size'] = 14"
"plt.rcParams['font.size'] = 14"
]
},
{
@@ -415,7 +390,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 14,
"metadata": {},
"outputs": [
{
@@ -449,7 +424,7 @@
" 'tableau-colorblind10']"
]
},
"execution_count": 12,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
@@ -464,17 +439,19 @@
"source": [
"Note that `seaborn-paper`, `seaborn-talk` and `seaborn-poster` are particularly intended to prepare versions of a figure with text sizes and other features that work well in papers, talks, and posters.\n",
"\n",
"To use any of these style sheets, run `plt.style.use` like this:"
"To use any of these style sheets, run `plt.style.use` like this:\n",
"\n",
"```\n",
"plt.style.use('fivethirtyeight')\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.style.use('fivethirtyeight')"
]
"source": []
},
{
"cell_type": "markdown",
@@ -491,21 +468,7 @@
"source": [
"If you can't find a style sheet that's exactly what you want, you can make your own. This repository includes a style sheet called `az-paper-twocol.mplstyle`, with customizations chosen by Azalee Bostroem for publication in astronomy journals.\n",
"\n",
"You can use it like this:"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"filename = 'az-paper-twocol.mplstyle'\n",
"\n",
"if not os.path.exists(filename):\n",
" !wget https://github.com/AllenDowney/AstronomicalData/raw/main/az-paper-twocol.mplstyle"
"The following cell downloads the style sheet."
]
},
{
@@ -514,31 +477,66 @@
"metadata": {},
"outputs": [],
"source": [
"plt.style.use('./az-paper-twocol.mplstyle')"
"import os\n",
"\n",
"filename = 'az-paper-twocol.mplstyle'\n",
"path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'\n",
"\n",
"if not os.path.exists(filename):\n",
" print(download(path+filename))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The prefix `./` tells Matplotlib to look for the file in the current directory.\n",
"You can use it like this:\n",
"\n",
"As an alternative, you can install a style sheet for your own use by putting it in your configuration directory. To find out where that is, you can run the following command:"
"```\n",
"plt.style.use('./az-paper-twocol.mplstyle')\n",
"```\n",
"\n",
"The prefix `./` tells Matplotlib to look for the file in the current directory."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The prefix `./` tells Matplotlib to look for the file in the current directory.\n",
"\n",
"As an alternative, you can install a style sheet for your own use by putting it in your configuration directory. To find out where that is, you can run the following command:\n",
"\n",
"```\n",
"import matplotlib as mpl\n",
"\n",
"mpl.get_configdir()\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'/home/downey/.config/matplotlib'"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
@@ -555,16 +553,32 @@
"text.usetex : true\n",
"```\n",
"\n",
"Or in a notebook you can run the following cell."
"Or in a notebook you can run the following code.\n",
"\n",
"```\n",
"plt.rcParams['text.usetex'] = True\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "NameError",
"evalue": "name 'plt' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-3-79831e1d619c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrcParams\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'text.usetex'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'plt' is not defined"
]
}
],
"source": [
"mpl.rcParams['text.usetex'] = True"
"plt.rcParams['text.usetex'] = True"
]
},
{
@@ -623,9 +637,10 @@
"import os\n",
"\n",
"filename = 'gd1_dataframe.hdf5'\n",
"path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'\n",
"\n",
"if not os.path.exists(filename):\n",
" !wget https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_dataframe.hdf5"
" print(download(path+filename))"
]
},
{
@@ -754,7 +769,7 @@
}
],
"source": [
"mpl.rcParams['text.usetex'] = False\n",
"plt.rcParams['text.usetex'] = False\n",
"plt.style.use('default')\n",
"\n",
"plot_proper_motion(centerline)"
@@ -778,9 +793,10 @@
"import os\n",
"\n",
"filename = 'gd1_candidates.hdf5'\n",
"path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'\n",
"\n",
"if not os.path.exists(filename):\n",
" !wget https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_candidates.hdf5"
" print(download(path+filename))"
]
},
{
@@ -951,9 +967,10 @@
"import os\n",
"\n",
"filename = 'gd1_polygon.hdf5'\n",
"path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'\n",
"\n",
"if not os.path.exists(filename):\n",
" !wget https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_polygon.hdf5"
" print(download(path+filename))"
]
},
{

View File

@@ -25,13 +25,16 @@ links below, you can read the notebooks on NBViewer or run them on Colab. If yo
want to run the notebooks in your own environment, you can download them from
this repository and follow the instructions below to set up your environment.
### Prerequisites
This material is also available in the form of [Carpentries lessons](https://datacarpentry.github.io/astronomy-python), but you should be
aware that these versions might diverge in the future.
**Prerequisites**
This material should be accessible to people familiar with basic Python, but not necessarily the libraries we will use, like Astropy or Pandas. If you are familiar with Python lists and dictionaries, and you know how to write a function that takes parameters and returns a value, that should be enough.
We assume that you are familiar with astronomy at the undergraduate level, but we will not assume specialized knowledge of the datasets or analysis methods we'll use.
### Notebook 1
**Notebook 1**
This notebook demonstrates the following steps:
@@ -50,7 +53,7 @@ Press this button to run this notebook on Colab:
[or click here to read it on NBViewer](https://nbviewer.jupyter.org/github/AllenDowney/AstronomicalData/blob/main/01_query.ipynb)
### Notebook 2
**Notebook 2**
This notebook starts with an example that does a "cone search"; that is, it selects stars that appear in a circular region of the sky.
@@ -73,7 +76,7 @@ Press this button to run this notebook on Colab:
[or click here to read it on NBViewer](https://nbviewer.jupyter.org/github/AllenDowney/AstronomicalData/blob/main/02_coords.ipynb)
### Notebook 3
**Notebook 3**
Here are the steps in this notebook:
@@ -94,7 +97,7 @@ Press this button to run this notebook on Colab:
[or click here to read it on NBViewer](https://nbviewer.jupyter.org/github/AllenDowney/AstronomicalData/blob/main/03_motion.ipynb)
### Notebook 4
**Notebook 4**
Here are the steps in this notebook:
@@ -113,7 +116,7 @@ Press this button to run this notebook on Colab:
[or click here to read it on NBViewer](https://nbviewer.jupyter.org/github/AllenDowney/AstronomicalData/blob/main/04_select.ipynb)
### Notebook 5
**Notebook 5**
Here are the steps in this notebook:
@@ -130,7 +133,7 @@ Press this button to run this notebook on Colab:
[or click here to read it on NBViewer](https://nbviewer.jupyter.org/github/AllenDowney/AstronomicalData/blob/main/05_join.ipynb)
### Notebook 6
**Notebook 6**
Here are the steps in this notebook:
@@ -147,7 +150,7 @@ Press this button to run this notebook on Colab:
[or click here to read it on NBViewer](https://nbviewer.jupyter.org/github/AllenDowney/AstronomicalData/blob/main/06_photo.ipynb)
### Notebook 7
**Notebook 7**
Here are the steps in this notebook:
@@ -164,6 +167,6 @@ Press this button to run this notebook on Colab:
[or click here to read it on NBViewer](https://nbviewer.jupyter.org/github/AllenDowney/AstronomicalData/blob/main/07_plot.ipynb)
## Installation instructions
**Installation instructions**
Coming soon.

View File

@@ -16,7 +16,7 @@ dependencies:
- astropy
- astroquery
- astro-gala
- wget
- python-wget
- pip
- pip:
- pyia

View File

@@ -4,6 +4,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Astronomical Data in Python\n",
"\n",
"This notebook imports the libraries we need for the workshop.\n",
"\n",
"If any of them are missing, you'll get an error message.\n",
@@ -13,7 +15,16 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"from wget import download"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
@@ -58,7 +69,24 @@
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Created TAP+ (v1.2.1) - Connection:\n",
"\tHost: gea.esac.esa.int\n",
"\tUse HTTPS: True\n",
"\tPort: 443\n",
"\tSSL Port: 443\n",
"Created TAP+ (v1.2.1) - Connection:\n",
"\tHost: geadata.esac.esa.int\n",
"\tUse HTTPS: True\n",
"\tPort: 443\n",
"\tSSL Port: 443\n"
]
}
],
"source": [
"# Note: running this import statement opens a connection\n",
"# to a Gaia server, so it will fail if you are not connected\n",
@@ -67,6 +95,15 @@
"from astroquery.gaia import Gaia"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"During the workshop, we might put some code on Slack and ask you to cut and paste it into the notebook.\n",
"\n",
"If you are on a Mac, you might encounter a problem: "
]
},
{
"cell_type": "code",
"execution_count": null,