{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Puts ALL WISE Astrometry reference catalogues into GAIA reference frame\n", "\n", "\n", "\n", "The WISE catalogues were produced by ../dmu16_allwise/make_wise_samples_for_stacking.csh\n", "\n", "In the catalogue, we keep:\n", "\n", "- The position;\n", "- The chi^2\n", "\n", "This astrometric correction is adapted from master list code (dmu1_ml_XMM-LSS/1.8_SERVS.ipynb) written by Yannick Rohlly and Raphael Shirley\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "field=\"AKARI-SEP\"\n", "field=\"AKARI-NEP\"\n", "field='Herschel-Stripe-82' \n", "\n", "field='HDF-N' \n", "field='XMM-LSS' \n", "field='AKARI-NEP' \n", "field='AKARI-SEP' \n", "field='Bootes' \n", "field='CDFS-SWIRE' \n", "field='COSMOS' \n", "field='EGS' \n", "field='ELAIS-N1' \n", "field='ELAIS-N2' \n", "field='ELAIS-S1' \n", "field='GAMA-09' \n", "field='GAMA-12' \n", "field='GAMA-15' \n", "field='NGP' \n", "field='SGP' \n", "field='Lockman-SWIRE' \n", "field='SA13' \n", "field='SPIRE-NEP' \n", "field='SSDF' \n", "field='xFLS' \n", "field='XMM-13hr' \n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "This notebook was run with herschelhelp_internal version: \n", "0aab440 (Thu Mar 22 09:41:13 2018 +0000)\n" ] } ], "source": [ "from herschelhelp_internal import git_version\n", "print(\"This notebook was run with herschelhelp_internal version: \\n{}\".format(git_version()))" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/sjo/anaconda3/envs/herschelhelp_internal/lib/python3.6/site-packages/seaborn/apionly.py:6: UserWarning: As seaborn no longer sets a default style on import, the seaborn.apionly module is deprecated. It will be removed in a future version.\n", " warnings.warn(msg, UserWarning)\n" ] } ], "source": [ "%matplotlib inline\n", "#%config InlineBackend.figure_format = 'svg'\n", "\n", "import matplotlib.pyplot as plt\n", "plt.rc('figure', figsize=(10, 6))\n", "\n", "from collections import OrderedDict\n", "import os\n", "\n", "from astropy import units as u\n", "from astropy.coordinates import SkyCoord\n", "from astropy.table import Column, Table\n", "import numpy as np\n", "\n", "from herschelhelp_internal.flagging import gaia_flag_column\n", "from herschelhelp_internal.masterlist import nb_astcor_diag_plot, remove_duplicates\n", "from herschelhelp_internal.utils import astrometric_correction, flux_to_mag" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "OUT_DIR = os.environ.get('TMP_DIR', \"../dmu16_allwise/data/\")\n", "try:\n", " os.makedirs(OUT_DIR)\n", "except FileExistsError:\n", " pass\n", "\n", "RA_COL = \"servs_ra\"\n", "DEC_COL = \"servs_dec\"" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "## I - Reading in WISE astrometric catalogue" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "Table length=10\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
idxradecw4mag
degdegmag
0203.414707737.42506459.378
1203.296217637.47273029.044
2203.29690637.47776359.444
3203.314349737.46861839.464
4203.312327337.47625169.059
5203.317757737.47715959.533
6203.331808437.46618659.343
7203.334291337.47314168.726
8203.345429537.46681589.445
9203.297008337.48799489.164
\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wise = Table.read(f\"../dmu16_allwise/data/Allwise_PSF_stack_{field}.fits\")\n", "wise_coords=SkyCoord(wise['ra'], wise['dec'])\n", "\n", "epoch = 2009\n", "\n", "wise[:10].show_in_notebook()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## III - Astrometry correction\n", "\n", "We match the astrometry to the Gaia one. We limit the Gaia catalogue to sources with a g band flux between the 30th and the 70th percentile. Some quick tests show that this give the lower dispersion in the results." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "../../dmu0/dmu0_GAIA/data/GAIA_XMM-13hr.fits\n" ] }, { "ename": "FileNotFoundError", "evalue": "[Errno 2] No such file or directory: '../dmu0/dmu0_GAIA/data/GAIA_XMM-13hr.fits'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m#gaia = Table.read(\"./dmu17_XMM-LSS/data/GAIA_XMM-LSS.fits\")\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"../../dmu0/dmu0_GAIA/data/GAIA_{field}.fits\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mgaia\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mTable\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"../dmu0/dmu0_GAIA/data/GAIA_{field}.fits\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mgaia_coords\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mSkyCoord\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgaia\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'ra'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgaia\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'dec'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/anaconda3/envs/herschelhelp_internal/lib/python3.6/site-packages/astropy/table/table.py\u001b[0m in \u001b[0;36mread\u001b[0;34m(cls, *args, **kwargs)\u001b[0m\n\u001b[1;32m 2529\u001b[0m \u001b[0mpassed\u001b[0m \u001b[0mthrough\u001b[0m \u001b[0mto\u001b[0m \u001b[0mthe\u001b[0m \u001b[0munderlying\u001b[0m \u001b[0mdata\u001b[0m \u001b[0mreader\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;31m \u001b[0m\u001b[0;31m`\u001b[0m\u001b[0;34m~\u001b[0m\u001b[0mastropy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mio\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mascii\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;31m`\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2530\u001b[0m \"\"\"\n\u001b[0;32m-> 2531\u001b[0;31m \u001b[0mout\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mio_registry\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcls\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2532\u001b[0m \u001b[0;31m# For some readers (e.g., ascii.ecsv), the returned `out` class is not\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2533\u001b[0m \u001b[0;31m# guaranteed to be the same as the desired output `cls`. If so,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/anaconda3/envs/herschelhelp_internal/lib/python3.6/site-packages/astropy/io/registry.py\u001b[0m in \u001b[0;36mread\u001b[0;34m(cls, format, *args, **kwargs)\u001b[0m\n\u001b[1;32m 500\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 501\u001b[0m \u001b[0mctx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mget_readable_fileobj\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mencoding\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'binary'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 502\u001b[0;31m \u001b[0mfileobj\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mctx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__enter__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 503\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mOSError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 504\u001b[0m \u001b[0;32mraise\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/anaconda3/envs/herschelhelp_internal/lib/python3.6/contextlib.py\u001b[0m in \u001b[0;36m__enter__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 79\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__enter__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 80\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 81\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mnext\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgen\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 82\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mStopIteration\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 83\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mRuntimeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"generator didn't yield\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/anaconda3/envs/herschelhelp_internal/lib/python3.6/site-packages/astropy/utils/data.py\u001b[0m in \u001b[0;36mget_readable_fileobj\u001b[0;34m(name_or_obj, encoding, cache, show_progress, remote_timeout)\u001b[0m\n\u001b[1;32m 191\u001b[0m \u001b[0mname_or_obj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcache\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcache\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mshow_progress\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mshow_progress\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 192\u001b[0m timeout=remote_timeout)\n\u001b[0;32m--> 193\u001b[0;31m \u001b[0mfileobj\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mio\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mFileIO\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname_or_obj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'r'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 194\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mis_url\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mcache\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 195\u001b[0m \u001b[0mdelete_fds\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfileobj\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: '../dmu0/dmu0_GAIA/data/GAIA_XMM-13hr.fits'" ] } ], "source": [ "#gaia = Table.read(\"./dmu17_XMM-LSS/data/GAIA_XMM-LSS.fits\")\n", "print(f\"../../dmu0/dmu0_GAIA/data/GAIA_{field}.fits\")\n", "gaia = Table.read(f\"../dmu0/dmu0_GAIA/data/GAIA_{field}.fits\")\n", "gaia_coords = SkyCoord(gaia['ra'], gaia['dec'])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nb_astcor_diag_plot(wise_coords.ra, wise_coords.dec, \n", " gaia_coords.ra, gaia_coords.dec, near_ra0=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "delta_ra, delta_dec = astrometric_correction(\n", " wise_coords,\n", " gaia_coords, near_ra0=True\n", ")\n", "\n", "print(\"RA correction: {}\".format(delta_ra))\n", "print(\"Dec correction: {}\".format(delta_dec))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print( wise[\"ra\"])\n", "print(delta_ra.to(u.deg))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#wise[\"ra\"] += delta_ra.to(u.deg)\n", "wise[\"ra\"] = wise[\"ra\"]+ delta_ra.to(u.deg)\n", "wise[\"dec\"] = wise[\"dec\"]+ delta_dec.to(u.deg)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nb_astcor_diag_plot(wise[\"ra\"], wise[\"dec\"], \n", " gaia_coords.ra, gaia_coords.dec, near_ra0=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## V - Saving to disk" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wise.write(f\"../dmu16_allwise/data/Allwise_PSF_stack_GAIA_{field}.fits\", overwrite=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python (herschelhelp_internal)", "language": "python", "name": "helpint" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" } }, "nbformat": 4, "nbformat_minor": 1 }