2D simulation profile

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
10:42:09 INFO    opendrift:509: OpenDriftSimulation initialised (version 1.13.1 / v1.13.1-25-g5021161)

Define some constant current, wind and Stokes drift

o.set_config('environment:fallback:x_wind', 7)
o.set_config('environment:fallback:x_sea_water_velocity', .1)
o.set_config('environment:fallback:sea_surface_wave_stokes_drift_x_velocity', .2)
o.set_config('environment:fallback:sea_surface_wave_significant_height', 2)
o.set_config('environment:fallback:sea_surface_wave_period_at_variance_spectral_density_maximum', 8)

Seed elements between surface and 5m depth

time = datetime.utcnow()
z = -np.linspace(0, 5, 50)
o.seed_elements(lon=4.5, lat=60.0, z=z, radius=0, number=len(z), time=time)
10:42:09 INFO    opendrift.models.basemodel.environment:206: Adding a global landmask from GSHHG
10:42:14 INFO    opendrift.models.basemodel.environment:229: Fallback values will be used for the following variables which have no readers:
10:42:14 INFO    opendrift.models.basemodel.environment:232:    x_sea_water_velocity: 0.100000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    y_sea_water_velocity: 0.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    sea_surface_height: 0.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    x_wind: 7.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    y_wind: 0.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    upward_sea_water_velocity: 0.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    ocean_vertical_diffusivity: 0.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    sea_surface_wave_significant_height: 2.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    sea_surface_wave_stokes_drift_x_velocity: 0.200000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    sea_surface_wave_period_at_variance_spectral_density_maximum: 8.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    sea_surface_swell_wave_to_direction: 0.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    sea_surface_swell_wave_peak_period_from_variance_spectral_density: 0.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    sea_surface_swell_wave_significant_height: 0.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    sea_surface_wind_wave_to_direction: 0.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    sea_surface_wind_wave_mean_period: 0.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    sea_surface_wind_wave_significant_height: 0.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    surface_downward_x_stress: 0.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    surface_downward_y_stress: 0.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    turbulent_kinetic_energy: 0.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    turbulent_generic_length_scale: 0.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    ocean_mixed_layer_thickness: 50.000000
10:42:14 INFO    opendrift.models.basemodel.environment:232:    sea_floor_depth_below_sea_level: 10000.000000

Running model for 6 hours

o.run(duration=timedelta(hours=6), time_step=600)
10:42:14 INFO    opendrift:923: Using existing reader for land_binary_mask
10:42:14 INFO    opendrift:934: All points are in ocean
10:42:14 INFO    opendrift:2060: 2025-04-22 10:42:09.969253 - step 1 of 36 - 50 active elements (0 deactivated)
10:42:14 INFO    opendrift:2060: 2025-04-22 10:52:09.969253 - step 2 of 36 - 50 active elements (0 deactivated)
10:42:14 INFO    opendrift:2060: 2025-04-22 11:02:09.969253 - step 3 of 36 - 50 active elements (0 deactivated)
10:42:14 INFO    opendrift:2060: 2025-04-22 11:12:09.969253 - step 4 of 36 - 50 active elements (0 deactivated)
10:42:14 INFO    opendrift:2060: 2025-04-22 11:22:09.969253 - step 5 of 36 - 50 active elements (0 deactivated)
10:42:14 INFO    opendrift:2060: 2025-04-22 11:32:09.969253 - step 6 of 36 - 50 active elements (0 deactivated)
10:42:14 INFO    opendrift:2060: 2025-04-22 11:42:09.969253 - step 7 of 36 - 50 active elements (0 deactivated)
10:42:14 INFO    opendrift:2060: 2025-04-22 11:52:09.969253 - step 8 of 36 - 50 active elements (0 deactivated)
10:42:14 INFO    opendrift:2060: 2025-04-22 12:02:09.969253 - step 9 of 36 - 50 active elements (0 deactivated)
10:42:14 INFO    opendrift:2060: 2025-04-22 12:12:09.969253 - step 10 of 36 - 50 active elements (0 deactivated)
10:42:14 INFO    opendrift:2060: 2025-04-22 12:22:09.969253 - step 11 of 36 - 50 active elements (0 deactivated)
10:42:14 INFO    opendrift:2060: 2025-04-22 12:32:09.969253 - step 12 of 36 - 50 active elements (0 deactivated)
10:42:14 INFO    opendrift:2060: 2025-04-22 12:42:09.969253 - step 13 of 36 - 50 active elements (0 deactivated)
10:42:14 INFO    opendrift:2060: 2025-04-22 12:52:09.969253 - step 14 of 36 - 50 active elements (0 deactivated)
10:42:14 INFO    opendrift:2060: 2025-04-22 13:02:09.969253 - step 15 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 13:12:09.969253 - step 16 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 13:22:09.969253 - step 17 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 13:32:09.969253 - step 18 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 13:42:09.969253 - step 19 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 13:52:09.969253 - step 20 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 14:02:09.969253 - step 21 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 14:12:09.969253 - step 22 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 14:22:09.969253 - step 23 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 14:32:09.969253 - step 24 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 14:42:09.969253 - step 25 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 14:52:09.969253 - step 26 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 15:02:09.969253 - step 27 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 15:12:09.969253 - step 28 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 15:22:09.969253 - step 29 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 15:32:09.969253 - step 30 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 15:42:09.969253 - step 31 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 15:52:09.969253 - step 32 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 16:02:09.969253 - step 33 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 16:12:09.969253 - step 34 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 16:22:09.969253 - step 35 of 36 - 50 active elements (0 deactivated)
10:42:15 INFO    opendrift:2060: 2025-04-22 16:32:09.969253 - step 36 of 36 - 50 active elements (0 deactivated)
<xarray.Dataset> Size: 260kB
Dimensions:                                                                              (
                                                                                          trajectory: 50,
                                                                                          time: 37)
Coordinates:
  * trajectory                                                                           (trajectory) int64 400B ...
  * time                                                                                 (time) datetime64[ns] 296B ...
Data variables: (12/35)
    status                                                                               (trajectory, time) float32 7kB ...
    moving                                                                               (trajectory, time) float32 7kB ...
    age_seconds                                                                          (trajectory, time) float32 7kB ...
    origin_marker                                                                        (trajectory, time) float32 7kB ...
    lon                                                                                  (trajectory, time) float32 7kB ...
    lat                                                                                  (trajectory, time) float32 7kB ...
    ...                                                                                   ...
    surface_downward_y_stress                                                            (trajectory, time) float32 7kB ...
    turbulent_kinetic_energy                                                             (trajectory, time) float32 7kB ...
    turbulent_generic_length_scale                                                       (trajectory, time) float32 7kB ...
    ocean_mixed_layer_thickness                                                          (trajectory, time) float32 7kB ...
    sea_floor_depth_below_sea_level                                                      (trajectory, time) float32 7kB ...
    land_binary_mask                                                                     (trajectory, time) float32 7kB ...
Attributes: (12/153)
    Conventions:                                                             ...
    standard_name_vocabulary:                                                ...
    featureType:                                                             ...
    title:                                                                   ...
    summary:                                                                 ...
    keywords:                                                                ...
    ...                                                                                                               ...
    geospatial_lon_units:                                                    ...
    geospatial_lon_resolution:                                               ...
    runtime:                                                                 ...
    geospatial_vertical_min:                                                 ...
    geospatial_vertical_max:                                                 ...
    geospatial_vertical_positive:                                            ...


To check that z is really kept constant for all particles

o.plot_property('z')
z

Vertical profile of advection. Note the decaying importance of Stokes drift, and the additional windage of the element at surface

o.animation_profile()
10:42:16 INFO    opendrift:4607: Saving animation to /root/project/docs/source/gallery/animations/example_2d_0.gif...
10:42:20 INFO    opendrift:3253: Time to make animation: 0:00:04.335790
../_images/example_2d_0.gif

Total running time of the script: (0 minutes 16.725 seconds)

Gallery generated by Sphinx-Gallery