{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Sherpa Quick Start\n",
    "==========\n",
    "\n",
    "This tutorial shows some basic Sherpa features. More information on Sherpa can be\n",
    "found in the [Sherpa documentation](https://sherpa.readthedocs.io/).\n",
    "\n",
    "Workflow:\n",
    "\n",
    "- create synthetic data: a parabola with noise and error bars\n",
    "- load data in Sherpa\n",
    "- plot data using matplotlib\n",
    "- set, inspect, edit a model to fit the data\n",
    "- fit the data\n",
    "- compute the confidence intervals for the parameters\n",
    "- explore the parameter space\n",
    "\n",
    "First of all, let's activate the inline matplotlib mode. Sherpa seamlessly uses matplotlib to provide immediate visual feedback to the user. Support for matplotlib in Sherpa requires the matplotlib package to be installed."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now, let's create a simple synthetic dataset, using numpy: a parabola between x=-5 and x=5, with some randomly generated noise (the form for `y` is chosen to match the model selected in step 6 below to fit the data, and the random seed used by NumPy is set to make this notebook repeatable):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "np.random.seed(824842)\n",
    "\n",
    "x = np.arange(-5, 5.1)\n",
    "\n",
    "c0_true = 23.2\n",
    "c1_true = 0\n",
    "c2_true = 1\n",
    "\n",
    "y = c2_true * x*x + c1_true * x + c0_true + np.random.normal(size=x.size)\n",
    "e = np.ones(x.size)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's import Sherpa:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING: imaging routines will not be available, \n",
      "failed to import sherpa.image.ds9_backend due to \n",
      "'RuntimeErr: DS9Win unusable: Could not find ds9 on your PATH'\n"
     ]
    }
   ],
   "source": [
    "from sherpa.astro import ui"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Depending on how you installed Sherpa, certain special features may be enabled or disabled. Sherpa prints some warning messages when it cannot find some of its modules, as shown above. These warnings are benign. You can refer to the Sherpa documentation to find out what additional features you can enable in Sherpa and how to enable them."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's load and plot the data we just created. Notice we are assigning the ID `mydata` to the dataset we are loading. We will use this ID to refer to the same dataset in the rest of the tutorial. Sherpa can deal with multiple datasets, fit them simultaneously with the same model, and even link parameters between models. Sherpa can read ASCII table and FITS files (provided the `astropy` package is installed)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 12468 characters]\n",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ui.load_arrays(\"mydata\", x, y, e)\n",
    "ui.plot_data(\"mydata\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The data can be retrieved with the `get_data` routine:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name      = \n",
      "x         = Float64[11]\n",
      "y         = Float64[11]\n",
      "staterror = Float64[11]\n",
      "syserror  = None\n"
     ]
    }
   ],
   "source": [
    "d = ui.get_data(\"mydata\")\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The object - in this case a [Data1D object](https://sherpa.readthedocs.io/en/latest/data/api/sherpa.data.Data1D.html) - has support for Jupyter notebooks and will display a summary of \n",
    "the data (in this case a plot, but other objects will display differently, as we will see below):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>/*\n",
       "Copyright (C) 2020  Smithsonian Astrophysical Observatory\n",
       "\n",
       "\n",
       " This program is free software; you can redistribute it and/or modify\n",
       " it under the terms of the GNU General Public License as published by\n",
       " the Free Software Foundation; either version 3 of the License, or\n",
       " (at your option) any later version.\n",
       "\n",
       " This program is distributed in the hope that it will be useful,\n",
       " but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
       " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n",
       " GNU General Public License for more details.\n",
       "\n",
       " You should have received a copy of the GNU General Public License along\n",
       " with this program; if not, write to the Free Software Foundation, Inc.,\n",
       " 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n",
       "\n",
       "*/\n",
       "\n",
       ":root {\n",
       "  --sherpa-border-color: var(--jp-border-color2, #e0e0e0);\n",
       "  --sherpa-background-color: var(--jp-layout-color0, white);\n",
       "  --sherpa-background-color-row-even: var(--jp-layout-color1, white);\n",
       "  --sherpa-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
       "\n",
       "  /* https://medium.com/ge-design/iot-cool-gray-is-a-great-background-color-for-data-visualization-ebf18c318418 */\n",
       "  --sherpa-background-color-dark1: #EBEFF2;\n",
       "  --sherpa-background-color-dark2: #D8E0E5;\n",
       "}\n",
       "\n",
       "div.sherpa-text-fallback {\n",
       "    display: none;\n",
       "}\n",
       "\n",
       "div.sherpa {\n",
       "    display: block;\n",
       "}\n",
       "\n",
       "div.sherpa details summary {\n",
       "    display: list-item;  /* needed for notebook, not lab */\n",
       "    font-size: larger;\n",
       "}\n",
       "\n",
       "div.sherpa details div.datavals {\n",
       "    display: grid;\n",
       "    grid-template-columns: 1fr 3fr;\n",
       "    column-gap: 0.5em;\n",
       "}\n",
       "\n",
       "div.sherpa div.dataname {\n",
       "    font-weight: bold;\n",
       "    border-right: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa div.dataval { }\n",
       "\n",
       "div.sherpa div.datavals div:nth-child(4n + 1) ,\n",
       "div.sherpa div.datavals div:nth-child(4n + 2) {\n",
       "    background: var(--sherpa-background-color-row-odd);\n",
       "}\n",
       "\n",
       "div.sherpa table.model tbody {\n",
       "    border-bottom: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa table.model tr.block {\n",
       "    border-top: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa table.model th.model-odd ,\n",
       "div.sherpa table.model th.model-even {\n",
       "    border-right: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa table.model th.model-odd {\n",
       "    background: var(--sherpa-background-color-dark1);\n",
       "}\n",
       "\n",
       "div.sherpa table.model th.model-even {\n",
       "    background: var(--sherpa-background-color-dark2);\n",
       "}\n",
       "\n",
       "div.sherpa .failed {\n",
       "    background: orange;\n",
       "    font-size: large;\n",
       "    padding: 1em;\n",
       "}\n",
       "</style><div class=\"sherpa-text-fallback\">&lt;Data1D data set instance &#x27;&#x27;&gt;</div><div hidden class=\"sherpa\"><style>/*\n",
       "Copyright (C) 2020  Smithsonian Astrophysical Observatory\n",
       "\n",
       "\n",
       " This program is free software; you can redistribute it and/or modify\n",
       " it under the terms of the GNU General Public License as published by\n",
       " the Free Software Foundation; either version 3 of the License, or\n",
       " (at your option) any later version.\n",
       "\n",
       " This program is distributed in the hope that it will be useful,\n",
       " but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
       " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n",
       " GNU General Public License for more details.\n",
       "\n",
       " You should have received a copy of the GNU General Public License along\n",
       " with this program; if not, write to the Free Software Foundation, Inc.,\n",
       " 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n",
       "\n",
       "*/\n",
       "\n",
       ":root {\n",
       "  --sherpa-border-color: var(--jp-border-color2, #e0e0e0);\n",
       "  --sherpa-background-color: var(--jp-layout-color0, white);\n",
       "  --sherpa-background-color-row-even: var(--jp-layout-color1, white);\n",
       "  --sherpa-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
       "\n",
       "  /* https://medium.com/ge-design/iot-cool-gray-is-a-great-background-color-for-data-visualization-ebf18c318418 */\n",
       "  --sherpa-background-color-dark1: #EBEFF2;\n",
       "  --sherpa-background-color-dark2: #D8E0E5;\n",
       "}\n",
       "\n",
       "div.sherpa-text-fallback {\n",
       "    display: none;\n",
       "}\n",
       "\n",
       "div.sherpa {\n",
       "    display: block;\n",
       "}\n",
       "\n",
       "div.sherpa details summary {\n",
       "    display: list-item;  /* needed for notebook, not lab */\n",
       "    font-size: larger;\n",
       "}\n",
       "\n",
       "div.sherpa details div.datavals {\n",
       "    display: grid;\n",
       "    grid-template-columns: 1fr 3fr;\n",
       "    column-gap: 0.5em;\n",
       "}\n",
       "\n",
       "div.sherpa div.dataname {\n",
       "    font-weight: bold;\n",
       "    border-right: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa div.dataval { }\n",
       "\n",
       "div.sherpa div.datavals div:nth-child(4n + 1) ,\n",
       "div.sherpa div.datavals div:nth-child(4n + 2) {\n",
       "    background: var(--sherpa-background-color-row-odd);\n",
       "}\n",
       "\n",
       "div.sherpa table.model tbody {\n",
       "    border-bottom: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa table.model tr.block {\n",
       "    border-top: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa table.model th.model-odd ,\n",
       "div.sherpa table.model th.model-even {\n",
       "    border-right: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa table.model th.model-odd {\n",
       "    background: var(--sherpa-background-color-dark1);\n",
       "}\n",
       "\n",
       "div.sherpa table.model th.model-even {\n",
       "    background: var(--sherpa-background-color-dark2);\n",
       "}\n",
       "\n",
       "div.sherpa .failed {\n",
       "    background: orange;\n",
       "    font-size: large;\n",
       "    padding: 1em;\n",
       "}\n",
       "</style><div class=\"sherpa-text-fallback\">&lt;sherpa.plot.DataPlot object at 0x7f76c7abacb0&gt;</div><div hidden class=\"sherpa\"><details open><summary>Data1D Plot</summary><svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"460.8pt\" height=\"345.6pt\" viewBox=\"0 0 460.8 345.6\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n",
       " <metadata>\n",
       "  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n",
       "   <cc:Work>\n",
       "    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n",
       "    <dc:date>2022-09-12T16:54:10.812098</dc:date>\n",
       "    <dc:format>image/svg+xml</dc:format>\n",
       "    <dc:creator>\n",
       "     <cc:Agent>\n",
       "      <dc:title>Matplotlib v3.5.2, https://matplotlib.org/</dc:title>\n",
       "     </cc:Agent>\n",
       "    </dc:creator>\n",
       "   </cc:Work>\n",
       "  </rdf:RDF>\n",
       " </metadata>\n",
       " <defs>\n",
       "  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 345.6 \n",
       "L 460.8 345.6 \n",
       "L 460.8 0 \n",
       "L 0 0 \n",
       "z\n",
       "\" style=\"fill: #ffffff\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path d=\"M 57.6 307.584 \n",
       "L 414.72 307.584 \n",
       "L 414.72 41.472 \n",
       "L 57.6 41.472 \n",
       "z\n",
       "\" style=\"fill: #ffffff\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\">\n",
       "    <g id=\"xtick_1\">\n",
       "     <g id=\"line2d_1\">\n",
       "      <defs>\n",
       "       <path id=\"m8b217ff0da\" d=\"M 0 0 \n",
       "L 0 3.5 \n",
       "\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </defs>\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8b217ff0da\" x=\"106.298182\" y=\"307.584\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_1\">\n",
       "      <!-- −4 -->\n",
       "      <g transform=\"translate(98.927088 322.182437)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \n",
       "L 4684 2272 \n",
       "L 4684 1741 \n",
       "L 678 1741 \n",
       "L 678 2272 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n",
       "L 825 1625 \n",
       "L 2419 1625 \n",
       "L 2419 4116 \n",
       "z\n",
       "M 2253 4666 \n",
       "L 3047 4666 \n",
       "L 3047 1625 \n",
       "L 3713 1625 \n",
       "L 3713 1100 \n",
       "L 3047 1100 \n",
       "L 3047 0 \n",
       "L 2419 0 \n",
       "L 2419 1100 \n",
       "L 313 1100 \n",
       "L 313 1709 \n",
       "L 2253 4666 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-2212\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-34\" x=\"83.789062\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_2\">\n",
       "     <g id=\"line2d_2\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8b217ff0da\" x=\"171.229091\" y=\"307.584\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_2\">\n",
       "      <!-- −2 -->\n",
       "      <g transform=\"translate(163.857997 322.182437)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n",
       "L 3431 531 \n",
       "L 3431 0 \n",
       "L 469 0 \n",
       "L 469 531 \n",
       "Q 828 903 1448 1529 \n",
       "Q 2069 2156 2228 2338 \n",
       "Q 2531 2678 2651 2914 \n",
       "Q 2772 3150 2772 3378 \n",
       "Q 2772 3750 2511 3984 \n",
       "Q 2250 4219 1831 4219 \n",
       "Q 1534 4219 1204 4116 \n",
       "Q 875 4013 500 3803 \n",
       "L 500 4441 \n",
       "Q 881 4594 1212 4672 \n",
       "Q 1544 4750 1819 4750 \n",
       "Q 2544 4750 2975 4387 \n",
       "Q 3406 4025 3406 3419 \n",
       "Q 3406 3131 3298 2873 \n",
       "Q 3191 2616 2906 2266 \n",
       "Q 2828 2175 2409 1742 \n",
       "Q 1991 1309 1228 531 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-2212\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-32\" x=\"83.789062\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_3\">\n",
       "     <g id=\"line2d_3\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8b217ff0da\" x=\"236.16\" y=\"307.584\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_3\">\n",
       "      <!-- 0 -->\n",
       "      <g transform=\"translate(232.97875 322.182437)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n",
       "Q 1547 4250 1301 3770 \n",
       "Q 1056 3291 1056 2328 \n",
       "Q 1056 1369 1301 889 \n",
       "Q 1547 409 2034 409 \n",
       "Q 2525 409 2770 889 \n",
       "Q 3016 1369 3016 2328 \n",
       "Q 3016 3291 2770 3770 \n",
       "Q 2525 4250 2034 4250 \n",
       "z\n",
       "M 2034 4750 \n",
       "Q 2819 4750 3233 4129 \n",
       "Q 3647 3509 3647 2328 \n",
       "Q 3647 1150 3233 529 \n",
       "Q 2819 -91 2034 -91 \n",
       "Q 1250 -91 836 529 \n",
       "Q 422 1150 422 2328 \n",
       "Q 422 3509 836 4129 \n",
       "Q 1250 4750 2034 4750 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-30\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_4\">\n",
       "     <g id=\"line2d_4\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8b217ff0da\" x=\"301.090909\" y=\"307.584\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_4\">\n",
       "      <!-- 2 -->\n",
       "      <g transform=\"translate(297.909659 322.182437)scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_5\">\n",
       "     <g id=\"line2d_5\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m8b217ff0da\" x=\"366.021818\" y=\"307.584\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_5\">\n",
       "      <!-- 4 -->\n",
       "      <g transform=\"translate(362.840568 322.182437)scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-34\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_6\">\n",
       "     <!-- x -->\n",
       "     <g transform=\"translate(233.200625 335.860562)scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path id=\"DejaVuSans-78\" d=\"M 3513 3500 \n",
       "L 2247 1797 \n",
       "L 3578 0 \n",
       "L 2900 0 \n",
       "L 1881 1375 \n",
       "L 863 0 \n",
       "L 184 0 \n",
       "L 1544 1831 \n",
       "L 300 3500 \n",
       "L 978 3500 \n",
       "L 1906 2253 \n",
       "L 2834 3500 \n",
       "L 3513 3500 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use xlink:href=\"#DejaVuSans-78\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_2\">\n",
       "    <g id=\"ytick_1\">\n",
       "     <g id=\"line2d_6\">\n",
       "      <defs>\n",
       "       <path id=\"m95f29963d7\" d=\"M 0 0 \n",
       "L -3.5 0 \n",
       "\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </defs>\n",
       "      <g>\n",
       "       <use xlink:href=\"#m95f29963d7\" x=\"57.6\" y=\"299.048386\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_7\">\n",
       "      <!-- 20 -->\n",
       "      <g transform=\"translate(37.875 302.847604)scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_2\">\n",
       "     <g id=\"line2d_7\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m95f29963d7\" x=\"57.6\" y=\"259.641907\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_8\">\n",
       "      <!-- 25 -->\n",
       "      <g transform=\"translate(37.875 263.441126)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n",
       "L 3169 4666 \n",
       "L 3169 4134 \n",
       "L 1269 4134 \n",
       "L 1269 2991 \n",
       "Q 1406 3038 1543 3061 \n",
       "Q 1681 3084 1819 3084 \n",
       "Q 2600 3084 3056 2656 \n",
       "Q 3513 2228 3513 1497 \n",
       "Q 3513 744 3044 326 \n",
       "Q 2575 -91 1722 -91 \n",
       "Q 1428 -91 1123 -41 \n",
       "Q 819 9 494 109 \n",
       "L 494 744 \n",
       "Q 775 591 1075 516 \n",
       "Q 1375 441 1709 441 \n",
       "Q 2250 441 2565 725 \n",
       "Q 2881 1009 2881 1497 \n",
       "Q 2881 1984 2565 2268 \n",
       "Q 2250 2553 1709 2553 \n",
       "Q 1456 2553 1204 2497 \n",
       "Q 953 2441 691 2322 \n",
       "L 691 4666 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-35\" x=\"63.623047\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_3\">\n",
       "     <g id=\"line2d_8\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m95f29963d7\" x=\"57.6\" y=\"220.235428\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_9\">\n",
       "      <!-- 30 -->\n",
       "      <g transform=\"translate(37.875 224.034647)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \n",
       "Q 3050 2419 3304 2112 \n",
       "Q 3559 1806 3559 1356 \n",
       "Q 3559 666 3084 287 \n",
       "Q 2609 -91 1734 -91 \n",
       "Q 1441 -91 1130 -33 \n",
       "Q 819 25 488 141 \n",
       "L 488 750 \n",
       "Q 750 597 1062 519 \n",
       "Q 1375 441 1716 441 \n",
       "Q 2309 441 2620 675 \n",
       "Q 2931 909 2931 1356 \n",
       "Q 2931 1769 2642 2001 \n",
       "Q 2353 2234 1838 2234 \n",
       "L 1294 2234 \n",
       "L 1294 2753 \n",
       "L 1863 2753 \n",
       "Q 2328 2753 2575 2939 \n",
       "Q 2822 3125 2822 3475 \n",
       "Q 2822 3834 2567 4026 \n",
       "Q 2313 4219 1838 4219 \n",
       "Q 1578 4219 1281 4162 \n",
       "Q 984 4106 628 3988 \n",
       "L 628 4550 \n",
       "Q 988 4650 1302 4700 \n",
       "Q 1616 4750 1894 4750 \n",
       "Q 2613 4750 3031 4423 \n",
       "Q 3450 4097 3450 3541 \n",
       "Q 3450 3153 3228 2886 \n",
       "Q 3006 2619 2597 2516 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-33\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_4\">\n",
       "     <g id=\"line2d_9\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m95f29963d7\" x=\"57.6\" y=\"180.82895\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_10\">\n",
       "      <!-- 35 -->\n",
       "      <g transform=\"translate(37.875 184.628168)scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-33\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-35\" x=\"63.623047\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_5\">\n",
       "     <g id=\"line2d_10\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m95f29963d7\" x=\"57.6\" y=\"141.422471\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_11\">\n",
       "      <!-- 40 -->\n",
       "      <g transform=\"translate(37.875 145.22169)scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-34\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_6\">\n",
       "     <g id=\"line2d_11\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m95f29963d7\" x=\"57.6\" y=\"102.015992\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_12\">\n",
       "      <!-- 45 -->\n",
       "      <g transform=\"translate(37.875 105.815211)scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-34\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-35\" x=\"63.623047\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_7\">\n",
       "     <g id=\"line2d_12\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m95f29963d7\" x=\"57.6\" y=\"62.609514\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_13\">\n",
       "      <!-- 50 -->\n",
       "      <g transform=\"translate(37.875 66.408733)scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-35\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_14\">\n",
       "     <!-- y -->\n",
       "     <g transform=\"translate(31.795313 177.487375)rotate(-90)scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \n",
       "Q 1816 -950 1584 -1140 \n",
       "Q 1353 -1331 966 -1331 \n",
       "L 506 -1331 \n",
       "L 506 -850 \n",
       "L 844 -850 \n",
       "Q 1081 -850 1212 -737 \n",
       "Q 1344 -625 1503 -206 \n",
       "L 1606 56 \n",
       "L 191 3500 \n",
       "L 800 3500 \n",
       "L 1894 763 \n",
       "L 2988 3500 \n",
       "L 3597 3500 \n",
       "L 2059 -325 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use xlink:href=\"#DejaVuSans-79\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"LineCollection_1\">\n",
       "    <path d=\"M 73.832727 69.330591 \n",
       "L 73.832727 53.568 \n",
       "\" clip-path=\"url(#p5e8223cfac)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n",
       "    <path d=\"M 106.298182 162.490409 \n",
       "L 106.298182 146.727817 \n",
       "\" clip-path=\"url(#p5e8223cfac)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n",
       "    <path d=\"M 138.763636 214.259911 \n",
       "L 138.763636 198.497319 \n",
       "\" clip-path=\"url(#p5e8223cfac)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n",
       "    <path d=\"M 171.229091 235.965447 \n",
       "L 171.229091 220.202856 \n",
       "\" clip-path=\"url(#p5e8223cfac)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n",
       "    <path d=\"M 203.694545 280.297888 \n",
       "L 203.694545 264.535297 \n",
       "\" clip-path=\"url(#p5e8223cfac)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n",
       "    <path d=\"M 236.16 295.488 \n",
       "L 236.16 279.725409 \n",
       "\" clip-path=\"url(#p5e8223cfac)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n",
       "    <path d=\"M 268.625455 274.482116 \n",
       "L 268.625455 258.719525 \n",
       "\" clip-path=\"url(#p5e8223cfac)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n",
       "    <path d=\"M 301.090909 232.480843 \n",
       "L 301.090909 216.718251 \n",
       "\" clip-path=\"url(#p5e8223cfac)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n",
       "    <path d=\"M 333.556364 207.182696 \n",
       "L 333.556364 191.420105 \n",
       "\" clip-path=\"url(#p5e8223cfac)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n",
       "    <path d=\"M 366.021818 143.378376 \n",
       "L 366.021818 127.615784 \n",
       "\" clip-path=\"url(#p5e8223cfac)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n",
       "    <path d=\"M 398.487273 82.102431 \n",
       "L 398.487273 66.339839 \n",
       "\" clip-path=\"url(#p5e8223cfac)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_13\">\n",
       "    <defs>\n",
       "     <path id=\"m49afba1ba4\" d=\"M 0 1.5 \n",
       "C 0.397805 1.5 0.77937 1.341951 1.06066 1.06066 \n",
       "C 1.341951 0.77937 1.5 0.397805 1.5 0 \n",
       "C 1.5 -0.397805 1.341951 -0.77937 1.06066 -1.06066 \n",
       "C 0.77937 -1.341951 0.397805 -1.5 0 -1.5 \n",
       "C -0.397805 -1.5 -0.77937 -1.341951 -1.06066 -1.06066 \n",
       "C -1.341951 -0.77937 -1.5 -0.397805 -1.5 0 \n",
       "C -1.5 0.397805 -1.341951 0.77937 -1.06066 1.06066 \n",
       "C -0.77937 1.341951 -0.397805 1.5 0 1.5 \n",
       "z\n",
       "\" style=\"stroke: #1f77b4\"/>\n",
       "    </defs>\n",
       "    <g clip-path=\"url(#p5e8223cfac)\">\n",
       "     <use xlink:href=\"#m49afba1ba4\" x=\"73.832727\" y=\"61.449296\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n",
       "     <use xlink:href=\"#m49afba1ba4\" x=\"106.298182\" y=\"154.609113\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n",
       "     <use xlink:href=\"#m49afba1ba4\" x=\"138.763636\" y=\"206.378615\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n",
       "     <use xlink:href=\"#m49afba1ba4\" x=\"171.229091\" y=\"228.084151\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n",
       "     <use xlink:href=\"#m49afba1ba4\" x=\"203.694545\" y=\"272.416592\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n",
       "     <use xlink:href=\"#m49afba1ba4\" x=\"236.16\" y=\"287.606704\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n",
       "     <use xlink:href=\"#m49afba1ba4\" x=\"268.625455\" y=\"266.600821\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n",
       "     <use xlink:href=\"#m49afba1ba4\" x=\"301.090909\" y=\"224.599547\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n",
       "     <use xlink:href=\"#m49afba1ba4\" x=\"333.556364\" y=\"199.3014\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n",
       "     <use xlink:href=\"#m49afba1ba4\" x=\"366.021818\" y=\"135.49708\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n",
       "     <use xlink:href=\"#m49afba1ba4\" x=\"398.487273\" y=\"74.221135\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path d=\"M 57.6 307.584 \n",
       "L 57.6 41.472 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path d=\"M 414.72 307.584 \n",
       "L 414.72 41.472 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path d=\"M 57.6 307.584 \n",
       "L 414.72 307.584 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path d=\"M 57.6 41.472 \n",
       "L 414.72 41.472 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p5e8223cfac\">\n",
       "   <rect x=\"57.6\" y=\"41.472\" width=\"357.12\" height=\"266.112\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n",
       "</details></div></div>"
      ],
      "text/plain": [
       "<Data1D data set instance ''>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can set the model we want to fit to the data using the `set_model` call. There are different ways to instantiate the models: in this case, we just use the string `polynom1d` to refer to a 1D polynomial. The name of the model will be `poly`, and will be accessible as a Python variable. One can use more object oriented patterns to access and instantiate built-in models. Also, new models can be added by the user as Python functions or from tabular data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "ui.set_model(\"mydata\", \"polynom1d.poly\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Several Sherpa commands can be used to inspect the model. In this case we just use a simple `print` to get a summary of the model and its components."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "polynom1d.poly\n",
      "   Param        Type          Value          Min          Max      Units\n",
      "   -----        ----          -----          ---          ---      -----\n",
      "   poly.c0      thawed            1 -3.40282e+38  3.40282e+38           \n",
      "   poly.c1      frozen            0 -3.40282e+38  3.40282e+38           \n",
      "   poly.c2      frozen            0 -3.40282e+38  3.40282e+38           \n",
      "   poly.c3      frozen            0 -3.40282e+38  3.40282e+38           \n",
      "   poly.c4      frozen            0 -3.40282e+38  3.40282e+38           \n",
      "   poly.c5      frozen            0 -3.40282e+38  3.40282e+38           \n",
      "   poly.c6      frozen            0 -3.40282e+38  3.40282e+38           \n",
      "   poly.c7      frozen            0 -3.40282e+38  3.40282e+38           \n",
      "   poly.c8      frozen            0 -3.40282e+38  3.40282e+38           \n",
      "   poly.offset  frozen            0 -3.40282e+38  3.40282e+38           \n"
     ]
    }
   ],
   "source": [
    "print(poly)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can also display it directly in a Jupyter notebook:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>/*\n",
       "Copyright (C) 2020  Smithsonian Astrophysical Observatory\n",
       "\n",
       "\n",
       " This program is free software; you can redistribute it and/or modify\n",
       " it under the terms of the GNU General Public License as published by\n",
       " the Free Software Foundation; either version 3 of the License, or\n",
       " (at your option) any later version.\n",
       "\n",
       " This program is distributed in the hope that it will be useful,\n",
       " but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
       " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n",
       " GNU General Public License for more details.\n",
       "\n",
       " You should have received a copy of the GNU General Public License along\n",
       " with this program; if not, write to the Free Software Foundation, Inc.,\n",
       " 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n",
       "\n",
       "*/\n",
       "\n",
       ":root {\n",
       "  --sherpa-border-color: var(--jp-border-color2, #e0e0e0);\n",
       "  --sherpa-background-color: var(--jp-layout-color0, white);\n",
       "  --sherpa-background-color-row-even: var(--jp-layout-color1, white);\n",
       "  --sherpa-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
       "\n",
       "  /* https://medium.com/ge-design/iot-cool-gray-is-a-great-background-color-for-data-visualization-ebf18c318418 */\n",
       "  --sherpa-background-color-dark1: #EBEFF2;\n",
       "  --sherpa-background-color-dark2: #D8E0E5;\n",
       "}\n",
       "\n",
       "div.sherpa-text-fallback {\n",
       "    display: none;\n",
       "}\n",
       "\n",
       "div.sherpa {\n",
       "    display: block;\n",
       "}\n",
       "\n",
       "div.sherpa details summary {\n",
       "    display: list-item;  /* needed for notebook, not lab */\n",
       "    font-size: larger;\n",
       "}\n",
       "\n",
       "div.sherpa details div.datavals {\n",
       "    display: grid;\n",
       "    grid-template-columns: 1fr 3fr;\n",
       "    column-gap: 0.5em;\n",
       "}\n",
       "\n",
       "div.sherpa div.dataname {\n",
       "    font-weight: bold;\n",
       "    border-right: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa div.dataval { }\n",
       "\n",
       "div.sherpa div.datavals div:nth-child(4n + 1) ,\n",
       "div.sherpa div.datavals div:nth-child(4n + 2) {\n",
       "    background: var(--sherpa-background-color-row-odd);\n",
       "}\n",
       "\n",
       "div.sherpa table.model tbody {\n",
       "    border-bottom: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa table.model tr.block {\n",
       "    border-top: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa table.model th.model-odd ,\n",
       "div.sherpa table.model th.model-even {\n",
       "    border-right: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa table.model th.model-odd {\n",
       "    background: var(--sherpa-background-color-dark1);\n",
       "}\n",
       "\n",
       "div.sherpa table.model th.model-even {\n",
       "    background: var(--sherpa-background-color-dark2);\n",
       "}\n",
       "\n",
       "div.sherpa .failed {\n",
       "    background: orange;\n",
       "    font-size: large;\n",
       "    padding: 1em;\n",
       "}\n",
       "</style><div class=\"sherpa-text-fallback\">&lt;Polynom1D model instance &#x27;polynom1d.poly&#x27;&gt;</div><div hidden class=\"sherpa\"><details open><summary>Model</summary><table class=\"model\"><caption>Expression: polynom1d.poly</caption><thead><tr><th>Component</th><th>Parameter</th><th>Thawed</th><th>Value</th><th>Min</th><th>Max</th><th>Units</th></tr></thead><tbody><tr><th class=\"model-odd\" scope=\"rowgroup\" rowspan=10>polynom1d.poly</th><td>c0</td><td><input disabled type=\"checkbox\" checked></input></td><td>1.0</td><td>-MAX</td><td>MAX</td><td></td></tr><tr><td>c1</td><td><input disabled type=\"checkbox\"></input></td><td>0.0</td><td>-MAX</td><td>MAX</td><td></td></tr><tr><td>c2</td><td><input disabled type=\"checkbox\"></input></td><td>0.0</td><td>-MAX</td><td>MAX</td><td></td></tr><tr><td>c3</td><td><input disabled type=\"checkbox\"></input></td><td>0.0</td><td>-MAX</td><td>MAX</td><td></td></tr><tr><td>c4</td><td><input disabled type=\"checkbox\"></input></td><td>0.0</td><td>-MAX</td><td>MAX</td><td></td></tr><tr><td>c5</td><td><input disabled type=\"checkbox\"></input></td><td>0.0</td><td>-MAX</td><td>MAX</td><td></td></tr><tr><td>c6</td><td><input disabled type=\"checkbox\"></input></td><td>0.0</td><td>-MAX</td><td>MAX</td><td></td></tr><tr><td>c7</td><td><input disabled type=\"checkbox\"></input></td><td>0.0</td><td>-MAX</td><td>MAX</td><td></td></tr><tr><td>c8</td><td><input disabled type=\"checkbox\"></input></td><td>0.0</td><td>-MAX</td><td>MAX</td><td></td></tr><tr><td>offset</td><td><input disabled type=\"checkbox\"></input></td><td>0.0</td><td>-MAX</td><td>MAX</td><td></td></tr></tbody></table></details></div>"
      ],
      "text/plain": [
       "<Polynom1D model instance 'polynom1d.poly'>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "poly"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "By default, only the first component (the intercept) is __thawed__, i.e. is free to vary in the fit. This corresponds to a constant function. In order to fit a parabola, we need to __thaw__ the coefficients of the first two orders in the polynomial, as shown below."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "ui.thaw(poly.c1, poly.c2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We are going to fit the dataset using the default settings. However, Sherpa has a number of optimization algorithms, each configurable by the user, and a number of statistics that can be used to take into account the error and other characteristics of data being fitted."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dataset               = mydata\n",
      "Method                = levmar\n",
      "Statistic             = chi2\n",
      "Initial fit statistic = 12642.8\n",
      "Final fit statistic   = 15.643 at function evaluation 8\n",
      "Data points           = 11\n",
      "Degrees of freedom    = 8\n",
      "Probability [Q-value] = 0.0477837\n",
      "Reduced statistic     = 1.95538\n",
      "Change in statistic   = 12627.2\n",
      "   poly.c0        23.1367      +/- 0.455477    \n",
      "   poly.c1        0.0537585    +/- 0.0953463   \n",
      "   poly.c2        1.04602      +/- 0.0341394   \n"
     ]
    }
   ],
   "source": [
    "ui.fit(\"mydata\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Notice that Sherpa used a Levenberg-Marquadt minimization strategy (`levmar`), and the $\\chi^2$ error function (`chi2`). These options can be changed with the `set_method` and `set_stat` functions. Note that when using the `levmar` optimiser the fit results include approximate error estimates, but you should use the `conf` routine (shown below) to get accurate error estimates.\n",
    "\n",
    "The best fit values of the parameters are close to the ones defined when we generated the dataset:\n",
    "\n",
    "| Parameter | true value | best-fit value |\n",
    "| --------- | ---------- | -------------- |\n",
    "| $c_0$     | 23.2       | 23.1367        |\n",
    "| $c_1$     | 0          | 0.0538         |\n",
    "| $c_2$     | 1          | 1.0460         |\n",
    "\n",
    "The `get_fit_results` function will return the information on the last fit:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "datasets       = ('mydata',)\n",
      "itermethodname = none\n",
      "methodname     = levmar\n",
      "statname       = chi2\n",
      "succeeded      = True\n",
      "parnames       = ('poly.c0', 'poly.c1', 'poly.c2')\n",
      "parvals        = (23.136688550821013, 0.05375853511753547, 1.046015029290237)\n",
      "statval        = 15.6430444797243\n",
      "istatval       = 12642.832375778722\n",
      "dstatval       = 12627.189331298998\n",
      "numpoints      = 11\n",
      "dof            = 8\n",
      "qval           = 0.04778369987400388\n",
      "rstat          = 1.9553805599655374\n",
      "message        = successful termination\n",
      "nfev           = 8\n"
     ]
    }
   ],
   "source": [
    "fitres = ui.get_fit_results()\n",
    "print(fitres)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Perhaps unsurprisingly by now, it too can be displayed automatically in a Jupyter notebook:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>/*\n",
       "Copyright (C) 2020  Smithsonian Astrophysical Observatory\n",
       "\n",
       "\n",
       " This program is free software; you can redistribute it and/or modify\n",
       " it under the terms of the GNU General Public License as published by\n",
       " the Free Software Foundation; either version 3 of the License, or\n",
       " (at your option) any later version.\n",
       "\n",
       " This program is distributed in the hope that it will be useful,\n",
       " but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
       " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n",
       " GNU General Public License for more details.\n",
       "\n",
       " You should have received a copy of the GNU General Public License along\n",
       " with this program; if not, write to the Free Software Foundation, Inc.,\n",
       " 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n",
       "\n",
       "*/\n",
       "\n",
       ":root {\n",
       "  --sherpa-border-color: var(--jp-border-color2, #e0e0e0);\n",
       "  --sherpa-background-color: var(--jp-layout-color0, white);\n",
       "  --sherpa-background-color-row-even: var(--jp-layout-color1, white);\n",
       "  --sherpa-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
       "\n",
       "  /* https://medium.com/ge-design/iot-cool-gray-is-a-great-background-color-for-data-visualization-ebf18c318418 */\n",
       "  --sherpa-background-color-dark1: #EBEFF2;\n",
       "  --sherpa-background-color-dark2: #D8E0E5;\n",
       "}\n",
       "\n",
       "div.sherpa-text-fallback {\n",
       "    display: none;\n",
       "}\n",
       "\n",
       "div.sherpa {\n",
       "    display: block;\n",
       "}\n",
       "\n",
       "div.sherpa details summary {\n",
       "    display: list-item;  /* needed for notebook, not lab */\n",
       "    font-size: larger;\n",
       "}\n",
       "\n",
       "div.sherpa details div.datavals {\n",
       "    display: grid;\n",
       "    grid-template-columns: 1fr 3fr;\n",
       "    column-gap: 0.5em;\n",
       "}\n",
       "\n",
       "div.sherpa div.dataname {\n",
       "    font-weight: bold;\n",
       "    border-right: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa div.dataval { }\n",
       "\n",
       "div.sherpa div.datavals div:nth-child(4n + 1) ,\n",
       "div.sherpa div.datavals div:nth-child(4n + 2) {\n",
       "    background: var(--sherpa-background-color-row-odd);\n",
       "}\n",
       "\n",
       "div.sherpa table.model tbody {\n",
       "    border-bottom: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa table.model tr.block {\n",
       "    border-top: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa table.model th.model-odd ,\n",
       "div.sherpa table.model th.model-even {\n",
       "    border-right: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa table.model th.model-odd {\n",
       "    background: var(--sherpa-background-color-dark1);\n",
       "}\n",
       "\n",
       "div.sherpa table.model th.model-even {\n",
       "    background: var(--sherpa-background-color-dark2);\n",
       "}\n",
       "\n",
       "div.sherpa .failed {\n",
       "    background: orange;\n",
       "    font-size: large;\n",
       "    padding: 1em;\n",
       "}\n",
       "</style><div class=\"sherpa-text-fallback\">&lt;Fit results instance&gt;</div><div hidden class=\"sherpa\"><details open><summary>Fit parameters</summary><table class=\"fit\"><thead><tr><th>Parameter</th><th>Best-fit value</th><th>Approximate error</th></tr></thead><tbody><tr><td>poly.c0</td><td>     23.1367</td><td>&#177;     0.455477</td></tr><tr><td>poly.c1</td><td>   0.0537585</td><td>&#177;    0.0953463</td></tr><tr><td>poly.c2</td><td>     1.04602</td><td>&#177;    0.0341394</td></tr></tbody></table></details><details><summary>Summary (11)</summary><div class=\"datavals\"><div class=\"dataname\">Dataset</div><div class=\"dataval\">mydata</div><div class=\"dataname\">Method</div><div class=\"dataval\">levmar</div><div class=\"dataname\">Statistic</div><div class=\"dataval\">chi2</div><div class=\"dataname\">Final statistic</div><div class=\"dataval\">15.643</div><div class=\"dataname\">Number of evaluations</div><div class=\"dataval\">8</div><div class=\"dataname\">Reduced statistic</div><div class=\"dataval\">1.95538</div><div class=\"dataname\">Probability (Q-value)</div><div class=\"dataval\">0.0477837</div><div class=\"dataname\">Initial statistic</div><div class=\"dataval\">12642.8</div><div class=\"dataname\">&#916; statistic</div><div class=\"dataval\">12627.2</div><div class=\"dataname\">Number of data points</div><div class=\"dataval\">11</div><div class=\"dataname\">Degrees of freedom</div><div class=\"dataval\">8</div></div></details></div>"
      ],
      "text/plain": [
       "<Fit results instance>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fitres"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The model object has also been updated by the fit:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>/*\n",
       "Copyright (C) 2020  Smithsonian Astrophysical Observatory\n",
       "\n",
       "\n",
       " This program is free software; you can redistribute it and/or modify\n",
       " it under the terms of the GNU General Public License as published by\n",
       " the Free Software Foundation; either version 3 of the License, or\n",
       " (at your option) any later version.\n",
       "\n",
       " This program is distributed in the hope that it will be useful,\n",
       " but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
       " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n",
       " GNU General Public License for more details.\n",
       "\n",
       " You should have received a copy of the GNU General Public License along\n",
       " with this program; if not, write to the Free Software Foundation, Inc.,\n",
       " 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n",
       "\n",
       "*/\n",
       "\n",
       ":root {\n",
       "  --sherpa-border-color: var(--jp-border-color2, #e0e0e0);\n",
       "  --sherpa-background-color: var(--jp-layout-color0, white);\n",
       "  --sherpa-background-color-row-even: var(--jp-layout-color1, white);\n",
       "  --sherpa-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
       "\n",
       "  /* https://medium.com/ge-design/iot-cool-gray-is-a-great-background-color-for-data-visualization-ebf18c318418 */\n",
       "  --sherpa-background-color-dark1: #EBEFF2;\n",
       "  --sherpa-background-color-dark2: #D8E0E5;\n",
       "}\n",
       "\n",
       "div.sherpa-text-fallback {\n",
       "    display: none;\n",
       "}\n",
       "\n",
       "div.sherpa {\n",
       "    display: block;\n",
       "}\n",
       "\n",
       "div.sherpa details summary {\n",
       "    display: list-item;  /* needed for notebook, not lab */\n",
       "    font-size: larger;\n",
       "}\n",
       "\n",
       "div.sherpa details div.datavals {\n",
       "    display: grid;\n",
       "    grid-template-columns: 1fr 3fr;\n",
       "    column-gap: 0.5em;\n",
       "}\n",
       "\n",
       "div.sherpa div.dataname {\n",
       "    font-weight: bold;\n",
       "    border-right: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa div.dataval { }\n",
       "\n",
       "div.sherpa div.datavals div:nth-child(4n + 1) ,\n",
       "div.sherpa div.datavals div:nth-child(4n + 2) {\n",
       "    background: var(--sherpa-background-color-row-odd);\n",
       "}\n",
       "\n",
       "div.sherpa table.model tbody {\n",
       "    border-bottom: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa table.model tr.block {\n",
       "    border-top: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa table.model th.model-odd ,\n",
       "div.sherpa table.model th.model-even {\n",
       "    border-right: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa table.model th.model-odd {\n",
       "    background: var(--sherpa-background-color-dark1);\n",
       "}\n",
       "\n",
       "div.sherpa table.model th.model-even {\n",
       "    background: var(--sherpa-background-color-dark2);\n",
       "}\n",
       "\n",
       "div.sherpa .failed {\n",
       "    background: orange;\n",
       "    font-size: large;\n",
       "    padding: 1em;\n",
       "}\n",
       "</style><div class=\"sherpa-text-fallback\">&lt;Polynom1D model instance &#x27;polynom1d.poly&#x27;&gt;</div><div hidden class=\"sherpa\"><details open><summary>Model</summary><table class=\"model\"><caption>Expression: polynom1d.poly</caption><thead><tr><th>Component</th><th>Parameter</th><th>Thawed</th><th>Value</th><th>Min</th><th>Max</th><th>Units</th></tr></thead><tbody><tr><th class=\"model-odd\" scope=\"rowgroup\" rowspan=10>polynom1d.poly</th><td>c0</td><td><input disabled type=\"checkbox\" checked></input></td><td>23.136688550821013</td><td>-MAX</td><td>MAX</td><td></td></tr><tr><td>c1</td><td><input disabled type=\"checkbox\" checked></input></td><td>0.05375853511753547</td><td>-MAX</td><td>MAX</td><td></td></tr><tr><td>c2</td><td><input disabled type=\"checkbox\" checked></input></td><td>1.046015029290237</td><td>-MAX</td><td>MAX</td><td></td></tr><tr><td>c3</td><td><input disabled type=\"checkbox\"></input></td><td>0.0</td><td>-MAX</td><td>MAX</td><td></td></tr><tr><td>c4</td><td><input disabled type=\"checkbox\"></input></td><td>0.0</td><td>-MAX</td><td>MAX</td><td></td></tr><tr><td>c5</td><td><input disabled type=\"checkbox\"></input></td><td>0.0</td><td>-MAX</td><td>MAX</td><td></td></tr><tr><td>c6</td><td><input disabled type=\"checkbox\"></input></td><td>0.0</td><td>-MAX</td><td>MAX</td><td></td></tr><tr><td>c7</td><td><input disabled type=\"checkbox\"></input></td><td>0.0</td><td>-MAX</td><td>MAX</td><td></td></tr><tr><td>c8</td><td><input disabled type=\"checkbox\"></input></td><td>0.0</td><td>-MAX</td><td>MAX</td><td></td></tr><tr><td>offset</td><td><input disabled type=\"checkbox\"></input></td><td>0.0</td><td>-MAX</td><td>MAX</td><td></td></tr></tbody></table></details></div>"
      ],
      "text/plain": [
       "<Polynom1D model instance 'polynom1d.poly'>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "poly"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In order to get immediate feedback of the fit results, we can plot the fit and the residuals. Again, Sherpa facilitates the creation of the plots, but users can harvest the power of matplotlib directly if they want to."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 27236 characters]\n",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ui.plot_fit_resid(\"mydata\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can now compute the confidence intervals for the free parameters in the fit:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "poly.c0 lower bound:\t-0.455477\n",
      "poly.c1 lower bound:\t-0.0953463\n",
      "poly.c0 upper bound:\t0.455477\n",
      "poly.c1 upper bound:\t0.0953463\n",
      "poly.c2 lower bound:\t-0.0341394\n",
      "poly.c2 upper bound:\t0.0341394\n",
      "Dataset               = mydata\n",
      "Confidence Method     = confidence\n",
      "Iterative Fit Method  = None\n",
      "Fitting Method        = levmar\n",
      "Statistic             = chi2gehrels\n",
      "confidence 1-sigma (68.2689%) bounds:\n",
      "   Param            Best-Fit  Lower Bound  Upper Bound\n",
      "   -----            --------  -----------  -----------\n",
      "   poly.c0           23.1367    -0.455477     0.455477\n",
      "   poly.c1         0.0537585   -0.0953463    0.0953463\n",
      "   poly.c2           1.04602   -0.0341394    0.0341394\n"
     ]
    }
   ],
   "source": [
    "ui.conf(\"mydata\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "datasets    = ('mydata',)\n",
      "methodname  = confidence\n",
      "iterfitname = none\n",
      "fitname     = levmar\n",
      "statname    = chi2gehrels\n",
      "sigma       = 1\n",
      "percent     = 68.26894921370858\n",
      "parnames    = ('poly.c0', 'poly.c1', 'poly.c2')\n",
      "parvals     = (23.136688550821013, 0.05375853511753547, 1.046015029290237)\n",
      "parmins     = (-0.4554769011263424, -0.09534625892453424, -0.03413943709996614)\n",
      "parmaxes    = (0.4554769011263424, 0.09534625892453424, 0.03413943709996614)\n",
      "nfits       = 6\n"
     ]
    }
   ],
   "source": [
    "conf = ui.get_conf_results()\n",
    "print(conf)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "or, if you want a fancy display, you can get the Jupter notebook to display it:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>/*\n",
       "Copyright (C) 2020  Smithsonian Astrophysical Observatory\n",
       "\n",
       "\n",
       " This program is free software; you can redistribute it and/or modify\n",
       " it under the terms of the GNU General Public License as published by\n",
       " the Free Software Foundation; either version 3 of the License, or\n",
       " (at your option) any later version.\n",
       "\n",
       " This program is distributed in the hope that it will be useful,\n",
       " but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
       " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n",
       " GNU General Public License for more details.\n",
       "\n",
       " You should have received a copy of the GNU General Public License along\n",
       " with this program; if not, write to the Free Software Foundation, Inc.,\n",
       " 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n",
       "\n",
       "*/\n",
       "\n",
       ":root {\n",
       "  --sherpa-border-color: var(--jp-border-color2, #e0e0e0);\n",
       "  --sherpa-background-color: var(--jp-layout-color0, white);\n",
       "  --sherpa-background-color-row-even: var(--jp-layout-color1, white);\n",
       "  --sherpa-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
       "\n",
       "  /* https://medium.com/ge-design/iot-cool-gray-is-a-great-background-color-for-data-visualization-ebf18c318418 */\n",
       "  --sherpa-background-color-dark1: #EBEFF2;\n",
       "  --sherpa-background-color-dark2: #D8E0E5;\n",
       "}\n",
       "\n",
       "div.sherpa-text-fallback {\n",
       "    display: none;\n",
       "}\n",
       "\n",
       "div.sherpa {\n",
       "    display: block;\n",
       "}\n",
       "\n",
       "div.sherpa details summary {\n",
       "    display: list-item;  /* needed for notebook, not lab */\n",
       "    font-size: larger;\n",
       "}\n",
       "\n",
       "div.sherpa details div.datavals {\n",
       "    display: grid;\n",
       "    grid-template-columns: 1fr 3fr;\n",
       "    column-gap: 0.5em;\n",
       "}\n",
       "\n",
       "div.sherpa div.dataname {\n",
       "    font-weight: bold;\n",
       "    border-right: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa div.dataval { }\n",
       "\n",
       "div.sherpa div.datavals div:nth-child(4n + 1) ,\n",
       "div.sherpa div.datavals div:nth-child(4n + 2) {\n",
       "    background: var(--sherpa-background-color-row-odd);\n",
       "}\n",
       "\n",
       "div.sherpa table.model tbody {\n",
       "    border-bottom: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa table.model tr.block {\n",
       "    border-top: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa table.model th.model-odd ,\n",
       "div.sherpa table.model th.model-even {\n",
       "    border-right: 1px solid var(--sherpa-border-color);\n",
       "}\n",
       "\n",
       "div.sherpa table.model th.model-odd {\n",
       "    background: var(--sherpa-background-color-dark1);\n",
       "}\n",
       "\n",
       "div.sherpa table.model th.model-even {\n",
       "    background: var(--sherpa-background-color-dark2);\n",
       "}\n",
       "\n",
       "div.sherpa .failed {\n",
       "    background: orange;\n",
       "    font-size: large;\n",
       "    padding: 1em;\n",
       "}\n",
       "</style><div class=\"sherpa-text-fallback\">&lt;confidence results instance&gt;</div><div hidden class=\"sherpa\"><details open><summary>confidence 1&#963; (68.2689%) bounds</summary><table><thead><tr><th>Parameter</th><th>Best-fit value</th><th>Lower Bound</th><th>Upper Bound</th></tr></thead><tbody><tr><td>poly.c0</td><td>     23.1367</td><td>   -0.455477</td><td>    0.455477</td></tr><tr><td>poly.c1</td><td>   0.0537585</td><td>  -0.0953463</td><td>   0.0953463</td></tr><tr><td>poly.c2</td><td>     1.04602</td><td>  -0.0341394</td><td>   0.0341394</td></tr></tbody></table></details><details><summary>Summary (3)</summary><div class=\"datavals\"><div class=\"dataname\">Dataset</div><div class=\"dataval\">mydata</div><div class=\"dataname\">Fitting Method</div><div class=\"dataval\">levmar</div><div class=\"dataname\">Statistic</div><div class=\"dataval\">chi2gehrels</div></div></details></div>"
      ],
      "text/plain": [
       "<confidence results instance>"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "conf"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Sherpa allows to inspect the parameter space. In the cell below we ask sherpa to show us the projection of the confidence regions for the `c0` and `c1` parameters. The contours are configurable by the user: by default they show the confidence curves at 1, 2, and 3 $\\sigma$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 50392 characters]\n",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ui.reg_proj(poly.c0, poly.c1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can also directlty inspect the parameter space. For instance, in the plot below Sherpa displays the Interval Projection of the `c0` parameter, i.e. a plot of the error for each value of the parameter, around the minimum found by the optimization method during the fit."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 38616 characters]\n",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ui.int_proj(poly.c0)"
   ]
  }
 ],
 "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.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
