{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Final stage of HELP data processing\n", "\n", "This notebook performs collates the final output files ready for writing to csv for ingestion to a VO server\n", "\n", "- Take DR1 masterlist suffixes from overview table\n", "- Find dmu32 full table names and write to a file\n", "- Create summary of all the data products per field using the dmu32 meta_main.yml files" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "\n", "from herschelhelp_internal import git_version\n", "print(\"This notebook was run with herschelhelp_internal version: \\n{}\".format(git_version()))\n", "import datetime\n", "print(\"This notebook was executed on: \\n{}\".format(datetime.datetime.now()))" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [], "source": [ "from astropy.table import Table, Column\n", "from astropy import units as u\n", "import numpy as np\n", "\n", "from pymoc import MOC\n", "\n", "from herschelhelp_internal.masterlist import find_last_ml_suffix\n", "\n", "import yaml\n", "\n", "import os\n", "import time\n", "\n", "import humanfriendly" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [], "source": [ "TODAY = os.environ.get('SUFFIX', time.strftime(\"_%Y%m%d\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The definition of HELP DR1\n", "Here we take the DR1 definition from dmu1. We then propagate those suffixes through to dmu32. Note that this does not include a specification of how the masterlist made its way through the whole HELP process." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": true }, "outputs": [], "source": [ "dr1 = Table.read(\"../dmu1/dr1_overview.fits\")" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "Table length=23\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", "\n", "
idxfielddr1_suffixlast_suffixobjectsarea_sq_degreesfile_size_bytesfile_size_readable
0AKARI-NEP20180215201802155317469.19473235878348848640348.85 MB
1AKARI-SEP20180221201802218441728.71330647513538606080538.61 MB
2Bootes2018052020180520348166111.42815299150020444805 GB
3CDFS-SWIRE2018061320180613217105112.971246403757055939205.71 GB
4COSMOS201806192018061925993745.08386347851051717536010.52 GB
5EGS201805012018050114126133.5663832751238084803203.81 GB
6ELAIS-N12017101620180216402629213.507484555552422796805.24 GB
7ELAIS-N2201802182018021817832409.1674799039920079648002.01 GB
8ELAIS-S1201804162018041616555649.0029406468919701561601.97 GB
9GAMA-0920180601201806011293798262.01393417281991161152019.91 GB
10GAMA-1220180218201802181236941562.70933280771463306688014.63 GB
11GAMA-1520180213201802131423288061.70114565981659558528016.6 GB
12HDF-N20180427201804271306790.671783255817185996160186 MB
13Herschel-Stripe-82201803072018030750196455363.227479306127047306240127.05 GB
14Lockman-SWIRE2018021920180219436629822.413863402951959318405.2 GB
15NGP20180219201805016759591177.69819710849548067204.95 GB
16SA13201805012018050197990.27416379328427216002.72 MB
17SGP201802212018022129790690294.568454094519253088045.19 GB
18SPIRE-NEP201802202018022026740.12806604693812038401.2 MB
19SSDF201802212018022112661903111.11624949380783193608.08 GB
20xFLS20180501201805019771487.4404324214110504742401.05 GB
21XMM-13hr2018050120180501386290.7570240166581067616010.68 MB
22XMM-LSS2018050420180504870583721.75457939332824183872028.24 GB
\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dr1.show_in_notebook()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "./dmu32_AKARI-NEP/data/AKARI-NEP_20180215_cigale.fits\n", "./dmu32_AKARI-SEP/data/AKARI-SEP_20180221_cigale.fits\n", "./dmu32_Bootes/data/Bootes_20180520_cigale.fits\n", "./dmu32_CDFS-SWIRE/data/CDFS-SWIRE_20180613.fits\n", "./dmu32_COSMOS/data/COSMOS_20180619.fits\n", "./dmu32_EGS/data/EGS_20180501_cigale.fits\n", "./dmu32_ELAIS-N1/data/ELAIS-N1_20171016.fits\n", "./dmu32_ELAIS-N2/data/ELAIS-N2_20180218_cigale.fits\n", "./dmu32_ELAIS-S1/data/ELAIS-S1_20180416.fits\n", "./dmu32_GAMA-09/data/GAMA-09_20180601.fits\n", "./dmu32_GAMA-12/data/GAMA-12_20180218.fits\n", "./dmu32_GAMA-15/data/GAMA-15_20180213.fits\n", "./dmu32_HDF-N/data/HDF-N_20180427_cigale.fits\n", "./dmu32_Herschel-Stripe-82/data/Herschel-Stripe-82_20180307_cigale.fits\n", "./dmu32_Lockman-SWIRE/data/Lockman-SWIRE_20180219.fits\n", "./dmu32_NGP/data/NGP_20180219_cigale.fits\n", "./dmu32_SA13/data/SA13_20180501_cigale.fits\n", "./dmu32_SGP/data/SGP_20180221_cigale.fits\n", "./dmu32_SPIRE-NEP/data/SPIRE-NEP_20180220_cigale.fits\n", "./dmu32_SSDF/data/SSDF_20180221_cigale.fits\n", "./dmu32_xFLS/data/xFLS_20180501_cigale.fits\n", "./dmu32_XMM-13hr/data/XMM-13hr_20180501_cigale.fits\n", "./dmu32_XMM-LSS/data/XMM-LSS_20180504_cigale.fits\n" ] } ], "source": [ "GAVO_FOLDER = '/mnt/hedam/data_vo/'\n", "stilts_command = 'stilts tpipe {in_file} omode=out ofmt=csv out={GAVO_FOLDER}{out_file}'\n", "\n", "final_data = open('help_to_vo.sh', 'w+')\n", "for field in dr1:\n", " final_help_product = './dmu32_{}/data/{}_{}.fits'.format(field[0], field[0], field[1])\n", " cigale_input = './dmu32_{}/data/{}_{}_cigale.fits'.format(field[0], field[0], field[1])\n", "\n", " if os.path.exists(final_help_product):\n", " print(final_help_product)\n", " \n", " #Test with Cigale input files\n", " final_data.write(stilts_command.format(in_file=final_help_product, \n", " GAVO_FOLDER=GAVO_FOLDER, \n", " out_file='herschelhelp/main/{}_{}_all.csv \\n'.format(field[0], \n", " field[1])))\n", " elif os.path.exists(cigale_input):\n", " print(cigale_input)\n", " final_data.write(stilts_command.format(in_file=cigale_input, \n", " GAVO_FOLDER=GAVO_FOLDER, \n", " out_file='herschelhelp/main/{}_{}_incomplete.csv \\n'.format(field[0], \n", " field[1])))\n", " \n", " else:\n", " final_data.write('# No data for {} \\n'.format(field[0]))\n", " \n", " #final_data.write('./dmu32_{}/data/{}_{}.fits'.format(field[0], field[0], field[1]))\n", " \n", "final_data.close()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The out put of this notebook is a shell script which will write all the fits files to csv files in the vo folder" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "../dmu1/dmu1_ml_AKARI-NEP/data/depths_akari-nep_20180215.fits\n", "../dmu1/dmu1_ml_AKARI-SEP/data/depths_akari-sep_20180221.fits\n", "../dmu1/dmu1_ml_Bootes/data/depths_bootes_20180520.fits\n", "../dmu1/dmu1_ml_CDFS-SWIRE/data/depths_cdfs-swire_20180613.fits\n", "../dmu1/dmu1_ml_COSMOS/data/depths_cosmos_20180619.fits\n", "../dmu1/dmu1_ml_EGS/data/depths_egs_20180501.fits\n", "../dmu1/dmu1_ml_ELAIS-N1/data/depths_elais-n1_20171016.fits\n", "../dmu1/dmu1_ml_ELAIS-N2/data/depths_elais-n2_20180218.fits\n", "../dmu1/dmu1_ml_ELAIS-S1/data/depths_elais-s1_20180416.fits\n", "../dmu1/dmu1_ml_GAMA-09/data/depths_gama-09_20180601.fits\n", "../dmu1/dmu1_ml_GAMA-12/data/depths_gama-12_20180218.fits\n", "../dmu1/dmu1_ml_GAMA-15/data/depths_gama-15_20180213.fits\n", "../dmu1/dmu1_ml_HDF-N/data/depths_hdf-n_20180427.fits\n", "../dmu1/dmu1_ml_Herschel-Stripe-82/data/depths_herschel-stripe-82_20180307.fits\n", "../dmu1/dmu1_ml_Lockman-SWIRE/data/depths_lockman-swire_20180219.fits\n", "../dmu1/dmu1_ml_NGP/data/depths_ngp_20180219.fits\n", "../dmu1/dmu1_ml_SA13/data/depths_sa13_20180501.fits\n", "../dmu1/dmu1_ml_SGP/data/depths_sgp_20180221.fits\n", "../dmu1/dmu1_ml_SPIRE-NEP/data/depths_spire-nep_20180220.fits\n", "../dmu1/dmu1_ml_SSDF/data/depths_ssdf_20180221.fits\n", "../dmu1/dmu1_ml_xFLS/data/depths_xfls_20180501.fits\n", "../dmu1/dmu1_ml_XMM-13hr/data/depths_xmm-13hr_20180501.fits\n", "../dmu1/dmu1_ml_XMM-LSS/data/depths_xmm-lss_20180504.fits\n" ] } ], "source": [ "depths_to_vo = open('depths_to_vo.sh', 'w+')\n", "for field in dr1:\n", " final_depth_product = '../dmu1/dmu1_ml_{}/data/depths_{}_{}.fits'.format(field[0], field[0].lower(), field[1])\n", " \n", "\n", " if os.path.exists(final_depth_product):\n", " print(final_depth_product)\n", " \n", " #Test with Cigale input files\n", " depths_to_vo.write(stilts_command.format(in_file=final_depth_product, \n", " GAVO_FOLDER=GAVO_FOLDER, \n", " out_file='depth/{}_{}.csv \\n'.format(field[0], \n", " field[1])))\n", "\n", " \n", " else:\n", " depths_to_vo.write('# No depths for {} \\n'.format(field[0]))\n", " \n", " #final_data.write('./dmu32_{}/data/{}_{}.fits'.format(field[0], field[0], field[1]))\n", " \n", "depths_to_vo.close()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Summarise completeness of HELP data sets\n", "\n", "Here we get information about what is available on each field to summarise the data products available per field. We take the cigale, xid+ and photo-z filenames from the per field meta_main.yml files here and check they are there and how large they are. This then given a summary of all the data present." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": true }, "outputs": [], "source": [ "dr1_data_products = dr1.copy()\n", "\n", "fields_info = yaml.load(open(\"../dmu2/meta_main.yml\", 'r'))" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "collapsed": true }, "outputs": [], "source": [ "dr1_data_products.add_column(Column(data =np.full(len(dr1_data_products), 0, dtype=int), name = 'xid_objects'))\n", "dr1_data_products.add_column(Column(data =np.full(len(dr1_data_products), 0, dtype=int), name = 'photoz_objects'))\n", "dr1_data_products.add_column(Column(data =np.full(len(dr1_data_products), 0, dtype=int), name = 'cigale_objects'))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "\n", "\n" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "AKARI-NEP:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n", "AKARI-SEP:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n", "Bootes:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n", "CDFS-SWIRE:\n", " - xid: dmu_products/dmu26/dmu26_XID+SPIRE_CDFS-SWIRE/data/dmu26_XID+SPIRE_CDFS-SWIRE_cat_20170919.fits\n", " - xid: dmu_products/dmu26/dmu26_XID+MIPS_CDFS-SWIRE/data/dmu26_XID+MIPS_CDFS-SWIRE_cat_20170901.fits\n", " - xid: dmu_products/dmu26/dmu26_XID+PACS_CDFS-SWIRE/data/dmu26_XID+PACS_CDFS-SWIRE_cat_20171019.fits\n", " - photoz: dmu_products/dmu24/dmu24_CDFS-SWIRE/data/master_catalogue_cdfs-swire_20171103_photoz_20180210.fits\n", " - cigale not done.\n", "COSMOS:\n", " - xid: dmu_products/dmu26/dmu26_XID+MIPS_COSMOS/data/dmu26_XID+MIPS_COSMOS_20170213.fits\n", " - xid: dmu_products/dmu26/dmu26_XID+PACS_COSMOS/data/dmu26_XID+PACS_COSMOS_20170303.fits\n", " - xid: dmu_products/dmu26/dmu26_XID+SPIRE_COSMOS/data/dmu26_XID+SPIRE_COSMOS_20161129.fits\n", " - photoz not done.\n", " - cigale not done.\n", "EGS:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n", "ELAIS-N1:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale: dmu_products/dmu28/dmu28_ELAIS-N1/data/zphot/HELP_final_results.fits\n", "ELAIS-N2:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n", "ELAIS-S1:\n", " - xid: dmu_products/dmu26/dmu26_XID+MIPS_ELAIS-S1/data/dmu26_XID+MIPS_ELAIS-S1_20180215.fits\n", " - xid: dmu_products/dmu26/dmu26_XID+PACS_ELAIS-S1/data/dmu26_XID+PACS_ELAIS-S1_cat_20180416.fits\n", " - xid: dmu_products/dmu26/dmu26_XID+SPIRE_ELAIS-S1/data/dmu26_XID+SPIRE_ELAIS-S1_20180327.fits\n", " - photoz not done.\n", " - cigale not done.\n", "GAMA-09:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n", "GAMA-12:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n", "GAMA-15:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n", "HDF-N:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n", "Herschel-Stripe-82:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n", "Lockman-SWIRE:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n", "NGP:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n", "SA13:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n", "SGP:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n", "SPIRE-NEP:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n", "SSDF:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n", "xFLS:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n", "XMM-13hr:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n", "XMM-LSS:\n", " - xid not done.\n", " - photoz not done.\n", " - cigale not done.\n" ] } ], "source": [ "for field in fields_info['fields']:\n", " print(field['name'] + ':')\n", " xid_objects = 0\n", " photoz_objects = 0\n", " cigale_objects = 0\n", " dmu32_info = yaml.load(open('./dmu32_{}/meta_main.yml'.format(field['name']), 'r'))\n", "\n", " \n", " try: \n", " for n, xid_file in enumerate(dmu32_info['xid']):\n", " xid_objects = len(Table.read(xid_file.replace('dmu_products', '..')))\n", " print(\" - xid: {}\".format(dmu32_info['xid'][n]))\n", " except FileNotFoundError:\n", " print(\" - xid not done.\".format(field['name']))\n", " \n", " try: \n", " photoz_objects = len(Table.read(dmu32_info['photoz'].replace('dmu_products', '..')))\n", " print(\" - photoz: {}\".format(dmu32_info['photoz']))\n", " except FileNotFoundError:\n", " print(\" - photoz not done.\".format(field['name']))\n", " \n", " try: \n", " cigale_objects = len(Table.read(dmu32_info['cigale'].replace('dmu_products', '..')))\n", " print(\" - cigale: {}\".format(dmu32_info['cigale']))\n", " except FileNotFoundError:\n", " print(\" - cigale not done.\".format(field['name']))\n", " \n", " \n", " dr1_data_products['xid_objects'][dr1_data_products['field'] == field['name']] = xid_objects\n", " dr1_data_products['photoz_objects'][dr1_data_products['field'] == field['name']] = photoz_objects\n", " dr1_data_products['cigale_objects'][dr1_data_products['field'] == field['name']] = cigale_objects" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "data": { "text/html": [ "Table length=23\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", "
fielddr1_suffixlast_suffixobjectsarea_sq_degreesfile_size_bytesfile_size_readablexid_objectsphotoz_objectscigale_objects
bytes18bytes20bytes20int64float64int64bytes20int64int64int64
AKARI-NEP20180215201802155317469.19473235878348848640348.85 MB000
AKARI-SEP20180221201802218441728.71330647513538606080538.61 MB000
Bootes2018052020180520348166111.42815299150020444805 GB000
CDFS-SWIRE2018061320180613217105112.971246403757055939205.71 GB2404891395320
COSMOS201806192018061925993745.08386347851051717536010.52 GB4431000
EGS201805012018050114126133.5663832751238084803203.81 GB000
ELAIS-N12017101620180216402629213.507484555552422796805.24 GB0050129
ELAIS-N2201802182018021817832409.1674799039920079648002.01 GB000
ELAIS-S1201804162018041616555649.0029406468919701561601.97 GB19427600
GAMA-0920180601201806011293798262.01393417281991161152019.91 GB000
..............................
Herschel-Stripe-82201803072018030750196455363.227479306127047306240127.05 GB000
Lockman-SWIRE2018021920180219436629822.413863402951959318405.2 GB000
NGP20180219201805016759591177.69819710849548067204.95 GB000
SA13201805012018050197990.27416379328427216002.72 MB000
SGP201802212018022129790690294.568454094519253088045.19 GB000
SPIRE-NEP201802202018022026740.12806604693812038401.2 MB000
SSDF201802212018022112661903111.11624949380783193608.08 GB000
xFLS20180501201805019771487.4404324214110504742401.05 GB000
XMM-13hr2018050120180501386290.7570240166581067616010.68 MB000
XMM-LSS2018050420180504870583721.75457939332824183872028.24 GB000
" ], "text/plain": [ "\n", " field dr1_suffix last_suffix ... photoz_objects cigale_objects\n", " bytes18 bytes20 bytes20 ... int64 int64 \n", "------------------ ---------- ----------- ... -------------- --------------\n", " AKARI-NEP 20180215 20180215 ... 0 0\n", " AKARI-SEP 20180221 20180221 ... 0 0\n", " Bootes 20180520 20180520 ... 0 0\n", " CDFS-SWIRE 20180613 20180613 ... 139532 0\n", " COSMOS 20180619 20180619 ... 0 0\n", " EGS 20180501 20180501 ... 0 0\n", " ELAIS-N1 20171016 20180216 ... 0 50129\n", " ELAIS-N2 20180218 20180218 ... 0 0\n", " ELAIS-S1 20180416 20180416 ... 0 0\n", " GAMA-09 20180601 20180601 ... 0 0\n", " ... ... ... ... ... ...\n", "Herschel-Stripe-82 20180307 20180307 ... 0 0\n", " Lockman-SWIRE 20180219 20180219 ... 0 0\n", " NGP 20180219 20180501 ... 0 0\n", " SA13 20180501 20180501 ... 0 0\n", " SGP 20180221 20180221 ... 0 0\n", " SPIRE-NEP 20180220 20180220 ... 0 0\n", " SSDF 20180221 20180221 ... 0 0\n", " xFLS 20180501 20180501 ... 0 0\n", " XMM-13hr 20180501 20180501 ... 0 0\n", " XMM-LSS 20180504 20180504 ... 0 0" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dr1_data_products" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [], "source": [ "dr1_data_products.write('dr1_data_products_overview{}.csv'.format(TODAY), 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.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }