{"id":10362,"library":"xradar","title":"xradar","description":"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.","status":"active","version":"0.11.1","language":"en","source_language":"en","source_url":"https://github.com/xarray-contrib/xradar","tags":["geospatial","radar","xarray","scientific-computing","weather","meteorology","data-io"],"install":[{"cmd":"pip install xradar","lang":"bash","label":"Install core library"},{"cmd":"pip install xradar[all]","lang":"bash","label":"Install with all optional dependencies (e.g., for plotting)"}],"dependencies":[{"reason":"Core dependency for the xarray data model.","package":"xarray","optional":false},{"reason":"Used for internal radar processing and coordinate transformations.","package":"wradlib","optional":false},{"reason":"Used for reading ODIM H5 files.","package":"pyodim","optional":false},{"reason":"Required for HDF5-based radar formats (e.g., ODIM H5).","package":"h5py","optional":false},{"reason":"Required for NetCDF-based radar formats.","package":"netcdf4","optional":false},{"reason":"Often used for plotting radar data on maps. Installed with `xradar[all]`.","package":"cartopy","optional":true}],"imports":[{"note":"Most IO functions are nested under `xradar.io`. It's best practice to import `xradar` itself and access submodules.","wrong":"from xradar import read_odim_h5","symbol":"read_odim_h5","correct":"import xradar as xrdr\nds = xrdr.io.read_odim_h5(...)"},{"note":"While `import xradar.io as xio` works, `import xradar as xrdr` is the most common and recommended alias, accessing `xrdr.io`.","wrong":"import xradar.io as xio\nds = xio.read_iris(...)","symbol":"xradar.io","correct":"import xradar as xrdr\nds = xrdr.io.read_iris(...)"}],"quickstart":{"code":"import xradar as xrdr\nimport xarray as xr\nimport os\n\n# --- Instructions to get an example ODIM H5 file ---\n# Option 1: Download it (requires 'wget' or equivalent)\n# If you don't have 'wget' (e.g., on Windows), manually download from:\n# https://github.com/xarray-contrib/xradar/raw/main/doc/source/notebooks/data/example.h5\n# Save it as 'example.h5' in the same directory as this script.\n# os.system(\"wget -nc https://github.com/xarray-contrib/xradar/raw/main/doc/source/notebooks/data/example.h5 -O example.h5\")\n\nfile_path = \"example.h5\"\n\nif os.path.exists(file_path):\n    try:\n        # Read the ODIM H5 file into an xarray Group of Datasets\n        # Each sweep is typically a separate Dataset within the Group\n        ds_group = xrdr.io.read_odim_h5(file_path)\n\n        print(f\"Successfully loaded data from: {file_path}\")\n        print(\"Dataset Group structure:\")\n        print(ds_group)\n\n        # Access a specific sweep (e.g., 'sweep_0')\n        if 'sweep_0' in ds_group.keys():\n            sweep_0 = ds_group['sweep_0']\n            print(\"\\nFirst sweep (sweep_0) details:\")\n            print(sweep_0)\n            \n            # Access a specific data variable (e.g., 'DBZH' - Reflectivity)\n            if 'DBZH' in sweep_0.data_vars:\n                print(\"\\nFirst sweep's reflectivity (DBZH) data snippet:\")\n                print(sweep_0.DBZH.isel(range=slice(0, 5), azimuth=slice(0, 5)))\n            else:\n                print(\"\\n'DBZH' variable not found in sweep_0.\")\n        else:\n            print(\"\\n'sweep_0' not found in the dataset group.\")\n\n    except Exception as e:\n        print(f\"Error processing file '{file_path}': {e}\")\n        print(\"Please ensure the file is a valid ODIM H5 radar file and dependencies are installed.\")\nelse:\n    print(f\"Error: Example file '{file_path}' not found.\")\n    print(\"Please download it as per the instructions above, or provide your own ODIM H5 file.\")","lang":"python","description":"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."},"warnings":[{"fix":"Always consult the latest documentation for `xradar.io` functions. Pin your xradar version for production environments to avoid unexpected API changes in minor releases, or carefully review release notes before upgrading.","message":"The internal implementation of IO functions might change, especially for complex formats, potentially affecting performance or requiring specific versions of underlying parsers (like `pyodim`). While the high-level `read_*` API aims for stability, argument changes are possible in 0.x.x versions.","severity":"breaking","affected_versions":"<0.11.0"},{"fix":"Familiarize yourself with the `xarray.Group` API. Use `ds_group.keys()` to see available sweeps and `ds_group['sweep_idx']` to select a specific sweep. The official xradar documentation provides examples of navigating this structure.","message":"xradar often returns an `xarray.Group` object where each radar sweep is a separate `xarray.Dataset`. Users accustomed to a single `xarray.Dataset` may find this hierarchical structure unexpected, requiring careful indexing (e.g., `ds_group['sweep_0']`) to access data.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Understand the coordinate reference system (CRS) embedded in your radar data (if any). Use `wradlib.georef` or `pyproj` for transformations if mapping to common geographic projections. Refer to `xradar`'s plotting examples or integrate with `wradlib`'s mapping capabilities.","message":"Radar data comes with complex coordinate systems (e.g., polar coordinates, varying projections). xradar ingests these, but direct plotting on geographical maps often requires explicit projection handling and transformations, often using `wradlib` or `cartopy`, which are not always automatic.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure you have the necessary system-level dependencies for HDF5 and NetCDF. On Linux, this usually involves `sudo apt-get install libhdf5-dev libnetcdf-dev`. On other OS, consult the documentation for `h5py` and `netcdf4`.","message":"Some radar formats might require specific C libraries (e.g., HDF5, netCDF-C) to be installed on your system in addition to the Python packages (`h5py`, `netcdf4`). Missing these can lead to errors during file reading.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Double-check the file path. Ensure the file exists and is accessible from where your Python script is run. Use `os.path.exists(file_path)` to verify before attempting to read.","cause":"The specified radar file path is incorrect, or the file does not exist at that location.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'your_radar_file.h5'"},{"fix":"Inspect the loaded `xarray.Group` (or `xarray.Dataset`) using `ds_group.keys()` and `ds_group['sweep_name'].data_vars.keys()` to discover the actual names of sweeps and variables available in your specific file.","cause":"The radar file's internal structure does not contain the expected sweep or variable name. Radar formats vary, and specific files might use different naming conventions or omit certain data products.","error":"KeyError: 'sweep_0' (or similar for other sweep/variable names)"},{"fix":"Verify the file path and permissions. Ensure the file is not corrupted and is a valid ODIM H5/NetCDF file. Try opening it with a different HDF5/NetCDF viewer if possible to confirm integrity. Also, check for system-level HDF5/NetCDF library installations.","cause":"Similar to `FileNotFoundError`, but often indicates an issue with the underlying HDF5 or NetCDF library failing to locate or open the file, possibly due to path, permissions, or a corrupted file.","error":"OSError: Can't open object (object 'your_radar_file.h5' doesn't exist)"},{"fix":"Remember that `xradar` often returns an `xarray.Group`. Access individual sweeps using `ds_group['sweep_name']` (e.g., `ds_group['sweep_0']`) before applying Dataset-specific operations like `ds.where()` or `ds.sel()`.","cause":"You are attempting to apply an `xarray.Dataset` method directly to an `xarray.Group` object, or expecting a single `Dataset` when `xradar` returned a Group containing multiple sweeps.","error":"TypeError: Cannot interpret 'xarray.Group' as a Dataset"}]}