{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import batoid\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "telescope = batoid.Optic.fromYaml(\"DECam.yaml\")\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(8, 16))\n",
    "\n",
    "telescope.draw2d(\n",
    "    ax, only=batoid.Lens, fc='c', alpha=0.2, \n",
    "#     labelpos=1.62, fontdict=dict(fontsize=18, weight='bold', color='c')\n",
    ")\n",
    "telescope.draw2d(ax, only=batoid.Detector, c='b', lw=2)\n",
    "telescope.draw2d(ax, only=batoid.Baffle, c='r', lw=1, ls=':',\n",
    ")\n",
    "telescope.draw2d(ax, only=batoid.Mirror, c='b', lw=2)\n",
    "\n",
    "# Fill the (x, z) plane with rays entering the pupil.\n",
    "z_pupil = telescope.backDist\n",
    "r_pupil = 0.5 * telescope.pupilSize\n",
    "x_pupil = np.linspace(-r_pupil, r_pupil, 22)\n",
    "\n",
    "# Trace and draw 500nm rays from 5 angles covering the field of view.\n",
    "wlen = 500e-9\n",
    "fov = np.deg2rad(2.2)\n",
    "thetas = np.linspace(-0.5 * fov, +0.5 * fov, 5)\n",
    "for theta in thetas:\n",
    "    rays = batoid.RayVector(x_pupil, 0, z_pupil, np.sin(theta), 0., -np.cos(theta), wavelength=wlen)\n",
    "    traceFull = telescope.traceFull(rays)\n",
    "    batoid.drawTrace2d(ax, traceFull, c='k', lw=1, alpha=0.3)\n",
    "\n",
    "# ax.set_xlim(-0.6, 0.7)\n",
    "ax.set_xlim(-2.1, 2.1)\n",
    "ax.set_ylim(0.0, 12.0)\n",
    "ax.set_aspect(1.0)\n",
    "ax.axis('off')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "telescope = batoid.Optic.fromYaml(\"DECam.yaml\")\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(8, 16))\n",
    "\n",
    "telescope.draw2d(\n",
    "    ax, only=batoid.Lens, fc='c', alpha=0.2, \n",
    "    labelpos=0.62, fontdict=dict(fontsize=18, weight='bold', color='c')\n",
    ")\n",
    "telescope.draw2d(ax, only=batoid.Detector, c='b', lw=2)\n",
    "telescope.draw2d(ax, only=batoid.Baffle, c='r', lw=1, ls=':',\n",
    "#     labelpos=0.62, fontdict=dict(fontsize=18, weight='bold', color='r')\n",
    ")\n",
    "telescope.draw2d(ax, only=batoid.Mirror, c='b', lw=2)\n",
    "\n",
    "# Fill the (x, z) plane with rays entering the pupil.\n",
    "z_pupil = telescope.backDist\n",
    "r_pupil = 0.5 * telescope.pupilSize\n",
    "x_pupil = np.linspace(-r_pupil, r_pupil, 12)\n",
    "\n",
    "# Trace and draw 500nm rays from 5 angles covering the field of view.\n",
    "wlen = 500e-9\n",
    "fov = np.deg2rad(2.2)\n",
    "thetas = np.linspace(-0.5 * fov, +0.5 * fov, 5)\n",
    "for theta in thetas:\n",
    "    rays = batoid.RayVector(x_pupil, 0, z_pupil, np.sin(theta), 0., -np.cos(theta), wavelength=wlen)\n",
    "    traceFull = telescope.traceFull(rays)\n",
    "    batoid.drawTrace2d(ax, traceFull, c='k', lw=1, alpha=0.3)\n",
    "\n",
    "ax.set_xlim(-0.6, 0.7)\n",
    "# ax.set_xlim(-2.2, 2.2)\n",
    "ax.set_ylim(8.5, 10.9)\n",
    "ax.set_aspect(1.0)\n",
    "ax.axis('off')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3",
   "metadata": {
    "interpreter": {
     "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
    }
   }
  },
  "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.8-final"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}