{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook prepare the catalogues that will be analysed by CIGALE for SED fitting and physical parameter estimation." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import numpy as np\n", "import os\n", "os.environ['LOG_LEVEL'] = 'INFO'\n", "\n", "from astropy.table import Table\n", "\n", "from herschelhelp.filters import correct_galactic_extinction\n", "from herschelhelp.external import convert_table_for_cigale" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "SUFFIX = '20190701'\n", "master_catalogue = Table.read(\"../../dmu32/dmu32_Bootes/data/Bootes_{}_cigale.fits\".format(SUFFIX))" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [ { "data": { "text/plain": [ "3398098" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(master_catalogue)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Best sources\n", "\n", "Define a good far-IR measurement as:\n", "- an existing flux in the band;\n", "- the flag from XID+ must not be set;\n", "- the signal to noise ratio must be over 2." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "good = {}\n", "for band in ['pacs_green', 'pacs_red', 'spire_250', 'spire_350', 'spire_500']:\n", " good[band] = (~np.isnan(master_catalogue['f_{}'.format(band)]) & \n", " ~master_catalogue['flag_{}'.format(band)])\n", " good[band][good[band]] &= (master_catalogue[good[band]]['f_{}'.format(band)] /\n", " master_catalogue[good[band]]['ferr_{}'.format(band)] >= 2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will keep only sources with at leat 2 good far-IR measurements (we may actually use less sources are not all may have a redshift)." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": true }, "outputs": [], "source": [ "combined_good = np.sum(list(good.values()), axis=0) >= 2" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of good sources: 45482\n" ] } ], "source": [ "print(\"Number of good sources: {}\".format(np.sum(combined_good)))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Only sources with at least two optical and at least two near infrared detections\n", "optnir = ((master_catalogue['flag_optnir_det'] == 3) \n", " | (master_catalogue['flag_optnir_det'] == 7))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Main catalogue for CIGALE" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": true }, "outputs": [], "source": [ "best_catalogue = master_catalogue[combined_good].copy()\n", "#best_catalogue = master_catalogue.copy()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "#best_catalogue.remove_column(\"redshift\")\n", "#best_catalogue[\"zspec\"].name = \"redshift\"" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "best_catalogue = best_catalogue[~np.isnan(best_catalogue[\"redshift\"])]" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Correction for galactic extinction\n", "best_catalogue = correct_galactic_extinction(best_catalogue, inplace=True)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "scrolled": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO:herschelhelp.external:For 8801 sources, the band lbc_u should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 7371 sources, the band mosaic_b should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 5643 sources, the band 90prime_g should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 5614 sources, the band gpc1_g should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 1633 sources, the band gpc1_r should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 1333 sources, the band 90prime_r should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 1228 sources, the band mosaic_r should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 48 sources, the band gpc1_i should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 23 sources, the band mosaic_i should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n" ] } ], "source": [ "# Convertion to CIGALE format\n", "best_catalogue = convert_table_for_cigale(best_catalogue, inplace=True, remove_zerofluxes=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Band selection\n", "\n", "We want to use only one filter for similar bands. We define an order of preference and set to NaN the flux in the lower prefered bands when a prefered band is available. Some band may have a 0 flux, we set there values to NaN." ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": true }, "outputs": [], "source": [ "u_bands = []\n", "g_bands = [ \"90prime_g\", \"gpc1_g\"]\n", "r_bands = [\"mosaic_r\", \"90prime_r\", \"gpc1_r\"]\n", "i_bands = [\"mosaic_i\", \"gpc1_i\"]\n", "z_bands = [\"mosaic_z\", \"90prime_z\", \"gpc1_z\" ]\n", "y_bands = [\"gpc1_y\"]\n", "\n", "j_bands = [\"newfirm_j\", \"ukidss_j\"]\n", "h_bands = [\"newfirm_h\"]\n", "k_bands = [\"newfirm_k\", \"tifkam_ks\"]\n", "\n", "def remove_unneeded_fluxes(list_of_bands):\n", " for band_idx, band in enumerate(list_of_bands[:-1]):\n", " mask = ~np.isnan(best_catalogue[band])\n", " for lower_band in list_of_bands[band_idx+1:]:\n", " best_catalogue[lower_band][mask] = np.nan\n", " best_catalogue[\"{}_err\".format(lower_band)][mask] = np.nan" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": true }, "outputs": [], "source": [ "remove_unneeded_fluxes(g_bands)\n", "remove_unneeded_fluxes(u_bands)\n", "remove_unneeded_fluxes(r_bands)\n", "remove_unneeded_fluxes(i_bands)\n", "remove_unneeded_fluxes(z_bands)\n", "remove_unneeded_fluxes(y_bands)\n", "remove_unneeded_fluxes(j_bands)\n", "remove_unneeded_fluxes(h_bands)\n", "remove_unneeded_fluxes(k_bands)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": true }, "outputs": [], "source": [ "best_catalogue.write(\"data_tmp/Bootes_cigale_best_extcor_{}.fits\".format(SUFFIX), overwrite=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## All optnir objects with photoz" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "best_catalogue = master_catalogue[optnir].copy()\n" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "best_catalogue = best_catalogue[~np.isnan(best_catalogue[\"redshift\"])]\n" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of optnir sources with z-phot: 1552018\n" ] } ], "source": [ "print(\"Number of optnir sources with z-phot: {}\".format(len(best_catalogue)))\n" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "# Correction for galactic extinction\n", "best_catalogue = correct_galactic_extinction(best_catalogue, inplace=True)\n" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO:herschelhelp.external:For 355425 sources, the band lbc_u should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 296996 sources, the band mosaic_b should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 226968 sources, the band 90prime_g should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 225763 sources, the band gpc1_g should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 65417 sources, the band gpc1_r should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 52951 sources, the band 90prime_r should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 48832 sources, the band mosaic_r should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 2266 sources, the band gpc1_i should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 1151 sources, the band mosaic_i should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n" ] } ], "source": [ "# Convertion to CIGALE format\n", "os.environ['LOG_LEVEL'] = 'INFO'\n", "best_catalogue = convert_table_for_cigale(best_catalogue, inplace=True, remove_zerofluxes=True)" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "remove_unneeded_fluxes(g_bands)\n", "remove_unneeded_fluxes(u_bands)\n", "remove_unneeded_fluxes(r_bands)\n", "remove_unneeded_fluxes(i_bands)\n", "remove_unneeded_fluxes(z_bands)\n", "remove_unneeded_fluxes(y_bands)\n", "remove_unneeded_fluxes(j_bands)\n", "remove_unneeded_fluxes(h_bands)\n", "remove_unneeded_fluxes(k_bands)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "best_catalogue.write(\"data_tmp/Bootes_cigale_optnir_extcor_{}.fits\".format(SUFFIX), overwrite=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Catalogue using spectroscopic redshift" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": true }, "outputs": [], "source": [ "best_catalogue = master_catalogue[optnir].copy()" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": true }, "outputs": [], "source": [ "best_catalogue.remove_column(\"redshift\")\n", "best_catalogue[\"zspec\"].name = \"redshift\"" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "collapsed": true }, "outputs": [], "source": [ "best_catalogue = best_catalogue[~np.isnan(best_catalogue[\"redshift\"])]" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of sources with z-spec: 55069\n" ] } ], "source": [ "print(\"Number of sources with z-spec: {}\".format(len(best_catalogue)))" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Correction for galactic extinction\n", "best_catalogue = correct_galactic_extinction(best_catalogue, inplace=True)" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO:herschelhelp.external:For 30896 sources, the band lbc_u should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30764 sources, the band mosaic_b should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30624 sources, the band 90prime_g should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30621 sources, the band gpc1_g should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30478 sources, the band gpc1_r should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30475 sources, the band 90prime_r should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30474 sources, the band mosaic_r should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30445 sources, the band gpc1_i should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30436 sources, the band mosaic_i should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band gpc1_z should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band suprime_z should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band mosaic_z should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band gpc1_y should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band 90prime_z should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band lbc_y should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band ukidss_j should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band newfirm_j should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band newfirm_h should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band tifkam_ks should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band newfirm_k should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band irac_i1 should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band irac_i2 should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band irac_i3 should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band irac_i4 should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band mips_24 should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band pacs_green should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band pacs_red should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band spire_250 should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band spire_350 should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n", "INFO:herschelhelp.external:For 30426 sources, the band spire_500 should not be used because it overlaps or is below the Lyman limit at the redshift of these sources. These fluxes were set to NaN.\n" ] } ], "source": [ "# Convertion to CIGALE format\n", "os.environ['LOG_LEVEL'] = 'INFO'\n", "best_catalogue = convert_table_for_cigale(best_catalogue, inplace=True, remove_zerofluxes=True)" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "collapsed": true }, "outputs": [], "source": [ "remove_unneeded_fluxes(g_bands)\n", "remove_unneeded_fluxes(u_bands)\n", "remove_unneeded_fluxes(r_bands)\n", "remove_unneeded_fluxes(i_bands)\n", "remove_unneeded_fluxes(z_bands)\n", "remove_unneeded_fluxes(y_bands)\n", "remove_unneeded_fluxes(j_bands)" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "collapsed": true }, "outputs": [], "source": [ "best_catalogue.write(\"data_tmp/Bootes_cigale_optnir_extcor_zspec_{}.fits\".format(SUFFIX), overwrite=True)" ] } ], "metadata": { "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.7.2" } }, "nbformat": 4, "nbformat_minor": 2 }