Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Initialize self. See help(type(self)) for accurate signature. API Reference
children
comment
comment: unicode
double_size
double_size: ‘int’
integer_size
integer_size: ‘int’
is_variable
is_variable: ‘bool’
model
name
parents
size
coming soon...
A simple parameter defining a constant value. API Reference
type
constantparameter
Yes
value
The constant value
Yes
type
dailyprofile
Yes
values
An array of 366 numbers whose indices represent the days of the year.
Yes
A collection of IndexParameters
This class behaves like a set. Parameters can be added or removed from it. Its index is the index of it’s child parameters aggregated using a aggregating function (e.g. sum). API Reference
agg_func
children
comment
comment: unicode
double_size
double_size: ‘int’
integer_size
integer_size: ‘int’
is_variable
is_variable: ‘bool’
model
name
parameters
parameters: list
parents
size
coming soon...
A collection of IndexParameters. This class behaves like a set. Parameters can be added or removed from it. It’s value is the value of it’s child parameters aggregated using a aggregating function (e.g. sum). API Reference
type
aggregated
Yes
parameters
The parameters to aggregate
Optional
agg_func
The aggregation function. Must be one of {“sum”, “min”, “max”, “mean”, “product”}, or a callable function which accepts a list of values
Optional
In this case Aggregated Parameter is multipliying two parameters togther
Control curve demand factor
This example shows a Baseline demand being multiplied by a factor that reduces demand based on a reservoir control curve. You can click on the each of these Parameters to see how they are defined.
All the Parameter subclasses in pywr are descended from a common base class.
An overview of Pywr parmeters supported by WaterStrategy
Paramters are functions that return a value in the model at each time-step. These values can be a constant, based on time (e.g., on the day or month), a calculation based on the time step's reservoir storage and many other calculations. Custom parameter can also be written in Python.
This page describes (most of) the parameter types supported by Pywr. An overview of parameters in Pywr can be found . The full list of built-in Pywr parameters are found .
In a Network, click the 'Parameters' Tab:
Next to the 'Parameters-Type Categories' section, click the '+' button and select 'PYWR_PARAMETER'.
A text-input will appear. Enter the name of your parameter:
Modify the parameter as required in the JSON editor provided:
To make parameter modifications simpler, WaterStrategy offers editors for commonly used Parameters, such as Monthly Profile parameters, with pre-populated default values, and graphical editors to make entering of data simpler.
In the Parameters Tab, when adding a new Parameter, select 'PYWR_PARAMETER_MONTHLY_PROFILE' as shown:
Note that the edior which appears will show a JSON tab, but also a Plot and Table tab. Modifying the data in the table will automaticall update the data in the JSON as shown:
These changes automatically update the JSON:
children
comment
comment: unicode
double_size
double_size: ‘int’
integer_size
integer_size: ‘int’
is_variable
is_variable: ‘bool’
model
name
parents
size
children
comment
comment: unicode
double_size
double_size: ‘int’
integer_size
integer_size: ‘int’
is_variable
is_variable: ‘bool’
model
name
parameter
parameter: pywr.parameters._parameters.Parameter
parents
size
children
comment
comment: unicode
double_size
double_size: ‘int’
integer_size
integer_size: ‘int’
is_variable
is_variable: ‘bool’
model
name
parents
size
children
comment
comment: unicode
double_size
double_size: ‘int’
integer_size
integer_size: ‘int’
is_variable
is_variable: ‘bool’
model
name
parents
size
Parameter that takes maximum of another Parameter and constant value (threshold).
This class is a more efficient version of AggregatedParameter where a single Parameter is compared to constant value. API Reference
children
comment
comment: unicode
double_size
double_size: ‘int’
integer_size
integer_size: ‘int’
is_variable
is_variable: ‘bool’
model
name
parameter
parameter: pywr.parameters._parameters.Parameter
parents
size
threshold
threshold: ‘double’
coming soon...
The weekly profile contains 52 weeks per year. The last week of the year will have more than 7 days, as 365 / 7 is not whole. API Reference
type
weeklyprofile
Yes
values
An array of 52 numbers whose indices represent the days of the year.
Yes
Parameter that takes maximum of the negative of a Parameter and constant value (threshold). API Reference
children
comment
comment: unicode
double_size
double_size: ‘int’
integer_size
integer_size: ‘int’
is_variable
is_variable: ‘bool’
model
name
parameter
parameter: pywr.parameters._parameters.Parameter
parents
size
threshold
threshold: ‘double’
coming soon...
Parameter that divides one Parameter by another. API Reference
children
comment
comment: unicode
denominator
double_size
double_size: ‘int’
integer_size
integer_size: ‘int’
is_variable
is_variable: ‘bool’
model
name
numerator
parents
size
coming soon...
Parameter that takes minimum of another Parameter and constant value (threshold).
This class is a more efficient version of AggregatedParameter where a single Parameter is compared to constant value. API Reference
children
comment
comment: unicode
double_size
double_size: ‘int’
integer_size
integer_size: ‘int’
is_variable
is_variable: ‘bool’
model
name
parameter
parameter: pywr.parameters._parameters.Parameter
parents
size
threshold
threshold: ‘double’
coming soon...
Time varying parameter using an array and Timestep.index with multiplicative factors per Scenario.
Values is the baseline timeseries data that is perturbed by a factor. The factor is taken from factors which is shape (scenario.size, 12). Therefore factors vary with the individual scenarios in scenario and month.
coming soon...
children
comment
comment: unicode
double_size
double_size: ‘int’
integer_size
integer_size: ‘int’
is_variable
is_variable: ‘bool’
model
name
offset
The offset to apply to the value returned by parameter
parameter
The parameter to compare with the float
lower_bounds
The lower bounds of the offset when used during optimisation
upper_bounds
The upper bounds of the offset when used during optimisation
parents
size
scenario
Scenario object over which different profiles should be provided
Yes
values
Length of 1st dimension should equal the number of members in the scenario object and the length of the second dimension should be 366
Yes
scenario
Scenario object over which different profiles should be provided
Yes
values
Length of 1st dimension should equal the number of members in the scenario object and the length of the second dimension should be 52
Yes
scenario
Scenario object over which different profiles should be provided
Yes
values
Length of 1st dimension should equal the number of members in the scenario object and the length of the second dimension should be 12
Yes
scenario
Scenario object over which different profiles should be provided
Yes
values
Length of 1st dimension should equal the number of members in the scenario object and the length of the second dimension should be 12
Yes
Parameter that takes minimum of the negative of a Parameter and constant value (threshold). API Reference
children
comment
comment: unicode
double_size
double_size: ‘int’
integer_size
integer_size: ‘int’
is_variable
is_variable: ‘bool’
model
name
parameter
parameter: pywr.parameters._parameters.Parameter
parents
size
threshold
threshold: ‘double’
coming soon...
Parameter which provides a uniformly reducing value from one to zero.
This parameter is intended to be used with an AnnualVirtualStorage node to provide a profile that represents perfect average utilisation of the annual volume. It returns a value of 1 on the reset day, and subsequently reduces by 1/366 every day afterward. API Reference
reset_day
The day of the month (1-31) to reset the volume to the initial value
Yes
reset_month
The month of the year (1-12) to reset the volume to the initial value
Yes
coming soon...
Parameter which interpolates a daily profile using a radial basis function (RBF).
The daily profile is computed during model reset using a radial basis function with day-of-year as the independent variables. The days of the year are defined by the user alongside the values to use on each of those days for the interpolation. The first day of the years should always be one, and its value is repeated as the 366th value. In addition the second and penultimate values are mirrored to encourage a consistent gradient to appear across the boundary. The RBF calculations are undertaken using the scipy.interpolate.Rbf object, please refer to Scipy’s documentation for more information. API Reference
days_of_year
The days of the year at which the interpolation values are defined. The first value should be one
Yes
values
Values to use for interpolation corresponding to the days_of_year
Yes
lower_bounds
The lower bounds of the values when used during optimisation
Yes
upper_bounds
The upper bounds of the values when used during optimisation
Yes
variable_days_of_year_range
The maximum bounds (positive or negative) for the days of year during optimisation. A non-zero value will cause the days of the year values to be exposed as integer variables (except the first value which remains at day 1). This value is bounds on those variables as maximum shift from the given days_of_year
Yes
min_value, max_value
Optionally cap the interpolated daily profile to a minimum and/or maximum value. The default values are negative and positive infinity for minimum and maximum respectively
Yes
rbf_kwargs
Optional dictionary of keyword arguments to base to the Rbf object
Optional
coming soon...
Time varying parameter using an array and Timestep.index
The values in this parameter are constant across all scenarios. API Reference
coming soon...
Base class for parameters returning one of two values depending on other state. API Reference
threshold
Threshold to compare the value of the recorder to
Yes
values
If the predicate evaluates False the zeroth value is returned, otherwise the first value is returned
Yes
predicate
One of {“LT”, “GT”, “EQ”, “LE”, “GE”}
Yes
ratchet
If true the parameter behaves like a ratchet. Once it is triggered first it stays in the triggered position (default=False)
Yes
coming soon...
Returns one of two values depending on the year of the current timestep. API Reference
threshold
Threshold to compare the value of the recorder to
Yes
ratchet
If true the parameter behaves like a ratchet. Once it is triggered first it stays in the triggered position (default=False)
Yes
coming soon...
Parameter which uses an IndexParameter to index an array of Parameters.
An example use of this parameter is to return a demand saving factor (as a float) based on the current demand saving level (calculated by an IndexParameter). API Reference
index_parameter
IndexParameter
Yes
params
iterable of Parameters or floats
Yes
The above code uses the Index supplied by the parameter called 'Reservoir control curve', which is a Control Curve Index Parameter. Index 0 returns a 1, Index 2 returns 0.9 etc...
In this example this parameter is used to reduce a demand based on a reservoir control curve. Please go to the Aggregated Parameter example to see how this is done.
Please see how the Reservoir control curve parameter is defined.
A Scenario varying Parameter.
The values in this parameter are vary in time based on index and vary within a single Scenario. API Reference
coming soon...
Returns one of two values depending on current volume in a Storage node. API Reference
threshold
Threshold to compare the value of the recorder to
Yes
storage
storage: pywr._core.AbstractStorage
Yes
ratchet
If true the parameter behaves like a ratchet. Once it is triggered first it stays in the triggered position (default=False)
Yes
coming soon...
Returns one of two values depending on the value of a Parameter. API Reference
threshold
Threshold to compare the value of the recorder to
Yes
ratchet
If true the parameter behaves like a ratchet. Once it is triggered first it stays in the triggered position (default=False)
Yes
coming soon...
Timeseries parameter with automatic alignment and resampling. API Reference
type
dataframe
Yes
model
Optional
dataframe
Optional
scenario
Optional
Parameter which provides a monthly profile. The monthly profile returns a different value based on the month of the current time-step. API Reference
type
monthlyprofile
Yes
values
An array of 12 numbers whose indices represent the months of the year.
Yes
Water Strategy offers an alternative way to work with Monthly Profiles.
This Parameter reads array data from a PyTables HDF database.
The parameter reads data using the PyTables array interface and therefore does not require loading the entire dataset in to memory. This is useful for large model runs. API Reference
By storing HDF5 files in the "fixed" format, users can achieve optimal data access speeds, making HDF5 an effective tool for Pywr-scenarios that use DataFrames as parameters, where fast data retrieval is crucial. HDF5 files are read as a dictionary, where each key represents a pandas DataFrame. For example, the structure of an inflows.h5 file might contain three keys, each representing a different river. Each key holds three time series that can be assigned to a Pywr scenario of size 3.
If using h5 file DataFrame for running pywr-scenarios, please refer to pywr-scenarios section in order to activate this feature
Note: The size of pywr-scenarios must match the number of keys in the h5 file
h5file
The tables file handle or filename to attach the CArray objects to. If a filename is given the object will open and close the file handles
Yes
node
Name of the node in the tables database to read data from
Yes
where
Path to read the node from
Yes
scenario
Scenario to use as the second index in the array
Yes
threshold
Threshold to compare the value of the recorder to
Yes
ratchet
If true the parameter behaves like a ratchet. Once it is triggered first it stays in the triggered position (default=False)
Yes
recorder
recorder: pywr.recorders._recorders.Recorder
threshold
Threshold to compare the value of the recorder to
Yes
ratchet
If true the parameter behaves like a ratchet. Once it is triggered first it stays in the triggered position (default=False)
Yes
threshold
Threshold to compare the value of the recorder to
Yes
ratchet
If true the parameter behaves like a ratchet. Once it is triggered first it stays in the triggered position (default=False)
Yes
type
interpolatedflow
Yes
node
Node to provide input flow values to interpolation calculation
Optional
flows
x coordinates of the data points for interpolation
Optional
values
y coordinates of the data points for interpolation
Optional
interp_kwargs
Dictionary of keyword arguments to pass to scipy.interpolate.interp1d class and used for interpolation
Optional
type
interpolatedflow
Yes
node
Node to provide input flow values to interpolation calculation
Optional
interp_kwargs
Dictionary of keyword arguments to pass to scipy.interpolate.interp1d class and used for interpolation
Optional
storage_node
An optional Storage node that can be used to query the current percentage volume
Yes
control_curves
The Parameter objects to use as a control curve(s)
Yes
The hydropower target parameter is a parameter that returns flow from a hydropower generation target. This parameter calculates the flow required to generate a particular hydropower production target. It is intended to be used on a node representing a turbine where a particular production target is required each time-step. API Reference
type
hydropowertarget
Yes
target
Hydropower production target. Units should be in units of energy per day
Optional
water_elevation_parameter
Elevation of water entering the turbine. The difference of this value with the turbine_elevation gives the working head of the turbine
Optional
max_flow
Upper bounds on the calculated flow. If set the flow returned by this parameter is at most the value of the max_flow parameter
Optional
min_flow
Lower bounds on the calculated flow. If set the flow returned by this parameter is at least the value of the min_flow parameter
Optional
min_head
Minimum head for flow to occur. If actual head is less than this value zero flow is returned
Optional
turbine_elevation
Elevation of the turbine itself. The difference between the water_elevation and this value gives the working head of the turbine
Optional
efficiency
The efficiency of the turbine
Optional
density
The density of water
Optional
flow_unit_conversion
A factor used to transform the units of flow to be compatible with the equation here. This should convert flow to units of m3/day
Optional
energy_unit_conversion
A factor used to transform the units of total energy. Defaults to 1e-6 to return MJ
Optional
Parameter track the deficit (max_flow - actual flow) of a Node. API Reference
Notes: This parameter is a little unusual in that it’s value is calculated during the after method, not calc_values. It is intended to be used in combination with a recorder (e.g. NumpyArrayNodeRecorder) to record the deficit ( defined as requested - actual flow) at a node. Note that this means recording this parameter does not give you the value that was used by the solver in this timestep. Alternatively, this parameter can be used in the model by other parameters and will evaluate to yesterdays deficit, where the deficit in the zeroth timestep is zero.
model
pywr.model.Model
Yes
node
The node that will have it’s deficit tracked
Yes
coming soon...
Parameter value is equal to the quadrature of the interpolation of another parameter. API Reference
upper_parameter
Upper value of the interpolated interval to integrate over
Yes
x
x coordinates of the data points for interpolation
Optional
y
y coordinates of the data points for interpolation
Optional
lower_parameter
Lower value of the interpolated interval to integrate over. Can be None in which case the lower value of interval is zero
Optional
interp_kwargs
Dictionary of keyword arguments to pass to scipy.interpolate.interp1d class and used for interpolation
Optional
coming soon...
A control curve Parameter that interpolates between three or more values.
Return values are linearly interpolated between control curves, with the first and last value being 100% and 0% respectively. API Reference
storage_node
An optional Storage node that can be used to query the current percentage volume
Yes
control_curves
The Parameter objects to use as a control curve(s)
Yes
values
A list of values to return corresponding to the control curves. The length of the list should be 2 + len(control_curves)
Yes
parameters
If values is None then parameters can specify a Parameter object to use at each of the control curves. The number of parameters should be 2 + len(control_curves)
Yes
coming soon...
A control curve Parameter that interpolates between two or more pairs of values.
Return values are linearly interpolated between a pair of values depending on the current storage. The first pair is used between maximum and the first control curve, the next pair between the first control curve and second control curve, and so on until the last pair is used between the last control curve and the minimum value. The first value in each pair is the value at the upper position, and the second the value at the lower position. API Reference
storage_node
The storage node to compare the control curve(s) to
Yes
control_curves
A list of parameters representing the control curve(s). These are often MonthlyProfileParameters or DailyProfileParameters, but may be any Parameter that returns values between 0.0 and 1.0. If floats are passed they are converted to ConstantParameter
Yes
values
A list of value pairs to interpolate between. The length of the list should be 1 + len(control_curves)
Yes
minimum
The storage considered the bottom of the lower curve, 0-1 (default=0)
Yes
maximum
The storage considered the top of the upper curve, 0-1 (default=1)
Yes
coming soon...
Parameter that returns the current discount factor based on discount rate and a base year. API Reference
discount_rate
Discount rate (expressed as 0 - 1) used calculate discount factor for each year
Yes
base_year
Discounting base year (i.e. the year with a discount factor equal to 1.0)
Yes
coming soon...
Parameter that integrates a piecewise function.
This parameter calculates the integral of a piecewise function. The piecewise function is given as two arrays (x and y) and is assumed to start from (0, 0). The values of x should be monotonically increasing and greater than zero. API Reference
parameter
The parameter the defines the right hand bounds of the integration
Yes
x
iterable of doubles
Yes
y
iterable of doubles
Yes
coming soon...
Parameter that returns the delayed flow for a node after a given number of timesteps or days. API Reference
model
pywr.model.Model
Yes
node
The node to delay for
Yes
timesteps
Number of timesteps to delay the flow
Yes
days
Number of days to delay the flow. Specifying a number of days (instead of a number of timesteps) is only valid if the number of days is exactly divisible by the model timestep length
Yes
initial_flow
Flow value to return for initial model timesteps prior to any delayed flow being available. This value is constant across all delayed timesteps and any model scenarios. Default is 0.0
Yes
coming soon...
The above code defines 3 reservoir control curves for the reservoir called "Reservoir name". It returns an Index depending on how full the reservoir is:
To see how this index is used with an Indexed Array Parameter click here.
Generic interpolation parameter that returns a value based on a Reservoir or Storage nodes current (time step) volume. The
parameter uses an array (table) of Reservoir Volumes and corresponding values. In this case the associated values are the corresponding Reservoir Area for a given Volume.
Interpolation is used to calculate values betwen points given in the interpolation array. API Reference
type
interpolatedvolume
Yes
node
Storage node to provide input volume values to interpolation calculation
Yes
volumes
x coordinates of the data points for interpolation
Yes
values
y coordinates of the data points for interpolation
Yes
interp_kwargs
Dictionary of keyword arguments to pass to scipy.interpolate.interp1d class and used for interpolation
Optional
The following Json shows an example Area vs Volume rating cure for a reservoir. This could be used to define the Area attribute of a Storage or Reservoir node.
The Json represents the table below:
0
1
7
2
10
4
15
6
25
14
When plotted it looks like this:
Below is an example Area rating table
0
1
7
2
10
4
15
6
25
14
When plotted it looks like this
Parameter that utilises a different child parameter in each scenario ensemble.
This parameter is used to switch between different child parameters based on different ensembles in a given Scenario. It can be used to vary data in a non-scenario aware parameter type across multiple scenario ensembles. For example, many of control curve or interpolation parameters do not explicitly support scenarios. This parameter can be used to test multiple control curve definitions as part of a single simulation. API Reference
scenario
The scenario instance which is used to select the parameters
Yes
parameters
The child parameters that are used in each of scenario’s ensembles. The number of parameters must equal the size of the given scenario
Yes
coming soon...
Parameter that provides the flow from a node from the previous time-step. API Reference
Notes: This parameter keeps track of the previous time step’s flow on the given node. These values can be used in calculations for the current timestep as though this was any other parameter.
model
pywr.model.Model
Yes
node
The node that will have its flow tracked
Yes
initial_value
The value to return on the first time-step before the node has any past flow
Yes
coming soon...
A Parameter which returns the value from an annual harmonic series.
This Parameter comprises a series N cosine function with a period of 365 days. The calculation is performed using the Julien day of the year minus 1. This causes a small discontinuity in non-leap years. API Reference
mean
Mean value for the series (i.e. the position of zeroth harmonic)
Yes
amplitudes
The amplitudes for the N harmonic cosine functions. Must be the same length as phases
Yes
phases
The phase shift of the N harmonic cosine functions. Must be the same length as amplitudes
Yes
coming soon...