{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Reading Older NEXRAD Data and Fixing Latitude and Longitude Issues\n\nIn this example, we will show how to read in older NEXRAD files prior\nto 2008 that are missing some coordinate metadata.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(__doc__)\n\n\n# Author: Zachary Sherman (zsherman@anl.gov)\n# License: BSD 3 clause" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Import our required packages.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import cartopy.crs as ccrs\nimport matplotlib.pyplot as plt\n\nimport pyart" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read older NEXRAD Level 2 Data\n\nOlder NEXRAD files prior to 2008, have the tendency to not contain some of\nthe required metadata for Py-ART's NEXRAD reader. This usually results in\nmissing latitude and longitude data, so after reading with Py-ART, both\ncoordinates have a value of 0. This example, we will show how to properly\nread in an older NEXRAD file.\n\nFirst we want to get an older file from amazon web service:\n\n ``s3://unidata-nexrad-level2/year/month/date/radarsite/{radarsite}{year}{month}{date}_{hour}{minute}{second}.gz``\n\nWhere in our case, we are using a sample data file from Handford, CA (KHNX)\non July 24, 2006, at 0203:38 UTC. This means our path would look like this:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Note: Older files do not contain the 'V06' but instead '.gz' in the AWS path.\n\naws_nexrad_level2_file = (\n \"s3://unidata-nexrad-level2/2006/07/24/KHNX/KHNX20060724_020338.gz\"\n)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can use the **pyart.io.read_nexrad_archive** module to access our data, passing in the filepath.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "radar = pyart.io.read_nexrad_archive(aws_nexrad_level2_file)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let us take a look at the radar latitude and longitude data.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(radar.latitude[\"data\"])\nprint(radar.longitude[\"data\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is clearly not correct! The problem is the reader could not find the\nmetadata (message 31) for the coordinates.\n\nLucky for us, we can provide the station in Py-ART's NEXRAD reader, which will\npull the coordinate information from a dictionary found within Py-ART.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "radar = pyart.io.read_nexrad_archive(aws_nexrad_level2_file, station=\"KHNX\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Again, let us take a look at the radar latitude and longitude data.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(radar.latitude[\"data\"])\nprint(radar.longitude[\"data\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Everything now looks correct as this is in Handford CA!\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# We can create a plot as well utilizing Cartopy to see how it looks.\ndisplay = pyart.graph.RadarMapDisplay(radar)\n\n# Setting projection and ploting the first tilt.\nprojection = ccrs.LambertConformal(\n central_latitude=radar.latitude[\"data\"][0],\n central_longitude=radar.longitude[\"data\"][0],\n)\n\nfig = plt.figure(figsize=(6, 6))\ndisplay.plot_ppi_map(\n \"reflectivity\", 0, vmin=-20, vmax=54, projection=projection, resolution=\"10m\"\n)" ] } ], "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 }