{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e40c18d5-e4e9-49ca-b3f5-faab7d3f1aaf",
   "metadata": {},
   "source": [
    "# daschlab Quicklook Notebook Template\n",
    "\n",
    "Use this template to quickly check out the DASCH data for a source of interest. To keep things\n",
    "terse, it does not include explanation — see [the documentation](https://dasch.cfa.harvard.edu/dr7/)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cfeee608-6f5d-4822-a5d2-93f5bcdfa333",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "## Configuration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "48ac67ec-a87c-4d84-900d-21da4f863d05",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Fill in the SIMBAD-resolvable name of your target source:\n",
    "SOURCE = \"source name goes here\"\n",
    "\n",
    "# Leave this unchanged unless you're sure that you want something else:\n",
    "REFCAT = \"apass\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "41e26299-8a75-4ba8-8c67-a6186e6c542e",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "## Initialization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ce5c4bf-673c-49e0-b591-bcce10cf9595",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get the main module:\n",
    "import daschlab\n",
    "\n",
    "# Set up Bokeh plots:\n",
    "from bokeh.io import output_notebook\n",
    "output_notebook()\n",
    "\n",
    "# Get some other imports that will be useful:\n",
    "from astropy import units as u\n",
    "from bokeh.plotting import figure, show\n",
    "import numpy as np\n",
    "from daschlab.photometry import AFlags, BFlags"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ed8b3e3-c916-485e-83a8-7c83d766ccdb",
   "metadata": {},
   "outputs": [],
   "source": [
    "sess = daschlab.open_session(source=SOURCE)\n",
    "sess.select_target(name=SOURCE)\n",
    "sess.select_refcat(REFCAT)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "35c1e265-6abb-433b-8914-b56d2fd32d99",
   "metadata": {},
   "source": [
    "#### **Before proceeding, make sure that the WWT JupyterLab app is open** — the [tutorial slideshow][slides] shows what to do\n",
    "\n",
    "Once that's done, you may continue:\n",
    "\n",
    "[slides]: https://dasch.cfa.harvard.edu/dr7/rycnc/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0059f3c9-22ea-453b-9d31-8cf5cae5d065",
   "metadata": {},
   "outputs": [],
   "source": [
    "await sess.connect_to_wwt()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a2c3937-a8e7-427b-bb4f-a92880b15df6",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "## Print and display the refcat\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "794bd586-f158-4921-8ba8-9100afbbb28b",
   "metadata": {},
   "outputs": [],
   "source": [
    "sess.refcat()[:12]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "df83affa-03a7-495b-a21c-832d9498163d",
   "metadata": {},
   "outputs": [],
   "source": [
    "sess.refcat().show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2a6fbadc-d40c-4a20-8810-4a6317301c64",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "## Select and show a nice sample cutout"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fd9cdb39-1047-4fae-be7c-0cdb1a5c57bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Print mini table of candidates\n",
    "sess.exposures().candidate_nice_cutouts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "08e2127a-b366-47c6-a7a7-721c6fe7e111",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Choose an exp_local_id from the above list of candidates\n",
    "SAMPLE_EXP_ID = id_goes_here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ee18b491-d774-482b-855f-db799f34ac18",
   "metadata": {},
   "outputs": [],
   "source": [
    "sess.exposures().show(SAMPLE_EXP_ID)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7bde450b-8785-4206-a154-57275d101d8b",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "## Plot the raw lightcurve"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2905ec4a-7273-4b91-9298-3c1bc029fc50",
   "metadata": {},
   "outputs": [],
   "source": [
    "# This number is a row index into the reference catalog table, `sess.refcat()`. That\n",
    "# table is sorted by promixity to the search target, so row 0 is probably what you want.\n",
    "\n",
    "TARGET_ID = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "75292ad7-598f-4f63-a4bd-cfab073f436d",
   "metadata": {},
   "outputs": [],
   "source": [
    "lc = sess.lightcurve(TARGET_ID)\n",
    "lc.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6bc2ad23-7431-4c27-b4bc-319f0be0cd2f",
   "metadata": {},
   "outputs": [],
   "source": [
    "lc.plot()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0e681404-5128-4b6a-86fb-658fb22ba319",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "## Plot after standard rejections"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9be85c99-61fa-4c6d-b92b-ac3fd351e113",
   "metadata": {},
   "outputs": [],
   "source": [
    "lc.apply_standard_rejections()\n",
    "print()\n",
    "lc.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d858825e-8e66-48d1-aea8-b887eb997cd8",
   "metadata": {},
   "outputs": [],
   "source": [
    "lc.plot()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e1263f40-d17c-4ea4-8fa2-0a6630b132d7",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "## Your Analysis Follows Here:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5e438fbf-bd45-40e3-b5ab-0c875f917e6b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}