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

Out:

16:11:07 INFO    opendrift.models.basemodel: OpenDriftSimulation initialised (version 1.7.1 / v1.7.1-145-gdf95ed3)

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)

Out:

===========================
Model:  OceanDrift     (OpenDrift version 1.7.1)
        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)

Out:

16:11:07 INFO    opendrift.models.basemodel: Fallback values will be used for the following variables which have no readers:
16:11:07 INFO    opendrift.models.basemodel:    x_sea_water_velocity: 0.000000
16:11:07 INFO    opendrift.models.basemodel:    y_sea_water_velocity: 0.000000
16:11:07 INFO    opendrift.models.basemodel:    x_wind: 0.000000
16:11:07 INFO    opendrift.models.basemodel:    y_wind: 0.000000
16:11:07 INFO    opendrift.models.basemodel:    upward_sea_water_velocity: 0.000000
16:11:07 INFO    opendrift.models.basemodel:    ocean_vertical_diffusivity: 0.000000
16:11:07 INFO    opendrift.models.basemodel:    sea_surface_wave_significant_height: 0.000000
16:11:07 INFO    opendrift.models.basemodel:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
16:11:07 INFO    opendrift.models.basemodel:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
16:11:07 INFO    opendrift.models.basemodel:    sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
16:11:07 INFO    opendrift.models.basemodel:    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
16:11:07 INFO    opendrift.models.basemodel:    surface_downward_x_stress: 0.000000
16:11:07 INFO    opendrift.models.basemodel:    surface_downward_y_stress: 0.000000
16:11:07 INFO    opendrift.models.basemodel:    turbulent_kinetic_energy: 0.000000
16:11:07 INFO    opendrift.models.basemodel:    turbulent_generic_length_scale: 0.000000
16:11:07 INFO    opendrift.models.basemodel:    ocean_mixed_layer_thickness: 50.000000
16:11:07 INFO    opendrift.models.basemodel:    sea_floor_depth_below_sea_level: 10000.000000
16:11:07 INFO    opendrift.models.basemodel: Adding a dynamical landmask with max. priority based on assumed maximum speed of 1 m/s. Adding a customised landmask may be faster...
16:11:10 INFO    opendrift.models.basemodel: Using existing reader for land_binary_mask
16:11:10 INFO    opendrift.models.basemodel: All points are in ocean
16:11:10 INFO    opendrift.models.basemodel: 2021-10-23 16:11:07.712393 - step 1 of 48 - 2000 active elements (0 deactivated)
16:11:10 INFO    opendrift.readers.reader_netCDF_CF_generic: Opening dataset: https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
16:11:14 INFO    opendrift.models.basemodel: 2021-10-23 16:41:07.712393 - step 2 of 48 - 2000 active elements (0 deactivated)
16:11:15 INFO    opendrift.models.basemodel: 2021-10-23 17:11:07.712393 - step 3 of 48 - 2000 active elements (0 deactivated)
16:11:16 INFO    opendrift.models.basemodel: 2021-10-23 17:41:07.712393 - step 4 of 48 - 2000 active elements (0 deactivated)
16:11:16 INFO    opendrift.models.basemodel: 2021-10-23 18:11:07.712393 - step 5 of 48 - 2000 active elements (0 deactivated)
16:11:17 INFO    opendrift.models.basemodel: 2021-10-23 18:41:07.712393 - step 6 of 48 - 2000 active elements (0 deactivated)
16:11:17 INFO    opendrift.models.basemodel: 2021-10-23 19:11:07.712393 - step 7 of 48 - 2000 active elements (0 deactivated)
16:11:19 INFO    opendrift.models.basemodel: 2021-10-23 19:41:07.712393 - step 8 of 48 - 2000 active elements (0 deactivated)
16:11:19 INFO    opendrift.models.basemodel: 2021-10-23 20:11:07.712393 - step 9 of 48 - 2000 active elements (0 deactivated)
16:11:21 INFO    opendrift.models.basemodel: 2021-10-23 20:41:07.712393 - step 10 of 48 - 2000 active elements (0 deactivated)
16:11:21 INFO    opendrift.models.basemodel: 2021-10-23 21:11:07.712393 - step 11 of 48 - 2000 active elements (0 deactivated)
16:11:22 INFO    opendrift.models.basemodel: 2021-10-23 21:41:07.712393 - step 12 of 48 - 2000 active elements (0 deactivated)
16:11:23 INFO    opendrift.models.basemodel: 2021-10-23 22:11:07.712393 - step 13 of 48 - 2000 active elements (0 deactivated)
16:11:24 INFO    opendrift.models.basemodel: 2021-10-23 22:41:07.712393 - step 14 of 48 - 2000 active elements (0 deactivated)
16:11:24 INFO    opendrift.models.basemodel: 2021-10-23 23:11:07.712393 - step 15 of 48 - 2000 active elements (0 deactivated)
16:11:26 INFO    opendrift.models.basemodel: 2021-10-23 23:41:07.712393 - step 16 of 48 - 2000 active elements (0 deactivated)
16:11:26 INFO    opendrift.models.basemodel: 2021-10-24 00:11:07.712393 - step 17 of 48 - 2000 active elements (0 deactivated)
16:11:28 INFO    opendrift.models.basemodel: 2021-10-24 00:41:07.712393 - step 18 of 48 - 2000 active elements (0 deactivated)
16:11:29 INFO    opendrift.models.basemodel: 2021-10-24 01:11:07.712393 - step 19 of 48 - 2000 active elements (0 deactivated)
16:11:30 INFO    opendrift.models.basemodel: 2021-10-24 01:41:07.712393 - step 20 of 48 - 2000 active elements (0 deactivated)
16:11:30 INFO    opendrift.models.basemodel: 2021-10-24 02:11:07.712393 - step 21 of 48 - 2000 active elements (0 deactivated)
16:11:32 INFO    opendrift.models.basemodel: 2021-10-24 02:41:07.712393 - step 22 of 48 - 2000 active elements (0 deactivated)
16:11:32 INFO    opendrift.models.basemodel: 2021-10-24 03:11:07.712393 - step 23 of 48 - 2000 active elements (0 deactivated)
16:11:34 INFO    opendrift.models.basemodel: 2021-10-24 03:41:07.712393 - step 24 of 48 - 2000 active elements (0 deactivated)
16:11:34 INFO    opendrift.models.basemodel: 2021-10-24 04:11:07.712393 - step 25 of 48 - 2000 active elements (0 deactivated)
16:11:35 INFO    opendrift.models.basemodel: 2021-10-24 04:41:07.712393 - step 26 of 48 - 2000 active elements (0 deactivated)
16:11:36 INFO    opendrift.models.basemodel: 2021-10-24 05:11:07.712393 - step 27 of 48 - 2000 active elements (0 deactivated)
16:11:37 INFO    opendrift.models.basemodel: 2021-10-24 05:41:07.712393 - step 28 of 48 - 2000 active elements (0 deactivated)
16:11:37 INFO    opendrift.models.basemodel: 2021-10-24 06:11:07.712393 - step 29 of 48 - 2000 active elements (0 deactivated)
16:11:40 INFO    opendrift.models.basemodel: 2021-10-24 06:41:07.712393 - step 30 of 48 - 2000 active elements (0 deactivated)
16:11:40 INFO    opendrift.models.basemodel: 2021-10-24 07:11:07.712393 - step 31 of 48 - 2000 active elements (0 deactivated)
16:11:42 INFO    opendrift.models.basemodel: 2021-10-24 07:41:07.712393 - step 32 of 48 - 2000 active elements (0 deactivated)
16:11:42 INFO    opendrift.models.basemodel: 2021-10-24 08:11:07.712393 - step 33 of 48 - 2000 active elements (0 deactivated)
16:11:44 INFO    opendrift.models.basemodel: 2021-10-24 08:41:07.712393 - step 34 of 48 - 2000 active elements (0 deactivated)
16:11:44 WARNING opendrift.readers.basereader.structured: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (7) must be increased. See `Variables.set_buffer_size`.
16:11:44 INFO    opendrift.models.basemodel: 2021-10-24 09:11:07.712393 - step 35 of 48 - 2000 active elements (0 deactivated)
16:11:46 INFO    opendrift.models.basemodel: 2021-10-24 09:41:07.712393 - step 36 of 48 - 2000 active elements (0 deactivated)
16:11:46 INFO    opendrift.models.basemodel: 2021-10-24 10:11:07.712393 - step 37 of 48 - 2000 active elements (0 deactivated)
16:11:48 INFO    opendrift.models.basemodel: 2021-10-24 10:41:07.712393 - step 38 of 48 - 2000 active elements (0 deactivated)
16:11:48 INFO    opendrift.models.basemodel: 2021-10-24 11:11:07.712393 - step 39 of 48 - 2000 active elements (0 deactivated)
16:11:50 INFO    opendrift.models.basemodel: 2021-10-24 11:41:07.712393 - step 40 of 48 - 2000 active elements (0 deactivated)
16:11:50 WARNING opendrift.readers.basereader.structured: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (7) must be increased. See `Variables.set_buffer_size`.
16:11:50 INFO    opendrift.models.basemodel: 2021-10-24 12:11:07.712393 - step 41 of 48 - 2000 active elements (0 deactivated)
16:11:52 INFO    opendrift.models.basemodel: 2021-10-24 12:41:07.712393 - step 42 of 48 - 2000 active elements (0 deactivated)
16:11:52 WARNING opendrift.readers.basereader.structured: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (7) must be increased. See `Variables.set_buffer_size`.
16:11:52 INFO    opendrift.models.basemodel: 2021-10-24 13:11:07.712393 - step 43 of 48 - 2000 active elements (0 deactivated)
16:11:55 INFO    opendrift.models.basemodel: 2021-10-24 13:41:07.712393 - step 44 of 48 - 2000 active elements (0 deactivated)
16:11:55 WARNING opendrift.readers.basereader.structured: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (7) must be increased. See `Variables.set_buffer_size`.
16:11:55 INFO    opendrift.models.basemodel: 2021-10-24 14:11:07.712393 - step 45 of 48 - 2000 active elements (0 deactivated)
16:11:57 WARNING opendrift.readers.basereader.structured: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (7) must be increased. See `Variables.set_buffer_size`.
16:11:57 INFO    opendrift.models.basemodel: 2021-10-24 14:41:07.712393 - step 46 of 48 - 2000 active elements (0 deactivated)
16:11:57 WARNING opendrift.readers.basereader.structured: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (7) must be increased. See `Variables.set_buffer_size`.
16:11:57 INFO    opendrift.models.basemodel: 2021-10-24 15:11:07.712393 - step 47 of 48 - 2000 active elements (0 deactivated)
16:11:59 INFO    opendrift.models.basemodel: 2021-10-24 15:41:07.712393 - step 48 of 48 - 2000 active elements (0 deactivated)
16:11:59 WARNING opendrift.readers.basereader.structured: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (7) must be increased. See `Variables.set_buffer_size`.

Plot results with lines and particles colored by depth

print(o)
o.plot(linecolor='z', buffer=.1, show_particles=False, fast=False)
o.animation(color='z', buffer=.1, fast=True)
OpenDrift - OceanDrift 2021-10-23 16:11 to 2021-10-24 16:11 UTC (49 steps)

Out:

===========================
--------------------
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:46.0  total
 0:00:00.0  preparing
 0:00:44.2  reading
 0:00:00.6  interpolation
 0:00:00.0  interpolation_time
 0:00:01.8  rotating vectors
 0:00:00.0  masking
--------------------
Performance:
   52.4 total time
    0.3 configuration
    2.6 preparing main loop
      2.6 making dynamical landmask
      0.0 moving elements to ocean
     48.5 readers
        0.0 global_landmask
        0.1 postprocessing
   49.3 main loop
       46.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.7.1)
        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: 2021-10-23 16:11:07.712393
        Present: 2021-10-24 16:11:07.712393
        Calculation steps: 48 * 0:30:00 - total time: 1 day, 0:00:00
        Output steps: 49 * 0:30:00
===========================

16:12:36 WARNING opendrift.models.basemodel: Plotting fast. This will make your plots less accurate.
16:12:38 INFO    opendrift.models.basemodel: Saving animation to /root/project/docs/source/gallery/animations/example_depth_0.gif...
16:12:38 INFO    opendrift.models.basemodel: Making animated gif...
MovieWriter imagemagick unavailable; using Pillow instead.
../_images/example_depth_0.gif

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

Gallery generated by Sphinx-Gallery