{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-08-31T19:41:01.871380Z",
     "start_time": "2019-08-31T19:41:01.633929Z"
    }
   },
   "outputs": [],
   "source": [
    "import batoid\n",
    "import numpy as np\n",
    "from ipywidgets import interact\n",
    "import ipywidgets as widgets\n",
    "import matplotlib.pyplot as plt\n",
    "from mpl_toolkits.mplot3d import Axes3D\n",
    "import ipyvolume as ipv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-08-31T19:41:01.954615Z",
     "start_time": "2019-08-31T19:41:01.872752Z"
    }
   },
   "outputs": [],
   "source": [
    "telescope = batoid.Optic.fromYaml(\"HSC.yaml\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-08-31T19:41:02.468173Z",
     "start_time": "2019-08-31T19:41:01.956122Z"
    }
   },
   "outputs": [],
   "source": [
    "fig1 = plt.figure(figsize=(12, 11))\n",
    "ax1 = fig1.add_subplot(111)\n",
    "telescope.draw2d(ax1, c='k')\n",
    "\n",
    "fig2 = plt.figure(figsize=(12, 11))\n",
    "ax2 = fig2.add_subplot(111, projection='3d')\n",
    "telescope.draw3d(ax2, c='k')\n",
    "\n",
    "ipv.figure(width=700, height=500)\n",
    "telescope.draw3d(ipv, color='black')\n",
    "\n",
    "x = np.array([-2.5, -1.5, 1.5, 2.5])\n",
    "\n",
    "for vx, c in zip(np.deg2rad([-0.7, 0, 0.7]), ['#377eb8', '#ff7f00', '#4daf4a']):\n",
    "    rays = batoid.RayVector(x, 0, 0, vx, 0, -np.sqrt(1-vx**2), wavelength=500e-9)\n",
    "    rays.propagate(-20)\n",
    "    tF = telescope.traceFull(rays)\n",
    "    batoid.drawTrace2d(ax1, tF, c=c)\n",
    "    batoid.drawTrace3d(ax2, tF, c=c)\n",
    "    batoid.drawTrace3d(ipv, tF, color=c)\n",
    "ax1.set_aspect('equal')\n",
    "ipv.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-08-31T19:41:02.973862Z",
     "start_time": "2019-08-31T19:41:02.469560Z"
    }
   },
   "outputs": [],
   "source": [
    "fig1 = plt.figure(figsize=(12, 11))\n",
    "ax1 = fig1.add_subplot(111)\n",
    "telescope['HSC'].draw2d(ax1, c='k')\n",
    "ax1.set_xlim(ax1.get_xlim())\n",
    "ax1.set_ylim(ax1.get_ylim())\n",
    "\n",
    "fig2 = plt.figure(figsize=(12, 11))\n",
    "ax2 = fig2.add_subplot(111, projection='3d')\n",
    "telescope['HSC'].draw3d(ax2, c='k')\n",
    "ax2.set_xlim(ax2.get_xlim())\n",
    "ax2.set_ylim(ax2.get_ylim())\n",
    "ax2.set_zlim(ax2.get_zlim())\n",
    "\n",
    "ipv.figure(width=700, height=500)\n",
    "telescope.draw3d(ipv, color='black')\n",
    "\n",
    "x = np.array([-2.5, -1.5, 1.5, 2.5])\n",
    "\n",
    "for vx, c in zip(np.deg2rad([-0.7, 0, 0.7]), ['#377eb8', '#ff7f00', '#4daf4a']):\n",
    "    rays = batoid.RayVector(x, 0, 0, vx, 0, -np.sqrt(1-vx**2), wavelength=500e-9)\n",
    "    rays.propagate(-20)\n",
    "    tF = telescope.traceFull(rays)\n",
    "    batoid.drawTrace2d(ax1, tF, c=c)\n",
    "    batoid.drawTrace3d(ax2, tF, c=c)\n",
    "    batoid.drawTrace3d(ipv, tF, color=c)\n",
    "ipv.xlim(-0.5, 0.5)\n",
    "ipv.ylim(-0.5, 0.5)\n",
    "ipv.zlim(13.4, 15.4)\n",
    "ipv.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "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.8-final"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}