{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Plot a spectrum\nThis is an example showing how to plot a spectrum with the\n:func:`mcalf.visualisation.plot_spectrum` function.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "First we shall create a list of wavelengths, with a variable\nwavelength spacing.\nNext, we shall use the Voigt profile to generate spectral\nintensities at each of the wavelength points.\nTypically you would provide a spectrum obtained from observations.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nwavelengths = np.linspace(8541, 8543, 20)\nwavelengths = np.delete(wavelengths, np.s_[1:6:2])\nwavelengths = np.delete(wavelengths, np.s_[-6::2])\n\nfrom mcalf.profiles.voigt import voigt\nspectrum = voigt(wavelengths, -526, 8542, 0.1, 0.1, 1242)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Next, we shall import :func:`mcalf.visualisation.plot_spectrum`.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from mcalf.visualisation import plot_spectrum"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "We can now simply plot the spectrum.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plot_spectrum(wavelengths, spectrum)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Notice how the spectrum above is normalised.\nThe normalisation is applied by dividing through\nby the mean of the three rightmost points.\nTo plot the raw spectrum,\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plot_spectrum(wavelengths, spectrum, normalised=False)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The line connecting the points provided in the ``spectrum``\narray above is smooth. This is due to spline interpolation\nbeing applied. Interpolation can be disabled, resulting\nin a straight line between each of the points.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plot_spectrum(wavelengths, spectrum, smooth=False)"
      ]
    }
  ],
  "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.8.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}