{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Reading NEXRAD Data from Google Cloud\n\nWithin this example, we show how you can remotely access Next Generation Weather Radar (NEXRAD) Data from Google Cloud Storage\nand plot quick looks of the datasets.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(__doc__)\n\n# Author: Zach Sherman\n# License: BSD 3 clause\n\nimport tarfile\n\n# This example requires installation of the gcsfs library\nimport gcsfs\nimport matplotlib.pyplot as plt\n\nimport pyart" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read NEXRAD Level 2 Data\n\nLet's start first with NEXRAD Level 2 data, which is ground-based radar data collected\nby the National Oceanic and Atmospheric Administration (NOAA), as a part of the National Weather Service\n### Configure our Filepath for NEXRAD Level 2 Data\nWe will access data from Google cloud storage, with the data organized as:\n\n ``gcp-public-data-nexrad-l2/year/month/day/radarsite/NWS_NEXRAD_NXL2DPBL_{radarsite}_{year}{month}{date}{hour}0000_{year}{month}{date}{hour}{minute}.tar``\n\nWhere in our case, we are using a sample data file from Miami, Florida (KAMX)\non October 7, 2016, at 0401:25 UTC. This means our path would look like:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "gcs_path = \"gcp-public-data-nexrad-l2/2016/10/07/KAMX/NWS_NEXRAD_NXL2DPBL_KAMX_20161007040000_20161007045959.tar\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First we can create a file system and retrieve the tar file to our current directory.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "fs = gcsfs.GCSFileSystem()\nfs.get(gcs_path, \".\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The we can use the tarfile module to extract the files within.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "file = tarfile.open(\"NWS_NEXRAD_NXL2DPBL_KAMX_20161007040000_20161007045959.tar\")\nmembers = file.getmembers()\n\n# This case we are getting only the first file.\nfile.extract(members[0].name, \".\", filter=\"data\")\nfile.close()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can use the **pyart.io.read_nexrad_archive** module to access our data, passing in the member filepath.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "radar = pyart.io.read_nexrad_archive(members[0].name)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's take a look at a summary of what fields are available.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(list(radar.fields))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's plot the reflectivity field as a first step to investigating our dataset.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "fig = plt.figure(figsize=(12, 4))\ndisplay = pyart.graph.RadarMapDisplay(radar)\n\ndisplay.plot_ppi_map(\"reflectivity\")\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 }