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
20:14:37 INFO opendrift.models.basemodel:515: OpenDriftSimulation initialised (version 1.12.0 / v1.12.0-26-g390e945)
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)
20:14:37 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...
20:14:41 INFO opendrift.models.basemodel.environment:245: Fallback values will be used for the following variables which have no readers:
20:14:41 INFO opendrift.models.basemodel.environment:248: x_sea_water_velocity: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: y_sea_water_velocity: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: sea_surface_height: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: x_wind: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: y_wind: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: upward_sea_water_velocity: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: ocean_vertical_diffusivity: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_significant_height: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_stokes_drift_x_velocity: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_stokes_drift_y_velocity: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_to_direction: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_peak_period_from_variance_spectral_density: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_significant_height: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_to_direction: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_mean_period: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_significant_height: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: surface_downward_x_stress: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: surface_downward_y_stress: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: turbulent_kinetic_energy: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: turbulent_generic_length_scale: 0.000000
20:14:41 INFO opendrift.models.basemodel.environment:248: ocean_mixed_layer_thickness: 50.000000
20:14:41 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)
20:14:41 INFO opendrift.models.basemodel:935: Using existing reader for land_binary_mask
20:14:41 INFO opendrift.models.basemodel:946: All points are in ocean
20:14:41 INFO opendrift.models.basemodel:2035: 2024-12-12 20:14:37.730139 - step 1 of 48 - 2000 active elements (0 deactivated)
20:14:41 INFO opendrift.readers:58: Opening file with xr.open_dataset
20:14:48 INFO opendrift.readers.reader_netCDF_CF_generic:337: Detected dimensions: {'x': 'X', 'y': 'Y', 'z': 'depth', 'time': 'time'}
20:14:51 INFO opendrift.models.basemodel:2035: 2024-12-12 20:44:37.730139 - step 2 of 48 - 2000 active elements (0 deactivated)
20:14:51 INFO opendrift.models.basemodel:2035: 2024-12-12 21:14:37.730139 - step 3 of 48 - 2000 active elements (0 deactivated)
20:14:52 INFO opendrift.models.basemodel:2035: 2024-12-12 21:44:37.730139 - step 4 of 48 - 2000 active elements (0 deactivated)
20:14:52 INFO opendrift.models.basemodel:2035: 2024-12-12 22:14:37.730139 - step 5 of 48 - 2000 active elements (0 deactivated)
20:14:53 INFO opendrift.models.basemodel:2035: 2024-12-12 22:44:37.730139 - step 6 of 48 - 2000 active elements (0 deactivated)
20:14:53 INFO opendrift.models.basemodel:2035: 2024-12-12 23:14:37.730139 - step 7 of 48 - 2000 active elements (0 deactivated)
20:14:55 INFO opendrift.models.basemodel:2035: 2024-12-12 23:44:37.730139 - step 8 of 48 - 2000 active elements (0 deactivated)
20:14:55 INFO opendrift.models.basemodel:2035: 2024-12-13 00:14:37.730139 - step 9 of 48 - 2000 active elements (0 deactivated)
20:14:57 INFO opendrift.models.basemodel:2035: 2024-12-13 00:44:37.730139 - step 10 of 48 - 2000 active elements (0 deactivated)
20:14:57 INFO opendrift.models.basemodel:2035: 2024-12-13 01:14:37.730139 - step 11 of 48 - 2000 active elements (0 deactivated)
20:14:58 INFO opendrift.models.basemodel:2035: 2024-12-13 01:44:37.730139 - step 12 of 48 - 2000 active elements (0 deactivated)
20:14:58 INFO opendrift.models.basemodel:2035: 2024-12-13 02:14:37.730139 - step 13 of 48 - 2000 active elements (0 deactivated)
20:15:00 INFO opendrift.models.basemodel:2035: 2024-12-13 02:44:37.730139 - step 14 of 48 - 2000 active elements (0 deactivated)
20:15:00 INFO opendrift.models.basemodel:2035: 2024-12-13 03:14:37.730139 - step 15 of 48 - 2000 active elements (0 deactivated)
20:15:01 INFO opendrift.models.basemodel:2035: 2024-12-13 03:44:37.730139 - step 16 of 48 - 2000 active elements (0 deactivated)
20:15:01 INFO opendrift.models.basemodel:2035: 2024-12-13 04:14:37.730139 - step 17 of 48 - 2000 active elements (0 deactivated)
20:15:02 INFO opendrift.models.basemodel:2035: 2024-12-13 04:44:37.730139 - step 18 of 48 - 2000 active elements (0 deactivated)
20:15:02 INFO opendrift.models.basemodel:2035: 2024-12-13 05:14:37.730139 - step 19 of 48 - 2000 active elements (0 deactivated)
20:15:04 INFO opendrift.models.basemodel:2035: 2024-12-13 05:44:37.730139 - step 20 of 48 - 2000 active elements (0 deactivated)
20:15:04 INFO opendrift.models.basemodel:2035: 2024-12-13 06:14:37.730139 - step 21 of 48 - 2000 active elements (0 deactivated)
20:15:06 INFO opendrift.models.basemodel:2035: 2024-12-13 06:44:37.730139 - step 22 of 48 - 2000 active elements (0 deactivated)
20:15:06 INFO opendrift.models.basemodel:2035: 2024-12-13 07:14:37.730139 - step 23 of 48 - 2000 active elements (0 deactivated)
20:15:07 INFO opendrift.models.basemodel:2035: 2024-12-13 07:44:37.730139 - step 24 of 48 - 2000 active elements (0 deactivated)
20:15:07 INFO opendrift.models.basemodel:2035: 2024-12-13 08:14:37.730139 - step 25 of 48 - 2000 active elements (0 deactivated)
20:15:09 INFO opendrift.models.basemodel:2035: 2024-12-13 08:44:37.730139 - step 26 of 48 - 2000 active elements (0 deactivated)
20:15:09 INFO opendrift.models.basemodel:2035: 2024-12-13 09:14:37.730139 - step 27 of 48 - 2000 active elements (0 deactivated)
20:15:11 INFO opendrift.models.basemodel:2035: 2024-12-13 09:44:37.730139 - step 28 of 48 - 2000 active elements (0 deactivated)
20:15:11 INFO opendrift.models.basemodel:2035: 2024-12-13 10:14:37.730139 - step 29 of 48 - 2000 active elements (0 deactivated)
20:15:13 INFO opendrift.models.basemodel:2035: 2024-12-13 10:44:37.730139 - step 30 of 48 - 2000 active elements (0 deactivated)
20:15:13 INFO opendrift.models.basemodel:2035: 2024-12-13 11:14:37.730139 - step 31 of 48 - 2000 active elements (0 deactivated)
20:15:14 INFO opendrift.models.basemodel:2035: 2024-12-13 11:44:37.730139 - step 32 of 48 - 2000 active elements (0 deactivated)
20:15:14 INFO opendrift.models.basemodel:2035: 2024-12-13 12:14:37.730139 - step 33 of 48 - 2000 active elements (0 deactivated)
20:15:16 INFO opendrift.models.basemodel:2035: 2024-12-13 12:44:37.730139 - step 34 of 48 - 2000 active elements (0 deactivated)
20:15:16 INFO opendrift.models.basemodel:2035: 2024-12-13 13:14:37.730139 - step 35 of 48 - 2000 active elements (0 deactivated)
20:15:17 INFO opendrift.models.basemodel:2035: 2024-12-13 13:44:37.730139 - step 36 of 48 - 2000 active elements (0 deactivated)
20:15:17 INFO opendrift.models.basemodel:2035: 2024-12-13 14:14:37.730139 - step 37 of 48 - 2000 active elements (0 deactivated)
20:15:19 INFO opendrift.models.basemodel:2035: 2024-12-13 14:44:37.730139 - step 38 of 48 - 2000 active elements (0 deactivated)
20:15:19 INFO opendrift.models.basemodel:2035: 2024-12-13 15:14:37.730139 - step 39 of 48 - 2000 active elements (0 deactivated)
20:15:20 INFO opendrift.models.basemodel:2035: 2024-12-13 15:44:37.730139 - step 40 of 48 - 2000 active elements (0 deactivated)
20:15:20 INFO opendrift.models.basemodel:2035: 2024-12-13 16:14:37.730139 - step 41 of 48 - 2000 active elements (0 deactivated)
20:15:22 INFO opendrift.models.basemodel:2035: 2024-12-13 16:44:37.730139 - step 42 of 48 - 2000 active elements (0 deactivated)
20:15:22 INFO opendrift.models.basemodel:2035: 2024-12-13 17:14:37.730139 - step 43 of 48 - 2000 active elements (0 deactivated)
20:15:23 INFO opendrift.models.basemodel:2035: 2024-12-13 17:44:37.730139 - step 44 of 48 - 2000 active elements (0 deactivated)
20:15:23 INFO opendrift.models.basemodel:2035: 2024-12-13 18:14:37.730139 - step 45 of 48 - 2000 active elements (0 deactivated)
20:15:25 INFO opendrift.models.basemodel:2035: 2024-12-13 18:44:37.730139 - step 46 of 48 - 2000 active elements (0 deactivated)
20:15:26 INFO opendrift.models.basemodel:2035: 2024-12-13 19:14:37.730139 - step 47 of 48 - 2000 active elements (0 deactivated)
20:15:28 INFO opendrift.models.basemodel:2035: 2024-12-13 19:44:37.730139 - 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:01.5 total
0:00:00.0 preparing
0:00:01.5 reading
0:00:00.0 masking
--------------------
https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
0:00:36.5 total
0:00:00.0 preparing
0:00:35.5 reading
0:00:00.5 interpolation
0:00:00.0 interpolation_time
0:00:01.0 rotating vectors
0:00:00.0 masking
--------------------
Performance:
52.1 total time
4.0 configuration
0.0 preparing main loop
0.0 moving elements to ocean
48.0 main loop
0.1 updating elements
0.0 cleaning up
--------------------
===========================
Model: OceanDrift (OpenDrift version 1.12.0)
1994 active Lagrangian3DArray particles (6 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: 2024-12-12 20:14:37.730139 UTC
Present: 2024-12-13 20:14:37.730139 UTC
Calculation steps: 48 * 0:30:00 - total time: 1 day, 0:00:00
Output steps: 49 * 0:30:00
===========================
20:16:33 WARNING opendrift.models.basemodel:2410: Plotting fast. This will make your plots less accurate.
20:16:35 INFO opendrift.models.basemodel:4613: Saving animation to /root/project/docs/source/gallery/animations/example_depth_0.gif...
20:17:09 INFO opendrift.models.basemodel:3037: Time to make animation: 0:00:35.714221
Total running time of the script: (2 minutes 42.217 seconds)