{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# TimeSeries Basics\n\nAn example to show some basic functions of TimeSeries.\n\nFor more information about TimeSeries, http://docs.sunpy.org/en/stable/guide/data_types/timeseries.html\nFor more information about AstroPy Units, http://docs.astropy.org/en/stable/units/\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nimport datetime\nimport pandas as pd\nimport sunpy.timeseries as ts\nfrom collections import OrderedDict\nimport astropy.units as u\n\n# The index of the SunPy Timeseries is always datetime\nbase = datetime.datetime.today()\ntimes = [base - datetime.timedelta(minutes=x) for x in range(24*60, 0, -1)]\nintensity = np.sin(np.arange(0, 12 * np.pi, ((12 * np.pi) / (24*60))))\n\n# This example shows how a TimeSeries object is made from a Pandas DataFrame\ndata = pd.DataFrame(intensity, index=times, columns=['intensity'])\n\n# TimeSeries can have a metadata attached to it.\nmeta = OrderedDict({'key':'value'})\n\n# AstroPy Units are attached to the TimeSeries by passing it alongside the data.\n# The units are stored in an OrderedDict object.\n# Each key is the unit, and the value is the astropy representation of the same.\nunits = OrderedDict([('intensity', u.W/u.m**2)])\nts_custom = ts.TimeSeries(data, meta, units)\n\n# Using sunpy.timeseries.TimeSeries.data will return a Pandas DataFrame of the TimeSeries object.\nprint(ts_custom.data)\n\n# To view the units, sunpy.timeserise.TimeSeries.units can be used.\nprint(ts_custom.units)\n\n# The values can be extracted along with their units as well.\n#sunpy.timeseries.TimeSeries.quantity(column_name)[index]\nprint(ts_custom.quantity('intensity')[1])"
      ]
    }
  ],
  "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
}