{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Make coverage MOCs\n",
    "\n",
    "We would like to have a MOC for each survey showing the coverage. In this notebook we simply add all the MOCs in teh data folders together to make a summary MOC. This should be equivalent to using the depth maps."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import glob\n",
    "\n",
    "from pymoc import MOC"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "dirlist = glob.glob('dmu0_*')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "surveys = []\n",
    "for d in dirlist:\n",
    "    surveys.append(d[5:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['NEP-Spitzer',\n",
       " 'UKIDSS-DXS',\n",
       " 'SSDF',\n",
       " 'VICS82',\n",
       " 'ALLWISE',\n",
       " 'SHELA',\n",
       " 'CFHTLS',\n",
       " 'SDWFS',\n",
       " 'UKIDSS-LAS',\n",
       " 'UKIDSS-UDS',\n",
       " 'CFHTLenS',\n",
       " 'UHS',\n",
       " 'GOODS-ACS',\n",
       " 'VIPERS-MLS',\n",
       " 'SEIP',\n",
       " 'GAIA',\n",
       " '2MASS-extended-sources',\n",
       " 'VISTA-VIDEO',\n",
       " 'SpARCS',\n",
       " '2MASS-point-sources',\n",
       " 'CANDELS-UDS',\n",
       " 'IBIS',\n",
       " 'IRAC-EGS',\n",
       " 'DataFusion-Spitzer',\n",
       " 'NDWFS',\n",
       " 'DES',\n",
       " 'Ultradeep-Ks-GOODS-N',\n",
       " 'Bootes_Brown',\n",
       " 'SCUBA2-Duivenvoorden2018',\n",
       " 'GALEX-GCAT',\n",
       " 'SPLASH-SXDF',\n",
       " 'SpIES',\n",
       " 'CANDELS-EGS',\n",
       " 'COMBO-17',\n",
       " 'DEEP2',\n",
       " 'VISTA-VHS',\n",
       " 'zBootes',\n",
       " 'SpUDS',\n",
       " 'Fireworks',\n",
       " 'SDSS-S82',\n",
       " 'VISTA-VIDEO-private',\n",
       " 'ATLAS',\n",
       " 'LegacySurvey',\n",
       " 'SXDS',\n",
       " 'SMUVS',\n",
       " 'RCSLenS',\n",
       " 'UKIDSS-DXS_DR10plus',\n",
       " 'KPNO-FLS',\n",
       " 'IAC_Stripe82_Legacy_Project',\n",
       " 'CANDELS-GOODS-N',\n",
       " 'SIMES',\n",
       " 'DECaLS',\n",
       " 'CANDELS-3D-HST',\n",
       " 'PanSTARRS1-3SS',\n",
       " 'VISTA-VIKING',\n",
       " 'ESIS-VOICE',\n",
       " 'KIDS',\n",
       " 'CFHT-WIRDS',\n",
       " 'SDSS-DR13',\n",
       " 'Hawaii-HDFN',\n",
       " 'AKARI-NEP-OptNIR',\n",
       " 'INTWFC',\n",
       " 'HSC',\n",
       " 'CANDELS-GOODS-S',\n",
       " 'COSMOS2015',\n",
       " 'AEGIS']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "surveys"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NEP-Spitzer has a total area of 7.532947333715363 square degrees.\n",
      "UKIDSS-DXS has a total area of 23.076477129805085 square degrees.\n",
      "SSDF has a total area of 98.19735648970652 square degrees.\n",
      "VICS82 has a total area of 81.28280282152015 square degrees.\n",
      "ALLWISE has a total area of 1278.3122503407403 square degrees.\n",
      "SHELA has a total area of 35.20443422764652 square degrees.\n",
      "CFHTLS has a total area of 24.77801385583866 square degrees.\n",
      "SDWFS has a total area of 11.278008357525055 square degrees.\n",
      "UKIDSS-LAS has a total area of 610.9795457873166 square degrees.\n",
      "UKIDSS-UDS has a total area of 0.8821189313071469 square degrees.\n",
      "CFHTLenS has a total area of 21.352605685185562 square degrees.\n",
      "UHS has a total area of 67.70609791736013 square degrees.\n",
      "GOODS-ACS has a total area of 0.1116223665109334 square degrees.\n",
      "VIPERS-MLS has a total area of 14.760585211531156 square degrees.\n",
      "SEIP has a total area of 117.27489446425253 square degrees.\n",
      "GAIA has a total area of 1123.9371343428127 square degrees.\n",
      "2MASS-extended-sources has a total area of 1582.9078148682606 square degrees.\n",
      "VISTA-VIDEO has a total area of 13.91473458471678 square degrees.\n",
      "SpARCS has a total area of 33.18570351655756 square degrees.\n",
      "2MASS-point-sources has a total area of 1309.4816820143103 square degrees.\n",
      "CANDELS-UDS has a total area of 0.06024226847951246 square degrees.\n",
      "IBIS has a total area of 10.05431166582557 square degrees.\n",
      "IRAC-EGS has a total area of 0.521741075224349 square degrees.\n",
      "DataFusion-Spitzer has a total area of 65.97389002342037 square degrees.\n",
      "NDWFS has a total area of 9.67431409135191 square degrees.\n",
      "DES has a total area of 599.2392702267651 square degrees.\n",
      "Ultradeep-Ks-GOODS-N has a total area of 0.38624719756422105 square degrees.\n",
      "Bootes_Brown has a total area of 9.632615786468984 square degrees.\n",
      "SCUBA2-Duivenvoorden2018 has a total area of 0.0 square degrees.\n",
      "GALEX-GCAT has a total area of 991.9983701456763 square degrees.\n",
      "SPLASH-SXDF has a total area of 4.351786727781925 square degrees.\n",
      "SpIES has a total area of 74.73319782261152 square degrees.\n",
      "CANDELS-EGS has a total area of 0.06224009881174119 square degrees.\n",
      "COMBO-17 has a total area of 0.2776471897610183 square degrees.\n",
      "DEEP2 has a total area of 2.45845828985439 square degrees.\n",
      "VISTA-VHS has a total area of 435.2262108948157 square degrees.\n",
      "zBootes has a total area of 7.308575619480443 square degrees.\n",
      "SpUDS has a total area of 0.8118362847477154 square degrees.\n",
      "Fireworks has a total area of 0.05307056985099908 square degrees.\n",
      "SDSS-S82 has a total area of 114.7848807004327 square degrees.\n",
      "VISTA-VIDEO-private has a total area of 13.917449584911855 square degrees.\n",
      "ATLAS has a total area of 309.3813414751648 square degrees.\n",
      "LegacySurvey has a total area of 91.75860546102722 square degrees.\n",
      "SXDS has a total area of 1.2775868842508853 square degrees.\n",
      "SMUVS has a total area of 1.0457361128748022 square degrees.\n",
      "RCSLenS has a total area of 178.18269657649105 square degrees.\n",
      "UKIDSS-DXS_DR10plus has a total area of 22.7094910657003 square degrees.\n",
      "KPNO-FLS has a total area of 9.248417645655767 square degrees.\n",
      "IAC_Stripe82_Legacy_Project has a total area of 273.8531562808596 square degrees.\n",
      "CANDELS-GOODS-N has a total area of 0.0527632113383485 square degrees.\n",
      "SIMES has a total area of 6.9864638982226435 square degrees.\n",
      "DECaLS has a total area of 673.236446864416 square degrees.\n",
      "CANDELS-3D-HST has a total area of 0.29050502087356733 square degrees.\n",
      "PanSTARRS1-3SS has a total area of 927.6547096733545 square degrees.\n",
      "VISTA-VIKING has a total area of 441.77991400722635 square degrees.\n",
      "ESIS-VOICE has a total area of 5.111167159703942 square degrees.\n",
      "KIDS has a total area of 270.4992601908166 square degrees.\n",
      "CFHT-WIRDS has a total area of 2.2855179000696664 square degrees.\n",
      "SDSS-DR13 has a total area of 659.0979552824897 square degrees.\n",
      "Hawaii-HDFN has a total area of 0.21740492128150585 square degrees.\n",
      "AKARI-NEP-OptNIR has a total area of 1.0663291332223905 square degrees.\n",
      "INTWFC has a total area of 42.361584553227786 square degrees.\n",
      "HSC has a total area of 85.43583104445469 square degrees.\n",
      "CANDELS-GOODS-S has a total area of 0.05071415458734467 square degrees.\n",
      "COSMOS2015 has a total area of 2.5350930123419326 square degrees.\n",
      "AEGIS has a total area of 0.691556653463791 square degrees.\n"
     ]
    }
   ],
   "source": [
    "for survey in surveys:\n",
    "    moc_list = glob.glob('dmu0_{}/data/*_MOC.fits'.format(survey))\n",
    "    survey_moc = MOC()\n",
    "    for moc in moc_list:\n",
    "        survey_moc =survey_moc + MOC(filename=moc)\n",
    "    print(\"{} has a total area of {} square degrees.\".format(survey, survey_moc.area_sq_deg))\n",
    "    survey_moc.write('./dmu0_{}/survey_coverage_MOC.fits'.format(survey), overwrite=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "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.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
