xradar

0.11.1 · active · verified Fri Apr 17

xradar (version 0.11.1) provides tools to load and process weather radar data into the xarray data model, enabling efficient, labeled multi-dimensional array computing. It focuses on reading various radar formats (e.g., ODIM H5, IRIS, GPM) and converting them into structured xarray Datasets or Groups, often leveraging internal dependencies like wradlib and pyodim. The library is actively maintained with several releases per year, evolving its API and adding support for new data formats and processing capabilities.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load a common ODIM H5 radar file using `xradar.io.read_odim_h5`. It then shows how to access the resulting xarray Group, navigate to individual sweeps (which are xarray Datasets), and inspect a data variable like reflectivity (DBZH). A helper comment is included to assist in downloading a suitable example file if you don't have one.

import xradar as xrdr
import xarray as xr
import os

# --- Instructions to get an example ODIM H5 file ---
# Option 1: Download it (requires 'wget' or equivalent)
# If you don't have 'wget' (e.g., on Windows), manually download from:
# https://github.com/xarray-contrib/xradar/raw/main/doc/source/notebooks/data/example.h5
# Save it as 'example.h5' in the same directory as this script.
# os.system("wget -nc https://github.com/xarray-contrib/xradar/raw/main/doc/source/notebooks/data/example.h5 -O example.h5")

file_path = "example.h5"

if os.path.exists(file_path):
    try:
        # Read the ODIM H5 file into an xarray Group of Datasets
        # Each sweep is typically a separate Dataset within the Group
        ds_group = xrdr.io.read_odim_h5(file_path)

        print(f"Successfully loaded data from: {file_path}")
        print("Dataset Group structure:")
        print(ds_group)

        # Access a specific sweep (e.g., 'sweep_0')
        if 'sweep_0' in ds_group.keys():
            sweep_0 = ds_group['sweep_0']
            print("\nFirst sweep (sweep_0) details:")
            print(sweep_0)
            
            # Access a specific data variable (e.g., 'DBZH' - Reflectivity)
            if 'DBZH' in sweep_0.data_vars:
                print("\nFirst sweep's reflectivity (DBZH) data snippet:")
                print(sweep_0.DBZH.isel(range=slice(0, 5), azimuth=slice(0, 5)))
            else:
                print("\n'DBZH' variable not found in sweep_0.")
        else:
            print("\n'sweep_0' not found in the dataset group.")

    except Exception as e:
        print(f"Error processing file '{file_path}': {e}")
        print("Please ensure the file is a valid ODIM H5 radar file and dependencies are installed.")
else:
    print(f"Error: Example file '{file_path}' not found.")
    print("Please download it as per the instructions above, or provide your own ODIM H5 file.")

view raw JSON →