{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Useful tools"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1- Transit observability predictions"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this section we present a tool to predict whether the next transits of your favorite exoplanet will be observable from ome of the SPECULOOS site"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Only a few basic information are needed:\n",
    "\n",
    "* Site name, ex: `obs_name = 'SSO'`\n",
    "\n",
    "* Planet name, ex: `name = TRAPPIST-1b`\n",
    "\n",
    "* Right ascension, ex: `ra = 346.622384`  \n",
    "\n",
    "* Declinaison, ex: `dec = -5.041398`\n",
    "\n",
    "* Timing (in BJD_TDB), ex: `timing = 2457322.51505`\n",
    "\n",
    "* Period (in days), ex: `period = 1.51088212`\n",
    "\n",
    "* Transit duration (in days), ex: `duration = 0.02511108`\n",
    "\n",
    "* Date to start prediction, ex start_date = `'2020-06-01 00:00:00'`\n",
    "\n",
    "* Number of next transits from this atart date, ex: `ntr = 4`\n",
    "\n",
    "\n",
    "Note that this tools is not suposed to be very precise as errors on timing, period and duration are **NOT** taken into account. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "
\n",
       "\n",
       "
\n",
       "  \n",
       "    \n",
       "       | \n",
       "      Ingress | \n",
       "      Egress | \n",
       "      mid transit | \n",
       "      mid transit JD | \n",
       "      Observable SSO | \n",
       "      Observable SNO | \n",
       "      Observable Saint-Ex | \n",
       "      Observable TN Oukaimeden | \n",
       "      Observable TS La Silla | \n",
       "    
\n",
       "  \n",
       "  \n",
       "    \n",
       "      | TRAPPIST-1b | \n",
       "      2020-10-02 11:38:11.217 | \n",
       "      2020-10-02 12:14:20.814 | \n",
       "      2020-10-02 11:56:16.015 | \n",
       "      2459124.997 | \n",
       "      False | \n",
       "      False | \n",
       "      False | \n",
       "      False | \n",
       "      False | \n",
       "    
\n",
       "    \n",
       "      | TRAPPIST-1b | \n",
       "      2020-10-03 23:53:51.432 | \n",
       "      2020-10-04 00:30:01.029 | \n",
       "      2020-10-04 00:11:56.231 | \n",
       "      2459126.508 | \n",
       "      True | \n",
       "      True | \n",
       "      False | \n",
       "      True | \n",
       "      True | \n",
       "    
\n",
       "    \n",
       "      | TRAPPIST-1b | \n",
       "      2020-10-05 12:09:31.647 | \n",
       "      2020-10-05 12:45:41.244 | \n",
       "      2020-10-05 12:27:36.446 | \n",
       "      2459128.019 | \n",
       "      False | \n",
       "      False | \n",
       "      False | \n",
       "      False | \n",
       "      False | \n",
       "    
\n",
       "    \n",
       "      | TRAPPIST-1b | \n",
       "      2020-10-07 00:25:11.862 | \n",
       "      2020-10-07 01:01:21.460 | \n",
       "      2020-10-07 00:43:16.661 | \n",
       "      2459129.530 | \n",
       "      True | \n",
       "      True | \n",
       "      False | \n",
       "      True | \n",
       "      True | \n",
       "    
\n",
       "  \n",
       "
\n",
       "
 "
      ],
      "text/plain": [
       "                             Ingress                   Egress  \\\n",
       "TRAPPIST-1b  2020-10-02 11:38:11.217  2020-10-02 12:14:20.814   \n",
       "TRAPPIST-1b  2020-10-03 23:53:51.432  2020-10-04 00:30:01.029   \n",
       "TRAPPIST-1b  2020-10-05 12:09:31.647  2020-10-05 12:45:41.244   \n",
       "TRAPPIST-1b  2020-10-07 00:25:11.862  2020-10-07 01:01:21.460   \n",
       "\n",
       "                         mid transit  mid transit JD  Observable SSO  \\\n",
       "TRAPPIST-1b  2020-10-02 11:56:16.015     2459124.997           False   \n",
       "TRAPPIST-1b  2020-10-04 00:11:56.231     2459126.508            True   \n",
       "TRAPPIST-1b  2020-10-05 12:27:36.446     2459128.019           False   \n",
       "TRAPPIST-1b  2020-10-07 00:43:16.661     2459129.530            True   \n",
       "\n",
       "             Observable SNO  Observable Saint-Ex  Observable TN Oukaimeden  \\\n",
       "TRAPPIST-1b           False                False                     False   \n",
       "TRAPPIST-1b            True                False                      True   \n",
       "TRAPPIST-1b           False                False                     False   \n",
       "TRAPPIST-1b            True                False                      True   \n",
       "\n",
       "             Observable TS La Silla  \n",
       "TRAPPIST-1b                   False  \n",
       "TRAPPIST-1b                    True  \n",
       "TRAPPIST-1b                   False  \n",
       "TRAPPIST-1b                    True  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import SPOCK.short_term_scheduler as SPOCKST\n",
    "\n",
    "SPOCKST.prediction(name='TRAPPIST-1b',ra=346.,dec=-5.05,\n",
    "                   timing=2457322.51505,\n",
    "                   period=1.51088212,duration=0.02511108,\n",
    "                   start_date='2020-10-01 00:00:00',ntr=4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2- Get info on a target from SPECULOOS target list"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you want to check rapidly the stellar properties, GAIA ID, its priority, its completion etc of a SPECULOOS `target`, you can use the following function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "
\n",
       "  \n",
       "    \n",
       "       | \n",
       "      Sp_ID | \n",
       "      2MASS | \n",
       "      Gaia_ID | \n",
       "      wise | \n",
       "      Program | \n",
       "      nb_hours_surved | \n",
       "      nb_hours_threshold | \n",
       "      RA | \n",
       "      DEC | \n",
       "      e_gra | \n",
       "      e_gdec | \n",
       "      telescope | \n",
       "      Filter_spc | \n",
       "      texp_spc | \n",
       "      Filter_trap | \n",
       "      texp_trap | \n",
       "      dist | \n",
       "      dist_err | \n",
       "      SpT | \n",
       "      e_SpT | \n",
       "      Ms | \n",
       "      e_Ms | \n",
       "      Rs | \n",
       "      e_Rs | \n",
       "      T_eff | \n",
       "      ... | \n",
       "      mag_rp | \n",
       "      mag_rp_err | \n",
       "      Habs | \n",
       "      e_Habs | \n",
       "      Jabs | \n",
       "      e_Jabs | \n",
       "      Kabs | \n",
       "      e_Kabs | \n",
       "      Gabs | \n",
       "      e_Gabs | \n",
       "      BCj | \n",
       "      BCj_err | \n",
       "      L_bol | \n",
       "      L_bol_err | \n",
       "      cf | \n",
       "      num_stars | \n",
       "      min_dist_stars | \n",
       "      avg_dist_stars | \n",
       "      rel_flux_stars | \n",
       "      plx | \n",
       "      plx_err | \n",
       "      pmra | \n",
       "      pmdec | \n",
       "      pmra_err | \n",
       "      pmdec_err | \n",
       "    
\n",
       "  \n",
       "  \n",
       "    \n",
       "      | 334 | \n",
       "      Sp0439-3235 | \n",
       "      04393407-3235516 | \n",
       "      4.871414e+18 | \n",
       "      J043933.97-323551.4 | \n",
       "      1.0 | \n",
       "      228.16 | \n",
       "      200.0 | \n",
       "      69.891853 | \n",
       "      -32.597658 | \n",
       "      0.056772 | \n",
       "      0.06425 | \n",
       "      ['Callisto'] | \n",
       "      I+z | \n",
       "      0.0 | \n",
       "      I+z | \n",
       "      0.0 | \n",
       "      20.2 | \n",
       "      0.0 | \n",
       "      5.4 | \n",
       "      0.9 | \n",
       "      0.113 | \n",
       "      0.001 | \n",
       "      0.138 | \n",
       "      0.02 | \n",
       "      2925.0 | \n",
       "      ... | \n",
       "      13.910709 | \n",
       "      0.003683 | \n",
       "      9.486847 | \n",
       "      0.025223 | \n",
       "      10.086847 | \n",
       "      0.022253 | \n",
       "      9.106847 | \n",
       "      0.025223 | \n",
       "      13.829693 | \n",
       "      0.003464 | \n",
       "      1.912446 | \n",
       "      0.029292 | \n",
       "      0.001248 | \n",
       "      0.000042 | \n",
       "      0.0 | \n",
       "      1.0 | \n",
       "      44.57 | \n",
       "      0.0 | \n",
       "      0.0 | \n",
       "      0.0 | \n",
       "      0.0 | \n",
       "      -101.527 | \n",
       "      9.711 | \n",
       "      0.124 | \n",
       "      0.145 | \n",
       "    
\n",
       "  \n",
       "
\n",
       "
1 rows × 72 columns
\n",
       "
 "
      ],
      "text/plain": [
       "           Sp_ID             2MASS       Gaia_ID                 wise  \\\n",
       "334  Sp0439-3235  04393407-3235516  4.871414e+18  J043933.97-323551.4   \n",
       "\n",
       "     Program  nb_hours_surved  nb_hours_threshold         RA        DEC  \\\n",
       "334      1.0           228.16               200.0  69.891853 -32.597658   \n",
       "\n",
       "        e_gra   e_gdec     telescope Filter_spc  texp_spc Filter_trap  \\\n",
       "334  0.056772  0.06425  ['Callisto']        I+z       0.0         I+z   \n",
       "\n",
       "     texp_trap  dist  dist_err  SpT  e_SpT     Ms   e_Ms     Rs  e_Rs   T_eff  \\\n",
       "334        0.0  20.2       0.0  5.4    0.9  0.113  0.001  0.138  0.02  2925.0   \n",
       "\n",
       "     ...     mag_rp  mag_rp_err      Habs    e_Habs       Jabs    e_Jabs  \\\n",
       "334  ...  13.910709    0.003683  9.486847  0.025223  10.086847  0.022253   \n",
       "\n",
       "         Kabs    e_Kabs       Gabs    e_Gabs       BCj   BCj_err     L_bol  \\\n",
       "334  9.106847  0.025223  13.829693  0.003464  1.912446  0.029292  0.001248   \n",
       "\n",
       "    L_bol_err   cf  num_stars  min_dist_stars  avg_dist_stars rel_flux_stars  \\\n",
       "334  0.000042  0.0        1.0           44.57             0.0            0.0   \n",
       "\n",
       "     plx  plx_err     pmra  pmdec  pmra_err  pmdec_err  \n",
       "334  0.0      0.0 -101.527  9.711     0.124      0.145  \n",
       "\n",
       "[1 rows x 72 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import SPOCK.stats as SPOCKstats\n",
    "\n",
    "SPOCKstats.info_on_Sp_target(target = 'Sp0439-3235')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3- Get info on scheduled night blocks"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here we propose a function to check which targets have been scheduled on the SPECULOOS telescopes by displaying its corresponding  **night_blocks** . The user will onyly have to precise the `date` and the `telescope`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "
\n",
       "  \n",
       "    \n",
       "       | \n",
       "      target | \n",
       "      start time (UTC) | \n",
       "      end time (UTC) | \n",
       "      duration (minutes) | \n",
       "      ra (h) | \n",
       "      ra (m) | \n",
       "      ra (s) | \n",
       "      dec (d) | \n",
       "      dec (m) | \n",
       "      dec (s) | \n",
       "      configuration | \n",
       "    
\n",
       "  \n",
       "  \n",
       "    \n",
       "      | 0 | \n",
       "      Sp2330-4736 | \n",
       "      2020-10-12 23:36:20.018 | \n",
       "      2020-10-12 23:31:00.021 | \n",
       "      56.666717 | \n",
       "      23.0 | \n",
       "      30.0 | \n",
       "      15.887304 | \n",
       "      -47.0 | \n",
       "      -36.0 | \n",
       "      -45.08424 | \n",
       "      {'filt=I+z', 'texp=15'} | \n",
       "    
\n",
       "    \n",
       "      | 1 | \n",
       "      Trappist-1b | \n",
       "      2020-10-12 23:31:00.021 | \n",
       "      2020-10-13 02:59:20.021 | \n",
       "      146.333333 | \n",
       "      23.0 | \n",
       "      6.0 | \n",
       "      29.000000 | \n",
       "      -5.0 | \n",
       "      -2.0 | \n",
       "      -28.00000 | \n",
       "      {'filt=I+z', 'texp=23'} | \n",
       "    
\n",
       "    \n",
       "      | 2 | \n",
       "      Sp2330-4736_2 | \n",
       "      2020-10-13 02:59:20.021 | \n",
       "      2020-10-13 04:23:20.018 | \n",
       "      83.999950 | \n",
       "      23.0 | \n",
       "      30.0 | \n",
       "      15.887304 | \n",
       "      -47.0 | \n",
       "      -36.0 | \n",
       "      -45.08424 | \n",
       "      {'filt=I+z', 'texp=15'} | \n",
       "    
\n",
       "    \n",
       "      | 3 | \n",
       "      Sp0553-7133 | \n",
       "      2020-10-13 04:24:20.028 | \n",
       "      2020-10-13 09:19:20.028 | \n",
       "      56.666717 | \n",
       "      5.0 | \n",
       "      53.0 | \n",
       "      26.479968 | \n",
       "      -71.0 | \n",
       "      -33.0 | \n",
       "      -49.79088 | \n",
       "      {'filt=i', 'texp=16'} | \n",
       "    
\n",
       "  \n",
       "
\n",
       "
 "
      ],
      "text/plain": [
       "          target         start time (UTC)           end time (UTC)  \\\n",
       "0    Sp2330-4736  2020-10-12 23:36:20.018  2020-10-12 23:31:00.021   \n",
       "1    Trappist-1b  2020-10-12 23:31:00.021  2020-10-13 02:59:20.021   \n",
       "2  Sp2330-4736_2  2020-10-13 02:59:20.021  2020-10-13 04:23:20.018   \n",
       "3    Sp0553-7133  2020-10-13 04:24:20.028  2020-10-13 09:19:20.028   \n",
       "\n",
       "   duration (minutes)  ra (h)  ra (m)     ra (s)  dec (d)  dec (m)   dec (s)  \\\n",
       "0           56.666717    23.0    30.0  15.887304    -47.0    -36.0 -45.08424   \n",
       "1          146.333333    23.0     6.0  29.000000     -5.0     -2.0 -28.00000   \n",
       "2           83.999950    23.0    30.0  15.887304    -47.0    -36.0 -45.08424   \n",
       "3           56.666717     5.0    53.0  26.479968    -71.0    -33.0 -49.79088   \n",
       "\n",
       "             configuration  \n",
       "0  {'filt=I+z', 'texp=15'}  \n",
       "1  {'filt=I+z', 'texp=23'}  \n",
       "2  {'filt=I+z', 'texp=15'}  \n",
       "3    {'filt=i', 'texp=16'}  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import SPOCK.stats as SPOCKstats\n",
    "\n",
    "SPOCKstats.read_night_plans_server(telescope = 'Io',date = '2020-10-12')\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "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.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}