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:14:38 INFO    opendrift.models.basemodel: OpenDriftSimulation initialised (version 1.6.0 / v1.6.0-161-g3380aa5)

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.6.0)
        0 active Lagrangian3DArray particles  (0 deactivated, 2000 scheduled)
-------------------
Environment variables:
  -----
Readers not added for the following variables:
  land_binary_mask
  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:14:38 INFO    opendrift.models.basemodel: Fallback values will be used for the following variables which have no readers:
16:14:38 INFO    opendrift.models.basemodel:    x_sea_water_velocity: 0.000000
16:14:38 INFO    opendrift.models.basemodel:    y_sea_water_velocity: 0.000000
16:14:38 INFO    opendrift.models.basemodel:    x_wind: 0.000000
16:14:38 INFO    opendrift.models.basemodel:    y_wind: 0.000000
16:14:38 INFO    opendrift.models.basemodel:    upward_sea_water_velocity: 0.000000
16:14:38 INFO    opendrift.models.basemodel:    ocean_vertical_diffusivity: 0.000000
16:14:38 INFO    opendrift.models.basemodel:    sea_surface_wave_significant_height: 0.000000
16:14:38 INFO    opendrift.models.basemodel:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
16:14:38 INFO    opendrift.models.basemodel:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
16:14:38 INFO    opendrift.models.basemodel:    sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
16:14:38 INFO    opendrift.models.basemodel:    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
16:14:38 INFO    opendrift.models.basemodel:    surface_downward_x_stress: 0.000000
16:14:38 INFO    opendrift.models.basemodel:    surface_downward_y_stress: 0.000000
16:14:38 INFO    opendrift.models.basemodel:    turbulent_kinetic_energy: 0.000000
16:14:38 INFO    opendrift.models.basemodel:    turbulent_generic_length_scale: 0.000000
16:14:38 INFO    opendrift.models.basemodel:    sea_floor_depth_below_sea_level: 10000.000000
16:14:38 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:14:40 INFO    opendrift.models.basemodel: Using existing reader for land_binary_mask
16:14:40 INFO    opendrift.models.basemodel: All points are in ocean
16:14:40 INFO    opendrift.models.basemodel: 2021-07-16 16:14:38.499999 - step 1 of 48 - 2000 active elements (0 deactivated)
16:14:41 INFO    opendrift.readers.reader_netCDF_CF_generic: Opening dataset: https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
16:14:43 INFO    opendrift.models.basemodel: 2021-07-16 16:44:38.499999 - step 2 of 48 - 2000 active elements (0 deactivated)
16:14:43 INFO    opendrift.models.basemodel: 2021-07-16 17:14:38.499999 - step 3 of 48 - 2000 active elements (0 deactivated)
16:14:44 INFO    opendrift.models.basemodel: 2021-07-16 17:44:38.499999 - step 4 of 48 - 2000 active elements (0 deactivated)
16:14:45 INFO    opendrift.models.basemodel: 2021-07-16 18:14:38.499999 - step 5 of 48 - 2000 active elements (0 deactivated)
16:14:46 INFO    opendrift.models.basemodel: 2021-07-16 18:44:38.499999 - step 6 of 48 - 2000 active elements (0 deactivated)
16:14:46 INFO    opendrift.models.basemodel: 2021-07-16 19:14:38.499999 - step 7 of 48 - 2000 active elements (0 deactivated)
16:14:47 INFO    opendrift.models.basemodel: 2021-07-16 19:44:38.499999 - step 8 of 48 - 2000 active elements (0 deactivated)
16:14:47 INFO    opendrift.models.basemodel: 2021-07-16 20:14:38.499999 - step 9 of 48 - 2000 active elements (0 deactivated)
16:14:48 INFO    opendrift.models.basemodel: 2021-07-16 20:44:38.499999 - step 10 of 48 - 2000 active elements (0 deactivated)
16:14:48 INFO    opendrift.models.basemodel: 2021-07-16 21:14:38.499999 - step 11 of 48 - 2000 active elements (0 deactivated)
16:14:49 INFO    opendrift.models.basemodel: 2021-07-16 21:44:38.499999 - step 12 of 48 - 2000 active elements (0 deactivated)
16:14:49 INFO    opendrift.models.basemodel: 2021-07-16 22:14:38.499999 - step 13 of 48 - 2000 active elements (0 deactivated)
16:14:50 INFO    opendrift.models.basemodel: 2021-07-16 22:44:38.499999 - step 14 of 48 - 2000 active elements (0 deactivated)
16:14:50 INFO    opendrift.models.basemodel: 2021-07-16 23:14:38.499999 - step 15 of 48 - 2000 active elements (0 deactivated)
16:14:51 INFO    opendrift.models.basemodel: 2021-07-16 23:44:38.499999 - step 16 of 48 - 2000 active elements (0 deactivated)
16:14:51 INFO    opendrift.models.basemodel: 2021-07-17 00:14:38.499999 - step 17 of 48 - 2000 active elements (0 deactivated)
16:14:52 INFO    opendrift.models.basemodel: 2021-07-17 00:44:38.499999 - step 18 of 48 - 2000 active elements (0 deactivated)
16:14:52 INFO    opendrift.models.basemodel: 2021-07-17 01:14:38.499999 - step 19 of 48 - 2000 active elements (0 deactivated)
16:14:53 INFO    opendrift.models.basemodel: 2021-07-17 01:44:38.499999 - step 20 of 48 - 2000 active elements (0 deactivated)
16:14:53 INFO    opendrift.models.basemodel: 2021-07-17 02:14:38.499999 - step 21 of 48 - 2000 active elements (0 deactivated)
16:14:54 INFO    opendrift.models.basemodel: 2021-07-17 02:44:38.499999 - step 22 of 48 - 2000 active elements (0 deactivated)
16:14:54 INFO    opendrift.models.basemodel: 2021-07-17 03:14:38.499999 - step 23 of 48 - 2000 active elements (0 deactivated)
16:14:55 INFO    opendrift.models.basemodel: 2021-07-17 03:44:38.499999 - step 24 of 48 - 2000 active elements (0 deactivated)
16:14:55 INFO    opendrift.models.basemodel: 2021-07-17 04:14:38.499999 - step 25 of 48 - 2000 active elements (0 deactivated)
16:14:57 INFO    opendrift.models.basemodel: 2021-07-17 04:44:38.499999 - step 26 of 48 - 2000 active elements (0 deactivated)
16:14:57 INFO    opendrift.models.basemodel: 2021-07-17 05:14:38.499999 - step 27 of 48 - 2000 active elements (0 deactivated)
16:14:58 INFO    opendrift.models.basemodel: 2021-07-17 05:44:38.499999 - step 28 of 48 - 2000 active elements (0 deactivated)
16:14:58 INFO    opendrift.models.basemodel: 2021-07-17 06:14:38.499999 - step 29 of 48 - 2000 active elements (0 deactivated)
16:14:59 INFO    opendrift.models.basemodel: 2021-07-17 06:44:38.499999 - step 30 of 48 - 2000 active elements (0 deactivated)
16:15:00 INFO    opendrift.models.basemodel: 2021-07-17 07:14:38.499999 - step 31 of 48 - 2000 active elements (0 deactivated)
16:15:01 INFO    opendrift.models.basemodel: 2021-07-17 07:44:38.499999 - step 32 of 48 - 2000 active elements (0 deactivated)
16:15:01 INFO    opendrift.models.basemodel: 2021-07-17 08:14:38.499999 - step 33 of 48 - 2000 active elements (0 deactivated)
16:15:02 INFO    opendrift.models.basemodel: 2021-07-17 08:44:38.499999 - step 34 of 48 - 2000 active elements (0 deactivated)
16:15:02 INFO    opendrift.models.basemodel: 2021-07-17 09:14:38.499999 - step 35 of 48 - 2000 active elements (0 deactivated)
16:15:03 INFO    opendrift.models.basemodel: 2021-07-17 09:44:38.499999 - step 36 of 48 - 2000 active elements (0 deactivated)
16:15:03 INFO    opendrift.models.basemodel: 2021-07-17 10:14:38.499999 - step 37 of 48 - 2000 active elements (0 deactivated)
16:15:04 INFO    opendrift.models.basemodel: 2021-07-17 10:44:38.499999 - step 38 of 48 - 2000 active elements (0 deactivated)
16:15:04 INFO    opendrift.models.basemodel: 2021-07-17 11:14:38.499999 - step 39 of 48 - 2000 active elements (0 deactivated)
16:15:05 INFO    opendrift.models.basemodel: 2021-07-17 11:44:38.499999 - step 40 of 48 - 2000 active elements (0 deactivated)
16:15:05 INFO    opendrift.models.basemodel: 2021-07-17 12:14:38.499999 - step 41 of 48 - 2000 active elements (0 deactivated)
16:15:06 INFO    opendrift.models.basemodel: 2021-07-17 12:44:38.499999 - step 42 of 48 - 2000 active elements (0 deactivated)
16:15:06 INFO    opendrift.models.basemodel: 2021-07-17 13:14:38.499999 - step 43 of 48 - 2000 active elements (0 deactivated)
16:15:07 INFO    opendrift.models.basemodel: 2021-07-17 13:44:38.499999 - step 44 of 48 - 2000 active elements (0 deactivated)
16:15:07 INFO    opendrift.models.basemodel: 2021-07-17 14:14:38.499999 - step 45 of 48 - 2000 active elements (0 deactivated)
16:15:08 INFO    opendrift.models.basemodel: 2021-07-17 14:44:38.499999 - step 46 of 48 - 2000 active elements (0 deactivated)
16:15:08 INFO    opendrift.models.basemodel: 2021-07-17 15:14:38.499999 - step 47 of 48 - 2000 active elements (0 deactivated)
16:15:09 INFO    opendrift.models.basemodel: 2021-07-17 15:44:38.499999 - 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_particles=False, fast=False)
o.animation(color='z', buffer=.1, fast=True)
OpenDrift - OceanDrift 2021-07-16 16:14 to 2021-07-17 16:14 UTC (49 steps)

Out:

===========================
--------------------
Reader performance:
--------------------
global_landmask
 0:00:00.1  total
 0:00:00.0  preparing
 0:00:00.1  reading
 0:00:00.0  masking
--------------------
https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
 0:00:27.4  total
 0:00:00.0  preparing
 0:00:25.7  reading
 0:00:00.5  interpolation
 0:00:00.0  interpolation_time
 0:00:01.7  rotating vectors
 0:00:00.0  masking
--------------------
Performance:
   31.9 total time
    0.2 configuration
    2.4 preparing main loop
      2.4 making dynamical landmask
      0.0 moving elements to ocean
     28.6 readers
        0.1 global_landmask
        0.1 postprocessing
   29.0 main loop
       27.5 https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
      0.1 updating elements
    0.1 cleaning up
--------------------
===========================
Model:  OceanDrift     (OpenDrift version 1.6.0)
        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_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-07-16 16:14:38.499999
        Present: 2021-07-17 16:14:38.499999
        Calculation steps: 48 * 0:30:00 - total time: 1 day, 0:00:00
        Output steps: 49 * 0:30:00
===========================

16:15:58 WARNING opendrift.models.basemodel: Plotting fast. This will make your plots less accurate.
16:15:59 INFO    opendrift.models.basemodel: Saving animation to /root/project/docs/source/gallery/animations/example_depth_0.gif...
16:15:59 INFO    opendrift.models.basemodel: Making animated gif...
../_images/example_depth_0.gif

Total running time of the script: ( 3 minutes 18.310 seconds)

Gallery generated by Sphinx-Gallery