{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Downloading and processing of HSC PDR2 wide photo_z\n",
    "\n",
    "We will perform some simple modifications to the tables of HSC PDR2 wide photoz generated from the sql\n",
    "\n",
    "'dmu_products/dmu0/dmu0_HSC/sql/wide_photoz_pdr2.sql'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from astropy.table import Table, Column, vstack\n",
    "from astropy.io.ascii import read\n",
    "\n",
    "from herschelhelp.utils import position_to_field\n",
    "from herschelhelp_internal.utils import coords_to_hpidx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "filenames = [\n",
    "    'HSC-PDR2_wide_W01_WIDE01H',\n",
    "    'HSC-PDR2_wide_W02_XMM',\n",
    "    'HSC-PDR2_wide_W03_GAMA09H',\n",
    "    'HSC-PDR2_wide_W04_WIDE12HpGAMA15H',\n",
    "    'HSC-PDR2_wide_W05_VVDS',\n",
    "    'HSC-PDR2_wide_W06_HECTOMAP',\n",
    "    'HSC-PDR2_wide_W07_AEGIS'\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "pdr2 = Table()\n",
    "for f in filenames:\n",
    "    pdr2 = vstack([\n",
    "        pdr2,\n",
    "        read(\"./data/{}.csv\".format(f), header_start=40)\n",
    "    ])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "pdr2.add_column(Column(\n",
    "    data=coords_to_hpidx(pdr2['ra'], pdr2['dec'], order=13),\n",
    "    name=\"hp_idx\"\n",
    "))\n",
    "\n",
    "pdr2.add_column(Column(\n",
    "    data=position_to_field(pdr2['ra'], pdr2['dec'], dmu_loc='../../'),\n",
    "    name=\"field\"\n",
    "))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "pdr2.write('./data/HSC-PDR2_wide_full.fits', overwrite = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "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.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
