{ "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 velocity using a RadarDisplay object\nand adding 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 spyi\n\nimport pyart\nfrom pyart.testing import get_test_data\n\nfilename = get_test_data(\"034142.mdv\")\n\n# create the plot using RadarDisplay\nsweep = 2\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 velocity\n# cmap is the color ramp being used in this case blue to red no 18\n# https://github.com/ARM-DOE/pyart/blob/master/pyart/graph/cm.py\n# for more information\n\ndisplay.plot(\n \"velocity\",\n sweep=sweep,\n vmin=-20,\n vmax=20.0,\n fig=fig,\n ax=ax,\n cmap=\"pyart_BuDRd18\",\n colorbar_label=\"Velocity (m/s)\",\n)\n\n# line commented out to show reflectivity\n# display.plot('reflectivity', sweep=sweep, vmin=-0, vmax=45.0, fig=fig,ax=ax)\n\n# get data\nstart = radar.get_start(sweep)\nend = radar.get_end(sweep) + 1\ndata = radar.get_field(sweep, \"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# smooth out the lines\ndata = spyi.gaussian_filter(data, sigma=1.2)\n\n# calculate (R)ange\nR = np.sqrt(x**2 + y**2) * np.sign(y)\nR = -R\ndisplay.set_limits(xlim=[25, 0], ylim=[0, 5])\n\n# add contours\n# creates steps 35 to 100 by 5\nlevels = np.arange(35, 100, 5)\n# adds coutours to plot\ncontours = ax.contour(\n R, z, data, levels, linewidths=1.5, colors=\"k\", linestyles=\"solid\", antialiased=True\n)\n\n# adds contour labels (fmt= '%r' displays 10.0 vs 10.0000)\nplt.clabel(contours, levels, fmt=\"%r\", inline=True, fontsize=10)\n\n\n# format plot\n# add grid (dotted lines, major axis only)\nax.grid(color=\"k\", linestyle=\":\", linewidth=1, which=\"major\")\n\n# horizontal\nax.axhline(0.9, 0, 1, linestyle=\"solid\", color=\"k\", linewidth=2)\nax.axhline(1.3, 0, 1, linestyle=\"dashed\", color=\"k\", linewidth=2)\n\n# vertical\nax.axvline(15, 0, 1, linestyle=\"solid\", color=\"#00b4ff\", linewidth=2)\nax.axvline(4.5, 0, 1, linestyle=\"solid\", color=\"#ff6800\", linewidth=2)\n\n# setting matplotlib overrides display.plot defaults\nax.set_ylabel(\"Altitude above CP-2 (km)\")\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.13.0" } }, "nbformat": 4, "nbformat_minor": 0 }