{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Plotting constant longitude slices\n\nThis example shows how to plot slices of constant longitude from a MAS model\noutput.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "First, load the required modules.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from psipy.model import MASOutput\nimport matplotlib.pyplot as plt"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Next, load a set of MAS output files. You will need to change this line to\npoint to a folder with MAS files in them.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "mas_path = '/Users/dstansby/github/psipy/data/helio'\nmodel = MASOutput(mas_path)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Each MAS model contains a number of variables. The variable names can be\naccessed using the ``.variables`` attribute.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "print(model.variables)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Set parameters for plotting. The first line will give us a horizontal\nerrorbar underneath the plots. The second line is the index to select for the\nlongitude slice.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "cbar_kwargs = {'orientation': 'horizontal'}\nphi_idx = 40"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot the slices\n\nNote that for density (rho) and pressure (p) we first normalise the data\nrelative to a power law decrease, to make it easer to see spatial variations.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig = plt.figure()\naxs = [plt.subplot(1, 3, i + 1, projection='polar') for i in range(3)]\n\nax = axs[0]\nmodel['vr'].plot_phi_cut(phi_idx, ax=ax, cbar_kwargs=cbar_kwargs)\n\nax = axs[1]\nrho = model['rho']\nrho_r2 = rho.radial_normalized(2)\nrho_r2.plot_phi_cut(phi_idx, ax=ax, cbar_kwargs=cbar_kwargs)\n\nax = axs[2]\np = model['p']\np_r3 = p.radial_normalized(3)\np_r3.plot_phi_cut(phi_idx, ax=ax, cbar_kwargs=cbar_kwargs)\n\n\n# Add a contour of br = 0 (the heliopsheric current sheet) to all the axes\nfor ax in axs:\n    model['br'].contour_phi_cut(phi_idx, levels=[0], ax=ax,\n                                colors='white', linestyles='--', linewidths=1)\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.9.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}