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
12:54:09 INFO opendrift.models.basemodel:515: OpenDriftSimulation initialised (version 1.11.13 / v1.11.13-99-gd2132d3)
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)
12:54:09 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...
12:54:13 INFO opendrift.models.basemodel.environment:245: Fallback values will be used for the following variables which have no readers:
12:54:13 INFO opendrift.models.basemodel.environment:248: x_sea_water_velocity: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: y_sea_water_velocity: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: sea_surface_height: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: x_wind: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: y_wind: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: upward_sea_water_velocity: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: ocean_vertical_diffusivity: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_significant_height: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_stokes_drift_x_velocity: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_stokes_drift_y_velocity: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_to_direction: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_peak_period_from_variance_spectral_density: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_significant_height: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_to_direction: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_mean_period: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_significant_height: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: surface_downward_x_stress: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: surface_downward_y_stress: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: turbulent_kinetic_energy: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: turbulent_generic_length_scale: 0.000000
12:54:13 INFO opendrift.models.basemodel.environment:248: ocean_mixed_layer_thickness: 50.000000
12:54:13 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)
12:54:14 INFO opendrift.models.basemodel:936: Using existing reader for land_binary_mask
12:54:14 INFO opendrift.models.basemodel:947: All points are in ocean
12:54:14 INFO opendrift.models.basemodel:2038: 2024-11-11 12:54:09.784063 - step 1 of 48 - 2000 active elements (0 deactivated)
12:54:14 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)
12:54:15 INFO opendrift.readers.reader_netCDF_CF_generic:325: Detected dimensions: {'x': 'X', 'y': 'Y', 'z': 'depth', 'time': 'time'}
12:54:18 INFO opendrift.models.basemodel:2038: 2024-11-11 13:24:09.784063 - step 2 of 48 - 2000 active elements (0 deactivated)
12:54:19 INFO opendrift.models.basemodel:2038: 2024-11-11 13:54:09.784063 - step 3 of 48 - 2000 active elements (0 deactivated)
12:54:19 INFO opendrift.models.basemodel:2038: 2024-11-11 14:24:09.784063 - step 4 of 48 - 2000 active elements (0 deactivated)
12:54:20 INFO opendrift.models.basemodel:2038: 2024-11-11 14:54:09.784063 - step 5 of 48 - 2000 active elements (0 deactivated)
12:54:20 INFO opendrift.models.basemodel:2038: 2024-11-11 15:24:09.784063 - step 6 of 48 - 2000 active elements (0 deactivated)
12:54:22 INFO opendrift.models.basemodel:2038: 2024-11-11 15:54:09.784063 - step 7 of 48 - 2000 active elements (0 deactivated)
12:54:22 INFO opendrift.models.basemodel:2038: 2024-11-11 16:24:09.784063 - step 8 of 48 - 2000 active elements (0 deactivated)
12:54:23 INFO opendrift.models.basemodel:2038: 2024-11-11 16:54:09.784063 - step 9 of 48 - 2000 active elements (0 deactivated)
12:54:23 INFO opendrift.models.basemodel:2038: 2024-11-11 17:24:09.784063 - step 10 of 48 - 2000 active elements (0 deactivated)
12:54:24 INFO opendrift.models.basemodel:2038: 2024-11-11 17:54:09.784063 - step 11 of 48 - 2000 active elements (0 deactivated)
12:54:24 INFO opendrift.models.basemodel:2038: 2024-11-11 18:24:09.784063 - step 12 of 48 - 2000 active elements (0 deactivated)
12:54:26 INFO opendrift.models.basemodel:2038: 2024-11-11 18:54:09.784063 - step 13 of 48 - 2000 active elements (0 deactivated)
12:54:26 INFO opendrift.models.basemodel:2038: 2024-11-11 19:24:09.784063 - step 14 of 48 - 2000 active elements (0 deactivated)
12:54:27 INFO opendrift.models.basemodel:2038: 2024-11-11 19:54:09.784063 - step 15 of 48 - 2000 active elements (0 deactivated)
12:54:27 INFO opendrift.models.basemodel:2038: 2024-11-11 20:24:09.784063 - step 16 of 48 - 2000 active elements (0 deactivated)
12:54:28 INFO opendrift.models.basemodel:2038: 2024-11-11 20:54:09.784063 - step 17 of 48 - 2000 active elements (0 deactivated)
12:54:28 INFO opendrift.models.basemodel:2038: 2024-11-11 21:24:09.784063 - step 18 of 48 - 2000 active elements (0 deactivated)
12:54:30 INFO opendrift.models.basemodel:2038: 2024-11-11 21:54:09.784063 - step 19 of 48 - 2000 active elements (0 deactivated)
12:54:30 INFO opendrift.models.basemodel:2038: 2024-11-11 22:24:09.784063 - step 20 of 48 - 2000 active elements (0 deactivated)
12:54:31 INFO opendrift.models.basemodel:2038: 2024-11-11 22:54:09.784063 - step 21 of 48 - 2000 active elements (0 deactivated)
12:54:32 INFO opendrift.models.basemodel:2038: 2024-11-11 23:24:09.784063 - step 22 of 48 - 2000 active elements (0 deactivated)
12:54:35 INFO opendrift.models.basemodel:2038: 2024-11-11 23:54:09.784063 - step 23 of 48 - 2000 active elements (0 deactivated)
12:54:35 INFO opendrift.models.basemodel:2038: 2024-11-12 00:24:09.784063 - step 24 of 48 - 2000 active elements (0 deactivated)
12:54:37 INFO opendrift.models.basemodel:2038: 2024-11-12 00:54:09.784063 - step 25 of 48 - 2000 active elements (0 deactivated)
12:54:37 INFO opendrift.models.basemodel:2038: 2024-11-12 01:24:09.784063 - step 26 of 48 - 2000 active elements (0 deactivated)
12:54:38 INFO opendrift.models.basemodel:2038: 2024-11-12 01:54:09.784063 - step 27 of 48 - 2000 active elements (0 deactivated)
12:54:38 INFO opendrift.models.basemodel:2038: 2024-11-12 02:24:09.784063 - step 28 of 48 - 2000 active elements (0 deactivated)
12:54:39 INFO opendrift.models.basemodel:2038: 2024-11-12 02:54:09.784063 - step 29 of 48 - 2000 active elements (0 deactivated)
12:54:39 INFO opendrift.models.basemodel:2038: 2024-11-12 03:24:09.784063 - step 30 of 48 - 2000 active elements (0 deactivated)
12:54:43 INFO opendrift.models.basemodel:2038: 2024-11-12 03:54:09.784063 - step 31 of 48 - 2000 active elements (0 deactivated)
12:54:43 INFO opendrift.models.basemodel:2038: 2024-11-12 04:24:09.784063 - step 32 of 48 - 2000 active elements (0 deactivated)
12:54:44 INFO opendrift.models.basemodel:2038: 2024-11-12 04:54:09.784063 - step 33 of 48 - 2000 active elements (0 deactivated)
12:54:45 INFO opendrift.models.basemodel:2038: 2024-11-12 05:24:09.784063 - step 34 of 48 - 2000 active elements (0 deactivated)
12:54:46 INFO opendrift.models.basemodel:2038: 2024-11-12 05:54:09.784063 - step 35 of 48 - 2000 active elements (0 deactivated)
12:54:46 INFO opendrift.models.basemodel:2038: 2024-11-12 06:24:09.784063 - step 36 of 48 - 2000 active elements (0 deactivated)
12:54:47 INFO opendrift.models.basemodel:2038: 2024-11-12 06:54:09.784063 - step 37 of 48 - 2000 active elements (0 deactivated)
12:54:47 INFO opendrift.models.basemodel:2038: 2024-11-12 07:24:09.784063 - step 38 of 48 - 2000 active elements (0 deactivated)
12:54:48 INFO opendrift.models.basemodel:2038: 2024-11-12 07:54:09.784063 - step 39 of 48 - 2000 active elements (0 deactivated)
12:54:48 INFO opendrift.models.basemodel:2038: 2024-11-12 08:24:09.784063 - step 40 of 48 - 2000 active elements (0 deactivated)
12:54:49 INFO opendrift.models.basemodel:2038: 2024-11-12 08:54:09.784063 - step 41 of 48 - 2000 active elements (0 deactivated)
12:54:49 INFO opendrift.models.basemodel:2038: 2024-11-12 09:24:09.784063 - step 42 of 48 - 2000 active elements (0 deactivated)
12:54:50 INFO opendrift.models.basemodel:2038: 2024-11-12 09:54:09.784063 - step 43 of 48 - 2000 active elements (0 deactivated)
/root/project/opendrift/readers/interpolation/interpolators.py:17: RuntimeWarning: overflow encountered in cast
data[mask] = np.finfo(np.float64).min
12:54:50 INFO opendrift.models.basemodel:2038: 2024-11-12 10:24:09.784063 - step 44 of 48 - 2000 active elements (0 deactivated)
12:54:51 INFO opendrift.models.basemodel:2038: 2024-11-12 10:54:09.784063 - step 45 of 48 - 2000 active elements (0 deactivated)
12:54:51 INFO opendrift.models.basemodel:2038: 2024-11-12 11:24:09.784063 - step 46 of 48 - 2000 active elements (0 deactivated)
12:54:54 INFO opendrift.models.basemodel:2038: 2024-11-12 11:54:09.784063 - step 47 of 48 - 2000 active elements (0 deactivated)
12:54:54 INFO opendrift.models.basemodel:2038: 2024-11-12 12:24:09.784063 - 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:01.5 total
0:00:00.0 preparing
0:00:01.5 reading
0:00:00.0 masking
--------------------
https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
0:00:36.7 total
0:00:00.0 preparing
0:00:35.8 reading
0:00:00.4 interpolation
0:00:00.0 interpolation_time
0:00:00.8 rotating vectors
0:00:00.0 masking
--------------------
Performance:
47.2 total time
4.5 configuration
0.0 preparing main loop
0.0 moving elements to ocean
41.1 main loop
0.1 updating elements
1.4 cleaning up
--------------------
===========================
Model: OceanDrift (OpenDrift version 1.11.13)
1999 active Lagrangian3DArray particles (1 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-11-11 12:54:09.784063 UTC
Present: 2024-11-12 12:54:09.784063 UTC
Calculation steps: 48 * 0:30:00 - total time: 1 day, 0:00:00
Output steps: 49 * 0:30:00
===========================
12:56:05 WARNING opendrift.models.basemodel:2411: Plotting fast. This will make your plots less accurate.
12:56:08 INFO opendrift.models.basemodel:4613: Saving animation to /root/project/docs/source/gallery/animations/example_depth_0.gif...
12:56:34 INFO opendrift.models.basemodel:3037: Time to make animation: 0:00:28.277436
Total running time of the script: (2 minutes 34.089 seconds)