{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Create an RHI plot with reflectivity contour lines from an MDV file\n\nAn example which creates an RHI plot of reflectivity using a RadarDisplay object\nand adding differnential Reflectivity contours from the same MDV file.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(__doc__)\n\n# Author: Cory Weber (cweber@anl.gov)\n# License: BSD 3 clause\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport scipy.ndimage as ndimage\n\nimport pyart\nfrom pyart.testing import get_test_data\n\nfilename = get_test_data(\"220629.mdv\")\n\n# create the plot using RadarDisplay\nsweep = 0\n# read file\nradar = pyart.io.read_mdv(filename)\ndisplay = pyart.graph.RadarDisplay(radar)\nfig = plt.figure(figsize=[20, 5])\nax = fig.add_subplot(111)\n\n# plot reflectivity\n# alpha=0.25 sets the transparency of the pcolormesh to 75% transparent against\n# the default white. matplolib overlaps the edges of the pcolormesh and creates\n# a visable border around the edge, even with the default of edgecolor set to\n# 'none' the transparancy is effected. the flowing paramters are designed to\n# compensate for that:\n# edgecolors=(1.0, 1.0, 1.0, 0.1) sets the lines between patches to nearly\n# transparent\n# linewidth=0.00015 makes lines between patches very small\n# antialiased=true removes moire patterns.\n\ndisplay.plot(\n \"reflectivity\",\n sweep=sweep,\n vmin=-8,\n vmax=64.0,\n fig=fig,\n ax=ax,\n colorbar_label=\"Reflectivity (dB)\",\n alpha=0.75,\n edgecolors=(0.5, 0.5, 0.5, 0.3),\n linewidth=0.001,\n antialiased=True,\n)\n\n# Normal no alpha\n# display.plot('reflectivity', sweep=sweep, vmin=-8, vmax=64.0, fig=fig,\n# ax=ax, colorbar_label='Reflectivity (dB)', antialiased=True)\n\n# get data\nstart = radar.get_start(sweep)\nend = radar.get_end(sweep) + 1\ndata = radar.get_field(sweep, \"differential_reflectivity\")\nx, y, z = radar.get_gate_x_y_z(sweep, edges=False)\n\nx /= 1000.0\ny /= 1000.0\nz /= 1000.0\n\n# apply a gaussian blur to the data set for nice smooth lines:\n# sigma adjusts the distance effect of blending each cell,\n# 4 is arbirarly set for visual impact.\ndata = ndimage.gaussian_filter(data, sigma=4)\n\n# calculate (R)ange\nR = np.sqrt(x**2 + y**2) * np.sign(y)\nR = -R\ndisplay.set_limits(xlim=[0, 40], ylim=[0, 15])\n\n# add contours\n# creates steps 35 to 100 by 5\nlevels = np.arange(-3, 4, 0.25)\n# levels_rain = np.arange(1, 4, 0.5)\nlevels_ice = np.arange(-2, -0, 0.5)\nlevels_rain = [0.75]\n\n# adds contours to plot\ncontours = ax.contour(R, z, data, levels, linewidths=1, colors=\"k\", antialiased=True)\n# adds more contours for ice and rain, matplotlib supports multiple sets of\n# contours ice\ncontours_ice = ax.contour(R, z, data, levels_ice, linewidths=2, colors=\"blue\")\n# contours heavy rain\ncontours_rain = ax.contour(R, z, data, levels_rain, linewidths=2, colors=\"red\")\n\n# adds contour labels (fmt= '%r' displays 10.0 vs 10.0000)\nplt.clabel(contours, levels, fmt=\"%r\", inline=True, fontsize=10)\n\nplt.show()" ] } ], "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.14.3" } }, "nbformat": 4, "nbformat_minor": 0 }