.. 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 21:49:02 INFO opendrift.models.basemodel:529: OpenDriftSimulation initialised (version 1.11.1 / v1.11.1-74-g4504ea0) 21:49:02 INFO opendrift.models.basemodel.environment:220: Adding a dynamical landmask with max. priority based on assumed maximum speed of 1.0 m/s. Adding a customised landmask may be faster... 21:49:08 INFO opendrift.models.basemodel.environment:247: Fallback values will be used for the following variables which have no readers: 21:49:08 INFO opendrift.models.basemodel.environment:250: x_sea_water_velocity: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: x_wind: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: y_wind: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: upward_sea_water_velocity: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: ocean_vertical_diffusivity: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: sea_surface_wave_significant_height: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: sea_surface_wave_stokes_drift_x_velocity: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: sea_surface_wave_stokes_drift_y_velocity: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: sea_surface_swell_wave_to_direction: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: sea_surface_swell_wave_peak_period_from_variance_spectral_density: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: sea_surface_swell_wave_significant_height: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: sea_surface_wind_wave_to_direction: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: sea_surface_wind_wave_mean_period: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: sea_surface_wind_wave_significant_height: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: surface_downward_x_stress: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: surface_downward_y_stress: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: turbulent_kinetic_energy: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: turbulent_generic_length_scale: 0.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: ocean_mixed_layer_thickness: 50.000000 21:49:08 INFO opendrift.models.basemodel.environment:250: sea_floor_depth_below_sea_level: 10000.000000 21:49:08 INFO opendrift.models.basemodel:892: Using existing reader for land_binary_mask 21:49:08 INFO opendrift.models.basemodel:904: All points are in ocean 21:49:08 INFO opendrift.models.basemodel:1995: 2024-03-24 21:49:02.705765 - step 1 of 15 - 10000 active elements (0 deactivated) 21:49:09 INFO opendrift.models.basemodel:1995: 2024-03-24 22:49:02.705765 - step 2 of 15 - 10000 active elements (0 deactivated) 21:49:09 INFO opendrift.models.basemodel:1995: 2024-03-24 23:49:02.705765 - step 3 of 15 - 10000 active elements (0 deactivated) 21:49:09 INFO opendrift.models.basemodel:1995: 2024-03-25 00:49:02.705765 - step 4 of 15 - 10000 active elements (0 deactivated) 21:49:09 INFO opendrift.models.basemodel:1995: 2024-03-25 01:49:02.705765 - step 5 of 15 - 10000 active elements (0 deactivated) 21:49:09 INFO opendrift.models.basemodel:1995: 2024-03-25 02:49:02.705765 - step 6 of 15 - 10000 active elements (0 deactivated) 21:49:09 INFO opendrift.models.basemodel:1995: 2024-03-25 03:49:02.705765 - step 7 of 15 - 10000 active elements (0 deactivated) 21:49:09 INFO opendrift.models.basemodel:1995: 2024-03-25 04:49:02.705765 - step 8 of 15 - 10000 active elements (0 deactivated) 21:49:09 INFO opendrift.models.basemodel:1995: 2024-03-25 05:49:02.705765 - step 9 of 15 - 10000 active elements (0 deactivated) 21:49:09 INFO opendrift.models.basemodel:1995: 2024-03-25 06:49:02.705765 - step 10 of 15 - 10000 active elements (0 deactivated) 21:49:09 INFO opendrift.models.basemodel:1995: 2024-03-25 07:49:02.705765 - step 11 of 15 - 10000 active elements (0 deactivated) 21:49:09 INFO opendrift.models.basemodel:1995: 2024-03-25 08:49:02.705765 - step 12 of 15 - 10000 active elements (0 deactivated) 21:49:09 INFO opendrift.models.basemodel:1995: 2024-03-25 09:49:02.705765 - step 13 of 15 - 10000 active elements (0 deactivated) 21:49:10 INFO opendrift.models.basemodel:1995: 2024-03-25 10:49:02.705765 - step 14 of 15 - 10000 active elements (0 deactivated) 21:49:10 INFO opendrift.models.basemodel:1995: 2024-03-25 11:49:02.705765 - step 15 of 15 - 10000 active elements (0 deactivated) 21:49:10 INFO opendrift.export.io_netcdf:112: Wrote 16 steps to file test.nc /opt/conda/envs/opendrift/lib/python3.11/site-packages/numpy/ma/core.py:467: RuntimeWarning: invalid value encountered in cast fill_value = np.array(fill_value, copy=False, dtype=ndtype) .. GENERATED FROM PYTHON SOURCE LINES 28-29 Calculate spatial density of elements at 1500m grid spacing .. GENERATED FROM PYTHON SOURCE LINES 29-36 .. code-block:: Python oa = opendrift.open_xarray(of) oa.ds = oa.ds.where(oa.ds.status==0) d = oa.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 21:49:11 DEBUG opendrift.config:161: Adding 15 config items from __init__ 21:49:11 DEBUG opendrift.config:171: Overwriting config item readers:max_number_of_fails 21:49:11 DEBUG opendrift.config:161: Adding 5 config items from __init__ 21:49:11 INFO opendrift.models.basemodel:529: OpenDriftSimulation initialised (version 1.11.1 / v1.11.1-74-g4504ea0) 21:49:11 DEBUG opendrift.config:161: Adding 15 config items from oceandrift 21:49:11 DEBUG opendrift.config:171: Overwriting config item seed:z 21:49:11 DEBUG opendrift.export.io_netcdf:216: Importing with Xarray from test.nc 21:49:11 INFO opendrift:118: Returning object 21:49:11 INFO opendrift.models.basemodel:3837: calculating for origin_marker 0... 21:49:11 INFO opendrift.models.basemodel:3837: calculating for origin_marker 1... 21:49:11 INFO opendrift.models.basemodel:3837: calculating for origin_marker 2... 21:49:11 INFO opendrift.models.basemodel:3837: calculating for origin_marker 3... 21:49:12 INFO opendrift.models.basemodel:3837: calculating for origin_marker 4... .. GENERATED FROM PYTHON SOURCE LINES 37-38 Show which of the 5 sources are dominating within each grid cell .. GENERATED FROM PYTHON SOURCE LINES 38-42 .. code-block:: Python oa.animation(background=dom, show_elements=False, bgalpha=1, legend=oa.origin_marker, colorbar=False, vmin=0, vmax=4) .. rst-class:: sphx-glr-script-out .. code-block:: none 21:49:12 DEBUG opendrift.models.basemodel:2316: Setting up map: corners=None, fast=False, lscale=None 21:49:12 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. /opt/conda/envs/opendrift/lib/python3.11/site-packages/cartopy/mpl/geoaxes.py:1696: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap', 'vmin', 'vmax' will be ignored result = super().scatter(*args, **kwargs) 21:49:31 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:32 DEBUG opendrift.models.basemodel:2993: Saving animation.. 21:49:32 INFO opendrift.models.basemodel:4546: Saving animation to /root/project/docs/source/gallery/animations/example_dominating_0.gif... 21:49:32 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:33 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:35 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:36 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:37 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:39 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:40 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:41 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:43 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:44 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:45 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:46 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:48 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:49 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:50 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:52 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:53 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:54 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:56 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:57 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:49:59 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:50:00 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:50:03 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:50:04 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:50:06 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:50:08 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:50:10 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:50:12 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:50:14 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:50:16 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:50:18 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:50:20 DEBUG opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746).. 21:50:23 DEBUG opendrift.models.basemodel:4584: MPLBACKEND = agg 21:50:23 DEBUG opendrift.models.basemodel:4585: DISPLAY = None 21:50:23 DEBUG opendrift.models.basemodel:4586: Time to save animation: 0:00:50.703745 21:50:23 INFO opendrift.models.basemodel:2986: Time to make animation: 0:01:11.267139 .. GENERATED FROM PYTHON SOURCE LINES 43-44 .. image:: /gallery/animations/example_dominating_0.gif .. GENERATED FROM PYTHON SOURCE LINES 44-46 .. code-block:: Python os.remove(of) .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 21.386 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 ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_