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)
14:11:20 INFO opendrift:568: OpenDriftSimulation initialised (version 1.14.9 / v1.14.9-43-g22dbf7d)
14:11:20 INFO opendrift.models.basemodel.environment:227: Fallback values will be used for the following variables which have no readers:
14:11:20 INFO opendrift.models.basemodel.environment:230: x_wind: 0.000000
14:11:20 INFO opendrift.models.basemodel.environment:230: y_wind: 0.000000
14:11:20 INFO opendrift:1905: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
14:11:20 INFO opendrift:1905: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
14:11:20 INFO opendrift:2202: 2026-04-16 14:11:19.939212 - step 1 of 48 - 10 active elements (0 deactivated)
14:11:20 INFO opendrift.readers:64: Opening file with xr.open_dataset
14:11:21 INFO opendrift.readers.reader_netCDF_CF_generic:340: Detected dimensions: {'time': ['time', 'time1', 'time2', 'time3'], 'x': 'lon', 'y': 'lat'}
14:11:21 INFO opendrift.readers.basereader:178: Variable x_wind will be rotated from eastward_wind
14:11:21 INFO opendrift.readers.basereader:178: Variable y_wind will be rotated from northward_wind
14:11:21 INFO opendrift:2202: 2026-04-16 15:11:19.939212 - step 2 of 48 - 10 active elements (0 deactivated)
14:11:21 INFO opendrift:2202: 2026-04-16 16:11:19.939212 - step 3 of 48 - 10 active elements (0 deactivated)
14:11:21 INFO opendrift:2202: 2026-04-16 17:11:19.939212 - step 4 of 48 - 10 active elements (0 deactivated)
14:11:21 INFO opendrift:2202: 2026-04-16 18:11:19.939212 - step 5 of 48 - 10 active elements (0 deactivated)
14:11:21 INFO opendrift:2202: 2026-04-16 19:11:19.939212 - step 6 of 48 - 10 active elements (0 deactivated)
14:11:21 INFO opendrift:2202: 2026-04-16 20:11:19.939212 - step 7 of 48 - 10 active elements (0 deactivated)
14:11:21 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`.
14:11:21 INFO opendrift:2202: 2026-04-16 21:11:19.939212 - step 8 of 48 - 10 active elements (0 deactivated)
14:11:22 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`.
14:11:22 INFO opendrift:2202: 2026-04-16 22:11:19.939212 - step 9 of 48 - 10 active elements (0 deactivated)
14:11:22 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`.
14:11:22 INFO opendrift:2202: 2026-04-16 23:11:19.939212 - step 10 of 48 - 10 active elements (0 deactivated)
14:11:22 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`.
14:11:22 INFO opendrift:2202: 2026-04-17 00:11:19.939212 - step 11 of 48 - 10 active elements (0 deactivated)
14:11:22 INFO opendrift:2202: 2026-04-17 01:11:19.939212 - step 12 of 48 - 10 active elements (0 deactivated)
14:11:22 INFO opendrift:2202: 2026-04-17 02:11:19.939212 - step 13 of 48 - 10 active elements (0 deactivated)
14:11:22 INFO opendrift:2202: 2026-04-17 03:11:19.939212 - step 14 of 48 - 10 active elements (0 deactivated)
14:11:22 INFO opendrift:2202: 2026-04-17 04:11:19.939212 - step 15 of 48 - 10 active elements (0 deactivated)
14:11:22 INFO opendrift:2202: 2026-04-17 05:11:19.939212 - step 16 of 48 - 10 active elements (0 deactivated)
14:11:22 INFO opendrift:2202: 2026-04-17 06:11:19.939212 - step 17 of 48 - 10 active elements (0 deactivated)
14:11:22 INFO opendrift:2202: 2026-04-17 07:11:19.939212 - step 18 of 48 - 10 active elements (0 deactivated)
14:11:22 INFO opendrift:2202: 2026-04-17 08:11:19.939212 - step 19 of 48 - 10 active elements (0 deactivated)
14:11:22 INFO opendrift:2202: 2026-04-17 09:11:19.939212 - step 20 of 48 - 10 active elements (0 deactivated)
14:11:22 INFO opendrift:2202: 2026-04-17 10:11:19.939212 - step 21 of 48 - 10 active elements (0 deactivated)
14:11:22 INFO opendrift:2202: 2026-04-17 11:11:19.939212 - step 22 of 48 - 10 active elements (0 deactivated)
14:11:22 INFO opendrift:2202: 2026-04-17 12:11:19.939212 - step 23 of 48 - 10 active elements (0 deactivated)
14:11:23 INFO opendrift:2202: 2026-04-17 13:11:19.939212 - step 24 of 48 - 10 active elements (0 deactivated)
14:11:23 INFO opendrift:2202: 2026-04-17 14:11:19.939212 - step 25 of 48 - 10 active elements (0 deactivated)
14:11:23 INFO opendrift:2202: 2026-04-17 15:11:19.939212 - step 26 of 48 - 10 active elements (0 deactivated)
14:11:23 INFO opendrift:2202: 2026-04-17 16:11:19.939212 - step 27 of 48 - 10 active elements (0 deactivated)
14:11:23 INFO opendrift:2202: 2026-04-17 17:11:19.939212 - step 28 of 48 - 10 active elements (0 deactivated)
14:11:23 INFO opendrift:2202: 2026-04-17 18:11:19.939212 - step 29 of 48 - 10 active elements (0 deactivated)
14:11:23 INFO opendrift:2202: 2026-04-17 19:11:19.939212 - step 30 of 48 - 10 active elements (0 deactivated)
14:11:23 INFO opendrift:2202: 2026-04-17 20:11:19.939212 - step 31 of 48 - 10 active elements (0 deactivated)
14:11:23 INFO opendrift:2202: 2026-04-17 21:11:19.939212 - step 32 of 48 - 10 active elements (0 deactivated)
14:11:23 INFO opendrift:2202: 2026-04-17 22:11:19.939212 - step 33 of 48 - 10 active elements (0 deactivated)
14:11:23 INFO opendrift:2202: 2026-04-17 23:11:19.939212 - step 34 of 48 - 10 active elements (0 deactivated)
14:11:23 INFO opendrift:2202: 2026-04-18 00:11:19.939212 - step 35 of 48 - 10 active elements (0 deactivated)
14:11:23 INFO opendrift:2202: 2026-04-18 01:11:19.939212 - step 36 of 48 - 10 active elements (0 deactivated)
14:11:23 INFO opendrift:2202: 2026-04-18 02:11:19.939212 - step 37 of 48 - 10 active elements (0 deactivated)
14:11:23 INFO opendrift:2202: 2026-04-18 03:11:19.939212 - step 38 of 48 - 10 active elements (0 deactivated)
14:11:23 INFO opendrift:2202: 2026-04-18 04:11:19.939212 - step 39 of 48 - 10 active elements (0 deactivated)
14:11:24 INFO opendrift:2202: 2026-04-18 05:11:19.939212 - step 40 of 48 - 10 active elements (0 deactivated)
14:11:24 INFO opendrift:2202: 2026-04-18 06:11:19.939212 - step 41 of 48 - 10 active elements (0 deactivated)
14:11:24 INFO opendrift:2202: 2026-04-18 07:11:19.939212 - step 42 of 48 - 10 active elements (0 deactivated)
14:11:24 INFO opendrift:2202: 2026-04-18 08:11:19.939212 - step 43 of 48 - 10 active elements (0 deactivated)
14:11:24 INFO opendrift:2202: 2026-04-18 09:11:19.939212 - step 44 of 48 - 10 active elements (0 deactivated)
14:11:24 INFO opendrift:2202: 2026-04-18 10:11:19.939212 - step 45 of 48 - 10 active elements (0 deactivated)
14:11:24 INFO opendrift:2202: 2026-04-18 11:11:19.939212 - step 46 of 48 - 10 active elements (0 deactivated)
14:11:24 INFO opendrift:2202: 2026-04-18 12:11:19.939212 - step 47 of 48 - 10 active elements (0 deactivated)
14:11:24 INFO opendrift:2202: 2026-04-18 13:11:19.939212 - step 48 of 48 - 10 active elements (0 deactivated)
14:11:24 INFO opendrift:568: OpenDriftSimulation initialised (version 1.14.9 / v1.14.9-43-g22dbf7d)
14:11:24 INFO opendrift.models.basemodel.environment:227: Fallback values will be used for the following variables which have no readers:
14:11:24 INFO opendrift.models.basemodel.environment:230: x_wind: 0.000000
14:11:24 INFO opendrift.models.basemodel.environment:230: y_wind: 0.000000
14:11:24 INFO opendrift:1905: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
14:11:24 INFO opendrift:1905: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
14:11:24 INFO opendrift:2202: 2026-04-16 14:11:19.939212 - step 1 of 48 - 10 active elements (0 deactivated)
14:11:24 INFO opendrift.readers:64: Opening file with xr.open_dataset
14:11:26 INFO opendrift.readers.reader_netCDF_CF_generic:340: Detected dimensions: {'time': 'time', 'x': 'longitude', 'y': 'latitude'}
14:11:26 INFO opendrift.readers.basereader:178: Variable x_wind will be rotated from eastward_wind
14:11:26 INFO opendrift.readers.basereader:178: Variable y_wind will be rotated from northward_wind
14:11:27 INFO opendrift:2202: 2026-04-16 15:11:19.939212 - step 2 of 48 - 10 active elements (0 deactivated)
14:11:27 INFO opendrift:2202: 2026-04-16 16:11:19.939212 - step 3 of 48 - 10 active elements (0 deactivated)
14:11:27 INFO opendrift:2202: 2026-04-16 17:11:19.939212 - step 4 of 48 - 10 active elements (0 deactivated)
14:11:27 INFO opendrift:2202: 2026-04-16 18:11:19.939212 - step 5 of 48 - 10 active elements (0 deactivated)
14:11:27 INFO opendrift:2202: 2026-04-16 19:11:19.939212 - step 6 of 48 - 10 active elements (0 deactivated)
14:11:27 INFO opendrift:2202: 2026-04-16 20:11:19.939212 - step 7 of 48 - 10 active elements (0 deactivated)
14:11:27 INFO opendrift:2202: 2026-04-16 21:11:19.939212 - step 8 of 48 - 10 active elements (0 deactivated)
14:11:27 INFO opendrift:2202: 2026-04-16 22:11:19.939212 - step 9 of 48 - 10 active elements (0 deactivated)
14:11:27 INFO opendrift:2202: 2026-04-16 23:11:19.939212 - step 10 of 48 - 10 active elements (0 deactivated)
14:11:27 INFO opendrift:2202: 2026-04-17 00:11:19.939212 - step 11 of 48 - 10 active elements (0 deactivated)
14:11:28 INFO opendrift:2202: 2026-04-17 01:11:19.939212 - step 12 of 48 - 10 active elements (0 deactivated)
14:11:28 INFO opendrift:2202: 2026-04-17 02:11:19.939212 - step 13 of 48 - 10 active elements (0 deactivated)
14:11:28 INFO opendrift:2202: 2026-04-17 03:11:19.939212 - step 14 of 48 - 10 active elements (0 deactivated)
14:11:28 WARNING opendrift.readers.basereader.structured:324: Data block from https://pae-paha.pacioos.hawaii.edu/thredds/dodsC/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd not large enough to cover element positions within timestep. Buffer size (7) must be increased. See `Variables.set_buffer_size`.
14:11:28 INFO opendrift:2202: 2026-04-17 04:11:19.939212 - step 15 of 48 - 10 active elements (0 deactivated)
14:11:28 WARNING opendrift.readers.basereader.structured:324: Data block from https://pae-paha.pacioos.hawaii.edu/thredds/dodsC/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd not large enough to cover element positions within timestep. Buffer size (7) must be increased. See `Variables.set_buffer_size`.
14:11:28 INFO opendrift:2202: 2026-04-17 05:11:19.939212 - step 16 of 48 - 10 active elements (0 deactivated)
14:11:28 WARNING opendrift.readers.basereader.structured:324: Data block from https://pae-paha.pacioos.hawaii.edu/thredds/dodsC/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd not large enough to cover element positions within timestep. Buffer size (7) must be increased. See `Variables.set_buffer_size`.
14:11:28 INFO opendrift:2202: 2026-04-17 06:11:19.939212 - step 17 of 48 - 10 active elements (0 deactivated)
14:11:29 INFO opendrift:2202: 2026-04-17 07:11:19.939212 - step 18 of 48 - 10 active elements (0 deactivated)
14:11:29 INFO opendrift:2202: 2026-04-17 08:11:19.939212 - step 19 of 48 - 10 active elements (0 deactivated)
14:11:29 INFO opendrift:2202: 2026-04-17 09:11:19.939212 - step 20 of 48 - 10 active elements (0 deactivated)
14:11:29 WARNING opendrift.readers.basereader.structured:324: Data block from https://pae-paha.pacioos.hawaii.edu/thredds/dodsC/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd not large enough to cover element positions within timestep. Buffer size (7) must be increased. See `Variables.set_buffer_size`.
14:11:29 INFO opendrift:2202: 2026-04-17 10:11:19.939212 - step 21 of 48 - 10 active elements (0 deactivated)
14:11:29 INFO opendrift:2202: 2026-04-17 11:11:19.939212 - step 22 of 48 - 10 active elements (0 deactivated)
14:11:29 INFO opendrift:2202: 2026-04-17 12:11:19.939212 - step 23 of 48 - 10 active elements (0 deactivated)
14:11:29 INFO opendrift:2202: 2026-04-17 13:11:19.939212 - step 24 of 48 - 10 active elements (0 deactivated)
14:11:29 INFO opendrift:2202: 2026-04-17 14:11:19.939212 - step 25 of 48 - 10 active elements (0 deactivated)
14:11:29 INFO opendrift:2202: 2026-04-17 15:11:19.939212 - step 26 of 48 - 10 active elements (0 deactivated)
14:11:30 INFO opendrift:2202: 2026-04-17 16:11:19.939212 - step 27 of 48 - 10 active elements (0 deactivated)
14:11:30 INFO opendrift:2202: 2026-04-17 17:11:19.939212 - step 28 of 48 - 10 active elements (0 deactivated)
14:11:30 INFO opendrift:2202: 2026-04-17 18:11:19.939212 - step 29 of 48 - 10 active elements (0 deactivated)
14:11:30 INFO opendrift:2202: 2026-04-17 19:11:19.939212 - step 30 of 48 - 10 active elements (0 deactivated)
14:11:30 INFO opendrift:2202: 2026-04-17 20:11:19.939212 - step 31 of 48 - 10 active elements (0 deactivated)
14:11:30 INFO opendrift:2202: 2026-04-17 21:11:19.939212 - step 32 of 48 - 10 active elements (0 deactivated)
14:11:30 INFO opendrift:2202: 2026-04-17 22:11:19.939212 - step 33 of 48 - 10 active elements (0 deactivated)
14:11:30 INFO opendrift:2202: 2026-04-17 23:11:19.939212 - step 34 of 48 - 10 active elements (0 deactivated)
14:11:30 INFO opendrift:2202: 2026-04-18 00:11:19.939212 - step 35 of 48 - 10 active elements (0 deactivated)
14:11:31 INFO opendrift:2202: 2026-04-18 01:11:19.939212 - step 36 of 48 - 10 active elements (0 deactivated)
14:11:31 INFO opendrift:2202: 2026-04-18 02:11:19.939212 - step 37 of 48 - 10 active elements (0 deactivated)
14:11:31 INFO opendrift:2202: 2026-04-18 03:11:19.939212 - step 38 of 48 - 10 active elements (0 deactivated)
14:11:31 INFO opendrift:2202: 2026-04-18 04:11:19.939212 - step 39 of 48 - 10 active elements (0 deactivated)
14:11:31 INFO opendrift:2202: 2026-04-18 05:11:19.939212 - step 40 of 48 - 10 active elements (0 deactivated)
14:11:31 INFO opendrift:2202: 2026-04-18 06:11:19.939212 - step 41 of 48 - 10 active elements (0 deactivated)
14:11:31 INFO opendrift:2202: 2026-04-18 07:11:19.939212 - step 42 of 48 - 10 active elements (0 deactivated)
14:11:31 INFO opendrift:2202: 2026-04-18 08:11:19.939212 - step 43 of 48 - 10 active elements (0 deactivated)
14:11:31 INFO opendrift:2202: 2026-04-18 09:11:19.939212 - step 44 of 48 - 10 active elements (0 deactivated)
14:11:32 INFO opendrift:2202: 2026-04-18 10:11:19.939212 - step 45 of 48 - 10 active elements (0 deactivated)
14:11:32 INFO opendrift:2202: 2026-04-18 11:11:19.939212 - step 46 of 48 - 10 active elements (0 deactivated)
14:11:32 INFO opendrift:2202: 2026-04-18 12:11:19.939212 - step 47 of 48 - 10 active elements (0 deactivated)
14:11:32 INFO opendrift:2202: 2026-04-18 13:11:19.939212 - 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-04-16 14:11 to 2026-04-18 14:11 UTC (49 steps)'}>, <Figure size 609.509x1100 with 1 Axes>)
Total running time of the script: (0 minutes 22.484 seconds)