Blog | wxster.comhttps://wxster.com/blog2019-02-27T03:34:55+00:00Recent postsPlot soundings from acars data2019-02-27T03:34:55+00:00Casey Websterhttps://wxster.com/blog/author/caseyhttps://wxster.com/blog/2019/02/plot-soundings-from-acars-data<p>Atmospheric soundings via balloon launch are few and far between, only normally launching twice per day at 00Z and 12Z. Even if you are interested in a sounding at those times, chances are you aren't close to one, as the spatial coverage of these launches is sparse.</p>
<p>However, plenty of aircraft flying overhead at all times of day and night are equipped with sensors that measure atmospheric temperature and moisture and in partnership with NOAA, ingest that data via ACARS. NOAA provides this data at <a href="https://madis-data.ncep.noaa.gov/madisPublic1/data/point/acars/netcdf/">here</a> but there are limited options for viewing this data through the NWS Madis website.</p>
<p>The data used for these plots is publicly available from the National Weather Service. For more information about this data, <a href="https://wxster.com/static/media/uploads/acars/intro_to_aircraft_soundings_2.ppt">see this presentation by Rich Mamrosh</a>, a NWS meteorologist in Wisconsin.
Having this data available as atmospheric sounding visualizations would be an asset to many people, and particularly the storm chasing community.</p>
<p>To that end, I present the initial release of my visualizations <a href="https://wxster.com/acars">here, at https://wxster.com/acars</a>, which will let you select a date and time (UTC) and select a profile to plot. Each profile is named for the airport the flight either departed from (UP) or landed at (DOWN). Not all of the profiles are complete, and not all are clean. You wouldn't want to initialize a model with this data as-is, but you could certainly use it out in the field if you didn't bring your own balloon launching equipment.</p>
<p><img alt="sounding" src="https://wxster.com/static/media/uploads/acars.png"/></p>
<p>I have plans to improve the site by adding the ability to browse the soundings by airport rather than by time and to visualize the available soundings on a map.</p>
<p>The sounding data available on the madis site only provides a few days back in time, but I am locally caching these datasets and will have as much history as I have free disk space on this server.</p>
<p>If you are interesting in plotting this data yourself, the plotting is performed by my <a href="https://github.com/cwebster2/pyMeteo">pyMeteo</a> project, which you can obtain via pip, anaconda or github. The <code>plot acars</code> command that is installed by this package will let you plot this same data with a little bit more than appears on the site currently.</p>
<p>If you want specific improvements to the site or the plots, please open an issue on the pyMeteo github site, as this provides me the most visibility to them and reminds me they exist.</p>Plotting Skew-T diagrams in Python 2015-12-27T23:19:01+00:00Casey Websterhttps://wxster.com/blog/author/caseyhttps://wxster.com/blog/2015/12/plotting-skew-t-diagrams-in-python<p>One feature of my python meteorological package <a href="https://wxster.com/projects/pymeteo">pyMeteo</a> is SkewT/LnP plotting from various data formats. These plots can read directly from certain kinds of model input and output data files from command line scripts and from numpy arrays in your python scripts.</p>
<div class="toc">
<ul>
<li><a href="https://wxster.com/blog/feeds/atom#skew-t-ln-p-diagrams">Skew-T / Ln-P diagrams</a><ul>
<li><a href="https://wxster.com/blog/feeds/atom#example-plot">Example plot</a></li>
</ul>
</li>
<li><a href="https://wxster.com/blog/feeds/atom#plotting-from-data">Plotting from data</a><ul>
<li><a href="https://wxster.com/blog/feeds/atom#tabular">Tabular</a></li>
<li><a href="https://wxster.com/blog/feeds/atom#cm1">CM1</a></li>
<li><a href="https://wxster.com/blog/feeds/atom#cm1-hdf5">CM1 / HDF5</a></li>
<li><a href="https://wxster.com/blog/feeds/atom#wrf">WRF</a></li>
<li><a href="https://wxster.com/blog/feeds/atom#from-numpy-arrays">From Numpy arrays</a></li>
</ul>
</li>
</ul>
</div>
<h1 id="skew-t-ln-p-diagrams">Skew-T / Ln-P diagrams</h1>
<p>Skew-T / Ln-P plots are simply 2-D plots with a skewed temperature axis and a logarithmic pressure axes (y). Data plotted on this style of plot include temperature, dew point, and various other derived values such as the temperature of a parcel lifted from the surface. The plots produced by these scripts also have a hodograph plotted and a data block with convective storm parameters.</p>
<h2 id="example-plot">Example plot</h2>
<p><a href="https://wxster.com/static/media/skewt/skewt.png"><img alt="skewt" src="https://wxster.com/static/media/skewt/skewt.png"/></a></p>
<h1 id="plotting-from-data">Plotting from data</h1>
<p>In all of the plotting methods, the plot output type is determined by the extension of the output file provided. You can write any type of file that the matplotlib backend can write.</p>
<h2 id="tabular">Tabular</h2>
<p>If you have tabular data suitable for WRF or CM1 model initialization, you can plot a skewt of this data with:</p>
<div class="codehilite"><pre><span class="nv">$ </span>skewt -f sounding.dat -o skewt.pdf
</pre></div>
<p>The format of the sounding data file is</p>
<blockquote>
<p>1 line header that contains: surface pressure (mb) surface theta (K) surface qv (g/kg)</p>
<p>following lines are: height (m) theta (K) qv (g/kg) u (m/s) v (m/s)</p>
</blockquote>
<h2 id="cm1">CM1</h2>
<p>For CM1 output in native GrADS format, you can plot a skewt from model output with</p>
<div class="codehilite"><pre><span class="nv">$ </span>skewt -p . -d cm1out -x <span class="m">0</span> -y <span class="m">0</span> -o skewt-cm1.pdf
</pre></div>
<p>In this case, <code>-p</code> is the path to the dataset, <code>-d</code> is the CM1 <code>output_basename</code>, <code>-x</code> and <code>-y</code> are the location of the plot in km and <code>-o</code> is the file to output. The current version (v0.4) of this script only works for CM1 datasets that are output with one file per timestep and will plot whatever timestep the file contains. </p>
<h2 id="cm1-hdf5">CM1 / HDF5</h2>
<p>For CM1 output in HDF5 format, you can plot a skewt from model output with:</p>
<div class="codehilite"><pre><span class="nv">$ </span>skewt-hdf -d model-data.h5 -x <span class="m">0</span> -y <span class="m">0</span> -o output.pdf
</pre></div>
<p>This currently requires that HDF5 output be un-tiled (though it might work for tiled files, I have not checked). The options are as in the CM1 GrADS version except that there is no <code>-p</code> and <code>-d</code> references a specific HDF5 file. This also assumes one file per timestep and will plot whatever timestep the file contains.</p>
<h2 id="wrf">WRF</h2>
<p>For WRF output in NetCDF format, you can plot a skewt from model output with:</p>
<div class="codehilite"><pre><span class="nv">$ </span>skewt-wrf -d wrfout.nc --lat <span class="m">30</span> --lon -80 -t <span class="m">0</span> -o skewt.pdf
</pre></div>
<p>In this case, <code>-d</code> references a WRF output file, <code>--lat</code> and <code>--lon</code> reference a location within the WRF domain, <code>-t</code> reference a timestep within the WRF output and <code>-o</code> specifies an output files.</p>
<h2 id="from-numpy-arrays">From Numpy arrays</h2>
<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pymeteo.skewt</span> <span class="kn">as</span> <span class="nn">skewt</span>
<span class="c"># prepare 1D arrays height (z), pressure (p), potential temperature (th), </span>
<span class="c"># water vapor mixing ratio (qv), winds (u and v) all of the same length.</span>
<span class="n">skewt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="bp">None</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">th</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">qv</span><span class="p">,</span> <span class="n">u</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="s">'output.pdf'</span><span class="p">)</span>
</pre></div>
<p>You can also choose to plot just the sounding, just the hodograph or plot each on on axes that you define. For details see the implementation of <code>pymeteo.skewt.plot()</code> and the <a href="http://pythonhosted.org/pymeteo/">pyMeteo documentation</a>.</p>Using two filled contour plots simultaneously in matplotlib2015-12-02T01:56:22+00:00Casey Websterhttps://wxster.com/blog/author/caseyhttps://wxster.com/blog/2015/12/using-two-filled-contour-plots-simultaneously-in-matplotlib<p>In my research endeavors I came across the need to overlay two filled contour plots to combine information with context needed to interpret it. I found some older solutions that were quite complicated but managed to find a much simpler solution. </p>
<div class="toc">
<ul>
<li><a href="https://wxster.com/blog/feeds/atom#motivation">Motivation</a></li>
<li><a href="https://wxster.com/blog/feeds/atom#alpha-blending">Alpha blending</a></li>
<li><a href="https://wxster.com/blog/feeds/atom#notes">Notes</a></li>
<li><a href="https://wxster.com/blog/feeds/atom#references">References</a></li>
</ul>
</div>
<h3 id="motivation">Motivation</h3>
<p>First, to motivate the need for two filled contours, here are examples of the data that I was looking at. The data I want to display is circulation, a measure of macroscopic rotation given by: $$\Gamma = \oint \mathbf{u}\cdot\mathrm{d}l$$ This is straightforward to plot:</p>
<p><img alt="Circulation" src="https://wxster.com/static/media/uploads/contourf-single-circ-resized.png"/></p>
<p>This presentation lacks context for the circulation, which the circulation is located in reference to storm structure. I also have reflectivity (simulated) data, which is similarly straightforward to plot:</p>
<p><img alt="Reflectivity" src="https://wxster.com/static/media/uploads/contourf-single-dbz-resized.png"/></p>
<p>One solution to plotting both sets of data together it to switch one to unfilled contour. This, however, makes interpreting the data more work. So how do we combine both filled contour plots into one image?</p>
<h3 id="alpha-blending">Alpha blending</h3>
<p>The key to plotting two filled plots is use alpha blending. This can be accomplished by setting the <code>alpha</code> kwarg in the call to <code>contourf</code>. Doing this for both contours though presents presentation problems. Ideally I want the reflectivity data to be a subtle background and the circulation plot to be the focus. To accomplish this I do plot the relfectivity with an <code>alpha</code> kwarg, e.g.</p>
<div class="codehilite"><pre>CSdbz = plt.contourf(X,Y,dbz[t,z25,:,:], levels=radar.cmap_radar_levels(),
cmap=plt.get_cmap('pymeteo_radar'), alpha=0.2)
</pre></div>
<p>For the circulation data I instead modify the colormap to include transparency so that the reds and blues can remain distinct without too much blending.</p>
<div class="codehilite"><pre>c_red = matplotlib.colors.colorConverter.to_rgba('red')
c_blue= matplotlib.colors.colorConverter.to_rgba('blue')
c_white_trans = matplotlib.colors.colorConverter.to_rgba('white',alpha = 0.0)
cmap_rb = matplotlib.colors.LinearSegmentedColormap.from_list('rb_cmap',[c_red,c_white_trans,c_blue],512)
</pre></div>
<p>This sets the colormap ends to red and blue and uses white to blend them together. This is essentially how the normal RedBlue colorbar works except my white color is completely transparent. This lets the background show through the blank parts of the circulation plot but lets the colors stay bright. I plot this with:</p>
<div class="codehilite"><pre> CSc = plt.contourf(Xc,Yc,circ[ct_idx,z25c,:,:], levels=levels, cmap=cmap_rb, extend='both')
</pre></div>
<p>The resulting plot is:</p>
<p><img alt="Reflectivity and Circ" src="https://wxster.com/static/media/uploads/contourf-dual-resized.png"/></p>
<h3 id="notes">Notes</h3>
<p>You will have to save the image in a format that supports alpha levels for this to work, otherwise only one of the plots will show. The PNG and PDF output work for producing raster and vector output but EPS will not work.</p>
<h3 id="references">References</h3>
<p>The referenced python modules:</p>
<ul>
<li><a href="http://matplotlib.org/">matplotlib</a> </li>
<li><a href="https://github.com/cwebster2/pyMeteo">pymeteo</a></li>
</ul>Welcome to wxster.com2015-11-29T19:13:45+00:00Casey Websterhttps://wxster.com/blog/author/caseyhttps://wxster.com/blog/2015/11/welcome-to-wxstercom<p>Welcome to my personal blog where I'll be posting about meteorology, software development, system administration, aviation and whatever else comes to mind. This is also a good excuse to become more familiar with front-end development to fill out my full stack credentials. </p>
<p>This blog is powered by <a href="http://mezzanine.jupo.org">Mezzanine</a> and <a href="https://www.djangoproject.com">Django</a>, themed with <a href="http://getbootstrap.com/css/">Bootstrap</a>, hosted with <a href="http://nginx.org">nginx</a> and <a href="https://github.com/unbit/uwsgi">uwsgi</a> over SSL with a certificate from <a href="https://letsencrypt.org">Let's Encrypt</a>. This is all running on a <a href="https://www.digitalocean.com">Digital Ocean VPS</a> running <a href="https://www.debian.org">Debian Linux</a>. </p>
<p>I've been writing software since I was a kid when my grandmother finally trusted me enough to mess around with her <a href="https://en.wikipedia.org/wiki/Commodore_64">Commodore-64</a> where I learned BASIC. I program in C, C++, Fortran (2003,2008), Python, Perl and others. I've been running Linux for 20 years and know my way around web servers (Apache, Nginx), mail servers (sendmail, postfix, dovecot), DNS, as well as system programming. I also wear the hats of a meteorologist (We Are!), an aviator (flight instructor and airline pilot), husband and father. </p>