Aardvark Weather

repository·main·Indexed 42 days ago

https://github.com/anna-allen/aardvark-weather-public

A multi-stage machine learning model for weather forecasting that provides global gridded and station-based forecasts for temperature and wind speed. The project includes the ConvCNPWeatherE2E class for end-to-end finetuned forecasts, training scripts for encoder, processor, and decoder modules, and tools for visualizing satellite (HIRS, AMSU, IASI, ASCAT) and SYNOPS (HadISD, ICOADS, IGRA) data.

Tokens
3.5K
Snippets
11
Records
15
Agent score
52%

What's inside Aardvark Weather

  1. Understand the Aardvark Weather training process

    main

    Aardvark Weather is trained in multiple stages using specific scripts. Note that the training commands provided below are for illustrative purposes to demonstrate the training process and may require specific local data loading pipelines and compute infrastructure to execute.

    Training Stages and Scripts

    • Encoder Training: Handled via train_module.py (illustrated by train_encoder.sh).
    • Processor Training: Includes pre-training via train_module.py (illustrated by train_processor.sh) and finetuning via finetune.py (illustrated by finetune.sh).
    • Decoder Training: Handled via train_module.py (illustrated by train_decoder.sh).
    • End-to-End Finetuning: Handled via e2e_train.py (illustrated by train_e2e.sh).
  2. Access Aardvark Weather model weights

    main

    Trained model weights for the encoder, decoder, processor, and end-to-end finetuned models (one-day lead time) are available on Hugging Face. For the decoder and end-to-end models, weights are provided for both temperature and wind speed modalities.

    https://huggingface.co/datasets/av555/aardvark-weather/tree/main/trained_model
  3. Access Aardvark Weather datasets

    main

    There are two ways to access data for this project:

    1. Sample Data: A local file data/sample_data_final.pkl is provided for immediate use with the demo notebooks.
    2. Full Training Dataset: A machine learning-ready dataset containing observational data from 2007-2019 at 24-hour resolution is available on Hugging Face for those wishing to train their own end-to-end models.
    https://huggingface.co/datasets/av555/aardvark-weather
  4. Generate weather forecasts using notebooks

    main

    The notebooks/ directory contains demonstrations for producing different types of forecasts:

    • Full Model Forecasts: Use forecast_demo.ipynb to load the complete Aardvark Weather model, generate predictions from sample data, and visualize global gridded and station forecasts.
    • Optimized Station Forecasts: Use e2e_finetune_demo.ipynb to generate optimized station forecasts using the end-to-end finetuned model.
  5. Understand the Aardvark Weather dataset structure

    main
    The Aardvark Weather forecast is generated using a single timeslice of observations. This data is typically produced by the WeatherDatasetE2E loader found in ../aardvark/loaders.py. The dataset is structured as a dictionary containing multiple assimilation channels, including satellite observations and SYNOPS (land/marine/radiosonde) data. Each channel contains multiple channels of observations and metadata.
  6. Visualize SYNOPS data (HadISD, ICOADS, IGRA)

    main

    SYNOPS data includes observations from land stations, marine platforms, and radiosonde profiles. Unlike the grid-based satellite data, these are often represented as point observations using scatter plots.

    Available SYNOPS keys:

    • x_context_hadisd_current / y_context_hadisd_current (HadISD)
    • icoads_x_current / icoads_current (ICOADS)
    • igra_x_current / igra_current (IGRA)

    For HadISD, the longitude and latitude are stored in separate x_context and y_context keys.

    # Example: Visualizing HadISD data
    plot_channel = 0
    plt.scatter(
        data["assimilation"]["x_context_hadisd_current"][plot_channel][0,0,:].cpu(),
        data["assimilation"]["x_context_hadisd_current"][plot_channel][0,1,:].cpu(),
        c = data["assimilation"]["y_context_hadisd_current"][plot_channel][0].T.cpu(), 
        cmap="magma"
    )
    plt.show()
  7. Unnormalise weather model predictions

    main

    The model outputs normalized predictions that must be unnormalised to represent physical values. This process requires loading the mean and std factors specific to the forecast variable from the norm_factors directory and applying a scaling factor (e.g., HADISD_SCALING_FACTOR = 10).

    The formula used is: (prediction * std + mean) * scaling_factor.

    # Load normalization factors
    mean = np.load(f"../data/norm_factors/mean_hadisd_{local_forecast_var}.npy")
    std = np.load(f"../data/norm_factors/std_hadisd_{local_forecast_var}.npy")
    
    # Unnormalise
    station_forecast_unnorm = (
        station_forecast.detach().cpu() * std + mean
    ) * HADISD_SCALING_FACTOR
  8. Visualize Satellite data (HIRS, AMSU, IASI, ASCAT)

    main

    Satellite data is stored under the data["assimilation"] key. The data is typically represented as tensors that need to be moved to the CPU and transposed for plotting.

    Available satellite keys:

    • hirs_current
    • amsua_current
    • amsub_current
    • iasi_current
    • ascat_current

    Note: For amsua_current, the latitude array may require an offset (e.g., lat[:-1]) depending on the grid dimensions.

    # Example: Visualizing HIRS data
    import matplotlib.pyplot as plt
    
    plot_channel = 11
    plt.contourf(
        lon, 
        lat, 
        data["assimilation"]["hirs_current"][0, ..., plot_channel].cpu().T, 
        levels=100, 
        cmap="magma"
    )
    plt.show()
  9. Unnormalise station forecast predictions

    main

    The station forecasts returned by the model are normalised. To obtain physically meaningful values (e.g., temperature in Celsius), you must unnormalise them using the mean and standard deviation factors stored in the norm_factors directory.

    For variables like tas (2m temperature), you may also need to apply a scaling factor (e.g., HADISD_SCALING_FACTOR = 10).

    Steps:

    1. Load mean_hadisd_{variable}.npy and std_hadisd_{variable}.npy from the norm_factors folder.
    2. Apply the transformation: (prediction * std + mean) * scaling_factor.
    # Example for variable 'tas'
    local_forecast_var = "tas"
    mean = np.load(f"../data/norm_factors/mean_hadisd_{local_forecast_var}.npy")
    std = np.load(f"../data/norm_factors/std_hadisd_{local_forecast_var}.npy")
    HADISD_SCALING_FACTOR = 10
    
    # Unnormalise
    station_forecast = (
        station_forecast.detach().cpu() * std + mean
    ) * HADISD_SCALING_FACTOR
  10. Initialize the ConvCNPWeatherE2E model for forecasting

    main

    To generate weather forecasts, use the ConvCNPWeatherE2E class from the e2e_model module. You must specify the lead_time, paths to the trained encoder, processor, and decoder models, and the path to auxiliary data. The decoder path is variable-specific (e.g., ../trained_models/decoder/tas/).

    Parameters:

    • device: The device to run on (e.g., `
  11. Reference: Training execution commands

    main

    The following shell commands illustrate the training and finetuning steps for the various modules. These are intended for transparency regarding the training process and are not guaranteed to be executable without specific local infrastructure setup.

    # Encoder
    bash train_encoder.sh
    
    # Processor
    bash train_processor.sh
    bash finetune.sh
    
    # Decoder
    bash train_decoder.sh
    
    # End-to-end
    bash train_e2e.sh