Note
Go to the end to download the full example code.
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)
20:15:21 INFO opendrift.models.basemodel:515: OpenDriftSimulation initialised (version 1.12.0 / v1.12.0-26-g390e945)
20:15:21 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...
20:15:25 INFO opendrift.models.basemodel.environment:245: Fallback values will be used for the following variables which have no readers:
20:15:25 INFO opendrift.models.basemodel.environment:248: sea_surface_height: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: x_wind: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: y_wind: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: upward_sea_water_velocity: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: ocean_vertical_diffusivity: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_significant_height: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_stokes_drift_x_velocity: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_stokes_drift_y_velocity: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_to_direction: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_peak_period_from_variance_spectral_density: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_significant_height: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_to_direction: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_mean_period: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_significant_height: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: surface_downward_x_stress: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: surface_downward_y_stress: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: turbulent_kinetic_energy: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: turbulent_generic_length_scale: 0.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: ocean_mixed_layer_thickness: 50.000000
20:15:25 INFO opendrift.models.basemodel.environment:248: sea_floor_depth_below_sea_level: 10000.000000
20:15:28 INFO opendrift.models.basemodel:935: Using existing reader for land_binary_mask
20:15:28 INFO opendrift.models.basemodel:946: All points are in ocean
20:15:28 INFO opendrift.models.basemodel:2035: 2024-12-12 20:15:21.989750 - step 1 of 96 - 522 active elements (0 deactivated)
20:15:28 INFO opendrift.models.basemodel:2035: 2024-12-12 20:45:21.989750 - step 2 of 96 - 1042 active elements (0 deactivated)
20:15:30 INFO opendrift.models.basemodel:2035: 2024-12-12 21:15:21.989750 - step 3 of 96 - 1564 active elements (0 deactivated)
20:15:30 INFO opendrift.models.basemodel:2035: 2024-12-12 21:45:21.989750 - step 4 of 96 - 2084 active elements (0 deactivated)
20:15:30 INFO opendrift.models.basemodel:2035: 2024-12-12 22:15:21.989750 - step 5 of 96 - 2606 active elements (0 deactivated)
20:15:30 INFO opendrift.models.basemodel:2035: 2024-12-12 22:45:21.989750 - step 6 of 96 - 3126 active elements (0 deactivated)
20:15:30 INFO opendrift.models.basemodel:2035: 2024-12-12 23:15:21.989750 - step 7 of 96 - 3646 active elements (0 deactivated)
20:15:30 INFO opendrift.models.basemodel:2035: 2024-12-12 23:45:21.989750 - step 8 of 96 - 4168 active elements (0 deactivated)
20:15:30 INFO opendrift.models.basemodel:2035: 2024-12-13 00:15:21.989750 - step 9 of 96 - 4688 active elements (0 deactivated)
20:15:30 INFO opendrift.models.basemodel:2035: 2024-12-13 00:45:21.989750 - step 10 of 96 - 5210 active elements (0 deactivated)
20:15:30 INFO opendrift.models.basemodel:2035: 2024-12-13 01:15:21.989750 - step 11 of 96 - 5730 active elements (0 deactivated)
20:15:30 INFO opendrift.models.basemodel:2035: 2024-12-13 01:45:21.989750 - step 12 of 96 - 6250 active elements (0 deactivated)
20:15:30 INFO opendrift.models.basemodel:2035: 2024-12-13 02:15:21.989750 - step 13 of 96 - 6772 active elements (0 deactivated)
20:15:30 INFO opendrift.models.basemodel:2035: 2024-12-13 02:45:21.989750 - step 14 of 96 - 7292 active elements (0 deactivated)
20:15:30 INFO opendrift.models.basemodel:2035: 2024-12-13 03:15:21.989750 - step 15 of 96 - 7814 active elements (0 deactivated)
20:15:30 INFO opendrift.models.basemodel:2035: 2024-12-13 03:45:21.989750 - step 16 of 96 - 8334 active elements (0 deactivated)
20:15:30 INFO opendrift.models.basemodel:2035: 2024-12-13 04:15:21.989750 - step 17 of 96 - 8854 active elements (0 deactivated)
20:15:30 INFO opendrift.models.basemodel:2035: 2024-12-13 04:45:21.989750 - step 18 of 96 - 9376 active elements (0 deactivated)
20:15:30 INFO opendrift.models.basemodel:2035: 2024-12-13 05:15:21.989750 - step 19 of 96 - 9896 active elements (0 deactivated)
20:15:31 INFO opendrift.models.basemodel:2035: 2024-12-13 05:45:21.989750 - step 20 of 96 - 10418 active elements (0 deactivated)
20:15:31 INFO opendrift.models.basemodel:2035: 2024-12-13 06:15:21.989750 - step 21 of 96 - 10938 active elements (0 deactivated)
20:15:31 INFO opendrift.models.basemodel:2035: 2024-12-13 06:45:21.989750 - step 22 of 96 - 11458 active elements (0 deactivated)
20:15:31 INFO opendrift.models.basemodel:2035: 2024-12-13 07:15:21.989750 - step 23 of 96 - 11980 active elements (0 deactivated)
20:15:31 INFO opendrift.models.basemodel:2035: 2024-12-13 07:45:21.989750 - step 24 of 96 - 12500 active elements (0 deactivated)
20:15:31 INFO opendrift.models.basemodel:2035: 2024-12-13 08:15:21.989750 - step 25 of 96 - 13022 active elements (0 deactivated)
20:15:31 INFO opendrift.models.basemodel:2035: 2024-12-13 08:45:21.989750 - step 26 of 96 - 13542 active elements (0 deactivated)
20:15:31 INFO opendrift.models.basemodel:2035: 2024-12-13 09:15:21.989750 - step 27 of 96 - 14062 active elements (0 deactivated)
20:15:31 INFO opendrift.models.basemodel:2035: 2024-12-13 09:45:21.989750 - step 28 of 96 - 14584 active elements (0 deactivated)
20:15:31 INFO opendrift.models.basemodel:2035: 2024-12-13 10:15:21.989750 - step 29 of 96 - 15104 active elements (0 deactivated)
20:15:31 INFO opendrift.models.basemodel:2035: 2024-12-13 10:45:21.989750 - step 30 of 96 - 15626 active elements (0 deactivated)
20:15:31 INFO opendrift.models.basemodel:2035: 2024-12-13 11:15:21.989750 - step 31 of 96 - 16146 active elements (0 deactivated)
20:15:32 INFO opendrift.models.basemodel:2035: 2024-12-13 11:45:21.989750 - step 32 of 96 - 16668 active elements (0 deactivated)
20:15:32 INFO opendrift.models.basemodel:2035: 2024-12-13 12:15:21.989750 - step 33 of 96 - 17188 active elements (0 deactivated)
20:15:32 INFO opendrift.models.basemodel:2035: 2024-12-13 12:45:21.989750 - step 34 of 96 - 17708 active elements (0 deactivated)
20:15:32 INFO opendrift.models.basemodel:2035: 2024-12-13 13:15:21.989750 - step 35 of 96 - 18230 active elements (0 deactivated)
20:15:32 INFO opendrift.models.basemodel:2035: 2024-12-13 13:45:21.989750 - step 36 of 96 - 18750 active elements (0 deactivated)
20:15:32 INFO opendrift.models.basemodel:2035: 2024-12-13 14:15:21.989750 - step 37 of 96 - 19272 active elements (0 deactivated)
20:15:32 INFO opendrift.models.basemodel:2035: 2024-12-13 14:45:21.989750 - step 38 of 96 - 19792 active elements (0 deactivated)
20:15:32 INFO opendrift.models.basemodel:2035: 2024-12-13 15:15:21.989750 - step 39 of 96 - 20312 active elements (0 deactivated)
20:15:32 INFO opendrift.models.basemodel:2035: 2024-12-13 15:45:21.989750 - step 40 of 96 - 20834 active elements (0 deactivated)
20:15:32 INFO opendrift.models.basemodel:2035: 2024-12-13 16:15:21.989750 - step 41 of 96 - 21354 active elements (0 deactivated)
20:15:33 INFO opendrift.models.basemodel:2035: 2024-12-13 16:45:21.989750 - step 42 of 96 - 21876 active elements (0 deactivated)
20:15:33 INFO opendrift.models.basemodel:2035: 2024-12-13 17:15:21.989750 - step 43 of 96 - 22396 active elements (0 deactivated)
20:15:33 INFO opendrift.models.basemodel:2035: 2024-12-13 17:45:21.989750 - step 44 of 96 - 22916 active elements (0 deactivated)
20:15:33 INFO opendrift.models.basemodel:2035: 2024-12-13 18:15:21.989750 - step 45 of 96 - 23438 active elements (0 deactivated)
20:15:33 INFO opendrift.models.basemodel:2035: 2024-12-13 18:45:21.989750 - step 46 of 96 - 23958 active elements (0 deactivated)
20:15:33 INFO opendrift.models.basemodel:2035: 2024-12-13 19:15:21.989750 - step 47 of 96 - 24480 active elements (0 deactivated)
20:15:33 INFO opendrift.models.basemodel:2035: 2024-12-13 19:45:21.989750 - step 48 of 96 - 25000 active elements (0 deactivated)
20:15:33 INFO opendrift.models.basemodel:2035: 2024-12-13 20:15:21.989750 - step 49 of 96 - 25520 active elements (0 deactivated)
20:15:34 INFO opendrift.models.basemodel:2035: 2024-12-13 20:45:21.989750 - step 50 of 96 - 26042 active elements (0 deactivated)
20:15:34 INFO opendrift.models.basemodel:2035: 2024-12-13 21:15:21.989750 - step 51 of 96 - 26562 active elements (0 deactivated)
20:15:34 INFO opendrift.models.basemodel:2035: 2024-12-13 21:45:21.989750 - step 52 of 96 - 27084 active elements (0 deactivated)
20:15:34 INFO opendrift.models.basemodel:2035: 2024-12-13 22:15:21.989750 - step 53 of 96 - 27604 active elements (0 deactivated)
20:15:34 INFO opendrift.models.basemodel:2035: 2024-12-13 22:45:21.989750 - step 54 of 96 - 28124 active elements (0 deactivated)
20:15:34 INFO opendrift.models.basemodel:2035: 2024-12-13 23:15:21.989750 - step 55 of 96 - 28646 active elements (0 deactivated)
20:15:35 INFO opendrift.models.basemodel:2035: 2024-12-13 23:45:21.989750 - step 56 of 96 - 29166 active elements (0 deactivated)
20:15:35 INFO opendrift.models.basemodel:2035: 2024-12-14 00:15:21.989750 - step 57 of 96 - 29688 active elements (0 deactivated)
20:15:35 INFO opendrift.models.basemodel:2035: 2024-12-14 00:45:21.989750 - step 58 of 96 - 30208 active elements (0 deactivated)
20:15:35 INFO opendrift.models.basemodel:2035: 2024-12-14 01:15:21.989750 - step 59 of 96 - 30728 active elements (0 deactivated)
20:15:35 INFO opendrift.models.basemodel:2035: 2024-12-14 01:45:21.989750 - step 60 of 96 - 31250 active elements (0 deactivated)
20:15:35 INFO opendrift.models.basemodel:2035: 2024-12-14 02:15:21.989750 - step 61 of 96 - 31770 active elements (0 deactivated)
20:15:36 INFO opendrift.models.basemodel:2035: 2024-12-14 02:45:21.989750 - step 62 of 96 - 32292 active elements (0 deactivated)
20:15:36 INFO opendrift.models.basemodel:2035: 2024-12-14 03:15:21.989750 - step 63 of 96 - 32812 active elements (0 deactivated)
20:15:36 INFO opendrift.models.basemodel:2035: 2024-12-14 03:45:21.989750 - step 64 of 96 - 33334 active elements (0 deactivated)
20:15:36 INFO opendrift.models.basemodel:2035: 2024-12-14 04:15:21.989750 - step 65 of 96 - 33854 active elements (0 deactivated)
20:15:36 INFO opendrift.models.basemodel:2035: 2024-12-14 04:45:21.989750 - step 66 of 96 - 34374 active elements (0 deactivated)
20:15:37 INFO opendrift.models.basemodel:2035: 2024-12-14 05:15:21.989750 - step 67 of 96 - 34896 active elements (0 deactivated)
20:15:37 INFO opendrift.models.basemodel:2035: 2024-12-14 05:45:21.989750 - step 68 of 96 - 35416 active elements (0 deactivated)
20:15:37 INFO opendrift.models.basemodel:2035: 2024-12-14 06:15:21.989750 - step 69 of 96 - 35938 active elements (0 deactivated)
20:15:38 INFO opendrift.models.basemodel:2035: 2024-12-14 06:45:21.989750 - step 70 of 96 - 36458 active elements (0 deactivated)
20:15:38 INFO opendrift.models.basemodel:2035: 2024-12-14 07:15:21.989750 - step 71 of 96 - 36978 active elements (0 deactivated)
20:15:38 INFO opendrift.models.basemodel:2035: 2024-12-14 07:45:21.989750 - step 72 of 96 - 37500 active elements (0 deactivated)
20:15:38 INFO opendrift.models.basemodel:2035: 2024-12-14 08:15:21.989750 - step 73 of 96 - 38020 active elements (0 deactivated)
20:15:39 INFO opendrift.models.basemodel:2035: 2024-12-14 08:45:21.989750 - step 74 of 96 - 38542 active elements (0 deactivated)
20:15:39 INFO opendrift.models.basemodel:2035: 2024-12-14 09:15:21.989750 - step 75 of 96 - 39062 active elements (0 deactivated)
20:15:39 INFO opendrift.models.basemodel:2035: 2024-12-14 09:45:21.989750 - step 76 of 96 - 39582 active elements (0 deactivated)
20:15:40 INFO opendrift.models.basemodel:2035: 2024-12-14 10:15:21.989750 - step 77 of 96 - 40104 active elements (0 deactivated)
20:15:40 INFO opendrift.models.basemodel:2035: 2024-12-14 10:45:21.989750 - step 78 of 96 - 40624 active elements (0 deactivated)
20:15:40 INFO opendrift.models.basemodel:2035: 2024-12-14 11:15:21.989750 - step 79 of 96 - 41146 active elements (0 deactivated)
20:15:41 INFO opendrift.models.basemodel:2035: 2024-12-14 11:45:21.989750 - step 80 of 96 - 41666 active elements (0 deactivated)
20:15:41 INFO opendrift.models.basemodel:2035: 2024-12-14 12:15:21.989750 - step 81 of 96 - 42186 active elements (0 deactivated)
20:15:42 INFO opendrift.models.basemodel:2035: 2024-12-14 12:45:21.989750 - step 82 of 96 - 42708 active elements (0 deactivated)
20:15:42 INFO opendrift.models.basemodel:2035: 2024-12-14 13:15:21.989750 - step 83 of 96 - 43228 active elements (0 deactivated)
20:15:42 INFO opendrift.models.basemodel:2035: 2024-12-14 13:45:21.989750 - step 84 of 96 - 43750 active elements (0 deactivated)
20:15:43 INFO opendrift.models.basemodel:2035: 2024-12-14 14:15:21.989750 - step 85 of 96 - 44270 active elements (0 deactivated)
20:15:43 INFO opendrift.models.basemodel:2035: 2024-12-14 14:45:21.989750 - step 86 of 96 - 44790 active elements (0 deactivated)
20:15:43 INFO opendrift.models.basemodel:2035: 2024-12-14 15:15:21.989750 - step 87 of 96 - 45312 active elements (0 deactivated)
20:15:44 INFO opendrift.models.basemodel:2035: 2024-12-14 15:45:21.989750 - step 88 of 96 - 45832 active elements (0 deactivated)
20:15:44 INFO opendrift.models.basemodel:2035: 2024-12-14 16:15:21.989750 - step 89 of 96 - 46354 active elements (0 deactivated)
20:15:45 INFO opendrift.models.basemodel:2035: 2024-12-14 16:45:21.989750 - step 90 of 96 - 46874 active elements (0 deactivated)
20:15:45 INFO opendrift.models.basemodel:2035: 2024-12-14 17:15:21.989750 - step 91 of 96 - 47394 active elements (0 deactivated)
20:15:46 INFO opendrift.models.basemodel:2035: 2024-12-14 17:45:21.989750 - step 92 of 96 - 47916 active elements (0 deactivated)
20:15:46 INFO opendrift.models.basemodel:2035: 2024-12-14 18:15:21.989750 - step 93 of 96 - 48436 active elements (0 deactivated)
20:15:47 INFO opendrift.models.basemodel:2035: 2024-12-14 18:45:21.989750 - step 94 of 96 - 48958 active elements (0 deactivated)
20:15:47 INFO opendrift.models.basemodel:2035: 2024-12-14 19:15:21.989750 - step 95 of 96 - 49478 active elements (0 deactivated)
20:15:48 INFO opendrift.models.basemodel:2035: 2024-12-14 19:45:21.989750 - step 96 of 96 - 50000 active elements (0 deactivated)
20:15:51 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)
20:16:00 DEBUG opendrift.config:168: Adding 18 config items from __init__
20:16:00 DEBUG opendrift.config:178: Overwriting config item readers:max_number_of_fails
20:16:00 DEBUG opendrift.config:168: Adding 5 config items from __init__
20:16:00 INFO opendrift.models.basemodel:515: OpenDriftSimulation initialised (version 1.12.0 / v1.12.0-26-g390e945)
20:16:00 DEBUG opendrift.config:168: Adding 15 config items from oceandrift
20:16:00 DEBUG opendrift.config:178: Overwriting config item seed:z
20:16:00 DEBUG opendrift.export.io_netcdf:239: Importing with Xarray from runoff.nc
20:16:00 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)
20:16:01 INFO opendrift.models.basemodel:3892: calculating for origin_marker 0...
20:16:01 INFO opendrift.models.basemodel:3892: calculating for origin_marker 1...
20:16:01 DEBUG opendrift.models.basemodel:2364: Setting up map: corners=None, fast=False, lscale=None
20:16:01 DEBUG opendrift.readers.reader_global_landmask:78: 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:1692: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap', 'vmin', 'vmax' will be ignored
result = super().scatter(*args, **kwargs)
20:16:21 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:23 DEBUG opendrift.models.basemodel:3044: Saving animation..
20:16:23 INFO opendrift.models.basemodel:4613: Saving animation to /root/project/docs/source/gallery/animations/example_river_runoff_0.gif...
20:16:23 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:24 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:26 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:28 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:30 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:31 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:33 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:35 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:36 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:38 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:40 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:41 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:43 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:44 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:47 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:48 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:50 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:52 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:53 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:55 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:57 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:16:58 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:00 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:01 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:03 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:05 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:06 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:08 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:10 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:12 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:14 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:16 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:18 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:19 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:21 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:22 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:24 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:26 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:27 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:29 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:30 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:32 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:34 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:35 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:37 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:39 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:40 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:42 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:44 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:46 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:48 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:49 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:51 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:53 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:55 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:56 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:58 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:17:59 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:01 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:03 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:04 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:06 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:08 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:09 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:11 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:13 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:14 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:16 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:18 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:19 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:21 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:22 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:24 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:26 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:27 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:29 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:30 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:32 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:34 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:35 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:37 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:38 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:40 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:41 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:43 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:44 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:46 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:47 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:49 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:50 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:52 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:53 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:55 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:57 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:18:58 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:19:00 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:19:01 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:19:03 DEBUG opendrift.readers.reader_global_landmask:78: Adding GSHHG shapes from cartopy, scale: h, extent: (7.309537506103514, 10.789533996582032, 57.41804962158203, 58.819724273681636)..
20:19:06 DEBUG opendrift.models.basemodel:4651: MPLBACKEND = agg
20:19:06 DEBUG opendrift.models.basemodel:4652: DISPLAY = None
20:19:06 DEBUG opendrift.models.basemodel:4653: Time to save animation: 0:02:42.828016
20:19:06 INFO opendrift.models.basemodel:3037: Time to make animation: 0:03:04.474319
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()
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)
20:19:06 INFO opendrift.models.basemodel:3892: calculating for origin_marker 0...
20:19:06 INFO opendrift.models.basemodel:3892: calculating for origin_marker 1...
20:19:07 INFO opendrift.models.basemodel:3892: calculating for origin_marker 0...
20:19:07 INFO opendrift.models.basemodel:3892: calculating for origin_marker 1...
20:19:07 DEBUG opendrift.models.basemodel:2364: Setting up map: corners=None, fast=True, lscale=None
20:19:07 WARNING opendrift.models.basemodel:2410: Plotting fast. This will make your plots less accurate.
Total running time of the script: (3 minutes 51.964 seconds)