{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-16T04:43:38.974061Z",
     "start_time": "2019-09-16T04:43:38.740685Z"
    }
   },
   "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",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-16T04:43:39.024953Z",
     "start_time": "2019-09-16T04:43:38.975352Z"
    }
   },
   "outputs": [],
   "source": [
    "fiducial_telescope = batoid.Optic.fromYaml(\"LSST_r.yaml\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-16T04:43:43.725014Z",
     "start_time": "2019-09-16T04:43:39.026386Z"
    }
   },
   "outputs": [],
   "source": [
    "theta_x = 0\n",
    "theta_y = 0\n",
    "wavelength = 620e-9\n",
    "\n",
    "telescope = fiducial_telescope.withGloballyShiftedOptic(\n",
    "    'LSST.LSSTCamera', [0,0,1e-3]\n",
    ")\n",
    "\n",
    "nx=1536\n",
    "fftpsf = batoid.fftPSF(\n",
    "    telescope, theta_x, theta_y, wavelength, \n",
    "    nx=nx, pad_factor=1\n",
    ")\n",
    "scale = np.sqrt(np.abs(np.linalg.det(fftpsf.primitiveVectors)))  # meters\n",
    "\n",
    "extent = scale*fftpsf.array.shape[0]/2*np.r_[-1., 1., -1., 1.] # meters\n",
    "extent -= scale/2\n",
    "extent *= 1e6 # microns\n",
    "\n",
    "plt.imshow(fftpsf.array/fftpsf.array.sum(), extent=extent)\n",
    "plt.colorbar()\n",
    "plt.title(\"FFT PSF\")\n",
    "plt.show()\n",
    "\n",
    "fftpsf_sub = fftpsf.array[16::32, 16::32]\n",
    "plt.imshow(fftpsf_sub/fftpsf_sub.sum(), extent=extent)\n",
    "plt.colorbar()\n",
    "plt.title(\"FFT PSF downsampled\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-16T04:43:48.551746Z",
     "start_time": "2019-09-16T04:43:43.726575Z"
    }
   },
   "outputs": [],
   "source": [
    "theta_x = 0\n",
    "theta_y = np.deg2rad(1.75)\n",
    "wavelength = 620e-9\n",
    "\n",
    "telescope = fiducial_telescope.withGloballyShiftedOptic(\n",
    "    'LSST.LSSTCamera', [0,0,1e-3]\n",
    ")\n",
    "\n",
    "nx=1536\n",
    "fftpsf = batoid.fftPSF(\n",
    "    telescope, theta_x, theta_y, wavelength, \n",
    "    nx=nx, pad_factor=1\n",
    ")\n",
    "scale = np.sqrt(np.abs(np.linalg.det(fftpsf.primitiveVectors)))  # meters\n",
    "\n",
    "extent = scale*fftpsf.array.shape[0]/2*np.r_[-1., 1., -1., 1.] # meters\n",
    "extent -= scale/2\n",
    "extent *= 1e6 # microns\n",
    "\n",
    "plt.imshow(fftpsf.array/fftpsf.array.sum(), extent=extent)\n",
    "plt.colorbar()\n",
    "plt.title(\"FFT PSF\")\n",
    "plt.show()\n",
    "\n",
    "fftpsf_sub = fftpsf.array[16::32, 16::32]\n",
    "plt.imshow(fftpsf_sub/fftpsf_sub.sum(), extent=extent)\n",
    "plt.colorbar()\n",
    "plt.title(\"FFT PSF downsampled\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-16T04:44:06.729074Z",
     "start_time": "2019-09-16T04:43:48.553096Z"
    }
   },
   "outputs": [],
   "source": [
    "wavelength = 500e-9\n",
    "theta_x = 0\n",
    "theta_y = np.deg2rad(1.75)\n",
    "\n",
    "telescope = fiducial_telescope.withGloballyShiftedOptic(\n",
    "    'LSST.LSSTCamera', [0,0,1e-3]\n",
    ")\n",
    "\n",
    "nx = 1800\n",
    "nxOut = 32\n",
    "dx = 1200*1e-6/nxOut\n",
    "huygensPSF = batoid.huygensPSF(\n",
    "    telescope, theta_x, theta_y, wavelength, \n",
    "    nx=nx, dx=dx, dy=dx, nxOut=nxOut\n",
    ")\n",
    "\n",
    "scale = np.sqrt(np.abs(np.linalg.det(huygensPSF.primitiveVectors)))  # meters\n",
    "if huygensPSF.primitiveVectors[0,0] < 1:\n",
    "    huygensPSF.array = huygensPSF.array[::-1,::-1]\n",
    "\n",
    "extent = scale*huygensPSF.array.shape[0]/2*np.r_[-1., 1., -1., 1.]  # meters\n",
    "extent -= scale/2\n",
    "extent *= 1e6 # microns\n",
    "\n",
    "plt.imshow(huygensPSF.array/huygensPSF.array.sum(), extent=extent)\n",
    "plt.colorbar()\n",
    "plt.title(\"Huygens PSF\")\n",
    "plt.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
}