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
09:36:10 INFO opendrift.models.basemodel:515: OpenDriftSimulation initialised (version 1.11.13 / v1.11.13-48-g5bea84b)
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)
09:36:10 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...
09:36:16 INFO opendrift.models.basemodel.environment:245: Fallback values will be used for the following variables which have no readers:
09:36:16 INFO opendrift.models.basemodel.environment:248: x_sea_water_velocity: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: y_sea_water_velocity: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: sea_surface_height: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: x_wind: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: y_wind: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: upward_sea_water_velocity: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: ocean_vertical_diffusivity: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_significant_height: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_stokes_drift_x_velocity: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_stokes_drift_y_velocity: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_to_direction: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_peak_period_from_variance_spectral_density: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_significant_height: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_to_direction: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_mean_period: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_significant_height: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: surface_downward_x_stress: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: surface_downward_y_stress: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: turbulent_kinetic_energy: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: turbulent_generic_length_scale: 0.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: ocean_mixed_layer_thickness: 50.000000
09:36:16 INFO opendrift.models.basemodel.environment:248: sea_floor_depth_below_sea_level: 10000.000000
===========================
Model: OceanDrift (OpenDrift version 1.11.13)
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)
09:36:17 INFO opendrift.models.basemodel:936: Using existing reader for land_binary_mask
09:36:17 INFO opendrift.models.basemodel:947: All points are in ocean
09:36:17 INFO opendrift.models.basemodel:2038: 2024-10-01 09:36:10.302073 - step 1 of 48 - 2000 active elements (0 deactivated)
09:36:17 INFO opendrift.readers.reader_netCDF_CF_generic:102: Opening dataset: https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
/opt/conda/envs/opendrift/lib/python3.11/site-packages/pyproj/crs/crs.py:1286: UserWarning: You will likely lose important projection information when converting to a PROJ string from another format. See: https://proj.org/faq.html#what-is-the-best-format-for-describing-coordinate-reference-systems
proj = self._crs.to_proj4(version=version)
09:36:18 INFO opendrift.readers.reader_netCDF_CF_generic:325: Detected dimensions: {'x': 'X', 'y': 'Y', 'z': 'depth', 'time': 'time'}
09:36:21 INFO opendrift.models.basemodel:2038: 2024-10-01 10:06:10.302073 - step 2 of 48 - 2000 active elements (0 deactivated)
09:36:23 INFO opendrift.models.basemodel:2038: 2024-10-01 10:36:10.302073 - step 3 of 48 - 2000 active elements (0 deactivated)
09:36:23 INFO opendrift.models.basemodel:2038: 2024-10-01 11:06:10.302073 - step 4 of 48 - 2000 active elements (0 deactivated)
09:36:25 INFO opendrift.models.basemodel:2038: 2024-10-01 11:36:10.302073 - step 5 of 48 - 2000 active elements (0 deactivated)
09:36:25 INFO opendrift.models.basemodel:2038: 2024-10-01 12:06:10.302073 - step 6 of 48 - 2000 active elements (0 deactivated)
09:36:26 INFO opendrift.models.basemodel:2038: 2024-10-01 12:36:10.302073 - step 7 of 48 - 2000 active elements (0 deactivated)
09:36:26 INFO opendrift.models.basemodel:2038: 2024-10-01 13:06:10.302073 - step 8 of 48 - 2000 active elements (0 deactivated)
09:36:28 INFO opendrift.models.basemodel:2038: 2024-10-01 13:36:10.302073 - step 9 of 48 - 2000 active elements (0 deactivated)
09:36:28 INFO opendrift.models.basemodel:2038: 2024-10-01 14:06:10.302073 - step 10 of 48 - 2000 active elements (0 deactivated)
09:36:29 INFO opendrift.models.basemodel:2038: 2024-10-01 14:36:10.302073 - step 11 of 48 - 2000 active elements (0 deactivated)
09:36:29 INFO opendrift.models.basemodel:2038: 2024-10-01 15:06:10.302073 - step 12 of 48 - 2000 active elements (0 deactivated)
09:36:31 INFO opendrift.models.basemodel:2038: 2024-10-01 15:36:10.302073 - step 13 of 48 - 2000 active elements (0 deactivated)
09:36:31 INFO opendrift.models.basemodel:2038: 2024-10-01 16:06:10.302073 - step 14 of 48 - 2000 active elements (0 deactivated)
09:36:32 INFO opendrift.models.basemodel:2038: 2024-10-01 16:36:10.302073 - step 15 of 48 - 2000 active elements (0 deactivated)
09:36:32 INFO opendrift.models.basemodel:2038: 2024-10-01 17:06:10.302073 - step 16 of 48 - 2000 active elements (0 deactivated)
09:36:34 INFO opendrift.models.basemodel:2038: 2024-10-01 17:36:10.302073 - step 17 of 48 - 2000 active elements (0 deactivated)
09:36:34 INFO opendrift.models.basemodel:2038: 2024-10-01 18:06:10.302073 - step 18 of 48 - 2000 active elements (0 deactivated)
09:36:35 INFO opendrift.models.basemodel:2038: 2024-10-01 18:36:10.302073 - step 19 of 48 - 2000 active elements (0 deactivated)
09:36:35 INFO opendrift.models.basemodel:2038: 2024-10-01 19:06:10.302073 - step 20 of 48 - 2000 active elements (0 deactivated)
09:36:37 INFO opendrift.models.basemodel:2038: 2024-10-01 19:36:10.302073 - step 21 of 48 - 2000 active elements (0 deactivated)
09:36:37 INFO opendrift.models.basemodel:2038: 2024-10-01 20:06:10.302073 - step 22 of 48 - 2000 active elements (0 deactivated)
09:36:38 INFO opendrift.models.basemodel:2038: 2024-10-01 20:36:10.302073 - step 23 of 48 - 2000 active elements (0 deactivated)
09:36:38 INFO opendrift.models.basemodel:2038: 2024-10-01 21:06:10.302073 - step 24 of 48 - 2000 active elements (0 deactivated)
09:36:40 INFO opendrift.models.basemodel:2038: 2024-10-01 21:36:10.302073 - step 25 of 48 - 2000 active elements (0 deactivated)
09:36:40 INFO opendrift.models.basemodel:2038: 2024-10-01 22:06:10.302073 - step 26 of 48 - 2000 active elements (0 deactivated)
09:36:42 INFO opendrift.models.basemodel:2038: 2024-10-01 22:36:10.302073 - step 27 of 48 - 2000 active elements (0 deactivated)
09:36:42 INFO opendrift.models.basemodel:2038: 2024-10-01 23:06:10.302073 - step 28 of 48 - 2000 active elements (0 deactivated)
09:36:43 INFO opendrift.models.basemodel:2038: 2024-10-01 23:36:10.302073 - step 29 of 48 - 2000 active elements (0 deactivated)
09:36:43 INFO opendrift.models.basemodel:2038: 2024-10-02 00:06:10.302073 - step 30 of 48 - 2000 active elements (0 deactivated)
09:36:45 INFO opendrift.models.basemodel:2038: 2024-10-02 00:36:10.302073 - step 31 of 48 - 2000 active elements (0 deactivated)
09:36:45 INFO opendrift.models.basemodel:2038: 2024-10-02 01:06:10.302073 - step 32 of 48 - 2000 active elements (0 deactivated)
09:36:46 INFO opendrift.models.basemodel:2038: 2024-10-02 01:36:10.302073 - step 33 of 48 - 2000 active elements (0 deactivated)
09:36:46 INFO opendrift.models.basemodel:2038: 2024-10-02 02:06:10.302073 - step 34 of 48 - 2000 active elements (0 deactivated)
09:36:48 INFO opendrift.models.basemodel:2038: 2024-10-02 02:36:10.302073 - step 35 of 48 - 2000 active elements (0 deactivated)
09:36:48 INFO opendrift.models.basemodel:2038: 2024-10-02 03:06:10.302073 - step 36 of 48 - 2000 active elements (0 deactivated)
09:36:49 INFO opendrift.models.basemodel:2038: 2024-10-02 03:36:10.302073 - step 37 of 48 - 2000 active elements (0 deactivated)
09:36:49 INFO opendrift.models.basemodel:2038: 2024-10-02 04:06:10.302073 - step 38 of 48 - 2000 active elements (0 deactivated)
09:36:51 INFO opendrift.models.basemodel:2038: 2024-10-02 04:36:10.302073 - step 39 of 48 - 2000 active elements (0 deactivated)
09:36:51 INFO opendrift.models.basemodel:2038: 2024-10-02 05:06:10.302073 - step 40 of 48 - 2000 active elements (0 deactivated)
09:36:52 INFO opendrift.models.basemodel:2038: 2024-10-02 05:36:10.302073 - step 41 of 48 - 2000 active elements (0 deactivated)
09:36:52 INFO opendrift.models.basemodel:2038: 2024-10-02 06:06:10.302073 - step 42 of 48 - 2000 active elements (0 deactivated)
09:36:54 INFO opendrift.models.basemodel:2038: 2024-10-02 06:36:10.302073 - step 43 of 48 - 2000 active elements (0 deactivated)
09:36:54 INFO opendrift.models.basemodel:2038: 2024-10-02 07:06:10.302073 - step 44 of 48 - 2000 active elements (0 deactivated)
09:36:55 INFO opendrift.models.basemodel:2038: 2024-10-02 07:36:10.302073 - step 45 of 48 - 2000 active elements (0 deactivated)
09:36:55 INFO opendrift.models.basemodel:2038: 2024-10-02 08:06:10.302073 - step 46 of 48 - 2000 active elements (0 deactivated)
09:36:56 INFO opendrift.models.basemodel:2038: 2024-10-02 08:36:10.302073 - step 47 of 48 - 2000 active elements (0 deactivated)
09:36:56 INFO opendrift.models.basemodel:2038: 2024-10-02 09:06:10.302073 - 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.0 total
0:00:00.0 preparing
0:00:37.0 reading
0:00:00.5 interpolation
0:00:00.0 interpolation_time
0:00:00.9 rotating vectors
0:00:00.0 masking
--------------------
Performance:
48.0 total time
6.8 configuration
0.0 preparing main loop
0.0 moving elements to ocean
41.1 main loop
0.1 updating elements
0.0 cleaning up
--------------------
===========================
Model: OceanDrift (OpenDrift version 1.11.13)
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: 2024-10-01 09:36:10.302073 UTC
Present: 2024-10-02 09:36:10.302073 UTC
Calculation steps: 48 * 0:30:00 - total time: 1 day, 0:00:00
Output steps: 49 * 0:30:00
===========================
09:38:33 WARNING opendrift.models.basemodel:2411: Plotting fast. This will make your plots less accurate.
09:38:35 INFO opendrift.models.basemodel:4608: Saving animation to /root/project/docs/source/gallery/animations/example_depth_0.gif...
09:39:03 INFO opendrift.models.basemodel:3037: Time to make animation: 0:00:30.608664
Total running time of the script: (3 minutes 6.879 seconds)