{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## astroquery ##\n", "#### One easy way to harness \"the internet\" with Python ...####\n", "\n", "4 real life cases:\n", "\n", "- 1) update a list of telluric stars\n", "- 2a) check the WCS solution of a MUSE cube\n", "- 2b) drizzle HST images onto a proper grid\n", "- 4) find all the \"SKY\" fields observed by MUSE" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1) Custom Simbad query ##" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " MAIN_ID RA_2_A_ICRS_J2017_5_2000 DEC_2_D_ICRS_J2017_5_2000 ... SP_TYPE OTYPE_3\n", " \"h:m:s\" \"d:m:s\" ... \n", "--------- ------------------------ ------------------------- ... ------- -------\n", "HD 167785 18 16 22.2020 +10 48 53.153 ... B2V *\n", " \n", " MAIN_ID RA_2_A_ICRS_J2017_5_2000 ... SP_TYPE OTYPE_3\n", " \"h:m:s\" ... \n", "----------------------- ------------------------ ... ------- -------\n", " HD 167785 18 16 22.2020 ... B2V *\n", " TYC 1014-45-1 18 16 31.9008 ... *\n", " TYC 1014-283-1 18 16 18.532 ... *\n", " TYC 1014-569-1 18 16 05.216 ... *\n", " TYC 1014-465-1 18 16 13.3392 ... *\n", " TYC 1014-695-1 18 16 40.2338 ... *\n", "2MASX J18162582+1054215 18 16 25.825 ... G\n", " LEDA 2808923 18 15 54.5 ... G\n", " LEDA 2808915 18 15 52.5 ... G\n", " TYC 1014-1031-1 18 15 48.172 ... *\n", " LEDA 2808926 18 15 55.6 ... G\n", " TYC 1014-675-1 18 16 58.089 ... *\n", " TYC 1014-501-1 18 16 25.9446 ... *\n", " LEDA 2809036 18 16 45.3 ... G\n", " TYC 1014-617-1 18 16 20.4787 ... *\n", " LEDA 2808905 18 15 46.6 ... G\n", "2MASX J18163281+1058195 18 16 32.820 ... G\n", " TYC 1014-687-1 18 15 54.2739 ... *\n" ] } ], "source": [ "from astroquery.simbad import Simbad\n", "Simbad.ROW_LIMIT = 15 # now any query fetches at most 15 rows\n", "\n", "from astropy.coordinates import FK5\n", "from astropy.coordinates import SkyCoord\n", "import astropy.units as u\n", "\n", "# Set up the SIMBAD call\n", "customSimbad0 = Simbad()\n", "customSimbad0.add_votable_fields('ra(2;A;ICRS;J2017.5;2000)',\n", " 'dec(2;D;ICRS;J2017.5;2000)',\n", " 'flux(V)','flux(I)','flux(J)','flux(H)','flux(K)',\n", " 'sp', 'otype(3)')\n", "customSimbad0.remove_votable_fields('coordinates')\n", "\n", "# Send the query !\n", "r0 = customSimbad0.query_object('Hip089551')\n", "r0.pprint()\n", "\n", "# Now, do a search by coordinates as well\n", "c = SkyCoord('18h16m22.2020s 10d48m53.153s',frame=FK5)\n", "print ' '\n", "r1 = customSimbad0.query_region(c, radius=10*u.arcmin)\n", "r1.pprint()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2a+b) Get all the GAIA DR1 stars around a target ##" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Launched query: 'SELECT TOP 2000 DISTANCE(POINT('ICRS',ra,dec), POINT('ICRS',16.0124878257,-72.0333324285)) AS dist, * FROM gaiadr1.gaia_source WHERE CONTAINS( POINT('ICRS',ra,dec), CIRCLE('ICRS',16.0124878257,-72.0333324285, 0.0416666666667))=1 ORDER BY dist ASC'\n", "Retrieving sync. results...\n", "Query finished.\n", " ra dec phot_g_mean_mag \n", " Angle[deg] Angle[deg] Magnitude[mag] \n", "------------------ ------------------- ------------------\n", "16.011509115204813 -72.032280132860222 17.901667686919737\n", "16.006894381348374 -72.031814726946351 20.46190717870785\n", "16.005081178931089 -72.032645287753965 16.525449483858822\n", "16.016960810442814 -72.035318888108321 19.248231538365758\n", "16.022509820289073 -72.03249448264944 18.585163348881821\n", "16.001962494319109 -72.032663083815578 20.036524778555325\n", " 16.00821002544966 -72.030167993721477 19.213980429292889\n", "16.020367279660153 -72.030830270697024 18.133825977609703\n", "16.015346804445262 -72.029753276263392 20.980371995689641\n", "16.021865481383166 -72.035771472819036 20.206737214186457\n", " ... ... ...\n", "16.038252286278436 -72.074052408426653 19.454896161524839\n", " 16.13726977056923 -72.048890415596375 16.407196142853582\n", "15.883075423492425 -72.04473638791589 18.003008642268494\n", "16.146529910727693 -72.029568765150287 20.499144703902981\n", "15.889938715602133 -72.050617908868119 11.82958904666193\n", "16.137117707298046 -72.017598974365626 18.22118250128797\n", "16.091591991533008 -71.999681970705453 19.935836394842624\n", " 15.89562982200656 -72.012608018937115 21.09638873119734\n", "16.138371968823083 -72.018339085742852 20.496362588589616\n", "16.070939215608824 -71.995787388273015 18.959243453988933\n", "Length = 1445 rows\n" ] } ], "source": [ "import astropy.units as u\n", "from astropy.coordinates.sky_coordinate import SkyCoord\n", "from astropy.units import Quantity\n", "from astroquery.gaia import Gaia\n", "\n", "target_coord = SkyCoord(ra='01h04m03.0s', dec='-72d02m00.000s', frame='icrs')\n", "search_radius = Quantity(2.5, u.arcmin)\n", "\n", "# Make it a sync search, because I don't think I need more than 2000 targets ...\n", "j = Gaia.cone_search(target_coord, search_radius)\n", "r = j.get_results()\n", "r['ra','dec','phot_g_mean_mag'].pprint()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3) Query the ESO archive ##" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of individual MUSE skies: 156\n", "Number of individual MUSE sky locations: 72\n" ] } ], "source": [ "from astroquery.eso import Eso\n", "from astropy.coordinates import SkyCoord\n", "from astropy.coordinates import Galactic, FK5\n", "import astropy.units as u\n", "import numpy as np\n", "\n", "eso = Eso()\n", "eso.ROW_LIMIT=-1 # Remove the upper limits to the query ... for some reason, this is still capped to 1e4 ...\n", "\n", "# Now query the archive ... that's magic !\n", "table_muse = eso.query_instrument('muse', column_filters={'dp_cat':'SCIENCE',\n", " #'dp_type':'SCIENCE',\n", " 'dp_type':'SKY',\n", " 'stime':'2014-01-01', \n", " 'etime':'2017-05-01',\n", " #'prog_type':'1',\n", " 'pi_coi':'ANDERSON',\n", " },\n", " #columns={\n", " #row_limit=1e6\n", " )\n", "\n", "print 'Number of individual MUSE skies: %i' % (len(table_muse))\n", "\n", "# Extract the coordinates\n", "muse_target_radec = SkyCoord(list(table_muse['Target Ra Dec']),FK5,unit=(u.hourangle,u.deg))\n", "\n", "# Cross match the sources with themselves. Look for anything close-by (10 arcsec)\n", "idxc, idxcatalog, d2d, d3d = muse_target_radec.search_around_sky(muse_target_radec,10*u.arcsec)\n", "\n", "# Then, make a list of all the groups (with each group listed only once)\n", "groups = []\n", "for (i,id) in enumerate(np.unique(idxc)):\n", " if not(idxcatalog[idxc==id].tolist() in groups):\n", " groups.append(idxcatalog[idxc==id].tolist())\n", "\n", "print 'Number of individual MUSE sky locations: %i' % (len(groups))" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "\n", "" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.11" } }, "nbformat": 4, "nbformat_minor": 0 }