Skip to content

timcash/nexrad_view

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nexrad Viewer

Downloading NEXRAD Data

Overview

NEXRAD (Next-Generation Radar) Level II data is publicly available through AWS S3. The data is organized by date and radar site, making it easy to download specific datasets.

Data Access Methods

1. AWS S3 Direct Access

NEXRAD Level II data is stored in the AWS S3 bucket: s3://noaa-nexrad-level2

Bucket Structure:

s3://noaa-nexrad-level2/
  └── YYYY/
      └── MM/
          └── DD/
              └── RADAR_SITE/
                  └── RADAR_SITE_YYYYMMDD_HHMMSS_V##.gz

Path Format:

  • YYYY - 4-digit year (e.g., 2024)
  • MM - 2-digit month (e.g., 01, 12)
  • DD - 2-digit day (e.g., 01, 31)
  • RADAR_SITE - 4-letter radar site identifier (e.g., KTLX, KFWS, KDFW)

Example Path:

s3://noaa-nexrad-level2/2024/01/15/KTLX/KTLX20240115_120000_V06.gz

2. Python Libraries

nexradaws

  • Library: nexradaws (pip install nexradaws)
  • Provides easy-to-use functions to query and download NEXRAD data
  • Example:
    import nexradaws
    
    conn = nexradaws.NexradAwsInterface()
    scans = conn.get_avail_scans('2024-01-15', 'KTLX')
    conn.download(scans, '/path/to/download')

pyart

  • Library: arm_pyart (pip install arm_pyart)
  • Comprehensive radar data analysis library
  • Can read NEXRAD Level II files after download

boto3 (AWS SDK)

  • Direct S3 access using AWS SDK
  • Example:
    import boto3
    
    s3 = boto3.client('s3', region_name='us-east-1')
    s3.download_file('noaa-nexrad-level2', 
                     '2024/01/15/KTLX/KTLX20240115_120000_V06.gz',
                     'local_file.gz')

3. Command Line Tools

AWS CLI

aws s3 ls s3://noaa-nexrad-level2/2024/01/15/KTLX/
aws s3 cp s3://noaa-nexrad-level2/2024/01/15/KTLX/file.gz ./

wget/curl

  • Can download directly from S3 public URLs (though S3 API is preferred)

Radar Site Codes

NEXRAD sites use 4-letter identifiers (ICAO format):

  • Format: K + 3-letter identifier
  • Examples:
    • KTLX - Twin Lakes, Oklahoma
    • KFWS - Fort Worth, Texas
    • KDFW - Dallas/Fort Worth, Texas
    • KJAX - Jacksonville, Florida

Full list of radar sites available at: https://www.weather.gov/radar_tabular

Data Organization Details

File Naming Convention:

RADAR_SITE_YYYYMMDD_HHMMSS_V##.gz
  • RADAR_SITE - 4-letter site code
  • YYYYMMDD - Date (year, month, day)
  • HHMMSS - Time (hour, minute, second, UTC)
  • V## - Version number (typically V06)
  • .gz - Gzip compressed

Data Format:

  • Files are compressed with gzip
  • Original format is NEXRAD Level II (binary format)
  • Requires specialized software/libraries to read (pyart, wradlib, etc.)

Time Resolution:

  • Scans typically occur every 4-10 minutes
  • Multiple scans per day available
  • Historical data available back to ~1991

Accessing Data by Date and Site

Query Available Scans:

  1. List all files for a specific date and site:

    aws s3 ls s3://noaa-nexrad-level2/YYYY/MM/DD/RADAR_SITE/ --recursive
  2. Using Python (nexradaws):

    import nexradaws
    conn = nexradaws.NexradAwsInterface()
    scans = conn.get_avail_scans('2024-01-15', 'KTLX')
    print(f"Found {len(scans)} scans")

Download Specific Time Range:

import nexradaws
from datetime import datetime

conn = nexradaws.NexradAwsInterface()
start = datetime(2024, 1, 15, 12, 0, 0)
end = datetime(2024, 1, 15, 18, 0, 0)
scans = conn.get_avail_scans_in_range(start, end, 'KTLX')
conn.download(scans, './downloads')

Using the Code

This project provides Python modules for downloading and visualizing NEXRAD Level II data.

Installation

The project uses pixi for dependency management. Install dependencies with:

pixi install

Dependencies include:

  • python (3.12.*)
  • nexradaws - For downloading NEXRAD data from AWS
  • arm_pyart - For reading and plotting radar data
  • matplotlib - For creating visualizations

Module: nexrad.py

The nexrad.py module provides functions for downloading and plotting NEXRAD data.

Functions

download_nexrad_data(date_str, radar_site, output_dir="./downloads", time_range=None)

  • Downloads NEXRAD Level II data for a given date and radar site
  • Parameters:
    • date_str: Date in format 'YYYY-MM-DD' (e.g., '2024-01-15')
    • radar_site: 4-letter radar site identifier (e.g., 'KTLX', 'KFWS')
    • output_dir: Directory to save downloaded files (default: './downloads')
    • time_range: Optional tuple of (start_time, end_time) as datetime objects
  • Returns: List of paths to downloaded files
  • Example:
    from nexrad import download_nexrad_data
    
    files = download_nexrad_data('2024-01-15', 'KTLX', './downloads')
    print(f"Downloaded {len(files)} files")

download_nexrad_data_by_time_range(date_str, radar_site, start_hour, end_hour, output_dir="./downloads")

  • Downloads NEXRAD data for a specific date and time range
  • Parameters:
    • date_str: Date in format 'YYYY-MM-DD'
    • radar_site: 4-letter radar site identifier
    • start_hour: Start hour (0-23) in UTC
    • end_hour: End hour (0-23) in UTC
    • output_dir: Directory to save downloaded files
  • Returns: List of paths to downloaded files
  • Example:
    from nexrad import download_nexrad_data_by_time_range
    
    files = download_nexrad_data_by_time_range(
        '2024-01-15', 'KTLX', 
        start_hour=12, 
        end_hour=18,
        output_dir='./downloads'
    )

plot_nexrad_data(file_path, output_path=None, field='reflectivity', sweep=0, figsize=(10, 10))

  • Plots NEXRAD Level II data using pyart
  • Parameters:
    • file_path: Path to the NEXRAD Level II file (.gz or uncompressed)
    • output_path: Optional path to save the plot. If None, saves to plots folder with naming: radar_date_time_variable.png
    • field: Radar field to plot (default: 'reflectivity'). Common fields: 'reflectivity', 'velocity', 'spectrum_width'
    • sweep: Sweep/elevation angle index to plot (default: 0, lowest elevation)
    • figsize: Figure size tuple (width, height) in inches
  • Returns: Path to the saved plot file
  • Example:
    from nexrad import plot_nexrad_data
    
    plot_path = plot_nexrad_data('./downloads/KTLX20240115_120000_V06')
    print(f"Plot saved to: {plot_path}")

plot_multiple_nexrad_files(file_paths, output_dir=None, field='reflectivity', sweep=0)

  • Plots multiple NEXRAD files and saves plots
  • Parameters:
    • file_paths: List of paths to NEXRAD Level II files
    • output_dir: Optional directory to save plots. If None, saves to plots folder next to each file
    • field: Radar field to plot (default: 'reflectivity')
    • sweep: Sweep/elevation angle index to plot (default: 0)
  • Returns: List of paths to saved plot files
  • Example:
    from nexrad import plot_multiple_nexrad_files
    
    files = ['./downloads/file1', './downloads/file2']
    plot_paths = plot_multiple_nexrad_files(files, field='reflectivity')

download_and_plot_sequential_scans(start_datetime, radar_site, n_additional, output_dir="./downloads", plots_dir=None, field='reflectivity', sweep=0)

  • Downloads and plots a scan at a given datetime plus n additional sequential scans
  • Parameters:
    • start_datetime: Starting datetime for the first scan (datetime object)
    • radar_site: 4-letter radar site identifier (e.g., 'KTLX')
    • n_additional: Number of additional scans to download and plot after the start datetime
    • output_dir: Directory to save downloaded files (default: './downloads')
    • plots_dir: Directory to save plots. If None, uses 'plots' folder at root
    • field: Radar field to plot (default: 'reflectivity')
    • sweep: Sweep/elevation angle index to plot (default: 0)
  • Returns: List of paths to saved plot files
  • Example:
    from nexrad import download_and_plot_sequential_scans
    from datetime import datetime
    
    start = datetime(2024, 1, 15, 12, 0, 0)
    plots = download_and_plot_sequential_scans(start, 'KTLX', 3)
    print(f"Created {len(plots)} plots")

Command Line Usage

You can also run nexrad.py directly from the command line:

pixi run python nexrad.py <date> <radar_site> [output_dir]

Example:

pixi run python nexrad.py 2024-01-15 KTLX ./downloads

This will download all scans for the specified date and radar site, and automatically plot the first file.

Module: test.py

The test.py script provides comprehensive tests for all functionality in nexrad.py.

Running Tests

Run all tests with:

pixi run python test.py

Test Functions

The test script includes the following test functions:

  1. test_list_available_scans() - Tests querying available scans for yesterday
  2. test_download_nexrad_data() - Tests downloading NEXRAD data for a 1-hour time window
  3. test_plot_nexrad_data() - Tests plotting a single NEXRAD file
  4. test_sequential_scans_plotting() - Tests downloading and plotting sequential scans

All tests use yesterday's date to ensure data availability and download a small sample to keep test execution time reasonable.

Test Output

The test script provides detailed output showing:

  • Number of scans found
  • Files downloaded
  • Plots created
  • File sizes and paths
  • Test pass/fail status

Plot Naming Convention

Plots are automatically saved with the naming format:

radar_date_time_variable.png

Example: KTLX_20240115_120505_reflectivity.png

  • KTLX - Radar site code
  • 20240115 - Date (YYYYMMDD)
  • 120505 - Time (HHMMSS UTC)
  • reflectivity - Radar variable plotted

Plots are saved in the plots folder at the project root by default.

Complete Example Workflow

from nexrad import download_and_plot_sequential_scans
from datetime import datetime

# Download and plot 4 sequential scans starting at noon
start_time = datetime(2024, 1, 15, 12, 0, 0)
plot_paths = download_and_plot_sequential_scans(
    start_datetime=start_time,
    radar_site='KTLX',
    n_additional=3,  # Total of 4 scans (1 initial + 3 additional)
    output_dir='./downloads',
    plots_dir='plots',
    field='reflectivity'
)

print(f"Created {len(plot_paths)} plots:")
for plot_path in plot_paths:
    print(f"  - {plot_path}")

Additional Resources

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages