River runoff

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


outfile = 'runoff.nc'  # Raw simulation output
analysis_file = 'runoff_density.nc'  # Raw simulation output
try:
    os.remove(analysis_file)
except OSError:
    pass

First make a simulation with two seedings, marked by origin_marker

o = OceanDrift(loglevel=20)
t1 = datetime.now()
t2 = t1 + timedelta(hours=48)
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]

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])
o.set_config('drift:horizontal_diffusivity', 300)
o.set_config('general:coastline_action', 'previous')
o.run(duration=timedelta(hours=48),
      time_step=1800, time_step_output=3600, outfile=outfile)

Out:

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

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. Note that the analysis file will be re-used if existing. Thus this file should be deleted after making any changes to the simulation above.

o = opendrift.open_xarray(outfile, analysis_file=analysis_file)

Out:

13:46:47 DEBUG   opendrift.models.basemodel: Adding 17 config items from basemodel
13:46:47 DEBUG   opendrift.models.basemodel: Adding 4 config items from basemodel
13:46:47 DEBUG   opendrift.models.basemodel: Adding 34 config items from basemodel
13:46:47 INFO    opendrift.models.basemodel: OpenDriftSimulation initialised (version 1.7.1 / v1.7.1-87-g074c1d2)
13:46:47 DEBUG   opendrift.models.basemodel: Adding 14 config items from oceandrift
13:46:47 DEBUG   opendrift.models.basemodel:   Overwriting config item seed:z
13:46:47 DEBUG   opendrift.export.io_netcdf: Importing with Xarray from runoff.nc
13:46:47 INFO    opendrift: 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

o.get_density_xarray(pixelsize_m=1500, weights=runoff)


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=o.ads.density.where(o.ads.density>0), bgalpha=1, fast=False,
            show_elements=False, vmin=0, vmax=120, text=text, box=box)

Out:

13:46:47 INFO    opendrift.models.basemodel: Calculating density array, this may take some time...
13:46:47 INFO    opendrift.models.basemodel:    calculating for origin_marker 0...
13:46:47 INFO    opendrift.models.basemodel:    calculating for origin_marker 1...
13:46:47 INFO    opendrift.models.basemodel: Time to calculate density array: 0:00:00.491491
13:46:47 DEBUG   opendrift.models.basemodel: Finding min longitude...
13:46:48 DEBUG   opendrift.models.basemodel: Finding max longitude...
13:46:48 DEBUG   opendrift.models.basemodel: Finding min latitude...
13:46:48 DEBUG   opendrift.models.basemodel: Finding max latitude...
13:46:48 DEBUG   opendrift.readers.reader_global_landmask: Using existing GSHHS shapes..
13:46:48 DEBUG   opendrift_landmask_data.mask: mask already memmapped
13:47:04 INFO    opendrift.models.basemodel: Saving animation to /root/project/docs/source/gallery/animations/example_river_runoff_0.gif...
13:47:04 INFO    opendrift.models.basemodel: Making animated gif...
MovieWriter imagemagick unavailable; using Pillow instead.
13:47:43 DEBUG   opendrift.models.basemodel: Time to make animation: 0:00:55.716070
../_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')
ax1.margins(x=0)
ax1.legend()
# Area 1
t1, t1_om = o.get_density_timeseries(lon=box1_lon, lat=box1_lat)
t1_om.isel(origin_marker=0).plot(label=o.origin_marker[0], ax=ax2)
t1_om.isel(origin_marker=1).plot(label=o.origin_marker[1], ax=ax2)
t1.plot(label='Total', linestyle='--', ax=ax2)
ax2.legend()
ax2.margins(x=0)
ax2.set_title('Amount of water passing through Area 1')
# Area 2
t2, t2_om = o.get_density_timeseries(lon=box2_lon, lat=box2_lat)
t2_om.isel(origin_marker=0).plot(label=o.origin_marker[0], ax=ax3)
t2_om.isel(origin_marker=1).plot(label=o.origin_marker[1], ax=ax3)
t2.plot(label='Total', linestyle='--', ax=ax3)
ax3.legend()
ax3.margins(x=0)
ax3.set_title('Amount of water passing through Area 2')
# Extracting time series at the location of the station
t, t_om = o.get_density_timeseries(lon=station_lon, lat=station_lat)
t_om.isel(origin_marker=0).plot(label=o.origin_marker[0], ax=ax4)
t_om.isel(origin_marker=1).plot(label=o.origin_marker[1], ax=ax4)
t.plot(label='Total', linestyle='--', ax=ax4)
ax4.legend()
ax4.margins(x=0)
ax4.set_title('Density of water at Station')

plt.show()


# Cleaning up
os.remove(outfile)
os.remove(analysis_file)
Runoff, Amount of water passing through Area 1, Amount of water passing through Area 2, Density of water at Station

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

Gallery generated by Sphinx-Gallery