{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/mc741/anaconda3/lib/python3.6/site-packages/mpl_toolkits/axes_grid/__init__.py:12: MatplotlibDeprecationWarning: \n", "The mpl_toolkits.axes_grid module was deprecated in Matplotlib 2.1 and will be removed two minor releases later. Use mpl_toolkits.axes_grid1 and mpl_toolkits.axisartist, which provide the same functionality instead.\n", " obj_type='module')\n" ] } ], "source": [ "import pylab as plt\n", "import pymoc\n", "import xidplus\n", "import numpy as np\n", "%matplotlib inline\n", "from astropy.table import Table, join" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import seaborn as sns" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook uses all the raw data from the CIGALE predictions and photoz catalogue, maps, PSF and relevant MOCs to create XID+ prior object and relevant tiling scheme" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read in MOCs\n", "The selection functions required are the main MOC associated with the masterlist. " ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "Sel_func=pymoc.MOC()\n", "Sel_func.read('../../dmu4/dmu4_sm_NGP/data/holes_NGP_ukidss_k_O16_20190204_MOC.fits')\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read in CIGALE predictions catalogue" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "cigale=Table.read('../../dmu28/dmu28_NGP/data/NGP_results_Ldust_prediction.fits')\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": true }, "outputs": [], "source": [ "cigale['id'].name = 'help_id'\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "Table length=1473955\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", "
help_idbayes.dust.luminositybayes.dust.luminosity_errbest.chi_squarebest.reduced_chi_square
bytes27float64float64float64float64
HELP_J124043.436+340454.9642.6255726460825376e+382.3341106226548585e+3813.67581467505491.9536878107221285
HELP_J124044.261+340515.9324.454774001790711e+361.1836721760690504e+3640.13125543772525.01640692971565
HELP_J124044.423+340508.3037.425850359374088e+388.50041825482934e+381.9974006891088060.3329001148514677
HELP_J124047.274+340554.9831.4016155289703243e+381.4433711696275098e+3836.5133196100448255.216188515720689
HELP_J124047.353+340507.9943.6873140591071903e+372.5681660957952962e+3736.020517773493514.502564721686689
HELP_J124048.661+340635.1892.3995085208439427e+351.1545619603215568e+3584.9562336601135510.619529207514194
HELP_J124049.481+340533.4861.03643281738859e+373.722264512058079e+36268.418590080897333.55232376011216
HELP_J124049.705+340627.8438.703772920561137e+367.527415818915938e+36179.8491455420211525.692735077431593
HELP_J124050.462+340830.8585.183459585477802e+385.7490736768374256e+387.2753702500218411.0393386071459774
HELP_J124050.879+340445.8115.653579254171697e+393.2226817865027835e+39178.6983888721333622.33729860901667
...............
HELP_J135159.418+234354.8907.461172966310608e+378.326149414968744e+379.7522977638745481.2190372204843185
HELP_J135159.427+233452.2352.176014166381297e+382.9921560143277654e+382.94507825724089130.4908463762068152
HELP_J135159.455+233704.4177.191836237872661e+389.253222575607047e+3814.8271870985595021.8533983873199378
HELP_J135159.631+233659.0371.5629847355631444e+381.944873488930478e+3813.9520498641967841.9931499805995405
HELP_J135159.634+234408.0552.1001621135172227e+372.197789962569013e+3714.773166237255981.8466457796569975
HELP_J135159.652+233129.7876.216848794517417e+376.093618868577244e+373.77803519551282240.4722543994391028
HELP_J135159.729+233139.0227.190633460347819e+377.105843237132505e+376.2129534331437570.7766191791429696
HELP_J135159.854+233206.6723.053461116040867e+383.462232577245399e+383.55945726908518270.44493215863564783
HELP_J135159.896+233644.7345.153674999945474e+375.243524093406064e+3712.6830451623671281.585380645295891
HELP_J135159.920+233945.3491.4586030615052245e+381.5263739794240154e+3812.8857549553209731.6107193694151216
" ], "text/plain": [ "\n", " help_id bayes.dust.luminosity ... best.reduced_chi_square\n", " bytes27 float64 ... float64 \n", "--------------------------- ---------------------- ... -----------------------\n", "HELP_J124043.436+340454.964 2.6255726460825376e+38 ... 1.9536878107221285\n", "HELP_J124044.261+340515.932 4.454774001790711e+36 ... 5.01640692971565\n", "HELP_J124044.423+340508.303 7.425850359374088e+38 ... 0.3329001148514677\n", "HELP_J124047.274+340554.983 1.4016155289703243e+38 ... 5.216188515720689\n", "HELP_J124047.353+340507.994 3.6873140591071903e+37 ... 4.502564721686689\n", "HELP_J124048.661+340635.189 2.3995085208439427e+35 ... 10.619529207514194\n", "HELP_J124049.481+340533.486 1.03643281738859e+37 ... 33.55232376011216\n", "HELP_J124049.705+340627.843 8.703772920561137e+36 ... 25.692735077431593\n", "HELP_J124050.462+340830.858 5.183459585477802e+38 ... 1.0393386071459774\n", "HELP_J124050.879+340445.811 5.653579254171697e+39 ... 22.33729860901667\n", " ... ... ... ...\n", "HELP_J135159.418+234354.890 7.461172966310608e+37 ... 1.2190372204843185\n", "HELP_J135159.427+233452.235 2.176014166381297e+38 ... 0.4908463762068152\n", "HELP_J135159.455+233704.417 7.191836237872661e+38 ... 1.8533983873199378\n", "HELP_J135159.631+233659.037 1.5629847355631444e+38 ... 1.9931499805995405\n", "HELP_J135159.634+234408.055 2.1001621135172227e+37 ... 1.8466457796569975\n", "HELP_J135159.652+233129.787 6.216848794517417e+37 ... 0.4722543994391028\n", "HELP_J135159.729+233139.022 7.190633460347819e+37 ... 0.7766191791429696\n", "HELP_J135159.854+233206.672 3.053461116040867e+38 ... 0.44493215863564783\n", "HELP_J135159.896+233644.734 5.153674999945474e+37 ... 1.585380645295891\n", "HELP_J135159.920+233945.349 1.4586030615052245e+38 ... 1.6107193694151216" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cigale" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read in photoz" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": true }, "outputs": [], "source": [ "photoz=Table.read('../../dmu24/dmu24_NGP/data/master_catalogue_ngp_20180501_photoz_20180601_r_optimised.fits')" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "Table length=3175339\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", "
help_idRADECidz1_medianz1_minz1_maxz1_areaz2_medianz2_minz2_maxz2_areaza_hbchi_r_eazychi_r_atlaschi_r_cosmoschi_r_stellarstellar_type
bytes27float64float64int64float64float64float64float64float64float64float64float64float64float64float64float64float64bytes6
HELP_J131410.500+302813.489198.5437504294315830.4704137267414720209940.16310.10170.23450.784-99.0-99.0-99.0-99.00.152332814912781220.1620430.48895650.744026250.10714735rg5iii
HELP_J133855.810+281107.598204.7325407809565528.1854437978217920209950.71770.26451.17460.798-99.0-99.0-99.0-99.00.72664830720933660.0966900750.408358750.0581108251.23097825m0iii
HELP_J130324.552+285933.902195.8523014973378328.9927504478853520209960.53960.16970.90040.796-99.0-99.0-99.0-99.00.57825035825782630.0124029350.04160540.619709250.6092085g5ii
HELP_J125051.674+284236.699192.7153087442242728.71019402793802320209970.67210.34661.03590.7861.06251.05431.07280.0050.61652848123102550.252063750.27411050.29775451.9183805m3v
HELP_J133040.559+290320.044202.6689941141103229.05556776089803620209980.6220.27210.99960.7530.2170.18030.25320.0440.6068727826799020.01167191750.036912250.17255480.57439175rf8v
HELP_J125342.104+271050.555193.4254347706226727.1807096059099120209990.67380.24571.11670.795-99.0-99.0-99.0-99.00.83875336546474970.0414525750.09497650.0713986253.30642m2p5v
HELP_J130655.638+304710.237196.731826970939830.7861768333014620210000.45780.1150.86090.797-99.0-99.0-99.0-99.00.375095869817667571.944646754.15663.73600755.64026a3iii
HELP_J132321.501+264200.206200.8395871197894626.70005719365088520210010.1910.13520.24190.789-99.0-99.0-99.0-99.00.190935367122588130.3307720.0315931750.0113860150.71356825rk4iii
HELP_J130554.319+305415.277196.476331037860930.90424374365774420210020.40680.16970.64580.799-99.0-99.0-99.0-99.00.383358820899401930.598047250.2157826250.42990750.5903925rk3iii
HELP_J133509.654+295231.029203.7902241187686629.87528592817221820210030.68780.26451.11670.795-99.0-99.0-99.0-99.00.84980243443782730.000371105750.00849507250.00544906251.97335075m2p5v
......................................................
HELP_J134135.307+344421.576205.397113307433534.739326599796960818560.62460.14541.12950.797-99.0-99.0-99.0-99.00.5972747586551431-99.0-99.0-99.0-99.0
HELP_J124858.080+341216.830192.242001087433534.204674899796960818570.79110.27211.33670.799-99.0-99.0-99.0-99.00.76323589477731350.01313327750.0008136260.00461288250.155416775m5v
HELP_J134424.709+335630.506206.1029544974334733.941807129796960818580.46680.1250.82230.798-99.0-99.0-99.0-99.00.4512751936257148-99.0-99.0-99.0-99.0
HELP_J133709.162+345604.772204.2881747374334834.934658939796960818590.54550.18380.95230.798-99.0-99.0-99.0-99.00.40844678181297480.345699751.332969250.819521252.979185f5iii
HELP_J134920.644+332452.682207.336016787433533.414633919796960818600.73430.38751.0790.798-99.0-99.0-99.0-99.00.75796200875106020.104833514285714290.137221928571428560.230143.830704285714286m3ii
HELP_J125306.685+333113.670193.277854087433533.520463959796960818620.61990.21251.04810.798-99.0-99.0-99.0-99.00.5179720228371970.0004874240.0195836750.0716894251.0567145m1v
HELP_J124548.943+313103.543191.4539282103293431.517650903959260818630.52180.25690.79520.793-99.0-99.0-99.0-99.00.53626982166441080.487267666666666650.143100316666666670.139414983333333333.8422983333333334m2i
HELP_J125400.987+335609.752193.5041120274334833.93604226979696081868-99.0-99.0-99.0-99.0-99.0-99.0-99.0-99.00.0628029174171393-99.0-99.0-99.0-99.0
HELP_J132505.187+340052.360201.27161309818834.0145445504916260818750.43920.15580.74220.660.88770.83330.9640.1310.41267212215841370.197161652.188884252.340738511.774875k0iv
HELP_J124622.195+335623.136191.592480077433533.939759949796960818770.12640.02220.20170.797-99.0-99.0-99.0-99.00.121681435902394436.4993916.35780522.5637427.0209f0v
" ], "text/plain": [ "\n", " help_id RA ... stellar_type\n", " bytes27 float64 ... bytes6 \n", "--------------------------- ------------------ ... ------------\n", "HELP_J131410.500+302813.489 198.54375042943158 ... rg5iii\n", "HELP_J133855.810+281107.598 204.73254078095655 ... m0iii\n", "HELP_J130324.552+285933.902 195.85230149733783 ... g5ii\n", "HELP_J125051.674+284236.699 192.71530874422427 ... m3v\n", "HELP_J133040.559+290320.044 202.66899411411032 ... rf8v\n", "HELP_J125342.104+271050.555 193.42543477062267 ... m2p5v\n", "HELP_J130655.638+304710.237 196.7318269709398 ... a3iii\n", "HELP_J132321.501+264200.206 200.83958711978946 ... rk4iii\n", "HELP_J130554.319+305415.277 196.4763310378609 ... rk3iii\n", "HELP_J133509.654+295231.029 203.79022411876866 ... m2p5v\n", " ... ... ... ...\n", "HELP_J134135.307+344421.576 205.3971133074335 ... \n", "HELP_J124858.080+341216.830 192.2420010874335 ... m5v\n", "HELP_J134424.709+335630.506 206.10295449743347 ... \n", "HELP_J133709.162+345604.772 204.28817473743348 ... f5iii\n", "HELP_J134920.644+332452.682 207.3360167874335 ... m3ii\n", "HELP_J125306.685+333113.670 193.2778540874335 ... m1v\n", "HELP_J124548.943+313103.543 191.45392821032934 ... m2i\n", "HELP_J125400.987+335609.752 193.50411202743348 ... \n", "HELP_J132505.187+340052.360 201.271613098188 ... k0iv\n", "HELP_J124622.195+335623.136 191.5924800774335 ... f0v" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "photoz" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Join CIGALE and photoz tables" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": true }, "outputs": [], "source": [ "prior=join(cigale,photoz,keys='help_id')" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from astropy.cosmology import Planck15 as cosmo\n", "from astropy import units as u\n", "f_pred=prior['bayes.dust.luminosity']/(4*np.pi*cosmo.luminosity_distance(prior['z1_median']).to(u.cm))\n" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": true }, "outputs": [], "source": [ "prior=prior[np.isfinite(f_pred.value)][np.log10(f_pred.value[np.isfinite(f_pred.value)])>8.5]" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": true }, "outputs": [], "source": [ "prior['DEC'].name='Dec'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read in Maps" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": true }, "outputs": [], "source": [ "\n", "pswfits='../../dmu19/dmu19_HELP-SPIRE-maps/data/HATLAS-NGP_SPIRE250_v1.0.fits'#SPIRE 250 map\n", "pmwfits='../../dmu19/dmu19_HELP-SPIRE-maps/data/HATLAS-NGP_SPIRE350_v1.0.fits'#SPIRE 350 map\n", "plwfits='../../dmu19/dmu19_HELP-SPIRE-maps/data/HATLAS-NGP_SPIRE500_v1.0.fits'#SPIRE 500 map\n", "\n", "#output folder\n", "output_folder='./'" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from astropy.io import fits\n", "from astropy import wcs\n", "\n", "#-----250-------------\n", "hdulist = fits.open(pswfits)\n", "im250phdu=hdulist[0].header\n", "im250hdu=hdulist[1].header\n", "\n", "im250=hdulist[1].data*1.0E3 #convert to mJy\n", "nim250=hdulist[3].data*1.0E3 #convert to mJy\n", "w_250 = wcs.WCS(hdulist[1].header)\n", "pixsize250=3600.0*w_250.wcs.cdelt #pixel size (in arcseconds)\n", "hdulist.close()\n", "#-----350-------------\n", "hdulist = fits.open(pmwfits)\n", "im350phdu=hdulist[0].header\n", "im350hdu=hdulist[1].header\n", "\n", "im350=hdulist[1].data*1.0E3 #convert to mJy\n", "nim350=hdulist[3].data*1.0E3 #convert to mJy\n", "w_350 = wcs.WCS(hdulist[1].header)\n", "pixsize350=3600.0*w_350.wcs.cdelt #pixel size (in arcseconds)\n", "hdulist.close()\n", "#-----500-------------\n", "hdulist = fits.open(plwfits)\n", "im500phdu=hdulist[0].header\n", "im500hdu=hdulist[1].header\n", "im500=hdulist[1].data*1.0E3 #convert to mJy\n", "nim500=hdulist[3].data*1.0E3 #convert to mJy\n", "w_500 = wcs.WCS(hdulist[1].header)\n", "pixsize500=3600.0*w_500.wcs.cdelt #pixel size (in arcseconds)\n", "hdulist.close()" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": true }, "outputs": [], "source": [ "## Set XID+ prior class" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING: AstropyDeprecationWarning: \n", "Private attributes \"_naxis1\" and \"_naxis2\" have been deprecated since v3.1.\n", "Instead use the \"pixel_shape\" property which returns a list of NAXISj keyword values.\n", " [astropy.wcs.wcs]\n", "WARNING: AstropyDeprecationWarning: \n", "Private attributes \"_naxis1\" and \"_naxis2\" have been deprecated since v3.1.\n", "Instead use the \"pixel_shape\" property which returns a list of NAXISj keyword values.\n", " [astropy.wcs.wcs]\n" ] } ], "source": [ "#---prior250--------\n", "prior250=xidplus.prior(im250,nim250,im250phdu,im250hdu, moc=Sel_func)#Initialise with map, uncertianty map, wcs info and primary header\n", "prior250.prior_cat(prior['RA'] ,prior['Dec'] ,'NGP_results_Ldust_prediction.fits',ID=prior['help_id'] )#Set input catalogue\n", "prior250.prior_bkg(-5.0,5)#Set prior on background (assumes Gaussian pdf with mu and sigma)\n", "#---prior350--------\n", "prior350=xidplus.prior(im350,nim350,im350phdu,im350hdu, moc=Sel_func)\n", "prior350.prior_cat(prior['RA'] ,prior['Dec'] ,'NGP_results_Ldust_prediction.fits',ID=prior['help_id'] )\n", "prior350.prior_bkg(-5.0,5)\n", "\n", "#---prior500--------\n", "prior500=xidplus.prior(im500,nim500,im500phdu,im500hdu, moc=Sel_func)\n", "prior500.prior_cat(prior['RA'] ,prior['Dec'] ,'NGP_results_Ldust_prediction.fits',ID=prior['help_id'] )\n", "prior500.prior_bkg(-5.0,5)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#pixsize array (size of pixels in arcseconds)\n", "pixsize=np.array([pixsize250,pixsize350,pixsize500])\n", "#point response function for the three bands\n", "prfsize=np.array([18.15,25.15,36.3])\n", "#use Gaussian2DKernel to create prf (requires stddev rather than fwhm hence pfwhm/2.355)\n", "from astropy.convolution import Gaussian2DKernel\n", "\n", "##---------fit using Gaussian beam-----------------------\n", "prf250=Gaussian2DKernel(prfsize[0]/2.355,x_size=101,y_size=101)\n", "prf250.normalize(mode='peak')\n", "prf350=Gaussian2DKernel(prfsize[1]/2.355,x_size=101,y_size=101)\n", "prf350.normalize(mode='peak')\n", "prf500=Gaussian2DKernel(prfsize[2]/2.355,x_size=101,y_size=101)\n", "prf500.normalize(mode='peak')\n", "\n", "pind250=np.arange(0,101,1)*1.0/pixsize[0,1] #get 250 scale in terms of pixel scale of map\n", "pind350=np.arange(0,101,1)*1.0/pixsize[1,1] #get 350 scale in terms of pixel scale of map\n", "pind500=np.arange(0,101,1)*1.0/pixsize[2,1] #get 500 scale in terms of pixel scale of map\n", "\n", "prior250.set_prf(prf250.array,pind250,pind250)#requires psf as 2d grid, and x and y bins for grid (in pixel scale)\n", "prior350.set_prf(prf350.array,pind350,pind350)\n", "prior500.set_prf(prf500.array,pind500,pind500)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "----- There are 4959 tiles required for input catalogue and 102 large tiles\n", "writing total_bytes=1588798331...\n", "writing bytes [0, 1073741824)... done.\n", "writing bytes [1073741824, 1588798331)... done.\n" ] }, { "ename": "SystemExit", "evalue": "", "output_type": "error", "traceback": [ "An exception has occurred, use %tb to see the full traceback.\n", "\u001b[0;31mSystemExit\u001b[0m\n" ] } ], "source": [ "import pickle\n", "#from moc, get healpix pixels at a given order\n", "from xidplus import moc_routines\n", "order=9\n", "tiles=moc_routines.get_HEALPix_pixels(order,prior250.sra,prior250.sdec,unique=True)\n", "order_large=6\n", "tiles_large=moc_routines.get_HEALPix_pixels(order_large,prior250.sra,prior250.sdec,unique=True)\n", "print('----- There are '+str(len(tiles))+' tiles required for input catalogue and '+str(len(tiles_large))+' large tiles')\n", "output_folder='./data/'\n", "outfile=output_folder+'Master_prior.pkl'\n", "xidplus.io.pickle_dump({'priors':[prior250,prior350,prior500],'tiles':tiles,'order':order,'version':xidplus.io.git_version()},outfile)\n", "outfile=output_folder+'Tiles.pkl'\n", "with open(outfile, 'wb') as f:\n", " pickle.dump({'tiles':tiles,'order':order,'tiles_large':tiles_large,'order_large':order_large,'version':xidplus.io.git_version()},f)\n", "raise SystemExit()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "prior250.nsrc" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "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.6.8" } }, "nbformat": 4, "nbformat_minor": 2 }