River runoff

import os
from datetime import datetime, timedelta
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter
import opendrift
from opendrift.models.oceandrift import OceanDrift
from opendrift.readers import reader_oscillating


outfile = 'runoff.nc'  # Raw simulation output
histogram_file = 'runoff_histogram.nc'

First make a simulation with two seedings, marked by origin_marker

o = OceanDrift(loglevel=20)
o.set_config('drift:horizontal_diffusivity', 300)
o.set_config('general:coastline_action', 'previous')
t1 = datetime.now()
t2 = t1 + timedelta(hours=48)
reader_x = reader_oscillating.Reader('x_sea_water_velocity', period_seconds=3600*24,
                amplitude=1, zero_time=t1)
reader_y = reader_oscillating.Reader('y_sea_water_velocity', period_seconds=3600*72,
                amplitude=.5, zero_time=t2)
o.add_reader([reader_x, reader_y])
number = 25000
o.seed_elements(time=[t1, t2], lon=9.017931, lat=58.562702, number=number,
                origin_marker_name='River 1')  # River 1
o.seed_elements(time=[t1, t2], lon=8.824815, lat=58.425648, number=number,
                origin_marker_name='River 2')  # River 2
seed_times = o.elements_scheduled_time[0:number]

o.run(duration=timedelta(hours=48),
      time_step=1800, time_step_output=3600, outfile=outfile)
09:36:27 INFO    opendrift.models.basemodel:515: OpenDriftSimulation initialised (version 1.11.13 / v1.11.13-48-g5bea84b)
09:36:27 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...
09:36:33 INFO    opendrift.models.basemodel.environment:245: Fallback values will be used for the following variables which have no readers:
09:36:33 INFO    opendrift.models.basemodel.environment:248:    sea_surface_height: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    x_wind: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    y_wind: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    upward_sea_water_velocity: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    ocean_vertical_diffusivity: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_significant_height: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    sea_surface_swell_wave_to_direction: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    sea_surface_swell_wave_peak_period_from_variance_spectral_density: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    sea_surface_swell_wave_significant_height: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wind_wave_to_direction: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wind_wave_mean_period: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wind_wave_significant_height: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    surface_downward_x_stress: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    surface_downward_y_stress: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    turbulent_kinetic_energy: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    turbulent_generic_length_scale: 0.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    ocean_mixed_layer_thickness: 50.000000
09:36:33 INFO    opendrift.models.basemodel.environment:248:    sea_floor_depth_below_sea_level: 10000.000000
09:36:36 INFO    opendrift.models.basemodel:936: Using existing reader for land_binary_mask
09:36:36 INFO    opendrift.models.basemodel:947: All points are in ocean
09:36:36 INFO    opendrift.models.basemodel:2038: 2024-10-01 09:36:27.227327 - step 1 of 96 - 522 active elements (0 deactivated)
09:36:36 INFO    opendrift.models.basemodel:2038: 2024-10-01 10:06:27.227327 - step 2 of 96 - 1042 active elements (0 deactivated)
09:36:36 INFO    opendrift.models.basemodel:2038: 2024-10-01 10:36:27.227327 - step 3 of 96 - 1564 active elements (0 deactivated)
09:36:36 INFO    opendrift.models.basemodel:2038: 2024-10-01 11:06:27.227327 - step 4 of 96 - 2084 active elements (0 deactivated)
09:36:36 INFO    opendrift.models.basemodel:2038: 2024-10-01 11:36:27.227327 - step 5 of 96 - 2606 active elements (0 deactivated)
09:36:36 INFO    opendrift.models.basemodel:2038: 2024-10-01 12:06:27.227327 - step 6 of 96 - 3126 active elements (0 deactivated)
09:36:36 INFO    opendrift.models.basemodel:2038: 2024-10-01 12:36:27.227327 - step 7 of 96 - 3646 active elements (0 deactivated)
09:36:37 INFO    opendrift.models.basemodel:2038: 2024-10-01 13:06:27.227327 - step 8 of 96 - 4168 active elements (0 deactivated)
09:36:37 INFO    opendrift.models.basemodel:2038: 2024-10-01 13:36:27.227327 - step 9 of 96 - 4688 active elements (0 deactivated)
09:36:37 INFO    opendrift.models.basemodel:2038: 2024-10-01 14:06:27.227327 - step 10 of 96 - 5210 active elements (0 deactivated)
09:36:37 INFO    opendrift.models.basemodel:2038: 2024-10-01 14:36:27.227327 - step 11 of 96 - 5730 active elements (0 deactivated)
09:36:37 INFO    opendrift.models.basemodel:2038: 2024-10-01 15:06:27.227327 - step 12 of 96 - 6250 active elements (0 deactivated)
09:36:37 INFO    opendrift.models.basemodel:2038: 2024-10-01 15:36:27.227327 - step 13 of 96 - 6772 active elements (0 deactivated)
09:36:37 INFO    opendrift.models.basemodel:2038: 2024-10-01 16:06:27.227327 - step 14 of 96 - 7292 active elements (0 deactivated)
09:36:37 INFO    opendrift.models.basemodel:2038: 2024-10-01 16:36:27.227327 - step 15 of 96 - 7814 active elements (0 deactivated)
09:36:37 INFO    opendrift.models.basemodel:2038: 2024-10-01 17:06:27.227327 - step 16 of 96 - 8334 active elements (0 deactivated)
09:36:37 INFO    opendrift.models.basemodel:2038: 2024-10-01 17:36:27.227327 - step 17 of 96 - 8854 active elements (0 deactivated)
09:36:37 INFO    opendrift.models.basemodel:2038: 2024-10-01 18:06:27.227327 - step 18 of 96 - 9376 active elements (0 deactivated)
09:36:37 INFO    opendrift.models.basemodel:2038: 2024-10-01 18:36:27.227327 - step 19 of 96 - 9896 active elements (0 deactivated)
09:36:37 INFO    opendrift.models.basemodel:2038: 2024-10-01 19:06:27.227327 - step 20 of 96 - 10418 active elements (0 deactivated)
09:36:37 INFO    opendrift.models.basemodel:2038: 2024-10-01 19:36:27.227327 - step 21 of 96 - 10938 active elements (0 deactivated)
09:36:37 INFO    opendrift.models.basemodel:2038: 2024-10-01 20:06:27.227327 - step 22 of 96 - 11458 active elements (0 deactivated)
09:36:37 INFO    opendrift.models.basemodel:2038: 2024-10-01 20:36:27.227327 - step 23 of 96 - 11980 active elements (0 deactivated)
09:36:38 INFO    opendrift.models.basemodel:2038: 2024-10-01 21:06:27.227327 - step 24 of 96 - 12500 active elements (0 deactivated)
09:36:38 INFO    opendrift.models.basemodel:2038: 2024-10-01 21:36:27.227327 - step 25 of 96 - 13022 active elements (0 deactivated)
09:36:38 INFO    opendrift.models.basemodel:2038: 2024-10-01 22:06:27.227327 - step 26 of 96 - 13542 active elements (0 deactivated)
09:36:38 INFO    opendrift.models.basemodel:2038: 2024-10-01 22:36:27.227327 - step 27 of 96 - 14062 active elements (0 deactivated)
09:36:38 INFO    opendrift.models.basemodel:2038: 2024-10-01 23:06:27.227327 - step 28 of 96 - 14584 active elements (0 deactivated)
09:36:38 INFO    opendrift.models.basemodel:2038: 2024-10-01 23:36:27.227327 - step 29 of 96 - 15104 active elements (0 deactivated)
09:36:38 INFO    opendrift.models.basemodel:2038: 2024-10-02 00:06:27.227327 - step 30 of 96 - 15626 active elements (0 deactivated)
09:36:38 INFO    opendrift.models.basemodel:2038: 2024-10-02 00:36:27.227327 - step 31 of 96 - 16146 active elements (0 deactivated)
09:36:38 INFO    opendrift.models.basemodel:2038: 2024-10-02 01:06:27.227327 - step 32 of 96 - 16668 active elements (0 deactivated)
09:36:38 INFO    opendrift.models.basemodel:2038: 2024-10-02 01:36:27.227327 - step 33 of 96 - 17188 active elements (0 deactivated)
09:36:39 INFO    opendrift.models.basemodel:2038: 2024-10-02 02:06:27.227327 - step 34 of 96 - 17708 active elements (0 deactivated)
09:36:39 INFO    opendrift.models.basemodel:2038: 2024-10-02 02:36:27.227327 - step 35 of 96 - 18230 active elements (0 deactivated)
09:36:39 INFO    opendrift.models.basemodel:2038: 2024-10-02 03:06:27.227327 - step 36 of 96 - 18750 active elements (0 deactivated)
09:36:39 INFO    opendrift.models.basemodel:2038: 2024-10-02 03:36:27.227327 - step 37 of 96 - 19272 active elements (0 deactivated)
09:36:39 INFO    opendrift.models.basemodel:2038: 2024-10-02 04:06:27.227327 - step 38 of 96 - 19792 active elements (0 deactivated)
09:36:39 INFO    opendrift.models.basemodel:2038: 2024-10-02 04:36:27.227327 - step 39 of 96 - 20312 active elements (0 deactivated)
09:36:39 INFO    opendrift.models.basemodel:2038: 2024-10-02 05:06:27.227327 - step 40 of 96 - 20834 active elements (0 deactivated)
09:36:39 INFO    opendrift.models.basemodel:2038: 2024-10-02 05:36:27.227327 - step 41 of 96 - 21354 active elements (0 deactivated)
09:36:40 INFO    opendrift.models.basemodel:2038: 2024-10-02 06:06:27.227327 - step 42 of 96 - 21876 active elements (0 deactivated)
09:36:40 INFO    opendrift.models.basemodel:2038: 2024-10-02 06:36:27.227327 - step 43 of 96 - 22396 active elements (0 deactivated)
09:36:40 INFO    opendrift.models.basemodel:2038: 2024-10-02 07:06:27.227327 - step 44 of 96 - 22916 active elements (0 deactivated)
09:36:40 INFO    opendrift.models.basemodel:2038: 2024-10-02 07:36:27.227327 - step 45 of 96 - 23438 active elements (0 deactivated)
09:36:40 INFO    opendrift.models.basemodel:2038: 2024-10-02 08:06:27.227327 - step 46 of 96 - 23958 active elements (0 deactivated)
09:36:40 INFO    opendrift.models.basemodel:2038: 2024-10-02 08:36:27.227327 - step 47 of 96 - 24480 active elements (0 deactivated)
09:36:40 INFO    opendrift.models.basemodel:2038: 2024-10-02 09:06:27.227327 - step 48 of 96 - 25000 active elements (0 deactivated)
09:36:41 INFO    opendrift.models.basemodel:2038: 2024-10-02 09:36:27.227327 - step 49 of 96 - 25520 active elements (0 deactivated)
09:36:41 INFO    opendrift.models.basemodel:2038: 2024-10-02 10:06:27.227327 - step 50 of 96 - 26042 active elements (0 deactivated)
09:36:41 INFO    opendrift.models.basemodel:2038: 2024-10-02 10:36:27.227327 - step 51 of 96 - 26562 active elements (0 deactivated)
09:36:41 INFO    opendrift.models.basemodel:2038: 2024-10-02 11:06:27.227327 - step 52 of 96 - 27084 active elements (0 deactivated)
09:36:41 INFO    opendrift.models.basemodel:2038: 2024-10-02 11:36:27.227327 - step 53 of 96 - 27604 active elements (0 deactivated)
09:36:41 INFO    opendrift.models.basemodel:2038: 2024-10-02 12:06:27.227327 - step 54 of 96 - 28124 active elements (0 deactivated)
09:36:42 INFO    opendrift.models.basemodel:2038: 2024-10-02 12:36:27.227327 - step 55 of 96 - 28646 active elements (0 deactivated)
09:36:42 INFO    opendrift.models.basemodel:2038: 2024-10-02 13:06:27.227327 - step 56 of 96 - 29166 active elements (0 deactivated)
09:36:42 INFO    opendrift.models.basemodel:2038: 2024-10-02 13:36:27.227327 - step 57 of 96 - 29688 active elements (0 deactivated)
09:36:42 INFO    opendrift.models.basemodel:2038: 2024-10-02 14:06:27.227327 - step 58 of 96 - 30208 active elements (0 deactivated)
09:36:42 INFO    opendrift.models.basemodel:2038: 2024-10-02 14:36:27.227327 - step 59 of 96 - 30728 active elements (0 deactivated)
09:36:43 INFO    opendrift.models.basemodel:2038: 2024-10-02 15:06:27.227327 - step 60 of 96 - 31250 active elements (0 deactivated)
09:36:43 INFO    opendrift.models.basemodel:2038: 2024-10-02 15:36:27.227327 - step 61 of 96 - 31770 active elements (0 deactivated)
09:36:43 INFO    opendrift.models.basemodel:2038: 2024-10-02 16:06:27.227327 - step 62 of 96 - 32292 active elements (0 deactivated)
09:36:43 INFO    opendrift.models.basemodel:2038: 2024-10-02 16:36:27.227327 - step 63 of 96 - 32812 active elements (0 deactivated)
09:36:44 INFO    opendrift.models.basemodel:2038: 2024-10-02 17:06:27.227327 - step 64 of 96 - 33334 active elements (0 deactivated)
09:36:44 INFO    opendrift.models.basemodel:2038: 2024-10-02 17:36:27.227327 - step 65 of 96 - 33854 active elements (0 deactivated)
09:36:44 INFO    opendrift.models.basemodel:2038: 2024-10-02 18:06:27.227327 - step 66 of 96 - 34374 active elements (0 deactivated)
09:36:44 INFO    opendrift.models.basemodel:2038: 2024-10-02 18:36:27.227327 - step 67 of 96 - 34896 active elements (0 deactivated)
09:36:45 INFO    opendrift.models.basemodel:2038: 2024-10-02 19:06:27.227327 - step 68 of 96 - 35416 active elements (0 deactivated)
09:36:45 INFO    opendrift.models.basemodel:2038: 2024-10-02 19:36:27.227327 - step 69 of 96 - 35938 active elements (0 deactivated)
09:36:45 INFO    opendrift.models.basemodel:2038: 2024-10-02 20:06:27.227327 - step 70 of 96 - 36458 active elements (0 deactivated)
09:36:45 INFO    opendrift.models.basemodel:2038: 2024-10-02 20:36:27.227327 - step 71 of 96 - 36978 active elements (0 deactivated)
09:36:46 INFO    opendrift.models.basemodel:2038: 2024-10-02 21:06:27.227327 - step 72 of 96 - 37500 active elements (0 deactivated)
09:36:46 INFO    opendrift.models.basemodel:2038: 2024-10-02 21:36:27.227327 - step 73 of 96 - 38020 active elements (0 deactivated)
09:36:46 INFO    opendrift.models.basemodel:2038: 2024-10-02 22:06:27.227327 - step 74 of 96 - 38542 active elements (0 deactivated)
09:36:46 INFO    opendrift.models.basemodel:2038: 2024-10-02 22:36:27.227327 - step 75 of 96 - 39062 active elements (0 deactivated)
09:36:47 INFO    opendrift.models.basemodel:2038: 2024-10-02 23:06:27.227327 - step 76 of 96 - 39582 active elements (0 deactivated)
09:36:47 INFO    opendrift.models.basemodel:2038: 2024-10-02 23:36:27.227327 - step 77 of 96 - 40104 active elements (0 deactivated)
09:36:48 INFO    opendrift.models.basemodel:2038: 2024-10-03 00:06:27.227327 - step 78 of 96 - 40624 active elements (0 deactivated)
09:36:48 INFO    opendrift.models.basemodel:2038: 2024-10-03 00:36:27.227327 - step 79 of 96 - 41146 active elements (0 deactivated)
09:36:48 INFO    opendrift.models.basemodel:2038: 2024-10-03 01:06:27.227327 - step 80 of 96 - 41666 active elements (0 deactivated)
09:36:48 INFO    opendrift.models.basemodel:2038: 2024-10-03 01:36:27.227327 - step 81 of 96 - 42186 active elements (0 deactivated)
09:36:49 INFO    opendrift.models.basemodel:2038: 2024-10-03 02:06:27.227327 - step 82 of 96 - 42708 active elements (0 deactivated)
09:36:49 INFO    opendrift.models.basemodel:2038: 2024-10-03 02:36:27.227327 - step 83 of 96 - 43228 active elements (0 deactivated)
09:36:50 INFO    opendrift.models.basemodel:2038: 2024-10-03 03:06:27.227327 - step 84 of 96 - 43750 active elements (0 deactivated)
09:36:50 INFO    opendrift.models.basemodel:2038: 2024-10-03 03:36:27.227327 - step 85 of 96 - 44270 active elements (0 deactivated)
09:36:50 INFO    opendrift.models.basemodel:2038: 2024-10-03 04:06:27.227327 - step 86 of 96 - 44790 active elements (0 deactivated)
09:36:51 INFO    opendrift.models.basemodel:2038: 2024-10-03 04:36:27.227327 - step 87 of 96 - 45312 active elements (0 deactivated)
09:36:51 INFO    opendrift.models.basemodel:2038: 2024-10-03 05:06:27.227327 - step 88 of 96 - 45832 active elements (0 deactivated)
09:36:51 INFO    opendrift.models.basemodel:2038: 2024-10-03 05:36:27.227327 - step 89 of 96 - 46354 active elements (0 deactivated)
09:36:52 INFO    opendrift.models.basemodel:2038: 2024-10-03 06:06:27.227327 - step 90 of 96 - 46874 active elements (0 deactivated)
09:36:52 INFO    opendrift.models.basemodel:2038: 2024-10-03 06:36:27.227327 - step 91 of 96 - 47394 active elements (0 deactivated)
09:36:53 INFO    opendrift.models.basemodel:2038: 2024-10-03 07:06:27.227327 - step 92 of 96 - 47916 active elements (0 deactivated)
09:36:53 INFO    opendrift.models.basemodel:2038: 2024-10-03 07:36:27.227327 - step 93 of 96 - 48436 active elements (0 deactivated)
09:36:54 INFO    opendrift.models.basemodel:2038: 2024-10-03 08:06:27.227327 - step 94 of 96 - 48958 active elements (0 deactivated)
09:36:54 INFO    opendrift.models.basemodel:2038: 2024-10-03 08:36:27.227327 - step 95 of 96 - 49478 active elements (0 deactivated)
09:36:54 INFO    opendrift.models.basemodel:2038: 2024-10-03 09:06:27.227327 - step 96 of 96 - 50000 active elements (0 deactivated)
09:36:58 INFO    opendrift.export.io_netcdf:121: Wrote 49 steps to file runoff.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)

Opening the output file lazily with Xarray. This will work even if the file is too large to fit in memory, as it will read and process data chuck-by-chunk directly from file using Dask.

o = opendrift.open_xarray(outfile)
09:37:08 DEBUG   opendrift.config:168: Adding 18 config items from __init__
09:37:08 DEBUG   opendrift.config:178:   Overwriting config item readers:max_number_of_fails
09:37:08 DEBUG   opendrift.config:168: Adding 5 config items from __init__
09:37:08 INFO    opendrift.models.basemodel:515: OpenDriftSimulation initialised (version 1.11.13 / v1.11.13-48-g5bea84b)
09:37:08 DEBUG   opendrift.config:168: Adding 15 config items from oceandrift
09:37:08 DEBUG   opendrift.config:178:   Overwriting config item seed:z
09:37:08 DEBUG   opendrift.export.io_netcdf:239: Importing with Xarray from runoff.nc
09:37:09 INFO    opendrift:118: Returning <class 'opendrift.models.oceandrift.OceanDrift'> object

We want to extract timeseries of river water at the coordinates of a hypothetical measuring station as well as the amount of river water passing through two defined areas/regions

station_lon = 9.4
station_lat = 58.1
box1_lon = [8.4, 8.8]
box1_lat = [57.9, 58.1]
box2_lon = [9.5, 9.9]
box2_lat = [58.3, 58.5]

Animation of the spatial density of river runoff water. Although there are the same number of elements from each river, the density plots are weighted with the actual runoff at time of seeding. This weighting can be done/changed afterwards without needing to redo the simulation. The calculated density fields will be stored/cached in the analysis file for later re-use, as their calculation may be time consuming for huge output files. Note that other analysis/plotting methods are not yet adapted to datasets opened lazily with open_xarray

runoff_river1 = np.abs(np.cos(np.arange(number)*2*np.pi/(number)))  # Impose a temporal variation of runoff
runoff_river2 = 10*runoff_river1  # Let river 2 have 10 times as large runoff as river 1
runoff = np.concatenate((runoff_river1, runoff_river2))

Calculate density with given pixel size, weighted by runoff amount per element

river_water = o.get_histogram(pixelsize_m=1500, weights=runoff, density=False)

rw = river_water.sum(dim='origin_marker')  # For both rivers
#rw = river_water.isel(origin_marker=1)    # For one of the rivers
river_water.name = 'River water [m3/cell]'

text = [{'s': o.origin_marker[0], 'x': 8.55, 'y': 58.56, 'fontsize': 20, 'color': 'g',
         'backgroundcolor': 'white', 'bbox': dict(facecolor='white', alpha=0.8), 'zorder': 1000},
        {'s': o.origin_marker[1], 'x': 8.35, 'y': 58.42, 'fontsize': 20, 'color': 'g',
         'backgroundcolor': 'white', 'bbox': dict(facecolor='white', alpha=0.8), 'zorder': 1000},
        {'s': '* Station', 'x': station_lon, 'y': station_lat, 'fontsize': 20, 'color': 'k',
         'backgroundcolor': 'white', 'bbox': dict(facecolor='none', edgecolor='none', alpha=0.4), 'zorder': 1000}]
box = [{'lon': box1_lon, 'lat': box1_lat, 'text': 'Area 1', 'fc': 'none', 'alpha': 0.8, 'lw': 1, 'ec': 'k'},
       {'lon': box2_lon, 'lat': box2_lat, 'text': 'Area 2', 'fc': 'none', 'alpha': 0.8, 'lw': 1, 'ec': 'k'}]

o.animation(background=rw.where(rw>0), bgalpha=1, fast=False,
            show_elements=False, vmin=0, vmax=120, text=text, box=box)
09:37:09 INFO    opendrift.models.basemodel:3892:       calculating for origin_marker 0...
09:37:10 INFO    opendrift.models.basemodel:3892:       calculating for origin_marker 1...
09:37:10 DEBUG   opendrift.models.basemodel:2365: Setting up map: corners=None, fast=False, lscale=None
09:37:10 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
/opt/conda/envs/opendrift/lib/python3.11/site-packages/cartopy/mpl/geoaxes.py:1683: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap', 'vmin', 'vmax' will be ignored
  result = super().scatter(*args, **kwargs)
09:37:29 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:37:30 DEBUG   opendrift.models.basemodel:3044: Saving animation..
09:37:30 INFO    opendrift.models.basemodel:4608: Saving animation to /root/project/docs/source/gallery/animations/example_river_runoff_0.gif...
09:37:30 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:37:32 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:37:34 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:37:36 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:37:39 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:37:41 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:37:44 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:37:45 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:37:47 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:37:49 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:37:51 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:37:52 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:37:54 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:37:55 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:37:57 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:37:59 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:01 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:02 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:04 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:05 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:07 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:09 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:11 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:12 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:14 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:16 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:17 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:19 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:21 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:22 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:24 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:25 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:27 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:28 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:30 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:31 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:33 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:35 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:36 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:38 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:40 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:41 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:43 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:44 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:46 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:47 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:49 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:51 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:52 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:54 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:56 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:58 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:38:59 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:01 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:03 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:05 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:07 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:09 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:10 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:12 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:14 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:16 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:18 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:19 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:21 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:22 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:24 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:26 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:28 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:30 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:32 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:34 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:35 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:37 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:39 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:41 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:43 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:44 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:46 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:47 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:49 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:51 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:53 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:54 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:56 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:39:58 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:40:00 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:40:02 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:40:04 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:40:06 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:40:08 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:40:10 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:40:11 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:40:13 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:40:14 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:40:16 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:40:18 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:40:19 DEBUG   opendrift.readers.reader_global_landmask:83: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
09:40:22 DEBUG   opendrift.models.basemodel:4646: MPLBACKEND = agg
09:40:22 DEBUG   opendrift.models.basemodel:4647: DISPLAY = None
09:40:22 DEBUG   opendrift.models.basemodel:4648: Time to save animation: 0:02:52.006375
09:40:22 INFO    opendrift.models.basemodel:3037: Time to make animation: 0:03:12.396718
../_images/example_river_runoff_0.gif

Plotting time series of river runoff, and corresponding water passing through the station and the two defined areas/boxes

fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1)
# Runoff
ax1.plot(seed_times, runoff_river1, label=o.origin_marker[0])
ax1.plot(seed_times, runoff_river2, label=o.origin_marker[1])
ax1.set_ylabel('Runoff  [m3/s]')
ax1.set_title('Runoff')
# Area 1
t1 = river_water.sel(lon_bin=slice(box1_lon[0], box1_lon[1]),
                     lat_bin=slice(box1_lat[0], box1_lat[1]))
t1 = t1.sum(('lon_bin', 'lat_bin'))
t1.isel(origin_marker=0).plot(label=o.origin_marker[0], ax=ax2)
t1.isel(origin_marker=1).plot(label=o.origin_marker[1], ax=ax2)
t1.sum(dim='origin_marker').plot(label='Total', linestyle='--', ax=ax2)
ax2.set_title('Amount of water passing through Area 1')
# Area 2
t2 = river_water.sel(lon_bin=slice(box2_lon[0], box2_lon[1]),
                     lat_bin=slice(box2_lat[0], box2_lat[1]))
t2 = t2.sum(('lon_bin', 'lat_bin'))
t2.isel(origin_marker=0).plot(label=o.origin_marker[0], ax=ax3)
t2.isel(origin_marker=1).plot(label=o.origin_marker[1], ax=ax3)
t2.sum(dim='origin_marker').plot(label='Total', linestyle='--', ax=ax3)
ax3.set_title('Amount of water passing through Area 2')
# Extracting time series at the location of the station
t = river_water.sel(lon_bin=station_lon, lat_bin=station_lat, method='nearest')
t.isel(origin_marker=0).plot(label=o.origin_marker[0], ax=ax4)
t.isel(origin_marker=1).plot(label=o.origin_marker[1], ax=ax4)
t.sum(dim='origin_marker').plot(label='Total', linestyle='--', ax=ax4)
ax4.legend()
ax4.margins(x=0)

for ax in [ax1, ax2, ax3]:
    ax.margins(x=0)
    ax.legend()
    #ax.set_xticks([])
    ax.set_xlabel(None)
ax4.set_title('Density of water at Station')
# TODO disabling due to recent problem with dateformatter
#ax4.xaxis.set_major_formatter(DateFormatter("%d %b %H"))
plt.show()
Runoff, Amount of water passing through Area 1, Amount of water passing through Area 2, Density of water at Station

Finally, plot the spatial distribution of mean age of water

num = o.get_histogram(pixelsize_m=1500, weights=None, density=False)
num.name = 'number'
num.to_netcdf(histogram_file)

mas = o.get_histogram(pixelsize_m=1500, weights=o.ds['age_seconds'], density=False)
mas = mas/3600  # in hours
mas = mas/num  # per area
mas.name='mean_age'
mas.to_netcdf(histogram_file, 'a')
mas = mas.mean(dim='time').sum(dim='origin_marker')  # Mean time of both rivers
#mas = mas.mean(dim='time').isel(origin_marker=1)  # Mean age of a single river
mas.name='Mean age of water [hours]'

o.plot(background=mas.where(mas>0), fast=True, show_elements=False)


# Cleaning up
os.remove(outfile)
os.remove(histogram_file)
OpenDrift - OceanDrift 2024-10-01 09:36 to 2024-10-03 09:36 UTC (49 steps)
09:40:23 INFO    opendrift.models.basemodel:3892:       calculating for origin_marker 0...
09:40:23 INFO    opendrift.models.basemodel:3892:       calculating for origin_marker 1...
09:40:23 INFO    opendrift.models.basemodel:3892:       calculating for origin_marker 0...
09:40:24 INFO    opendrift.models.basemodel:3892:       calculating for origin_marker 1...
09:40:24 DEBUG   opendrift.models.basemodel:2365: Setting up map: corners=None, fast=True, lscale=None
09:40:24 WARNING opendrift.models.basemodel:2411: Plotting fast. This will make your plots less accurate.

Total running time of the script: (4 minutes 6.102 seconds)

Gallery generated by Sphinx-Gallery