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
12:21:47 INFO    opendrift.models.basemodel:532: OpenDriftSimulation initialised (version 1.10.5 / v0.10.5-2-g8025fe7)

Using live data from Thredds

o.add_readers_from_list([
    'https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be'])

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)
===========================
Model:  OceanDrift     (OpenDrift version 1.10.5)
        0 active Lagrangian3DArray particles  (0 deactivated, 2000 scheduled)
-------------------
Environment variables:
  -----
Readers not added for the following variables:
  land_binary_mask
  ocean_mixed_layer_thickness
  ocean_vertical_diffusivity
  sea_floor_depth_below_sea_level
  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
  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
===========================

Adding some diffusion

o.set_config('drift:horizontal_diffusivity', 10)  # m2/s

Running model

o.run(duration=timedelta(hours=24), time_step=1800)
12:21:47 INFO    opendrift.models.basemodel:2574: Fallback values will be used for the following variables which have no readers:
12:21:47 INFO    opendrift.models.basemodel:2577:       x_sea_water_velocity: 0.000000
12:21:47 INFO    opendrift.models.basemodel:2577:       y_sea_water_velocity: 0.000000
12:21:47 INFO    opendrift.models.basemodel:2577:       x_wind: 0.000000
12:21:47 INFO    opendrift.models.basemodel:2577:       y_wind: 0.000000
12:21:47 INFO    opendrift.models.basemodel:2577:       upward_sea_water_velocity: 0.000000
12:21:47 INFO    opendrift.models.basemodel:2577:       ocean_vertical_diffusivity: 0.000000
12:21:47 INFO    opendrift.models.basemodel:2577:       sea_surface_wave_significant_height: 0.000000
12:21:47 INFO    opendrift.models.basemodel:2577:       sea_surface_wave_stokes_drift_x_velocity: 0.000000
12:21:47 INFO    opendrift.models.basemodel:2577:       sea_surface_wave_stokes_drift_y_velocity: 0.000000
12:21:47 INFO    opendrift.models.basemodel:2577:       sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
12:21:47 INFO    opendrift.models.basemodel:2577:       sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
12:21:47 INFO    opendrift.models.basemodel:2577:       surface_downward_x_stress: 0.000000
12:21:47 INFO    opendrift.models.basemodel:2577:       surface_downward_y_stress: 0.000000
12:21:47 INFO    opendrift.models.basemodel:2577:       turbulent_kinetic_energy: 0.000000
12:21:47 INFO    opendrift.models.basemodel:2577:       turbulent_generic_length_scale: 0.000000
12:21:47 INFO    opendrift.models.basemodel:2577:       ocean_mixed_layer_thickness: 50.000000
12:21:47 INFO    opendrift.models.basemodel:2577:       sea_floor_depth_below_sea_level: 10000.000000
12:21:47 INFO    opendrift.models.basemodel:2736: Adding a dynamical landmask with max. priority based on assumed maximum speed of 1 m/s. Adding a customised landmask may be faster...
12:21:53 INFO    opendrift.models.basemodel:1689: Using existing reader for land_binary_mask
12:21:53 INFO    opendrift.models.basemodel:1701: All points are in ocean
12:21:53 INFO    opendrift.models.basemodel:2865: 2023-01-26 12:21:47.384260 - step 1 of 48 - 2000 active elements (0 deactivated)
12:21:53 INFO    opendrift.readers.reader_netCDF_CF_generic:129: Opening dataset: https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
12:21:57 INFO    opendrift.models.basemodel:2865: 2023-01-26 12:51:47.384260 - step 2 of 48 - 2000 active elements (0 deactivated)
12:21:57 INFO    opendrift.models.basemodel:2865: 2023-01-26 13:21:47.384260 - step 3 of 48 - 2000 active elements (0 deactivated)
12:21:59 INFO    opendrift.models.basemodel:2865: 2023-01-26 13:51:47.384260 - step 4 of 48 - 2000 active elements (0 deactivated)
12:21:59 INFO    opendrift.models.basemodel:2865: 2023-01-26 14:21:47.384260 - step 5 of 48 - 2000 active elements (0 deactivated)
12:22:00 INFO    opendrift.models.basemodel:2865: 2023-01-26 14:51:47.384260 - step 6 of 48 - 2000 active elements (0 deactivated)
12:22:00 INFO    opendrift.models.basemodel:2865: 2023-01-26 15:21:47.384260 - step 7 of 48 - 2000 active elements (0 deactivated)
12:22:01 INFO    opendrift.models.basemodel:2865: 2023-01-26 15:51:47.384260 - step 8 of 48 - 2000 active elements (0 deactivated)
12:22:01 INFO    opendrift.models.basemodel:2865: 2023-01-26 16:21:47.384260 - step 9 of 48 - 2000 active elements (0 deactivated)
12:22:02 INFO    opendrift.models.basemodel:2865: 2023-01-26 16:51:47.384260 - step 10 of 48 - 2000 active elements (0 deactivated)
12:22:02 INFO    opendrift.models.basemodel:2865: 2023-01-26 17:21:47.384260 - step 11 of 48 - 2000 active elements (0 deactivated)
12:22:03 INFO    opendrift.models.basemodel:2865: 2023-01-26 17:51:47.384260 - step 12 of 48 - 2000 active elements (0 deactivated)
12:22:03 INFO    opendrift.models.basemodel:2865: 2023-01-26 18:21:47.384260 - step 13 of 48 - 2000 active elements (0 deactivated)
12:22:05 INFO    opendrift.models.basemodel:2865: 2023-01-26 18:51:47.384260 - step 14 of 48 - 2000 active elements (0 deactivated)
12:22:05 INFO    opendrift.models.basemodel:2865: 2023-01-26 19:21:47.384260 - step 15 of 48 - 2000 active elements (0 deactivated)
12:22:06 INFO    opendrift.models.basemodel:2865: 2023-01-26 19:51:47.384260 - step 16 of 48 - 2000 active elements (0 deactivated)
12:22:06 INFO    opendrift.models.basemodel:2865: 2023-01-26 20:21:47.384260 - step 17 of 48 - 2000 active elements (0 deactivated)
12:22:08 INFO    opendrift.models.basemodel:2865: 2023-01-26 20:51:47.384260 - step 18 of 48 - 2000 active elements (0 deactivated)
12:22:08 INFO    opendrift.models.basemodel:2865: 2023-01-26 21:21:47.384260 - step 19 of 48 - 2000 active elements (0 deactivated)
12:22:09 INFO    opendrift.models.basemodel:2865: 2023-01-26 21:51:47.384260 - step 20 of 48 - 2000 active elements (0 deactivated)
12:22:09 INFO    opendrift.models.basemodel:2865: 2023-01-26 22:21:47.384260 - step 21 of 48 - 2000 active elements (0 deactivated)
12:22:11 INFO    opendrift.models.basemodel:2865: 2023-01-26 22:51:47.384260 - step 22 of 48 - 2000 active elements (0 deactivated)
12:22:11 INFO    opendrift.models.basemodel:2865: 2023-01-26 23:21:47.384260 - step 23 of 48 - 2000 active elements (0 deactivated)
12:22:12 INFO    opendrift.models.basemodel:2865: 2023-01-26 23:51:47.384260 - step 24 of 48 - 2000 active elements (0 deactivated)
12:22:13 INFO    opendrift.models.basemodel:2865: 2023-01-27 00:21:47.384260 - step 25 of 48 - 2000 active elements (0 deactivated)
12:22:14 INFO    opendrift.models.basemodel:2865: 2023-01-27 00:51:47.384260 - step 26 of 48 - 2000 active elements (0 deactivated)
12:22:14 INFO    opendrift.models.basemodel:2865: 2023-01-27 01:21:47.384260 - step 27 of 48 - 2000 active elements (0 deactivated)
12:22:15 INFO    opendrift.models.basemodel:2865: 2023-01-27 01:51:47.384260 - step 28 of 48 - 2000 active elements (0 deactivated)
12:22:15 INFO    opendrift.models.basemodel:2865: 2023-01-27 02:21:47.384260 - step 29 of 48 - 2000 active elements (0 deactivated)
12:22:18 INFO    opendrift.models.basemodel:2865: 2023-01-27 02:51:47.384260 - step 30 of 48 - 2000 active elements (0 deactivated)
12:22:18 INFO    opendrift.models.basemodel:2865: 2023-01-27 03:21:47.384260 - step 31 of 48 - 2000 active elements (0 deactivated)
12:22:19 INFO    opendrift.models.basemodel:2865: 2023-01-27 03:51:47.384260 - step 32 of 48 - 2000 active elements (0 deactivated)
12:22:19 INFO    opendrift.models.basemodel:2865: 2023-01-27 04:21:47.384260 - step 33 of 48 - 2000 active elements (0 deactivated)
12:22:20 INFO    opendrift.models.basemodel:2865: 2023-01-27 04:51:47.384260 - step 34 of 48 - 2000 active elements (0 deactivated)
12:22:20 INFO    opendrift.models.basemodel:2865: 2023-01-27 05:21:47.384260 - step 35 of 48 - 2000 active elements (0 deactivated)
12:22:22 INFO    opendrift.models.basemodel:2865: 2023-01-27 05:51:47.384260 - step 36 of 48 - 2000 active elements (0 deactivated)
12:22:22 INFO    opendrift.models.basemodel:2865: 2023-01-27 06:21:47.384260 - step 37 of 48 - 2000 active elements (0 deactivated)
12:22:23 INFO    opendrift.models.basemodel:2865: 2023-01-27 06:51:47.384260 - step 38 of 48 - 2000 active elements (0 deactivated)
12:22:23 INFO    opendrift.models.basemodel:2865: 2023-01-27 07:21:47.384260 - step 39 of 48 - 2000 active elements (0 deactivated)
12:22:28 INFO    opendrift.models.basemodel:2865: 2023-01-27 07:51:47.384260 - step 40 of 48 - 2000 active elements (0 deactivated)
12:22:28 INFO    opendrift.models.basemodel:2865: 2023-01-27 08:21:47.384260 - step 41 of 48 - 2000 active elements (0 deactivated)
12:22:30 INFO    opendrift.models.basemodel:2865: 2023-01-27 08:51:47.384260 - step 42 of 48 - 2000 active elements (0 deactivated)
12:22:30 INFO    opendrift.models.basemodel:2865: 2023-01-27 09:21:47.384260 - step 43 of 48 - 2000 active elements (0 deactivated)
12:22:31 INFO    opendrift.models.basemodel:2865: 2023-01-27 09:51:47.384260 - step 44 of 48 - 2000 active elements (0 deactivated)
12:22:31 INFO    opendrift.models.basemodel:2865: 2023-01-27 10:21:47.384260 - step 45 of 48 - 2000 active elements (0 deactivated)
12:22:32 INFO    opendrift.models.basemodel:2865: 2023-01-27 10:51:47.384260 - step 46 of 48 - 2000 active elements (0 deactivated)
12:22:32 INFO    opendrift.models.basemodel:2865: 2023-01-27 11:21:47.384260 - step 47 of 48 - 2000 active elements (0 deactivated)
12:22:34 INFO    opendrift.models.basemodel:2865: 2023-01-27 11:51:47.384260 - 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)
OpenDrift - OceanDrift 2023-01-26 12:21 to 2023-01-27 12:21 UTC (49 steps)
===========================
--------------------
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:37.9  total
 0:00:00.0  preparing
 0:00:36.8  reading
 0:00:00.5  interpolation
 0:00:00.0  interpolation_time
 0:00:01.1  rotating vectors
 0:00:00.0  masking
--------------------
Performance:
   47.0 total time
    0.0 configuration
    5.6 preparing main loop
      5.6 making dynamical landmask
      0.0 moving elements to ocean
     40.4 readers
        0.0 global_landmask
        0.2 postprocessing
   41.2 main loop
       38.1 https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
      0.1 updating elements
    0.0 cleaning up
--------------------
===========================
Model:  OceanDrift     (OpenDrift version 1.10.5)
        2000 active Lagrangian3DArray particles  (0 deactivated, 0 scheduled)
-------------------
Environment variables:
  -----
  land_binary_mask
     1) global_landmask
  -----
  sea_floor_depth_below_sea_level
  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_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
  surface_downward_x_stress
  surface_downward_y_stress
  turbulent_generic_length_scale
  turbulent_kinetic_energy

Time:
        Start: 2023-01-26 12:21:47.384260
        Present: 2023-01-27 12:21:47.384260
        Calculation steps: 48 * 0:30:00 - total time: 1 day, 0:00:00
        Output steps: 49 * 0:30:00
===========================

12:23:26 WARNING opendrift.models.basemodel:3209: Plotting fast. This will make your plots less accurate.
12:23:28 INFO    opendrift.models.basemodel:5329: Saving animation to /root/project/docs/source/gallery/animations/example_depth_0.gif...
12:23:38 INFO    opendrift.models.basemodel:3831: Time to make animation: 0:00:11.520763
../_images/example_depth_0.gif

Total running time of the script: ( 1 minutes 56.753 seconds)

Gallery generated by Sphinx-Gallery