ECMWF Realtime Data Visualization
This notebook analyzes and displays data from the most recent 0000 / 1200 UTC runs of the ECMWF’s Integrated Forecast System (IFS) and Artificial Intelligence/Integrated Forecasting System (AIFS) numerical weather prediction model output.
Overview¶
In this notebook, we will read in real-time numerical weather prediction data in GRIB format and visualize some output in the form of time series at a specific location. We will also apply the datetime library to dynamically determine the date and time of the most recently-complete model run.¶
Imports¶
import xarray as xr
import numpy as np
import pandas as pd
import cartopy.feature as cfeature
import cartopy.crs as ccrs
import cartopy.util as cutil
from datetime import datetime, timedelta
from time import strftime, strptime, gmtime
import metpy.calc as mpcalc
from metpy.units import units
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter, AutoDateLocator,HourLocator,DayLocator,MonthLocator
import cfgrib
import seaborn as sns
import warningsSuppress any warning messages from cells that follow. While they can be useful, they clutter up the output.
warnings.filterwarnings("ignore") Invoke Seaborn’s default setting, which is especially nice for improving the look of time-series plots.
sns.set()Parse the current time and choose a recent hour when we might expect our Dataset to be available.¶
currHour = strftime("%H",gmtime()).zfill(2)
currMin = strftime("%M",gmtime())
currDate = strftime("%Y%m%d",gmtime())
currTime = datetime(int(currDate[0:4]),int(currDate[4:6]),int(currDate[6:8]),int(currHour))
if (int(currHour) >= 21) :
model_hour = "12"
hr_delta = int(currHour) - 12
elif (int (currHour) >= 9):
model_hour = "00"
hr_delta = int(currHour)
else:
model_hour = "12"
hr_delta = int(currHour) + 12
modelInit = currTime - timedelta(hours=hr_delta)
print (modelInit)
modelDateStr = modelInit.strftime('%Y%m%d')
modelDateTimeStr = modelInit.strftime('%Y%m%d%H')
print (modelDateTimeStr)2025-10-02 00:00:00
2025100200
Set the file names and the directory path of the two datasets.
dirPath = '/data7/ecmwf/'
IFS_grib = f'{dirPath}{modelDateTimeStr}_ec.grib2'
AIFS_grib = f'{dirPath}{modelDateTimeStr}_aifs.grib2'/data7/ecmwf directory and modify the modelDateTimeStr string to fit another time that may be available. There will be a seven-day archive in this directory.
Open the data files (it may take a minute or two)
cfgrib engine ... analogous to how Xarray opens a NetCDF file using its netcdf engine.filter_by_keys and returns a list of all valid xarray.Dataset`'s in the GRIB file. Instead of returning a single Xarray Dataset, it will return a list of Datasets.%%time
ds_aifs = cfgrib.open_datasets(AIFS_grib)
ds_ifs = cfgrib.open_datasets(IFS_grib)CPU times: user 4.14 s, sys: 466 ms, total: 4.61 s
Wall time: 5.43 s
What datasets are within each of the two lists? Let’s take advantage of Python’s enumerate function.¶
for n, ds in enumerate(ds_ifs):
print('')
print('*****Individual datasets within IFS*****')
print('')
print(f'Dataset {n}')
print(ds)
*****Individual datasets within IFS*****
Dataset 0
<xarray.Dataset> Size: 341MB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 days...
entireAtmosphere float64 8B 0.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B 2025-10-02 ... 2025-10-12
Data variables:
tcw (step, latitude, longitude) float32 170MB ...
tcwv (step, latitude, longitude) float32 170MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within IFS*****
Dataset 1
<xarray.Dataset> Size: 511MB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 day...
heightAboveGround float64 8B 10.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B 2025-10-02 ... 2025-10-12
Data variables:
u10 (step, latitude, longitude) float32 170MB ...
v10 (step, latitude, longitude) float32 170MB ...
max_i10fg (step, latitude, longitude) float32 170MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within IFS*****
Dataset 2
<xarray.Dataset> Size: 341MB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 day...
heightAboveGround float64 8B 2.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B 2025-10-02 ... 2025-10-12
Data variables:
t2m (step, latitude, longitude) float32 170MB ...
d2m (step, latitude, longitude) float32 170MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within IFS*****
Dataset 3
<xarray.Dataset> Size: 341MB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 day...
heightAboveGround float64 8B 100.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B 2025-10-02 ... 2025-10-12
Data variables:
u100 (step, latitude, longitude) float32 170MB ...
v100 (step, latitude, longitude) float32 170MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within IFS*****
Dataset 4
<xarray.Dataset> Size: 170MB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 03:00:00 ... 10 day...
heightAboveGround float64 8B 2.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B 2025-10-02T03:00:00 ... 202...
Data variables:
t2m (step, latitude, longitude) float32 170MB 0.0 ... 221.8
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within IFS*****
Dataset 5
<xarray.Dataset> Size: 170MB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 03:00:00 ... 10 day...
heightAboveGround float64 8B 2.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B 2025-10-02T03:00:00 ... 202...
Data variables:
t2m (step, latitude, longitude) float32 170MB 0.0 ... 221.2
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within IFS*****
Dataset 6
<xarray.Dataset> Size: 20GB
Dimensions: (step: 41, isobaricInhPa: 13, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 days 00...
* isobaricInhPa (isobaricInhPa) float64 104B 1e+03 925.0 850.0 ... 100.0 50.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.5 -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 -179.5 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B 2025-10-02 ... 2025-10-12
Data variables:
t (step, isobaricInhPa, latitude, longitude) float32 2GB ...
u (step, isobaricInhPa, latitude, longitude) float32 2GB ...
v (step, isobaricInhPa, latitude, longitude) float32 2GB ...
q (step, isobaricInhPa, latitude, longitude) float32 2GB ...
w (step, isobaricInhPa, latitude, longitude) float32 2GB ...
vo (step, isobaricInhPa, latitude, longitude) float32 2GB ...
d (step, isobaricInhPa, latitude, longitude) float32 2GB ...
gh (step, isobaricInhPa, latitude, longitude) float32 2GB ...
r (step, isobaricInhPa, latitude, longitude) float32 2GB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within IFS*****
Dataset 7
<xarray.Dataset> Size: 170MB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 days 00:00:00
meanSea float64 8B 0.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.5 -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 -179.5 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B ...
Data variables:
msl (step, latitude, longitude) float32 170MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within IFS*****
Dataset 8
<xarray.Dataset> Size: 170MB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 da...
mostUnstableParcel float64 8B 0.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B ...
Data variables:
mucape (step, latitude, longitude) float32 170MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within IFS*****
Dataset 9
<xarray.Dataset> Size: 170MB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 days 00:00:00
nominalTop float64 8B 0.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.5 -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 -179.5 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B ...
Data variables:
ttr (step, latitude, longitude) float32 170MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within IFS*****
Dataset 10
<xarray.Dataset> Size: 1GB
Dimensions: (step: 41, soilLayer: 4, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 days 00:00:00
* soilLayer (soilLayer) float64 32B 1.0 2.0 3.0 4.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.5 -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 -179.5 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B 2025-10-02 ... 2025-10-12
Data variables:
vsw (step, soilLayer, latitude, longitude) float32 681MB ...
sot (step, soilLayer, latitude, longitude) float32 681MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within IFS*****
Dataset 11
<xarray.Dataset> Size: 3GB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 days 00:00:00
surface float64 8B 0.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.5 -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 -179.5 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B 2025-10-02 ... 2025-10-12
Data variables: (12/18)
asn (step, latitude, longitude) float32 170MB ...
sp (step, latitude, longitude) float32 170MB ...
ssrd (step, latitude, longitude) float32 170MB ...
lsm (step, latitude, longitude) float32 170MB ...
strd (step, latitude, longitude) float32 170MB ...
ssr (step, latitude, longitude) float32 170MB ...
... ...
ptype (step, latitude, longitude) float32 170MB ...
tprate (step, latitude, longitude) float32 170MB ...
sithick (step, latitude, longitude) float32 170MB ...
zos (step, latitude, longitude) float32 170MB ...
svn (step, latitude, longitude) float32 170MB ...
sve (step, latitude, longitude) float32 170MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within IFS*****
Dataset 12
<xarray.Dataset> Size: 12MB
Dimensions: (latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
step timedelta64[ns] 8B 00:00:00
surface float64 8B 0.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.5 -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 -179.5 ... 179.5 179.8
valid_time datetime64[ns] 8B 2025-10-02
Data variables:
z (latitude, longitude) float32 4MB ...
sdor (latitude, longitude) float32 4MB ...
slor (latitude, longitude) float32 4MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
for n, ds in enumerate(ds_aifs):
print('')
print('*****Individual datasets within AIFS*****')
print('')
print(f'Dataset {n}')
print(ds)
*****Individual datasets within AIFS*****
Dataset 0
<xarray.Dataset> Size: 341MB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 days...
entireAtmosphere float64 8B 0.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B 2025-10-02 ... 2025-10-12
Data variables:
tcw (step, latitude, longitude) float32 170MB ...
tcc (step, latitude, longitude) float32 170MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within AIFS*****
Dataset 1
<xarray.Dataset> Size: 341MB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 day...
heightAboveGround float64 8B 10.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B 2025-10-02 ... 2025-10-12
Data variables:
u10 (step, latitude, longitude) float32 170MB ...
v10 (step, latitude, longitude) float32 170MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within AIFS*****
Dataset 2
<xarray.Dataset> Size: 341MB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 day...
heightAboveGround float64 8B 2.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B 2025-10-02 ... 2025-10-12
Data variables:
t2m (step, latitude, longitude) float32 170MB ...
d2m (step, latitude, longitude) float32 170MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within AIFS*****
Dataset 3
<xarray.Dataset> Size: 341MB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 day...
heightAboveGround float64 8B 100.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B 2025-10-02 ... 2025-10-12
Data variables:
u100 (step, latitude, longitude) float32 170MB ...
v100 (step, latitude, longitude) float32 170MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within AIFS*****
Dataset 4
<xarray.Dataset> Size: 170MB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 days 0...
highCloudLayer float64 8B 450.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B ...
Data variables:
hcc (step, latitude, longitude) float32 170MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within AIFS*****
Dataset 5
<xarray.Dataset> Size: 13GB
Dimensions: (step: 41, isobaricInhPa: 13, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 days 00...
* isobaricInhPa (isobaricInhPa) float64 104B 1e+03 925.0 850.0 ... 100.0 50.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.5 -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 -179.5 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B 2025-10-02 ... 2025-10-12
Data variables:
z (step, isobaricInhPa, latitude, longitude) float32 2GB ...
t (step, isobaricInhPa, latitude, longitude) float32 2GB ...
u (step, isobaricInhPa, latitude, longitude) float32 2GB ...
v (step, isobaricInhPa, latitude, longitude) float32 2GB ...
q (step, isobaricInhPa, latitude, longitude) float32 2GB ...
w (step, isobaricInhPa, latitude, longitude) float32 2GB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within AIFS*****
Dataset 6
<xarray.Dataset> Size: 170MB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 days 00...
lowCloudLayer float64 8B 0.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.5 -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 -179.5 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B ...
Data variables:
lcc (step, latitude, longitude) float32 170MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within AIFS*****
Dataset 7
<xarray.Dataset> Size: 170MB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 days 00:00:00
meanSea float64 8B 0.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.5 -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 -179.5 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B ...
Data variables:
msl (step, latitude, longitude) float32 170MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within AIFS*****
Dataset 8
<xarray.Dataset> Size: 170MB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 days...
mediumCloudLayer float64 8B 800.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B ...
Data variables:
mcc (step, latitude, longitude) float32 170MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within AIFS*****
Dataset 9
<xarray.Dataset> Size: 681MB
Dimensions: (step: 41, soilLayer: 2, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 days 00:00:00
* soilLayer (soilLayer) float64 16B 1.0 2.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.5 -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 -179.5 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B 2025-10-02 ... 2025-10-12
Data variables:
vsw (step, soilLayer, latitude, longitude) float32 341MB ...
sot (step, soilLayer, latitude, longitude) float32 341MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within AIFS*****
Dataset 10
<xarray.Dataset> Size: 17MB
Dimensions: (latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
step timedelta64[ns] 8B 00:00:00
surface float64 8B 0.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.5 -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 -179.5 ... 179.5 179.8
valid_time datetime64[ns] 8B 2025-10-02
Data variables:
z (latitude, longitude) float32 4MB ...
sdor (latitude, longitude) float32 4MB ...
slor (latitude, longitude) float32 4MB ...
lsm (latitude, longitude) float32 4MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
*****Individual datasets within AIFS*****
Dataset 11
<xarray.Dataset> Size: 1GB
Dimensions: (step: 41, latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] 8B 2025-10-02
* step (step) timedelta64[ns] 328B 0 days 00:00:00 ... 10 days 00:00:00
surface float64 8B 0.0
* latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.5 -89.75 -90.0
* longitude (longitude) float64 12kB -180.0 -179.8 -179.5 ... 179.5 179.8
valid_time (step) datetime64[ns] 328B 2025-10-02 ... 2025-10-12
Data variables:
sp (step, latitude, longitude) float32 170MB ...
ssrd (step, latitude, longitude) float32 170MB ...
strd (step, latitude, longitude) float32 170MB ...
skt (step, latitude, longitude) float32 170MB ...
cp (step, latitude, longitude) float32 170MB ...
sf (step, latitude, longitude) float32 170MB ...
tp (step, latitude, longitude) float32 170MB ...
rowe (step, latitude, longitude) float32 170MB ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
Examine the number of time steps in each of the two models (we can safely assume this won’t vary per model within the individual datasets, but due to occasional gaps in our retrieval of these model runs, it’s possible that the number of time steps in the AIFS might not equal that of the IFS. If so, the resulting time series plots will not be generated properly.
aifs_tsteps = ds_aifs[0].step.size
ifs_tsteps = ds_ifs[0].step.size
print (aifs_tsteps, ifs_tsteps)
try:
assert aifs_tsteps == ifs_tsteps
except:
print("Number of time steps between the two models are not equal. There likely was a problem retrieving the GRIB files at some point. Try again when the next model run has completed.")41 41
Compare the two runs for two different variables. We’ll choose 2 meter temperature and total accumulated precipitation and create Xarray DataArray objects for each of them.
t2m_ifs, t2m_aifs = ds_ifs[2].t2m, ds_aifs[2].t2m
tp_ifs, tp_aifs = ds_ifs[11].tp, ds_aifs[11].tpExamine one of the DataArrays
t2m_aifsCreate an object to represent the array of valid date and times, which we’ll use as the x-axis in the time series plots. Examine that object. It’s just another DataArray, this time for one of the coordinates.
valTimes = t2m_ifs.valid_time # This will be the same regardless of what meteorological parameters we selected
valTimesThese already have a datetime class of datatype (dtype), not merely a set of strings, so they will render nicely on the time axis in the upcoming plots.
Specify a latitude and longitude in degrees. Recall that positive (negative) values of latitude and longitude correspond to north (south) and east (west).
lat, lon = 42.7, -73.8 # ALB airportCreate a well-labeled time series for the two parameters of interest.¶
tmpc_i = t2m_ifs.sel(latitude=lat, longitude=lon, method='nearest').metpy.convert_units('degC')
tmpc_a= t2m_aifs.sel(latitude=lat, longitude=lon, method='nearest').metpy.convert_units('degC')
fig, ax = plt.subplots(figsize=(15,10))
ax.plot (valTimes, tmpc_i, color='blue', marker='+',label = "IFS")
ax.plot (valTimes, tmpc_a, color='purple', marker='+',label = "AIFS")
ax.set_title (f"ECMWF 2m Temperature °C at {lat}N {lon}E")
ax.set_xlabel('Date')
ax.set_ylabel('Temperature (°C)' )
ax.xaxis.set_major_locator(HourLocator(interval=12))
dateFmt = DateFormatter('%d %H')
ax.xaxis.set_major_formatter(dateFmt)
ax.legend (loc="best");
qpf_i = tp_ifs.sel(latitude=lat, longitude=lon, method='nearest').metpy.convert_units('mm')
qpf_a= tp_aifs.sel(latitude=lat, longitude=lon, method='nearest')
fig, ax = plt.subplots(figsize=(15,10))
ax.plot (valTimes, qpf_i, color='blue', marker='+',label = "IFS")
ax.plot (valTimes, qpf_a, color='purple', marker='+',label = "AIFS")
ax.set_title (f"ECMWF Accumulated Precip (mm) at {lat}N {lon}E")
ax.set_xlabel('Date')
ax.set_ylabel('QPF (mm)' )
ax.xaxis.set_major_locator(HourLocator(interval=12))
dateFmt = DateFormatter('%d %H')
ax.xaxis.set_major_formatter(dateFmt)
ax.legend (loc="best");
Select a different location. Consider adding the name of that location (e.g. ALB International Airport, Albany NY) to the title.
Select different parameters, but be sure they are represented in both IFS and AIFS output.
Explore parameters that are unique to each model.
Examine the units attribute of each parameter. Try using MetPy to perform unit conversions.
ADVANCED A similar set of GRIB-formatted model output, from NOAA's Global Forecast System (GFS), can be found in
/data7/gfs. Read in that data and create time series plots from parameters of interest to you. If you can determine which GFS variable is equivalent to that of ECMWF's, add that to your time series so one can compare all three model forecasts!