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
- Read ECMWF ai-models documentation
- module load apps/miniconda/3.6
- conda create -n fourcastnetv2 -c conda-forge python=3.10 -y
- source activate fourcastnetv2
- pip install ai-models ai-models-fourcastnetv2
- Dir of model weights and climatology files will be made automactially to: /home/x_yan/fourcastnetv2-small
- Config api - two options: (a. Commercial or ECMWF authorized MARS access), or (b. Open research CDS access)
- (Option a. MARS) Follow link to get MARS access
- Make file .ecmwfapirc, add {“url” : “https://api.ecmwf.int/v1”, \n “key” : “xxxxxxxxxxxxxxxxxxx”, \n “email” : “xxxxxxxxx”}
- (Option b. CDS) Follow link to get CDS access
- Make file .cdsapirc, url: https://cds.climate.copernicus.eu/api \n key: xxxx-xxxx-xxxx-xxxx
- Download data by running: ai-models –download-assets fourcastnetv2-small
- Files of weights.tar, global_means.npy, and global_stds.npy should be seen in path /home/x_yan/fourcastnetv2-small/
- (fourcastnetv2) x_yan@dolma:~$ cd fourcastnetv2-small/
- 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)
- (fourcastnetv2) x_yan@dolma:~/fourcastnetv2-small$ ai-models –input cds –date 20230110 –time 0000 fourcastnetv2-small
- (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
- Output forecast file would be in the same folder named fourcastnetv2-small.grib
- Enjoy!
Interpret Results
- Load the jupyter notebook from link.
- The forecast grib file is divided into surface and pressure-level data
- Sample intial, 5day, and 10 day data visualizes as
Multiple Models: FourCastNetv2-small & Panguweather
- module load apps/miniconda/3.6
- conda create -n ai-weather -c conda-forge python=3.10 -y
- source activate ai-weather
- Check your available nvaa cuda version by: conda search -c nvidia cudatoolkit
- conda install -c “nvidia/label/cuda-11.7.0” \ cudatoolkit=11.7.0 \ cudnn=8.9.5
- pip install onnxruntime-gpu==1.17.1
- conda install -c “nvidia/label/cuda-11.7.0” cuda-nvcc
- Check nvcc –version
- pip install ai-models ai-models-fourcastnetv2 ai-models-panguweather
- ai-models –download-assets –assets
- Modify the model.py as above section
- 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)
- ai-models –input cds –date 20250110 –time 0000 –lead-time 48 panguweather
- 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.
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
- Geopotential Height z500
- Temperature T500
- Zonal wind u500
- Merdional wind v500