{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# TimeSeries Plotting Example\n\nAn example to show Sunpy's TimeSeries in HelioPy.\n\nFor more information on TimeSeries, see\nhttp://docs.sunpy.org/en/stable/guide/data_types/timeseries.html\n\nFor more information on AstroPy Units, see\nhttp://docs.astropy.org/en/stable/units/\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Import modules\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import heliopy.data.ulysses as ulysses\nimport matplotlib.pyplot as plt\nfrom datetime import datetime"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Set up support for plotting data with units\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from astropy.visualization import quantity_support\nquantity_support()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Load data. In this example we use Ulysses data.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "starttime = datetime(1993, 1, 1, 0, 0, 0)\nendtime = datetime(1993, 2, 1, 0, 0, 0)\ntimeseries_data = ulysses.swics_abundances(starttime, endtime)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "timeseries_data is a TimeSeries data type.\nThe .index attribute gets the time index of the data\nthe .quantity() method can be used to extract data with units attached\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "print(timeseries_data.data.keys())\nfig, axs = plt.subplots(2, 1, sharex=True)\naxs[0].plot(timeseries_data.index, timeseries_data.quantity('VEL_ALPHA'))\n\nion_ratios = ['RAT_C6_C5', 'RAT_O7_O6', 'RAT_FE_O']\nfor r in ion_ratios:\n    axs[1].plot(timeseries_data.index, timeseries_data.quantity(r), label=r)\n\naxs[1].set_yscale('log')\naxs[1].legend()\nfig.autofmt_xdate()\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.3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}