{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\nParker Solar Probe peihelion 1\n==============================\n\nThis example shows how to plot magnetic field data from the first perihelion\npass of Parker Solar Probe. Not shown here (because the files are quite large!)\nare the particle properties measured by SWEAP, which can be accessed with\n`heliopy.data.psp.sweap_spc_l3`.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Import the required packages\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from heliopy.data import psp\nfrom datetime import datetime\nimport matplotlib.pyplot as plt"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Define the starttime and endtime of the perihelion pass\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "starttime = datetime(2018, 11, 2)\nendtime = datetime(2018, 11, 10)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Download and load the magnetic field data\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "mag = psp.fields_mag_rtn_1min(starttime, endtime)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot the data!\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig, ax = plt.subplots(figsize=(10, 4))\n\nfor comp, label in enumerate(['Br', 'Bt', 'Bn']):\n    ax.plot(mag.index, mag.quantity(f'psp_fld_l2_mag_RTN_1min_{comp}'),\n            linewidth=1, zorder=-comp, label=label)\n\nax.legend()\nax.set_ylabel('nT')\nax.set_title('PSP Perihelion 1')\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
}