WeatherBench-X

repository·main·Indexed 42 days ago

https://github.com/google-research/weatherbenchx

A modular framework for evaluating weather forecasts and ground truth data, supporting both dense and sparse datasets. Built on Xarray and designed for scalability using Apache Beam, it serves as the successor to WeatherBench 2. The framework provides comprehensive tools for data loading, spatial and temporal interpolation, and the calculation of deterministic, probabilistic, and categorical metrics, including advanced statistical inference for confidence intervals and significance testing.

Tokens
15K
Snippets
38
Records
61
Agent score
54%

What's inside WeatherBench-X

  1. Overview of WeatherBench-X

    main

    WeatherBench-X is a modular evaluation framework designed for the flexible evaluation of weather forecasts and ground truth data. It supports various data types, including sparse datasets from weather stations or satellites. It serves as the successor to the WeatherBench 2 evaluation code and powers the WeatherBench 2 benchmark.

    Key technical characteristics:

    • Modularity: Uses interoperable classes to define Data loaders, Interpolations, Metrics, and Aggregation.
    • Xarray-based: All internal logic is built on xarray.DataArray objects.
    • Scalability: Designed to handle very large datasets by splitting operations into small chunks, enabling scalable evaluation via Apache Beam.
  2. Statistical inference for evaluation metrics in weatherbenchX

    main

    WeatherbenchX provides tools for performing statistical inference on evaluation metrics computed from finite samples of weather predictions. Instead of relying solely on point estimates, these tools allow you to compute:

    • Confidence intervals for a metric.
    • Estimated standard errors (the standard deviation of the estimate under resampling).
    • Significance tests (including p-values) to compare two models (testing the null hypothesis that the difference between their true underlying metrics is zero).
    • Confidence intervals and standard errors for the difference between two models.

    Note that these methods rely on statistical assumptions that may not hold for all metrics, data sources, or sample sizes. Use them with care and consider the specific assumptions of the chosen method.

  3. How weatherbenchX handles temporal and spatial dependence

    main

    Standard statistical methods often assume independent and identically distributed (IID) observations, which is frequently violated in weather forecasting due to temporal dependence between nearby forecast initialization times.

    WeatherbenchX addresses this in two ways:

    1. Temporal Dependence: Implements specific statistical methods (such as AR(2) correction, HAC estimators, and various bootstrap methods) designed to account for autocorrelation in time series.
    2. Spatial Correlation: To avoid the complexity of spatial dependence, weatherbenchX typically treats spatial locations (e.g., grid points) as fixed and averages over them before performing statistical inference.

    When choosing a method, consider the trade-offs between computational complexity and the ability to handle the specific dependence structure of your data.

  4. Run the WeatherBench evaluation script

    main

    The evaluation is performed using run_benchmark_evaluation.py in conjunction with a configuration file (e.g., public_configs) that defines data loader settings for specific models, ground truths, years, and resolutions.

    For small datasets, you can run the script locally using the DirectRunner. For full-scale evaluations, use DataflowRunner to execute the job on Google Cloud Dataflow. When using DataflowRunner, additional arguments must be passed after a -- separator to configure the Dataflow job (e.g., --project, --region, --temp_location).

    # Local execution for small data
    python run_benchmark_evaluation.py \
      --config=public_configs \
      --prediction=hres \
      --target=era5 \
      --resolution=64x32 \
      --year=2020 \
      --time_start=2020-01-01 \
      --time_stop=2020-01-01T12 \
      --lead_time_start=0 \
      --lead_time_stop=12 \
      --lead_time_frequency=6 \
      --output_dir=./results/ \
      --runner=DirectRunner
    
    # Full evaluation using Dataflow
    export BUCKET=my-bucket
    export PROJECT=my-project
    export REGION=us-central1
    
    python run_benchmark_evaluation.py \
      --config=public_configs \
      --prediction=hres \
      --target=era5 \
      --resolution=64x32 \
      --year=2020 \
      --time_start=2020-01-01 \
      --time_stop=2020-01-01T12 \
      --lead_time_start=0 \
      --lead_time_stop=12 \
      --lead_time_frequency=6 \
      --output_dir=gs://$BUCKET/tmp/ \
      --runner=DataflowRunner \
      -- \
      --project=$PROJECT \
      --region=$REGION \
      --temp_location=gs://$BUCKET/tmp/ \
      --setup_file=../setup.py \
      --job_name=wbx-evaluation
  5. Run distributed evaluation jobs on Google Cloud Dataflow

    main

    To evaluate large datasets, use Google Cloud Dataflow by setting --runner=DataflowRunner. This requires an active Google Cloud account and specific parameters to be passed as Beam pipeline options (following the -- separator in the command).

    Required/Common Dataflow parameters:

    • --runner: Set to DataflowRunner for cloud execution.
    • --project: Your Google Cloud Project ID.
    • --temp_location: A Cloud Storage path (starting with gs://) for temporary files.
    • --region: The regional endpoint (e.g., us-central1).
    • --job_name: A unique name for the job in the Dataflow UI.
    • --setup_file: Path to a setup.py file to ensure all required packages are installed on the worker nodes.
    export BUCKET=<your-bucket>
    export PROJECT=<your-project>
    export REGION=us-central1
    
    python run_example_evaluation.py \
      --prediction_path=gs://weatherbench2/datasets/hres/2016-2022-0012-64x32_equiangular_conservative.zarr \
      --target_path=gs://weatherbench2/datasets/era5/1959-2022-6h-64x32_equiangular_conservative.zarr \
      --time_start=2020-01-01 \
      --time_stop=2020-01-02 \
      --output_path=gs://$BUCKET/results.nc \
      --runner=DataflowRunner \
      -- \
      --project=$PROJECT \
      --region=$REGION \
      --temp_location=gs://$BUCKET/tmp/ \
      --setup_file=../setup.py \
      --job_name=wbx-eval
  6. Generate scorecards and interactive graphics

    main

    After combining results, you can visualize the data using the following methods:

    1. Scorecards: Use the WB_X_Website_Scorecard.ipynb notebook to plot scorecards.
    2. Interactive Graphics: The code for the interactive Deterministic and Probabilistic tabs is located in the apps directory. Refer to the README within that directory for specific instructions on running the apps.
  7. Combine evaluation results

    main

    To prepare evaluation results for downstream tasks like generating scorecards or interactive graphics, use combine_results.py. This script merges results into a single file.

    Note that deterministic and probabilistic results must be processed separately using the --mode flag.

    # Process deterministic results
    python combine_results.py \
        --input_dir=gs://weatherbench2/benchmark_results \
        --output_dir=./ \
        --mode=deterministic
    
    # Process probabilistic results
    python combine_results.py \
        --input_dir=gs://weatherbench2/benchmark_results \
        --output_dir=./ \
        --mode=probabilistic
  8. Run Beam pipelines locally using DirectRunner

    main

    For testing or processing small datasets, you can run the evaluation pipeline on your local machine. Use the DirectRunner as the --runner argument. You can control the level of parallelism by setting the --direct_num_workers flag (passed after the -- separator).

    python run_example_evaluation.py \
      --prediction_path=gs://weatherbench2/datasets/hres/2016-2022-0012-64x32_equiangular_conservative.zarr \
      --target_path=gs://weatherbench2/datasets/era5/1959-2022-6h-64x32_equiangular_conservative.zarr \
      --time_start=2020-01-01 \
      --time_stop=2020-01-02 \
      --output_path=./results.nc \
      --runner=DirectRunner \
      -- \
      --direct_num_workers 2
  9. How statistics and metrics work together

    main

    WeatherBench-X separates the per-element calculation from the final metric aggregation to allow for efficient processing of large datasets.

    • Statistics (e.g., SquaredError) perform the heavy lifting by calculating values for every point in the prediction/target arrays. These are often PerVariableStatistic objects.
    • Metrics (e.g., RMSE) act as a container. They specify a mapping of statistic names to Statistic objects via the statistics property.
    • The metric then uses a method (like _values_from_mean_statistics_per_variable) to transform the averaged statistics into the final reported metric value. This allows you to perform operations like sqrt after the mean has been computed, which is mathematically different from taking the square root of every individual error before averaging.
  10. How Data Loaders work in WeatherBench-X

    main

    Data loaders are responsible for reading data from a source and returning it as an Xarray Dataset (or a dictionary of DataArrays).

    Key Requirements:

    • They must ensure that target and prediction datasets are aligned (having the same variable names and coordinates that can be broadcast against each other).
    • If data is sparse, loaders should use interpolators to achieve alignment.

    Common loaders include:

    • weatherbenchX.data_loaders.xarray_loaders.TargetsFromXarray: Loads target datasets.
    • weatherbenchX.data_loaders.xarray_loaders.PredictionsFromXarray: Loads prediction datasets.

    Once initialized, you can use .load_chunk(init_times, lead_times) to retrieve specific temporal slices of data.

    from weatherbenchX.data_loaders import xarray_loaders
    
    target_data_loader = xarray_loaders.TargetsFromXarray(
        path=target_path,
        variables=['2m_temperature', 'geopotential'],
    )
    
    prediction_data_loader = xarray_loaders.PredictionsFromXarray(
        path=prediction_path,
        variables=['2m_temperature', 'geopotential'],
    )
    
    # Load specific chunks
    target_chunk = target_data_loader.load_chunk(init_times, lead_times)