{ "cells": [ { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from awips.dataaccess import DataAccessLayer\n", "from awips.tables import profiler\n", "import matplotlib.tri as mtri\n", "from datetime import datetime, timedelta\n", "from matplotlib.dates import date2num\n", "from metpy.units import units\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "# Query ESRL/PSD profiler data from Unidata AWIPS\n", "DataAccessLayer.changeEDEXHost(\"edex-cloud.unidata.ucar.edu\")\n", "request = DataAccessLayer.newDataRequest()\n", "request.setDatatype(\"profiler\")\n", "profilerSites = DataAccessLayer.getAvailableLocationNames(request)\n", "\n", "%matplotlib inline\n", "fig = plt.figure(figsize=(16,7*len(profilerSites)))\n", " \n", "for i, site in enumerate(profilerSites):\n", " request = DataAccessLayer.newDataRequest()\n", " request.setDatatype(\"profiler\")\n", " request.setLocationNames(site)\n", " request.setParameters(\"uComponent\",\"vComponent\")\n", "\n", " # Request the last twelve hourly obs\n", " hrs=12\n", " requestTimes = DataAccessLayer.getAvailableTimes(request)[-1*hrs:]\n", " response = DataAccessLayer.getGeometryData(request,requestTimes)\n", "\n", " # Build arrays \n", " u,v,times=[],[],[]\n", " for time in requestTimes:\n", " uu,vv,heights=[],[],[]\n", " for ob in response:\n", " if str(ob.getDataTime().getValidPeriod().start) == str(time):\n", " uu.append(float(ob.getString(\"uComponent\")))\n", " vv.append(float(ob.getString(\"vComponent\")))\n", " heights.append(float(ob.getLevel().translate(None, 'FHAG')))\n", " u.append(uu)\n", " v.append(vv)\n", " times.append(time.validPeriod.start)\n", "\n", " # Convert u,v components to knots and transpose arrays to match t,h\n", " u = (np.asarray(u, dtype=np.float32) * units('m/s')).to('knots').T\n", " v = (np.asarray(v, dtype=np.float32) * units('m/s')).to('knots').T\n", " t, h = np.meshgrid(times, heights)\n", " C = np.sqrt(u**2 + v**2)\n", " cmap=plt.cm.RdYlGn_r\n", " \n", " profilerName=str(profiler[site]['profilerName'])\n", " profilerId=str(profiler[site]['profilerId'])\n", " profilerLat=str(profiler[site]['latitude'])\n", " profilerLng=str(profiler[site]['longitude'])\n", " imgTitle=site +\" \"+ profilerId +\", \"+ profilerName +\" (\"+ profilerLat +\",\"+ profilerLng +\")\"\n", " \n", " ax = fig.add_subplot(len(profilerSites),1,i+1)\n", " ax.title.set_text(imgTitle)\n", " ax.barbs(date2num(t), h, u, v, C, cmap=cmap)\n", " ax.xaxis_date()\n", " ax.set_xlim(times[0]-timedelta(hours=1), times[-1]+timedelta(hours=1))\n", " ax.set_ylim(0,10000)\n", " ax.grid(axis='x', which='major', alpha=0.5)\n", " ax.grid(axis='y', which='major', linestyle=':')\n", " plt.gca().invert_xaxis()" ] } ], "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.6.6" } }, "nbformat": 4, "nbformat_minor": 1 }