Validation of ERA5 and ERA5-Land reanalysis data (code)

Published:

Matching Timezone and calendar of station and ERA5-Land data

Timezone of ERA5-Land was converted to local UTC+6 time zone and calendar type of BMD data matches with ERA5 Land data

import xarray as xr
import pandas as pd
import numpy as np
ERA5_Land = xr.open_dataset(r"D:\CMIP6 Project\Thesis work\Data Analysis\Data\ERA5Land_Data\merged_data\ERA5_Land_Daily_Tmin_Tmax_1950_2019(unmasked_localized).nc",
                            chunks = {"time": 365})
ERA5_Land
<xarray.Dataset> Size: 625MB
Dimensions:     (latitude: 65, longitude: 47, valid_time: 25568)
Coordinates:
  * latitude    (latitude) float64 520B 27.0 26.9 26.8 26.7 ... 20.8 20.7 20.6
  * longitude   (longitude) float64 376B 88.0 88.1 88.2 88.3 ... 92.4 92.5 92.6
    number      int64 8B ...
  * valid_time  (valid_time) datetime64[ns] 205kB 1950-01-01 ... 2020-01-01
Data variables:
    t2m_min     (valid_time, latitude, longitude) float32 312MB dask.array<chunksize=(25568, 65, 47), meta=np.ndarray>
    t2m_max     (valid_time, latitude, longitude) float32 312MB dask.array<chunksize=(25568, 65, 47), meta=np.ndarray>
25568 * 59 * 46
69391552
BMD_temp_data = pd.read_csv(r"D:\CMIP6 Project\Thesis work\BMD_stations Data\BMD_temp_data_cleaned(2).csv")
BMD_temp_data
Station_IDTmaxDateTminLatitudeLongitude
01111126.41989-01-0114.723.7890.39
11111127.81989-02-0111.623.7890.39
21111133.01989-03-0119.723.7890.39
31111133.31989-04-0122.323.7890.39
41111133.31989-05-0124.423.7890.39
.....................
3502471192934.02019-05-3127.020.8792.26
3502481192931.22019-07-3124.520.8792.26
3502491192932.82019-08-3125.520.8792.26
3502501192932.52019-10-3124.520.8792.26
3502511192928.62019-12-3114.520.8792.26

350252 rows × 6 columns

BMD_temp_data["Date"] = pd.to_datetime(BMD_temp_data["Date"])
era5_start = pd.to_datetime(ERA5_Land.valid_time.min().values)
era5_end   = pd.to_datetime(ERA5_Land.valid_time.max().values)

bmd_start = BMD_temp_data["Date"].min()
bmd_end   = BMD_temp_data["Date"].max()

start = max(era5_start, bmd_start)
end   = min(era5_end, bmd_end)

print("Overlap:", start, "to", end)
Overlap: 1989-01-01 00:00:00 to 2019-12-31 00:00:00
ERA5_Land = ERA5_Land.sel(valid_time = slice(start, end))
BMD_temp_data = BMD_temp_data.query("Date >= @start and Date <= @end")

Station Location

ERA5_Land.valid_time
<xarray.DataArray 'valid_time' (valid_time: 11322)> Size: 91kB
array(['1989-01-01T00:00:00.000000000', '1989-01-02T00:00:00.000000000',
       '1989-01-03T00:00:00.000000000', ..., '2019-12-29T00:00:00.000000000',
       '2019-12-30T00:00:00.000000000', '2019-12-31T00:00:00.000000000'],
      dtype='datetime64[ns]')
Coordinates:
    number      int64 8B ...
  * valid_time  (valid_time) datetime64[ns] 91kB 1989-01-01 ... 2019-12-31
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature

# ------------------------------------------
# 2. Select 1 day (example: 2005-06-15)
# ------------------------------------------
date = "2012-12-31T00:00:00.000000000"
tmax = ERA5_Land["t2m_max"].sel(valid_time=date)  # change variable name if needed

# ----------------------l--------------------
# 3. Clip the data to Bangladesh extent
# ------------------------------------------
bd_extent = {
    "lon_min": 88.0,
    "lon_max": 93.0,
    "lat_min": 20.5,
    "lat_max": 26.7
}


# ------------------------------------------
# 4. Plot map
# ------------------------------------------
plt.figure(figsize=(10, 8))
ax = plt.axes(projection=ccrs.PlateCarree())

# Plot temperature data
temp_plot = tmax.plot(
    ax=ax,
    transform=ccrs.PlateCarree(),
    cmap="coolwarm",
    cbar_kwargs={"label": "Daily Max Temperature (°C)"}
)

# Add borders and coastlines
ax.add_feature(cfeature.BORDERS, linewidth=1)
ax.add_feature(cfeature.COASTLINE, linewidth=1)

# Set map extent to Bangladesh
ax.set_extent([
    bd_extent["lon_min"],
    bd_extent["lon_max"],
    bd_extent["lat_min"],
    bd_extent["lat_max"]
], crs=ccrs.PlateCarree())

# ------------------------------------------
# 5. Add station locations
# ------------------------------------------

# Plot station points
ax.scatter(
    BMD_temp_data["Longitude"],
    BMD_temp_data["Latitude"],
    color="black",
    s= 5,
    marker="o",
    transform=ccrs.PlateCarree(),
    zorder=5,
    label="Stations"
)

lons = BMD_temp_data["Longitude"].values
lats = BMD_temp_data["Latitude"].values
ids = BMD_temp_data["Station_ID"].values

# # Faster annotation loop (zip is faster than iterrows)
# for lon, lat, sid in zip(lons, lats, ids):
#     ax.annotate(
#         sid,
#         xy=(lon, lat),
#         xytext=(3, 3),  # offset in points (better than adding 0.05 degrees)
#         textcoords="offset points",
#         fontsize=7,
#         transform=ccrs.PlateCarree(),
#         zorder=6
#     )

# Title
plt.title(f"ERA5-Land Daily Maximum Temperature (Clipped) — {date}")

plt.show()

png

Spatial Matching

stations = pd.DataFrame({
    "station": BMD_temp_data["Station_ID"],
    "lat": BMD_temp_data["Latitude"],
    "lon": BMD_temp_data["Longitude"]
}).drop_duplicates().sort_values("station")

stations = stations.set_index("station")

Bilinear Interpolation to match ERA5 Land with BMD

ERA5_interpolated = ERA5_Land.interp(
    latitude = xr.DataArray(stations["lat"], dims="station"),
    longitude=xr.DataArray(stations["lon"], dims="station"),
    method="linear"
)
ERA5_interpolated
<xarray.Dataset> Size: 3MB
Dimensions:     (valid_time: 11322, station: 31)
Coordinates:
    number      int64 8B ...
  * valid_time  (valid_time) datetime64[ns] 91kB 1989-01-01 ... 2019-12-31
    latitude    (station) float64 248B 25.63 25.72 24.35 ... 24.15 23.64 22.43
    longitude   (station) float64 248B 88.66 89.26 88.56 ... 89.55 88.84 89.66
  * station     (station) int64 248B 10120 10208 10320 ... 41909 41926 41958
Data variables:
    t2m_min     (valid_time, station) float32 1MB dask.array<chunksize=(11322, 31), meta=np.ndarray>
    t2m_max     (valid_time, station) float32 1MB dask.array<chunksize=(11322, 31), meta=np.ndarray>
ERA5_interpolated_df = ERA5_interpolated.to_dataframe().reset_index().copy()
ERA5_interpolated_df.query("station == 10724").isnull().sum()
valid_time    0
station       0
number        0
t2m_min       0
t2m_max       0
latitude      0
longitude     0
dtype: int64
ERA5_interpolated_df.groupby("station").agg({
    't2m_min': ['min', 'max', 'mean', 'std'],
    't2m_max': ['min', 'max', 'mean', 'std']
}).sort_values("station")
t2m_mint2m_max
minmaxmeanstdminmaxmeanstd
station
101206.41237928.49178320.2578435.28625016.55157842.77244829.2962663.785527
102086.32208628.38012320.3739545.08741916.13173542.58695929.0502193.478245
103206.70049430.94492821.2715025.17870115.99556343.34702829.9899994.078047
104086.15491829.35770120.6251565.20102916.04851242.54071929.5662323.591045
106096.61516728.25027520.4915544.94388917.06471639.28267229.2148623.192209
107057.01091927.09650019.9381475.04205815.92182336.44472328.3130823.051478
107247.16156927.96337020.6004804.91657616.25914737.77903029.0679453.141100
109106.55404931.21856121.2224705.20107716.45041642.50160829.9288813.822689
111117.71829729.68679321.5463574.87112617.07704739.12695929.5827193.204785
113136.95057328.72833621.0727134.92145917.32768238.99866829.4521672.984413
113169.77463529.39560222.2732674.41008117.83381538.05814629.2029643.057549
114077.07729130.77407321.4381675.24556416.69376641.30692030.2315373.553976
115058.92838530.25550422.0514374.60907916.49354639.97657829.6206473.461003
115138.61252629.87761421.7978094.73035017.52720339.71114929.7140503.267853
116048.81592430.45254522.0654834.85738417.39810240.33638330.0153193.320520
116109.21522130.76860022.5914974.73652017.36864939.98650529.9697243.428891
117049.27134429.68018222.2440394.55056617.91372738.77368829.5085783.126911
11706NaNNaNNaNNaNNaNNaNNaNNaN
118057.40301428.55359021.2528644.91078617.91805339.11197929.3925242.783592
118098.20057329.06992821.6576154.88358417.97006538.98091429.2272332.738281
11912NaNNaNNaNNaNNaNNaNNaNNaN
11925NaNNaNNaNNaNNaNNaNNaNNaN
11927NaNNaNNaNNaNNaNNaNNaNNaN
11929NaNNaNNaNNaNNaNNaNNaNNaN
1200710.78181827.83389321.4729834.04154217.58062138.57222329.2170293.034111
121039.21349229.80807322.1837274.71282417.70622739.20698929.5736702.967243
12110NaNNaNNaNNaNNaNNaNNaNNaN
418586.18394228.25654920.2599635.15650216.27329742.77695929.1284083.599653
419097.38320930.57608021.3732665.03068316.71304341.35080029.7074463.597685
419266.56092431.32776021.3069855.24991115.73548542.60071930.1322653.895679
419589.88014330.35430322.4742374.51762417.65893739.78693029.7246873.264485

Missing values are only for coastal regions as bilinear interpolatin is picking null grid cells. (6 regions in total)

Using KDTree to bypass nearest null grid cells

mask = ~ERA5_Land["t2m_min"].isel(valid_time = 0).isnull()

lats = ERA5_Land.latitude.values
lons = ERA5_Land.longitude.values

lon2d, lat2d = np.meshgrid(lons, lats)

valid_lats = lat2d[mask.values]
valid_lons = lon2d[mask.values]
from scipy.spatial import cKDTree

coords = np.column_stack([valid_lats, valid_lons])
tree = cKDTree(coords)
station_coords = np.column_stack([
    stations["lat"].values,
    stations["lon"].values
])

dist, idx = tree.query(station_coords)

nearest_lat = valid_lats[idx]
nearest_lon = valid_lons[idx]
era_sel_valid = ERA5_Land.sel(
    latitude = xr.DataArray(nearest_lat, dims="station"),
    longitude = xr.DataArray(nearest_lon, dims="station"),
    method="nearest"
)

Using nearest neighbors where bilinear fails

ERA5_final = ERA5_interpolated.where(~ERA5_interpolated.isnull(), era_sel_valid)
ERA5_final
<xarray.Dataset> Size: 3MB
Dimensions:     (valid_time: 11322, station: 31)
Coordinates:
    number      int64 8B 0
  * valid_time  (valid_time) datetime64[ns] 91kB 1989-01-01 ... 2019-12-31
  * station     (station) int64 248B 10120 10208 10320 ... 41909 41926 41958
Data variables:
    t2m_min     (valid_time, station) float32 1MB dask.array<chunksize=(11322, 31), meta=np.ndarray>
    t2m_max     (valid_time, station) float32 1MB dask.array<chunksize=(11322, 31), meta=np.ndarray>

Bilinear Interpolation was failing for more than 12 stations because of missing grid cells. Moreover, for nearest neighbors six stations were giving negative values due to nearest neighbor being a null grid cell. KDTree is utilized to select nearest non-negative cells.

Validation of the ERA5 Land

Station wise min-max temperature.

ERA5_final.to_dataframe().reset_index().groupby("station").agg({
    't2m_min': ['min', 'max', 'mean', 'std'],
    't2m_max': ['min', 'max', 'mean', 'std']
}).sort_values("station")
t2m_mint2m_max
minmaxmeanstdminmaxmeanstd
station
101206.41237928.49178320.2578435.28625016.55157842.77244829.2962663.785527
102086.32208628.38012320.3739545.08741916.13173542.58695929.0502193.478245
103206.70049430.94492821.2715025.17870115.99556343.34702829.9899994.078047
104086.15491829.35770120.6251565.20102916.04851242.54071929.5662323.591045
106096.61516728.25027520.4915544.94388917.06471639.28267229.2148623.192209
107057.01091927.09650019.9381475.04205815.92182336.44472328.3130823.051478
107247.16156927.96337020.6004804.91657616.25914737.77903029.0679453.141100
109106.55404931.21856121.2224705.20107716.45041642.50160829.9288813.822689
111117.71829729.68679321.5463574.87112617.07704739.12695929.5827193.204785
113136.95057328.72833621.0727134.92145917.32768238.99866829.4521672.984413
113169.77463529.39560222.2732674.41008117.83381538.05814629.2029643.057549
114077.07729130.77407321.4381675.24556416.69376641.30692030.2315373.553976
115058.92838530.25550422.0514374.60907916.49354639.97657829.6206473.461003
115138.61252629.87761421.7978094.73035017.52720339.71114929.7140503.267853
116048.81592430.45254522.0654834.85738417.39810240.33638330.0153193.320520
116109.21522130.76860022.5914974.73652017.36864939.98650529.9697243.428891
117049.27134429.68018222.2440394.55056617.91372738.77368829.5085783.126911
1170610.48892229.53018222.7945564.22171518.25698938.42251629.0367632.969537
118057.40301428.55359021.2528644.91078617.91805339.11197929.3925242.783592
118098.20057329.06992821.6576154.88358417.97006538.98091429.2272332.738281
1191212.25576828.85366822.5745613.78937917.78555338.07730128.3069542.480430
1192512.27163728.85025022.9440273.48647219.24819934.79336527.7679182.476537
1192711.93325828.51773122.7676653.39508719.67373735.69766228.2243062.491416
1192913.35318028.34610022.8407093.21252920.76968436.16250628.4313342.156101
1200710.78181827.83389321.4729834.04154217.58062138.57222329.2170293.034111
121039.21349229.80807322.1837274.71282417.70622739.20698929.5736702.967243
1211012.13345330.24502623.4757274.09206818.59146137.17666628.6966252.544665
418586.18394228.25654920.2599635.15650216.27329742.77695929.1284083.599653
419097.38320930.57608021.3732665.03068316.71304341.35080029.7074463.597685
419266.56092431.32776021.3069855.24991115.73548542.60071930.1322653.895679
419589.88014330.35430322.4742374.51762417.65893739.78693029.7246873.264485
BMD_temp_data.groupby("Station_ID").agg({
    'Tmin': ['min', 'max', 'mean', 'std'],
    'Tmax': ['min', 'max', 'mean', 'std']
}).sort_values("Station_ID")
TminTmax
minmaxmeanstdminmaxmeanstd
Station_ID
101203.229.820.1650445.95946711.041.430.1435164.190926
102083.530.520.3830875.65536110.939.829.7107683.934541
103203.430.220.5851006.10011612.643.731.3689474.462741
104084.530.021.1374935.53862211.044.030.8122193.827229
106094.730.620.9292675.44302212.738.129.9301253.484783
107053.429.420.8136944.65009915.039.630.3986213.413802
107244.029.019.5840975.94821215.039.230.6765713.481706
109103.931.020.6482866.11345413.543.031.1548914.265283
111116.530.322.0328065.05857713.440.230.8731823.622845
113135.330.221.1388085.21018915.239.230.4050403.297922
113167.229.722.0836274.79383415.040.030.7130293.488855
114074.230.020.9823255.92274413.643.231.9060203.938520
115055.630.021.4202375.36922213.341.230.8440903.802004
115136.029.521.4842725.40061214.539.731.0255563.523218
116046.430.021.9044005.39131113.640.731.4193213.707221
116105.531.321.6948225.63952613.543.431.3918273.715452
117046.529.821.4459885.42820115.839.430.8213823.236582
117067.230.421.7451785.25498615.238.930.5696863.069304
118056.130.021.3207254.96246916.339.430.4227883.081824
118098.529.822.2965204.63824915.539.330.4938283.386917
119125.731.020.9951325.42779217.240.230.9647492.813139
1192510.032.022.3547214.25207018.238.530.0938782.704971
1192710.331.022.4589223.95952119.739.530.9250622.563048
119299.729.522.1738234.27197121.038.030.4292902.242611
120075.528.820.8661504.76322716.541.130.9573603.275935
121037.430.022.0678394.97460415.439.530.8765403.233258
121107.730.422.2232925.04666415.640.030.6193462.907762
418582.931.020.2190035.76025711.641.030.1122084.101184
419095.131.020.8836975.57768113.540.530.6785903.928976
419263.930.020.8781346.05353512.543.531.6106384.298561
419587.230.522.5333364.81938214.840.531.1273633.602428

After observing the above statistics, I can say that there is a warm-bias in ERA5.

Time series Plot ERA5 VS Observational data
ERA5_final
<xarray.Dataset> Size: 3MB
Dimensions:     (valid_time: 11322, station: 31)
Coordinates:
    number      int64 8B 0
  * valid_time  (valid_time) datetime64[ns] 91kB 1989-01-01 ... 2019-12-31
  * station     (station) int64 248B 10120 10208 10320 ... 41909 41926 41958
Data variables:
    t2m_min     (valid_time, station) float32 1MB dask.array<chunksize=(11322, 31), meta=np.ndarray>
    t2m_max     (valid_time, station) float32 1MB dask.array<chunksize=(11322, 31), meta=np.ndarray>
ERA5_final_df = ERA5_final.to_dataframe().reset_index().copy().drop(columns = ['number'])
ERA5_final_df.rename(columns = {"t2m_min": "Tmin", "t2m_max": "Tmax",
                                    "valid_time": "Date", "station": "Station_ID"}, inplace = True)
# Save this file for later use (Extreme Indices, and Statistical Test):
# ERA5_final_df.to_csv(r"D:\CMIP6 Project\Thesis work\Data Analysis\Data\ERA5Land_Data\interpolated data\ERA5_Land_interpolated.csv", index = False)

Visual Inspection:

import matplotlib.pyplot as plt

# Select data for a specific station:
station_id = 11111
df_era5 = ERA5_final_df.query("Station_ID == @station_id")
df_bmd = BMD_temp_data.query("Station_ID == @station_id")

# Convert "Date" columns to datetime and sort by date
df_era5["Date"] = pd.to_datetime(df_era5["Date"])
df_era5 = df_era5.sort_values("Date")

df_bmd["Date"] = pd.to_datetime(df_bmd["Date"])
df_bmd = df_bmd.sort_values("Date")


# Create figure
plt.figure(figsize=(12, 6))

# Plot ERA5 (Red, Dotted)
plt.plot(
    df_era5['Date'],
    df_era5['Tmax'],
    color='red',
    linestyle='-',
    alpha=0.5,
    label='ERA5-Land Tmax'
)

# Plot BMD (Blue, Solid)
plt.plot(
    df_bmd['Date'],
    df_bmd['Tmax'],
    color='blue',
    linestyle='-',
    alpha=0.3,
    label='BMD Tmax'
)

# Labels and title
plt.xlabel('Date')
plt.ylabel('Maximum Temperature (°C)')
plt.title(f'Daily Maximum Temperature: ERA5-Land vs BMD - Station ID: {station_id}')

# Legend
plt.legend()

# Improve layout
plt.tight_layout()

# Show plot
plt.show()

png

Dark shaded color means complete alignment.

# Create figure
plt.figure(figsize=(12, 6))

# Plot ERA5 (Red, Dotted)
plt.plot(
    df_era5['Date'],
    df_era5['Tmin'],
    color='red',
    linestyle='-',
    alpha=0.5,
    label='ERA5-Land Tmin'
)

# Plot BMD (Blue, Solid)
plt.plot(
    df_bmd['Date'],
    df_bmd['Tmin'],
    color='blue',
    linestyle='-',
    alpha=0.3,
    label='BMD Tmin'
)

# Labels and title
plt.xlabel('Date')
plt.ylabel('Minimum Temperature (°C)')
plt.title(f'Daily Minimum Temperature: ERA5-Land vs BMD - Station ID: {station_id}')

# Legend
plt.legend()

# Improve layout
plt.tight_layout()

# Show plot
plt.show()

png

Stationwise correlation, RMSE, and Mean Bias

df_merged = pd.merge(
    BMD_temp_data,
    ERA5_final_df,
    on=['Station_ID', 'Date'],
    suffixes=('_bmd', '_era5'),
    how='inner'
)
df_merged.isna().sum()
Station_ID       0
Tmax_bmd      1233
Date             0
Tmin_bmd      1362
Latitude         0
Longitude        0
Tmin_era5        0
Tmax_era5        0
dtype: int64
df_merged = df_merged.dropna(subset=['Tmin_bmd', 'Tmin_era5', 'Tmax_bmd', 'Tmax_era5'])
bmd_st_name = pd.read_csv(r"D:\CMIP6 Project\Thesis work\BMD_stations Data\MaxTempAverRain (1).csv")
df_merged = pd.merge(
    df_merged,
    bmd_st_name.loc[:, ["Stn_Name", "Stn_ID"]],
    left_on="Station_ID",
    right_on="Stn_ID",
    how="left"
)
import numpy as np
from scipy.stats import pearsonr


def rmse(obs, sim):
    return np.sqrt(np.mean((sim - obs) ** 2))


def bias(obs, sim):
    return np.mean(sim - obs)


def corr(obs, sim):
    return pearsonr(obs, sim)[0]

def mae(obs, sim):
    return np.mean(np.abs(sim - obs))
results = []

for station, group in df_merged.groupby('Stn_Name'):

    obs = group['Tmax_bmd']
    sim = group['Tmax_era5']

    r = corr(obs, sim)
    r_rmse = rmse(obs, sim)
    r_mae = mae(obs, sim)
    r_bias = bias(obs, sim)

    results.append({
        'station_id': station,
        'Correlation': r,
        'RMSE (°C)': r_rmse,
        "MAE (°C)": r_mae,
        'Mean Bias (°C)': r_bias,
        'Missing Days': 11321 - len(group)
    })


df_metrics = pd.DataFrame(results)

print("Overall Metrics for Tmax:")
df_metrics
Overall Metrics for Tmax:
station_idCorrelationRMSE (°C)MAE (°C)Mean Bias (°C)Missing Days
0Barisal0.8991011.9430851.637737-1.31256014
1Bhola0.8954862.0680091.789841-1.536216241
2Bogra0.8931672.1328641.785701-1.24941353
3Chandpur0.9043912.1218931.801667-1.50634779
4Chuadanga0.9372042.1136951.782615-1.48411916
5Comilla0.8740591.8668691.540787-0.95265516
6Cox's Bazar0.8683012.9963662.750040-2.70026628
7Dhaka0.9229251.9065631.603062-1.2923445
8Dinajpur0.9019942.0000671.617733-0.85183222
9Faridpur0.9274491.8772001.563969-1.22417725
10Feni0.8697451.8449851.526159-1.03871699
11Ishurdi0.9399581.9177201.583985-1.23352217
12Jessore0.9260022.2491311.915988-1.68600838
13Khepupara0.9035242.2995272.046775-1.93073036
14Khulna0.9102322.0821551.723965-1.40570910
15Kutubdia0.8878752.6360192.384397-2.322544134
16Madaripur0.9128391.9719501.663936-1.341305338
17MaijdeeCourt0.8838572.0413081.667049-1.263498169
18Mongla0.9155242.0182481.677803-1.40449113
19Mymensingh0.8851331.7753531.411911-0.7146619
20Patuakhali0.8957041.9410021.614801-1.30213812
21Rajshahi0.9396092.0683941.723744-1.38924234
22Rangamati0.8962042.2615451.944847-1.728864178
23Rangpur0.8939701.8836191.490916-0.66147412
24Satkhira0.9269081.9964731.682351-1.42875420
25Sitakunda0.8805972.9754342.738066-2.659711193
26Srimangal0.9024262.2025291.908509-1.611512106
27Syedpur0.8951772.0748651.690975-0.978229769
28Sylhet0.8850272.6217582.318249-2.08491010
29Tangail0.9101021.8965491.549974-0.9724658
30Teknaf0.8402562.3540362.075474-1.995419174

Overall, there is a good alignment of ERA5 Land with BMD station data

The validation results indicate strong agreement between ERA5-Land and BMD observations, with correlation coefficients ranging from 0.87 to 0.94 and RMSE values mostly below 2.5°C. A systematic negative bias (–1 to –2.7°C) was observed, indicating underestimation of Tmax by ERA5-Land. These results demonstrate that ERA5-Land reliably represents the temporal variability of daily maximum temperature and is suitable as a reference dataset for bias correction of CMIP6 outputs.

Station wise Comparison for Tmin
results = []

for station, group in df_merged.groupby('Stn_Name'):

    obs = group['Tmin_bmd']
    sim = group['Tmin_era5']

    r = corr(obs, sim)
    r_rmse = rmse(obs, sim)
    r_mae = mae(obs, sim)
    r_bias = bias(obs, sim)

    results.append({
        'station_id': station,
        'Correlation': r,
        'RMSE (°C)': r_rmse,
        'MAE (°C)': r_mae,
        'Mean Bias (°C)': r_bias,
        'Missing Days': 11321 - len(group)
    })


df_metrics_min = pd.DataFrame(results)
print("Overall Metrics for Tmin:")
df_metrics_min
Overall Metrics for Tmin:
station_idCorrelationRMSE (°C)MAE (°C)Mean Bias (°C)Missing Days
0Barisal0.9672471.7388181.2859830.79796014
1Bhola0.9667401.9050521.3804811.038662241
2Bogra0.9728331.3930511.123921-0.51653153
3Chandpur0.9643911.2979240.9643660.18937979
4Chuadanga0.9732291.5910651.2224850.42823116
5Comilla0.9647211.3774641.050279-0.06793316
6Cox's Bazar0.9555261.2688590.9327090.31024728
7Dhaka0.9593291.5088461.214102-0.4867445
8Dinajpur0.9752101.4224481.1193060.09206722
9Faridpur0.9641881.6581981.2515390.63264325
10Feni0.9625881.3546870.983305-0.07810699
11Ishurdi0.9739221.6790591.2928770.57319717
12Jessore0.9724431.5450531.1717780.45955138
13Khepupara0.9612612.0138081.5043381.24482036
14Khulna0.9635961.4897171.1349810.16224310
15Kutubdia0.9485951.5689171.1581320.595911134
16Madaripur0.9650351.5232701.1664980.290087338
17MaijdeeCourt0.9519491.5945631.239393-0.576673169
18Mongla0.9653091.2668660.956352-0.05704713
19Mymensingh0.9695251.4423191.172017-0.4367559
20Patuakhali0.9668231.2799480.9434180.11701112
21Rajshahi0.9731421.7361401.3265640.68185334
22Rangamati0.9617891.5647271.1624970.661660178
23Rangpur0.9720841.3889001.088237-0.00921512
24Satkhira0.9658191.8562731.3933820.89681920
25Sitakunda0.9620042.5714981.8658941.546527193
26Srimangal0.9723481.9151901.4272180.992119106
27Syedpur0.9711171.4439011.1330460.056812769
28Sylhet0.9637731.6189811.320147-0.87700410
29Tangail0.9700511.4900041.1256660.4903308
30Teknaf0.9487701.7123451.2552940.649354174
df_metrics_min.to_csv(r"D:\CMIP6 Project\Thesis work\Data Analysis\Data\Error metrics\ERA5L_Tmin_metrics.csv", index = False)

Hexbin Density Plot

from scipy.stats import linregress
from scipy.stats import linregress
import matplotlib.pyplot as plt

def density_scatter_plot(
    x, y,
    title="",
    xlabel="",
    ylabel="",
    panel_label=None,
    ax=None,
    label_fontsize=14,
    tick_fontsize=12,
    title_fontsize=14,
    panel_fontsize=16
):
    if ax is None:
        fig, ax = plt.subplots(figsize=(7, 6))

    # Hexbin density plot
    hb = ax.hexbin(
        x, y,
        gridsize=80,
        bins='log',
        cmap='viridis',
        mincnt=1
    )

    # Colorbar
    cb = plt.colorbar(hb, ax=ax)
    cb.set_label("Collocation Count (log scale)", fontsize=12)
    cb.ax.tick_params(labelsize=11)

    # 1:1 line
    min_val = min(x.min(), y.min())
    max_val = max(x.max(), y.max())

    ax.plot(
        [min_val, max_val],
        [min_val, max_val],
        'b--',
        lw=2,
        label='1:1 Line'
    )

    # Regression line
    slope, intercept, r, p, _ = linregress(x, y)

    ax.plot(
        x,
        slope * x + intercept,
        'r',
        lw=2,
        label='Regression'
    )

    # Axis labels
    ax.set_xlabel(xlabel, fontsize=label_fontsize)
    ax.set_ylabel(ylabel, fontsize=label_fontsize)

    # Tick font size
    ax.tick_params(axis='both', labelsize=tick_fontsize)

    # Title
    ax.set_title(
        f"{title}\nSlope = {slope:.2f}",
        fontsize=title_fontsize
    )


    # Panel label (a), (b), (c), ...
    if panel_label is not None:
        ax.text(
            -0.12, 1.08,               # x, y position (outside upper-left corner)
            f"({panel_label})",
            transform=ax.transAxes,
            fontsize=panel_fontsize,
            fontweight="bold",
            va="top",
            ha="left",
            clip_on=False              # ensures the label isn't clipped
        )

    ax.legend(fontsize=11)

    return ax
fig, ax = plt.subplots(figsize=(7, 6))

density_scatter_plot(
    df_merged['Tmax_bmd'],
    df_merged['Tmax_era5'],
    xlabel="BMD Tmax (°C)",
    ylabel="ERA5-Land Tmax (°C)",
    panel_label="b",
    ax=ax
)

plt.tight_layout()

fig.savefig(
    "D:\CMIP6 Project\Thesis work\Table and Charts\Modifed charts\ERA5Land_tmax_density_scatter_plot.png",
    dpi=600,
    bbox_inches="tight"
)

png

The hexbin density scatter plot indicates strong agreement between ERA5-Land and BMD observations, with a high correlation coefficient (r = 0.893). The majority of data points are concentrated along the 1:1 line, particularly in the range of 25–35°C, demonstrating good performance under typical climatic conditions. The regression slope (0.82) and the position of the fitted line below the 1:1 line indicate a systematic underestimation of Tmax by ERA5-Land, especially at higher temperatures. The relatively narrow spread around the regression line suggests moderate random error, while deviations at extreme values reflect reduced performance during heatwave events. Overall, the consistent and linear error structure supports the suitability of ERA5-Land as a reference dataset for bias correction

fig, ax = plt.subplots(figsize=(7, 6))

density_scatter_plot(
    df_merged['Tmin_bmd'],
    df_merged['Tmin_era5'],
    xlabel = "BMD Tmin (°C)",
    ylabel = "ERA5-Land Tmin (°C)",
    panel_label="b",
    ax=ax
)

plt.tight_layout()

fig.savefig(
    "D:\CMIP6 Project\Thesis work\Table and Charts\Modifed charts\ERA5-Land_tmin_density_scatter_plot.png",
    dpi=600,
    bbox_inches="tight"
)

png

Seasonal Evaluation

I will divide dataset into four seasons: Winter (Dec-Feb), Pre-Moonsoon (March-May), Moonsoon (June-Auguest), Post-Moonsoon (Oct-Nov)

df = df_merged.copy()

df['month'] = df['Date'].dt.month

def get_season(month):

    if month in [12, 1, 2]:
        return 'Winter (DJF)'
    elif month in [3, 4, 5]:
        return 'Pre-monsoon (MAM)'
    elif month in [6, 7, 8, 9]:
        return 'Monsoon (JJAS)'
    else:
        return 'Post-monsoon (ON)'


df['season'] = df['month'].apply(get_season)

Seasonal Metrics (All Stations Combined)

For Tmax

seasonal_results = []

for season, g in df.groupby('season'):

    obs = g['Tmax_bmd']
    sim = g['Tmax_era5']

    seasonal_results.append({
        'Season': season,
        'Correlation': corr(obs, sim),
        'RMSE (°C)': rmse(obs, sim),
        'MAE (°C)': mae(obs, sim),
        'Bias (°C)': bias(obs, sim)
    })

print("Sesonal Metrics for Tmax:")
df_seasonal_max = pd.DataFrame(seasonal_results)

df_seasonal_max

Sesonal Metrics for Tmax:
SeasonCorrelationRMSE (°C)MAE (°C)Bias (°C)
0Monsoon (JJAS)0.7585262.3120712.020203-1.831061
1Post-monsoon (ON)0.8445512.4031832.164631-2.068258
2Pre-monsoon (MAM)0.8128262.0152101.630170-1.053579
3Winter (DJF)0.8345271.8732331.480978-0.960740
obs = df["Tmax_bmd"]
sim = df["Tmax_era5"]
overall_metrics_Tmax = pd.DataFrame({
        'Season': "Overall",
        'Correlation': corr(obs, sim),
        'RMSE (°C)': rmse(obs, sim),
        'MAE (°C)': mae(obs, sim),
        'Bias (°C)': bias(obs, sim)
}, index = [0])
df_Tmax = pd.concat([df_seasonal_max, overall_metrics_Tmax], ignore_index=True).round(3)
df_Tmax
SeasonCorrelationRMSE (°C)MAE (°C)Bias (°C)
0Monsoon (JJAS)0.7592.3122.020-1.831
1Post-monsoon (ON)0.8452.4032.165-2.068
2Pre-monsoon (MAM)0.8132.0151.630-1.054
3Winter (DJF)0.8351.8731.481-0.961
4Overall0.8972.1541.813-1.460
# df_Tmax.to_csv(r"D:\CMIP6 Project\Thesis work\Table and Charts\ERA5-Land_Tmax_metrics_seasonal_overall.csv", index = False)

For Tmin:

seasonal_results = []

for season, g in df.groupby('season'):

    obs = g['Tmin_bmd']
    sim = g['Tmin_era5']

    seasonal_results.append({
        'Season': season,
        'Correlation': corr(obs, sim),
        'RMSE (°C)': rmse(obs, sim),
        'MAE (°C)': mae(obs, sim),
        'Bias (°C)': bias(obs, sim)
    })

print("Sesonal Metrics for Tmin:")
df_seasonal_min = pd.DataFrame(seasonal_results)

df_seasonal_min

Sesonal Metrics for Tmin:
SeasonCorrelationRMSE (°C)MAE (°C)Bias (°C)
0Monsoon (JJAS)0.5308391.0853420.831987-0.288820
1Post-monsoon (ON)0.9149021.3860631.081253-0.156158
2Pre-monsoon (MAM)0.8640681.8262841.3673590.647656
3Winter (DJF)0.8368932.0468121.6282931.113549
obs = df["Tmin_bmd"]
sim = df["Tmin_era5"]
overall_metrics_Tmin = pd.DataFrame({
        'Season': "Overall",
        'Correlation': corr(obs, sim),
        'RMSE (°C)': rmse(obs, sim),
        'MAE (°C)': mae(obs, sim),
        'Bias (°C)': bias(obs, sim)
}, index = [0])

df_Tmin = pd.concat([df_seasonal_min, overall_metrics_Tmin], ignore_index=True).round(3)
df_Tmin
SeasonCorrelationRMSE (°C)MAE (°C)Bias (°C)
0Monsoon (JJAS)0.5311.0850.832-0.289
1Post-monsoon (ON)0.9151.3861.081-0.156
2Pre-monsoon (MAM)0.8641.8261.3670.648
3Winter (DJF)0.8372.0471.6281.114
4Overall0.9581.6091.2050.316
df_Tmin.to_csv(r"D:\CMIP6 Project\Thesis work\Table and Charts\ERA5Land_Tmin_metrics_seasonal_overall.csv", index = False)
Seasonal Hexabin Plots:
def seasonal_hexbin(df, var1, var2, season, ax, var3):

    d = df[df['season'] == season]

    density_scatter_plot(
        d[var1],
        d[var2],
        title= f"{season}",
        ax=ax,
    )


seasons = df['season'].unique()

fig, ax = plt.subplots(2, 2, figsize=(10,8))

ax = ax.flatten()

for i, s in enumerate(seasons):
    seasonal_hexbin(df, "Tmax_bmd", "Tmax_era5",s, ax[i], "Tmax")

fig.supxlabel("BMD Tmax (°C)", fontsize=12)
fig.supylabel("ERA5-Land Tmax (°C)", fontsize=12)
# fig.suptitle("Seasonal Validation of ERA5-Land Tmax", fontsize=16, weight="bold")

plt.tight_layout()
plt.show()

png

seasons = df['season'].unique()

fig, ax = plt.subplots(2, 2, figsize=(10,8))

ax = ax.flatten()

for i, s in enumerate(seasons):
    seasonal_hexbin(df, "Tmin_bmd", "Tmin_era5",s, ax[i], "Tmin")

fig.supxlabel("BMD Tmin (°C)", fontsize=14)
fig.supylabel("ERA5-Land Tmin (°C)", fontsize=14)
plt.tight_layout()
plt.show()

png

Seasonal Metrics (Station Wise) For Maximum Temperature
season_station = []

for (st, season), g in df.groupby(['Stn_Name', 'season']):

    obs = g['Tmax_bmd']
    sim = g['Tmax_era5']

    season_station.append({
        'Station': st,
        'Season': season,
        'Correlation': corr(obs, sim),
        'RMSE': rmse(obs, sim),
        'MAE': mae(obs, sim),
        'Bias': bias(obs, sim)
    })

# print("Station wise Seasonal Metrics for Tmax:")
df_season_station = pd.DataFrame(season_station)

# # pd.set_option('display.max_rows', 500)
# df_season_station
season_order = [
    'Winter (DJF)',
    'Pre-monsoon (MAM)',
    'Monsoon (JJAS)',
    'Post-monsoon (ON)'
]

df_season_station['Season'] = pd.Categorical(
    df_season_station['Season'],
    categories=season_order,
    ordered=True
)
Seasonal Comparison by Boxplot
Tmax
import seaborn as sns
# Set style
sns.set_style("whitegrid")
sns.set_context("talk")   # bigger fonts

# Create figure
fig, axes = plt.subplots(
    nrows=4,
    ncols=1,
    figsize=(10, 12),
    sharex=True
)

# -----------------------------
# 1. Correlation
# -----------------------------
sns.boxplot(
    data=df_season_station,
    x="Season",
    y="Correlation",
    ax=axes[0],
    width=0.6,
    showfliers=False,
    palette="Blues"
)

axes[0].set_ylabel("Correlation (r)")
axes[0].set_title("Seasonal Validation of ERA5-Land Tmax", fontsize=16, weight="bold")


# -----------------------------
# 2. RMSE
# -----------------------------
sns.boxplot(
    data=df_season_station,
    x="Season",
    y="RMSE",
    ax=axes[1],
    width=0.6,
    showfliers=False,
    palette="Blues"
)

axes[1].set_ylabel("RMSE (°C)")


#---------------------
# 3. MAE
#---------------------
sns.boxplot(
    data=df_season_station,
    x="Season",
    y="MAE",
    ax=axes[2],
    width=0.6,
    showfliers=False,
    palette="Blues"
)

axes[2].set_ylabel("MAE (°C)")

# -----------------------------
# 3. Bias
# -----------------------------
sns.boxplot(
    data=df_season_station,
    x="Season",
    y="Bias",
    ax=axes[3],
    width=0.6,
    showfliers=False,
    palette="Blues"
)

axes[3].set_ylabel("Bias (°C)")
axes[3].set_xlabel("Season")
# Enable x labels
axes[3].tick_params(labelbottom=True)

# Add zero line for bias
axes[3].axhline(0, color="black", linestyle="--", linewidth=1)


# -----------------------------
# Final Layout
# -----------------------------
plt.tight_layout()
plt.show()
C:\Users\Anwoy\AppData\Local\Temp\ipykernel_17300\2471159410.py:17: FutureWarning: 

Passing `palette` without assigning `hue` is deprecated and will be removed in v0.14.0. Assign the `x` variable to `hue` and set `legend=False` for the same effect.

  sns.boxplot(
C:\Users\Anwoy\AppData\Local\Temp\ipykernel_17300\2471159410.py:34: FutureWarning: 

Passing `palette` without assigning `hue` is deprecated and will be removed in v0.14.0. Assign the `x` variable to `hue` and set `legend=False` for the same effect.

  sns.boxplot(
C:\Users\Anwoy\AppData\Local\Temp\ipykernel_17300\2471159410.py:50: FutureWarning: 

Passing `palette` without assigning `hue` is deprecated and will be removed in v0.14.0. Assign the `x` variable to `hue` and set `legend=False` for the same effect.

  sns.boxplot(
C:\Users\Anwoy\AppData\Local\Temp\ipykernel_17300\2471159410.py:65: FutureWarning: 

Passing `palette` without assigning `hue` is deprecated and will be removed in v0.14.0. Assign the `x` variable to `hue` and set `legend=False` for the same effect.

  sns.boxplot(

png

Boxplot for Tmin:

season_station = []

for (st, season), g in df.groupby(['Stn_Name', 'season']):

    obs = g['Tmin_bmd']
    sim = g['Tmin_era5']

    season_station.append({
        'Station': st,
        'Season': season,
        'Correlation': corr(obs, sim),
        'RMSE': rmse(obs, sim),
        'MAE': mae(obs, sim),
        'Bias': bias(obs, sim)
    })

# print("Station wise Seasonal Metrics for Tmin:")
df_season_station_Tmin = pd.DataFrame(season_station)

# # pd.set_option('display.max_rows', 500)
# df_season_station_Tmin
season_order = [
    'Winter (DJF)',
    'Pre-monsoon (MAM)',
    'Monsoon (JJAS)',
    'Post-monsoon (ON)'
]

df_season_station_Tmin['Season'] = pd.Categorical(
    df_season_station_Tmin['Season'],
    categories=season_order,
    ordered=True
)
import seaborn as sns
# Set style
sns.set_style("whitegrid")
sns.set_context("talk")   # bigger fonts

# Create figure
fig, axes = plt.subplots(
    nrows=4,
    ncols=1,
    figsize=(10, 12),
    sharex=True
)

# -----------------------------
# 1. Correlation
# -----------------------------
sns.boxplot(
    data=df_season_station_Tmin,
    x="Season",
    y="Correlation",
    ax=axes[0],
    width=0.6,
    showfliers=False,
    palette="Blues"
)

axes[0].set_ylabel("Correlation (r)")
axes[0].set_title("Seasonal Validation of ERA5-Land Tmin", fontsize=16, weight="bold")


# -----------------------------
# 2. RMSE
# -----------------------------
sns.boxplot(
    data=df_season_station_Tmin,
    x="Season",
    y="RMSE",
    ax=axes[1],
    width=0.6,
    showfliers=False,
    palette="Blues"
)

axes[1].set_ylabel("RMSE (°C)")


#---------------------
# 3. MAE
#---------------------
sns.boxplot(
    data=df_season_station_Tmin,
    x="Season",
    y="MAE",
    ax=axes[2],
    width=0.6,
    showfliers=False,
    palette="Blues"
)

axes[2].set_ylabel("MAE (°C)")

# -----------------------------
# 3. Bias
# -----------------------------
sns.boxplot(
    data=df_season_station_Tmin,
    x="Season",
    y="Bias",
    ax=axes[3],
    width=0.6,
    showfliers=False,
    palette="Blues"
)

axes[3].set_ylabel("Bias (°C)")
axes[3].set_xlabel("Season")
# Enable x labels
axes[3].tick_params(labelbottom=True)

# Add zero line for bias
axes[3].axhline(0, color="black", linestyle="--", linewidth=1)


# -----------------------------
# Final Layout
# -----------------------------
plt.tight_layout()
plt.show()
C:\Users\Anwoy\AppData\Local\Temp\ipykernel_17300\2815008242.py:17: FutureWarning: 

Passing `palette` without assigning `hue` is deprecated and will be removed in v0.14.0. Assign the `x` variable to `hue` and set `legend=False` for the same effect.

  sns.boxplot(
C:\Users\Anwoy\AppData\Local\Temp\ipykernel_17300\2815008242.py:34: FutureWarning: 

Passing `palette` without assigning `hue` is deprecated and will be removed in v0.14.0. Assign the `x` variable to `hue` and set `legend=False` for the same effect.

  sns.boxplot(
C:\Users\Anwoy\AppData\Local\Temp\ipykernel_17300\2815008242.py:50: FutureWarning: 

Passing `palette` without assigning `hue` is deprecated and will be removed in v0.14.0. Assign the `x` variable to `hue` and set `legend=False` for the same effect.

  sns.boxplot(
C:\Users\Anwoy\AppData\Local\Temp\ipykernel_17300\2815008242.py:65: FutureWarning: 

Passing `palette` without assigning `hue` is deprecated and will be removed in v0.14.0. Assign the `x` variable to `hue` and set `legend=False` for the same effect.

  sns.boxplot(

png