.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/plotting/plot_max_cappi.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_plotting_plot_max_cappi.py: ============= Plot Max-CAPPI ============= This is an example of how to plot a Max-CAPPI within a Py-ART grid display object. .. GENERATED FROM PYTHON SOURCE LINES 10-22 .. code-block:: Python print(__doc__) # Author: Hamid Ali Syed (syed44@purdue.edu) # License: BSD 3 clause import matplotlib.pyplot as plt import numpy as np import pyart from pyart.testing import get_test_data .. GENERATED FROM PYTHON SOURCE LINES 23-25 ** MAX-CAPPI Display .. GENERATED FROM PYTHON SOURCE LINES 25-36 .. code-block:: Python # Define and Read in the test data grid_file = get_test_data("20110520100000_nexrad_grid.nc") grid = pyart.io.read_grid(grid_file) # Create a grid display gdisplay = pyart.graph.GridMapDisplay(grid) gdisplay.plot_maxcappi(field="REF", range_rings=True, add_slogan=True) .. image-sg:: /examples/plotting/images/sphx_glr_plot_max_cappi_001.png :alt: plot max cappi :srcset: /examples/plotting/images/sphx_glr_plot_max_cappi_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 37-40 ** Second Example Let's read in a Nexrad data and create a grid. .. GENERATED FROM PYTHON SOURCE LINES 40-112 .. code-block:: Python import logging from datetime import datetime import fsspec import pytz def download_nexrad(timezone, date, site, local_date=False): """Download NEXRAD radar data from an S3 bucket.""" try: utc_date = ( pytz.timezone(timezone).localize(date).astimezone(pytz.utc) if local_date else date ) logging.info(f"Time: {utc_date}") fs = fsspec.filesystem("s3", anon=True) nexrad_path = utc_date.strftime( f"s3://noaa-nexrad-level2/%Y/%m/%d/{site}/{site}%Y%m%d_%H*" ) files = sorted(fs.glob(nexrad_path)) return [file for file in files if not file.endswith("_MDM")] except Exception as e: logging.error("Error in processing: %s", e) return [] # Load NEXRAD data from S3 Bucket site = "PHWA" timezone = "UTC" date = datetime(2024, 8, 25, 8, 29) # Correctly passing the site and timezone file = download_nexrad(timezone, date, site, local_date=False)[0] # Read the data using nexrad_archive reader radar = pyart.io.read_nexrad_archive("s3://" + file) # Create a 3D grid # Mask out last 10 gates of each ray, this removes the "ring" around the radar. radar.fields["reflectivity"]["data"][:, -10:] = np.ma.masked # Exclude masked gates from the gridding gatefilter = pyart.filters.GateFilter(radar) gatefilter.exclude_transition() gatefilter.exclude_masked("reflectivity") gatefilter.exclude_outside("reflectivity", 10, 80) # Perform Cartesian mapping, limit to the reflectivity field. max_range = np.ceil(radar.range["data"].max()) if max_range / 1e3 > 250: max_range = 250 * 1e3 grid = pyart.map.grid_from_radars( (radar,), gatefilters=(gatefilter,), grid_shape=(30, 441, 441), grid_limits=((0, 10000), (-max_range, max_range), (-max_range, max_range)), fields=["reflectivity"], ) # Create a grid display gdisplay = pyart.graph.GridMapDisplay(grid) with plt.style.context("dark_background"): gdisplay.plot_maxcappi( field="reflectivity", cmap="pyart_HomeyerRainbow", add_slogan=True ) .. image-sg:: /examples/plotting/images/sphx_glr_plot_max_cappi_002.png :alt: plot max cappi :srcset: /examples/plotting/images/sphx_glr_plot_max_cappi_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none WARNING:matplotlib.font_manager:findfont: Font family 'Courier New' not found. WARNING:matplotlib.font_manager:findfont: Font family 'Courier New' not found. WARNING:matplotlib.font_manager:findfont: Font family 'Courier New' not found. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 13.076 seconds) .. _sphx_glr_download_examples_plotting_plot_max_cappi.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_max_cappi.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_max_cappi.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_max_cappi.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_