Note
Go to the end to download the full example code.
Drift at different depths
from datetime import datetime, timedelta
import numpy as np
from opendrift.models.oceandrift import OceanDrift
o = OceanDrift(loglevel=20) # Set loglevel to 0 for debug information
17:21:28 INFO opendrift.models.basemodel:512: OpenDriftSimulation initialised (version 1.12.0 / v1.12.0-55-g4faa301)
Using live data from Thredds
o.add_readers_from_list([
'https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be'])
Adding some diffusion
o.set_config('drift:horizontal_diffusivity', 10) # m2/s
Seed 1000 elements at random depths
z = -np.random.rand(2000)*50
o.seed_elements(lon=4.8, lat=60.0, z=z, radius=0, number=2000,
time=datetime.utcnow())
print(o)
17:21:28 INFO opendrift.models.basemodel.environment:218: Adding a dynamical landmask with max. priority based on assumed maximum speed of 2.0 m/s. Adding a customised landmask may be faster...
17:21:31 INFO opendrift.models.basemodel.environment:245: Fallback values will be used for the following variables which have no readers:
17:21:31 INFO opendrift.models.basemodel.environment:248: x_sea_water_velocity: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: y_sea_water_velocity: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: sea_surface_height: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: x_wind: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: y_wind: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: upward_sea_water_velocity: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: ocean_vertical_diffusivity: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_significant_height: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_stokes_drift_x_velocity: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_stokes_drift_y_velocity: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_to_direction: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_peak_period_from_variance_spectral_density: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_significant_height: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_to_direction: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_mean_period: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_significant_height: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: surface_downward_x_stress: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: surface_downward_y_stress: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: turbulent_kinetic_energy: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: turbulent_generic_length_scale: 0.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: ocean_mixed_layer_thickness: 50.000000
17:21:31 INFO opendrift.models.basemodel.environment:248: sea_floor_depth_below_sea_level: 10000.000000
===========================
Model: OceanDrift (OpenDrift version 1.12.0)
0 active Lagrangian3DArray particles (0 deactivated, 2000 scheduled)
-------------------
Environment variables:
-----
land_binary_mask
1) global_landmask
-----
Readers not added for the following variables:
ocean_mixed_layer_thickness
ocean_vertical_diffusivity
sea_floor_depth_below_sea_level
sea_surface_height
sea_surface_swell_wave_peak_period_from_variance_spectral_density
sea_surface_swell_wave_significant_height
sea_surface_swell_wave_to_direction
sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment
sea_surface_wave_period_at_variance_spectral_density_maximum
sea_surface_wave_significant_height
sea_surface_wave_stokes_drift_x_velocity
sea_surface_wave_stokes_drift_y_velocity
sea_surface_wind_wave_mean_period
sea_surface_wind_wave_significant_height
sea_surface_wind_wave_to_direction
surface_downward_x_stress
surface_downward_y_stress
turbulent_generic_length_scale
turbulent_kinetic_energy
upward_sea_water_velocity
x_sea_water_velocity
x_wind
y_sea_water_velocity
y_wind
---
Lazy readers:
LazyReader: https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
Discarded readers:
===========================
Running model
o.run(duration=timedelta(hours=24), time_step=1800)
17:21:32 INFO opendrift.models.basemodel:932: Using existing reader for land_binary_mask
17:21:32 INFO opendrift.models.basemodel:943: All points are in ocean
17:21:32 INFO opendrift.models.basemodel:2032: 2025-01-14 17:21:28.693840 - step 1 of 48 - 2000 active elements (0 deactivated)
17:21:32 INFO opendrift.readers:58: Opening file with xr.open_dataset
17:21:38 INFO opendrift.readers.reader_netCDF_CF_generic:338: Detected dimensions: {'x': 'X', 'y': 'Y', 'z': 'depth', 'time': 'time'}
17:21:41 INFO opendrift.models.basemodel:2032: 2025-01-14 17:51:28.693840 - step 2 of 48 - 2000 active elements (0 deactivated)
17:21:41 INFO opendrift.models.basemodel:2032: 2025-01-14 18:21:28.693840 - step 3 of 48 - 2000 active elements (0 deactivated)
17:21:42 INFO opendrift.models.basemodel:2032: 2025-01-14 18:51:28.693840 - step 4 of 48 - 2000 active elements (0 deactivated)
17:21:43 INFO opendrift.models.basemodel:2032: 2025-01-14 19:21:28.693840 - step 5 of 48 - 2000 active elements (0 deactivated)
17:21:44 INFO opendrift.models.basemodel:2032: 2025-01-14 19:51:28.693840 - step 6 of 48 - 2000 active elements (0 deactivated)
17:21:44 INFO opendrift.models.basemodel:2032: 2025-01-14 20:21:28.693840 - step 7 of 48 - 2000 active elements (0 deactivated)
17:21:46 INFO opendrift.models.basemodel:2032: 2025-01-14 20:51:28.693840 - step 8 of 48 - 2000 active elements (0 deactivated)
17:21:46 INFO opendrift.models.basemodel:2032: 2025-01-14 21:21:28.693840 - step 9 of 48 - 2000 active elements (0 deactivated)
17:21:48 INFO opendrift.models.basemodel:2032: 2025-01-14 21:51:28.693840 - step 10 of 48 - 2000 active elements (0 deactivated)
17:21:48 INFO opendrift.models.basemodel:2032: 2025-01-14 22:21:28.693840 - step 11 of 48 - 2000 active elements (0 deactivated)
17:21:49 INFO opendrift.models.basemodel:2032: 2025-01-14 22:51:28.693840 - step 12 of 48 - 2000 active elements (0 deactivated)
17:21:49 INFO opendrift.models.basemodel:2032: 2025-01-14 23:21:28.693840 - step 13 of 48 - 2000 active elements (0 deactivated)
17:21:51 INFO opendrift.models.basemodel:2032: 2025-01-14 23:51:28.693840 - step 14 of 48 - 2000 active elements (0 deactivated)
17:21:51 INFO opendrift.models.basemodel:2032: 2025-01-15 00:21:28.693840 - step 15 of 48 - 2000 active elements (0 deactivated)
17:21:52 INFO opendrift.models.basemodel:2032: 2025-01-15 00:51:28.693840 - step 16 of 48 - 2000 active elements (0 deactivated)
17:21:52 INFO opendrift.models.basemodel:2032: 2025-01-15 01:21:28.693840 - step 17 of 48 - 2000 active elements (0 deactivated)
17:21:53 INFO opendrift.models.basemodel:2032: 2025-01-15 01:51:28.693840 - step 18 of 48 - 2000 active elements (0 deactivated)
17:21:54 INFO opendrift.models.basemodel:2032: 2025-01-15 02:21:28.693840 - step 19 of 48 - 2000 active elements (0 deactivated)
17:21:55 INFO opendrift.models.basemodel:2032: 2025-01-15 02:51:28.693840 - step 20 of 48 - 2000 active elements (0 deactivated)
17:21:55 INFO opendrift.models.basemodel:2032: 2025-01-15 03:21:28.693840 - step 21 of 48 - 2000 active elements (0 deactivated)
17:21:57 INFO opendrift.models.basemodel:2032: 2025-01-15 03:51:28.693840 - step 22 of 48 - 2000 active elements (0 deactivated)
17:21:57 INFO opendrift.models.basemodel:2032: 2025-01-15 04:21:28.693840 - step 23 of 48 - 2000 active elements (0 deactivated)
17:21:59 INFO opendrift.models.basemodel:2032: 2025-01-15 04:51:28.693840 - step 24 of 48 - 2000 active elements (0 deactivated)
17:21:59 INFO opendrift.models.basemodel:2032: 2025-01-15 05:21:28.693840 - step 25 of 48 - 2000 active elements (0 deactivated)
17:22:01 INFO opendrift.models.basemodel:2032: 2025-01-15 05:51:28.693840 - step 26 of 48 - 2000 active elements (0 deactivated)
17:22:01 INFO opendrift.models.basemodel:2032: 2025-01-15 06:21:28.693840 - step 27 of 48 - 2000 active elements (0 deactivated)
17:22:02 INFO opendrift.models.basemodel:2032: 2025-01-15 06:51:28.693840 - step 28 of 48 - 2000 active elements (0 deactivated)
17:22:02 INFO opendrift.models.basemodel:2032: 2025-01-15 07:21:28.693840 - step 29 of 48 - 2000 active elements (0 deactivated)
17:22:04 INFO opendrift.models.basemodel:2032: 2025-01-15 07:51:28.693840 - step 30 of 48 - 2000 active elements (0 deactivated)
17:22:04 INFO opendrift.models.basemodel:2032: 2025-01-15 08:21:28.693840 - step 31 of 48 - 2000 active elements (0 deactivated)
17:22:05 INFO opendrift.models.basemodel:2032: 2025-01-15 08:51:28.693840 - step 32 of 48 - 2000 active elements (0 deactivated)
17:22:05 INFO opendrift.models.basemodel:2032: 2025-01-15 09:21:28.693840 - step 33 of 48 - 2000 active elements (0 deactivated)
17:22:07 INFO opendrift.models.basemodel:2032: 2025-01-15 09:51:28.693840 - step 34 of 48 - 2000 active elements (0 deactivated)
17:22:07 INFO opendrift.models.basemodel:2032: 2025-01-15 10:21:28.693840 - step 35 of 48 - 2000 active elements (0 deactivated)
17:22:09 INFO opendrift.models.basemodel:2032: 2025-01-15 10:51:28.693840 - step 36 of 48 - 2000 active elements (0 deactivated)
17:22:09 INFO opendrift.models.basemodel:2032: 2025-01-15 11:21:28.693840 - step 37 of 48 - 2000 active elements (0 deactivated)
17:22:10 INFO opendrift.models.basemodel:2032: 2025-01-15 11:51:28.693840 - step 38 of 48 - 2000 active elements (0 deactivated)
17:22:11 INFO opendrift.models.basemodel:2032: 2025-01-15 12:21:28.693840 - step 39 of 48 - 2000 active elements (0 deactivated)
17:22:12 INFO opendrift.models.basemodel:2032: 2025-01-15 12:51:28.693840 - step 40 of 48 - 2000 active elements (0 deactivated)
17:22:12 INFO opendrift.models.basemodel:2032: 2025-01-15 13:21:28.693840 - step 41 of 48 - 2000 active elements (0 deactivated)
17:22:13 INFO opendrift.models.basemodel:2032: 2025-01-15 13:51:28.693840 - step 42 of 48 - 2000 active elements (0 deactivated)
17:22:13 INFO opendrift.models.basemodel:2032: 2025-01-15 14:21:28.693840 - step 43 of 48 - 2000 active elements (0 deactivated)
17:22:15 INFO opendrift.models.basemodel:2032: 2025-01-15 14:51:28.693840 - step 44 of 48 - 2000 active elements (0 deactivated)
17:22:15 INFO opendrift.models.basemodel:2032: 2025-01-15 15:21:28.693840 - step 45 of 48 - 2000 active elements (0 deactivated)
17:22:16 INFO opendrift.models.basemodel:2032: 2025-01-15 15:51:28.693840 - step 46 of 48 - 2000 active elements (0 deactivated)
17:22:17 INFO opendrift.models.basemodel:2032: 2025-01-15 16:21:28.693840 - step 47 of 48 - 2000 active elements (0 deactivated)
17:22:18 INFO opendrift.models.basemodel:2032: 2025-01-15 16:51:28.693840 - step 48 of 48 - 2000 active elements (0 deactivated)
Plot results with lines and particles colored by depth
print(o)
o.plot(linecolor='z', buffer=.1, show_elements=False, fast=False)
o.animation(color='z', buffer=.1, fast=True)
===========================
--------------------
Reader performance:
--------------------
global_landmask
0:00:00.0 total
0:00:00.0 preparing
0:00:00.0 reading
0:00:00.0 masking
--------------------
https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
0:00:38.5 total
0:00:00.0 preparing
0:00:37.5 reading
0:00:00.5 interpolation
0:00:00.0 interpolation_time
0:00:00.9 rotating vectors
0:00:00.0 masking
--------------------
Performance:
49.9 total time
3.6 configuration
0.0 preparing main loop
0.0 moving elements to ocean
46.2 main loop
0.1 updating elements
0.0 cleaning up
--------------------
===========================
Model: OceanDrift (OpenDrift version 1.12.0)
2000 active Lagrangian3DArray particles (0 deactivated, 0 scheduled)
-------------------
Environment variables:
-----
land_binary_mask
1) global_landmask
-----
sea_floor_depth_below_sea_level
sea_surface_height
upward_sea_water_velocity
x_sea_water_velocity
x_wind
y_sea_water_velocity
y_wind
1) https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
-----
Readers not added for the following variables:
ocean_mixed_layer_thickness
ocean_vertical_diffusivity
sea_surface_swell_wave_peak_period_from_variance_spectral_density
sea_surface_swell_wave_significant_height
sea_surface_swell_wave_to_direction
sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment
sea_surface_wave_period_at_variance_spectral_density_maximum
sea_surface_wave_significant_height
sea_surface_wave_stokes_drift_x_velocity
sea_surface_wave_stokes_drift_y_velocity
sea_surface_wind_wave_mean_period
sea_surface_wind_wave_significant_height
sea_surface_wind_wave_to_direction
surface_downward_x_stress
surface_downward_y_stress
turbulent_generic_length_scale
turbulent_kinetic_energy
Discarded readers:
Time:
Start: 2025-01-14 17:21:28.693840 UTC
Present: 2025-01-15 17:21:28.693840 UTC
Calculation steps: 48 * 0:30:00 - total time: 1 day, 0:00:00
Output steps: 49 * 0:30:00
===========================
17:23:31 WARNING opendrift.models.basemodel:2407: Plotting fast. This will make your plots less accurate.
17:23:32 INFO opendrift.models.basemodel:4606: Saving animation to /root/project/docs/source/gallery/animations/example_depth_0.gif...
17:23:58 INFO opendrift.models.basemodel:3034: Time to make animation: 0:00:26.769054
Total running time of the script: (2 minutes 36.151 seconds)