From 9b6712add94be73c5dfbe5f0794bbf82d43f43be Mon Sep 17 00:00:00 2001 From: Allen Downey Date: Thu, 18 Mar 2021 08:34:37 -0400 Subject: [PATCH] Updating solutions --- soln/02_coords.ipynb | 2 +- soln/05_join.ipynb | 255 ++----------------------------------------- soln/06_photo.ipynb | 10 +- soln/07_plot.ipynb | 6 +- 4 files changed, 15 insertions(+), 258 deletions(-) diff --git a/soln/02_coords.ipynb b/soln/02_coords.ipynb index f29a08a..e6df5ef 100644 --- a/soln/02_coords.ipynb +++ b/soln/02_coords.ipynb @@ -1341,7 +1341,7 @@ } ], "source": [ - "## Solution\n", + "# Solution\n", "\n", "radius = 5 * u.arcmin\n", "print(radius)\n", diff --git a/soln/05_join.ipynb b/soln/05_join.ipynb index b9b3223..b75d4fb 100644 --- a/soln/05_join.ipynb +++ b/soln/05_join.ipynb @@ -14,13 +14,11 @@ "\n", "objectives:\n", "\n", - "- \"Upload a table to the Gaia server.\"\n", - "\n", "- \"Write ADQL queries involving `JOIN` operations.\"\n", "\n", "keypoints:\n", "\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", + "- \"Use `JOIN` operations to combine data from multiple tables in a database, 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", "\n", @@ -1097,34 +1095,7 @@ "WHERE 1=CONTAINS(\n", " POINT(gaia.ra, gaia.dec),\n", " CIRCLE(88.8, 7.4, 0.08333333))\n", - "\"\"\"\n" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "SELECT \n", - "gaia.source_id, gaia.ra, gaia.dec, gaia.pmra, gaia.pmdec, best.best_neighbour_multiplicity, best.number_of_mates, ps.g_mean_psf_mag, ps.i_mean_psf_mag\n", - "FROM gaiadr2.gaia_source as gaia\n", - "JOIN gaiadr2.panstarrs1_best_neighbour as best\n", - " ON gaia.source_id = best.source_id\n", - "JOIN gaiadr2.panstarrs1_original_valid as ps\n", - " ON best.original_ext_source_id = ps.obj_id\n", - "WHERE 1=CONTAINS(\n", - " POINT(gaia.ra, gaia.dec),\n", - " CIRCLE(88.8, 7.4, 0.08333333))\n", - "\n" - ] - } - ], - "source": [ - "# Solution\n", + "\"\"\"\n", "\n", "column_list = ['gaia.source_id',\n", " 'gaia.ra',\n", @@ -1139,101 +1110,9 @@ "columns = ', '.join(column_list)\n", "\n", "query = query_base.format(columns=columns)\n", - "print(query)" - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "INFO: Query finished. [astroquery.utils.tap.core]\n" - ] - } - ], - "source": [ - "# Solution\n", - "\n", - "job = Gaia.launch_job_async(query=query)" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "data": { - "text/html": [ - "Table length=490\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
source_idradecpmrapmdecbest_neighbour_multiplicitynumber_of_matesg_mean_psf_magi_mean_psf_mag
degdegmas / yrmas / yrmag
int64float64float64float64float64int16int16float64float64
332277396505606553688.781780201833757.3349365305831410.2980633722108194-2.50570369647369071019.943199157714817.4221992492676
332277406813427110488.82060921880337.353158142762173-1.1065462654445488-1.52608894458580441018.621200561523416.6007995605469
332277393069632051288.808433392903487.3348531622999282.6074384482375215-0.929210439544571710--20.2203998565674
332277437737442572888.868061081822657.3712877312759393.9555477866915383-3.86766248309024351018.067600250244116.9762001037598
332277372453789145688.813086028134347.3248857449205951.34995462741039-33.0781334309520861020.190700531005917.8700008392334
332277372453789132888.815703292087437.32230197723248551.93899884989518450.31105269315765761022.630800247192419.6004009246826
332277393069632179288.80507367703317.3323714722065832.2640148344763111.07727555051380081021.211999893188518.3528003692627
332277372453789094488.812416515405337.327864052479726-0.36003627434304625-6.3939392915413331020.809400558471718.1343002319336
332277393069632217688.801286825748247.334292036448643----1019.7306003570557--
...........................
332296235950148108888.850377229082717.4021627170535842.058216493648542-2.2492553225585841017.403499603271515.9040002822876
332296239386122854488.821082349761557.4044425496203-0.916760881643629-1.111331905386144110----
332295583115125491288.746203477995087.3427286191458550.1559833902071379-1.7505984559597341018.496099472045917.3892993927002
332296211898335603288.761096377229497.380564308268047----1018.064399719238316.7395000457764
332296352773258598488.788137017048237.4566968897595241.1363354614104264-2.462512969619791017.803499221801816.1214008331299
332296177538596902488.797232158623697.3597565529065352.121021366548921-6.6057117925729641018.207000732421915.9947996139526
332296208462531251288.782867563138687.384598632215225-0.093507178109964871.34959036805712261016.797899246215815.1180000305176
332296293932269260888.732893578186797.407688975612043-0.110029347835697041.0021268139914551017.1863002777116.3645992279053
332296345901311180888.803489318428457.4386999012048710.800833828337078-3.378065546636462610--16.294900894165
332296201590414387288.747408222716437.387057037713974-0.72011785332501120.55658412723415931018.470699310302716.8038005828857
" - ], - "text/plain": [ - "\n", - " source_id ra ... g_mean_psf_mag i_mean_psf_mag \n", - " deg ... mag \n", - " int64 float64 ... float64 float64 \n", - "------------------- ----------------- ... ---------------- ----------------\n", - "3322773965056065536 88.78178020183375 ... 19.9431991577148 17.4221992492676\n", - "3322774068134271104 88.8206092188033 ... 18.6212005615234 16.6007995605469\n", - "3322773930696320512 88.80843339290348 ... -- 20.2203998565674\n", - "3322774377374425728 88.86806108182265 ... 18.0676002502441 16.9762001037598\n", - "3322773724537891456 88.81308602813434 ... 20.1907005310059 17.8700008392334\n", - "3322773724537891328 88.81570329208743 ... 22.6308002471924 19.6004009246826\n", - "3322773930696321792 88.8050736770331 ... 21.2119998931885 18.3528003692627\n", - "3322773724537890944 88.81241651540533 ... 20.8094005584717 18.1343002319336\n", - "3322773930696322176 88.80128682574824 ... 19.7306003570557 --\n", - " ... ... ... ... ...\n", - "3322962359501481088 88.85037722908271 ... 17.4034996032715 15.9040002822876\n", - "3322962393861228544 88.82108234976155 ... -- --\n", - "3322955831151254912 88.74620347799508 ... 18.4960994720459 17.3892993927002\n", - "3322962118983356032 88.76109637722949 ... 18.0643997192383 16.7395000457764\n", - "3322963527732585984 88.78813701704823 ... 17.8034992218018 16.1214008331299\n", - "3322961775385969024 88.79723215862369 ... 18.2070007324219 15.9947996139526\n", - "3322962084625312512 88.78286756313868 ... 16.7978992462158 15.1180000305176\n", - "3322962939322692608 88.73289357818679 ... 17.18630027771 16.3645992279053\n", - "3322963459013111808 88.80348931842845 ... -- 16.294900894165\n", - "3322962015904143872 88.74740822271643 ... 18.4706993103027 16.8038005828857" - ] - }, - "execution_count": 28, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Solution\n", + "print(query)\n", "\n", + "job = Gaia.launch_job_async(query=query)\n", "results = job.get_results()\n", "results" ] @@ -1474,137 +1353,17 @@ " POLYGON({point_list}))\n", " AND 1 = CONTAINS(POINT(gaia.pmra, gaia.pmdec),\n", " POLYGON({pm_point_list}))\n", - "\"\"\"" - ] - }, - { - "cell_type": "code", - "execution_count": 35, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "SELECT \n", - "gaia.source_id, gaia.ra, gaia.dec, gaia.pmra, gaia.pmdec, best.best_neighbour_multiplicity, best.number_of_mates, ps.g_mean_psf_mag, ps.i_mean_psf_mag\n", - "FROM gaiadr2.gaia_source as gaia\n", - "JOIN gaiadr2.panstarrs1_best_neighbour as best\n", - " ON gaia.source_id = best.source_id\n", - "JOIN gaiadr2.panstarrs1_original_valid as ps\n", - " ON best.original_ext_source_id = ps.obj_id\n", - "WHERE parallax < 1\n", - " AND bp_rp BETWEEN -0.75 AND 2 \n", - " AND 1 = CONTAINS(POINT(gaia.ra, gaia.dec), \n", - " POLYGON(135.306, 8.39862, 126.51, 13.4449, 163.017, 54.2424, 172.933, 46.4726, 135.306, 8.39862))\n", - " AND 1 = CONTAINS(POINT(gaia.pmra, gaia.pmdec),\n", - " POLYGON( -4.05037121,-14.75623261, -3.41981085,-14.72365546, -3.03521988,-14.44357135, -2.26847919,-13.7140236 , -2.61172203,-13.24797471, -2.73471401,-13.09054471, -3.19923146,-12.5942653 , -3.34082546,-12.47611926, -5.67489413,-11.16083338, -5.95159272,-11.10547884, -6.42394023,-11.05981295, -7.09631023,-11.95187806, -7.30641519,-12.24559977, -7.04016696,-12.88580702, -6.00347705,-13.75912098, -4.42442296,-14.74641176))\n", - "\n" - ] - } - ], - "source": [ - "# Solution\n", + "\"\"\"\n", "\n", "columns = ', '.join(column_list)\n", "\n", "query7 = query7_base.format(columns=columns,\n", " point_list=point_series['point_list'],\n", " pm_point_list=point_series['pm_point_list'])\n", - "print(query7)" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "INFO: Query finished. [astroquery.utils.tap.core]\n" - ] - } - ], - "source": [ - "# Solution\n", + "print(query7)\n", "\n", - "job = Gaia.launch_job_async(query=query7)" - ] - }, - { - "cell_type": "code", - "execution_count": 37, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "Table length=3725\n", - "
\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
source_idradecpmrapmdecbest_neighbour_multiplicitynumber_of_matesg_mean_psf_magi_mean_psf_mag
degdegmas / yrmas / yrmag
int64float64float64float64float64int16int16float64float64
635860218726658176138.518706521717319.09233926905897-5.941679495793577-11.3464091298763921017.897800445556617.5174007415771
635674126383965568138.842874102638619.031798198627634-3.8970011609340207-12.7027795253896341019.287300109863317.6781005859375
635535454774983040137.837751825543618.864006786112604-4.335040664412791-14.4923086049056521016.923799514770516.478099822998
635497276810313600138.044516021375919.00947118796605-7.1729306406216615-12.2914991698159871019.924200057983418.3339996337891
635614168640132864139.5921974814583618.807955539071433-3.309602916796381-13.7089049084786311016.151599884033214.6662998199463
635598607974369792139.2092002308950818.624132868942702-6.124445176881091-12.8338240271006111016.522399902343816.1375007629395
635737661835496576139.9332755247393419.167962454651423-7.119403303682826-12.6879474976337931014.503299713134813.9849004745483
635850945892748672139.8654288847211520.011312663154804-3.786655365804428-14.284156007182061016.517499923706116.0450000762939
635600532119713664139.2286994961681618.685939084485494-3.9742788217925122-12.3424266233842451020.450599670410219.5177001953125
...........................
612241781249124608134.375583506519418.129179169751275-2.831807894848964-13.9021185736135971020.234399795532218.6518001556396
612332147361443072134.1458472136365318.45685585044513-6.234287981021865-11.5004641956950721021.384899139404320.3076000213623
612426744016802432134.6852280506107618.77090626983678-3.7691372464459554-12.8891674931188621017.828100204467817.4281005859375
612331739340341760134.1217619690225418.42768872157865-3.9894012386388735-12.605044105074411021.865699768066419.5223007202148
612282738058264960134.044576818923518.11915820167003-2.5972485319419127-13.6517409292721871022.515199661254919.9743995666504
612386332668697600135.4570104832309318.63266345155342-5.07684899854408-12.4366413047866721019.379299163818417.9923000335693
612296172717818624133.8006028696066818.08186533343457-6.112792578821885-12.507508613704021017.494400024414116.926700592041
612250375480101760134.6475471246677418.122419425065015-2.8969262278467127-14.0616763538454871015.333000183105514.6280002593994
612394926899159168135.5199706001384418.817675531233004-3.9968965218753763-13.5268210994315331016.441400527954115.8212003707886
612256418500423168134.9075297273992418.280596648172743-6.109836304219565-12.1452123311657761020.871599197387719.9612007141113
" - ], - "text/plain": [ - "\n", - " source_id ra ... g_mean_psf_mag i_mean_psf_mag \n", - " deg ... mag \n", - " int64 float64 ... float64 float64 \n", - "------------------ ------------------ ... ---------------- ----------------\n", - "635860218726658176 138.5187065217173 ... 17.8978004455566 17.5174007415771\n", - "635674126383965568 138.8428741026386 ... 19.2873001098633 17.6781005859375\n", - "635535454774983040 137.8377518255436 ... 16.9237995147705 16.478099822998\n", - "635497276810313600 138.0445160213759 ... 19.9242000579834 18.3339996337891\n", - "635614168640132864 139.59219748145836 ... 16.1515998840332 14.6662998199463\n", - "635598607974369792 139.20920023089508 ... 16.5223999023438 16.1375007629395\n", - "635737661835496576 139.93327552473934 ... 14.5032997131348 13.9849004745483\n", - "635850945892748672 139.86542888472115 ... 16.5174999237061 16.0450000762939\n", - "635600532119713664 139.22869949616816 ... 20.4505996704102 19.5177001953125\n", - " ... ... ... ... ...\n", - "612241781249124608 134.3755835065194 ... 20.2343997955322 18.6518001556396\n", - "612332147361443072 134.14584721363653 ... 21.3848991394043 20.3076000213623\n", - "612426744016802432 134.68522805061076 ... 17.8281002044678 17.4281005859375\n", - "612331739340341760 134.12176196902254 ... 21.8656997680664 19.5223007202148\n", - "612282738058264960 134.0445768189235 ... 22.5151996612549 19.9743995666504\n", - "612386332668697600 135.45701048323093 ... 19.3792991638184 17.9923000335693\n", - "612296172717818624 133.80060286960668 ... 17.4944000244141 16.926700592041\n", - "612250375480101760 134.64754712466774 ... 15.3330001831055 14.6280002593994\n", - "612394926899159168 135.51997060013844 ... 16.4414005279541 15.8212003707886\n", - "612256418500423168 134.90752972739924 ... 20.8715991973877 19.9612007141113" - ] - }, - "execution_count": 37, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Solution\n", "\n", + "job = Gaia.launch_job_async(query=query7)\n", "results = job.get_results()\n", "results" ] diff --git a/soln/06_photo.ipynb b/soln/06_photo.ipynb index 8694817..4f65435 100644 --- a/soln/06_photo.ipynb +++ b/soln/06_photo.ipynb @@ -10,23 +10,21 @@ "exercises: 0\n", "questions:\n", "\n", - "- \"How do we use Matplotlib to select a polygon and Pandas to merge data from multiple tables?\"\n", + "- \"How do we use Matplotlib to define a polygon and select points that fall inside it?\"\n", "\n", "objectives:\n", "\n", - "- \"Use Matplotlib to specify a polygon and determine which points fall inside it.\"\n", + "- \"Use isochrone data to specify a polygon and determine which points fall inside it.\"\n", "\n", - "- \"Use Pandas to merge data from multiple `DataFrames`, much like a database `JOIN` operation.\"\n", + "- \"Use Matplotlib features to customize the appearance of figures.\"\n", "\n", "keypoints:\n", "\n", "- \"Matplotlib provides operations for working with points, polygons, and other geometric entities, so it's not just for making figures.\"\n", "\n", - "- \"If you want to perform something like a database `JOIN` operation with data that is in a Pandas `DataFrame`, you can use the `join` or `merge` function. In many cases, `merge` is easier to use because the arguments are more like SQL.\"\n", - "\n", "- \"Use Matplotlib options to control the size and aspect ratio of figures to make them easier to interpret.\"\n", "\n", - "- \"Be sure to record every element of the data analysis pipeline that would be needed to replicate the results.\"\n", + "- \"Record every element of the data analysis pipeline that would be needed to replicate the results.\"\n", "\n", "---\n", "\n", diff --git a/soln/07_plot.ipynb b/soln/07_plot.ipynb index 091fcda..e31c0af 100644 --- a/soln/07_plot.ipynb +++ b/soln/07_plot.ipynb @@ -22,9 +22,9 @@ "\n", "keypoints:\n", "\n", - "- \"The most effective figures focus on telling a single story clearly and compellingly.\"\n", + "- \"The most effective figures focus on telling a single story clearly.\"\n", "\n", - "- \"Consider using annotations to guide the readers attention to the most important elements of a figure.\"\n", + "- \"Consider using annotations to guide the reader's attention to the most important elements of a figure.\"\n", "\n", "- \"The default Matplotlib style generates good quality figures, but there are several ways you can override the defaults.\"\n", "\n", @@ -1265,7 +1265,7 @@ "\n", "* The most effective figures focus on telling a single story clearly and compellingly.\n", "\n", - "* Consider using annotations to guide the readers attention to the most important elements of a figure.\n", + "* Consider using annotations to guide the reader's attention to the most important elements of a figure.\n", "\n", "* The default Matplotlib style generates good quality figures, but there are several ways you can override the defaults.\n", "\n",