{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Making the red SPIRE catalogue\n",
    "\n",
    "![HELP LOGO](https://avatars1.githubusercontent.com/u/7880370?s=100&v=4>)\n",
    "\n",
    "\n",
    "### The method we used is decsribed in Asboth et al. 2016. We recommend the user to read this paper before using the data products.\n",
    "### Our method creates a 6 arcsec 500um map by using bicubic interpolation. Than a D-map is created with D  = 0.92M500 − 0.392M250, with M500 the 500um map and M250 the 250um map.\n",
    "### The D-map is created in the same way as Asboth et al. 2016, and we select all sources with a 3sigma detection in the D-map. We extract the flux density of the sources by using the same method as used for the standart blind catalogue. \n",
    "\n",
    "### The data product created is: \"name_field\"_D_MF_cat.fits, and contains all the 3sigma detecion in the D-map, therfore this catalogue is very complete, but also has a very low reliability.\n",
    "\n",
    "### The RED SPIRE sources are validated with the 'red_validation.ipynb' notebook, which contains cuts to find reliable 500um riser candidates. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from astropy.io import fits\n",
    "from astropy.table import Table\n",
    "import os\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "from astropy.wcs import WCS\n",
    "from matplotlib.patches import Ellipse\n",
    "from astropy.coordinates import SkyCoord\n",
    "from astropy import units as u\n",
    "%matplotlib inline  \n",
    "from reproject import reproject_interp\n",
    "from reproject import reproject_exact\n",
    "import sys\n",
    "sys.path.append('../') # location of func_make_cat.py\n",
    "import func_make_cat as fc\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "all_names =  ['GAMA-09_SPIRE','GAMA-12_SPIRE','GAMA-15_SPIRE','HATLAS-NGP_SPIRE','HATLAS-SGP_SPIRE','SSDF_SPIRE',\\\n",
    "              'AKARI-SEP_SPIRE','Bootes_SPIRE','CDFS-SWIRE_SPIRE','COSMOS_SPIRE','EGS_SPIRE',\\\n",
    "              'ELAIS-N1_SPIRE','ELAIS-N2_SPIRE','ELAIS-S1_SPIRE','HDF-N_SPIRE','Lockman-SWIRE_SPIRE','SA13_SPIRE',\\\n",
    "              'SPIRE-NEP_SPIRE','xFLS_SPIRE','XMM-13hr_SPIRE','XMM-LSS_SPIRE','AKARI-NEP_SPIRE']\n",
    "all_names = ['EGS_SPIRE']\n",
    "\n",
    "band = ['250','350','500']\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "EGS_SPIRE250_v1.0.fits\n"
     ]
    }
   ],
   "source": [
    "for j in range(np.size(all_names)):  # loops over the HELP fields\n",
    "    loc = '../../dmu19/dmu19_HELP-SPIRE-maps/data/' # location of help fields\n",
    "\n",
    "    print(all_names[j]+band[0]+'_v1.0.fits')\n",
    "    name = all_names[j]+band[0]+'_v1.0.fits'\n",
    "    hdulist250 = fits.open(loc+name)\n",
    "    \n",
    "    name = all_names[j]+band[1]+'_v1.0.fits'\n",
    "    hdulist350 = fits.open(loc+name)\n",
    "\n",
    "    name = all_names[j]+band[2]+'_v1.0.fits'\n",
    "    hdulist500 = fits.open(loc+name)\n",
    "\n",
    "    # https://reproject.readthedocs.io/en/stable/ for info about the reproject function\n",
    "    # order 0 pics the nearest pixel from the projected header\n",
    "    # we use the order 0 reproject map to find the masked pixels (NaN's), the order 2 interplolation requiers\n",
    "    # the NaN's to ber removed. \n",
    "    new_image0, footprint0 = reproject_interp(hdulist500[\"MFILT\"], hdulist250['IMAGE'].header, order = 0) \n",
    "\n",
    "    # NaN pixels in the orignal 500um \n",
    "    # These locations are needed as the Bicubic interpolation needs NaN's to be set to 0\n",
    "    bad = np.isnan(hdulist500[\"MFILT\"].data)\n",
    "    hdulist500[\"MFILT\"].data[bad] = 0 \n",
    "\n",
    "    # Bicubic interplolation of the 500um map to the 250um map fits header and pixel size\n",
    "    # Note that Asboth et al. used 500um maps which where made with 6 arcsec resolution, where we use\n",
    "    # a bicubic interplotations scheme to got from the 500um resolution to 6 arcsec\n",
    "    new_image2, footprint2 = reproject_interp(hdulist500[\"MFILT\"], hdulist250['IMAGE'].header, order = 2) \n",
    "    bad = np.isnan(new_image0)\n",
    "    new_image2[bad] = np.nan\n",
    "\n",
    "    # uses a matched filter on the 500um and 250um map and calculated D\n",
    "    new_D = fc.do_filtering(hdulist250,hdulist500,new_image2)\n",
    "    \n",
    "    new_image2 -= np.nanmean(new_image2) # make sure the new image is mean substracted\n",
    "    Dhdu = fits.ImageHDU(header=hdulist250['IMAGE'].header,data=new_image2)\n",
    "    Dhdu.writeto('data/'+all_names[j]+'_map_500_6ac.fits') \n",
    "\n",
    "    Dhdu = fits.ImageHDU(header=hdulist250['IMAGE'].header,data=new_D)\n",
    "    Dhdu.writeto('data/'+all_names[j]+'_D_map.fits') \n",
    "    Dhdu = fits.open('data/'+all_names[j]+'_D_map.fits')\n",
    "    # select 3 sigma peaks\n",
    "    dmin = 3*np.nanstd(Dhdu[1].data)\n",
    "    dp, rap, decp, xp, yp = fc.find_peak_red(Dhdu,dmin)\n",
    "    \n",
    "\n",
    "    # for the AKARI-NEP a region file has to be used due to the very noisy edges \n",
    "    if all_names[j] == 'AKARI-NEP_SPIRE':\n",
    "        import pyregion\n",
    "        x_all = np.arange(0,np.shape(Dhdu[1].data)[0])\n",
    "        y_all = np.arange(0,np.shape(Dhdu[1].data)[1])\n",
    "        x_mat = np.tile(x_all,np.size(y_all))\n",
    "        y_mat = np.repeat(y_all,np.size(x_all))\n",
    "    \n",
    "        region_name = \"AKARI-NEP.reg\"\n",
    "        r = pyregion.open(region_name)\n",
    "        r250 = r.get_filter(hdulist250[1].header)\n",
    "        \n",
    "        mask = r250.inside(y_mat,x_mat)\n",
    "        Dhdu[1].data[x_mat[~mask],y_mat[~mask]] = np.nan\n",
    "        Dhdu.writeto('data/'+all_names[j]+'_D_map3.fits') \n",
    "\n",
    "        dmin = 3*np.nanstd(Dhdu[1].data)\n",
    "        dp, rap, decp, xp, yp = np.array(fc.find_peak_red(Dhdu,dmin))        \n",
    "\n",
    "\n",
    "\n",
    "    w1 = WCS(hdulist250[\"NEBFILT\"].header) \n",
    "    w2 = WCS(hdulist350[\"NEBFILT\"].header)\n",
    "    w3 = WCS(hdulist500[\"MFILT\"].header)    \n",
    "    \n",
    "    x_250, y_250 = np.round(w1.wcs_world2pix(rap,  decp, 0)).astype(int)\n",
    "    x_350, y_350 = np.round(w2.wcs_world2pix(rap,  decp, 0)).astype(int)\n",
    "    x_500, y_500 = np.round(w3.wcs_world2pix(rap,  decp, 0)).astype(int)\n",
    "    # pixel flux density at peak location\n",
    "    S250 = hdulist250[\"NEBFILT\"].data[y_250,x_250]\n",
    "    E250 = hdulist250[\"ERROR\"].data[y_250,x_250]\n",
    "    S350 = hdulist350[\"NEBFILT\"].data[y_350,x_350]\n",
    "    E350 = hdulist350[\"ERROR\"].data[y_350,x_350]\n",
    "    S500 = hdulist500[\"NEBFILT\"].data[y_500,x_500]\n",
    "    E500 = hdulist500[\"ERROR\"].data[y_500,x_500]\n",
    "\n",
    "    hdu = fits.BinTableHDU.from_columns(\\\n",
    "         [fits.Column(name='RA', array=rap, format ='F'),\n",
    "         fits.Column(name='Dec', array=decp, format='F'),\n",
    "         fits.Column(name='F_RED_pix_SPIRE_250', array=S250, format ='F'),\n",
    "         fits.Column(name='FErr_RED_pix_SPIRE_250', array=E250, format ='F'),          \n",
    "         fits.Column(name='F_RED_pix_SPIRE_350', array=S350, format ='F'),\n",
    "         fits.Column(name='FErr_RED_pix_SPIRE_350', array=E350, format ='F'),\n",
    "         fits.Column(name='F_RED_pix_SPIRE_500', array=S500, format ='F'),\n",
    "         fits.Column(name='FErr_RED_pix_SPIRE_500', array=E500, format ='F')         \n",
    "         ])\n",
    "    hdu.writeto('data/'+all_names[j]+'_D_cat.fits')\n",
    "    \n",
    "    \n",
    "    hdulist250.close()\n",
    "    hdulist350.close()\n",
    "    hdulist500.close()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "../../dmu19/dmu19_HELP-SPIRE-maps/data/EGS_SPIRE250_v1.0.fits\n",
      "(0.0, '%')\n",
      "(0.10649627263045794, '%')\n",
      "(0.21299254526091588, '%')\n",
      "(0.3194888178913738, '%')\n",
      "(0.42598509052183176, '%')\n",
      "(0.5324813631522897, '%')\n",
      "(0.6389776357827476, '%')\n",
      "(0.7454739084132056, '%')\n",
      "(0.8519701810436635, '%')\n",
      "(0.9584664536741214, '%')\n",
      "(1.0649627263045793, '%')\n",
      "(1.1714589989350372, '%')\n",
      "(1.2779552715654952, '%')\n",
      "(1.384451544195953, '%')\n",
      "(1.4909478168264112, '%')\n",
      "(1.5974440894568689, '%')\n",
      "(1.703940362087327, '%')\n",
      "(1.810436634717785, '%')\n",
      "(1.9169329073482428, '%')\n",
      "(2.023429179978701, '%')\n",
      "(2.1299254526091587, '%')\n",
      "(2.2364217252396164, '%')\n",
      "(2.3429179978700745, '%')\n",
      "(2.4494142705005326, '%')\n",
      "(2.5559105431309903, '%')\n",
      "(2.6624068157614484, '%')\n",
      "(2.768903088391906, '%')\n",
      "(2.8753993610223643, '%')\n",
      "(2.9818956336528224, '%')\n",
      "(3.08839190628328, '%')\n",
      "(3.1948881789137378, '%')\n",
      "(3.301384451544196, '%')\n",
      "(3.407880724174654, '%')\n",
      "(3.5143769968051117, '%')\n",
      "(3.62087326943557, '%')\n",
      "(3.727369542066028, '%')\n",
      "(3.8338658146964857, '%')\n",
      "(3.940362087326944, '%')\n",
      "(4.046858359957402, '%')\n",
      "(4.15335463258786, '%')\n",
      "(4.259850905218317, '%')\n",
      "(4.366347177848776, '%')\n",
      "(4.472843450479233, '%')\n",
      "(4.579339723109691, '%')\n",
      "(4.685835995740149, '%')\n",
      "(4.792332268370607, '%')\n",
      "(4.898828541001065, '%')\n",
      "(5.005324813631523, '%')\n",
      "(5.111821086261981, '%')\n",
      "(5.218317358892439, '%')\n",
      "(5.324813631522897, '%')\n",
      "(5.431309904153355, '%')\n",
      "(5.537806176783812, '%')\n",
      "(5.644302449414271, '%')\n",
      "(5.7507987220447285, '%')\n",
      "(5.857294994675186, '%')\n",
      "(5.963791267305645, '%')\n",
      "(6.070287539936102, '%')\n",
      "(6.17678381256656, '%')\n",
      "(6.283280085197019, '%')\n",
      "(6.3897763578274756, '%')\n",
      "(6.496272630457935, '%')\n",
      "(6.602768903088392, '%')\n",
      "(6.7092651757188495, '%')\n",
      "(6.815761448349308, '%')\n",
      "(6.922257720979766, '%')\n",
      "(7.0287539936102235, '%')\n",
      "(7.135250266240682, '%')\n",
      "(7.24174653887114, '%')\n",
      "(7.348242811501597, '%')\n",
      "(7.454739084132056, '%')\n",
      "(7.561235356762514, '%')\n",
      "(7.667731629392971, '%')\n",
      "(7.77422790202343, '%')\n",
      "(7.880724174653888, '%')\n",
      "(7.987220447284344, '%')\n",
      "(8.093716719914804, '%')\n",
      "(8.20021299254526, '%')\n",
      "(8.30670926517572, '%')\n",
      "(8.413205537806178, '%')\n",
      "(8.519701810436635, '%')\n",
      "(8.626198083067091, '%')\n",
      "(8.732694355697552, '%')\n",
      "(8.839190628328009, '%')\n",
      "(8.945686900958465, '%')\n",
      "(9.052183173588926, '%')\n",
      "(9.158679446219383, '%')\n",
      "(9.26517571884984, '%')\n",
      "(9.371671991480298, '%')\n",
      "(9.478168264110757, '%')\n",
      "(9.584664536741213, '%')\n",
      "(9.691160809371672, '%')\n",
      "(9.79765708200213, '%')\n",
      "(9.904153354632587, '%')\n",
      "(10.010649627263046, '%')\n",
      "(10.117145899893504, '%')\n",
      "(10.223642172523961, '%')\n",
      "(10.33013844515442, '%')\n",
      "(10.436634717784878, '%')\n",
      "(10.543130990415335, '%')\n",
      "(10.649627263045794, '%')\n",
      "(10.75612353567625, '%')\n",
      "(10.86261980830671, '%')\n",
      "(10.969116080937168, '%')\n",
      "(11.075612353567625, '%')\n",
      "(11.182108626198083, '%')\n",
      "(11.288604898828542, '%')\n",
      "(11.395101171458998, '%')\n",
      "(11.501597444089457, '%')\n",
      "(11.608093716719916, '%')\n",
      "(11.714589989350372, '%')\n",
      "(11.821086261980831, '%')\n",
      "(11.92758253461129, '%')\n",
      "(12.034078807241746, '%')\n",
      "(12.140575079872203, '%')\n",
      "(12.247071352502664, '%')\n",
      "(12.35356762513312, '%')\n",
      "(12.460063897763577, '%')\n",
      "(12.566560170394037, '%')\n",
      "(12.673056443024494, '%')\n",
      "(12.779552715654951, '%')\n",
      "(12.88604898828541, '%')\n",
      "(12.99254526091587, '%')\n",
      "(13.099041533546327, '%')\n",
      "(13.205537806176784, '%')\n",
      "(13.312034078807242, '%')\n",
      "(13.418530351437699, '%')\n",
      "(13.525026624068156, '%')\n",
      "(13.631522896698616, '%')\n",
      "(13.738019169329075, '%')\n",
      "(13.844515441959532, '%')\n",
      "(13.951011714589988, '%')\n",
      "(14.057507987220447, '%')\n",
      "(14.164004259850904, '%')\n",
      "(14.270500532481364, '%')\n",
      "(14.376996805111823, '%')\n",
      "(14.48349307774228, '%')\n",
      "(14.589989350372736, '%')\n",
      "(14.696485623003195, '%')\n",
      "(14.802981895633652, '%')\n",
      "(14.909478168264112, '%')\n",
      "(15.015974440894569, '%')\n",
      "(15.122470713525027, '%')\n",
      "(15.228966986155484, '%')\n",
      "(15.335463258785943, '%')\n",
      "(15.4419595314164, '%')\n",
      "(15.54845580404686, '%')\n",
      "(15.654952076677317, '%')\n",
      "(15.761448349307775, '%')\n",
      "(15.867944621938232, '%')\n",
      "(15.974440894568689, '%')\n",
      "(16.080937167199146, '%')\n",
      "(16.187433439829608, '%')\n",
      "(16.293929712460063, '%')\n",
      "(16.40042598509052, '%')\n",
      "(16.50692225772098, '%')\n",
      "(16.61341853035144, '%')\n",
      "(16.719914802981894, '%')\n",
      "(16.826411075612356, '%')\n",
      "(16.93290734824281, '%')\n",
      "(17.03940362087327, '%')\n",
      "(17.145899893503728, '%')\n",
      "(17.252396166134183, '%')\n",
      "(17.35889243876464, '%')\n",
      "(17.465388711395104, '%')\n",
      "(17.57188498402556, '%')\n",
      "(17.678381256656017, '%')\n",
      "(17.784877529286476, '%')\n",
      "(17.89137380191693, '%')\n",
      "(17.99787007454739, '%')\n",
      "(18.10436634717785, '%')\n",
      "(18.210862619808307, '%')\n",
      "(18.317358892438765, '%')\n",
      "(18.423855165069224, '%')\n",
      "(18.53035143769968, '%')\n",
      "(18.636847710330137, '%')\n",
      "(18.743343982960596, '%')\n",
      "(18.849840255591054, '%')\n",
      "(18.956336528221513, '%')\n",
      "(19.06283280085197, '%')\n",
      "(19.169329073482427, '%')\n",
      "(19.275825346112885, '%')\n",
      "(19.382321618743344, '%')\n",
      "(19.488817891373802, '%')\n",
      "(19.59531416400426, '%')\n",
      "(19.701810436634716, '%')\n",
      "(19.808306709265175, '%')\n",
      "(19.914802981895633, '%')\n",
      "(20.02129925452609, '%')\n",
      "(20.12779552715655, '%')\n",
      "(20.23429179978701, '%')\n",
      "(20.340788072417464, '%')\n",
      "(20.447284345047922, '%')\n",
      "(20.55378061767838, '%')\n",
      "(20.66027689030884, '%')\n",
      "(20.766773162939298, '%')\n",
      "(20.873269435569757, '%')\n",
      "(20.979765708200212, '%')\n",
      "(21.08626198083067, '%')\n",
      "(21.19275825346113, '%')\n",
      "(21.299254526091588, '%')\n",
      "(21.405750798722046, '%')\n",
      "(21.5122470713525, '%')\n",
      "(21.61874334398296, '%')\n",
      "(21.72523961661342, '%')\n",
      "(21.831735889243873, '%')\n",
      "(21.938232161874335, '%')\n",
      "(22.044728434504794, '%')\n",
      "(22.15122470713525, '%')\n",
      "(22.257720979765708, '%')\n",
      "(22.364217252396166, '%')\n",
      "(22.470713525026625, '%')\n",
      "(22.577209797657083, '%')\n",
      "(22.683706070287542, '%')\n",
      "(22.790202342917997, '%')\n",
      "(22.896698615548456, '%')\n",
      "(23.003194888178914, '%')\n",
      "(23.109691160809373, '%')\n",
      "(23.21618743343983, '%')\n",
      "(23.322683706070286, '%')\n",
      "(23.429179978700745, '%')\n",
      "(23.535676251331203, '%')\n",
      "(23.642172523961662, '%')\n",
      "(23.74866879659212, '%')\n",
      "(23.85516506922258, '%')\n",
      "(23.961661341853034, '%')\n",
      "(24.068157614483493, '%')\n",
      "(24.17465388711395, '%')\n",
      "(24.281150159744406, '%')\n",
      "(24.38764643237487, '%')\n",
      "(24.494142705005327, '%')\n",
      "(24.600638977635782, '%')\n",
      "(24.70713525026624, '%')\n",
      "(24.8136315228967, '%')\n",
      "(24.920127795527154, '%')\n",
      "(25.026624068157616, '%')\n",
      "(25.133120340788075, '%')\n",
      "(25.23961661341853, '%')\n",
      "(25.34611288604899, '%')\n",
      "(25.452609158679447, '%')\n",
      "(25.559105431309902, '%')\n",
      "(25.66560170394036, '%')\n",
      "(25.77209797657082, '%')\n",
      "(25.878594249201274, '%')\n",
      "(25.98509052183174, '%')\n",
      "(26.091586794462195, '%')\n",
      "(26.198083067092654, '%')\n",
      "(26.304579339723112, '%')\n",
      "(26.411075612353567, '%')\n",
      "(26.517571884984026, '%')\n",
      "(26.624068157614484, '%')\n",
      "(26.73056443024494, '%')\n",
      "(26.837060702875398, '%')\n",
      "(26.943556975505857, '%')\n",
      "(27.05005324813631, '%')\n",
      "(27.15654952076677, '%')\n",
      "(27.263045793397232, '%')\n",
      "(27.36954206602769, '%')\n",
      "(27.47603833865815, '%')\n",
      "(27.582534611288605, '%')\n",
      "(27.689030883919063, '%')\n",
      "(27.79552715654952, '%')\n",
      "(27.902023429179977, '%')\n",
      "(28.008519701810435, '%')\n",
      "(28.115015974440894, '%')\n",
      "(28.221512247071352, '%')\n",
      "(28.328008519701807, '%')\n",
      "(28.434504792332266, '%')\n",
      "(28.541001064962728, '%')\n",
      "(28.647497337593187, '%')\n",
      "(28.753993610223645, '%')\n",
      "(28.8604898828541, '%')\n",
      "(28.96698615548456, '%')\n",
      "(29.073482428115017, '%')\n",
      "(29.179978700745473, '%')\n",
      "(29.28647497337593, '%')\n",
      "(29.39297124600639, '%')\n",
      "(29.499467518636845, '%')\n",
      "(29.605963791267303, '%')\n",
      "(29.712460063897762, '%')\n",
      "(29.818956336528224, '%')\n",
      "(29.925452609158683, '%')\n",
      "(30.031948881789138, '%')\n",
      "(30.138445154419596, '%')\n",
      "(30.244941427050055, '%')\n",
      "(30.35143769968051, '%')\n",
      "(30.45793397231097, '%')\n",
      "(30.564430244941427, '%')\n",
      "(30.670926517571885, '%')\n",
      "(30.77742279020234, '%')\n",
      "(30.8839190628328, '%')\n",
      "(30.990415335463258, '%')\n",
      "(31.09691160809372, '%')\n",
      "(31.20340788072418, '%')\n",
      "(31.309904153354633, '%')\n",
      "(31.416400425985092, '%')\n",
      "(31.52289669861555, '%')\n",
      "(31.629392971246006, '%')\n",
      "(31.735889243876464, '%')\n",
      "(31.842385516506923, '%')\n",
      "(31.948881789137378, '%')\n",
      "(32.05537806176784, '%')\n",
      "(32.16187433439829, '%')\n",
      "(32.26837060702875, '%')\n",
      "(32.374866879659216, '%')\n",
      "(32.481363152289674, '%')\n",
      "(32.587859424920126, '%')\n",
      "(32.694355697550584, '%')\n",
      "(32.80085197018104, '%')\n",
      "(32.9073482428115, '%')\n",
      "(33.01384451544196, '%')\n",
      "(33.12034078807242, '%')\n",
      "(33.22683706070288, '%')\n",
      "(33.33333333333333, '%')\n",
      "(33.43982960596379, '%')\n",
      "(33.54632587859425, '%')\n",
      "(33.65282215122471, '%')\n",
      "(33.75931842385517, '%')\n",
      "(33.86581469648562, '%')\n",
      "(33.97231096911608, '%')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(34.07880724174654, '%')\n",
      "(34.185303514377, '%')\n",
      "(34.291799787007456, '%')\n",
      "(34.398296059637914, '%')\n",
      "(34.504792332268366, '%')\n",
      "(34.611288604898824, '%')\n",
      "(34.71778487752928, '%')\n",
      "(34.82428115015975, '%')\n",
      "(34.93077742279021, '%')\n",
      "(35.03727369542066, '%')\n",
      "(35.14376996805112, '%')\n",
      "(35.250266240681576, '%')\n",
      "(35.356762513312034, '%')\n",
      "(35.46325878594249, '%')\n",
      "(35.56975505857295, '%')\n",
      "(35.67625133120341, '%')\n",
      "(35.78274760383386, '%')\n",
      "(35.88924387646432, '%')\n",
      "(35.99574014909478, '%')\n",
      "(36.102236421725244, '%')\n",
      "(36.2087326943557, '%')\n",
      "(36.315228966986155, '%')\n",
      "(36.42172523961661, '%')\n",
      "(36.52822151224707, '%')\n",
      "(36.63471778487753, '%')\n",
      "(36.74121405750799, '%')\n",
      "(36.84771033013845, '%')\n",
      "(36.9542066027689, '%')\n",
      "(37.06070287539936, '%')\n",
      "(37.167199148029816, '%')\n",
      "(37.273695420660275, '%')\n",
      "(37.38019169329074, '%')\n",
      "(37.48668796592119, '%')\n",
      "(37.59318423855165, '%')\n",
      "(37.69968051118211, '%')\n",
      "(37.80617678381257, '%')\n",
      "(37.912673056443026, '%')\n",
      "(38.019169329073485, '%')\n",
      "(38.12566560170394, '%')\n",
      "(38.232161874334395, '%')\n",
      "(38.33865814696485, '%')\n",
      "(38.44515441959531, '%')\n",
      "(38.55165069222577, '%')\n",
      "(38.65814696485623, '%')\n",
      "(38.76464323748669, '%')\n",
      "(38.871139510117146, '%')\n",
      "(38.977635782747605, '%')\n",
      "(39.08413205537806, '%')\n",
      "(39.19062832800852, '%')\n",
      "(39.29712460063898, '%')\n",
      "(39.40362087326943, '%')\n",
      "(39.51011714589989, '%')\n",
      "(39.61661341853035, '%')\n",
      "(39.72310969116081, '%')\n",
      "(39.829605963791266, '%')\n",
      "(39.936102236421725, '%')\n",
      "(40.04259850905218, '%')\n",
      "(40.14909478168264, '%')\n",
      "(40.2555910543131, '%')\n",
      "(40.36208732694356, '%')\n",
      "(40.46858359957402, '%')\n",
      "(40.57507987220447, '%')\n",
      "(40.68157614483493, '%')\n",
      "(40.788072417465386, '%')\n",
      "(40.894568690095845, '%')\n",
      "(41.0010649627263, '%')\n",
      "(41.10756123535676, '%')\n",
      "(41.21405750798722, '%')\n",
      "(41.32055378061768, '%')\n",
      "(41.42705005324814, '%')\n",
      "(41.533546325878596, '%')\n",
      "(41.640042598509055, '%')\n",
      "(41.746538871139514, '%')\n",
      "(41.853035143769965, '%')\n",
      "(41.959531416400424, '%')\n",
      "(42.06602768903088, '%')\n",
      "(42.17252396166134, '%')\n",
      "(42.2790202342918, '%')\n",
      "(42.38551650692226, '%')\n",
      "(42.49201277955272, '%')\n",
      "(42.598509052183175, '%')\n",
      "(42.705005324813634, '%')\n",
      "(42.81150159744409, '%')\n",
      "(42.91799787007455, '%')\n",
      "(43.024494142705, '%')\n",
      "(43.13099041533546, '%')\n",
      "(43.23748668796592, '%')\n",
      "(43.34398296059638, '%')\n",
      "(43.45047923322684, '%')\n",
      "(43.556975505857295, '%')\n",
      "(43.66347177848775, '%')\n",
      "(43.76996805111821, '%')\n",
      "(43.87646432374867, '%')\n",
      "(43.98296059637913, '%')\n",
      "(44.08945686900959, '%')\n",
      "(44.19595314164005, '%')\n",
      "(44.3024494142705, '%')\n",
      "(44.40894568690096, '%')\n",
      "(44.515441959531415, '%')\n",
      "(44.621938232161874, '%')\n",
      "(44.72843450479233, '%')\n",
      "(44.83493077742279, '%')\n",
      "(44.94142705005325, '%')\n",
      "(45.04792332268371, '%')\n",
      "(45.15441959531417, '%')\n",
      "(45.260915867944625, '%')\n",
      "(45.367412140575084, '%')\n",
      "(45.473908413205535, '%')\n",
      "(45.580404685835994, '%')\n",
      "(45.68690095846645, '%')\n",
      "(45.79339723109691, '%')\n",
      "(45.89989350372737, '%')\n",
      "(46.00638977635783, '%')\n",
      "(46.11288604898828, '%')\n",
      "(46.219382321618745, '%')\n",
      "(46.325878594249204, '%')\n",
      "(46.43237486687966, '%')\n",
      "(46.53887113951012, '%')\n",
      "(46.64536741214057, '%')\n",
      "(46.75186368477103, '%')\n",
      "(46.85835995740149, '%')\n",
      "(46.96485623003195, '%')\n",
      "(47.07135250266241, '%')\n",
      "(47.177848775292865, '%')\n",
      "(47.284345047923324, '%')\n",
      "(47.390841320553776, '%')\n",
      "(47.49733759318424, '%')\n",
      "(47.6038338658147, '%')\n",
      "(47.71033013844516, '%')\n",
      "(47.81682641107562, '%')\n",
      "(47.92332268370607, '%')\n",
      "(48.02981895633653, '%')\n",
      "(48.136315228966986, '%')\n",
      "(48.242811501597444, '%')\n",
      "(48.3493077742279, '%')\n",
      "(48.45580404685836, '%')\n",
      "(48.56230031948881, '%')\n",
      "(48.66879659211927, '%')\n",
      "(48.77529286474974, '%')\n",
      "(48.881789137380196, '%')\n",
      "(48.988285410010654, '%')\n",
      "(49.094781682641106, '%')\n",
      "(49.201277955271564, '%')\n",
      "(49.30777422790202, '%')\n",
      "(49.41427050053248, '%')\n",
      "(49.52076677316294, '%')\n",
      "(49.6272630457934, '%')\n",
      "(49.73375931842385, '%')\n",
      "(49.84025559105431, '%')\n",
      "(49.94675186368477, '%')\n",
      "(50.05324813631523, '%')\n",
      "(50.159744408945684, '%')\n",
      "(50.26624068157615, '%')\n",
      "(50.3727369542066, '%')\n",
      "(50.47923322683706, '%')\n",
      "(50.58572949946751, '%')\n",
      "(50.69222577209798, '%')\n",
      "(50.798722044728436, '%')\n",
      "(50.905218317358894, '%')\n",
      "(51.01171458998935, '%')\n",
      "(51.118210862619804, '%')\n",
      "(51.22470713525027, '%')\n",
      "(51.33120340788072, '%')\n",
      "(51.43769968051119, '%')\n",
      "(51.54419595314164, '%')\n",
      "(51.6506922257721, '%')\n",
      "(51.75718849840255, '%')\n",
      "(51.863684771033014, '%')\n",
      "(51.97018104366348, '%')\n",
      "(52.07667731629393, '%')\n",
      "(52.18317358892439, '%')\n",
      "(52.28966986155484, '%')\n",
      "(52.39616613418531, '%')\n",
      "(52.50266240681576, '%')\n",
      "(52.609158679446224, '%')\n",
      "(52.715654952076676, '%')\n",
      "(52.822151224707135, '%')\n",
      "(52.928647497337586, '%')\n",
      "(53.03514376996805, '%')\n",
      "(53.1416400425985, '%')\n",
      "(53.24813631522897, '%')\n",
      "(53.35463258785943, '%')\n",
      "(53.46112886048988, '%')\n",
      "(53.567625133120345, '%')\n",
      "(53.674121405750796, '%')\n",
      "(53.78061767838126, '%')\n",
      "(53.88711395101171, '%')\n",
      "(53.99361022364217, '%')\n",
      "(54.10010649627262, '%')\n",
      "(54.20660276890309, '%')\n",
      "(54.31309904153354, '%')\n",
      "(54.419595314164006, '%')\n",
      "(54.526091586794465, '%')\n",
      "(54.632587859424916, '%')\n",
      "(54.73908413205538, '%')\n",
      "(54.84558040468583, '%')\n",
      "(54.9520766773163, '%')\n",
      "(55.05857294994675, '%')\n",
      "(55.16506922257721, '%')\n",
      "(55.27156549520767, '%')\n",
      "(55.378061767838126, '%')\n",
      "(55.48455804046858, '%')\n",
      "(55.59105431309904, '%')\n",
      "(55.6975505857295, '%')\n",
      "(55.80404685835995, '%')\n",
      "(55.91054313099042, '%')\n",
      "(56.01703940362087, '%')\n",
      "(56.123535676251336, '%')\n",
      "(56.23003194888179, '%')\n",
      "(56.33652822151225, '%')\n",
      "(56.443024494142705, '%')\n",
      "(56.54952076677316, '%')\n",
      "(56.656017039403615, '%')\n",
      "(56.76251331203408, '%')\n",
      "(56.86900958466453, '%')\n",
      "(56.975505857295, '%')\n",
      "(57.082002129925456, '%')\n",
      "(57.18849840255591, '%')\n",
      "(57.29499467518637, '%')\n",
      "(57.401490947816825, '%')\n",
      "(57.50798722044729, '%')\n",
      "(57.61448349307774, '%')\n",
      "(57.7209797657082, '%')\n",
      "(57.82747603833865, '%')\n",
      "(57.93397231096912, '%')\n",
      "(58.04046858359957, '%')\n",
      "(58.146964856230035, '%')\n",
      "(58.25346112886049, '%')\n",
      "(58.359957401490945, '%')\n",
      "(58.46645367412141, '%')\n",
      "(58.57294994675186, '%')\n",
      "(58.67944621938233, '%')\n",
      "(58.78594249201278, '%')\n",
      "(58.89243876464324, '%')\n",
      "(58.99893503727369, '%')\n",
      "(59.105431309904155, '%')\n",
      "(59.21192758253461, '%')\n",
      "(59.31842385516507, '%')\n",
      "(59.424920127795524, '%')\n",
      "(59.53141640042598, '%')\n",
      "(59.63791267305645, '%')\n",
      "(59.7444089456869, '%')\n",
      "(59.850905218317365, '%')\n",
      "(59.95740149094782, '%')\n",
      "(60.063897763578275, '%')\n",
      "(60.17039403620873, '%')\n",
      "(60.27689030883919, '%')\n",
      "(60.383386581469644, '%')\n",
      "(60.48988285410011, '%')\n",
      "(60.59637912673056, '%')\n",
      "(60.70287539936102, '%')\n",
      "(60.809371671991485, '%')\n",
      "(60.91586794462194, '%')\n",
      "(61.0223642172524, '%')\n",
      "(61.128860489882854, '%')\n",
      "(61.23535676251331, '%')\n",
      "(61.34185303514377, '%')\n",
      "(61.44834930777423, '%')\n",
      "(61.55484558040468, '%')\n",
      "(61.66134185303515, '%')\n",
      "(61.7678381256656, '%')\n",
      "(61.87433439829606, '%')\n",
      "(61.980830670926515, '%')\n",
      "(62.087326943556974, '%')\n",
      "(62.19382321618744, '%')\n",
      "(62.30031948881789, '%')\n",
      "(62.40681576144836, '%')\n",
      "(62.51331203407881, '%')\n",
      "(62.61980830670927, '%')\n",
      "(62.72630457933972, '%')\n",
      "(62.832800851970184, '%')\n",
      "(62.939297124600635, '%')\n",
      "(63.0457933972311, '%')\n",
      "(63.15228966986155, '%')\n",
      "(63.25878594249201, '%')\n",
      "(63.36528221512248, '%')\n",
      "(63.47177848775293, '%')\n",
      "(63.578274760383394, '%')\n",
      "(63.684771033013845, '%')\n",
      "(63.791267305644304, '%')\n",
      "(63.897763578274756, '%')\n",
      "(64.00425985090521, '%')\n",
      "(64.11075612353568, '%')\n",
      "(64.21725239616613, '%')\n",
      "(64.32374866879658, '%')\n",
      "(64.43024494142705, '%')\n",
      "(64.5367412140575, '%')\n",
      "(64.64323748668797, '%')\n",
      "(64.74973375931843, '%')\n",
      "(64.85623003194888, '%')\n",
      "(64.96272630457935, '%')\n",
      "(65.0692225772098, '%')\n",
      "(65.17571884984025, '%')\n",
      "(65.28221512247072, '%')\n",
      "(65.38871139510117, '%')\n",
      "(65.49520766773162, '%')\n",
      "(65.60170394036209, '%')\n",
      "(65.70820021299254, '%')\n",
      "(65.814696485623, '%')\n",
      "(65.92119275825347, '%')\n",
      "(66.02768903088392, '%')\n",
      "(66.13418530351439, '%')\n",
      "(66.24068157614484, '%')\n",
      "(66.3471778487753, '%')\n",
      "(66.45367412140575, '%')\n",
      "(66.5601703940362, '%')\n",
      "(66.66666666666666, '%')\n",
      "(66.77316293929712, '%')\n",
      "(66.87965921192757, '%')\n",
      "(66.98615548455804, '%')\n",
      "(67.0926517571885, '%')\n",
      "(67.19914802981896, '%')\n",
      "(67.30564430244942, '%')\n",
      "(67.41214057507987, '%')\n",
      "(67.51863684771034, '%')\n",
      "(67.62513312034079, '%')\n",
      "(67.73162939297124, '%')\n",
      "(67.8381256656017, '%')\n",
      "(67.94462193823216, '%')\n",
      "(68.05111821086261, '%')\n",
      "(68.15761448349308, '%')\n",
      "(68.26411075612353, '%')\n",
      "(68.370607028754, '%')\n",
      "(68.47710330138446, '%')\n",
      "(68.58359957401491, '%')\n",
      "(68.69009584664538, '%')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(68.79659211927583, '%')\n",
      "(68.90308839190628, '%')\n",
      "(69.00958466453673, '%')\n",
      "(69.1160809371672, '%')\n",
      "(69.22257720979765, '%')\n",
      "(69.32907348242811, '%')\n",
      "(69.43556975505857, '%')\n",
      "(69.54206602768903, '%')\n",
      "(69.6485623003195, '%')\n",
      "(69.75505857294995, '%')\n",
      "(69.86155484558041, '%')\n",
      "(69.96805111821087, '%')\n",
      "(70.07454739084132, '%')\n",
      "(70.18104366347177, '%')\n",
      "(70.28753993610223, '%')\n",
      "(70.39403620873269, '%')\n",
      "(70.50053248136315, '%')\n",
      "(70.6070287539936, '%')\n",
      "(70.71352502662407, '%')\n",
      "(70.82002129925452, '%')\n",
      "(70.92651757188499, '%')\n",
      "(71.03301384451545, '%')\n",
      "(71.1395101171459, '%')\n",
      "(71.24600638977637, '%')\n",
      "(71.35250266240682, '%')\n",
      "(71.45899893503727, '%')\n",
      "(71.56549520766772, '%')\n",
      "(71.67199148029819, '%')\n",
      "(71.77848775292864, '%')\n",
      "(71.8849840255591, '%')\n",
      "(71.99148029818956, '%')\n",
      "(72.09797657082002, '%')\n",
      "(72.20447284345049, '%')\n",
      "(72.31096911608094, '%')\n",
      "(72.4174653887114, '%')\n",
      "(72.52396166134186, '%')\n",
      "(72.63045793397231, '%')\n",
      "(72.73695420660276, '%')\n",
      "(72.84345047923323, '%')\n",
      "(72.94994675186368, '%')\n",
      "(73.05644302449414, '%')\n",
      "(73.1629392971246, '%')\n",
      "(73.26943556975506, '%')\n",
      "(73.37593184238551, '%')\n",
      "(73.48242811501598, '%')\n",
      "(73.58892438764644, '%')\n",
      "(73.6954206602769, '%')\n",
      "(73.80191693290735, '%')\n",
      "(73.9084132055378, '%')\n",
      "(74.01490947816826, '%')\n",
      "(74.12140575079871, '%')\n",
      "(74.22790202342918, '%')\n",
      "(74.33439829605963, '%')\n",
      "(74.4408945686901, '%')\n",
      "(74.54739084132055, '%')\n",
      "(74.65388711395101, '%')\n",
      "(74.76038338658148, '%')\n",
      "(74.86687965921193, '%')\n",
      "(74.97337593184238, '%')\n",
      "(75.07987220447284, '%')\n",
      "(75.1863684771033, '%')\n",
      "(75.29286474973375, '%')\n",
      "(75.39936102236422, '%')\n",
      "(75.50585729499467, '%')\n",
      "(75.61235356762514, '%')\n",
      "(75.71884984025559, '%')\n",
      "(75.82534611288605, '%')\n",
      "(75.9318423855165, '%')\n",
      "(76.03833865814697, '%')\n",
      "(76.14483493077742, '%')\n",
      "(76.25133120340789, '%')\n",
      "(76.35782747603834, '%')\n",
      "(76.46432374866879, '%')\n",
      "(76.57082002129926, '%')\n",
      "(76.6773162939297, '%')\n",
      "(76.78381256656017, '%')\n",
      "(76.89030883919062, '%')\n",
      "(76.99680511182109, '%')\n",
      "(77.10330138445154, '%')\n",
      "(77.209797657082, '%')\n",
      "(77.31629392971246, '%')\n",
      "(77.42279020234292, '%')\n",
      "(77.52928647497338, '%')\n",
      "(77.63578274760383, '%')\n",
      "(77.74227902023429, '%')\n",
      "(77.84877529286474, '%')\n",
      "(77.95527156549521, '%')\n",
      "(78.06176783812566, '%')\n",
      "(78.16826411075613, '%')\n",
      "(78.27476038338658, '%')\n",
      "(78.38125665601704, '%')\n",
      "(78.48775292864751, '%')\n",
      "(78.59424920127796, '%')\n",
      "(78.70074547390841, '%')\n",
      "(78.80724174653886, '%')\n",
      "(78.91373801916933, '%')\n",
      "(79.02023429179978, '%')\n",
      "(79.12673056443025, '%')\n",
      "(79.2332268370607, '%')\n",
      "(79.33972310969116, '%')\n",
      "(79.44621938232162, '%')\n",
      "(79.55271565495208, '%')\n",
      "(79.65921192758253, '%')\n",
      "(79.765708200213, '%')\n",
      "(79.87220447284345, '%')\n",
      "(79.9787007454739, '%')\n",
      "(80.08519701810437, '%')\n",
      "(80.19169329073482, '%')\n",
      "(80.29818956336528, '%')\n",
      "(80.40468583599574, '%')\n",
      "(80.5111821086262, '%')\n",
      "(80.61767838125665, '%')\n",
      "(80.72417465388712, '%')\n",
      "(80.83067092651757, '%')\n",
      "(80.93716719914804, '%')\n",
      "(81.04366347177849, '%')\n",
      "(81.15015974440894, '%')\n",
      "(81.2566560170394, '%')\n",
      "(81.36315228966986, '%')\n",
      "(81.46964856230032, '%')\n",
      "(81.57614483493077, '%')\n",
      "(81.68264110756124, '%')\n",
      "(81.78913738019169, '%')\n",
      "(81.89563365282216, '%')\n",
      "(82.0021299254526, '%')\n",
      "(82.10862619808307, '%')\n",
      "(82.21512247071352, '%')\n",
      "(82.32161874334398, '%')\n",
      "(82.42811501597444, '%')\n",
      "(82.53461128860489, '%')\n",
      "(82.64110756123536, '%')\n",
      "(82.74760383386581, '%')\n",
      "(82.85410010649628, '%')\n",
      "(82.96059637912673, '%')\n",
      "(83.06709265175719, '%')\n",
      "(83.17358892438764, '%')\n",
      "(83.28008519701811, '%')\n",
      "(83.38658146964856, '%')\n",
      "(83.49307774227903, '%')\n",
      "(83.59957401490948, '%')\n",
      "(83.70607028753993, '%')\n",
      "(83.8125665601704, '%')\n",
      "(83.91906283280085, '%')\n",
      "(84.02555910543131, '%')\n",
      "(84.13205537806176, '%')\n",
      "(84.23855165069223, '%')\n",
      "(84.34504792332268, '%')\n",
      "(84.45154419595315, '%')\n",
      "(84.5580404685836, '%')\n",
      "(84.66453674121406, '%')\n",
      "(84.77103301384452, '%')\n",
      "(84.87752928647497, '%')\n",
      "(84.98402555910543, '%')\n",
      "(85.09052183173588, '%')\n",
      "(85.19701810436635, '%')\n",
      "(85.3035143769968, '%')\n",
      "(85.41001064962727, '%')\n",
      "(85.51650692225772, '%')\n",
      "(85.62300319488818, '%')\n",
      "(85.72949946751864, '%')\n",
      "(85.8359957401491, '%')\n",
      "(85.94249201277955, '%')\n",
      "(86.04898828541, '%')\n",
      "(86.15548455804047, '%')\n",
      "(86.26198083067092, '%')\n",
      "(86.36847710330139, '%')\n",
      "(86.47497337593184, '%')\n",
      "(86.5814696485623, '%')\n",
      "(86.68796592119276, '%')\n",
      "(86.79446219382322, '%')\n",
      "(86.90095846645367, '%')\n",
      "(87.00745473908414, '%')\n",
      "(87.11395101171459, '%')\n",
      "(87.22044728434504, '%')\n",
      "(87.3269435569755, '%')\n",
      "(87.43343982960596, '%')\n",
      "(87.53993610223642, '%')\n",
      "(87.64643237486688, '%')\n",
      "(87.75292864749734, '%')\n",
      "(87.8594249201278, '%')\n",
      "(87.96592119275826, '%')\n",
      "(88.07241746538871, '%')\n",
      "(88.17891373801918, '%')\n",
      "(88.28541001064963, '%')\n",
      "(88.3919062832801, '%')\n",
      "(88.49840255591054, '%')\n",
      "(88.604898828541, '%')\n",
      "(88.71139510117146, '%')\n",
      "(88.81789137380191, '%')\n",
      "(88.92438764643238, '%')\n",
      "(89.03088391906283, '%')\n",
      "(89.1373801916933, '%')\n",
      "(89.24387646432375, '%')\n",
      "(89.35037273695421, '%')\n",
      "(89.45686900958466, '%')\n",
      "(89.56336528221513, '%')\n",
      "(89.66986155484558, '%')\n",
      "(89.77635782747603, '%')\n",
      "(89.8828541001065, '%')\n",
      "(89.98935037273695, '%')\n",
      "(90.09584664536742, '%')\n",
      "(90.20234291799787, '%')\n",
      "(90.30883919062833, '%')\n",
      "(90.41533546325878, '%')\n",
      "(90.52183173588925, '%')\n",
      "(90.6283280085197, '%')\n",
      "(90.73482428115017, '%')\n",
      "(90.84132055378062, '%')\n",
      "(90.94781682641107, '%')\n",
      "(91.05431309904152, '%')\n",
      "(91.16080937167199, '%')\n",
      "(91.26730564430245, '%')\n",
      "(91.3738019169329, '%')\n",
      "(91.48029818956337, '%')\n",
      "(91.58679446219382, '%')\n",
      "(91.69329073482429, '%')\n",
      "(91.79978700745474, '%')\n",
      "(91.9062832800852, '%')\n",
      "(92.01277955271566, '%')\n",
      "(92.11927582534611, '%')\n",
      "(92.22577209797656, '%')\n",
      "(92.33226837060703, '%')\n",
      "(92.43876464323749, '%')\n",
      "(92.54526091586794, '%')\n",
      "(92.65175718849841, '%')\n",
      "(92.75825346112886, '%')\n",
      "(92.86474973375933, '%')\n",
      "(92.97124600638978, '%')\n",
      "(93.07774227902024, '%')\n",
      "(93.1842385516507, '%')\n",
      "(93.29073482428115, '%')\n",
      "(93.39723109691161, '%')\n",
      "(93.50372736954206, '%')\n",
      "(93.61022364217251, '%')\n",
      "(93.71671991480298, '%')\n",
      "(93.82321618743345, '%')\n",
      "(93.9297124600639, '%')\n",
      "(94.03620873269436, '%')\n",
      "(94.14270500532481, '%')\n",
      "(94.24920127795528, '%')\n",
      "(94.35569755058573, '%')\n",
      "(94.46219382321618, '%')\n",
      "(94.56869009584665, '%')\n",
      "(94.6751863684771, '%')\n",
      "(94.78168264110755, '%')\n",
      "(94.88817891373802, '%')\n",
      "(94.99467518636848, '%')\n",
      "(95.10117145899893, '%')\n",
      "(95.2076677316294, '%')\n",
      "(95.31416400425985, '%')\n",
      "(95.42066027689032, '%')\n",
      "(95.52715654952077, '%')\n",
      "(95.63365282215123, '%')\n",
      "(95.74014909478169, '%')\n",
      "(95.84664536741214, '%')\n",
      "(95.95314164004259, '%')\n",
      "(96.05963791267305, '%')\n",
      "(96.1661341853035, '%')\n",
      "(96.27263045793397, '%')\n",
      "(96.37912673056444, '%')\n",
      "(96.48562300319489, '%')\n",
      "(96.59211927582535, '%')\n",
      "(96.6986155484558, '%')\n",
      "(96.80511182108627, '%')\n",
      "(96.91160809371672, '%')\n",
      "(97.01810436634717, '%')\n",
      "(97.12460063897763, '%')\n",
      "(97.23109691160809, '%')\n",
      "(97.33759318423854, '%')\n",
      "(97.44408945686901, '%')\n",
      "(97.55058572949947, '%')\n",
      "(97.65708200212993, '%')\n",
      "(97.76357827476039, '%')\n",
      "(97.87007454739084, '%')\n",
      "(97.97657082002131, '%')\n",
      "(98.08306709265176, '%')\n",
      "(98.18956336528221, '%')\n",
      "(98.29605963791266, '%')\n",
      "(98.40255591054313, '%')\n",
      "(98.50905218317358, '%')\n",
      "(98.61554845580405, '%')\n",
      "(98.7220447284345, '%')\n",
      "(98.82854100106496, '%')\n",
      "(98.93503727369543, '%')\n",
      "(99.04153354632588, '%')\n",
      "(99.14802981895635, '%')\n",
      "(99.2545260915868, '%')\n",
      "(99.36102236421725, '%')\n",
      "(99.4675186368477, '%')\n",
      "(99.57401490947817, '%')\n",
      "(99.68051118210862, '%')\n",
      "(99.78700745473908, '%')\n",
      "(99.89350372736953, '%')\n"
     ]
    }
   ],
   "source": [
    "# fids matched filter flux densities on sub-pixel scale\n",
    "for j in range(np.size(all_names)):   \n",
    "    print(loc+all_names[j]+band[0]+'_v1.0.fits')\n",
    "\n",
    "    name = all_names[j]+band[0]+'_v1.0.fits'\n",
    "    hdulist1 = fits.open(loc+name)\n",
    "    name = all_names[j]+band[1]+'_v1.0.fits'\n",
    "    hdulist2 = fits.open(loc+name)\n",
    "    name = all_names[j]+band[2]+'_v1.0.fits'\n",
    "    hdulist3 = fits.open(loc+name)\n",
    "\n",
    "    ff = fits.open('data/'+all_names[j]+'_D_cat.fits')\n",
    "    ra,dec = (ff[1].data)['RA'],(ff[1].data)['Dec']\n",
    "\n",
    "    r_1, ra_1, dec_1, S250_1, E250_1, S350_1, E350_1, S500_1, E500_1 = \\\n",
    "                fc.corr_psf_max_MF(hdulist1,hdulist2,hdulist3,ra, dec)\n",
    "    hdu = fits.BinTableHDU.from_columns(\\\n",
    "         [fits.Column(name='RA', array=ra_1, format ='F',unit='degree'),\n",
    "         fits.Column(name='Dec', array=dec_1, format='F',unit='degree'),\n",
    "         fits.Column(name='F_RED_MF_SPIRE_250', array=1000*S250_1, format ='F',unit='mJy'),\n",
    "         fits.Column(name='FErr_RED_MF_SPIRE_250', array=1000*E250_1, format ='F',unit='mJy'),\n",
    "         fits.Column(name='F_RED_MF_SPIRE_350', array=1000*S350_1, format ='F',unit='mJy'),\n",
    "         fits.Column(name='FErr_RED_MF_SPIRE_350', array=1000*E350_1, format ='F',unit='mJy'),\n",
    "         fits.Column(name='F_RED_MF_SPIRE_500', array=1000*S500_1, format ='F',unit='mJy'),\n",
    "         fits.Column(name='FErr_RED_MF_SPIRE_500', array=1000*E500_1, format ='F',unit='mJy'),\n",
    "         fits.Column(name='r', array=r_1, format ='F'),\n",
    "         fits.Column(name='RA_pix', array=(ff[1].data)['RA'], format ='F'), \n",
    "         fits.Column(name='Dec_pix', array=(ff[1].data)['Dec'], format ='F'), \n",
    "         fits.Column(name='F_RED_pix_SPIRE_250', array=1000*(ff[1].data)['F_RED_pix_SPIRE_250'], format ='F',unit='mJy'), \n",
    "         fits.Column(name='FErr_RED_pix_SPIRE_250', array=1000*(ff[1].data)['FErr_RED_pix_SPIRE_250'], format ='F',unit='mJy'), \n",
    "         fits.Column(name='F_RED_pix_SPIRE_350', array=1000*(ff[1].data)['F_RED_pix_SPIRE_350'], format ='F',unit='mJy'), \n",
    "         fits.Column(name='FErr_RED_pix_SPIRE_350', array=1000*(ff[1].data)['FErr_RED_pix_SPIRE_350'], format ='F',unit='mJy'), \n",
    "         fits.Column(name='F_RED_pix_SPIRE_500', array=1000*(ff[1].data)['F_RED_pix_SPIRE_500'], format ='F',unit='mJy'), \n",
    "         fits.Column(name='FErr_RED_pix_SPIRE_500', array=1000*(ff[1].data)['FErr_RED_pix_SPIRE_500'], format ='F',unit='mJy') \n",
    "         ])\n",
    "    hdu.writeto('data/'+all_names[j]+'_D_MF_cat.fits') "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![HELP LOGO](https://avatars1.githubusercontent.com/u/7880370?s=75&v=4)\n",
    "\n",
    "**Authors**: Steven Duivenvoorden \n",
    "\n",
    "For a full description of the database and how it is organised in to `dmu_products` please the top level [readme](../readme.md).\n",
    "\n",
    "The Herschel Extragalactic Legacy Project, ([HELP](http://herschel.sussex.ac.uk/)), is a [European Commission Research Executive Agency](https://ec.europa.eu/info/departments/research-executive-agency_en)\n",
    "funded project under the SP1-Cooperation, Collaborative project, Small or medium-scale focused research project, FP7-SPACE-2013-1 scheme, Grant Agreement Number 607254.\n",
    "\n",
    "[Acknowledgements](http://herschel.sussex.ac.uk/acknowledgements)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
