|
1 | | -# Cerrora |
| 1 | +# Cerrora |
| 2 | + |
| 3 | +This repository contains the code to train Cerrora, a weather model based on |
| 4 | +Microsoft's Aurora foundation model. |
| 5 | +It is a fork of the [Microsoft Aurora repository](https://github.com/microsoft/aurora). |
| 6 | +The Aurora model is a foundation model for atmospheric forecasting, which we finetune |
| 7 | +on the CERRA regional reanalysis dataset to predict weather in the European region. |
| 8 | +The original repo has a [documentation website](https://microsoft.github.io/aurora) |
| 9 | +, which contains detailed information on how to use the model. |
| 10 | + |
| 11 | +## Getting Started |
| 12 | + |
| 13 | +We use `conda` / `mamba` for development. To install the dependencies, navigate to the repository folder and run: |
| 14 | + |
| 15 | +```bash |
| 16 | +mamba env create -f environment.yml |
| 17 | +``` |
| 18 | + |
| 19 | +Then activate the environment with: |
| 20 | + |
| 21 | +```bash |
| 22 | +conda activate cerrora |
| 23 | +``` |
| 24 | + |
| 25 | +## Setting up the CERRA dataset |
| 26 | + |
| 27 | +The CERRA dataset is available on the ECMWF's Climate Data Store (CDS). |
| 28 | +To access the data, you need to create an account on the [CDS website](https://cds.climate.copernicus.eu/). |
| 29 | +Then, you can use our provided `download_cerra.py` script to download the data. |
| 30 | +For this, navigate to the scripts folder and run: |
| 31 | + |
| 32 | +```bash |
| 33 | +python download_cerra.py \ |
| 34 | +--request_template cerra_full.yaml \ |
| 35 | +--start_year 2022 \ |
| 36 | +--start_month 1 \ |
| 37 | +--end_year 2022 \ |
| 38 | +--end_month 6 \ |
| 39 | +--outdir /path/to/cerra/data |
| 40 | +``` |
| 41 | + |
| 42 | +This will download the CERRA data for the specified time range and save it in the specified output directory. |
| 43 | +After downloading, we need to compute a few derived variables to fit the settings of the Aurora model. |
| 44 | +This for example includes converting 10m wind speed and direction to u and v components. |
| 45 | +To precompute the derived variables, run: |
| 46 | + |
| 47 | +```bash |
| 48 | +python precompute_derived_variables.py \ |
| 49 | +--src_dir /path/to/cerra/data \ |
| 50 | +--dst_dir /path/to/updated/data \ |
| 51 | +--compute_10m_wind \ |
| 52 | +--compute_relative_humidity \ |
| 53 | +--compute_specific_humidity \ |
| 54 | +--compute_geopotential_at_surface |
| 55 | +``` |
| 56 | + |
| 57 | +This will create a new dataset in the specified destination directory with the derived variables added. |
| 58 | +Finally, we need to add the soil type information to the dataset, which is not included in the CERRA data. |
| 59 | +We provide a script to interpolate the ERA5 soil type data to the CERRA grid. |
| 60 | +To do this, run: |
| 61 | + |
| 62 | +```bash |
| 63 | +python regrid_slt.py --cerra_zarr_path /path/to/updated/data |
| 64 | +``` |
| 65 | + |
| 66 | +## Setting up the boundary conditions |
| 67 | + |
| 68 | +The rollout-trained Cerrora model requires lateral boundary conditions to maintain the forecast quality |
| 69 | +over longer lead times. |
| 70 | +For this, we use the IFS forecasts provided in WeatherBench2. |
| 71 | +To download the forecasts, navigate to the scripts/rollout folder and run: |
| 72 | + |
| 73 | +```bash |
| 74 | +python download_ifs_forecasts.py \ |
| 75 | +--start_year 2022 \ |
| 76 | +--start_month 1 \ |
| 77 | +--end_year 2022 \ |
| 78 | +--end_month 6 \ |
| 79 | +--outdir /path/to/ifs/forecasts |
| 80 | +``` |
| 81 | + |
| 82 | +After downloading, we need to regrid the forecasts to the CERRA grid. |
| 83 | +To do this, run: |
| 84 | +```bash |
| 85 | +python create_rollout_boundaries.py \ |
| 86 | +--global_path /path/to/ifs/forecasts \ |
| 87 | +--boundary_size 250 \ |
| 88 | +--num_cores 10 \ |
| 89 | +--start_time "2022-01-01T00:00:00" \ |
| 90 | +--end_time "2022-06-30T21:00:00" \ |
| 91 | +--output_path /path/to/regridded/forecasts |
| 92 | +``` |
| 93 | + |
| 94 | +Finally, we need to add the static variables to the regridded forecasts. |
| 95 | +To do this, run: |
| 96 | +```bash |
| 97 | +python add_static_vars_to_rollout_boundaries.py \ |
| 98 | +--global_path /path/to/ifs/forecasts \ |
| 99 | +--boundary_size 250 \ |
| 100 | +--num_cores 10 \ |
| 101 | +--output_path /path/to/regridded/forecasts |
| 102 | +``` |
| 103 | + |
| 104 | +## Training Cerrora |
| 105 | + |
| 106 | +To train the 6-hour lead time Cerrora model that is used as a base for the rollout training, adjust |
| 107 | +the dataset and checkpoint paths in `train_6h.sh`, then run the script. |
| 108 | +In case you need to resume training from a checkpoint, you can run `train_resume_6h.sh`, after |
| 109 | +adjusting the paths accordingly. |
| 110 | + |
| 111 | +Afterwards, to train the rollout Cerrora model, first create the checkpoint path for the training, |
| 112 | +and place the 6-hour model checkpoint in that folder. |
| 113 | +Then, adjust the dataset and checkpoint paths in `train_rollout_long_w_boundaries.sh`, and run the script. |
| 114 | + |
| 115 | +To reduce VRAM usage, we can use `task.use_activation_checkpointing=True`, which will trade off |
| 116 | +some speed for memory usage, by checkpointing the backbone activations. |
| 117 | +This setting is active by default in the provided training scripts. |
| 118 | +In addition, we can use `task.checkpoint_encoder_decoder=True` to enable checkpointing for the |
| 119 | +encoder and decoder parts of the model as well. |
| 120 | +This setting is active by default only for the rollout training scripts. |
| 121 | +As a result, the training can be run on GPUs with 80GB of VRAM (e.g. H100 80GB). |
| 122 | +We trained on one node with 8 GPUs, this can be changed by adjusting the torchrun `--nnodes` and |
| 123 | +`--nproc_per_node` parameters. |
| 124 | + |
| 125 | +### Logging |
| 126 | + |
| 127 | +We use Weights and Biases for logging metrics and settings, adjust ```logging.use_wandb``` to deactivate |
| 128 | +the logging if you wish to disable it. |
| 129 | +Before starting a run with W&B logging, you need to run ```wandb login``` and enter your access key. |
| 130 | +You find the key here: [Authorize page](https://wandb.ai/authorize) |
| 131 | + |
| 132 | +## Inferencing |
| 133 | + |
| 134 | +To create forecasts, adjust the dataset and checkpoint paths in `forecast.sh`, then run the script. |
| 135 | +For evaluating the forecasts, use our forked WeatherBench2 repository: [MISSING LINK] |
| 136 | + |
| 137 | +## License |
| 138 | + |
| 139 | +See [`LICENSE.txt`](LICENSE.txt). |
0 commit comments