{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "from matplotlib import pyplot as plt\n",
    "\n",
    "import numpy as np\n",
    "\n",
    "from astropy.modeling import Fittable2DModel, Parameter\n",
    "\n",
    "from scipy.special import kn\n",
    "\n",
    "from numpy import cosh, cos, sin"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "class EdgeOnDisk(Fittable2DModel):\n",
    "    \n",
    "    amplitude = Parameter(default=1)\n",
    "    scale_x = Parameter(default=1)\n",
    "    scale_y = Parameter(default=0.5)\n",
    "    x_0 = Parameter(default=0)\n",
    "    y_0 = Parameter(default=0)\n",
    "    theta = Parameter(default=0)\n",
    "    \n",
    "\n",
    "    @classmethod\n",
    "    def evaluate(cls, x, y, amplitude, scale_x, scale_y, x_0, y_0, theta):\n",
    "        \"\"\"Two dimensional Sersic profile function.\"\"\"\n",
    "\n",
    "\n",
    "\n",
    "        x_maj = abs((x - x_0) * cos(theta) + (y - y_0) * sin(theta))\n",
    "        x_min = -(x - x_0) * sin(theta) + (y - y_0) * cos(theta)\n",
    "        \n",
    "\n",
    "        return amplitude * (x_maj / scale_x) * kn(1, x_maj/scale_x) / (cosh(x_min / scale_y) ** 2)\n",
    "    \n",
    "\n",
    "edge_on = EdgeOnDisk(x_0=251/2, y_0=251/2, scale_x=25, scale_y=10, theta=35)\n",
    "\n",
    "x, y = np.mgrid[:251, :251]\n",
    "\n",
    "z = edge_on(x, y)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 21408 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure()\n",
    "plt.imshow(z)\n",
    "plt.colorbar()\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "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.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
