Note
Go to the end to download the full example code.
Making GRIB dataset CF-compatible
from datetime import datetime, timedelta
from opendrift.models.windblow import WindBlow
Comparing / using two different wind datasets
- The first dataset (UCAR) is a GRIB dataset served by Thredds as a netCDF dataset, but with GRIB attributes
- CF standard_name are added for identified surface variables (wind) with this method:
This should be used with care, making sure that only surface (10m height) variables are used
The second dataset (PACIOOS) is a netCDF4 dataset served by Thredds with CF attributes
wind_datasets = [
'https://thredds.ucar.edu/thredds/dodsC/grib/NCEP/GFS/Global_0p25deg/Best',
'https://pae-paha.pacioos.hawaii.edu/thredds/dodsC/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd'
]
simulations = []
time = datetime.now() - timedelta(days=5)
for wind in wind_datasets:
o = WindBlow(loglevel=20)
o.add_readers_from_list(wind)
o.seed_elements(lon=3, lat=60, time=time, number=10, radius=10000)
o.run(duration=timedelta(hours=48))
simulations.append(o)
13:26:25 INFO opendrift:569: OpenDriftSimulation initialised (version 1.14.10 / v1.14.10-27-gff3ada1)
13:26:25 INFO opendrift.models.basemodel.environment:227: Fallback values will be used for the following variables which have no readers:
13:26:25 INFO opendrift.models.basemodel.environment:230: x_wind: 0.000000
13:26:25 INFO opendrift.models.basemodel.environment:230: y_wind: 0.000000
13:26:25 INFO opendrift:1914: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
13:26:25 INFO opendrift:1914: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
13:26:25 INFO opendrift:2211: 2026-07-09 13:26:24.873974 - step 1 of 48 - 10 active elements (0 deactivated)
13:26:25 INFO opendrift.readers:67: Opening file with xr.open_dataset
13:26:26 INFO opendrift.readers.reader_netCDF_CF_generic:340: Detected dimensions: {'time': ['time', 'time1', 'time2', 'time3'], 'x': 'lon', 'y': 'lat'}
13:26:26 INFO opendrift.readers.basereader:175: Variable x_wind will be rotated from eastward_wind
13:26:26 INFO opendrift.readers.basereader:175: Variable y_wind will be rotated from northward_wind
13:26:26 INFO opendrift:2211: 2026-07-09 14:26:24.873974 - step 2 of 48 - 10 active elements (0 deactivated)
13:26:26 INFO opendrift:2211: 2026-07-09 15:26:24.873974 - step 3 of 48 - 10 active elements (0 deactivated)
13:26:27 INFO opendrift:2211: 2026-07-09 16:26:24.873974 - step 4 of 48 - 10 active elements (0 deactivated)
13:26:27 INFO opendrift:2211: 2026-07-09 17:26:24.873974 - step 5 of 48 - 10 active elements (0 deactivated)
13:26:27 INFO opendrift:2211: 2026-07-09 18:26:24.873974 - step 6 of 48 - 10 active elements (0 deactivated)
13:26:27 INFO opendrift:2211: 2026-07-09 19:26:24.873974 - step 7 of 48 - 10 active elements (0 deactivated)
13:26:27 INFO opendrift:2211: 2026-07-09 20:26:24.873974 - step 8 of 48 - 10 active elements (0 deactivated)
13:26:27 INFO opendrift:2211: 2026-07-09 21:26:24.873974 - step 9 of 48 - 10 active elements (0 deactivated)
13:26:27 INFO opendrift:2211: 2026-07-09 22:26:24.873974 - step 10 of 48 - 10 active elements (0 deactivated)
13:26:27 INFO opendrift:2211: 2026-07-09 23:26:24.873974 - step 11 of 48 - 10 active elements (0 deactivated)
13:26:27 INFO opendrift:2211: 2026-07-10 00:26:24.873974 - step 12 of 48 - 10 active elements (0 deactivated)
13:26:27 INFO opendrift:2211: 2026-07-10 01:26:24.873974 - step 13 of 48 - 10 active elements (0 deactivated)
13:26:27 INFO opendrift:2211: 2026-07-10 02:26:24.873974 - step 14 of 48 - 10 active elements (0 deactivated)
13:26:28 INFO opendrift:2211: 2026-07-10 03:26:24.873974 - step 15 of 48 - 10 active elements (0 deactivated)
13:26:28 INFO opendrift:2211: 2026-07-10 04:26:24.873974 - step 16 of 48 - 10 active elements (0 deactivated)
13:26:28 INFO opendrift:2211: 2026-07-10 05:26:24.873974 - step 17 of 48 - 10 active elements (0 deactivated)
13:26:28 INFO opendrift:2211: 2026-07-10 06:26:24.873974 - step 18 of 48 - 10 active elements (0 deactivated)
13:26:28 INFO opendrift:2211: 2026-07-10 07:26:24.873974 - step 19 of 48 - 10 active elements (0 deactivated)
13:26:28 INFO opendrift:2211: 2026-07-10 08:26:24.873974 - step 20 of 48 - 10 active elements (0 deactivated)
13:26:28 INFO opendrift:2211: 2026-07-10 09:26:24.873974 - step 21 of 48 - 10 active elements (0 deactivated)
13:26:28 INFO opendrift:2211: 2026-07-10 10:26:24.873974 - step 22 of 48 - 10 active elements (0 deactivated)
13:26:28 INFO opendrift:2211: 2026-07-10 11:26:24.873974 - step 23 of 48 - 10 active elements (0 deactivated)
13:26:28 INFO opendrift:2211: 2026-07-10 12:26:24.873974 - step 24 of 48 - 10 active elements (0 deactivated)
13:26:29 INFO opendrift:2211: 2026-07-10 13:26:24.873974 - step 25 of 48 - 10 active elements (0 deactivated)
13:26:29 INFO opendrift:2211: 2026-07-10 14:26:24.873974 - step 26 of 48 - 10 active elements (0 deactivated)
13:26:29 INFO opendrift:2211: 2026-07-10 15:26:24.873974 - step 27 of 48 - 10 active elements (0 deactivated)
13:26:29 INFO opendrift:2211: 2026-07-10 16:26:24.873974 - step 28 of 48 - 10 active elements (0 deactivated)
13:26:29 INFO opendrift:2211: 2026-07-10 17:26:24.873974 - step 29 of 48 - 10 active elements (0 deactivated)
13:26:29 INFO opendrift:2211: 2026-07-10 18:26:24.873974 - step 30 of 48 - 10 active elements (0 deactivated)
13:26:29 INFO opendrift:2211: 2026-07-10 19:26:24.873974 - step 31 of 48 - 10 active elements (0 deactivated)
13:26:29 WARNING opendrift.readers.basereader.structured:324: Data block from https://thredds.ucar.edu/thredds/dodsC/grib/NCEP/GFS/Global_0p25deg/Best not large enough to cover element positions within timestep. Buffer size (12) must be increased. See `Variables.set_buffer_size`.
13:26:29 INFO opendrift:2211: 2026-07-10 20:26:24.873974 - step 32 of 48 - 10 active elements (0 deactivated)
13:26:29 INFO opendrift:2211: 2026-07-10 21:26:24.873974 - step 33 of 48 - 10 active elements (0 deactivated)
13:26:30 WARNING opendrift.readers.basereader.structured:324: Data block from https://thredds.ucar.edu/thredds/dodsC/grib/NCEP/GFS/Global_0p25deg/Best not large enough to cover element positions within timestep. Buffer size (12) must be increased. See `Variables.set_buffer_size`.
13:26:30 INFO opendrift:2211: 2026-07-10 22:26:24.873974 - step 34 of 48 - 10 active elements (0 deactivated)
13:26:30 WARNING opendrift.readers.basereader.structured:324: Data block from https://thredds.ucar.edu/thredds/dodsC/grib/NCEP/GFS/Global_0p25deg/Best not large enough to cover element positions within timestep. Buffer size (12) must be increased. See `Variables.set_buffer_size`.
13:26:30 INFO opendrift:2211: 2026-07-10 23:26:24.873974 - step 35 of 48 - 10 active elements (0 deactivated)
13:26:30 WARNING opendrift.readers.basereader.structured:324: Data block from https://thredds.ucar.edu/thredds/dodsC/grib/NCEP/GFS/Global_0p25deg/Best not large enough to cover element positions within timestep. Buffer size (12) must be increased. See `Variables.set_buffer_size`.
13:26:30 INFO opendrift:2211: 2026-07-11 00:26:24.873974 - step 36 of 48 - 10 active elements (0 deactivated)
13:26:30 INFO opendrift:2211: 2026-07-11 01:26:24.873974 - step 37 of 48 - 10 active elements (0 deactivated)
13:26:30 INFO opendrift:2211: 2026-07-11 02:26:24.873974 - step 38 of 48 - 10 active elements (0 deactivated)
13:26:30 INFO opendrift:2211: 2026-07-11 03:26:24.873974 - step 39 of 48 - 10 active elements (0 deactivated)
13:26:31 INFO opendrift:2211: 2026-07-11 04:26:24.873974 - step 40 of 48 - 10 active elements (0 deactivated)
13:26:31 INFO opendrift:2211: 2026-07-11 05:26:24.873974 - step 41 of 48 - 10 active elements (0 deactivated)
13:26:31 INFO opendrift:2211: 2026-07-11 06:26:24.873974 - step 42 of 48 - 10 active elements (0 deactivated)
13:26:31 INFO opendrift:2211: 2026-07-11 07:26:24.873974 - step 43 of 48 - 10 active elements (0 deactivated)
13:26:31 INFO opendrift:2211: 2026-07-11 08:26:24.873974 - step 44 of 48 - 10 active elements (0 deactivated)
13:26:32 INFO opendrift:2211: 2026-07-11 09:26:24.873974 - step 45 of 48 - 10 active elements (0 deactivated)
13:26:32 INFO opendrift:2211: 2026-07-11 10:26:24.873974 - step 46 of 48 - 10 active elements (0 deactivated)
13:26:32 INFO opendrift:2211: 2026-07-11 11:26:24.873974 - step 47 of 48 - 10 active elements (0 deactivated)
13:26:32 INFO opendrift:2211: 2026-07-11 12:26:24.873974 - step 48 of 48 - 10 active elements (0 deactivated)
13:26:33 INFO opendrift:569: OpenDriftSimulation initialised (version 1.14.10 / v1.14.10-27-gff3ada1)
13:26:33 INFO opendrift.models.basemodel.environment:227: Fallback values will be used for the following variables which have no readers:
13:26:33 INFO opendrift.models.basemodel.environment:230: x_wind: 0.000000
13:26:33 INFO opendrift.models.basemodel.environment:230: y_wind: 0.000000
13:26:33 INFO opendrift:1914: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
13:26:33 INFO opendrift:1914: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
13:26:33 INFO opendrift:2211: 2026-07-09 13:26:24.873974 - step 1 of 48 - 10 active elements (0 deactivated)
13:26:33 INFO opendrift.readers:67: Opening file with xr.open_dataset
13:26:34 INFO opendrift.readers.reader_netCDF_CF_generic:340: Detected dimensions: {'time': 'time', 'x': 'longitude', 'y': 'latitude'}
13:26:34 INFO opendrift.readers.basereader:175: Variable x_wind will be rotated from eastward_wind
13:26:34 INFO opendrift.readers.basereader:175: Variable y_wind will be rotated from northward_wind
13:26:35 INFO opendrift:2211: 2026-07-09 14:26:24.873974 - step 2 of 48 - 10 active elements (0 deactivated)
13:26:35 INFO opendrift:2211: 2026-07-09 15:26:24.873974 - step 3 of 48 - 10 active elements (0 deactivated)
13:26:35 INFO opendrift:2211: 2026-07-09 16:26:24.873974 - step 4 of 48 - 10 active elements (0 deactivated)
13:26:35 INFO opendrift:2211: 2026-07-09 17:26:24.873974 - step 5 of 48 - 10 active elements (0 deactivated)
13:26:35 INFO opendrift:2211: 2026-07-09 18:26:24.873974 - step 6 of 48 - 10 active elements (0 deactivated)
13:26:36 INFO opendrift:2211: 2026-07-09 19:26:24.873974 - step 7 of 48 - 10 active elements (0 deactivated)
13:26:36 INFO opendrift:2211: 2026-07-09 20:26:24.873974 - step 8 of 48 - 10 active elements (0 deactivated)
13:26:36 INFO opendrift:2211: 2026-07-09 21:26:24.873974 - step 9 of 48 - 10 active elements (0 deactivated)
13:26:36 INFO opendrift:2211: 2026-07-09 22:26:24.873974 - step 10 of 48 - 10 active elements (0 deactivated)
13:26:36 INFO opendrift:2211: 2026-07-09 23:26:24.873974 - step 11 of 48 - 10 active elements (0 deactivated)
13:26:36 INFO opendrift:2211: 2026-07-10 00:26:24.873974 - step 12 of 48 - 10 active elements (0 deactivated)
13:26:36 INFO opendrift:2211: 2026-07-10 01:26:24.873974 - step 13 of 48 - 10 active elements (0 deactivated)
13:26:36 INFO opendrift:2211: 2026-07-10 02:26:24.873974 - step 14 of 48 - 10 active elements (0 deactivated)
13:26:36 INFO opendrift:2211: 2026-07-10 03:26:24.873974 - step 15 of 48 - 10 active elements (0 deactivated)
13:26:36 INFO opendrift:2211: 2026-07-10 04:26:24.873974 - step 16 of 48 - 10 active elements (0 deactivated)
13:26:36 INFO opendrift:2211: 2026-07-10 05:26:24.873974 - step 17 of 48 - 10 active elements (0 deactivated)
13:26:37 INFO opendrift:2211: 2026-07-10 06:26:24.873974 - step 18 of 48 - 10 active elements (0 deactivated)
13:26:37 INFO opendrift:2211: 2026-07-10 07:26:24.873974 - step 19 of 48 - 10 active elements (0 deactivated)
13:26:37 INFO opendrift:2211: 2026-07-10 08:26:24.873974 - step 20 of 48 - 10 active elements (0 deactivated)
13:26:37 INFO opendrift:2211: 2026-07-10 09:26:24.873974 - step 21 of 48 - 10 active elements (0 deactivated)
13:26:37 INFO opendrift:2211: 2026-07-10 10:26:24.873974 - step 22 of 48 - 10 active elements (0 deactivated)
13:26:37 INFO opendrift:2211: 2026-07-10 11:26:24.873974 - step 23 of 48 - 10 active elements (0 deactivated)
13:26:37 INFO opendrift:2211: 2026-07-10 12:26:24.873974 - step 24 of 48 - 10 active elements (0 deactivated)
13:26:37 INFO opendrift:2211: 2026-07-10 13:26:24.873974 - step 25 of 48 - 10 active elements (0 deactivated)
13:26:37 INFO opendrift:2211: 2026-07-10 14:26:24.873974 - step 26 of 48 - 10 active elements (0 deactivated)
13:26:37 INFO opendrift:2211: 2026-07-10 15:26:24.873974 - step 27 of 48 - 10 active elements (0 deactivated)
13:26:38 INFO opendrift:2211: 2026-07-10 16:26:24.873974 - step 28 of 48 - 10 active elements (0 deactivated)
13:26:38 INFO opendrift:2211: 2026-07-10 17:26:24.873974 - step 29 of 48 - 10 active elements (0 deactivated)
13:26:38 INFO opendrift:2211: 2026-07-10 18:26:24.873974 - step 30 of 48 - 10 active elements (0 deactivated)
13:26:38 INFO opendrift:2211: 2026-07-10 19:26:24.873974 - step 31 of 48 - 10 active elements (0 deactivated)
13:26:38 INFO opendrift:2211: 2026-07-10 20:26:24.873974 - step 32 of 48 - 10 active elements (0 deactivated)
13:26:38 INFO opendrift:2211: 2026-07-10 21:26:24.873974 - step 33 of 48 - 10 active elements (0 deactivated)
13:26:38 INFO opendrift:2211: 2026-07-10 22:26:24.873974 - step 34 of 48 - 10 active elements (0 deactivated)
13:26:38 INFO opendrift:2211: 2026-07-10 23:26:24.873974 - step 35 of 48 - 10 active elements (0 deactivated)
13:26:38 INFO opendrift:2211: 2026-07-11 00:26:24.873974 - step 36 of 48 - 10 active elements (0 deactivated)
13:26:39 INFO opendrift:2211: 2026-07-11 01:26:24.873974 - step 37 of 48 - 10 active elements (0 deactivated)
13:26:39 INFO opendrift:2211: 2026-07-11 02:26:24.873974 - step 38 of 48 - 10 active elements (0 deactivated)
13:26:39 INFO opendrift:2211: 2026-07-11 03:26:24.873974 - step 39 of 48 - 10 active elements (0 deactivated)
13:26:39 INFO opendrift:2211: 2026-07-11 04:26:24.873974 - step 40 of 48 - 10 active elements (0 deactivated)
13:26:39 INFO opendrift:2211: 2026-07-11 05:26:24.873974 - step 41 of 48 - 10 active elements (0 deactivated)
13:26:39 INFO opendrift:2211: 2026-07-11 06:26:24.873974 - step 42 of 48 - 10 active elements (0 deactivated)
13:26:39 INFO opendrift:2211: 2026-07-11 07:26:24.873974 - step 43 of 48 - 10 active elements (0 deactivated)
13:26:39 INFO opendrift:2211: 2026-07-11 08:26:24.873974 - step 44 of 48 - 10 active elements (0 deactivated)
13:26:39 INFO opendrift:2211: 2026-07-11 09:26:24.873974 - step 45 of 48 - 10 active elements (0 deactivated)
13:26:40 INFO opendrift:2211: 2026-07-11 10:26:24.873974 - step 46 of 48 - 10 active elements (0 deactivated)
13:26:40 INFO opendrift:2211: 2026-07-11 11:26:24.873974 - step 47 of 48 - 10 active elements (0 deactivated)
13:26:40 INFO opendrift:2211: 2026-07-11 12:26:24.873974 - step 48 of 48 - 10 active elements (0 deactivated)
Some differences are expected as datasets may origin from different runs
simulations[0].plot(compare=simulations[1:], lscale='i', legend=['GRIB converted', 'netCDF CF compatible'])

(<GeoAxes: title={'center': 'OpenDrift - WindBlow\n2026-07-09 13:26 to 2026-07-11 13:26 UTC (49 steps)'}>, <Figure size 940.177x1100 with 1 Axes>)
Total running time of the script: (0 minutes 28.415 seconds)