{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Plotting 500mb Geopotential Height and Absolute Vorticity\n\nThis example plots the 500mb geopotential height and absolute vorticity.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from __future__ import print_function\nimport Ngl, Nio\nimport pandas as pd\nimport numpy as np\nimport xarray as xr\nimport netCDF4 as nc\nfrom netCDF4 import Dataset\nimport matplotlib.pyplot as plt\n\n# Read in NETCDF data\nfv3=nc.MFDataset('GFSv16beta/GFSPRS.GrbF156.nc')\ngridlat=fv3[\"latitude\"][:]\ngridlon=fv3[\"longitude\"][:]\nhgt=fv3[\"HGT_500mb\"][0,:,:]*0.1\nugrd=fv3[\"UGRD_500mb\"][0,:,:]\nvgrd=fv3[\"VGRD_500mb\"][0,:,:]\nabsv=fv3[\"ABSV_500mb\"][0,:,:]*1e5\nlat=gridlat\nlon=gridlon\nmaxlat=lat.max()\nminlat=lat.min()\nmaxlon=lon.max()\nminlon=lon.min()\n\n# Define work station and output figure name\nwks_type = \"png\"\nwks = Ngl.open_wks(wks_type,\"GFSv16beta_500mb_Hgt_Abs\")\n\n# Define map resources\nmpres = Ngl.Resources()\nmpres.nglMaximize = False\nmpres.nglFrame     = False\nmpres.mpFillOn               = True\nmpres.mpGridAndLimbOn = True\nmpres.mpOceanFillColor       = \"Transparent\"\nmpres.mpLandFillColor        = \"Gray90\"#\"Gray90\"\nmpres.mpInlandWaterFillColor = \"Transparent\"\nmpres.mpLimitMode        = \"LatLon\"\nmpres.mpDataBaseVersion     = \"MediumRes\"\nmpres.mpOutlineBoundarySets = \"USStates\"\nmpres.mpUSStateLineThicknessF=2 \nmpres.mpGeophysicalLineThicknessF= 2\nmpres.mpCountyLineThicknessF=2\nmpres.mpNationalLineThicknessF=2\nmpres.mpGeophysicalLineColor=\"gray60\"\nmpres.mpNationalLineColor=\"gray60\"\nmpres.mpUSStateLineColor=\"gray60\"\nmpres.mpGridLineDashPattern=11\nmpres.mpGridLineColor=\"grey60\"\n\n# Define plot resources\ncnres                 = Ngl.Resources()\ncnres.cnLevelSelectionMode=\"ExplicitLevels\"# Contour resources\n\n# Define color map attributes\ncnres.cnFillColors=[\"Transparent\",\"(/1.,.9607843,.8/)\",\"(/1,0.9019608,0.4392157/)\",\"(/1,.8,.2/)\",\"(/1.,0.6862745,0.2/)\",\"(/1.,0.6,0.2/)\",\"(/1.,0.43529412,0.2, /)\",\"(/1.,0.33333334,0./)\",\"(/0.9019608,0.15686275,0.11764706/)\",\"(/0.78431374,0.11764706,0.07843138/)\"]\ncnres.cnLevels    = [9,12,15,18,21,24,27,30]\n\n# Define plot resources\ncnres.cnFillOn        = True\ncnres.cnLinesOn       = False\ncnres.cnLineLabelsOn  = False\ncnres.nglFrame    = False\ncnres.tiXAxisString = \"Lon\"\ncnres.tiYAxisString = \"Lat\"\ncnres.lbOrientation   = \"horizontal\"\ncnres.sfXArray        = lon[:]\ncnres.sfYArray        = lat[:]\n\n# Define resources for ABSV\ncnres0=cnres\ncnres0.lbLabelFontHeightF = 0.012\ncnres0.pmLabelBarHeightF =0.1\ncnres0.pmLabelBarWidthF=0.6\nmpres.tiMainString = \"UFS_v1.0.0_GFSv16beta: 500mb Heights(dam) /Abs Vorticity (10^-5/s)/ Winds (m/s)  ~C~  Initialized: 12Z 25 Oct 2019 | Valid: 00Z 1 Nov 2019\"\nmpres.tiMainFontHeightF=0.012\nmpres.tiMainPosition = \"Center\"\n\n# Define resources for HGT\ncnres1= Ngl.Resources()\ncnres1.nglDraw=False\ncnres1.nglFrame    = False\ncnres1.cnFillOn    = False\ncnres1.cnLinesOn = True\ncnres1.sfXArray        = lon[:]\ncnres1.sfYArray        = lat[:]\ncnres1.cnLineThicknessF = 3.0\ncnres1.cnLevelSelectionMode = \"ManualLevels\"\ncnres1.cnMinLevelValF = 504#-45\ncnres1.cnMaxLevelValF = 624\ncnres1.cnLevelSpacingF=6\ncnres1.cnInfoLabelOn   = False\ncnres1.cnLineLabelBackgroundColor= \"white\"#\"Transparent\" \ncnres1.cnLineLabelDensityF=1.5\ncnres1.cnLineLabelFontHeightF=0.008\n\n# Define resources for wind field\nresources= cnres\nresources.nglDraw     = False\nresources.nglFrame    = False\nresources.vcMinFracLengthF = 1\nresources.vcRefMagnitudeF  =10\nresources.vcRefLengthF     = 0.025\nresources.vcMinDistanceF = 0.025\nresources.vcMonoLineArrowColor  = True   # Draw vectors in color.\nresources.vfXArray=lon[:]\nresources.vfYArray=lat[:]\nresources.vcGlyphStyle = \"WindBarb\"\n\n# Make plots for ABSV, wind field, and HGT\nmap=Ngl.map(wks,mpres)\npabsv=Ngl.contour(wks,absv[:,:],cnres0)\npwb=Ngl.vector(wks,ugrd,vgrd,resources)\nphgt=Ngl.contour(wks,hgt[:,:],cnres1)\n\n#Ovelay plots\nNgl.overlay(map,pabsv)\nNgl.overlay(map,phgt)\nNgl.overlay(map,pwb)\nNgl.draw(map)\nNgl.frame(wks)\nNgl.end()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ".. figure:: /images/500mb_2019110100_GFSv16beta_150s.png\n :width: 600\n :align: center\n\n"
      ]
    }
  ],
  "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
}