.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/example_depth.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_example_depth.py: Drift at different depths ========================== .. GENERATED FROM PYTHON SOURCE LINES 6-13 .. code-block:: Python 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 .. rst-class:: sphx-glr-script-out .. code-block:: none 15:18:53 INFO opendrift:568: OpenDriftSimulation initialised (version 1.14.3 / v1.14.3-4-ga7b402c) .. GENERATED FROM PYTHON SOURCE LINES 14-15 Using live data from Thredds .. GENERATED FROM PYTHON SOURCE LINES 15-18 .. code-block:: Python o.add_readers_from_list([ 'https://thredds.met.no/thredds/dodsC/fou-hi/norkystv3_800m_m00_be']) .. GENERATED FROM PYTHON SOURCE LINES 19-20 Adding some diffusion .. GENERATED FROM PYTHON SOURCE LINES 20-22 .. code-block:: Python o.set_config('drift:horizontal_diffusivity', 10) # m2/s .. GENERATED FROM PYTHON SOURCE LINES 23-24 Seed 1000 elements at random depths .. GENERATED FROM PYTHON SOURCE LINES 24-30 .. code-block:: Python z = -np.random.rand(2000)*50 o.seed_elements(lon=4.8, lat=60.0, z=z, radius=0, number=2000, time=datetime.now()) print(o) .. rst-class:: sphx-glr-script-out .. code-block:: none 15:18:53 INFO opendrift.models.basemodel.environment:206: Adding a global landmask from GSHHG 15:18:58 INFO opendrift.models.basemodel.environment:229: Fallback values will be used for the following variables which have no readers: 15:18:58 INFO opendrift.models.basemodel.environment:232: x_sea_water_velocity: 0.000000 15:18:58 INFO opendrift.models.basemodel.environment:232: y_sea_water_velocity: 0.000000 15:18:58 INFO opendrift.models.basemodel.environment:232: sea_surface_height: 0.000000 15:18:58 INFO opendrift.models.basemodel.environment:232: x_wind: 0.000000 15:18:58 INFO opendrift.models.basemodel.environment:232: y_wind: 0.000000 15:18:58 INFO opendrift.models.basemodel.environment:232: upward_sea_water_velocity: 0.000000 15:18:58 INFO opendrift.models.basemodel.environment:232: ocean_vertical_diffusivity: 0.000000 15:18:58 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_significant_height: 0.000000 15:18:58 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_x_velocity: 0.000000 15:18:58 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_y_velocity: 0.000000 15:18:58 INFO opendrift.models.basemodel.environment:232: ocean_mixed_layer_thickness: 50.000000 15:18:58 INFO opendrift.models.basemodel.environment:232: sea_floor_depth_below_sea_level: 10000.000000 =========================== Model: OceanDrift (OpenDrift version 1.14.3) 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_wave_significant_height sea_surface_wave_stokes_drift_x_velocity sea_surface_wave_stokes_drift_y_velocity 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/fou-hi/norkystv3_800m_m00_be Discarded readers: =========================== .. GENERATED FROM PYTHON SOURCE LINES 31-32 Running model .. GENERATED FROM PYTHON SOURCE LINES 32-34 .. code-block:: Python o.run(duration=timedelta(hours=24), time_step=1800) .. rst-class:: sphx-glr-script-out .. code-block:: none 15:18:58 INFO opendrift:1778: Skipping environment variable ocean_vertical_diffusivity because of condition ['drift:vertical_mixing', 'is', False] 15:18:58 INFO opendrift:1778: Skipping environment variable ocean_mixed_layer_thickness because of condition ['drift:vertical_mixing', 'is', False] 15:18:58 INFO opendrift:1789: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous'])) 15:18:58 INFO opendrift:1789: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous'])) 15:18:58 INFO opendrift:1797: Storing previous values of environment variable sea_surface_height because of condition ['drift:vertical_advection', 'is', True] 15:18:58 INFO opendrift:944: Using existing reader for land_binary_mask to move elements to ocean 15:18:58 INFO opendrift:974: All points are in ocean 15:18:58 INFO opendrift:2085: 2025-09-12 15:18:53.053154 - step 1 of 48 - 2000 active elements (0 deactivated) 15:18:58 INFO opendrift.readers:61: Opening file with xr.open_dataset 15:19:01 INFO opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'x': 'X', 'y': 'Y', 'z': 'depth', 'time': 'time'} 15:19:01 INFO opendrift.readers.basereader:176: Variable x_sea_water_velocity will be rotated from eastward_sea_water_velocity 15:19:01 INFO opendrift.readers.basereader:176: Variable y_sea_water_velocity will be rotated from northward_sea_water_velocity 15:19:01 INFO opendrift.readers.basereader:176: Variable x_wind will be rotated from eastward_wind 15:19:01 INFO opendrift.readers.basereader:176: Variable y_wind will be rotated from northward_wind 15:19:04 INFO opendrift:2085: 2025-09-12 15:48:53.053154 - step 2 of 48 - 2000 active elements (0 deactivated) 15:19:04 INFO opendrift:2085: 2025-09-12 16:18:53.053154 - step 3 of 48 - 2000 active elements (0 deactivated) 15:19:06 INFO opendrift:2085: 2025-09-12 16:48:53.053154 - step 4 of 48 - 2000 active elements (0 deactivated) 15:19:06 INFO opendrift:2085: 2025-09-12 17:18:53.053154 - step 5 of 48 - 2000 active elements (0 deactivated) 15:19:08 INFO opendrift:2085: 2025-09-12 17:48:53.053154 - step 6 of 48 - 2000 active elements (0 deactivated) 15:19:08 INFO opendrift:2085: 2025-09-12 18:18:53.053154 - step 7 of 48 - 2000 active elements (0 deactivated) 15:19:10 INFO opendrift:2085: 2025-09-12 18:48:53.053154 - step 8 of 48 - 2000 active elements (0 deactivated) 15:19:10 INFO opendrift:2085: 2025-09-12 19:18:53.053154 - step 9 of 48 - 2000 active elements (0 deactivated) 15:19:12 INFO opendrift:2085: 2025-09-12 19:48:53.053154 - step 10 of 48 - 2000 active elements (0 deactivated) 15:19:12 INFO opendrift:2085: 2025-09-12 20:18:53.053154 - step 11 of 48 - 2000 active elements (0 deactivated) 15:19:14 INFO opendrift:2085: 2025-09-12 20:48:53.053154 - step 12 of 48 - 2000 active elements (0 deactivated) 15:19:14 INFO opendrift:2085: 2025-09-12 21:18:53.053154 - step 13 of 48 - 2000 active elements (0 deactivated) 15:19:17 INFO opendrift:2085: 2025-09-12 21:48:53.053154 - step 14 of 48 - 2000 active elements (0 deactivated) 15:19:17 INFO opendrift:2085: 2025-09-12 22:18:53.053154 - step 15 of 48 - 2000 active elements (0 deactivated) 15:19:20 INFO opendrift:2085: 2025-09-12 22:48:53.053154 - step 16 of 48 - 2000 active elements (0 deactivated) 15:19:20 INFO opendrift:2085: 2025-09-12 23:18:53.053154 - step 17 of 48 - 2000 active elements (0 deactivated) 15:19:21 INFO opendrift:2085: 2025-09-12 23:48:53.053154 - step 18 of 48 - 2000 active elements (0 deactivated) 15:19:21 INFO opendrift:2085: 2025-09-13 00:18:53.053154 - step 19 of 48 - 2000 active elements (0 deactivated) 15:19:23 INFO opendrift:2085: 2025-09-13 00:48:53.053154 - step 20 of 48 - 2000 active elements (0 deactivated) 15:19:23 INFO opendrift:2085: 2025-09-13 01:18:53.053154 - step 21 of 48 - 2000 active elements (0 deactivated) 15:19:24 INFO opendrift:2085: 2025-09-13 01:48:53.053154 - step 22 of 48 - 2000 active elements (0 deactivated) 15:19:24 INFO opendrift:2085: 2025-09-13 02:18:53.053154 - step 23 of 48 - 2000 active elements (0 deactivated) 15:19:25 INFO opendrift:2085: 2025-09-13 02:48:53.053154 - step 24 of 48 - 2000 active elements (0 deactivated) 15:19:25 INFO opendrift:2085: 2025-09-13 03:18:53.053154 - step 25 of 48 - 2000 active elements (0 deactivated) 15:19:27 INFO opendrift:2085: 2025-09-13 03:48:53.053154 - step 26 of 48 - 2000 active elements (0 deactivated) 15:19:27 INFO opendrift:2085: 2025-09-13 04:18:53.053154 - step 27 of 48 - 2000 active elements (0 deactivated) 15:19:28 INFO opendrift:2085: 2025-09-13 04:48:53.053154 - step 28 of 48 - 2000 active elements (0 deactivated) 15:19:28 INFO opendrift:2085: 2025-09-13 05:18:53.053154 - step 29 of 48 - 2000 active elements (0 deactivated) 15:19:29 INFO opendrift:2085: 2025-09-13 05:48:53.053154 - step 30 of 48 - 2000 active elements (0 deactivated) 15:19:29 INFO opendrift:2085: 2025-09-13 06:18:53.053154 - step 31 of 48 - 2000 active elements (0 deactivated) 15:19:31 INFO opendrift:2085: 2025-09-13 06:48:53.053154 - step 32 of 48 - 2000 active elements (0 deactivated) 15:19:31 INFO opendrift:2085: 2025-09-13 07:18:53.053154 - step 33 of 48 - 2000 active elements (0 deactivated) 15:19:33 INFO opendrift:2085: 2025-09-13 07:48:53.053154 - step 34 of 48 - 2000 active elements (0 deactivated) 15:19:33 INFO opendrift:2085: 2025-09-13 08:18:53.053154 - step 35 of 48 - 2000 active elements (0 deactivated) 15:19:34 INFO opendrift:2085: 2025-09-13 08:48:53.053154 - step 36 of 48 - 2000 active elements (0 deactivated) 15:19:34 INFO opendrift:2085: 2025-09-13 09:18:53.053154 - step 37 of 48 - 2000 active elements (0 deactivated) 15:19:35 INFO opendrift:2085: 2025-09-13 09:48:53.053154 - step 38 of 48 - 2000 active elements (0 deactivated) 15:19:36 INFO opendrift:2085: 2025-09-13 10:18:53.053154 - step 39 of 48 - 2000 active elements (0 deactivated) 15:19:37 INFO opendrift:2085: 2025-09-13 10:48:53.053154 - step 40 of 48 - 2000 active elements (0 deactivated) 15:19:37 INFO opendrift:2085: 2025-09-13 11:18:53.053154 - step 41 of 48 - 2000 active elements (0 deactivated) 15:19:39 INFO opendrift:2085: 2025-09-13 11:48:53.053154 - step 42 of 48 - 2000 active elements (0 deactivated) 15:19:39 INFO opendrift:2085: 2025-09-13 12:18:53.053154 - step 43 of 48 - 2000 active elements (0 deactivated) 15:19:40 INFO opendrift:2085: 2025-09-13 12:48:53.053154 - step 44 of 48 - 2000 active elements (0 deactivated) 15:19:40 INFO opendrift:2085: 2025-09-13 13:18:53.053154 - step 45 of 48 - 2000 active elements (0 deactivated) 15:19:41 INFO opendrift:2085: 2025-09-13 13:48:53.053154 - step 46 of 48 - 2000 active elements (0 deactivated) 15:19:41 INFO opendrift:2085: 2025-09-13 14:18:53.053154 - step 47 of 48 - 2000 active elements (0 deactivated) 15:19:43 INFO opendrift:2085: 2025-09-13 14:48:53.053154 - step 48 of 48 - 2000 active elements (0 deactivated) .. raw:: html
<xarray.Dataset> Size: 8MB
    Dimensions:                                   (trajectory: 2000, time: 49)
    Coordinates:
      * trajectory                                (trajectory) int64 16kB 0 ... 1999
      * time                                      (time) datetime64[ns] 392B 2025...
    Data variables: (12/21)
        status                                    (trajectory, time) float32 392kB ...
        moving                                    (trajectory, time) float32 392kB ...
        age_seconds                               (trajectory, time) float32 392kB ...
        origin_marker                             (trajectory, time) float32 392kB ...
        lon                                       (trajectory, time) float32 392kB ...
        lat                                       (trajectory, time) float32 392kB ...
        ...                                        ...
        upward_sea_water_velocity                 (trajectory, time) float32 392kB ...
        sea_surface_wave_significant_height       (trajectory, time) float32 392kB ...
        sea_surface_wave_stokes_drift_x_velocity  (trajectory, time) float32 392kB ...
        sea_surface_wave_stokes_drift_y_velocity  (trajectory, time) float32 392kB ...
        sea_floor_depth_below_sea_level           (trajectory, time) float32 392kB ...
        land_binary_mask                          (trajectory, time) float32 392kB ...
    Attributes: (12/119)
        Conventions:                                                           CF...
        standard_name_vocabulary:                                              CF...
        featureType:                                                           tr...
        title:                                                                 Op...
        summary:                                                               Ou...
        keywords:                                                              tr...
        ...                                                                    ...
        geospatial_lon_units:                                                  de...
        geospatial_lon_resolution:                                             point
        runtime:                                                               0:...
        geospatial_vertical_min:                                               -5...
        geospatial_vertical_max:                                               0.0
        geospatial_vertical_positive:                                          up


.. GENERATED FROM PYTHON SOURCE LINES 35-36 Plot results with lines and particles colored by depth .. GENERATED FROM PYTHON SOURCE LINES 36-40 .. code-block:: Python print(o) o.plot(linecolor='z', buffer=.1, show_elements=False) o.animation(color='z', buffer=.1) .. image-sg:: /gallery/images/sphx_glr_example_depth_001.png :alt: OpenDrift - OceanDrift 2025-09-12 15:18 to 2025-09-13 15:18 UTC (49 steps) :srcset: /gallery/images/sphx_glr_example_depth_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none =========================== -------------------- 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/fou-hi/norkystv3_800m_m00_be 0:00:40.1 total 0:00:00.0 preparing 0:00:39.7 reading 0:00:00.8 interpolation 0:00:00.0 interpolation_time 0:00:00.4 rotating vectors 0:00:00.0 masking -------------------- Performance: 51.6 total time 5.2 configuration 0.0 preparing main loop 0.0 moving elements to ocean 44.7 main loop 0.1 updating elements 1.5 cleaning up -------------------- =========================== Model: OceanDrift (OpenDrift version 1.14.3) 2000 active Lagrangian3DArray particles (0 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/fou-hi/norkystv3_800m_m00_be ----- Readers not added for the following variables: sea_surface_wave_significant_height sea_surface_wave_stokes_drift_x_velocity sea_surface_wave_stokes_drift_y_velocity Discarded readers: Time: Start: 2025-09-12 15:18:53.053154 UTC Present: 2025-09-13 15:18:53.053154 UTC Calculation steps: 48 * 0:30:00 - total time: 1 day, 0:00:00 Output steps: 49 * 0:30:00 =========================== 15:20:45 INFO opendrift:4612: Saving animation to /root/project/docs/source/gallery/animations/example_depth_0.gif... 15:21:19 INFO opendrift:3053: Time to make animation: 0:00:35.599888 .. GENERATED FROM PYTHON SOURCE LINES 41-41 .. image:: /gallery/animations/example_depth_0.gif .. rst-class:: sphx-glr-timing **Total running time of the script:** (2 minutes 35.695 seconds) .. _sphx_glr_download_gallery_example_depth.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_depth.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_depth.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_depth.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_