--- license: apache-2.0 datasets: - openclimatefix/era5 language: - es - en metrics: - mse library_name: transformers pipeline_tag: image-to-image tags: - climate - transformers - super-resolution --- # Europe Reanalysis Super Resolution The aim of the project is to create a Machine learning (ML) model that can generate high-resolution regional reanalysis data (similar to the one produced by CERRA) by downscaling global reanalysis data from ERA5. This will be accomplished by using state-of-the-art Deep Learning (DL) techniques like U-Net, conditional GAN, and diffusion models (among others). Additionally, an ingestion module will be implemented to assess the possible benefit of using CERRA pseudo-observations as extra predictors. Once the model is designed and trained, a detailed validation framework takes the place. It combines classical deterministic error metrics with in-depth validations, including time series, maps, spatio-temporal correlations, and computer vision metrics, disaggregated by months, seasons, and geographical regions, to evaluate the effectiveness of the model in reducing errors and representing physical processes. This level of granularity allows for a more comprehensive and accurate assessment, which is critical for ensuring that the model is effective in practice. Moreover, tools for interpretability of DL models can be used to understand the inner workings and decision-making processes of these complex structures by analyzing the activations of different neurons and the importance of different features in the input data. This work is funded by [Code for Earth 2023](https://codeforearth.ecmwf.int/) initiative. The model **ConvSwin2SR** is released in Apache 2.0, making it usable without restrictions anywhere. # Table of Contents - [Model Card for Europe Reanalysis Super Resolution](#model-card-for--model_id-) - [Table of Contents](#table-of-contents) - [Model Details](#model-details) - [Model Description](#model-description) - [Uses](#uses) - [Direct Use](#direct-use) - [Out-of-Scope Use](#out-of-scope-use) - [Bias, Risks, and Limitations](#bias-risks-and-limitations) - [Training Details](#training-details) - [Training Data](#training-data) - [Training Procedure](#training-procedure) - [Preprocessing](#preprocessing) - [Speeds, Sizes, Times](#speeds-sizes-times) - [Evaluation](#evaluation) - [Testing Data, Factors & Metrics](#testing-data-factors--metrics) - [Testing Data](#testing-data) - [Factors](#factors) - [Metrics](#metrics) - [Results](#results) - [Technical Specifications](#technical-specifications-optional) - [Model Architecture and Objective](#model-architecture-and-objective) - [Compute Infrastructure](#compute-infrastructure) - [Hardware](#hardware) - [Software](#software) - [Authors](#authors) # Model Details ## Model Description We present the ConvSwin2SR tranformer, a vision model for down-scaling (from 0.25º to 0.05º) regional reanalysis grids in the mediterranean area. - **Developed by:** A team of Predictia Intelligent Data Solutions S.L. & Instituto de Fisica de Cantabria (IFCA) - **Model type:** Vision model - **Language(s) (NLP):** en, es - **License:** Apache-2.0 - **Resources for more information:** More information needed - [GitHub Repo](https://github.com/ECMWFCode4Earth/DeepR) # Uses ## Direct Use The primary use of the ConvSwin2SR transformer is to enhance the spatial resolution in the Mediterranean area of global reanalysis grids using a regional reanalysis grid as groundtruth. This enhancement is crucial for more precise climate studies, which can aid in better decision-making for various stakeholders including policymakers, researchers, and weather-dependent industries like agriculture, energy, and transportation. ## Out-of-Scope Use The model is specifically designed for downscaling ERA5 reanalysis grids to the CERRA regional reanalysis grid and may not perform well or provide accurate results for other types of geospatial data or geographical regions. # Bias, Risks, and Limitations Significant research has explored bias and fairness issues with language models (see, e.g., [Sheng et al. (2021)](https://aclanthology.org/2021.acl-long.330.pdf) and [Bender et al. (2021)](https://dl.acm.org/doi/pdf/10.1145/3442188.3445922)). Predictions generated by the model may include disturbing and harmful stereotypes across protected classes; identity characteristics; and sensitive, social, and occupational groups. # Training Details ## Training Data The datasets that are mainly used in the project can be found in the following Copernicus Climate Data Store catalogue entries: - [ERA5 hourly data on single levels from 1940 to present](https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-single-levels?tab=overview) - [CERRA sub-daily regional reanalysis data for Europe on single levels from 1984 to present](https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-cerra-single-levels?tab=overview) 1. Input low-resolution grids (ERA5): The input grids are structured as a 3D array with dimensions of (time, 60, 44), where 60 and 44 are the number of grid points along the longitude and latitude axes, respectively. Geographically, these grids cover a longitude range from -8.35 to 6.6 and a latitude range from 46.45 to 35.50. This implies that the data covers a region extending from a westernmost point at longitude -8.35 to an easternmost point at longitude 6.6, and from a northernmost point at latitude 46.45 to a southernmost point at latitude 35.50. 2. Target high-resolution grids (CERRA): They are represented as a 3D array with larger dimensions of (time, 240, 160), indicating a finer grid resolution compared to the input grids. Here, 240 and 160 are the number of grid points along the longitude and latitude axes, respectively. The geographical coverage for these high-resolution grids is defined by a longitude range from -6.85 to 5.1 and a latitude range from 44.95 to 37. This region extends from a westernmost point at longitude -6.85 to an easternmost point at longitude 5.1, and from a northernmost point at latitude 44.95 to a southernmost point at latitude 37. ![spatial-coverages](spatial-coverages.png) The dataset's temporal division is structured to optimize model training and subsequent per-epoch validation. The training duration spans 29 years, commencing in January 1985 and culminating in December 2013. Sequentially, the validation phase begins, covering the period from January 2014 to December 2017. This 4-year interval is solely dedicated to evaluating the model's aptitude on data it hasn't been exposed to during training. This separation ensures the model's robustness and its capability to make dependable predictions for the validation period. ## Training Procedure ### Preprocessing The preprocessing of climate datasets ERA5 and CERRA, extracted from the Climate Data Store (CDS), is a critical step before their utilization in training models. This section defines the preprocessing steps undertaken to homogenize these datasets into a common format. The steps include unit standardization, coordinate system rectification, and grid interpolation. The rationale and methodologies employed in each step are discussed comprehensively, setting a robust foundation for the subsequent training procedure. 1. Unit Standardization: A preliminary step in the preprocessing pipeline involved the standardization of units across both datasets. This was imperative to ensure a uniform unit system, facilitating a seamless integration of the datasets in later stages. The units in both datasets were scrutinized and amended to adhere to a common unit system, thereby eliminating any discrepancies that could hinder the analysis. 2. Coordinate System Rectification: The coordinate system of the datasets was rectified to ensure a coherent representation of geographical information. Specifically, the coordinates and dimensions were renamed to a standardized format with longitude (lon) and latitude (lat) as designated names. The longitude values were adjusted to range from -180 to 180 instead of the initial 0 to 360 range, while latitude values were ordered in ascending order, thereby aligning with conventional geographical coordinate systems. 3. Grid Interpolation: The ERA5 dataset is structured on a regular grid with a spatial resolution of 0.25º, whereas the CERRA dataset inhabits a curvilinear grid with a Lambert Conformal projection of higher spatial resolution (0.05º). To overcome this disparity, a grid interpolation procedure was initiated. This step was crucial to align the datasets onto a common regular grid (with different spatial resolution), thereby ensuring consistency in spatial representation. The interpolation transformed the CERRA dataset to match the regular grid structure of the ERA5 dataset, keeping its initial spatial resolution of 0.05º (5.5 km). ### Speeds, Sizes, Times - Training time: The training duration for the ConvSwin2SR model is notably extensive, clocking in at 3,648 days to complete a total of 100 epochs with a batch size of 2 for a total number of batches equal to ~43000. - Model size: The ConvSwin2SR model is a robust machine learning model boasting a total of 12,383,377 parameters. This size reflects a substantial capacity for learning and generalizing complex relationships within the data, enabling the model to effectively upscale lower-resolution reanalysis grids to higher-resolution versions. - Inference speed: The ConvSwin2SR model demonstrates a commendable inference speed, particularly when handling a substantial batch of samples. Specifically, when tasked with downscaling 248 samples, which is synonymous with processing data for an entire month at 3-hour intervals, the model completes the operation in a mere 21 seconds. This level of efficiency is observed in a local computing environment outfitted with 16GB o f RAM and 4GB of GPU memory. # Evaluation ## Testing Data, Factors & Metrics ### Testing Data In terms of spatial dimensions, both the input grids from ERA5 and the target high-resolution grids from CERRA remain consistent throughout the training and testing phases. This spatial consistency ensures that the model is evaluated under the same geographic conditions as it was trained, allowing for a direct comparison of its performance across different temporal segments. The testing data samples correspond to the three-year period from 2018 to 2020, inclusive. This segment is crucial for assessing the model's real-world applicability and its performance on the most recent data points, ensuring its relevance and reliability in current and future scenarios. ### Factors ### Metrics More information needed ## Results More information needed # Technical Specifications ## Model Architecture and Objective The model architecture is based on the original Swin2 architecture for Super Resolution (SR) tasks. The library [transformers](https://github.com/huggingface/transformers) is used to simplify the model design. ![architecture](architecture.png) The main component of the model is a [transformers.Swin2SRModel](https://huggingface.co/docs/transformers/model_doc/swin2sr#transformers.Swin2SRModel) which increases x8 the spatial resolution of its inputs (Swin2SR only supports upscaling ratios power of 2). As the real upscale ratio is ~5 and the output shape of the region considered is (160, 240), a Convolutional Neural Network (CNN) is included as a pre-process component which convert the inputs into a (20, 30) feature maps that can be fed to the Swin2SRModel. This network is trained to learn the residuals of the bicubic interpolation. The specific parameters of this network are available in [config.json](https://huggingface.co/predictia/convswin2sr_mediterranean/blob/main/config.json). ## Compute Infrastructure The use of GPUs in deep learning projects significantly accelerates model training and inference, leading to substantial reductions in computation time and making it feasible to tackle complex tasks and large datasets with efficiency. The generosity and collaboration of our partners are instrumental to the success of this projects, significantly contributing to our research and development endeavors. - **AI4EOSC**: AI4EOSC stands for "Artificial Intelligence for the European Open Science Cloud." The European Open Science Cloud (EOSC) is a European Union initiative that aims to create a federated environment of research data and services. AI4EOSC is a specific project or initiative within the EOSC framework that focuses on the integration and application of artificial intelligence (AI) technologies in the context of open science. - **European Weather Cloud**: The European Weather Cloud is the cloud-based collaboration platform for meteorological application development and operations in Europe. Services provided range from delivery of weather forecast data and products to the provision of computing and storage resources, support and expert advice. ### Hardware For our project, we have deployed two virtual machines (VMs), each featuring a dedicated Graphics Processing Unit (GPU). One VM is equipped with a 16GB GPU, while the other boasts a more substantial 20GB GPU. This resource configuration allows us to efficiently manage a wide range of computing tasks, from data processing to model training and sampling, and ultimately drives the successful execution of our project. ### Software The code used to train and evaluate this model is freely available through its GitHub Repository [ECMWFCode4Earth/DeepR](https://github.com/ECMWFCode4Earth/DeepR) hosted in the ECWMF Code 4 Earth organization. ### Authors - Mario Santa Cruz. Predictia Intelligent Data Solutions S.L. - Antonio Pérez. Predictia Intelligent Data Solutions S.L. - Javier Díez. Predictia Intelligent Data Solutions S.L.