### Install WeatherBench-X Framework Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/index.md These commands detail the installation process for the WeatherBench-X library. The first command allows for direct installation of the library from its Git repository using pip. The subsequent commands are for developers, enabling them to clone the repository and install it in an editable mode for local development and testing. ```bash pip install git+https://github.com/google-research/weatherbenchX.git ``` ```bash git clone git@github.com:google-research/weatherbenchX.git ``` ```bash pip install -e . ``` -------------------------------- ### Example Custom Data Loader Implementation Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/data_loaders.ipynb This Python class `MyNewDataLoader` demonstrates how to extend the `data_loader_base.DataLoader` in WB-X. It implements the `__init__` method to pass arguments to the superclass and provides a concrete example of `_load_chunk_from_source` for loading data based on `init_times` and `lead_times`, specifically handling cases where exact lead times are required. ```python class MyNewDataLoader(data_loader_base.DataLoader): def __init__( self, *args, interpolation: Optional[interpolations.Interpolation] = None, compute: bool = True, add_nan_mask: bool = False, ): super().__init__( interpolation=interpolation, compute=compute, add_nan_mask=add_nan_mask, ) def _load_chunk_from_source( self, init_times: np.ndarray, lead_times: Optional[Union[np.ndarray, slice]] = None, ) -> Mapping[Hashable, xr.DataArray]: if not isinstance(lead_times, np.ndarray): raise ValueError('Only exact lead times are supported.') datasets = [] for init_time in init_times: for lead_time in lead_times: ds = some_data_loading_function(init_time, lead_time) datasets.append(ds) chunk = xr.merge(datasets) return chunk ``` -------------------------------- ### Define Initial and Lead Times for Data Loading Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/metric_wrappers.ipynb Specifies the `init_times` and `lead_times` as NumPy datetime arrays. `init_times` defines the start of the forecast period, and `lead_times` indicates the forecast horizon, which are used to load a specific chunk of data. ```python init_times = np.array(['2020-01-01T00'], dtype='datetime64[ns]') lead_times = np.array([6], dtype='timedelta64[h]').astype('timedelta64[ns]') # To silence xr warnings. ``` -------------------------------- ### Run WeatherBench Evaluation Script with Google Cloud Dataflow Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/benchmark.md Executes the `run_benchmark_evaluation.py` script using Google Cloud Dataflow for full-scale evaluation. It requires setting environment variables for the Google Cloud Storage bucket, project ID, and region, and specifies Dataflow-specific runner arguments and a setup file. This approach is recommended for larger datasets. ```shell 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 ``` -------------------------------- ### Run WeatherBench-X Evaluation on Google Cloud Dataflow Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/beam_dataflow.md This example illustrates how to execute a WeatherBench-X evaluation pipeline on Google Cloud Dataflow. It involves setting environment variables for the Cloud Storage bucket, GCP project, and region, then running the Python script with `DataflowRunner` and specifying Dataflow-specific parameters like temporary location, setup file, and job name. ```Python export BUCKET= export 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 ``` -------------------------------- ### Python Package Dependencies List Source: https://github.com/google-research/weatherbenchx/blob/main/public_benchmark/apps/requirements.txt This snippet provides a list of Python packages and their exact or minimum required versions. This format is commonly used in `requirements.txt` files to manage project dependencies, ensuring that all necessary libraries are installed correctly for the application to function. ```Python plotly==5.24.1 xarray>=2024.1.0 zarr==2.13.3 dash==2.14.2 dash_bootstrap_components==1.6.0 seaborn==0.13.2 fsspec==2024.12.0 gcsfs==2024.12.0 gunicorn>=19.5.0 ``` -------------------------------- ### Initialize Sample Data for Metric Calculation Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/implement_metrics.ipynb Creates sample `xarray.Dataset` objects for `predictions` and `targets` to demonstrate metric computation. Both datasets contain a '2m_temperature' DataArray with dummy data, mimicking typical weather model outputs for testing purposes. ```python predictions = xr.Dataset({'2m_temperature': xr.DataArray(np.ones((2, 32, 64)), dims=['init_time', 'latitude', 'longitude'])}) targets = predictions.copy() predictions ``` -------------------------------- ### Define Variables and Time Parameters for Data Loading Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/sparse_data.ipynb Sets up the meteorological variables ('2m_temperature', '10m_wind_speed'), initial times, and lead times as NumPy arrays. These parameters specify the data chunks to be loaded for both target observations and gridded predictions. ```python variables = ['2m_temperature', '10m_wind_speed'] init_times = np.array(['2020-01-01T00', '2020-01-01T12'], dtype='datetime64[ns]') lead_times = np.array([6, 12], dtype='timedelta64[h]').astype('timedelta64[ns]') ``` -------------------------------- ### DataLoader Base Class Initialization Arguments Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/data_loaders.ipynb Describes the arguments for the `__init__` method of the `DataLoader` base class in WB-X. These parameters control data interpolation, in-memory computation, and the addition of NaN masks for data variables. ```APIDOC Args: interpolation: (Optional) Interpolation to be applied to the data. compute: Load chunk into memory. Default: True. add_nan_mask: Adds a boolean coordinate named 'mask' to each variable (variables will be split into DataArrays if they are not already), with False indicating NaN values. To be used for masked aggregation. Default: False. ``` -------------------------------- ### Load Data Chunks for Prediction and Target Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/metric_wrappers.ipynb Loads a specific chunk of target and prediction data using the previously initialized data loaders. The `load_chunk` method retrieves data corresponding to the defined `init_times` and `lead_times`, making it available for metric computation. ```python target_chunk = target_data_loader.load_chunk(init_times, lead_times) prediction_chunk = prediction_data_loader.load_chunk(init_times, lead_times) ``` -------------------------------- ### Import WeatherbenchX Libraries Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/metric_wrappers.ipynb Imports necessary modules from `numpy` for numerical operations and various `weatherbenchX` sub-packages. These imports include tools for data aggregation, loading data from xarray datasets, and defining categorical metrics and metric wrappers. ```python import numpy as np from weatherbenchX import aggregation from weatherbenchX.data_loaders import xarray_loaders from weatherbenchX.metrics import categorical from weatherbenchX.metrics import wrappers ``` -------------------------------- ### Initialize METAR Parquet Data Loader for Target Data Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/sparse_data.ipynb Creates an instance of `sparse_parquet.METARFromParquet` to load sparse METAR weather station data from a Google Cloud Storage path. It configures the loader with specified variables, partitioning by month, and enables a NaN mask for handling missing values. ```python target_data_loader = sparse_parquet.METARFromParquet( path='gs://weatherbench2/datasets/metar/metar-timeNominal-by-month/', variables=variables, partitioned_by='month', time_dim='timeNominal', add_nan_mask=True ) ``` -------------------------------- ### weatherbenchX.binning Module Class Reference Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/api/binning.md This section lists the primary classes available within the `weatherbenchX.binning` module, as specified by Sphinx `autoclass` directives. These classes are fundamental for defining and applying various data binning and region partitioning methods. ```APIDOC weatherbenchX.binning module classes: - Binning - Regions - ByExactCoord - ByTimeUnit - ByCoordBins - BySets ``` -------------------------------- ### Run WeatherBench Evaluation Script Locally Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/benchmark.md Executes the `run_benchmark_evaluation.py` script with specified configuration, prediction, target, resolution, year, time range, lead time, and output directory. This method is suitable for small datasets and local execution. ```shell 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 ``` -------------------------------- ### Initialize Xarray Data Loaders Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/metric_wrappers.ipynb Sets up data loaders using `xarray_loaders.TargetsFromXarray` and `xarray_loaders.PredictionsFromXarray`. These loaders are configured to retrieve the 'total_precipitation_6hr' variable from the specified GCS paths, preparing the data for subsequent processing. ```python variables = ['total_precipitation_6hr'] target_data_loader = xarray_loaders.TargetsFromXarray( path=target_path, variables=variables, ) prediction_data_loader = xarray_loaders.PredictionsFromXarray( path=prediction_path, variables=variables, ) ``` -------------------------------- ### Initialize Xarray Data Loader for Gridded Predictions Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/sparse_data.ipynb Creates a `xarray_loaders.PredictionsFromXarray` instance to load gridded forecast data from a Zarr store. It configures the data loader with the specified variables and the previously defined interpolation method, preparing it to load forecast data. ```python prediction_path = 'gs://weatherbench2/datasets/hres/2016-2022-0012-64x32_equiangular_conservative.zarr' prediction_data_loader = xarray_loaders.PredictionsFromXarray( path=prediction_path, variables=variables, interpolation=interpolation, ) ``` -------------------------------- ### Display Target Data Chunk Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/metric_wrappers.ipynb Outputs the loaded `target_chunk` to the console. This allows for a quick inspection of the data's structure, dimensions, and variables, confirming that the data was loaded correctly. ```python target_chunk ``` -------------------------------- ### Import WeatherBenchX Libraries for Sparse Data Evaluation Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/sparse_data.ipynb Imports necessary modules from `numpy` and `weatherbenchX` for handling sparse data, including interpolations, binning, aggregation, metrics, and data loaders for Parquet and Xarray. ```python import numpy as np from weatherbenchX import interpolations from weatherbenchX import binning from weatherbenchX import aggregation from weatherbenchX.metrics import base as metrics_base from weatherbenchX.metrics import deterministic from weatherbenchX.data_loaders import sparse_parquet from weatherbenchX.data_loaders import xarray_loaders ``` -------------------------------- ### Define Probabilistic Lead Times and Models Source: https://github.com/google-research/weatherbenchx/blob/main/public_benchmark/WB_X_Website_Scorecard.ipynb This snippet initializes arrays for lead times (in days) and a list of probabilistic weather models to be included in the analysis. These variables are crucial for selecting and filtering data for probabilistic forecasts. ```python lead_times = np.array([1, 3, 5, 10, 15], dtype='timedelta64[D]') models = [ 'IFS ENS vs Analysis', 'GenCast (oper.) vs Analysis', 'NeuralGCM ENS vs ERA5', 'GenCast vs ERA5', 'ArchesWeatherGen vs ERA5', 'Probabilistic Climatology vs ERA5' ] ``` -------------------------------- ### Define Deterministic Lead Times and Models Source: https://github.com/google-research/weatherbenchx/blob/main/public_benchmark/WB_X_Website_Scorecard.ipynb This snippet initializes arrays for lead times (in days) and a list of deterministic weather models to be included in the analysis. These variables are crucial for selecting and filtering data. ```python lead_times = np.array([1, 3, 5, 7, 10], dtype='timedelta64[D]') models = [ 'IFS HRES vs Analysis', 'IFS ENS (mean) vs Analysis', 'ERA5-Forecasts vs ERA5', 'Pangu-Weather (oper.) vs Analysis', 'GraphCast (oper.) vs Analysis', 'GenCast (oper.) (mean) vs Analysis', 'Keisler (2022) vs ERA5', 'Pangu-Weather vs ERA5', 'GraphCast vs ERA5', 'FuXi vs ERA5', 'NeuralGCM 0.7 vs ERA5', 'NeuralGCM ENS (mean) vs ERA5', 'GenCast (mean) vs ERA5', 'Stormer ENS (mean) vs ERA5', 'Excarta (HEAL-ViT) vs ERA5', 'ArchesWeather-Mx4 vs ERA5', 'ArchesWeatherGen (mean) vs ERA5', 'Climatology vs ERA5' ] ``` -------------------------------- ### Authenticate Google Colab for Cloud Access Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/metric_wrappers.ipynb Provides authentication for Google Colab environments to access cloud datasets, typically Google Cloud Storage. This step is crucial when running the notebook in Colab to ensure data loading from remote paths succeeds. ```python from google.colab import auth auth.authenticate_user() ``` -------------------------------- ### Metric Wrapper Classes Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/api/metrics.md API documentation for wrapper classes within the `weatherbenchX.metrics.wrappers` module. These classes provide utilities to transform inputs or combine existing statistics and metrics. ```APIDOC Module: weatherbenchX.metrics.wrappers Classes: InputTransform EnsembleMean ContinuousToBinary WrappedStatistic WrappedMetric ``` -------------------------------- ### Compute Metrics and Aggregate Statistics for Forecast Evaluation Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/sparse_data.ipynb Defines a dictionary of metrics (RMSE, MAE) and computes unique statistics using `metrics_base.compute_unique_statistics_for_all_metrics`. It then sets up an `Aggregator` to reduce dimensions and bin results by `lead_time`, preparing the data for final metric calculation. ```python metrics = { 'rmse': deterministic.RMSE(), 'mae': deterministic.MAE(), } statistics = metrics_base.compute_unique_statistics_for_all_metrics( metrics, prediction_chunk, target_chunk ) bin_by = [binning.ByExactCoord('lead_time')] aggregator = aggregation.Aggregator( reduce_dims=['index'], bin_by=bin_by, masked=True ) aggregation_state = aggregator.aggregate_statistics(statistics) ``` -------------------------------- ### Define Cloud Storage Paths for Forecast Data Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/metric_wrappers.ipynb Specifies the Google Cloud Storage (GCS) paths for the prediction and target datasets. The `prediction_path` points to an IFS ensemble forecast dataset, while `target_path` refers to an ERA5 reanalysis dataset, both stored in Zarr format. ```python prediction_path = 'gs://weatherbench2/datasets/ifs_ens/2018-2022-64x32_equiangular_conservative.zarr' target_path = 'gs://weatherbench2/datasets/era5/1959-2022-6h-64x32_equiangular_conservative.zarr' ``` -------------------------------- ### Instantiate RMSE Metric Object Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/implement_metrics.ipynb Creates an instance of the `RMSE` metric class from the `deterministic` module. This step prepares the RMSE object for use in calculating the root mean squared error on actual or sample data. ```python rmse = deterministic.RMSE() ``` -------------------------------- ### Configure Wrapped CSI Metric with Multiple Transforms Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/metric_wrappers.ipynb Defines a `WrappedMetric` for the Critical Success Index (CSI) by applying a sequence of transformations. These transformations include converting continuous precipitation to binary, computing the ensemble mean of predictions, and then thresholding probabilities to binary values, preparing the data for accurate CSI calculation. ```python wrapped_csi = wrappers.WrappedMetric( metric=categorical.CSI(), transforms=[ wrappers.ContinuousToBinary( which='both', threshold_value=[1/1000, 5/1000], # Raw values are in m threshold_dim='threshold_precipitation' ), wrappers.EnsembleMean( which='predictions', ensemble_dim='number' ), wrappers.ContinuousToBinary( which='predictions', threshold_value=[0.25, 0.75], threshold_dim='threshold_probability' ), ], ) metrics = {'csi': wrapped_csi} ``` -------------------------------- ### Display Prediction Data Chunk Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/metric_wrappers.ipynb Outputs the loaded `prediction_chunk` to the console. This provides an immediate view of the prediction data's structure, including its dimensions and variables, to verify successful loading. ```python prediction_chunk ``` -------------------------------- ### Load Deterministic Results from Zarr Source: https://github.com/google-research/weatherbenchx/blob/main/public_benchmark/WB_X_Website_Scorecard.ipynb This code loads pre-computed deterministic weather forecast results from a Zarr store, which is a format optimized for large, array-like datasets. The `.compute()` call ensures the data is loaded into memory. ```python results = xr.open_zarr(f'{RESULTS_PATH}/deterministic.zarr').compute() ``` -------------------------------- ### Load a Chunk of Sparse METAR Target Data Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/sparse_data.ipynb Loads a specific chunk of the target METAR data using the defined initial and lead times. This operation retrieves the sparse observations for the specified time range, which will serve as the ground truth for evaluation. ```python target_chunk = target_data_loader.load_chunk(init_times, lead_times) target_chunk ``` -------------------------------- ### Run WeatherBench-X Evaluation Locally with DirectRunner Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/beam_dataflow.md This command demonstrates how to execute a WeatherBench-X evaluation pipeline locally using Apache Beam's `DirectRunner`. It specifies input/output paths, a time range for the evaluation, and configures the number of local workers for parallel processing, suitable for testing or small datasets. ```Python 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 ``` -------------------------------- ### Define Query Initialization and Lead Times Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/forecast_latency.ipynb Defines the specific `init_times` (initialization time) and `lead_times` (forecast lead time) as NumPy datetime and timedelta arrays. These represent the 'query' parameters for which a forecast is desired, allowing the system to find the most appropriate available forecast. ```python init_times = np.array(['2020-01-01T21'], dtype='datetime64[ns]') lead_times = np.array([3], dtype='timedelta64[h]').astype('timedelta64[ns]') ``` -------------------------------- ### Python Documentation Build Dependencies Source: https://github.com/google-research/weatherbenchx/blob/main/docs/requirements.txt Specifies the exact versions of Python packages necessary to build the project's documentation. These typically include Sphinx for documentation generation, a theme like Furo, and parsers for different markup languages like MyST. ```Python furo==2024.4.27 Jinja2==3.1.5 myst-nb==1.1.0 myst-parser==3.0.1 sphinx==7.3.7 ``` -------------------------------- ### Load Probabilistic Results from Zarr Source: https://github.com/google-research/weatherbenchx/blob/main/public_benchmark/WB_X_Website_Scorecard.ipynb This code loads pre-computed probabilistic weather forecast results from a Zarr store, which is a format optimized for large, array-like datasets. The `.compute()` call ensures the data is loaded into memory. ```python results = xr.open_zarr(f'{RESULTS_PATH}/probabilistic.zarr').compute() ``` -------------------------------- ### weatherbenchX.interpolations Module API Reference Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/api/interpolations.md API documentation for the `weatherbenchX.interpolations` module, listing the primary classes available for performing various interpolation and coordinate transformation operations. ```APIDOC Module: weatherbenchX.interpolations Classes: - Interpolation - MultipleInterpolation - InterpolateToFixedCoords - InterpolateToReferenceCoords - GridToSparseWithAltitudeAdjustment - NeighborhoodThresholdProbabilities ``` -------------------------------- ### Compute Metric Values for a Single Data Chunk Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/metric_wrappers.ipynb Initializes an `Aggregator` to reduce specified dimensions (init_time, latitude, longitude) for metric computation. It then calls `compute_metric_values_for_single_chunk` to calculate the configured CSI metric using the prepared prediction and target data chunks. ```python aggregator = aggregation.Aggregator( reduce_dims=['init_time', 'latitude', 'longitude'], ) aggregation.compute_metric_values_for_single_chunk( metrics, aggregator, prediction_chunk, target_chunk ) ``` -------------------------------- ### Import WeatherBench-X Metric Components Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/implement_metrics.ipynb Imports necessary libraries and base classes for defining custom metrics and statistics in WeatherBench-X, including numpy, xarray, and WeatherBench-X's base and deterministic metric modules. These imports provide the foundational elements for building new measurement tools. ```python import numpy as np import xarray as xr from weatherbenchX.metrics import base from weatherbenchX.metrics import deterministic ``` -------------------------------- ### Deterministic Metrics Classes Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/api/metrics.md API documentation for metric classes used in deterministic evaluations within the `weatherbenchX.metrics.deterministic` module. These classes provide common deterministic skill scores like MAE, MSE, and ACC. ```APIDOC Module: weatherbenchX.metrics.deterministic Classes: Bias MAE MSE RMSE PredictionAverage TargetAverage WindVectorRMSE ACC PredictionActivity ``` -------------------------------- ### Select Coarse Data Selections in Python Source: https://github.com/google-research/weatherbenchx/blob/main/public_benchmark/WB_X_Website_Scorecard.ipynb This snippet performs initial data selection on a 'results' object, filtering by lead time, region, year, and resolution. It's typically used for setting up the initial dataset for analysis. ```python results = results.sel(lead_time=lead_times, region='Global', year='2020', resolution='240x121') ``` -------------------------------- ### Probabilistic Statistics Classes Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/api/metrics.md API documentation for statistical classes used in probabilistic metric calculations within the `weatherbenchX.metrics.probabilistic` module. These classes support the evaluation of ensemble forecasts. ```APIDOC Module: weatherbenchX.metrics.probabilistic Classes: CRPSSkill CRPSSpread EnsembleVariance UnbiasedEnsembleMeanSquaredError ``` -------------------------------- ### Documenting weatherbenchX Beam Pipeline Function Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/api/beam_pipeline.md This snippet illustrates the use of Sphinx reStructuredText directives (`currentmodule` and `autofunction`) to automatically generate API documentation for the `define_pipeline` function, which is part of the `weatherbenchX.beam_pipeline` module. This approach is common in Python projects for maintaining up-to-date API references. ```APIDOC .. currentmodule:: weatherbenchX.beam_pipeline .. autofunction:: define_pipeline ``` -------------------------------- ### Base Metrics and Statistics Classes Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/api/metrics.md Documents the core base classes for statistics and metrics within the `weatherbenchX.metrics.base` module. These classes serve as foundational elements for defining various evaluation measures. ```APIDOC Module: weatherbenchX.metrics.base Classes: Statistic PerVariableStatistic Metric PerVariableMetric PerVariableStatisticWithClimatology ``` -------------------------------- ### Constant Latency Wrappers Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/api/data_loaders.md Documents classes that wrap existing data loaders to simulate or manage constant latency in data access. This includes a generic constant latency wrapper, an Xarray-specific version, and a wrapper for applying constant latency to multiple data sources. ```APIDOC weatherbenchX.data_loaders.latency_wrappers.ConstantLatencyWrapper weatherbenchX.data_loaders.latency_wrappers.XarrayConstantLatencyWrapper weatherbenchX.data_loaders.latency_wrappers.MultipleConstantLatencyWrapper ``` -------------------------------- ### List User-Defined Metrics for a Dataflow Job (Beta) Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/beam_dataflow.md This beta `gcloud` command allows users to retrieve custom, user-defined metrics for a specified Dataflow job. It requires the job ID and the `--source=user` flag to filter for application-specific metrics, which are crucial for detailed performance monitoring and debugging. ```Shell JOBID= gcloud beta dataflow metrics list $JOBID --source=user ``` -------------------------------- ### View Logs for a Dataflow Job (Beta) Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/beam_dataflow.md This beta `gcloud` command enables users to view the logs generated by a specific Dataflow job. It provides access to operational and application-level logs, which are essential for debugging, understanding job execution behavior, and troubleshooting issues. ```Shell gcloud beta dataflow logs list $JOBID ``` -------------------------------- ### Import Core Libraries for WeatherBenchX Utilities Source: https://github.com/google-research/weatherbenchx/blob/main/public_benchmark/WB_X_Website_Scorecard.ipynb Imports essential Python libraries including xarray for data handling, matplotlib and seaborn for plotting, numpy for numerical operations, and fsspec for file system abstraction, used across WeatherBenchX utility functions. ```python import xarray as xr import matplotlib.pyplot as plt import matplotlib import seaborn as sns import numpy as np import matplotlib as mpl import fsspec ``` -------------------------------- ### Combine WeatherBench Evaluation Results Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/benchmark.md Runs the `combine_results.py` script to merge deterministic or probabilistic evaluation results from a specified input directory (e.g., a GCS bucket) into a single local output file. This script processes precomputed results for further analysis or visualization, such as generating scorecards or interactive graphics. ```shell python combine_results.py \ --input_dir=gs://weatherbench2/benchmark_results \ --output_dir=./ \ --mode=deterministic # or --mode=probabilistic ``` -------------------------------- ### API Documentation for TimeChunks Class Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/api/time_chunks.md Documents the `TimeChunks` class, specifying its module path. This entry serves as a reference for developers looking to understand the class's structure and how to import it. ```APIDOC weatherbenchX.time_chunks.TimeChunks ``` -------------------------------- ### WeatherbenchX Weighting Module API Reference Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/api/weighting.md API documentation for the 'weatherbenchX.weighting' module. It defines the 'Weighting' base class for general weighting operations and the 'GridAreaWeighting' class, which is a specialized implementation likely used for applying weights based on grid cell areas. Further details on methods and attributes would typically be auto-generated by Sphinx from docstrings. ```APIDOC Module: weatherbenchX.weighting Class: Weighting Purpose: Base class for defining and applying weighting schemes. (Further details like methods, attributes, and usage examples are typically derived from docstrings and not explicitly present in this snippet.) Class: GridAreaWeighting Purpose: A specialized weighting class, likely used to apply weights based on grid cell areas or similar spatial considerations. (Further details like methods, attributes, and usage examples are typically derived from docstrings and not explicitly present in this snippet.) ``` -------------------------------- ### Load Gridded Prediction Chunk Referencing Sparse Target Data Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/sparse_data.ipynb Loads a chunk of gridded prediction data, passing the `target_chunk` as a reference. This ensures that the gridded predictions are interpolated to the exact coordinates of the sparse target observations, enabling direct comparison. ```python prediction_chunk = prediction_data_loader.load_chunk(init_times, lead_times, reference=target_chunk) prediction_chunk ``` -------------------------------- ### Import WeatherBench-X and NumPy Libraries Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/nan_handling.ipynb Imports necessary libraries for data handling and testing within the WeatherBench-X framework: `numpy` for numerical operations, `test_utils` for generating mock data, and `xarray_loaders` for loading data from xarray datasets. ```python import numpy as np from weatherbenchX import test_utils from weatherbenchX.data_loaders import xarray_loaders ``` -------------------------------- ### Deterministic Statistics Classes Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/api/metrics.md API documentation for statistical classes used in deterministic metric calculations within the `weatherbenchX.metrics.deterministic` module. These classes compute fundamental error components and passthrough values. ```APIDOC Module: weatherbenchX.metrics.deterministic Classes: Error AbsoluteError SquaredError PredictionPassthrough TargetPassthrough WindVectorSquaredError SquaredPredictionAnomaly SquaredTargetAnomaly AnomalyCovariance ``` -------------------------------- ### Categorical Statistics Classes Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/api/metrics.md API documentation for statistical classes used in categorical metric calculations within the `weatherbenchX.metrics.categorical` module. These classes compute components like true/false positives/negatives for binary classification. ```APIDOC Module: weatherbenchX.metrics.categorical Classes: TruePositives TrueNegatives FalsePositives FalseNegatives SEEPSStatistic ``` -------------------------------- ### weatherbenchX.aggregation Module API Documentation Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/api/aggregation.md This section outlines the API for the `AggregationState` and `Aggregator` classes within the `weatherbenchX.aggregation` module. These classes are core components for managing and performing aggregation operations in weatherbenchX. The documentation is automatically generated from Python source code using Sphinx's `autoclass` directives. ```APIDOC weatherbenchX.aggregation.AggregationState: # This class represents the state of an aggregation process. # Methods and attributes would be listed here if available in source. weatherbenchX.aggregation.Aggregator: # This class is responsible for performing aggregation operations. # Methods and attributes would be listed here if available in source. ``` -------------------------------- ### Process Deterministic Results with Utility Functions Source: https://github.com/google-research/weatherbenchx/blob/main/public_benchmark/WB_X_Website_Scorecard.ipynb This code applies two utility functions to the deterministic results: first, it replaces analysis precipitation scores with ERA5 scores, and then it computes relative performance metrics against 'IFS HRES vs Analysis' as a reference. ```python results = replace_analysis_with_era_precip(results) relative = compute_relative_results(results, 'IFS HRES vs Analysis') ``` -------------------------------- ### Base Data Loader Class Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/api/data_loaders.md Documents the foundational DataLoader class in weatherbenchX, serving as the base for all data loading operations. This class provides the core interface for data retrieval. ```APIDOC weatherbenchX.data_loaders.base.DataLoader ``` -------------------------------- ### Define Variables and Titles for Deterministic Plots Source: https://github.com/google-research/weatherbenchx/blob/main/public_benchmark/WB_X_Website_Scorecard.ipynb This section defines lists of variables, their corresponding titles, and subtitles for both upper atmosphere and surface measurements. These definitions are used to configure the scorecard plots. ```python nphysical = 3 upper_variables = [ ('Geopotential', 500, 'RMSE'), ('Temperature', 850, 'RMSE'), ('Specific Humidity', 700, 'RMSE'), ('Wind Vector', 850, 'RMSE') ] upper_titles = ['Geopotential', 'Temperature', 'Humidity', 'Wind Vector'] upper_subtitles = [f'500hPa geopotential RMSE [kg$^2$/m$^2$]', '850hPa temperature RMSE [K]', '700hPa specific humidity RMSE [g/kg]', '850hPa wind vector RMSE [m/s]'] surface_variables = [ ('2m Temperature', None, 'RMSE'), ('Sea Level Pressure', None, 'RMSE'), ('10m Wind Speed', None, 'RMSE'), ('24h Precipitation', None, 'SEEPS') ] surface_titles = ['2m Temperature', 'Surface Pressure', '10m Wind Speed', 'Precipitation'] surface_subtitles = ['RMSE [K]', 'RMSE [Pa]', 'RMSE [m/s]', '24h precipitation SEEPS'] surface_models = [ 'IFS HRES vs Analysis', 'IFS ENS (mean) vs Analysis', 'ERA5-Forecasts vs ERA5', 'Pangu-Weather (oper.) vs Analysis', 'GraphCast (oper.) vs Analysis', 'GenCast (oper.) (mean) vs Analysis', 'Pangu-Weather vs ERA5', 'GraphCast vs ERA5', 'FuXi vs ERA5', 'GenCast (mean) vs ERA5', 'Stormer ENS (mean) vs ERA5', 'Excarta (HEAL-ViT) vs ERA5', 'ArchesWeather-Mx4 vs ERA5', 'ArchesWeatherGen (mean) vs ERA5', 'Climatology vs ERA5' ] ``` -------------------------------- ### Define Diverging Color Map and Normalization for Weather Data Source: https://github.com/google-research/weatherbenchx/blob/main/public_benchmark/WB_X_Website_Scorecard.ipynb Initializes a diverging color map and a boundary normalization for plotting meteorological data. It uses `seaborn` to create color palettes and `matplotlib` to combine them into a custom `ListedColormap` with specific boundary levels for visualization. ```python reds = sns.color_palette('Reds', 6) blues = sns.color_palette('Blues_r', 6) cmap = matplotlib.colors.ListedColormap(blues + [(0.95, 0.95, 0.95)] + reds) cb_levels = [-50, -20,-10, -5, -2, -1, 1, 2, 5, 10, 20, 50] norm = matplotlib.colors.BoundaryNorm(cb_levels, cmap.N, extend='both') ``` -------------------------------- ### Generate Mock Prediction Data and Introduce NaNs Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/nan_handling.ipynb Generates a sample prediction dataset using `test_utils.mock_prediction_data()`. Subsequently, it intentionally introduces `NaN` values into this dataset for demonstration purposes, specifically where the latitude is not greater than 0, simulating real-world data imperfections. ```python predictions = test_utils.mock_prediction_data() ``` ```python predictions = predictions.where(predictions.latitude >0, np.nan) ``` ```python predictions ``` -------------------------------- ### Xarray-based Data Loaders Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/api/data_loaders.md Documents a collection of data loader classes specifically designed for handling Xarray datasets. This includes a general Xarray loader, as well as specialized loaders for predictions, targets, climatology, persistence, and probabilistic climatology derived from Xarray sources. ```APIDOC weatherbenchX.data_loaders.xarray_loaders.XarrayDataLoader weatherbenchX.data_loaders.xarray_loaders.PredictionsFromXarray weatherbenchX.data_loaders.xarray_loaders.TargetsFromXarray weatherbenchX.data_loaders.xarray_loaders.ClimatologyFromXarray weatherbenchX.data_loaders.xarray_loaders.PersistenceFromXarray weatherbenchX.data_loaders.xarray_loaders.ProbabilisticClimatologyFromXarray ``` -------------------------------- ### Define Global Configuration Paths Source: https://github.com/google-research/weatherbenchx/blob/main/public_benchmark/WB_X_Website_Scorecard.ipynb Establishes global variables for local figure saving (SAVE_PATH) and remote data access (RESULTS_PATH) on Google Cloud Storage, crucial for managing WeatherBenchX outputs and inputs. ```python # To save figures SAVE_PATH = './' # Results paths RESULTS_PATH = 'gs://wb2-app-data/v4' # No trailing slash ``` -------------------------------- ### Initialize Xarray Prediction Data Loader Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/forecast_latency.ipynb Initializes a `PredictionsFromXarray` data loader, specifying the previously defined `prediction_path` and a list of `variables` to load (2m_temperature, geopotential). This object prepares the data for subsequent loading operations. ```python variables = ['2m_temperature', 'geopotential'] prediction_data_loader = xarray_loaders.PredictionsFromXarray( path=prediction_path, variables=variables, ) ``` -------------------------------- ### Retrieve Aggregated Metric Values from Evaluation State Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/sparse_data.ipynb Calls the `metric_values` method on the `aggregation_state` object, passing the defined metrics. This final step retrieves the computed and aggregated metric values, providing the quantitative results of the forecast evaluation. ```python aggregation_state.metric_values(metrics) ``` -------------------------------- ### Define Interpolation for Gridded Forecast to Sparse Data Source: https://github.com/google-research/weatherbenchx/blob/main/docs/source/how_to/sparse_data.ipynb Initializes an `InterpolateToReferenceCoords` object, specifying 'nearest' neighbor interpolation and enabling longitude wrapping. This interpolator is crucial for aligning gridded predictions with the irregular, sparse locations of the METAR observations. ```python interpolation = interpolations.InterpolateToReferenceCoords( method='nearest', wrap_longitude=True ) ```