python-awips/examples/notebooks/Profiler_Wind_Barb_Time-Series.ipynb

108 lines
3.7 KiB
Text
Raw Normal View History

2018-09-05 15:52:38 -06:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
2018-09-05 15:52:38 -06:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Figure size 1152x0 with 0 Axes>"
2018-09-05 15:52:38 -06:00
]
},
"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(\"149.165.156.89\")\n",
2018-09-05 15:52:38 -06:00
"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(b\"uComponent\")))\n",
" vv.append(float(ob.getString(b\"vComponent\")))\n",
2018-09-05 15:52:38 -06:00
" 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()"
2018-09-05 15:52:38 -06:00
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
2018-09-05 15:52:38 -06:00
"language": "python",
"name": "python3"
2018-09-05 15:52:38 -06:00
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
2018-09-05 15:52:38 -06:00
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
2018-09-05 15:52:38 -06:00
}
},
"nbformat": 4,
"nbformat_minor": 1
}