Show dominating source

import os
from datetime import datetime
import xarray as xr
import opendrift
from opendrift.models.oceandrift import OceanDrift

of = 'test.nc'

Seed elements at 5 different locations/longitudes

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)
12:56:50 INFO    opendrift.models.basemodel:515: OpenDriftSimulation initialised (version 1.11.13 / v1.11.13-99-gd2132d3)
12:56:50 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:56:54 INFO    opendrift.models.basemodel.environment:245: Fallback values will be used for the following variables which have no readers:
12:56:54 INFO    opendrift.models.basemodel.environment:248:    x_sea_water_velocity: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    sea_surface_height: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    x_wind: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    y_wind: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    upward_sea_water_velocity: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    ocean_vertical_diffusivity: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_significant_height: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    sea_surface_swell_wave_to_direction: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    sea_surface_swell_wave_peak_period_from_variance_spectral_density: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    sea_surface_swell_wave_significant_height: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wind_wave_to_direction: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wind_wave_mean_period: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wind_wave_significant_height: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    surface_downward_x_stress: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    surface_downward_y_stress: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    turbulent_kinetic_energy: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    turbulent_generic_length_scale: 0.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    ocean_mixed_layer_thickness: 50.000000
12:56:54 INFO    opendrift.models.basemodel.environment:248:    sea_floor_depth_below_sea_level: 10000.000000
12:56:55 INFO    opendrift.models.basemodel:936: Using existing reader for land_binary_mask
12:56:55 INFO    opendrift.models.basemodel:947: All points are in ocean
12:56:55 INFO    opendrift.models.basemodel:2038: 2024-11-11 12:56:50.828021 - step 1 of 15 - 10000 active elements (0 deactivated)
12:56:55 INFO    opendrift.models.basemodel:2038: 2024-11-11 13:56:50.828021 - step 2 of 15 - 10000 active elements (0 deactivated)
12:56:55 INFO    opendrift.models.basemodel:2038: 2024-11-11 14:56:50.828021 - step 3 of 15 - 10000 active elements (0 deactivated)
12:56:55 INFO    opendrift.models.basemodel:2038: 2024-11-11 15:56:50.828021 - step 4 of 15 - 10000 active elements (0 deactivated)
12:56:55 INFO    opendrift.models.basemodel:2038: 2024-11-11 16:56:50.828021 - step 5 of 15 - 10000 active elements (0 deactivated)
12:56:56 INFO    opendrift.models.basemodel:2038: 2024-11-11 17:56:50.828021 - step 6 of 15 - 10000 active elements (0 deactivated)
12:56:56 INFO    opendrift.models.basemodel:2038: 2024-11-11 18:56:50.828021 - step 7 of 15 - 10000 active elements (0 deactivated)
12:56:56 INFO    opendrift.models.basemodel:2038: 2024-11-11 19:56:50.828021 - step 8 of 15 - 10000 active elements (0 deactivated)
12:56:56 INFO    opendrift.models.basemodel:2038: 2024-11-11 20:56:50.828021 - step 9 of 15 - 10000 active elements (0 deactivated)
12:56:56 INFO    opendrift.models.basemodel:2038: 2024-11-11 21:56:50.828021 - step 10 of 15 - 10000 active elements (0 deactivated)
12:56:56 INFO    opendrift.models.basemodel:2038: 2024-11-11 22:56:50.828021 - step 11 of 15 - 10000 active elements (0 deactivated)
12:56:56 INFO    opendrift.models.basemodel:2038: 2024-11-11 23:56:50.828021 - step 12 of 15 - 10000 active elements (0 deactivated)
12:56:56 INFO    opendrift.models.basemodel:2038: 2024-11-12 00:56:50.828021 - step 13 of 15 - 10000 active elements (0 deactivated)
12:56:56 INFO    opendrift.models.basemodel:2038: 2024-11-12 01:56:50.828021 - step 14 of 15 - 10000 active elements (0 deactivated)
12:56:56 INFO    opendrift.models.basemodel:2038: 2024-11-12 02:56:50.828021 - step 15 of 15 - 10000 active elements (0 deactivated)
12:56:56 INFO    opendrift.export.io_netcdf:121: 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)

Calculate spatial density of elements at 1500m grid spacing

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'
12:56:57 DEBUG   opendrift.config:168: Adding 18 config items from __init__
12:56:57 DEBUG   opendrift.config:178:   Overwriting config item readers:max_number_of_fails
12:56:57 DEBUG   opendrift.config:168: Adding 5 config items from __init__
12:56:57 INFO    opendrift.models.basemodel:515: OpenDriftSimulation initialised (version 1.11.13 / v1.11.13-99-gd2132d3)
12:56:57 DEBUG   opendrift.config:168: Adding 15 config items from oceandrift
12:56:57 DEBUG   opendrift.config:178:   Overwriting config item seed:z
12:56:57 DEBUG   opendrift.export.io_netcdf:239: Importing with Xarray from test.nc
12:56:57 INFO    opendrift:118: Returning <class 'opendrift.models.oceandrift.OceanDrift'> object
12:56:58 INFO    opendrift.models.basemodel:3892:       calculating for origin_marker 0...
12:56:58 INFO    opendrift.models.basemodel:3892:       calculating for origin_marker 1...
12:56:58 INFO    opendrift.models.basemodel:3892:       calculating for origin_marker 2...
12:56:58 INFO    opendrift.models.basemodel:3892:       calculating for origin_marker 3...
12:56:58 INFO    opendrift.models.basemodel:3892:       calculating for origin_marker 4...

Show which of the 5 sources are dominating within each grid cell

oa.animation(background=dom, show_elements=False, bgalpha=1,
             legend=oa.origin_marker, colorbar=False, vmin=0, vmax=4)
12:56:58 DEBUG   opendrift.models.basemodel:2365: Setting up map: corners=None, fast=False, lscale=None
12:56:58 DEBUG   opendrift.readers.reader_global_landmask:78: 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:1692: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap', 'vmin', 'vmax' will be ignored
  result = super().scatter(*args, **kwargs)
12:57:16 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:18 DEBUG   opendrift.models.basemodel:3044: Saving animation..
12:57:18 INFO    opendrift.models.basemodel:4613: Saving animation to /root/project/docs/source/gallery/animations/example_dominating_0.gif...
12:57:18 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:19 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:21 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:22 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:24 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:25 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:26 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:28 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:29 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:30 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:32 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:33 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:35 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:36 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:38 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:39 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:41 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:42 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:43 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:45 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:46 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:47 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:49 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:50 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:52 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:53 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:55 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:56 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:58 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:57:59 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:58:00 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:58:02 DEBUG   opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (3.435968017578124, 5.1932105064392085, 59.68026428222656, 60.350817871093746)..
12:58:03 DEBUG   opendrift.models.basemodel:4651: MPLBACKEND = agg
12:58:03 DEBUG   opendrift.models.basemodel:4652: DISPLAY = None
12:58:03 DEBUG   opendrift.models.basemodel:4653: Time to save animation: 0:00:45.770464
12:58:03 INFO    opendrift.models.basemodel:3037: Time to make animation: 0:01:05.489294
../_images/example_dominating_0.gif
os.remove(of)

Total running time of the script: (1 minutes 17.520 seconds)

Gallery generated by Sphinx-Gallery