{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# NCL_skewt_1.py\nThis script illustrates the following concepts:\n   - Drawing a default Skew-T background\n   - Customizing the background of a Skew-T plot\n\nSee following URLs to see the reproduced NCL plot & script:\n    - Original NCL script: https://www.ncl.ucar.edu/Applications/Scripts/skewt_1.ncl\n    - Original NCL plots: https://www.ncl.ucar.edu/Applications/Images/skewt_1_1_lg.png and https://www.ncl.ucar.edu/Applications/Images/skewt_1_2_lg.png and https://www.ncl.ucar.edu/Applications/Images/skewt_1_3_lg.png\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Import packages:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport matplotlib.lines as mlines\nimport numpy as np\nfrom metpy.plots import SkewT\nfrom metpy.units import units\n\nimport geocat.viz.util as gvutil"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot Skew-T with MetPy Defaults:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Note that there are no labels on the axes. This is because we have not yet\n# plotted any data. Once data is plotted, MetPy will use the units of the\n# data to create appropriate labels.\nfig = plt.figure(figsize=(9, 9))\nskew = SkewT(fig)\nax = skew.ax\n\nskew.plot_dry_adiabats()\nskew.plot_moist_adiabats()\nskew.plot_mixing_lines()\n\ngvutil.set_titles_and_labels(ax, maintitle=\"MetPy Default Skew-T\")\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot Skew-T that is similar to NCL's default Skew-T plot:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Note that MetPy forces the x axis scale to be in Celsius and the y axis\n# scale to be in hectoPascals. Once data is plotted, then the axes labels are\n# automatically added\nfig = plt.figure(figsize=(9, 9))\n\n# The rotation keyword changes how skewed the temperature lines are. MetPy has\n# a default skew of 30 degrees\nskew = SkewT(fig, rotation=45)\nax = skew.ax\n\n# Shade every other section between isotherms\nx1 = np.linspace(-100, 40, 8)  # The starting x values for the shaded regions\nx2 = np.linspace(-90, 50, 8)  # The ending x values for the shaded regions\ny = [1050, 100]  # The range of y values that the shades regions should cover\nfor i in range(0, 8):\n    skew.shade_area(y=y,\n                    x1=x1[i],\n                    x2=x2[i],\n                    color='limegreen',\n                    alpha=0.25,\n                    zorder=1)\n\n# Choose starting temperatures in Kelvin for the dry adiabats\nt0 = units.K * np.arange(243.15, 444.15, 10)\nskew.plot_dry_adiabats(t0=t0, linestyles='solid', colors='tan', linewidths=1.5)\n\n# Choose starting temperatures in Kelvin for the moist adiabats\nt0 = units.K * np.arange(281.15, 306.15, 4)\nskew.plot_moist_adiabats(t0=t0,\n                         linestyles='solid',\n                         colors='lime',\n                         linewidth=1.5)\n\n# Choose mixing ratios\nw = np.array([0.001, 0.002, 0.003, 0.005, 0.008, 0.012, 0.020]).reshape(-1, 1)\n\n# Choose the range of pressures that the mixing ratio lines are drawn over\np = units.hPa * np.linspace(1000, 400, 7)\n\n# Plot mixing ratio lines\nskew.plot_mixing_lines(w=w,\n                       p=p,\n                       linestyle='dashed',\n                       colors='lime',\n                       linewidths=1)\n\n# Use geocat.viz utility functions to set axes limits and ticks\ngvutil.set_axes_limits_and_ticks(\n    ax=ax,\n    xlim=[-32, 38],\n    yticks=[1000, 850, 700, 500, 400, 300, 250, 200, 150, 100])\n\n# Use geocat.viz utility functions to add a main title\ngvutil.set_titles_and_labels(ax=ax, maintitle=\"NCL Style Plot\")\n\n# Plot empty wind barbs with dummy data\nu = np.zeros(22)\nv = u\np = np.linspace(1010, 110, 22)\nskew.plot_barbs(p=p,\n                u=u,\n                v=v,\n                xloc=1.05,\n                fill_empty=True,\n                sizes=dict(emptybarb=0.075, width=0.1, height=0.2))\n\n# Draw line underneath wind barbs\nline = mlines.Line2D([1.05, 1.05], [0, 1],\n                     color='gray',\n                     linewidth=0.5,\n                     transform=ax.transAxes,\n                     clip_on=False,\n                     zorder=1)\nax.add_line(line)\n\n# Change the style of the gridlines\nplt.grid(True,\n         which='major',\n         axis='both',\n         color='tan',\n         linewidth=1.5,\n         alpha=0.5)\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
}