{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Plot Max-CAPPI\n\nThis is an example of how to plot a Max-CAPPI\nwithin a Py-ART grid display object.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(__doc__)\n\n# Author: Hamid Ali Syed (syed44@purdue.edu)\n# License: BSD 3 clause\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nimport pyart\nfrom pyart.testing import get_test_data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## MAX-CAPPI Display\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Define and Read in the test data\ngrid_file = get_test_data(\"20110520100000_nexrad_grid.nc\")\ngrid = pyart.io.read_grid(grid_file)\n\n\n# Create a grid display\ngdisplay = pyart.graph.GridMapDisplay(grid)\ngdisplay.plot_maxcappi(field=\"REF\", range_rings=True, add_slogan=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Second Example\n\nLet's read in a Nexrad data and create a grid.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import logging\nfrom datetime import datetime\n\nimport fsspec\nimport pytz\n\n\ndef download_nexrad(timezone, date, site, local_date=False):\n \"\"\"Download NEXRAD radar data from an S3 bucket.\"\"\"\n try:\n utc_date = (\n pytz.timezone(timezone).localize(date).astimezone(pytz.utc)\n if local_date\n else date\n )\n logging.info(f\"Time: {utc_date}\")\n\n fs = fsspec.filesystem(\"s3\", anon=True)\n nexrad_path = utc_date.strftime(\n f\"s3://unidata-nexrad-level2/%Y/%m/%d/{site}/{site}%Y%m%d_%H*\"\n )\n files = sorted(fs.glob(nexrad_path))\n\n return [file for file in files if not file.endswith(\"_MDM\")]\n except Exception as e:\n logging.error(\"Error in processing: %s\", e)\n return []\n\n\n# Load NEXRAD data from S3 Bucket\nsite = \"PHWA\"\ntimezone = \"UTC\"\ndate = datetime(2024, 8, 25, 8, 29)\n\n# Correctly passing the site and timezone\nfile = download_nexrad(timezone, date, site, local_date=False)[0]\n\n\n# Read the data using nexrad_archive reader\nradar = pyart.io.read_nexrad_archive(\"s3://\" + file)\n\n# Create a 3D grid\n# Mask out last 10 gates of each ray, this removes the \"ring\" around the radar.\nradar.fields[\"reflectivity\"][\"data\"][:, -10:] = np.ma.masked\n\n# Exclude masked gates from the gridding\ngatefilter = pyart.filters.GateFilter(radar)\ngatefilter.exclude_transition()\ngatefilter.exclude_masked(\"reflectivity\")\ngatefilter.exclude_outside(\"reflectivity\", 10, 80)\n\n# Perform Cartesian mapping, limit to the reflectivity field.\nmax_range = np.ceil(radar.range[\"data\"].max())\nif max_range / 1e3 > 250:\n max_range = 250 * 1e3\n\ngrid = pyart.map.grid_from_radars(\n (radar,),\n gatefilters=(gatefilter,),\n grid_shape=(30, 441, 441),\n grid_limits=((0, 10000), (-max_range, max_range), (-max_range, max_range)),\n fields=[\"reflectivity\"],\n)\n\n# Create a grid display\ngdisplay = pyart.graph.GridMapDisplay(grid)\nwith plt.style.context(\"dark_background\"):\n gdisplay.plot_maxcappi(field=\"reflectivity\", cmap=\"HomeyerRainbow\", add_slogan=True)" ] } ], "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 }