Skip to content

Instantly share code, notes, and snippets.

Created November 22, 2017 14:23
Show Gist options
  • Save anonymous/3da3480e71a62a36983b68dc7ad398d6 to your computer and use it in GitHub Desktop.
Save anonymous/3da3480e71a62a36983b68dc7ad398d6 to your computer and use it in GitHub Desktop.
testing/miller_composite.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "%matplotlib inline",
"execution_count": 1,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "\n# Miller Composite Chart\n\n\nCreate a Miller Composite chart based on Miller 1972 in Python with MetPy and\nMatplotlib.\n\n"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import cartopy.crs as ccrs\nimport cartopy.feature as cfeature\nimport matplotlib.lines as lines\nimport matplotlib.patches as mpatches\nimport matplotlib.pyplot as plt\nimport metpy.calc as mcalc\nfrom metpy.units import units\nfrom netCDF4 import num2date\nimport numpy as np\nimport numpy.ma as ma\nfrom scipy.ndimage import gaussian_filter\nfrom siphon.ncss import NCSS",
"execution_count": 2,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "**Get the data**\n\nThis example will use data from the North American Mesoscale Model Analysis\n(https://nomads.ncdc.gov/) for 12 UTC 27 April 2011.\n\n"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "ncss = NCSS('https://nomads.ncdc.noaa.gov/thredds/ncss/grid/namanl/201104/20110427/'\n 'namanl_218_20110427_1800_000.grb')\n\n# Query for required variables\ngfsdata = ncss.query().all_times()\ngfsdata.variables('Geopotential_height',\n 'u_wind',\n 'v_wind',\n 'Temperature',\n 'Relative_humidity',\n 'Best_4-layer_lifted_index',\n 'Absolute_vorticity',\n 'Pressure_reduced_to_MSL',\n 'Dew_point_temperature'\n ).add_lonlat()\n\n# Set the lat/lon box for the data to pull in.\ngfsdata.lonlat_box(-135, -60, 15, 65)\n\n# Actually getting the data\ndata = ncss.get_data(gfsdata)\n\n# Assign variable names to collected data\ndtime = data.variables['Geopotential_height'].dimensions[0]\ndlev = data.variables['Geopotential_height'].dimensions[1]\nlat = data.variables['lat'][:]\nlon = data.variables['lon'][:]\nlev = data.variables[dlev][:] * units.hPa\ntimes = data.variables[dtime]\nvtimes = num2date(times[:], times.units)\ntemps = data.variables['Temperature']\ntmp = temps[0, :] * units.kelvin\nuwnd = data.variables['u_wind'][0, :] * units.meter / units.second\nvwnd = data.variables['v_wind'][0, :] * units.meter / units.second\nhgt = data.variables['Geopotential_height'][0, :] * units.meter\nrelh = data.variables['Relative_humidity'][0, :]\nlifted_index = (data.variables['Best_4-layer_lifted_index'][0, 0, :] *\n units(data.variables['Best_4-layer_lifted_index'].units))\nTd_sfc = (data.variables['Dew_point_temperature'][0, 0, :] *\n units(data.variables['Dew_point_temperature'].units))\navor = data.variables['Absolute_vorticity'][0, :] * units('1/s')\npmsl = (data.variables['Pressure_reduced_to_MSL'][0, :] *\n units(data.variables['Pressure_reduced_to_MSL'].units))",
"execution_count": 3,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "Query for 00 UTC to calculate pressure falls and height change\n\n"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "ncss2 = NCSS('https://nomads.ncdc.noaa.gov/thredds/ncss/grid/namanl/201104/20110427/'\n 'namanl_218_20110427_0600_000.grb')\n\n# Query for required variables\ngfsdata2 = ncss2.query().all_times()\ngfsdata2.variables('Geopotential_height',\n 'Pressure_reduced_to_MSL').add_lonlat()\n\n# Set the lat/lon box for the data you want to pull in.\ngfsdata2.lonlat_box(-135, -60, 15, 65)\n\n# Actually getting the data\ndata2 = ncss2.get_data(gfsdata)\n\nhgt_00z = data2.variables['Geopotential_height'][0, :] * units.meter\npmsl_00z = (data2.variables['Pressure_reduced_to_MSL'][0, :] *\n units(data2.variables['Pressure_reduced_to_MSL'].units))",
"execution_count": 4,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "**Subset the Data**\n\nWith the data pulled in, we will now subset to the specific levels desired\n\n"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "# 300 hPa, index 28\nu_300 = uwnd[28, :].to('kt')\nv_300 = vwnd[28, :].to('kt')\n\n# 500 hPa, index 20\navor_500 = avor[3, :]\nu_500 = uwnd[20, :].to('kt')\nv_500 = vwnd[20, :].to('kt')\nhgt_500 = hgt[20, :]\nhgt_500_00z = hgt_00z[20, :]\n\n# 700 hPa, index 12\ntmp_700 = tmp[12, :].to('degC')\nrh_700 = relh[12, :]\nu_700 = uwnd[12, :].to('kt')\nv_700 = vwnd[12, :].to('kt')\n\n# 850 hPa, index 6\ntmp_850 = tmp[6, :].to('degC')\nu_850 = uwnd[6, :].to('kt')\nv_850 = vwnd[6, :].to('kt')\nrh_850 = relh[6, :]",
"execution_count": 5,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "Calculation of advections will require the help of the following function to find deltas\n\n"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def calc_dx_dy(longitude, latitude, shape='sphere', radius=6370997.):\n \"\"\" This definition calculates the distance between grid points that are in\n a latitude/longitude format.\n\n Using pyproj GEOD; different Earth Shapes\n https://jswhit.github.io/pyproj/pyproj.Geod-class.html\n\n Common shapes: 'sphere', 'WGS84', 'GRS80'\n\n Accepts, 1D or 2D arrays for latitude and longitude\n\n Assumes [Y, X] for 2D arrays\n\n Returns: dx, dy; 2D arrays of distances between grid points\n in the x and y direction with units of meters\n \"\"\"\n from pyproj import Geod\n\n if radius != 6370997.:\n g = Geod(a=radius, b=radius)\n else:\n g = Geod(ellps=shape)\n\n if latitude.ndim == 1:\n longitude, latitude = np.meshgrid(longitude, latitude)\n\n dy = np.zeros(latitude.shape)\n dx = np.zeros(longitude.shape)\n\n for i in range(longitude.shape[1]):\n for j in range(latitude.shape[0]-1):\n _, _, dy[j, i] = g.inv(longitude[j, i], latitude[j, i],\n longitude[j+1, i], latitude[j+1, i])\n dy[j+1, :] = dy[j, :]\n\n for i in range(longitude.shape[1]-1):\n for j in range(latitude.shape[0]):\n _, _, dx[j, i] = g.inv(longitude[j, i], latitude[j, i],\n longitude[j, i+1], latitude[j, i+1])\n dx[:, i+1] = dx[:, i]\n\n xdiff_sign = np.sign(longitude[0, 1]-longitude[0, 0])\n ydiff_sign = np.sign(latitude[1, 0]-latitude[0, 0])\n return xdiff_sign*dx*units.meter, ydiff_sign*dy*units.meter",
"execution_count": 6,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "**Prepare Variables for Plotting**\n\nWith the data queried and subset, we will make any needed calculations in preparation for\nplotting.\n\nThe following fields should be plotted:\n 500-hPa cyclonic vorticity advection\n\n Surface-based Lifted Index\n\n The axis of the 300-hPa, 500-hPa, and 850-hPa jets\n\n Surface dewpoint\n\n 700-hPa dewpoint depression\n\n 12-hr surface pressure falls and 500-hPa height changes\n\n"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "# 500 hPa CVA\ndx, dy = calc_dx_dy(lon, lat)\nvort_adv_500 = mcalc.advection(avor_500, [v_500.to('m/s'), u_500.to('m/s')], (dy, dx),\n dim_order='yx') * 1e9\nvort_adv_500_smooth = gaussian_filter(vort_adv_500, 4)",
"execution_count": 7,
"outputs": [
{
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-7-d65ce030b5e0>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0mdx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdy\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcalc_dx_dy\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlon\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlat\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m vort_adv_500 = mcalc.advection(avor_500, [v_500.to('m/s'), u_500.to('m/s')], (dy, dx),\n\u001b[1;32m----> 4\u001b[1;33m dim_order='yx') * 1e9\n\u001b[0m\u001b[0;32m 5\u001b[0m \u001b[0mvort_adv_500_smooth\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mgaussian_filter\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvort_adv_500\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m4\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\AppData\\Local\\Continuum\\Miniconda3\\envs\\IOOS3b\\lib\\site-packages\\metpy\\calc\\kinematics.py\u001b[0m in \u001b[0;36mwrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 79\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mk\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_check_and_flip\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mv\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 80\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 81\u001b[1;33m \u001b[0mret\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 82\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 83\u001b[0m \u001b[1;31m# If we flipped on the way in, need to flip on the way out so that output array(s)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\AppData\\Local\\Continuum\\Miniconda3\\envs\\IOOS3b\\lib\\site-packages\\metpy\\calc\\kinematics.py\u001b[0m in \u001b[0;36madvection\u001b[1;34m(scalar, wind, deltas)\u001b[0m\n\u001b[0;32m 386\u001b[0m \u001b[1;31m# this to an array with dimension as the first index. Reverse the deltas to line up\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 387\u001b[0m \u001b[1;31m# with the order of the dimensions.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 388\u001b[1;33m \u001b[0mgrad\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_stack\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m_gradient\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mscalar\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0mdeltas\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 389\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 390\u001b[0m \u001b[1;31m# Make them be at least 2D (handling the 1D case) so that we can do the\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\AppData\\Local\\Continuum\\Miniconda3\\envs\\IOOS3b\\lib\\site-packages\\metpy\\calc\\kinematics.py\u001b[0m in \u001b[0;36m_gradient\u001b[1;34m(f, *args, **kwargs)\u001b[0m\n\u001b[0;32m 24\u001b[0m \u001b[0margs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mlist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 25\u001b[0m \u001b[0margs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mextend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0munits\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mQuantity\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1.\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'dimensionless'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m*\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[1;33m-\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 26\u001b[1;33m \u001b[0mgrad\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgradient\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmagnitude\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0ma\u001b[0m \u001b[1;32min\u001b[0m \u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 27\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 28\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0munits\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mQuantity\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mgrad\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0munits\u001b[0m \u001b[1;33m/\u001b[0m \u001b[0margs\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0munits\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\AppData\\Local\\Continuum\\Miniconda3\\envs\\IOOS3b\\lib\\site-packages\\numpy\\lib\\function_base.py\u001b[0m in \u001b[0;36mgradient\u001b[1;34m(f, *varargs, **kwargs)\u001b[0m\n\u001b[0;32m 1698\u001b[0m \u001b[1;32mcontinue\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1699\u001b[0m \u001b[1;32melif\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndim\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdistances\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1700\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"distances must be either scalars or 1d\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1701\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdistances\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0maxes\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1702\u001b[0m raise ValueError(\"when 1d, distances must match \"\n",
"\u001b[1;31mValueError\u001b[0m: distances must be either scalars or 1d"
],
"ename": "ValueError",
"evalue": "distances must be either scalars or 1d"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "For the jet axes, we will calculate the windspeed at each level, and plot the highest values\n\n"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "wspd_300 = gaussian_filter(mcalc.get_wind_speed(u_300, v_300), 5)\nwspd_500 = gaussian_filter(mcalc.get_wind_speed(u_500, v_500), 5)\nwspd_850 = gaussian_filter(mcalc.get_wind_speed(u_850, v_850), 5)",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "850-hPa dewpoint will be calculated from RH and temperature\n\n"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "Td_850 = mcalc.dewpoint_rh(tmp_850, rh_850 / 100.)",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "700-hPa dewpoint depression will be calculated from temperature and RH\n\n"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "Td_dep_700 = tmp_700 - mcalc.dewpoint_rh(tmp_700, rh_700 / 100.)",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "12-hr surface pressure falls and 500-hPa height changes\n\n"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "pmsl_change = pmsl - pmsl_00z\nhgt_500_change = hgt_500 - hgt_500_00z",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "To plot the jet axes, we will mask the wind fields below the upper 1/3 of windspeed.\n\n"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "mask_500 = ma.masked_less_equal(wspd_500, 0.66 * np.max(wspd_500)).mask\nu_500[mask_500] = np.nan\nv_500[mask_500] = np.nan\n\n# 300 hPa\nmask_300 = ma.masked_less_equal(wspd_300, 0.66 * np.max(wspd_300)).mask\nu_300[mask_300] = np.nan\nv_300[mask_300] = np.nan\n\n# 850 hPa\nmask_850 = ma.masked_less_equal(wspd_850, 0.66 * np.max(wspd_850)).mask\nu_850[mask_850] = np.nan\nv_850[mask_850] = np.nan",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "**Create the Plot**\n\nWith the data now ready, we will create the plot\n\n"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "# Set up our projection\ncrs = ccrs.LambertConformal(central_longitude=-100.0, central_latitude=45.0)\n\n\n# Coordinates to limit map area\nbounds = [(-122., -75., 25., 50.)]\n# Choose a level to plot, in this case 296 K\nlevel = 0\n\n# Get data to plot state and province boundaries\nstates_provinces = cfeature.NaturalEarthFeature(category='cultural',\n name='admin_1_states_provinces_lakes',\n scale='50m',\n facecolor='none')",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "Plot the composite\n\n"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "fig = plt.figure(1, figsize=(17., 12.))\nax = plt.subplot(111, projection=crs)\nax.set_extent(*bounds, crs=ccrs.PlateCarree())\nax.coastlines('50m', edgecolor='black', linewidth=0.75)\nax.add_feature(states_provinces, edgecolor='black', linewidth=0.25)\n\n# Plot Lifted Index\ncs1 = ax.contour(lon, lat, lifted_index, range(-8, -2, 2), transform=ccrs.PlateCarree(),\n colors='red', linewidths=0.75, linestyles='solid', zorder=7,\n label='Best Lifted Index')\nplt.clabel(cs1, fontsize=10, inline=1, inline_spacing=7,\n fmt='%i', rightside_up=True, use_clabeltext=True)\n\n# Plot Surface pressure falls\ncs2 = ax.contour(lon, lat, pmsl_change.to('hPa'), range(-10, -1, 4),\n transform=ccrs.PlateCarree(),\n colors='k', linewidths=0.75, linestyles='dashed', zorder=6)\nplt.clabel(cs2, fontsize=10, inline=1, inline_spacing=7,\n fmt='%i', rightside_up=True, use_clabeltext=True)\n\n# Plot 500-hPa height falls\ncs3 = ax.contour(lon, lat, hgt_500_change, range(-60, -29, 15),\n colors='k', linewidths=0.75, linestyles='solid', zorder=5)\nplt.clabel(cs3, fontsize=10, inline=1, inline_spacing=7,\n fmt='%i', rightside_up=True, use_clabeltext=True)\n\n# Plot surface pressure\nax.contourf(lon, lat, pmsl.to('hPa'), range(990, 1011, 20), alpha=0.5,\n transform=ccrs.PlateCarree(),\n colors='yellow', zorder=1)\n\n# Plot surface dewpoint\nax.contourf(lon, lat, Td_sfc.to('degF'), range(65, 76, 10), alpha=0.4,\n transform=ccrs.PlateCarree(),\n colors=['green'], zorder=2)\n\n# Plot 700-hPa dewpoint depression\nax.contourf(lon, lat, Td_dep_700, range(15, 46, 30), alpha=0.5, transform=ccrs.PlateCarree(),\n colors='tan', zorder=3)\n\n# Plot Vorticity Advection\nax.contourf(lon, lat, vort_adv_500_smooth, range(5, 106, 100), alpha=0.5,\n transform=ccrs.PlateCarree(),\n colors='BlueViolet', zorder=4)\n\n# 300-hPa wind barbs\njet300 = ax.barbs(lon, lat, u_300.m, v_300.m, length=6, regrid_shape=20,\n transform=ccrs.PlateCarree(),\n color='green', zorder=10, label='300-hPa Jet Core Winds (kt)')\n\n\n# 500-hPa wind barbs\njet500 = ax.barbs(lon, lat, u_500.m, v_500.m, length=6, regrid_shape=20,\n transform=ccrs.PlateCarree(),\n color='blue', zorder=9, label='500-hPa Jet Core Winds (kt)')\n\n# 850-hPa wind barbs\njet850 = ax.barbs(lon, lat, u_850.m, v_850.m, length=6, regrid_shape=20,\n transform=ccrs.PlateCarree(),\n color='k', zorder=8, label='850-hPa Jet Core Winds (kt)')\n\n# Legend\npurple = mpatches.Patch(color='BlueViolet', label='Cyclonic Absolute Vorticity Advection')\nyellow = mpatches.Patch(color='yellow', label='Surface MSLP < 1010 hPa')\ngreen = mpatches.Patch(color='green', label='Surface Td > 65 F')\ntan = mpatches.Patch(color='tan', label='700 hPa Dewpoint Depression > 15 C')\nred_line = lines.Line2D([], [], color='red', label='Best Lifted Index (C)')\ndashed_black_line = lines.Line2D([], [], linestyle='dashed', color='k',\n label='12-hr Surface Pressure Falls (hPa)')\nblack_line = lines.Line2D([], [], linestyle='solid', color='k',\n label='12-hr 500-hPa Height Falls (m)')\nplt.legend(handles=[jet300, jet500, jet850, dashed_black_line, black_line, red_line,\n purple, tan, green, yellow], loc=3,\n title='Composite Analysis Valid: {:s}'.format(str(vtimes[0])))\n\nplt.show()",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"language_info": {
"codemirror_mode": {
"version": 3,
"name": "ipython"
},
"version": "3.6.2",
"name": "python",
"pygments_lexer": "ipython3",
"mimetype": "text/x-python",
"file_extension": ".py",
"nbconvert_exporter": "python"
},
"kernelspec": {
"name": "conda-env-IOOS3b-py",
"display_name": "Python [conda env:IOOS3b]",
"language": "python"
},
"gist": {
"id": "",
"data": {
"description": "testing/miller_composite.ipynb",
"public": true
}
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment