This commit is contained in:
Allen Downey
2020-12-28 17:20:54 -05:00
parent f49039fb32
commit 995fe90081
10 changed files with 5574 additions and 1523 deletions

View File

@@ -14,6 +14,7 @@
"exercises: 0\n",
"questions:\n",
"- \"How can we select and download the data we want from the Gaia server?\"\n",
"\n",
"objectives:\n",
"- \"Compose a basic query in ADQL/SQL.\"\n",
"- \"Use queries to explore a database and its tables.\"\n",
@@ -38,7 +39,6 @@
"lines, but you should.\"\n",
"\n",
"---\n",
"FIXME\n",
"\n",
"{% include links.md %}\n"
]
@@ -887,6 +887,15 @@
"Read [the documentation of this table](https://gea.esac.esa.int/archive/documentation/GDR2/Gaia_archive/chap_datamodel/sec_dm_main_tables/ssec_dm_gaia_source.html) and choose a column that looks interesting to you. Add the column name to the query and run it again. What are the units of the column you selected? What is its data type?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Solution"
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -1071,6 +1080,15 @@
"* Launching test queries synchronously might make them start faster, too."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Solution"
]
},
{
"cell_type": "markdown",
"metadata": {},

View File

@@ -35,7 +35,6 @@
"- \"Once you have a query working, save the data in a local file. If you shut down the notebook and come back to it later, you can reload the file; you don't have to run the query again.\"\n",
"\n",
"---\n",
"FIXME\n",
"\n",
"{% include links.md %}\n"
]
@@ -115,7 +114,7 @@
"IN_COLAB = 'google.colab' in sys.modules\n",
"\n",
"if IN_COLAB:\n",
" !pip install astroquery astro-gala"
" !pip install astroquery gala"
]
},
{
@@ -194,7 +193,7 @@
"data": {
"text/html": [
"<i>Table length=10</i>\n",
"<table id=\"table140686245658336\" class=\"table-striped table-bordered table-condensed\">\n",
"<table id=\"table139996071891536\" 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",
@@ -243,7 +242,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise\n",
"### Exercise\n",
"\n",
"When you are debugging queries like this, you can use `TOP` to limit the size of the results, but then you still don't know how big the results will be.\n",
"\n",
@@ -252,6 +251,24 @@
"In the previous query, replace `TOP 10 source_id` with `COUNT(source_id)` and run the query again. How many stars has Gaia identified in the cone we searched?"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# Solution\n",
"\n",
"query = \"\"\"\n",
"SELECT \n",
"COUNT(source_id)\n",
"FROM gaiadr2.gaia_source\n",
"WHERE 1=CONTAINS(\n",
" POINT(ra, dec),\n",
" CIRCLE(266.41683, -29.00781, 0.08333333))\n",
"\"\"\""
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -303,7 +320,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
@@ -312,7 +329,7 @@
"<module 'astropy.units' from '/home/downey/anaconda3/envs/AstronomicalData/lib/python3.8/site-packages/astropy/units/__init__.py'>"
]
},
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
@@ -334,7 +351,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [
{
@@ -804,6 +821,7 @@
" 'Tmin',\n",
" 'Tmol',\n",
" 'Tohm',\n",
" 'Torr',\n",
" 'Tpc',\n",
" 'Tph',\n",
" 'Tphoton',\n",
@@ -1339,11 +1357,10 @@
" 'dRy',\n",
" 'dS',\n",
" 'dSt',\n",
" 'dT',\n",
" ...]"
]
},
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
@@ -1361,7 +1378,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [
{
@@ -1370,7 +1387,7 @@
"astropy.units.quantity.Quantity"
]
},
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
@@ -1391,7 +1408,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [
{
@@ -1403,7 +1420,7 @@
"<Quantity 30. deg>"
]
},
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
@@ -1425,7 +1442,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
@@ -1444,7 +1461,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
@@ -1465,7 +1482,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"outputs": [
{
@@ -1474,7 +1491,7 @@
"gala.coordinates.gd1.GD1Koposov10"
]
},
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
@@ -1495,7 +1512,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {},
"outputs": [
{
@@ -1505,7 +1522,7 @@
" [(-55., -8.), (-55., 4.), (-45., 4.), (-45., -8.)]>"
]
},
"execution_count": 11,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
@@ -1523,7 +1540,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 27,
"metadata": {},
"outputs": [
{
@@ -1532,7 +1549,7 @@
"astropy.coordinates.builtin_frames.icrs.ICRS"
]
},
"execution_count": 12,
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
@@ -1540,7 +1557,7 @@
"source": [
"import astropy.coordinates as coord\n",
"\n",
"corners_icrs = corners.transform_to(coord.ICRS)\n",
"corners_icrs = corners.transform_to(coord.ICRS())\n",
"type(corners_icrs)"
]
},
@@ -1553,7 +1570,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 28,
"metadata": {},
"outputs": [
{
@@ -1564,7 +1581,7 @@
" (141.60264825, 34.3048303 ), (152.81671045, 27.13611254)]>"
]
},
"execution_count": 13,
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
@@ -1607,7 +1624,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 29,
"metadata": {},
"outputs": [
{
@@ -1639,7 +1656,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 30,
"metadata": {},
"outputs": [
{
@@ -1667,7 +1684,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 31,
"metadata": {},
"outputs": [
{
@@ -1695,7 +1712,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 32,
"metadata": {},
"outputs": [
{
@@ -1707,7 +1724,7 @@
" '152.81671044675923, 27.136112541397996']"
]
},
"execution_count": 17,
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
@@ -1729,7 +1746,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 33,
"metadata": {},
"outputs": [
{
@@ -1738,7 +1755,7 @@
"'146.27533313607782, 19.261909820533692, 135.42163944306296, 25.87738722767213, 141.60264825107333, 34.304830296257144, 152.81671044675923, 27.136112541397996'"
]
},
"execution_count": 18,
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
@@ -1759,7 +1776,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
@@ -1775,7 +1792,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
@@ -1797,7 +1814,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 36,
"metadata": {},
"outputs": [
{
@@ -1831,7 +1848,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 37,
"metadata": {
"scrolled": true
},
@@ -1852,10 +1869,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: 1605624329053O\n",
"Jobid: 1608673335788O\n",
"Phase: COMPLETED\n",
"Owner: None\n",
"Output file: async_20201117094529.vot\n",
"Output file: async_20201222164215.vot\n",
"Results: None\n"
]
}
@@ -1874,7 +1891,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 38,
"metadata": {},
"outputs": [
{
@@ -1883,7 +1900,7 @@
"140340"
]
},
"execution_count": 23,
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
@@ -1915,7 +1932,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
@@ -1936,14 +1953,14 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-rw-rw-r-- 1 downey downey 8.6M Nov 17 09:45 gd1_results.fits\r\n"
"-rw-rw-r-- 1 downey downey 8.6M Dec 22 16:41 gd1_results.fits\r\n"
]
}
],

View File

@@ -12,11 +12,10 @@
"title: \"Plotting and Pandas\"\n",
"teaching: 3000\n",
"exercises: 0\n",
"\n",
"questions:\n",
"\n",
"- \"How do we make scatter plots in Matplotlib?\"\n",
"\n",
"- \"How do we store data in a Pandas `DataFrame`?\"\n",
"- \"How do we make scatter plots in Matplotlib? How do we store data in a Pandas `DataFrame`?\"\n",
"\n",
"objectives:\n",
"\n",
@@ -32,14 +31,13 @@
"\n",
"keypoints:\n",
"\n",
"- \"When you make a scatter plot, adjust the size of the markers and their transparency so the figure is not overplotted; otherwise it can misrepresent the data badly.\n",
"- \"When you make a scatter plot, adjust the size of the markers and their transparency so the figure is not overplotted; otherwise it can misrepresent the data badly.\"\n",
"\n",
"- \"For simple scatter plots in Matplotlib, `plot` is faster than `scatter`.\n",
"- \"For simple scatter plots in Matplotlib, `plot` is faster than `scatter`.\"\n",
"\n",
"- \"An Astropy `Table` and a Pandas `DataFrame` are similar in many ways and they provide many of the same functions. They have pros and cons, but for many projects, either one would be a reasonable choice.\"\n",
"\n",
"---\n",
"FIXME\n",
"\n",
"{% include links.md %}\n"
]
@@ -109,7 +107,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 52,
"metadata": {
"tags": [
"remove-cell"
@@ -141,7 +139,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 53,
"metadata": {},
"outputs": [],
"source": [
@@ -164,7 +162,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 54,
"metadata": {},
"outputs": [],
"source": [
@@ -184,7 +182,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 55,
"metadata": {},
"outputs": [
{
@@ -203,7 +201,7 @@
"radial_velocity float64 km / s Radial velocity"
]
},
"execution_count": 4,
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
@@ -225,7 +223,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 56,
"metadata": {},
"outputs": [
{
@@ -241,7 +239,7 @@
" 'radial_velocity']"
]
},
"execution_count": 5,
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
@@ -259,7 +257,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 57,
"metadata": {},
"outputs": [
{
@@ -323,7 +321,7 @@
" 143.7702681295401"
]
},
"execution_count": 6,
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
@@ -341,7 +339,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 58,
"metadata": {},
"outputs": [
{
@@ -350,7 +348,7 @@
"astropy.table.column.Column"
]
},
"execution_count": 7,
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
@@ -368,14 +366,14 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 59,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<i>Row index=0</i>\n",
"<table id=\"table140419756472688\">\n",
"<table id=\"table139962822334928\">\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",
@@ -391,7 +389,7 @@
"637987125186749568 142.48301935991023 21.75771616932985 -2.5168384683875766 2.941813096629439 -0.2573448962333354 0.823720794509811 1e+20"
]
},
"execution_count": 8,
"execution_count": 59,
"metadata": {},
"output_type": "execute_result"
}
@@ -409,7 +407,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 60,
"metadata": {},
"outputs": [
{
@@ -418,7 +416,7 @@
"astropy.table.row.Row"
]
},
"execution_count": 9,
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
@@ -440,7 +438,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 61,
"metadata": {},
"outputs": [
{
@@ -449,7 +447,7 @@
"142.48301935991023"
]
},
"execution_count": 10,
"execution_count": 61,
"metadata": {},
"output_type": "execute_result"
}
@@ -467,7 +465,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 62,
"metadata": {},
"outputs": [
{
@@ -476,7 +474,7 @@
"142.48301935991023"
]
},
"execution_count": 11,
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
@@ -507,7 +505,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 63,
"metadata": {},
"outputs": [],
"source": [
@@ -535,7 +533,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 64,
"metadata": {},
"outputs": [
{
@@ -577,17 +575,33 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise\n",
"### Exercise\n",
"\n",
"In the call to `plt.plot`, add the keyword argument `markersize=0.1` to make the markers smaller.\n",
"In the call to `plt.plot`, use the keyword argument `markersize` to make the markers smaller.\n",
"\n",
"Then add the argument `alpha=0.1` to make the markers nearly transparent.\n",
"Then add the keyword argument `alpha` to make the markers partly transparent.\n",
"\n",
"Adjust these arguments until you think the figure shows the data most clearly.\n",
"\n",
"Note: Once you have made these changes, you might notice that the figure shows stripes with lower density of stars. These stripes are caused by the way Gaia scans the sky, which [you can read about here](https://www.cosmos.esa.int/web/gaia/scanning-law). The dataset we are using, [Gaia Data Release 2](https://www.cosmos.esa.int/web/gaia/dr2), covers 22 months of observations; during this time, some parts of the sky were scanned more than others."
]
},
{
"cell_type": "code",
"execution_count": 68,
"metadata": {},
"outputs": [],
"source": [
"# Solution\n",
"\n",
"# x = results['ra']\n",
"# y = results['dec']\n",
"# plt.plot(x, y, 'ko', markersize=0.1, alpha=0.1)\n",
"\n",
"# plt.xlabel('ra (degree ICRS)')\n",
"# plt.ylabel('dec (degree ICRS)');"
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -597,7 +611,7 @@
"Remember that we selected data from a rectangle of coordinates in the `GD1Koposov10` frame, then transformed them to ICRS when we constructed the query.\n",
"The coordinates in `results` are in ICRS.\n",
"\n",
"To plot them, we will transform them back to the `GD1Koposov10` frame; that way, the axes of the figure are aligned with the GD-1, which will make it easy to select stars near the centerline of the stream.\n",
"To plot them, we will transform them back to the `GD1Koposov10` frame; that way, the axes of the figure are aligned with GD-1, which will make it easy to select stars near the centerline of the stream.\n",
"\n",
"To do that, we'll put the results into a `SkyCoord` object, \n",
"which is an \"interface for celestial coordinate representation, manipulation, and transformation between systems\", provided by Astropy."
@@ -605,7 +619,7 @@
},
{
"cell_type": "code",
"execution_count": 53,
"execution_count": 77,
"metadata": {},
"outputs": [],
"source": [
@@ -629,19 +643,12 @@
"\n",
"We provide `distance` and `radial_velocity` to prepare the data for reflex correction, which we explain below.\n",
"\n",
"The result is a `SkyCoord` object ([documentation here](https://docs.astropy.org/en/stable/api/astropy.coordinates.SkyCoord.html#astropy.coordinates.SkyCoord))."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The result is an Astropy `SkyCoord` object."
"The result is an Astropy `SkyCoord` object ([documentation here](https://docs.astropy.org/en/stable/api/astropy.coordinates.SkyCoord.html#astropy.coordinates.SkyCoord))."
]
},
{
"cell_type": "code",
"execution_count": 59,
"execution_count": 78,
"metadata": {},
"outputs": [
{
@@ -650,7 +657,7 @@
"astropy.coordinates.sky_coordinate.SkyCoord"
]
},
"execution_count": 59,
"execution_count": 78,
"metadata": {},
"output_type": "execute_result"
}
@@ -668,7 +675,7 @@
},
{
"cell_type": "code",
"execution_count": 60,
"execution_count": 79,
"metadata": {},
"outputs": [
{
@@ -677,7 +684,7 @@
"astropy.coordinates.sky_coordinate.SkyCoord"
]
},
"execution_count": 60,
"execution_count": 79,
"metadata": {},
"output_type": "execute_result"
}
@@ -724,7 +731,7 @@
},
{
"cell_type": "code",
"execution_count": 61,
"execution_count": 80,
"metadata": {},
"outputs": [
{
@@ -733,7 +740,7 @@
"astropy.coordinates.sky_coordinate.SkyCoord"
]
},
"execution_count": 61,
"execution_count": 80,
"metadata": {},
"output_type": "execute_result"
}
@@ -759,7 +766,7 @@
},
{
"cell_type": "code",
"execution_count": 57,
"execution_count": 81,
"metadata": {
"scrolled": true
},
@@ -778,7 +785,7 @@
},
{
"cell_type": "code",
"execution_count": 58,
"execution_count": 82,
"metadata": {},
"outputs": [
{
@@ -819,7 +826,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 83,
"metadata": {},
"outputs": [
{
@@ -828,7 +835,7 @@
"astropy.table.table.Table"
]
},
"execution_count": 21,
"execution_count": 83,
"metadata": {},
"output_type": "execute_result"
}
@@ -846,7 +853,7 @@
},
{
"cell_type": "code",
"execution_count": 63,
"execution_count": 84,
"metadata": {},
"outputs": [
{
@@ -855,7 +862,7 @@
"astropy.coordinates.sky_coordinate.SkyCoord"
]
},
"execution_count": 63,
"execution_count": 84,
"metadata": {},
"output_type": "execute_result"
}
@@ -888,7 +895,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 85,
"metadata": {},
"outputs": [
{
@@ -897,7 +904,7 @@
"(140340, 8)"
]
},
"execution_count": 24,
"execution_count": 85,
"metadata": {},
"output_type": "execute_result"
}
@@ -905,8 +912,8 @@
"source": [
"import pandas as pd\n",
"\n",
"df = results.to_pandas()\n",
"df.shape"
"results_df = results.to_pandas()\n",
"results_df.shape"
]
},
{
@@ -920,7 +927,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 86,
"metadata": {},
"outputs": [
{
@@ -1030,13 +1037,13 @@
"4 0.486224 1.000000e+20 "
]
},
"execution_count": 25,
"execution_count": 86,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
"results_df.head()"
]
},
{
@@ -1055,24 +1062,24 @@
},
{
"cell_type": "code",
"execution_count": 64,
"execution_count": 87,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(140340, 12)"
"(140340, 10)"
]
},
"execution_count": 64,
"execution_count": 87,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['phi1'] = gd1_coord.phi1\n",
"df['phi2'] = gd1_coord.phi2\n",
"df.shape"
"results_df['phi1'] = gd1_coord.phi1\n",
"results_df['phi2'] = gd1_coord.phi2\n",
"results_df.shape"
]
},
{
@@ -1084,7 +1091,7 @@
},
{
"cell_type": "code",
"execution_count": 65,
"execution_count": 88,
"metadata": {},
"outputs": [
{
@@ -1093,15 +1100,15 @@
"(140340, 12)"
]
},
"execution_count": 65,
"execution_count": 88,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['pm_phi1'] = gd1_coord.pm_phi1_cosphi2\n",
"df['pm_phi2'] = gd1_coord.pm_phi2\n",
"df.shape"
"results_df['pm_phi1'] = gd1_coord.pm_phi1_cosphi2\n",
"results_df['pm_phi2'] = gd1_coord.pm_phi2\n",
"results_df.shape"
]
},
{
@@ -1126,7 +1133,7 @@
},
{
"cell_type": "code",
"execution_count": 66,
"execution_count": 89,
"metadata": {},
"outputs": [
{
@@ -1321,13 +1328,13 @@
"max -45.000086 4.014794 39.802471 79.275199 "
]
},
"execution_count": 66,
"execution_count": 89,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.describe()"
"results_df.describe()"
]
},
{
@@ -1345,7 +1352,7 @@
},
{
"cell_type": "code",
"execution_count": 68,
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
@@ -1399,7 +1406,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 90,
"metadata": {},
"outputs": [
{
@@ -1408,13 +1415,13 @@
"pandas.core.series.Series"
]
},
"execution_count": 28,
"execution_count": 90,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"phi2 = df['phi2']\n",
"phi2 = results_df['phi2']\n",
"type(phi2)"
]
},
@@ -1429,7 +1436,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 91,
"metadata": {},
"outputs": [
{
@@ -1438,7 +1445,7 @@
"pandas.core.series.Series"
]
},
"execution_count": 29,
"execution_count": 91,
"metadata": {},
"output_type": "execute_result"
}
@@ -1447,13 +1454,13 @@
"phi2_min = -1.0 * u.deg\n",
"phi2_max = 1.0 * u.deg\n",
"\n",
"mask = (df['phi2'] > phi2_min)\n",
"mask = (results_df['phi2'] > phi2_min)\n",
"type(mask)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 92,
"metadata": {},
"outputs": [
{
@@ -1462,7 +1469,7 @@
"dtype('bool')"
]
},
"execution_count": 30,
"execution_count": 92,
"metadata": {},
"output_type": "execute_result"
}
@@ -1480,7 +1487,7 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 93,
"metadata": {},
"outputs": [
{
@@ -1494,7 +1501,7 @@
"Name: phi2, dtype: bool"
]
},
"execution_count": 31,
"execution_count": 93,
"metadata": {},
"output_type": "execute_result"
}
@@ -1512,7 +1519,7 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 94,
"metadata": {},
"outputs": [
{
@@ -1521,13 +1528,13 @@
"pandas.core.frame.DataFrame"
]
},
"execution_count": 32,
"execution_count": 94,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"subset = df[mask]\n",
"subset = results_df[mask]\n",
"type(subset)"
]
},
@@ -1535,19 +1542,19 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"`subset` is a `DataFrame` that contains only the rows from `df` that correspond to `True` values in `mask`.\n",
"`subset` is a `DataFrame` that contains only the rows from `results_df` that correspond to `True` values in `mask`.\n",
"\n",
"The previous mask selects all stars where `phi2` exceeds `phi2_min`; now we'll select stars where `phi2` falls between `phi2_min` and `phi2_max`."
]
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 95,
"metadata": {},
"outputs": [],
"source": [
"phi_mask = ((df['phi2'] > phi2_min) & \n",
" (df['phi2'] < phi2_max))"
"phi_mask = ((results_df['phi2'] > phi2_min) & \n",
" (results_df['phi2'] < phi2_max))"
]
},
{
@@ -1561,7 +1568,7 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 96,
"metadata": {},
"outputs": [
{
@@ -1570,7 +1577,7 @@
"25084"
]
},
"execution_count": 34,
"execution_count": 96,
"metadata": {},
"output_type": "execute_result"
}
@@ -1588,7 +1595,7 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": 97,
"metadata": {},
"outputs": [
{
@@ -1597,13 +1604,13 @@
"25084"
]
},
"execution_count": 35,
"execution_count": 97,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"centerline = df[phi_mask]\n",
"centerline = results_df[phi_mask]\n",
"len(centerline)"
]
},
@@ -1616,7 +1623,7 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 98,
"metadata": {},
"outputs": [
{
@@ -1653,7 +1660,7 @@
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 99,
"metadata": {},
"outputs": [
{
@@ -1712,7 +1719,7 @@
},
{
"cell_type": "code",
"execution_count": 44,
"execution_count": 100,
"metadata": {},
"outputs": [],
"source": [
@@ -1731,7 +1738,7 @@
},
{
"cell_type": "code",
"execution_count": 45,
"execution_count": 101,
"metadata": {},
"outputs": [],
"source": [
@@ -1748,7 +1755,7 @@
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": 102,
"metadata": {},
"outputs": [
{
@@ -1784,7 +1791,7 @@
},
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 103,
"metadata": {},
"outputs": [],
"source": [
@@ -1809,12 +1816,12 @@
},
{
"cell_type": "code",
"execution_count": 42,
"execution_count": 104,
"metadata": {},
"outputs": [],
"source": [
"pm_mask = (between(df['pm_phi1'], pm1_min, pm1_max) & \n",
" between(df['pm_phi2'], pm2_min, pm2_max))"
"pm_mask = (between(results_df['pm_phi1'], pm1_min, pm1_max) & \n",
" between(results_df['pm_phi2'], pm2_min, pm2_max))"
]
},
{
@@ -1826,7 +1833,7 @@
},
{
"cell_type": "code",
"execution_count": 43,
"execution_count": 105,
"metadata": {},
"outputs": [
{
@@ -1835,7 +1842,7 @@
"1049"
]
},
"execution_count": 43,
"execution_count": 105,
"metadata": {},
"output_type": "execute_result"
}
@@ -1848,12 +1855,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we can use this mask to select rows from `df`."
"Now we can use this mask to select rows from `results_df`."
]
},
{
"cell_type": "code",
"execution_count": 44,
"execution_count": 106,
"metadata": {},
"outputs": [
{
@@ -1862,13 +1869,13 @@
"1049"
]
},
"execution_count": 44,
"execution_count": 106,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"selected = df[pm_mask]\n",
"selected = results_df[pm_mask]\n",
"len(selected)"
]
},
@@ -1881,7 +1888,7 @@
},
{
"cell_type": "code",
"execution_count": 45,
"execution_count": 107,
"metadata": {},
"outputs": [
{
@@ -1927,7 +1934,7 @@
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": 108,
"metadata": {},
"outputs": [
{
@@ -1936,7 +1943,7 @@
"astropy.table.table.Table"
]
},
"execution_count": 46,
"execution_count": 108,
"metadata": {},
"output_type": "execute_result"
}
@@ -1974,13 +1981,13 @@
},
{
"cell_type": "code",
"execution_count": 48,
"execution_count": 114,
"metadata": {},
"outputs": [],
"source": [
"filename = 'gd1_dataframe.hdf5'\n",
"\n",
"df.to_hdf(filename, 'df', mode='w')"
"results_df.to_hdf(filename, 'results_df')"
]
},
{
@@ -1989,21 +1996,21 @@
"source": [
"Because an HDF5 file can contain more than one Dataset, we have to provide a name, or \"key\", that identifies the Dataset in the file.\n",
"\n",
"We could use any string as the key, but in this example I use the variable name `df`."
"We could use any string as the key, but in this example I use the variable name `results_df`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise \n",
"### Exercise \n",
"\n",
"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."
]
},
{
"cell_type": "code",
"execution_count": 49,
"execution_count": 115,
"metadata": {
"tags": [
"hide-cell"
@@ -2043,14 +2050,14 @@
},
{
"cell_type": "code",
"execution_count": 50,
"execution_count": 116,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-rw-rw-r-- 1 downey downey 17M Nov 18 19:06 gd1_dataframe.hdf5\r\n"
"-rw-rw-r-- 1 downey downey 17M Dec 28 17:17 gd1_dataframe.hdf5\r\n"
]
}
],
@@ -2073,7 +2080,7 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": 117,
"metadata": {},
"outputs": [
{
@@ -2082,13 +2089,13 @@
"(140340, 12)"
]
},
"execution_count": 51,
"execution_count": 117,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"read_back_df = pd.read_hdf(filename, 'df')\n",
"read_back_df = pd.read_hdf(filename, 'results_df')\n",
"read_back_df.shape"
]
},

View File

@@ -14,7 +14,7 @@
"exercises: 0\n",
"questions:\n",
"\n",
"- \"Question?\"\n",
"- \"How do we transform proper motion from one frame to another?\"\n",
"\n",
"objectives:\n",
"\n",
@@ -35,7 +35,6 @@
"- \"On the other hand, CSV is a 'least common denominator' format; that is, it can be read by practically any application that works with data.\"\n",
"\n",
"---\n",
"FIXME\n",
"\n",
"{% include links.md %}\n"
]
@@ -129,7 +128,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
@@ -145,13 +144,12 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 42,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"df = pd.read_hdf(filename, 'df')\n",
"centerline = pd.read_hdf(filename, 'centerline')\n",
"selected = pd.read_hdf(filename, 'selected')"
]
@@ -183,7 +181,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 43,
"metadata": {},
"outputs": [],
"source": [
@@ -195,7 +193,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 44,
"metadata": {},
"outputs": [],
"source": [
@@ -220,7 +218,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 45,
"metadata": {},
"outputs": [
{
@@ -265,7 +263,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 46,
"metadata": {},
"outputs": [
{
@@ -319,7 +317,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 47,
"metadata": {},
"outputs": [
{
@@ -328,7 +326,7 @@
"(1049, 2)"
]
},
"execution_count": 8,
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
@@ -361,16 +359,16 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 48,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<scipy.spatial.qhull.ConvexHull at 0x7f0d570cd700>"
"<scipy.spatial.qhull.ConvexHull at 0x7f3b45d974c0>"
]
},
"execution_count": 9,
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
@@ -391,7 +389,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 49,
"metadata": {},
"outputs": [
{
@@ -401,7 +399,7 @@
" 971, 967, 1001, 969, 940], dtype=int32)"
]
},
"execution_count": 10,
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
@@ -419,7 +417,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 50,
"metadata": {},
"outputs": [
{
@@ -443,7 +441,7 @@
" [ -4.42442296, -14.74641176]])"
]
},
"execution_count": 11,
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
@@ -462,7 +460,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 51,
"metadata": {},
"outputs": [],
"source": [
@@ -480,7 +478,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 52,
"metadata": {},
"outputs": [
{
@@ -533,7 +531,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 53,
"metadata": {},
"outputs": [],
"source": [
@@ -564,7 +562,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 54,
"metadata": {},
"outputs": [
{
@@ -604,7 +602,7 @@
" '-14.7464117578883']"
]
},
"execution_count": 15,
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
@@ -623,7 +621,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 55,
"metadata": {},
"outputs": [
{
@@ -632,7 +630,7 @@
"'-4.050371212154984, -14.75623260987968, -3.4198108491382455, -14.723655456335619, -3.035219883740934, -14.443571352854612, -2.268479190206636, -13.714023598831554, -2.611722027231764, -13.247974712069263, -2.7347140078529106, -13.090544709622938, -3.199231461993783, -12.594265302440828, -3.34082545787549, -12.476119260818695, -5.674894125178565, -11.160833381392624, -5.95159272432137, -11.105478836426514, -6.423940229776128, -11.05981294804957, -7.096310230579248, -11.951878058650085, -7.306415190921692, -12.245599765990594, -7.040166963232815, -12.885807024935527, -6.0034770546523735, -13.759120984106968, -4.42442296194263, -14.7464117578883'"
]
},
"execution_count": 16,
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
@@ -653,7 +651,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 56,
"metadata": {},
"outputs": [],
"source": [
@@ -665,7 +663,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 57,
"metadata": {},
"outputs": [],
"source": [
@@ -682,23 +680,15 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 58,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING: AstropyDeprecationWarning: Transforming a frame instance to a frame class (as opposed to another frame instance) will not be supported in the future. Either explicitly instantiate the target frame, or first convert the source frame instance to a `astropy.coordinates.SkyCoord` and use its `transform_to()` method. [astropy.coordinates.baseframe]\n"
]
}
],
"outputs": [],
"source": [
"import gala.coordinates as gc\n",
"import astropy.coordinates as coord\n",
"\n",
"corners = gc.GD1Koposov10(phi1=phi1_rect, phi2=phi2_rect)\n",
"corners_icrs = corners.transform_to(coord.ICRS)"
"corners_icrs = corners.transform_to(coord.ICRS())"
]
},
{
@@ -710,7 +700,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 59,
"metadata": {},
"outputs": [
{
@@ -719,7 +709,7 @@
"'135.30559858565638, 8.398623940157561, 126.50951508623503, 13.44494195652069, 163.0173655836748, 54.24242734020255, 172.9328536286811, 46.47260492416258'"
]
},
"execution_count": 20,
"execution_count": 59,
"metadata": {},
"output_type": "execute_result"
}
@@ -744,7 +734,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 60,
"metadata": {},
"outputs": [],
"source": [
@@ -769,7 +759,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 61,
"metadata": {
"tags": [
"hide-cell"
@@ -800,7 +790,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 62,
"metadata": {},
"outputs": [],
"source": [
@@ -818,7 +808,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 63,
"metadata": {
"tags": [
"hide-cell"
@@ -860,7 +850,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 64,
"metadata": {
"scrolled": true
},
@@ -869,16 +859,6 @@
"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",
"INFO: Query finished. [astroquery.utils.tap.core]\n",
"<Table length=7346>\n",
" name dtype unit description n_bad\n",
@@ -890,10 +870,10 @@
" pmdec float64 mas / yr Proper motion in declination direction 0\n",
" parallax float64 mas Parallax 0\n",
"radial_velocity float64 km / s Radial velocity 7295\n",
"Jobid: 1607614394159O\n",
"Jobid: 1609193890845O\n",
"Phase: COMPLETED\n",
"Owner: None\n",
"Output file: async_20201210103314.vot\n",
"Output file: async_20201228171811.vot\n",
"Results: None\n"
]
}
@@ -914,7 +894,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 65,
"metadata": {},
"outputs": [
{
@@ -923,7 +903,7 @@
"7346"
]
},
"execution_count": 26,
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
@@ -944,7 +924,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 66,
"metadata": {},
"outputs": [
{
@@ -980,7 +960,7 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 67,
"metadata": {},
"outputs": [],
"source": [
@@ -1019,7 +999,7 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 68,
"metadata": {},
"outputs": [],
"source": [
@@ -1035,7 +1015,7 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 69,
"metadata": {},
"outputs": [
{
@@ -1091,7 +1071,7 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 70,
"metadata": {},
"outputs": [],
"source": [
@@ -1109,14 +1089,14 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 71,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-rw-rw-r-- 1 downey downey 698K Dec 10 19:18 gd1_candidates.hdf5\r\n"
"-rw-rw-r-- 1 downey downey 698K Dec 28 17:18 gd1_candidates.hdf5\r\n"
]
}
],
@@ -1156,7 +1136,7 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": 72,
"metadata": {},
"outputs": [],
"source": [
@@ -1172,14 +1152,14 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 73,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-rw-rw-r-- 1 downey downey 1.4M Dec 10 19:19 gd1_candidates.csv\r\n"
"-rw-rw-r-- 1 downey downey 1.4M Dec 28 17:18 gd1_candidates.csv\r\n"
]
}
],
@@ -1198,7 +1178,7 @@
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 74,
"metadata": {},
"outputs": [
{
@@ -1226,7 +1206,7 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": 75,
"metadata": {},
"outputs": [],
"source": [
@@ -1242,7 +1222,7 @@
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 76,
"metadata": {},
"outputs": [
{
@@ -1338,7 +1318,7 @@
"2 NaN -59.133391 -2.306901 -7.560608 -0.741800 "
]
},
"execution_count": 39,
"execution_count": 76,
"metadata": {},
"output_type": "execute_result"
}
@@ -1349,7 +1329,7 @@
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": 77,
"metadata": {},
"outputs": [
{
@@ -1449,7 +1429,7 @@
"2 0.779463 NaN -59.133391 -2.306901 -7.560608 -0.741800 "
]
},
"execution_count": 40,
"execution_count": 77,
"metadata": {},
"output_type": "execute_result"
}

View File

@@ -22,10 +22,9 @@
"\n",
"- \"Use `JOIN` operations to combine data from multiple tables in a databased, using some kind of identifier to match up records from one table with records from another.\"\n",
"\n",
"* \"This is another example of a practice we saw in the previous notebook, moving the computation to the data.\"\n",
"- \"This is another example of a practice we saw in the previous notebook, moving the computation to the data.\"\n",
"\n",
"---\n",
"FIXME\n",
"\n",
"{% include links.md %}\n"
]
@@ -40,7 +39,8 @@
"\n",
"As a continuing example, we will replicate part of the analysis in a recent paper, \"[Off the beaten path: Gaia reveals GD-1 stars outside of the main stream](https://arxiv.org/abs/1805.00425)\" by Adrian M. Price-Whelan and Ana Bonaca.\n",
"\n",
"Picking up where we left off, the next step in the analysis is to select candidate stars based on photometry data. The following figure from the paper is a color-magnitude diagram for the stars selected based on proper motion:\n",
"Picking up where we left off, the next step in the analysis is to select candidate stars based on photometry data.\n",
"The following figure from the paper is a color-magnitude diagram for the stars selected based on proper motion:\n",
"\n",
"<img width=\"300\" src=\"https://github.com/datacarpentry/astronomy-python/raw/gh-pages/fig/gd1-3.png\">\n",
"\n",
@@ -380,7 +380,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"-rw-rw-r-- 1 downey downey 396K Dec 10 11:33 candidate_df.xml\r\n"
"-rw-rw-r-- 1 downey downey 396K Dec 28 17:06 candidate_df.xml\r\n"
]
}
],
@@ -407,60 +407,39 @@
"\n",
"There's a gotcha here we want to warn you about. Why do you think we used double brackets to specify the column we wanted? What happens if you use single brackets?\n",
"\n",
"Run these cells to find out."
"Run these code snippets to find out.\n",
"\n",
"```\n",
"table_id = candidate_table[['source_id']]\n",
"print(type(table_id))\n",
"```\n",
"\n",
"```\n",
"column = candidate_table['source_id']\n",
"print(type(column))\n",
"```\n",
"\n",
"```\n",
"# This one should cause an error\n",
"table_id.write('candidate_df.xml', \n",
" format='votable', \n",
" overwrite=True)\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"astropy.table.table.Table"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"table_id = candidate_table[['source_id']]\n",
"type(table_id)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"astropy.table.column.Column"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"column = candidate_table['source_id']\n",
"type(column)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"# This line is commented out because it would cause an error\n",
"# Solution\n",
"\n",
"# writeto(column, 'candidate_df.xml')"
"# table_id is a Table\n",
"\n",
"# column is a Column\n",
"\n",
"# Column does not provide `write`, so you get an AttributeError"
]
},
{
@@ -478,7 +457,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
@@ -500,7 +479,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 11,
"metadata": {},
"outputs": [
{
@@ -542,7 +521,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 12,
"metadata": {
"scrolled": true
},
@@ -551,7 +530,7 @@
"data": {
"text/html": [
"<i>Table length=7346</i>\n",
"<table id=\"table140668290919488\" class=\"table-striped table-bordered table-condensed\">\n",
"<table id=\"table139700968537728\" 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>635559124339440000</td></tr>\n",
@@ -605,7 +584,7 @@
"612429144902815104"
]
},
"execution_count": 14,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
@@ -624,7 +603,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 13,
"metadata": {},
"outputs": [
{
@@ -633,33 +612,53 @@
"(7346, 7346)"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(table_id), len(results)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['source_id']"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"table_id.colnames"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['source_id']"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(candidate_table), len(results)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"set(candidate_table['source_id']) == set(results['source_id'])"
"results.colnames"
]
},
{
@@ -682,7 +681,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
@@ -714,7 +713,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 17,
"metadata": {},
"outputs": [
{
@@ -740,14 +739,14 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<i>Table length=3724</i>\n",
"<table id=\"table140668268803072\" class=\"table-striped table-bordered table-condensed\">\n",
"<table id=\"table139700968371152\" class=\"table-striped table-bordered table-condensed\">\n",
"<thead><tr><th>source_id</th><th>original_ext_source_id</th><th>angular_distance</th><th>number_of_neighbours</th><th>number_of_mates</th><th>best_neighbour_multiplicity</th><th>gaia_astrometric_params</th><th>source_id_2</th></tr></thead>\n",
"<thead><tr><th></th><th></th><th>arcsec</th><th></th><th></th><th></th><th></th><th></th></tr></thead>\n",
"<thead><tr><th>int64</th><th>int64</th><th>float64</th><th>int32</th><th>int16</th><th>int16</th><th>int16</th><th>int64</th></tr></thead>\n",
@@ -801,7 +800,7 @@
"612256418500423168 129931349075297310 ... 612256418500423168"
]
},
"execution_count": 19,
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
@@ -820,7 +819,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 19,
"metadata": {
"scrolled": true
},
@@ -838,7 +837,7 @@
" 'source_id_2']"
]
},
"execution_count": 20,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
@@ -858,7 +857,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 20,
"metadata": {},
"outputs": [
{
@@ -867,7 +866,7 @@
"3724"
]
},
"execution_count": 21,
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
@@ -885,7 +884,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 21,
"metadata": {},
"outputs": [
{
@@ -949,7 +948,7 @@
" 1"
]
},
"execution_count": 22,
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
@@ -969,7 +968,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 22,
"metadata": {},
"outputs": [
{
@@ -986,7 +985,7 @@
"dtype: float64"
]
},
"execution_count": 23,
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
@@ -1009,7 +1008,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 23,
"metadata": {},
"outputs": [
{
@@ -1026,7 +1025,7 @@
"dtype: float64"
]
},
"execution_count": 24,
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
@@ -1077,7 +1076,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 24,
"metadata": {
"tags": [
"hide-cell"
@@ -1100,7 +1099,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 25,
"metadata": {},
"outputs": [
{
@@ -1156,7 +1155,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 26,
"metadata": {
"tags": [
"hide-cell"
@@ -1174,7 +1173,7 @@
"\n",
"# Second test\n",
"\n",
"query2 = \"\"\"SELECT TOP 10 *\n",
"query2 = \"\"\"SELECT TOP 10\n",
"FROM gaiadr2.panstarrs1_original_valid\n",
"\"\"\"\n",
"\n",
@@ -1205,7 +1204,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 27,
"metadata": {},
"outputs": [
{
@@ -1224,14 +1223,14 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<i>Table length=3724</i>\n",
"<table id=\"table140668299958448\" class=\"table-striped table-bordered table-condensed\">\n",
"<table id=\"table139700958811232\" class=\"table-striped table-bordered table-condensed\">\n",
"<thead><tr><th>source_id</th><th>g_mean_psf_mag</th><th>i_mean_psf_mag</th></tr></thead>\n",
"<thead><tr><th></th><th></th><th>mag</th></tr></thead>\n",
"<thead><tr><th>int64</th><th>float64</th><th>float64</th></tr></thead>\n",
@@ -1285,7 +1284,7 @@
"612256418500423168 20.8715991973877 19.9612007141113"
]
},
"execution_count": 29,
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
@@ -1308,77 +1307,16 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"INFO: Query finished. [astroquery.utils.tap.core]\n"
"ename": "IndentationError",
"evalue": "unexpected indent (<ipython-input-29-a17188e54878>, line 13)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-29-a17188e54878>\"\u001b[0;36m, line \u001b[0;32m13\u001b[0m\n\u001b[0;31m upload_resource='candidate_df.xml',\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m unexpected indent\n"
]
},
{
"data": {
"text/html": [
"<i>Table length=3724</i>\n",
"<table id=\"table140668275467456\" class=\"table-striped table-bordered table-condensed\">\n",
"<thead><tr><th>source_id</th><th>g_mean_psf_mag</th><th>i_mean_psf_mag</th></tr></thead>\n",
"<thead><tr><th></th><th></th><th>mag</th></tr></thead>\n",
"<thead><tr><th>int64</th><th>float64</th><th>float64</th></tr></thead>\n",
"<tr><td>635860218726658176</td><td>17.8978004455566</td><td>17.5174007415771</td></tr>\n",
"<tr><td>635674126383965568</td><td>19.2873001098633</td><td>17.6781005859375</td></tr>\n",
"<tr><td>635535454774983040</td><td>16.9237995147705</td><td>16.478099822998</td></tr>\n",
"<tr><td>635497276810313600</td><td>19.9242000579834</td><td>18.3339996337891</td></tr>\n",
"<tr><td>635614168640132864</td><td>16.1515998840332</td><td>14.6662998199463</td></tr>\n",
"<tr><td>635598607974369792</td><td>16.5223999023438</td><td>16.1375007629395</td></tr>\n",
"<tr><td>635737661835496576</td><td>14.5032997131348</td><td>13.9849004745483</td></tr>\n",
"<tr><td>635850945892748672</td><td>16.5174999237061</td><td>16.0450000762939</td></tr>\n",
"<tr><td>635600532119713664</td><td>20.4505996704102</td><td>19.5177001953125</td></tr>\n",
"<tr><td>...</td><td>...</td><td>...</td></tr>\n",
"<tr><td>612241781249124608</td><td>20.2343997955322</td><td>18.6518001556396</td></tr>\n",
"<tr><td>612332147361443072</td><td>21.3848991394043</td><td>20.3076000213623</td></tr>\n",
"<tr><td>612426744016802432</td><td>17.8281002044678</td><td>17.4281005859375</td></tr>\n",
"<tr><td>612331739340341760</td><td>21.8656997680664</td><td>19.5223007202148</td></tr>\n",
"<tr><td>612282738058264960</td><td>22.5151996612549</td><td>19.9743995666504</td></tr>\n",
"<tr><td>612386332668697600</td><td>19.3792991638184</td><td>17.9923000335693</td></tr>\n",
"<tr><td>612296172717818624</td><td>17.4944000244141</td><td>16.926700592041</td></tr>\n",
"<tr><td>612250375480101760</td><td>15.3330001831055</td><td>14.6280002593994</td></tr>\n",
"<tr><td>612394926899159168</td><td>16.4414005279541</td><td>15.8212003707886</td></tr>\n",
"<tr><td>612256418500423168</td><td>20.8715991973877</td><td>19.9612007141113</td></tr>\n",
"</table>"
],
"text/plain": [
"<Table length=3724>\n",
" source_id g_mean_psf_mag i_mean_psf_mag \n",
" mag \n",
" int64 float64 float64 \n",
"------------------ ---------------- ----------------\n",
"635860218726658176 17.8978004455566 17.5174007415771\n",
"635674126383965568 19.2873001098633 17.6781005859375\n",
"635535454774983040 16.9237995147705 16.478099822998\n",
"635497276810313600 19.9242000579834 18.3339996337891\n",
"635614168640132864 16.1515998840332 14.6662998199463\n",
"635598607974369792 16.5223999023438 16.1375007629395\n",
"635737661835496576 14.5032997131348 13.9849004745483\n",
"635850945892748672 16.5174999237061 16.0450000762939\n",
"635600532119713664 20.4505996704102 19.5177001953125\n",
" ... ... ...\n",
"612241781249124608 20.2343997955322 18.6518001556396\n",
"612332147361443072 21.3848991394043 20.3076000213623\n",
"612426744016802432 17.8281002044678 17.4281005859375\n",
"612331739340341760 21.8656997680664 19.5223007202148\n",
"612282738058264960 22.5151996612549 19.9743995666504\n",
"612386332668697600 19.3792991638184 17.9923000335693\n",
"612296172717818624 17.4944000244141 16.926700592041\n",
"612250375480101760 15.3330001831055 14.6280002593994\n",
"612394926899159168 16.4414005279541 15.8212003707886\n",
"612256418500423168 20.8715991973877 19.9612007141113"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
@@ -1393,12 +1331,12 @@
" ON ps.obj_id = best.original_ext_source_id\n",
"\"\"\"\n",
"\n",
"job3 = Gaia.launch_job_async(query=query3, \n",
"# job3 = Gaia.launch_job_async(query=query3, \n",
" upload_resource='candidate_df.xml', \n",
" upload_table_name='candidate_df')\n",
"\n",
"results3 = job3.get_results()\n",
"results3"
"# results3 = job3.get_results()\n",
"# results3"
]
},
{
@@ -1412,7 +1350,7 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -1429,17 +1367,9 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-rw-rw-r-- 1 downey downey 96K Dec 10 11:34 gd1_photo.fits\r\n"
]
}
],
"outputs": [],
"source": [
"!ls -lh gd1_photo.fits"
]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1005
pilot_day1.ipynb Normal file

File diff suppressed because it is too large Load Diff

1423
pilot_day3.ipynb Normal file

File diff suppressed because one or more lines are too long

1855
pilot_day4.ipynb Normal file

File diff suppressed because one or more lines are too long