Skip to content

khashashin/meteoswiss-radar-api

Repository files navigation

title emoji colorFrom colorTo sdk app_port pinned license
MeteoSwiss Radar API
🌦
blue
indigo
docker
8000
false
mit

MeteoSwiss Radar API

A standalone, containerized Python backend service that fetches, processes, and serves real-time Swiss precipitation radar data as standard GeoJSON.

Designed to power web applications and Home Assistant cards (e.g., meteoswiss-radar-card) by bridging the gap between the complex official MeteoSwiss data and web-friendly formats.

Features

  • HDF5 Processing: Natively handles MeteoSwiss ODIM HDF5 files (including DEFLATE compression) using h5py.
  • Coordinate Transformation: Automatically projects Swiss grid coordinates (LV95 / CH1903+) to WGS84 for map compatibility.
  • STAC API Integration: Polls the official MeteoSwiss STAC API for the latest precipitation data (ch.meteoschweiz.ogd-radar-precip).
  • GeoJSON Output: Converts radar imagery into vectorized GeoJSON polygons (contours) for efficient rendering.
  • Dockerized: Ready-to-run container image.
  • Caching: Caches processed frames to minimize upstream bandwidth usage.

API Endpoints

  • GET /versions.json: Returns the list of available timestamps (latest first).
  • GET /radar/{timestamp}: Returns the radar data for a specific timestamp as a GeoJSON FeatureCollection.
  • GET /precipitation/animation/...: Compatibility endpoints for the legacy simplified JSON format (if implemented).
  • GET /docs: Interactive Swagger UI documentation.

Installation

Option 1: Docker (Recommended)

  1. Build the image:

    docker build -t meteoswiss-radar-api .
  2. Run the container:

    docker run -p 8000:8000 meteoswiss-radar-api

The API will be available at http://localhost:8000.

Option 2: Local Python Environment

Requires Python 3.10+.

  1. Install dependencies: Using uv (recommended):

    uv sync

    Or standard pip:

    pip install -r requirements.txt
  2. Run the server:

    uv run python -m uvicorn app.main:app --reload

Home Assistant Integration

This service outputs standard GeoJSON. If you are developing a custom card (e.g., using Leaflet), you can consume the data directly.

Example Snippet:

/**
 * Decodes the response from the Radar API.
 * The API returns a standard GeoJSON FeatureCollection.
 */
export function decodeRadarData(data: any) {
    if (data.type !== 'FeatureCollection') {
        console.error('Invalid format: expected FeatureCollection');
        return [];
    }
    // Return features directly for Leaflet's L.geoJSON()
    return data;
}

Data Attribution

This project uses Open Data from MeteoSwiss. Source: MeteoSwiss

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Real-time Swiss precipitation radar data as standard GeoJSON

Resources

License

Stars

Watchers

Forks

Packages