{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Comparison of data and model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this tutorial, the photometric fluxes of the brown dwarf companion PZ Tel B is compared with a spectrum from the AMES-Cond atmospheric model."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Initiating *species*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import species"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Initiating species v0.1.0... [DONE]\n",
      "Creating species_config.ini... [DONE]\n",
      "Database: /Users/tomasstolker/applications/species/docs/tutorials/species_database.hdf5\n",
      "Data folder: /Users/tomasstolker/applications/species/docs/tutorials/data\n",
      "Working folder: /Users/tomasstolker/applications/species/docs/tutorials\n",
      "Creating species_database.hdf5... [DONE]\n",
      "Creating data folder... [DONE]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<species.core.setup.SpeciesInit at 0x12556b5f8>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "species.SpeciesInit()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Adding model spectra"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A `Database` object is now created which can be used for importing of data into the database."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "database = species.Database()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The spectra of the AMES-Cond model are downloaded and added to the database. This requires sufficient disk storage in the *data_folder* that is set in the configuration file.\n",
    "\n",
    "While the full AMES-Cond grid is downloaded, a restiction on the wavelength and T<sub>eff</sub> range can be used when the data is imported. Also the spectral resolution can be set to downsample the high-resolution of the original spectra spectra."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloading AMES-Cond model spectra (823 MB)... [DONE]\n",
      "Unpacking AMES-Cond model spectra (823 MB)... [DONE]\n",
      "Adding AMES-Cond model spectra... [DONE]                                        \n"
     ]
    }
   ],
   "source": [
    "database.add_model(model='ames-cond',\n",
    "                   wavel_range=(0.1, 6.),\n",
    "                   spec_res=1000.\n",
    "                   teff_range=(2800., 3000.))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Adding companion data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The distance and magnitudes of PZ Tel B are added to the database. This will automatically download the filter transmission profiles and a flux calibrated spectrum of Vega, which are used for the flux calibration."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Adding filter: Paranal/SPHERE.ZIMPOL_R_PRIM... [DONE]\n",
      "Downloading Vega spectrum (270 kB)... [DONE]\n",
      "Adding Vega spectrum... [DONE]\n",
      "Adding filter: Paranal/SPHERE.ZIMPOL_I_PRIM... [DONE]\n",
      "Adding filter: Paranal/SPHERE.IRDIS_D_H23_2... [DONE]\n",
      "Adding filter: Paranal/SPHERE.IRDIS_D_H23_3... [DONE]\n",
      "Adding filter: Paranal/SPHERE.IRDIS_D_K12_1... [DONE]\n",
      "Adding filter: Paranal/SPHERE.IRDIS_D_K12_2... [DONE]\n",
      "Adding filter: Paranal/NACO.J... [DONE]\n",
      "Adding filter: Paranal/NACO.H... [DONE]\n",
      "Adding filter: Paranal/NACO.Ks... [DONE]\n",
      "Adding filter: Paranal/NACO.Lp... [DONE]\n",
      "Adding filter: Paranal/NACO.NB405... [DONE]\n",
      "Adding filter: Paranal/NACO.Mp... [DONE]\n",
      "Adding filter: Gemini/NICI.ED286... [DONE]\n",
      "Adding filter: Gemini/NIRI.H2S1v2-1-G0220... [DONE]\n",
      "Adding object: PZ Tel B... [DONE]\n"
     ]
    }
   ],
   "source": [
    "database.add_companion(name='PZ Tel B')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Alternatively, the `add_object` method of `Database` can be used for manually adding magnitudes and spectra of an individual object. Before coninuing, let's check the content of the database."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Database content:\n",
      "- filters: <HDF5 group \"/filters\" (2 members)>\n",
      "\t- Gemini: <HDF5 group \"/filters/Gemini\" (2 members)>\n",
      "\t\t- NICI.ED286: <HDF5 dataset \"NICI.ED286\": shape (2, 387), type \"<f4\">\n",
      "\t\t- NIRI.H2S1v2-1-G0220: <HDF5 dataset \"NIRI.H2S1v2-1-G0220\": shape (2, 129), type \"<f4\">\n",
      "\t- Paranal: <HDF5 group \"/filters/Paranal\" (12 members)>\n",
      "\t\t- NACO.H: <HDF5 dataset \"NACO.H\": shape (2, 23), type \"<f4\">\n",
      "\t\t- NACO.J: <HDF5 dataset \"NACO.J\": shape (2, 20), type \"<f4\">\n",
      "\t\t- NACO.Ks: <HDF5 dataset \"NACO.Ks\": shape (2, 27), type \"<f4\">\n",
      "\t\t- NACO.Lp: <HDF5 dataset \"NACO.Lp\": shape (2, 31), type \"<f4\">\n",
      "\t\t- NACO.Mp: <HDF5 dataset \"NACO.Mp\": shape (2, 18), type \"<f4\">\n",
      "\t\t- NACO.NB405: <HDF5 dataset \"NACO.NB405\": shape (2, 67), type \"<f4\">\n",
      "\t\t- SPHERE.IRDIS_D_H23_2: <HDF5 dataset \"SPHERE.IRDIS_D_H23_2\": shape (2, 113), type \"<f4\">\n",
      "\t\t- SPHERE.IRDIS_D_H23_3: <HDF5 dataset \"SPHERE.IRDIS_D_H23_3\": shape (2, 180), type \"<f4\">\n",
      "\t\t- SPHERE.IRDIS_D_K12_1: <HDF5 dataset \"SPHERE.IRDIS_D_K12_1\": shape (2, 175), type \"<f4\">\n",
      "\t\t- SPHERE.IRDIS_D_K12_2: <HDF5 dataset \"SPHERE.IRDIS_D_K12_2\": shape (2, 191), type \"<f4\">\n",
      "\t\t- SPHERE.ZIMPOL_I_PRIM: <HDF5 dataset \"SPHERE.ZIMPOL_I_PRIM\": shape (2, 189), type \"<f4\">\n",
      "\t\t- SPHERE.ZIMPOL_R_PRIM: <HDF5 dataset \"SPHERE.ZIMPOL_R_PRIM\": shape (2, 169), type \"<f4\">\n",
      "- models: <HDF5 group \"/models\" (1 members)>\n",
      "\t- ames-cond: <HDF5 group \"/models/ames-cond\" (4 members)>\n",
      "\t\t- flux: <HDF5 dataset \"flux\": shape (3, 13, 4097), type \"<f4\">\n",
      "\t\t- logg: <HDF5 dataset \"logg\": shape (13,), type \"<f4\">\n",
      "\t\t- teff: <HDF5 dataset \"teff\": shape (3,), type \"<f4\">\n",
      "\t\t- wavelength: <HDF5 dataset \"wavelength\": shape (4097,), type \"<f4\">\n",
      "- objects: <HDF5 group \"/objects\" (1 members)>\n",
      "\t- PZ Tel B: <HDF5 group \"/objects/PZ Tel B\" (3 members)>\n",
      "\t\t- Gemini: <HDF5 group \"/objects/PZ Tel B/Gemini\" (2 members)>\n",
      "\t\t\t- NICI.ED286: <HDF5 dataset \"NICI.ED286\": shape (4,), type \"<f4\">\n",
      "\t\t\t- NIRI.H2S1v2-1-G0220: <HDF5 dataset \"NIRI.H2S1v2-1-G0220\": shape (4,), type \"<f4\">\n",
      "\t\t- Paranal: <HDF5 group \"/objects/PZ Tel B/Paranal\" (12 members)>\n",
      "\t\t\t- NACO.H: <HDF5 dataset \"NACO.H\": shape (4,), type \"<f4\">\n",
      "\t\t\t- NACO.J: <HDF5 dataset \"NACO.J\": shape (4,), type \"<f4\">\n",
      "\t\t\t- NACO.Ks: <HDF5 dataset \"NACO.Ks\": shape (4,), type \"<f4\">\n",
      "\t\t\t- NACO.Lp: <HDF5 dataset \"NACO.Lp\": shape (4,), type \"<f4\">\n",
      "\t\t\t- NACO.Mp: <HDF5 dataset \"NACO.Mp\": shape (4,), type \"<f4\">\n",
      "\t\t\t- NACO.NB405: <HDF5 dataset \"NACO.NB405\": shape (4,), type \"<f4\">\n",
      "\t\t\t- SPHERE.IRDIS_D_H23_2: <HDF5 dataset \"SPHERE.IRDIS_D_H23_2\": shape (4,), type \"<f4\">\n",
      "\t\t\t- SPHERE.IRDIS_D_H23_3: <HDF5 dataset \"SPHERE.IRDIS_D_H23_3\": shape (4,), type \"<f4\">\n",
      "\t\t\t- SPHERE.IRDIS_D_K12_1: <HDF5 dataset \"SPHERE.IRDIS_D_K12_1\": shape (4,), type \"<f4\">\n",
      "\t\t\t- SPHERE.IRDIS_D_K12_2: <HDF5 dataset \"SPHERE.IRDIS_D_K12_2\": shape (4,), type \"<f4\">\n",
      "\t\t\t- SPHERE.ZIMPOL_I_PRIM: <HDF5 dataset \"SPHERE.ZIMPOL_I_PRIM\": shape (4,), type \"<f4\">\n",
      "\t\t\t- SPHERE.ZIMPOL_R_PRIM: <HDF5 dataset \"SPHERE.ZIMPOL_R_PRIM\": shape (4,), type \"<f4\">\n",
      "\t\t- distance: <HDF5 dataset \"distance\": shape (2,), type \"<f4\">\n",
      "- spectra: <HDF5 group \"/spectra\" (1 members)>\n",
      "\t- calibration: <HDF5 group \"/spectra/calibration\" (1 members)>\n",
      "\t\t- vega: <HDF5 dataset \"vega\": shape (3, 8827), type \"<f4\">\n"
     ]
    }
   ],
   "source": [
    "database.list_content()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Reading model spectra"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Model spectra are read from the database by creating an object of `ReadModel`. The model name and optionally a wavelength range should be provided. The wavelength range should fit within the range that was specified in `add_model`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "readmodel = species.ReadModel(model='ames-cond',\n",
    "                              wavel_range=(0.1, 6.))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Before extracting a spectrum, let's check which parameters are required for the AMES-Cond models."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['teff', 'logg']"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "readmodel.get_parameters()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And also the grid boundaries that are stored in the database."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'teff': (2800.0, 3000.0), 'logg': (0.0, 6.0)}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "readmodel.get_bounds()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The parameters are provided in a dictionary. Make sure to chose values within the grid boundaries. The radius (R<sub>Jup</sub>) and distance (pc) will scale the emitted spectrum to the observer. Without these values, the spectrum is provided at the outermost layer of the atmosphere."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "model_param = {'teff': 2900., 'logg': 4.5, 'radius': 2.2, 'distance': 47.13}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The grid of spectra is linearly interpolated at a spectral resolution of 100 and stored in a `ModelBox`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "modelbox = readmodel.get_model(model_param=model_param,\n",
    "                               spec_res=100.)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Reading companion data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The photometry data of PZ Tel B are also read from the database and stored in an `ObjectBox`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Getting object: PZ Tel B... [DONE]\n"
     ]
    }
   ],
   "source": [
    "objectbox = database.get_object(object_name='PZ Tel B')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Synthetic photometry for all filters"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For comparison, we create synthetic photometry from the model spectrum for all filters of PZ Tel B, which are stored in a `SynphotBox`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Calculating synthetic photometry... [DONE]\n"
     ]
    }
   ],
   "source": [
    "synphotbox = species.multi_photometry(datatype='model',\n",
    "                                      spectrum='ames-cond',\n",
    "                                      filters=objectbox.filters,\n",
    "                                      parameters=model_param)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Creating flux residuals"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `get_residuals` function is used to calculate the difference between the observed fluxes and the synthetic photometry of the model spectrum. The residuals are stored in a `ResidualsBox`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Calculating synthetic photometry... [DONE]\n",
      "Calculating residuals... [DONE]\n"
     ]
    }
   ],
   "source": [
    "residualsbox = species.get_residuals(datatype='model',\n",
    "                                     spectrum='ames-cond',\n",
    "                                     parameters=model_param,\n",
    "                                     filters=objectbox.filters,\n",
    "                                     objectbox=objectbox,\n",
    "                                     inc_phot=True,\n",
    "                                     inc_spec=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Opening Box objects"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `open_box` function can be used to view the content of a `Box` object. For example, the `ModelBox` contains several attributes, including the wavelength points and flux densities."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Opening ModelBox...\n",
      "\n",
      "model = ames-cond\n",
      "type = None\n",
      "wavelength = [0.1       0.1001    0.1002001 ... 5.739604  5.7453437 5.751089 ]\n",
      "flux = [7.69244319e-10 6.23827156e-09 1.04784443e-05 ... 3.85241479e-16\n",
      " 3.84432439e-16 3.83581166e-16]\n",
      "parameters = {'teff': 2900.0, 'logg': 4.5, 'radius': 2.2, 'distance': 47.13, 'mass': 61.7508434070773}\n",
      "quantity = flux\n"
     ]
    }
   ],
   "source": [
    "modelbox.open_box()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Similarly, an `ObjectBox` contains a dictionary with the apparent magnitudes and a dictionary with the flux densities."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Opening ObjectBox...\n",
      "\n",
      "name = PZ Tel B\n",
      "filters = ['Gemini/NICI.ED286', 'Gemini/NIRI.H2S1v2-1-G0220', 'Paranal/NACO.H', 'Paranal/NACO.J', 'Paranal/NACO.Ks', 'Paranal/NACO.Lp', 'Paranal/NACO.Mp', 'Paranal/NACO.NB405', 'Paranal/SPHERE.IRDIS_D_H23_2', 'Paranal/SPHERE.IRDIS_D_H23_3', 'Paranal/SPHERE.IRDIS_D_K12_1', 'Paranal/SPHERE.IRDIS_D_K12_2', 'Paranal/SPHERE.ZIMPOL_I_PRIM', 'Paranal/SPHERE.ZIMPOL_R_PRIM']\n",
      "magnitude = {'Gemini/NICI.ED286': array([11.68,  0.14], dtype=float32), 'Gemini/NIRI.H2S1v2-1-G0220': array([11.39,  0.14], dtype=float32), 'Paranal/NACO.H': array([11.93,  0.14], dtype=float32), 'Paranal/NACO.J': array([12.47,  0.2 ], dtype=float32), 'Paranal/NACO.Ks': array([11.53,  0.07], dtype=float32), 'Paranal/NACO.Lp': array([11.04,  0.22], dtype=float32), 'Paranal/NACO.Mp': array([10.93,  0.03], dtype=float32), 'Paranal/NACO.NB405': array([10.94,  0.07], dtype=float32), 'Paranal/SPHERE.IRDIS_D_H23_2': array([11.78,  0.19], dtype=float32), 'Paranal/SPHERE.IRDIS_D_H23_3': array([11.65,  0.19], dtype=float32), 'Paranal/SPHERE.IRDIS_D_K12_1': array([11.56,  0.09], dtype=float32), 'Paranal/SPHERE.IRDIS_D_K12_2': array([11.29,  0.1 ], dtype=float32), 'Paranal/SPHERE.ZIMPOL_I_PRIM': array([15.16,  0.12], dtype=float32), 'Paranal/SPHERE.ZIMPOL_R_PRIM': array([17.84,  0.31], dtype=float32)}\n",
      "flux = {'Gemini/NICI.ED286': array([2.7825625e-14, 3.5979198e-15], dtype=float32), 'Gemini/NIRI.H2S1v2-1-G0220': array([1.0590437e-14, 1.3693687e-15], dtype=float32), 'Paranal/NACO.H': array([1.9687588e-14, 2.5456521e-15], dtype=float32), 'Paranal/NACO.J': array([3.1106848e-14, 5.7625536e-15], dtype=float32), 'Paranal/NACO.Ks': array([1.1241627e-14, 7.2527667e-16], dtype=float32), 'Paranal/NACO.Lp': array([2.0200626e-15, 4.1212692e-16], dtype=float32), 'Paranal/NACO.Mp': array([9.1877844e-16, 2.5390018e-17], dtype=float32), 'Paranal/NACO.NB405': array([1.6704631e-15, 1.0777336e-16], dtype=float32), 'Paranal/SPHERE.IRDIS_D_H23_2': array([2.5412999e-14, 4.4699182e-15], dtype=float32), 'Paranal/SPHERE.IRDIS_D_H23_3': array([2.4269955e-14, 4.2688669e-15], dtype=float32), 'Paranal/SPHERE.IRDIS_D_K12_1': array([1.1547812e-14, 9.5833011e-16], dtype=float32), 'Paranal/SPHERE.IRDIS_D_K12_2': array([1.1428121e-14, 1.0540576e-15], dtype=float32), 'Paranal/SPHERE.ZIMPOL_I_PRIM': array([1.0862880e-14, 1.2030557e-15], dtype=float32), 'Paranal/SPHERE.ZIMPOL_R_PRIM': array([1.8263311e-15, 5.2856905e-16], dtype=float32)}\n",
      "distance = 47.130001068115234\n",
      "spectrum = None\n"
     ]
    }
   ],
   "source": [
    "objectbox.open_box()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The attributes in the `Box` objects can be extracted for further analyis or manual plots, for example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.1      , 0.1001   , 0.1002001, ..., 5.739604 , 5.7453437,\n",
       "       5.751089 ], dtype=float32)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "modelbox.wavelength"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Plotting spectra, fluxes and filters"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `Box` objects can provided as list to `plot_spectrum`, which will be interpreted accordingly. Optionally, the filter names can be included for plotting the transmission profiles and the `ResidualsBox` can be included for showing the residuals. The `ObjectBox` requires a color for the photometry data and a spectrum with the latter set to `None` in this case."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Plotting spectrum: spectrum.png... [DONE]\n"
     ]
    }
   ],
   "source": [
    "species.plot_spectrum(boxes=[modelbox, objectbox, synphotbox],\n",
    "                      filters=objectbox.filters,\n",
    "                      residuals=residualsbox,\n",
    "                      colors=('darkblue', ('black', None), 'black'),\n",
    "                      offset=(-0.08, -0.06),\n",
    "                      xlim=(0.2, 5.5),\n",
    "                      ylim=(-3e-15, 4.8e-14),\n",
    "                      legend='upper right',\n",
    "                      output='spectrum.png')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's have a look at the result. The plot is stored in the working folder. The black squares are the photometry data of PZ Tel B and the open squares are the synthetic photometry computed from the model spectrum. The residuals are shown relative to the uncertainties on the fluxes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 50808 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from IPython.display import Image\n",
    "Image('spectrum.png') "
   ]
  }
 ],
 "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.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
