{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Downloading Legacy Survey DR4\n", "\n", "This notebook describes the downloading of the 'Legacy Survey' DR4\n", "\n", "http://legacysurvey.org/dr4/description/\n", "\n", "There are still edge effects due to using the brick centre to check if it is in HELP. TODO: develop a nearMoc function which says if a given ra/dec is near a given moc (within a given distance). This function already exists within Stilts." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import subprocess\n", "\n", "from astropy.table import Table\n", "\n", "from pymoc import MOC\n", "\n", "from herschelhelp_internal.utils import inMoc" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "log_file = open('log.txt', 'a')" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Download the list of all bricks\n", "subprocess.call(['wget', \n", " 'ftp://archive.noao.edu/public/hlsp/ls/dr4/survey-bricks-dr4.fits.gz', '-P', './data'], \n", " stdout=log_file)\n", "\n", "#Download the list of all bricks\n", "subprocess.call(['wget', \n", " 'ftp://archive.noao.edu/public/hlsp/ls/dr4/survey-bricks.fits.gz', '-P', './data'], \n", " stdout=log_file)\n", "\n", "#Download the list of all bricks\n", "subprocess.call(['wget', \n", " 'ftp://archive.noao.edu/public/hlsp/ls/dr3/survey-bricks-dr3.fits.gz', '-P', './data'], \n", " stdout=log_file)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Total bricks on whole sky: 662174\n", "Total bricks on DECaLS DR3: 149464\n", "Total bricks on Legacy Survey DR4: 65543\n" ] } ], "source": [ "dr4_bricks = Table.read('./data/survey-bricks-dr4.fits.gz')\n", "dr3_bricks = Table.read('./data/survey-bricks-dr3.fits.gz')\n", "total_bricks = Table.read('./data/survey-bricks.fits.gz')\n", "print('Total bricks on whole sky: ' + str(len(total_bricks)))\n", "print('Total bricks on DECaLS DR3: ' + str(len(dr3_bricks)))\n", "print('Total bricks on Legacy Survey DR4: ' + str(len(dr4_bricks)))" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "<Table length=10>\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
idxbricknameradecnexp_gnexp_rnexp_znexphist_g [6]nexphist_r [6]nexphist_z [6]nobjsnpsfnsimpnexpndevncomppsfsize_gpsfsize_rpsfsize_zpsfdepth_gpsfdepth_rpsfdepth_zgaldepth_ggaldepth_rgaldepth_zebvtrans_gtrans_rtrans_zext_gext_rext_zwise_nobs [4]trans_wise [4]ext_w1ext_w2ext_w3ext_w4
00556p33255.67164179133.250080 .. 00 .. 03983213 .. 68692312434171642418810060.00.01.100440.00.023.53820.00.023.15850.4985280.2286090.3700620.5734731.602271.079310.60371770 .. 120.918985 .. 0.995830.09172910.05633360.01201450.0045366
10557p33055.785123966933.00060 .. 00 .. 03515900 .. 6151845230816463811789940.00.01.127770.00.023.59380.00.023.23220.5283840.2092710.3486740.5546911.698231.143950.63987374 .. 120.914347 .. 0.9955810.09722260.05970730.0127340.00480827
20557p33555.764119601333.500100 .. 00 .. 0335689 .. 891853834092322567297208150.00.01.088770.00.023.63770.00.023.25580.557020.1922630.3293220.5372541.790261.205950.67455173 .. 120.90992 .. 0.9953420.1024920.06294330.01342420.0050689
30559p33255.970149253733.2500100 .. 00 .. 08565 .. 1152423738432595694332210120.00.01.103830.00.023.54160.00.023.17770.5678370.1862040.3222950.5308111.825031.229370.68765172 .. 130.908254 .. 0.9952520.1044820.06416560.01368490.00516734
40560p33056.082644628133.00060 .. 00 .. 03395289 .. 6321674224315664161599840.00.01.152550.00.023.46390.00.023.11470.6161660.1613830.2926850.5029551.980361.3340.74617774 .. 120.900845 .. 0.9948490.1133740.06962670.01484960.00560712
50560p33556.063122923633.500100 .. 00 .. 060892 .. 978233933902384590256145150.00.01.095240.00.023.62860.00.023.24680.5592810.190980.3278410.5359011.797531.210840.67728973 .. 130.909572 .. 0.9953230.1029080.06319870.01347870.00508944
60562p33256.268656716433.250090 .. 00 .. 01228886 .. 96075093287235452827012870.00.01.137150.00.023.55520.00.023.20010.6339240.1531180.2825020.4930912.037431.372450.76768274 .. 130.898138 .. 0.9947010.1166420.07163340.01527760.00576871
70563p33056.380165289333.00000 .. 00 .. 07450967 .. 28218421156820187964670.00.01.176650.00.023.47110.00.023.1320.6478520.1469340.2747640.485492.08221.40260.78454973 .. 130.896021 .. 0.9945850.1192050.07320730.01561330.00589546
80563p33556.362126245833.50020 .. 00 .. 05186227 .. 4945981184114022441197150.00.01.122850.00.023.64270.00.023.27540.5629550.1889140.3254480.5337091.809341.21880.68173874 .. 130.909006 .. 0.9952930.1035840.06361390.01356720.00512286
90644p67764.472727272767.750100 .. 04711324 .. 00 .. 0104492566193040.01.400170.00.022.00050.00.021.39130.00.5161020.217020.3573190.5623421.658751.117360.625113 .. 160.916252 .. 0.9956840.09496280.05831950.01243810.00469654
\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dr4_bricks[:10].show_in_notebook()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#TODO: Maybe check for edge effects and add add extra leeway\n", "fields= [\n", "# Field RAtyp DECtyp RAmin RAmax DECmin DECmax\n", "['AKARI-NEP', 274.65, 65.796, 263.6, 266.5, 68.48, 69.51 ],\n", "['AKARI-SEP', 72.231, -54.380, 66.1, 75.5, -55.96, -51.61 ],\n", "['Bootes', 216.43, 32.401, 215.7, 220.7, 32.12, 36.18 ],\n", "['CDFS-SWIRE', 51.022, -29.818, 50.7, 55.5, -30.50, -25.92 ],\n", "['COSMOS', 149.29, 1.0821, 148.6, 151.6, 0.72, 3.71 ],\n", "['EGS', 217.27, 53.644, 212.3, 217.6, 51.08, 54.31 ],\n", "['ELAIS-N1', 247.09, 55.175, 237.9, 247.9, 52.37, 57.59 ],\n", "['ELAIS-N2', 248.42, 39.127, 246.1, 252.3, 39.02, 43.02 ],\n", "['ELAIS-S1', 7.1062, -43.863, 6.3, 11.3, -45.60, -41.53 ],\n", "['GAMA-09', 129.07, -2.2317, 127.1, 142.2, -2.53, 3.55 ],\n", "['GAMA-12', 172.84, -0.482, 172.2, 187.4, -3.54, 2.59 ],\n", "['GAMA-15', 211.75, -2.2857, 209.9, 225.3, -2.57, 3.5 ],\n", "['HDF-N', 190.25, 62.205, 188.0, 190.4, 61.69, 62.78 ],\n", "['Herschel-Stripe-82', 353.75, -7.1089, 348.3, 19.1, -9.5, 9.25 ],\n", "['Lockman-SWIRE', 161.94, 59.056, 154.7, 167.8, 54.95, 60.89 ],\n", "['NGP', 192.89, 22.099, 189.8, 209.3, 21.62, 36.16 ],\n", "['SA13', 197.89, 42.440, 197.5, 198.6, 42.34, 43.09 ],\n", "['SGP', 334.29, -34.503, 333.5, 28.2, -37.1, -26.0 ],\n", "['SPIRE-NEP', 266.33, 68.790, 264.6, 275.4, 64.41, 68.63 ],\n", "['SSDF', 341.57, -59.186, 340.5, 2.8, -61.2, -48.6 ],\n", "['xFLS', 261.38, 58.018, 255.6, 262.5, 57.85, 60.84 ],\n", "['XMM-13hr', 203.31, 37.474, 202.8, 204.4, 37.31, 38.52 ],\n", "['XMM-LSS', 32.941, -6.0229, 32.1, 38.2, -7.53, -1.52 ]]\n", " \n", " \n", "#Has a field been removed? ( RA BETWEEN 13.4 AND 36.3 AND DEC BETWEEN -2.32 AND 2.49 )\n", " \n", " \n", " \n", " " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "help_moc = MOC()\n", "field_mocs = []\n", "for field in fields:\n", " help_moc += MOC(filename=\"../../dmu2/dmu2_field_coverages/{}_MOC.fits\".format(field[0])) \n", " field_mocs.append(MOC(filename=\"../../dmu2/dmu2_field_coverages/{}_MOC.fits\".format(field[0])))\n", "help_moc.write(\"../../dmu2/help_coverage_MOC.fits\")" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": true }, "outputs": [], "source": [ "help_mask = inMoc(dr4_bricks['ra'],\n", " dr4_bricks['dec'],\n", " MOC(filename=\"../../dmu2/help_coverage_MOC.fits\"))\n" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "There are 1505 bricks in Legacy Survey DR4 in HELP fields\n", "There are 0 bricks in Legacy Survey DR4 for AKARI-NEP\n", "There are 0 bricks in Legacy Survey DR4 for AKARI-SEP\n", "There are 175 bricks in Legacy Survey DR4 for Bootes\n", "There are 0 bricks in Legacy Survey DR4 for CDFS-SWIRE\n", "There are 0 bricks in Legacy Survey DR4 for COSMOS\n", "There are 57 bricks in Legacy Survey DR4 for EGS\n", "There are 215 bricks in Legacy Survey DR4 for ELAIS-N1\n", "There are 147 bricks in Legacy Survey DR4 for ELAIS-N2\n", "There are 0 bricks in Legacy Survey DR4 for ELAIS-S1\n", "There are 0 bricks in Legacy Survey DR4 for GAMA-09\n", "There are 0 bricks in Legacy Survey DR4 for GAMA-12\n", "There are 0 bricks in Legacy Survey DR4 for GAMA-15\n", "There are 0 bricks in Legacy Survey DR4 for HDF-N\n", "There are 0 bricks in Legacy Survey DR4 for Herschel-Stripe-82\n", "There are 182 bricks in Legacy Survey DR4 for Lockman-SWIRE\n", "There are 618 bricks in Legacy Survey DR4 for NGP\n", "There are 5 bricks in Legacy Survey DR4 for SA13\n", "There are 0 bricks in Legacy Survey DR4 for SGP\n", "There are 0 bricks in Legacy Survey DR4 for SPIRE-NEP\n", "There are 0 bricks in Legacy Survey DR4 for SSDF\n", "There are 93 bricks in Legacy Survey DR4 for xFLS\n", "There are 13 bricks in Legacy Survey DR4 for XMM-13hr\n", "There are 0 bricks in Legacy Survey DR4 for XMM-LSS\n" ] } ], "source": [ "print('There are ' + str(len(dr4_bricks[help_mask])) + ' bricks in Legacy Survey DR4 in HELP fields')\n", "help_bricks_file = open(\"./data/help_bricks.lis\", \"w\")\n", "help_downloads_file = open(\"./data/help_bricks_downloads.lis\", \"w\")\n", "field_coverages = {}\n", "\n", "for field in fields:\n", " \n", " #TODO: creplace inMoc with new function nearMoc to avoid any edge effects\n", " field_mask = inMoc(dr4_bricks['ra'],\n", " dr4_bricks['dec'],\n", " MOC(filename=\"../../dmu2/dmu2_field_coverages/{}_MOC.fits\".format(field[0])))\n", " print('There are ' + str(len(dr4_bricks[field_mask])) + ' bricks in Legacy Survey DR4 for ' + field[0])\n", " field_coverages[field[0]] = len(dr4_bricks[field_mask])\n", " field_bricks_file = open(\"./data/{}_bricks.lis\".format(field[0]), \"w\")\n", " field_downloads_file = open(\"./data/{}_bricks_downloads.lis\".format(field[0]), \"w\")\n", " for brick in dr4_bricks[field_mask]:\n", " \n", " brick_string = (\"public/hlsp/ls/dr4/tractor/\" \n", " + brick['brickname'][:3] \n", " + '/tractor-' \n", " + brick['brickname'] \n", " + '.fits\\n')\n", " field_bricks_file.write(brick_string)\n", " field_downloads_file.write(\"ftp://archive.noao.edu/\" + brick_string)\n", " help_bricks_file.write(brick_string)\n", " help_downloads_file.write(\"ftp://archive.noao.edu/\" + brick_string)\n", " field_bricks_file.close()\n", " field_downloads_file.close()\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Using the RA/DEC limits\n", "Because of edge effects it is better to use the conservative ra/dec bounding boxes" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "print('There are ' + str(len(dr4_bricks[help_mask])) + ' bricks in Legacy Survey DR4 in HELP fields')\n", "help_bricks_file = open(\"./data/help_bricks.lis\", \"w\")\n", "help_downloads_file = open(\"./data/help_bricks_downloads.lis\", \"w\")\n", "field_coverages = {}\n", "\n", "def inRectangle(RAmin, RAmax, DECmin, DECmax, ra, dec):\n", " if RAmin < RAmax:\n", " if ra > RAmin and ra < RAmax and dec > DECmin and dec < DECmax:\n", " output = True\n", " else:\n", " output = False\n", " elif RAmin > RAmax:\n", " if (ra > RAmin or ra < RAmax) and (dec > DECmin and dec < DECmax):\n", " output = True\n", " else:\n", " output = False\n", " \n", " return output\n", " \n", "\n", "for field in fields:\n", " \n", " #TODO: creplace inMoc with new function nearMoc to avoid any edge effects\n", " field_mask = inMoc(dr4_bricks['ra'],\n", " dr4_bricks['dec'],\n", " MOC(filename=\"../../dmu2/dmu2_field_coverages/{}_MOC.fits\".format(field[0])))\n", " print('There are ' + str(len(dr4_bricks[field_mask])) + ' bricks in Legacy Survey DR4 for ' + field[0])\n", " field_coverages[field[0]] = len(dr4_bricks[field_mask])\n", " field_bricks_file = open(\"./data/{}_bricks_wider.lis\".format(field[0]), \"w\")\n", " field_downloads_file = open(\"./data/{}_bricks_downloads_wider.lis\".format(field[0]), \"w\")\n", " for brick in dr4_bricks:\n", " if inRectangle(field[3], field[4], field[5], field[6], brick['ra'], brick['dec'])\n", " \n", " brick_string = (\"public/hlsp/ls/dr4/tractor/\" \n", " + brick['brickname'][:3] \n", " + '/tractor-' \n", " + brick['brickname'] \n", " + '.fits\\n')\n", " field_bricks_file.write(brick_string)\n", " field_downloads_file.write(\"ftp://archive.noao.edu/\" + brick_string)\n", " help_bricks_file.write(brick_string)\n", " help_downloads_file.write(\"ftp://archive.noao.edu/\" + brick_string)\n", " field_bricks_file.close()\n", " field_downloads_file.close()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Comparison to DECaLS DR3\n", "We were originally confused about the relation between Legacy Survey Dr4 and DECaLS DR3 and wanted to compare coverages. It seems that they only marginally overlap and that DECaLS DR3 is officially included in Legacy Survey DR4 but that the actual data provided is only from BASS and MzLS." ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "There are 0 bricks in AKARI-NEP\n", "There are 0 bricks in AKARI-SEP\n", "There are 152 bricks in Bootes\n", "There are 0 bricks in CDFS-SWIRE\n", "There are 83 bricks in COSMOS\n", "There are 0 bricks in EGS\n", "There are 0 bricks in ELAIS-N1\n", "There are 0 bricks in ELAIS-N2\n", "There are 0 bricks in ELAIS-S1\n", "There are 966 bricks in GAMA-09\n", "There are 1006 bricks in GAMA-12\n", "There are 986 bricks in GAMA-15\n", "There are 0 bricks in HDF-N\n", "There are 4908 bricks in Herschel-Stripe-82\n", "There are 0 bricks in Lockman-SWIRE\n", "There are 2591 bricks in NGP\n", "There are 0 bricks in SA13\n", "There are 0 bricks in SGP\n", "There are 0 bricks in SPIRE-NEP\n", "There are 0 bricks in SSDF\n", "There are 0 bricks in xFLS\n", "There are 0 bricks in XMM-13hr\n", "There are 349 bricks in XMM-LSS\n" ] } ], "source": [ "for field in fields:\n", " field_mask = inMoc(dr3_bricks['ra'],\n", " dr3_bricks['dec'],\n", " MOC(filename=\"../../dmu2/dmu2_field_coverages/{}_MOC.fits\".format(field[0])))\n", " print('There are ' + str(len(dr3_bricks[field_mask])) + ' bricks in DECaLS DR3 for ' + field[0])\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#Download only the bricks for help fields\n", "#for field in fields\n", "# subprocess.call(['wget', \n", "# '-irx', '{}_bricks.lis'.format(field[0]), '-P', './data'], \n", "# stdout=log_file)\n", "\n", "#Download just the files with HELP coverage\n", "subprocess.call(['wget', \n", " '-irx', './data/help_bricks_downloads.lis', '-P', './data'], \n", " stdout=log_file)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#Concatenate all the fits files into one fits file\n", "for field in fields:\n", " if field_coverages[field[0]] == 0:\n", " continue\n", " #First creat the overall fits files by concatenating all the relevant tables\n", " subprocess.call(['stilts', \n", " 'tcat', 'in=@{}_bricks.lis'.format(field[0]), 'out=LegacySurvey-dr4_{}.fits'.format(field[0])], \n", " stdout=log_file)\n", " \n", " #TODO: Remove all the sources which are not in HELP (Due to edge effects where part of the bricks go outside)\n", " #Label the points by Field\n", " #subprocess.call(['stilts', \n", " # 'addcol', \n", " # 'Field',\n", " # '\\\"inMoc(\\\"../../dmu2/field_coverages/{}_MOC.fits\\\") ?\\\"COSMOS\\\" : \\\"NOFIELD\\\"\\\"'], \n", " # stdout=log_file)\n", " # \n", " #Remove the points with \"NOFIELD\"\n", " #subprocess.call(['stilts', \n", " # 'select', \n", " # '\\\"Field',\n", " # '!=',\n", " # '\\\"NOFIELD\\\"\\\"'\n", " # ], \n", " # stdout=log_file)\n", " \n", " # Then generate the MOCs\n", " subprocess.call(['stilts', \n", " 'pixfoot', \n", " 'in=LegacySurvey-dr4_{}.fits'.format(field[0]), \n", " 'out=LegacySurvey-dr4_{}_MOC.fits'.format(field[0]),\n", " 'order=12' #Order 12 seems to avoid any holes\n", " ], \n", " stdout=log_file)" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING: UnitsWarning: '1/deg^2' did not parse as fits unit: Numeric factor not supported by FITS [astropy.units.core]\n", "WARNING: UnitsWarning: 'nanomaggy' did not parse as fits unit: At col 0, Unit 'nanomaggy' not supported by the FITS standard. [astropy.units.core]\n", "WARNING: UnitsWarning: '1/nanomaggy^2' did not parse as fits unit: Numeric factor not supported by FITS [astropy.units.core]\n", "WARNING: UnitsWarning: '1/arcsec^2' did not parse as fits unit: Numeric factor not supported by FITS [astropy.units.core]\n" ] } ], "source": [ "#Can also be done with astropy\n", "for field in fields:\n", " if field_coverages[field[0]] == 0:\n", " continue\n", " field_catalogue = Table.read('./data/LegacySurvey-dr4_{}.fits'.format(field[0]))\n", " mask = inMoc(field_catalogue['ra'],\n", " field_catalogue['dec'],\n", " MOC(filename='../../dmu2/dmu2_field_coverages/{}_MOC.fits'.format(field[0])))\n", " field_catalogue.add_column(Column(data=field[0], name=\"Field\")) #Does it work without providing an array\n", " field_catalogue[mask].write('./data/LegacySurvey-dr4_{}_help_only.fits'.format(field[0]))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Alternative method\n", "This descibes an alternate method using the filter and tag shell script. This downloads everything and then tags it. It doesn't suffer from any edge effects but requires very large memory resources (both RAM and storage)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#Download all the files (Total ~270 Gb)\n", "subprocess.call(['wget', \n", " '-r', \n", " 'ftp://archive.noao.edu/public/hlsp/ls/dr4/tractor/', \n", " '-P', \n", " './data'], \n", " stdout=log_file)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#Create a list of all the fits files \n", "subprocess.call(['ls', \n", " './data/archive.noao.edu/public/hlsp/ls/dr4/tractor/*/*.fits', \n", " '>', \n", " '.data/tractor_files.lis'], \n", " stdout=log_file)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "subprocess.call(['stilts', \n", " 'tcat', \n", " 'in=@tractor_files.lis'.format(field[0]), \n", " 'out=LegacySurvey-dr4.fits'.format(field[0])], \n", " stdout=log_file)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#Use the tag script to filter in to HELP fields\n", "subprocess.call(['./filterAndTag.sh', \n", " 'LegacySurvey_dr4.fits',\n", " 'LegacySurvey_dr4_HELP-coverage.fits'], \n", " stdout=log_file)" ] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:herschelhelp_internal]", "language": "python", "name": "conda-env-herschelhelp_internal-py" }, "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.1" } }, "nbformat": 4, "nbformat_minor": 2 }