Running a multi-member hydrological ensemble on the Raven Server¶
Here we use birdy’s WPS client to launch the GR4JCN hydrological model using two sets of parameters.
[1]:
from birdy import WPSClient
from example_data import TESTDATA
import datetime as dt
from urllib.request import urlretrieve
import xarray as xr
import numpy as np
from matplotlib import pyplot as plt
import os
# Set environment variable WPS_URL to "http://localhost:9099" to run on the default local server
url = os.environ.get("WPS_URL", "https://pavics.ouranos.ca/twitcher/ows/proxy/raven/wps")
wps = WPSClient(url)
[2]:
# The model parameters for gr4jcn and hmets.
# It's not possible at the moment to pass multiple parameters as a nested list due to the WPSClient limitations.
# Use a list of strings instead.
params = ['0.529, -3.396, 407.29, 1.072, 16.9, 0.947', '0.4, -3.96, 307.29, 1.072, 16.9, 0.947']
# Forcing files. Raven uses the same forcing files for all and extracts the information it requires for each model.
ts=TESTDATA['raven-gr4j-cemaneige-nc-ts']
# Model configuration parameters.
config = dict(
start_date=dt.datetime(2000, 1, 1),
end_date=dt.datetime(2002, 1, 1),
area=4250.6,
name="Salmon",
elevation=843.0,
latitude=54.4848,
longitude=-123.3659,
)
# Launch the WPS to get the multi-model results. Note the "gr4jcn" and "hmets" keys.
resp = wps.raven_gr4j_cemaneige(ts=str(ts), params=params, **config)
The hydrograph
and storage
output are netCDF files where the simulations are concatenated along the params
dimension. The solution
output is a list of rvc
files, and the diagnostics
a list of performance metrics comparing simulations with observations.
[3]:
[hydrograph, storage, solution, diagnostics, rv] = resp.get(asobj=True)
hydrograph
[3]:
xarray.Dataset
- nbasins: 1
- params: 2
- time: 732
- basin_name(nbasins)object...
- long_name :
- Name/ID of sub-basins with simulated outflows
- cf_role :
- timeseries_id
- units :
- 1
array(['Salmon'], dtype=object)
- time(time)datetime64[ns]2000-01-01 ... 2002-01-01
- standard_name :
- time
array(['2000-01-01T00:00:00.000000000', '2000-01-02T00:00:00.000000000', '2000-01-03T00:00:00.000000000', ..., '2001-12-30T00:00:00.000000000', '2001-12-31T00:00:00.000000000', '2002-01-01T00:00:00.000000000'], dtype='datetime64[ns]')
- q_obs(time, nbasins)float64...
- units :
- m**3 s**-1
- long_name :
- Observed outflows
array([[ nan], [11.1], [10.9], ..., [11.7], [12.1], [12.3]])
- q_in(time, nbasins)float64...
- units :
- m**3 s**-1
- long_name :
- Observed inflows
array([[nan], [nan], [nan], ..., [nan], [nan], [nan]])
- precip(time)float64...
- units :
- mm d**-1
- long_name :
- Precipitation
array([ nan, 2.478706, 0.628235, ..., 0. , 0.003882, 0. ])
- q_sim(params, time, nbasins)float64...
- units :
- m**3 s**-1
- long_name :
- Simulated outflows
array([[[ 0. ], [ 0.165788], ..., [13.330653], [13.25446 ]], [[ 0. ], [ 0.123831], ..., [11.191918], [11.114937]]])
- Conventions :
- CF-1.6
- featureType :
- timeSeries
- history :
- Created on 2020-05-01 17:35:52 by Raven
- description :
- Standard Output
- title :
- Simulated river discharge
- references :
- Craig J.R. and the Raven Development Team Raven user's and developer's manual (Version 2.8) URL: http://raven.uwaterloo.ca/ (2018).
- comment :
- Raven Hydrological Framework version 2.9 rev#254
- model_id :
- gr4jcn
- time_frequency :
- day
- time_coverage_start :
- 2000-01-01 00:00:00
- time_coverage_end :
- 2002-01-01 00:00:00
[4]:
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
hydrograph.q_sim.isel(nbasins=0).plot.line(hue='params')
[4]:
[<matplotlib.lines.Line2D at 0x7f1c8632c2b0>,
<matplotlib.lines.Line2D at 0x7f1c84e988d0>]
[5]:
print(diagnostics)
['observed data series,filename,DIAG_NASH_SUTCLIFFE,DIAG_RMSE,\nHYDROGRAPH,/tmp/pywps_process_mv5m3m6u/Salmon-River-Near-Prince-George_meteo_daily.nc,-0.117301,37.9493,\n', 'observed data series,filename,DIAG_NASH_SUTCLIFFE,DIAG_RMSE,\nHYDROGRAPH,/tmp/pywps_process_mv5m3m6u/Salmon-River-Near-Prince-George_meteo_daily.nc,-0.0559845,36.8933,\n']