{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Spectra : spectra\n\nIf you would like something that looks similar to your peak scans, you can use\n:func:`~interferences.plot.spectra.spectra`, which you can also access from your\ndataframe using the :class:`~interferences.mz` accessor:\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nfrom interferences import build_table\nfrom pyrolite.geochem.ind import REE"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Here build a table based on some low-mass isotopes, and focus in on the BO+ ion:\n\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "window = (\"B[10]O[16]\", 0.05)\ndf = build_table([\"C\", \"B\", \"N\", \"O\"], window=window, max_atoms=2)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "From this table, we can create our plot, limiting the labelling to the\nfive peaks with highest estimated intensity. Note we should specify the mass\nresolution for the simulated peaks:\n\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "ax = df.mz.spectra(window=window, mass_resolution=3000, max_labels=5, figsize=(8, 4))\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Thesse peaks better show the 'interference' aspect of these ions at relatively low\nmass resolution, but are notably unnaturally square. To simulate some shoulders for\nyour peaks (i.e. a non-zero-width image of your source, and a signal limited by a\ncollector slit or similar ) you can specify a ratio for the `image_ratio` keyword\nargument. Here we explore the effect this parameter with a few different values\n(0, <1, 1, and >1):\n\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig, ax = plt.subplots(2, 2, sharex=True, sharey=True, figsize=(8, 8))\nfor a, ratio in zip(ax.flat, [0, 0.2, 1, 1.5]):\n    df.mz.spectra(\n        ax=a, window=window, mass_resolution=3000, image_ratio=ratio, max_labels=5\n    )\n    a.annotate(\n        \"ratio={:.1f}\".format(ratio),\n        xy=(0.9, 0.9),\n        xycoords=a.transAxes,\n        ha=\"right\",\n        fontsize=12,\n    )\nplt.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.9"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}