Run Your Own AI Weather Model

misc., misc., 2025

This is a quick intro on how to use run the fourcastnetv2 and pangu ai model from ecmwf instructions.

Partial results are used in my final project for 12.810 Atm. Dynm. (2025 Spring, taught by Paul O’Gorman)

Are AI Weather Forecasts Respecting Atmosphere Dynamics?

[Presentation slides and write-ups will be available in 2025 summer]

As of April 10th, 2025

For non-commerical usage of ECMWF open accounts, the service/MARS will not be available, which means the most recent 30 day reanalysis will NOT be available, and the configuration of “/.ecmwfapirc” file would thus lead to errors of not being authorized. Issues have been encountered in post and issue

Instead, the solution is to use copernicus CDS open access data, which requires a “/.cdsapirc” file that you can find api instructions here.


Tutorials on running your own 10-day, 6-hourly AI weather forecast!


Single Model: FourCastNetv2-small

HPC setup and conda env demonstration for MIT Dolma Cluster

  1. Read ECMWF ai-models documentation
  2. module load apps/miniconda/3.6
  3. conda create -n fourcastnetv2 -c conda-forge python=3.10 -y
  4. source activate fourcastnetv2
  5. pip install ai-models ai-models-fourcastnetv2
  6. Dir of model weights and climatology files will be made automactially to: /home/x_yan/fourcastnetv2-small
  7. Config api - two options: (a. Commercial or ECMWF authorized MARS access), or (b. Open research CDS access)
  8. (Option a. MARS) Follow link to get MARS access
  9. Make file .ecmwfapirc, add {“url” : “https://api.ecmwf.int/v1”, \n “key” : “xxxxxxxxxxxxxxxxxxx”, \n “email” : “xxxxxxxxx”}
  10. (Option b. CDS) Follow link to get CDS access
  11. Make file .cdsapirc, url: https://cds.climate.copernicus.eu/api \n key: xxxx-xxxx-xxxx-xxxx
  12. Download data by running: ai-models –download-assets fourcastnetv2-small
  13. Files of weights.tar, global_means.npy, and global_stds.npy should be seen in path /home/x_yan/fourcastnetv2-small/
  14. (fourcastnetv2) x_yan@dolma:~$ cd fourcastnetv2-small/
  15. When using CDS option, modify when using PyTorch > 2.6: (i)cd to your model.py path: cd /home/x_yan/.conda/envs/fourcastnetv2/lib/python3.10/site-packages/ai_models_fourcastnetv2/, (ii) open model.py, (iii) change line 146 checkpoint = torch.load(checkpoint_file, map_location=self.device) into checkpoint = torch.load(checkpoint_file, map_location=self.device, weights_only=False)
  16. (fourcastnetv2) x_yan@dolma:~/fourcastnetv2-small$ ai-models –input cds –date 20230110 –time 0000 fourcastnetv2-small
  17. (Optional) Other params - notice lead-time has unit of 1 hour - could be –date 2023-10-01 \ –time 00:00 \ –lead-time 24h \ –path /net/flood/data/users/x_yan/fourcastnetv2 \ –assets-sub-directory \ –input cds \ –output file
  18. Output forecast file would be in the same folder named fourcastnetv2-small.grib
  19. Enjoy! image

Interpret Results

  1. Load the jupyter notebook from link.
  2. The forecast grib file is divided into surface and pressure-level data
  3. Sample intial, 5day, and 10 day data visualizes asimageimageimageimageimageimage

Multiple Models: FourCastNetv2-small & Panguweather

  1. module load apps/miniconda/3.6
  2. conda create -n ai-weather -c conda-forge python=3.10 -y
  3. source activate ai-weather
  4. Check your available nvaa cuda version by: conda search -c nvidia cudatoolkit
  5. conda install -c “nvidia/label/cuda-11.7.0” \ cudatoolkit=11.7.0 \ cudnn=8.9.5
  6. pip install onnxruntime-gpu==1.17.1
  7. conda install -c “nvidia/label/cuda-11.7.0” cuda-nvcc
  8. Check nvcc –version
  9. pip install ai-models ai-models-fourcastnetv2 ai-models-panguweather
  10. ai-models –download-assets –assets
  11. Modify the model.py as above section
  12. cd to dir to run models (Example: cd /home/x_yan/ai_weather_models/fourcastnetv2-small, or cd /home/x_yan/ai_weather_models/panguweather)
  13. ai-models –input cds –date 20250110 –time 0000 –lead-time 48 panguweather
  14. As of April 11, 2025, the panguweather could only be run on CPU due to ONNX issues, such that each step takes around 4 minutes to run on a CPU, rather than seconds on a GPU; see details here. The solution of conda env with cuda-toolkit is not helpful. image

Below is a 48-lead time, 6-hourly forecast comparison btwn Pangu (upper row) vs. FourCastNetv2 (lower row), evaluated at init. (same), 24 hr, & 48 hr

  1. Geopotential Height z500 image image
  2. Temperature T500 image image
  3. Zonal wind u500 image image
  4. Merdional wind v500 image image