.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/example_2d.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_2d.py: 2D simulation profile ===================== .. 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 17:12:54 INFO opendrift:513: OpenDriftSimulation initialised (version 1.14.2 / v1.14.2-88-gf09b7bd) .. GENERATED FROM PYTHON SOURCE LINES 14-15 Define some constant current, wind and Stokes drift .. GENERATED FROM PYTHON SOURCE LINES 15-20 .. code-block:: Python o.set_config('environment:fallback:x_wind', 7) o.set_config('environment:fallback:x_sea_water_velocity', .1) o.set_config('environment:fallback:sea_surface_wave_stokes_drift_x_velocity', .2) o.set_config('environment:fallback:sea_surface_wave_significant_height', 2) .. GENERATED FROM PYTHON SOURCE LINES 21-22 Seed elements between surface and 5m depth .. GENERATED FROM PYTHON SOURCE LINES 22-26 .. code-block:: Python time = datetime.utcnow() z = -np.linspace(0, 5, 50) o.seed_elements(lon=4.5, lat=60.0, z=z, radius=0, number=len(z), time=time) .. rst-class:: sphx-glr-script-out .. code-block:: none /root/project/examples/example_2d.py:22: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC). time = datetime.utcnow() 17:12:54 INFO opendrift.models.basemodel.environment:206: Adding a global landmask from GSHHG 17:12:59 INFO opendrift.models.basemodel.environment:229: Fallback values will be used for the following variables which have no readers: 17:12:59 INFO opendrift.models.basemodel.environment:232: x_sea_water_velocity: 0.100000 17:12:59 INFO opendrift.models.basemodel.environment:232: y_sea_water_velocity: 0.000000 17:12:59 INFO opendrift.models.basemodel.environment:232: sea_surface_height: 0.000000 17:12:59 INFO opendrift.models.basemodel.environment:232: x_wind: 7.000000 17:12:59 INFO opendrift.models.basemodel.environment:232: y_wind: 0.000000 17:12:59 INFO opendrift.models.basemodel.environment:232: upward_sea_water_velocity: 0.000000 17:12:59 INFO opendrift.models.basemodel.environment:232: ocean_vertical_diffusivity: 0.000000 17:12:59 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_significant_height: 2.000000 17:12:59 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_x_velocity: 0.200000 17:12:59 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_y_velocity: 0.000000 17:12:59 INFO opendrift.models.basemodel.environment:232: ocean_mixed_layer_thickness: 50.000000 17:12:59 INFO opendrift.models.basemodel.environment:232: sea_floor_depth_below_sea_level: 10000.000000 .. GENERATED FROM PYTHON SOURCE LINES 27-28 Running model for 6 hours .. GENERATED FROM PYTHON SOURCE LINES 28-30 .. code-block:: Python o.run(duration=timedelta(hours=6), time_step=600) .. rst-class:: sphx-glr-script-out .. code-block:: none 17:12:59 INFO opendrift:1732: Skipping environment variable ocean_vertical_diffusivity because of condition ['drift:vertical_mixing', 'is', False] 17:12:59 INFO opendrift:1732: Skipping environment variable ocean_mixed_layer_thickness because of condition ['drift:vertical_mixing', 'is', False] 17:12:59 INFO opendrift:1743: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous'])) 17:12:59 INFO opendrift:1743: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous'])) 17:12:59 INFO opendrift:1751: Storing previous values of environment variable sea_surface_height because of condition ['drift:vertical_advection', 'is', True] 17:12:59 INFO opendrift:899: Using existing reader for land_binary_mask 17:12:59 INFO opendrift:928: All points are in ocean 17:12:59 INFO opendrift:2035: 2025-07-11 17:12:54.924711 - step 1 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 17:22:54.924711 - step 2 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 17:32:54.924711 - step 3 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 17:42:54.924711 - step 4 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 17:52:54.924711 - step 5 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 18:02:54.924711 - step 6 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 18:12:54.924711 - step 7 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 18:22:54.924711 - step 8 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 18:32:54.924711 - step 9 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 18:42:54.924711 - step 10 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 18:52:54.924711 - step 11 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 19:02:54.924711 - step 12 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 19:12:54.924711 - step 13 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 19:22:54.924711 - step 14 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 19:32:54.924711 - step 15 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 19:42:54.924711 - step 16 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 19:52:54.924711 - step 17 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 20:02:54.924711 - step 18 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 20:12:54.924711 - step 19 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 20:22:54.924711 - step 20 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 20:32:54.924711 - step 21 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 20:42:54.924711 - step 22 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 20:52:54.924711 - step 23 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 21:02:54.924711 - step 24 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 21:12:54.924711 - step 25 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 21:22:54.924711 - step 26 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 21:32:54.924711 - step 27 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 21:42:54.924711 - step 28 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 21:52:54.924711 - step 29 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 22:02:54.924711 - step 30 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 22:12:54.924711 - step 31 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 22:22:54.924711 - step 32 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 22:32:54.924711 - step 33 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 22:42:54.924711 - step 34 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 22:52:54.924711 - step 35 of 36 - 50 active elements (0 deactivated) 17:12:59 INFO opendrift:2035: 2025-07-11 23:02:54.924711 - step 36 of 36 - 50 active elements (0 deactivated) .. raw:: html
<xarray.Dataset> Size: 156kB
    Dimensions:                                   (trajectory: 50, time: 37)
    Coordinates:
      * trajectory                                (trajectory) int64 400B 0 1 ... 49
      * time                                      (time) datetime64[ns] 296B 2025...
    Data variables: (12/21)
        status                                    (trajectory, time) float32 7kB ...
        moving                                    (trajectory, time) float32 7kB ...
        age_seconds                               (trajectory, time) float32 7kB ...
        origin_marker                             (trajectory, time) float32 7kB ...
        lon                                       (trajectory, time) float32 7kB ...
        lat                                       (trajectory, time) float32 7kB ...
        ...                                        ...
        upward_sea_water_velocity                 (trajectory, time) float32 7kB ...
        sea_surface_wave_significant_height       (trajectory, time) float32 7kB ...
        sea_surface_wave_stokes_drift_x_velocity  (trajectory, time) float32 7kB ...
        sea_surface_wave_stokes_drift_y_velocity  (trajectory, time) float32 7kB ...
        sea_floor_depth_below_sea_level           (trajectory, time) float32 7kB ...
        land_binary_mask                          (trajectory, time) float32 7kB ...
    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.0
        geospatial_vertical_max:                                               -0.0
        geospatial_vertical_positive:                                          up


.. GENERATED FROM PYTHON SOURCE LINES 31-32 To check that z is really kept constant for all particles .. GENERATED FROM PYTHON SOURCE LINES 32-34 .. code-block:: Python o.plot_property('z') .. image-sg:: /gallery/images/sphx_glr_example_2d_001.png :alt: z :srcset: /gallery/images/sphx_glr_example_2d_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 35-36 Vertical profile of advection. Note the decaying importance of Stokes drift, and the additional windage of the element at surface .. GENERATED FROM PYTHON SOURCE LINES 36-38 .. code-block:: Python o.animation_profile() .. rst-class:: sphx-glr-script-out .. code-block:: none 17:13:00 INFO opendrift:4553: Saving animation to /root/project/docs/source/gallery/animations/example_2d_0.gif... 17:13:06 INFO opendrift:3204: Time to make animation: 0:00:06.020720 .. GENERATED FROM PYTHON SOURCE LINES 39-40 .. image:: /gallery/animations/example_2d_0.gif .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 18.123 seconds) .. _sphx_glr_download_gallery_example_2d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_2d.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_2d.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_2d.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_