Climateformer¶
Before starting training and evaluation, please download the ERA5 dataset file.
Before starting evaluation, please download or train to generate a pretrained model.
The 2018 data of the ERA5 dataset for evaluation has been saved and can be downloaded and evaluated through the following links: 2018.h5, mean.nc, std.nc.
1. Background Introduction¶
Long-term climate prediction mainly involves predicting weather changes in the next few weeks or even months. Such predictions usually need to cover multiple meteorological elements, such as temperature, humidity, wind speed, etc., which have complex spatiotemporal dependencies on meteorological changes. Accurate climate prediction is of great significance for disaster prevention and mitigation, agricultural production, aerospace and other fields. Traditional meteorological prediction models mainly rely on physical formulas and Numerical Weather Prediction (NWP), but with the rapid development of deep learning, data-driven models are gradually showing stronger prediction capabilities.
Climateformer is a spatiotemporal deep learning framework for long-term climate prediction. The design goal of this model is to learn and simulate the evolution paradigm of meteorological systems over long periods. Its architecture usually contains three modules: the encoder encodes multi-source and multi-sphere climate variables such as sea temperature, air pressure, and wind field into a global vector that can represent the current "climate state". The core evolution module (based on Transformer structure) is dedicated to capturing the long-range time dependence of these climate states across weeks or even months. Finally, the decoder predicts the average key climate indices for multiple future cycles based on the evolved state vector. Through Climateformer, climate forecasting can achieve more efficient and accurate multi-element prediction, providing more reliable data support for meteorological services.
2. Model Principle¶
This chapter briefly introduces the model principle of Climateformer.
2.1 Encoder¶
This module uses two layers of Transformer to extract spatial features and update node features:
2.2 Evolver¶
This module uses two layers of Transformer to learn global temporal dynamic characteristics:
2.3 Decoder¶
This module uses two layers of convolution to decode spatiotemporal representations into future multi-meteorological elements:
2.4 Climateformer Model Structure¶
The overall structure of the model is shown in the figure:
The Climateformer model first uses a feature embedding layer to encode spatial features of input signals (average time frames of multiple meteorological elements over the past few weeks):
| ppsci/arch/climateformer.py | |
|---|---|
Then the model uses the evolver to learn the dynamic characteristics of spatial features and predict the meteorological characteristics of the average time frames of the next few weeks:
| ppsci/arch/climateformer.py | |
|---|---|
Finally, the model combines spatiotemporal dynamic characteristics with initial underlying meteorological features, and uses two layers of convolution to predict the weekly average values of multiple meteorological elements for the next few weeks to months:
| ppsci/arch/climateformer.py | |
|---|---|
3. Model Training¶
3.1 Dataset Introduction¶
The case uses the preprocessed ERA5Climate dataset, which is a subset of the ERA5 reanalysis data. ERA5Climate contains multiple variables of global atmosphere, land and ocean. The study area ranges from 140°E to 70°W, from 55°N to the equator, with a spatial resolution of 0.25°. The dataset runs from 2016 to 2020, providing hourly estimates of weather conditions, which is very suitable for tasks such as short- and medium-term multi-meteorological element prediction. In practical applications, the time interval is one week, and each frame is selected as the weekly average value within 7*24 hours.
The dataset is saved as a T x C x H x W matrix, recording the values of corresponding meteorological elements at the corresponding location and time, where T is the time series length, C represents the channel dimension (in the case, meteorological information such as temperature, relative humidity, eastward wind speed, northward wind speed at 3 different pressure levels are selected), H and W represent the height and width of the matrix divided by latitude and longitude. According to the year, the dataset is divided into training set, validation set, and test set at a ratio of 7:2:1. In the case, the mean and standard deviation of meteorological element data are pre-calculated for subsequent regularization operations.
3.2 Model Training¶
3.2.1 Model Construction¶
This case is implemented based on the Climateformer model, expressed in PaddleScience code as follows:
3.2.2 Constraint Construction¶
This case solves the problem based on data-driven methods, so it is necessary to use SupervisedConstraint built in PaddleScience to construct a supervised constraint. Before defining the constraint, you need to first specify each parameter used for data loading in the constraint.
The code for loading training set data is as follows:
The code for defining supervised constraint is as follows:
| examples/climateformer/main.py | |
|---|---|
3.2.3 Validator Construction¶
In this case, the training process will use the validation set to evaluate the training status of the current model at a certain training epoch interval, and SupervisedValidator needs to be used to construct the validator.
The code for loading validation set data is as follows:
The code for defining supervised validator is as follows:
| examples/climateformer/main.py | |
|---|---|
3.2.4 Learning Rate and Optimizer Construction¶
In this case, the learning rate is set to 1e-3, and the optimizer uses Adam, expressed in PaddleScience code as follows:
| examples/climateformer/main.py | |
|---|---|
3.2.5 Model Training¶
After completing the above settings, you only need to pass the instantiated objects to ppsci.solver.Solver in order, and then start training.
3.2.6 Evaluation During Training¶
By setting the eval_during_train parameter in ppsci.solver.Solver, the model parameters with the best effect on the validation set can be automatically saved.
| examples/climateformer/main.py | |
|---|---|
3.3 Evaluation Model¶
3.3.1 Validator Construction¶
The code for loading test set data is as follows:
The code for defining supervised validator is as follows:
| examples/climateformer/main.py | |
|---|---|
Similar to SupervisedValidator for validation set, the evaluation metrics used here are MAE and MSE.
3.3.2 Load Model and Evaluate¶
Set the loading path of pretrained model parameters and load the model.
Instantiate ppsci.solver.Solver, and then start evaluation.
4. Complete Code¶
Dataset Interface:
| ppsci/data/dataset/era5climate_dataset.py | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
Model Structure:
| ppsci/arch/climateformer.py | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | |
Model Training:
| examples/climateformer/main.py | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
Configuration File:
5. Result Display¶
The figure below shows the comparison between the prediction results of the Climateformer model and the ground truth in the temperature prediction task at 1000 hPa isobaric layer. The horizontal axis represents different prediction time steps, with a time interval of 1 week, and each time the model predicts the weekly average value for the next 6 weeks.

