.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/example_dominating.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_dominating.py: Show dominating source ====================== .. GENERATED FROM PYTHON SOURCE LINES 6-15 .. code-block:: Python import os from datetime import datetime import xarray as xr import opendrift from opendrift.models.oceandrift import OceanDrift of = 'test.nc' .. GENERATED FROM PYTHON SOURCE LINES 16-17 Seed elements at 5 different locations/longitudes .. GENERATED FROM PYTHON SOURCE LINES 17-27 .. code-block:: Python lons = [4, 4.2, 4.3, 4.32, 4.6] t = datetime.now() o = OceanDrift(loglevel=20) o.set_config('environment:constant:y_sea_water_velocity', .1) for i, lon in enumerate(lons): o.seed_elements(lon=lon, lat=60, radius=3000, number=2000, time=t, origin_marker_name='Lon %f' % lon) o.run(steps=15, outfile=of) .. rst-class:: sphx-glr-script-out .. code-block:: none 13:18:38 INFO opendrift:576: OpenDriftSimulation initialised (version 1.14.8 / v1.14.8-4-g48afd36) 13:18:38 INFO opendrift.models.basemodel.environment:203: Adding a global landmask from GSHHG 13:18:42 INFO opendrift.models.basemodel.environment:227: Fallback values will be used for the following variables which have no readers: 13:18:42 INFO opendrift.models.basemodel.environment:230: x_sea_water_velocity: 0.000000 13:18:42 INFO opendrift.models.basemodel.environment:230: sea_surface_height: 0.000000 13:18:42 INFO opendrift.models.basemodel.environment:230: x_wind: 0.000000 13:18:42 INFO opendrift.models.basemodel.environment:230: y_wind: 0.000000 13:18:42 INFO opendrift.models.basemodel.environment:230: upward_sea_water_velocity: 0.000000 13:18:42 INFO opendrift.models.basemodel.environment:230: ocean_vertical_diffusivity: 0.000000 13:18:42 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_significant_height: 0.000000 13:18:42 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_stokes_drift_x_velocity: 0.000000 13:18:42 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_stokes_drift_y_velocity: 0.000000 13:18:42 INFO opendrift.models.basemodel.environment:230: ocean_mixed_layer_thickness: 50.000000 13:18:42 INFO opendrift.models.basemodel.environment:230: sea_floor_depth_below_sea_level: 10000.000000 13:18:42 INFO opendrift:1810: Skipping environment variable ocean_vertical_diffusivity because of condition ['drift:vertical_mixing', 'is', False] 13:18:42 INFO opendrift:1810: Skipping environment variable ocean_mixed_layer_thickness because of condition ['drift:vertical_mixing', 'is', False] 13:18:42 INFO opendrift:1821: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous'])) 13:18:42 INFO opendrift:1821: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous'])) 13:18:42 INFO opendrift:1829: Storing previous values of environment variable sea_surface_height because of condition ['drift:vertical_advection', 'is', True] 13:18:42 INFO opendrift:952: Using existing reader for land_binary_mask to move elements to ocean 13:18:42 INFO opendrift:982: All points are in ocean 13:18:42 INFO opendrift:2118: 2026-01-28 13:18:38.262187 - step 1 of 15 - 10000 active elements (0 deactivated) 13:18:42 INFO opendrift:2118: 2026-01-28 14:18:38.262187 - step 2 of 15 - 10000 active elements (0 deactivated) 13:18:42 INFO opendrift:2118: 2026-01-28 15:18:38.262187 - step 3 of 15 - 10000 active elements (0 deactivated) 13:18:42 INFO opendrift:2118: 2026-01-28 16:18:38.262187 - step 4 of 15 - 10000 active elements (0 deactivated) 13:18:42 INFO opendrift:2118: 2026-01-28 17:18:38.262187 - step 5 of 15 - 10000 active elements (0 deactivated) 13:18:42 INFO opendrift:2118: 2026-01-28 18:18:38.262187 - step 6 of 15 - 10000 active elements (0 deactivated) 13:18:42 INFO opendrift:2118: 2026-01-28 19:18:38.262187 - step 7 of 15 - 10000 active elements (0 deactivated) 13:18:42 INFO opendrift:2118: 2026-01-28 20:18:38.262187 - step 8 of 15 - 10000 active elements (0 deactivated) 13:18:42 INFO opendrift:2118: 2026-01-28 21:18:38.262187 - step 9 of 15 - 10000 active elements (0 deactivated) 13:18:42 INFO opendrift:2118: 2026-01-28 22:18:38.262187 - step 10 of 15 - 10000 active elements (0 deactivated) 13:18:42 INFO opendrift:2118: 2026-01-28 23:18:38.262187 - step 11 of 15 - 10000 active elements (0 deactivated) 13:18:43 INFO opendrift:2118: 2026-01-29 00:18:38.262187 - step 12 of 15 - 10000 active elements (0 deactivated) 13:18:43 INFO opendrift:2118: 2026-01-29 01:18:38.262187 - step 13 of 15 - 10000 active elements (0 deactivated) 13:18:43 INFO opendrift:2118: 2026-01-29 02:18:38.262187 - step 14 of 15 - 10000 active elements (0 deactivated) 13:18:43 INFO opendrift:2118: 2026-01-29 03:18:38.262187 - step 15 of 15 - 10000 active elements (0 deactivated) .. raw:: html
<xarray.Dataset> Size: 15MB
    Dimensions:                                   (trajectory: 10000, time: 16)
    Coordinates:
      * trajectory                                (trajectory) int32 40kB 0 ... 9999
      * time                                      (time) datetime64[ns] 128B 2026...
    Data variables: (12/21)
        status                                    (trajectory, time) float64 1MB ...
        moving                                    (trajectory, time) float64 1MB ...
        age_seconds                               (trajectory, time) float32 640kB ...
        origin_marker                             (trajectory, time) float64 1MB ...
        lon                                       (trajectory, time) float32 640kB ...
        lat                                       (trajectory, time) float32 640kB ...
        ...                                        ...
        upward_sea_water_velocity                 (trajectory, time) float32 640kB ...
        sea_surface_wave_significant_height       (trajectory, time) float32 640kB ...
        sea_surface_wave_stokes_drift_x_velocity  (trajectory, time) float32 640kB ...
        sea_surface_wave_stokes_drift_y_velocity  (trajectory, time) float32 640kB ...
        sea_floor_depth_below_sea_level           (trajectory, time) float32 640kB ...
        land_binary_mask                          (trajectory, time) float32 640kB ...
    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:                                               0.0
        geospatial_vertical_max:                                               0.0
        geospatial_vertical_positive:                                          up


.. GENERATED FROM PYTHON SOURCE LINES 28-29 Calculate spatial density of elements at 1500m grid spacing .. GENERATED FROM PYTHON SOURCE LINES 29-34 .. code-block:: Python d = o.get_histogram(pixelsize_m=1500, weights=None) dom = d.argmax(dim='origin_marker', skipna=True) dom = dom.where(d.sum(dim='origin_marker')>0) dom.name = 'Dominating source' .. rst-class:: sphx-glr-script-out .. code-block:: none 13:18:44 INFO opendrift:3955: calculating for origin_marker 0... 13:18:44 INFO opendrift:3955: calculating for origin_marker 1... 13:18:44 INFO opendrift:3955: calculating for origin_marker 2... 13:18:44 INFO opendrift:3955: calculating for origin_marker 3... 13:18:44 INFO opendrift:3955: calculating for origin_marker 4... .. GENERATED FROM PYTHON SOURCE LINES 35-36 Show which of the 5 sources are dominating within each grid cell .. GENERATED FROM PYTHON SOURCE LINES 36-40 .. code-block:: Python o.animation(background=dom, show_elements=False, bgalpha=1, legend=list(o.origin_marker.values()), colorbar=False, vmin=0, vmax=4) .. rst-class:: sphx-glr-script-out .. code-block:: none 13:18:55 INFO opendrift:4675: Saving animation to /root/project/docs/source/gallery/animations/example_dominating_0.gif... 13:19:04 INFO opendrift:3101: Time to make animation: 0:00:20.226469 .. GENERATED FROM PYTHON SOURCE LINES 41-42 .. image:: /gallery/animations/example_dominating_0.gif .. GENERATED FROM PYTHON SOURCE LINES 42-44 .. code-block:: Python os.remove(of) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 32.192 seconds) .. _sphx_glr_download_gallery_example_dominating.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_dominating.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_dominating.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_dominating.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_