Mumbai Rainfall Forecasting

A Transformer-based model with a U-Net-style CNN backbone that forecasts rainfall 3 hours ahead at 37 weather stations across Mumbai.

Code on GitHub · Advisor: Prof. Subimal Ghosh

I forecast rainfall for the next 3 hours at 37 automatic weather stations (AWS) across Mumbai, from rainfall, wind-speed and GFS forecast data for the past 3 hours at 15-minute intervals. I started with two LSTM models and then moved to Transformer-based models. The final model adds 2D CNN backbones such as U-Net to capture the overlap in data between nearby stations. This improved the correlation by 17% over the entire prediction period and increased the hit rate for periods of heavy rainfall.

Data Preprocessing

The data available to me had rainfall, wind speed, GFS forecasts and the coordinates of the AWS stations in Mumbai. The first data-processing task was to combine all of these into a single CSV file. The data was collected by 37 stations all over Mumbai at 15-minute intervals over the years 2015–22.

Rainfall and wind-speed data were combined as they were, after basic preprocessing such as removing NaN values. The GFS predictions had to be shifted left in the timeline by 15 minutes so that they could also be used as inputs to the model. The final CSV file had 93,695 rows, each with 37 + 37 + 37 = 111 features.

Task: 3-hour forecast from a 3-hour lookback

The aim of this project was to predict the rainfall in different areas of Mumbai for the next 3 hours at a lead time of 15 minutes, given all 111 features for the past 3 hours at 15-minute intervals. So the input to the model has shape (12, 111), while the output has shape (12, 1) for each of the 37 stations.

Test & Train Data

The dataset was split into two DataFrames, one for training and one for testing, with a training split of 0.9. The DataFrame used to generate the training data has shape (84325, 111), and the one used to generate the test data has shape (9370, 111). Both DataFrames were normalized with min-max normalization, where the min and max of each of the 111 features were computed on the training DataFrame only. The same values were later used to normalize the test DataFrame before feeding it to the model, and to convert the model outputs back to their original scale after evaluation.

With the normalized data, I built two 3-dimensional arrays, x_train and x_test, with the number of samples as the first dimension, lead time as the second and features as the third. I also built y_train and y_test, 2D arrays for each station, with the number of samples as the first dimension and lead time as the second. All of these arrays were converted into tensors and split into batches after shuffling, so that the model learns the true characteristics of rainfall rather than just extrapolating the previous values.

Model Architectures

I first tried two models based on the LSTM architecture, then a Transformer, and finally a Transformer with a 2D CNN (U-Net-style) backbone.

LSTM Model 1

This model was implemented in TensorFlow using the Sequential API. It has a few layers with a gradually decreasing number of units, so that only the relevant information flows through. It gave the best correlation of 51% with the target time series. The model architecture, the correlation values and the time-series plot for one of the stations (Andheri) are shown below.

Architecture of LSTM model 1
Correlation of LSTM model 1 predictions with the original time series
Left: model architecture. Right: correlation values with the original time series.
Predicted and actual rainfall time series at Andheri for LSTM model 1
Predicted vs. actual rainfall time series at Andheri

LSTM Model 2

This model was implemented in PyTorch. It has 4 identical layers with a predefined hidden-state dimension, and gave a best correlation of around 58% with the target time series. The model architecture, the correlation values and the time-series plot for one of the stations (Andheri) are shown below.

Architecture of LSTM model 2
Correlation of LSTM model 2 predictions with the original time series
Left: model architecture. Right: correlation values with the original time series.
Predicted and actual rainfall time series at Andheri for LSTM model 2
Predicted vs. actual rainfall time series at Andheri

Transformer with Positional Encoding

This model uses the predefined Transformer model in PyTorch. I additionally included a positional-encoding block, which lets the model learn the relative importance of the different lead times in the input when predicting future rainfall. The model has two inputs, one each for the encoder and the decoder of the Transformer, so it needs three arrays instead of the two used by the LSTM models. There should be a non-zero overlap between the encoder input and the decoder input, and between the decoder input and the model output. So the encoder input spans 24 time steps, while the decoder input and the Transformer output span 16 time steps. The model architecture is as follows:

Architecture of the Transformer model with positional encoding
Transformer model architecture

Final Model: Transformer with a CNN Backbone

Rainfall at nearby stations is strongly related, so the final model adds 2D CNN backbones such as U-Net that extract the overlap in data between spatially close stations. This improved the correlation by 17% over the entire prediction period and increased the hit rate for periods of heavy rainfall.