{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b140f180-46e2-45f4-b358-bdc1a275734e",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib widget\n",
    "\n",
    "import ipyvolume as ipv\n",
    "import batoid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3d5ebded-9214-4a5c-8efe-2c3b7108e31c",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "telescope = batoid.Optic.fromYaml(\"CBP.yaml\")\n",
    "telescope.backDist = 1\n",
    "telescope.stopSurface = batoid.Interface(batoid.Plane(), coordSys=batoid.CoordSys(origin=[0, 0, 0.349]))\n",
    "telescope.pupilSize = 0.254\n",
    "telescope.pupilObscuration = 0.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b7f6ecd4-d09a-4f6f-af35-60d62a93ba44",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "max_th = 2.\n",
    "pixSize = 1e-6\n",
    "\n",
    "dthx_drx = []\n",
    "dthy_dry = []\n",
    "thetas = np.linspace(0., max_th, 20)\n",
    "for th in thetas:\n",
    "    dth_dr = batoid.dthdr(telescope, np.deg2rad(th), 0, 620e-9)\n",
    "    dthx_drx.append(abs(dth_dr[0,0]))\n",
    "    dthy_dry.append(abs(dth_dr[1,1]))\n",
    "\n",
    "dthx_drx = np.array(dthx_drx) * 206265 * pixSize # arcsec per micron\n",
    "dthy_dry = np.array(dthy_dry) * 206265 * pixSize # arcsec per micron\n",
    "\n",
    "fig, ax = plt.subplots(ncols=1, figsize=(5, 4))\n",
    "ax.plot(thetas, dthx_drx, c='b', label='radial')\n",
    "ax.plot(thetas, dthy_dry, c='r', label='tangential')\n",
    "ax.set_xlabel('radius (deg)')\n",
    "ax.set_ylabel('arcsec per micron')\n",
    "ax.legend(loc='upper left')\n",
    "ax.set_title(\"CBP\")\n",
    "\n",
    "fig.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4fb61385-3740-4920-85a1-c00fa04be7be",
   "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.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
