hbranch¶
The HydPy-H-Branch defines methods for branching single inflow values into multiple outflow values.
Method Features¶
- class hydpy.models.hbranch.hbranch_model.Model[source]¶
Bases:
AdHocModelThe HydPy-H-Branch model.
- The following “inlet update methods” are called in the given sequence at the beginning of each simulation step:
Pick_OriginalInput_V1UpdateOriginalInputbased onTotal.
- The following “run methods” are called in the given sequence during each simulation step:
Calc_AdjustedInput_V1Adjust the original input data.Calc_Outputs_V1Perform the actual interpolation or extrapolation.
- The following “outlet update methods” are called in the given sequence at the end of each simulation step:
Pass_Outputs_V1UpdateBranchedbased onOutputs.
- connect() None[source]¶
Connect the
LinkSequenceinstances handled by the actual model to theNodeSequenceinstances handled by one inlet node and multiple oulet nodes.The HydPy-H-Branch model passes multiple output values to different outlet nodes. This requires additional information regarding the direction of each output value. Therefore, node names are used as keywords. Assume the discharge values of both nodes inflow1 and inflow2 shall be branched to nodes outflow1 and outflow2 via element branch:
>>> from hydpy import Element, pub >>> branch = Element("branch", ... inlets=["inflow1", "inflow2"], ... outlets=["outflow1", "outflow2"])
Then parameter
YPointsrelates different supporting points via its keyword arguments to the respective nodes:>>> pub.timegrids = "2000-01-01", "2000-01-02", "1d" >>> from hydpy.models.hbranch import * >>> parameterstep() >>> delta(0.0) >>> xpoints(0.0, 3.0) >>> ypoints(outflow1=[0.0, 1.0], outflow2=[0.0, 2.0]) >>> parameters.update()
After connecting the model with its element the total discharge value of nodes inflow1 and inflow2 can be properly divided:
>>> branch.model = model >>> branch.inlets.inflow1.sequences.sim = 1.0 >>> branch.inlets.inflow2.sequences.sim = 5.0 >>> model.simulate(0) >>> branch.outlets.outflow1.sequences.sim sim(2.0) >>> branch.outlets.outflow2.sequences.sim sim(4.0)
In case of missing (or misspelled) outlet nodes, the following error is raised:
>>> branch.outlets.mutable = True >>> del branch.outlets.outflow1 >>> parameters.update() >>> model.connect() Traceback (most recent call last): ... RuntimeError: Model `hbranch` of element `branch` tried to connect to an outlet node named `outflow1`, which is not an available outlet node of element `branch`.
A missing reference to the corresponding element results in the following error message:
>>> model.element = None >>> model.connect() Traceback (most recent call last): ... RuntimeError: Model hbranch does not know the element it shall connect with so far.
- class hydpy.models.hbranch.hbranch_model.Pick_OriginalInput_V1[source]¶
Bases:
MethodUpdate
OriginalInputbased onTotal.- Requires the inlet sequence:
- Calculates the flux sequence:
- Basic equation:
\(OriginalInput = \sum Total\)
- class hydpy.models.hbranch.hbranch_model.Calc_AdjustedInput_V1[source]¶
Bases:
MethodAdjust the original input data.
- Requires the control parameters:
- Requires the derived parameter:
- Requires the flux sequence:
- Calculates the flux sequence:
- Basic equation:
\(AdjustedInput = max(OriginalInput + Delta, Minimum)\)
Examples:
The degree of the input adjustment may vary monthly. Hence, we need to define a concrete initialisation period for the following examples:
>>> from hydpy import pub >>> pub.timegrids = "2000-03-30", "2000-04-03", "1d" >>> from hydpy.models.hbranch import * >>> parameterstep() >>> derived.moy.update()
Negative
Deltavalues correspond to decreasing input:>>> delta.mar = -1.0 >>> minimum(0.0) >>> model.idx_sim = pub.timegrids.init["2000-03-31"] >>> fluxes.originalinput = 1.5 >>> model.calc_adjustedinput_v1() >>> fluxes.adjustedinput adjustedinput(0.5)
The adjusted input values are never smaller than the threshold value defined by parameter
Minimum:>>> minimum(1.0) >>> model.calc_adjustedinput_v1() >>> fluxes.adjustedinput adjustedinput(1.0)
Positive
Deltavalues correspond to increasing input:>>> model.idx_sim = pub.timegrids.init["2000-04-01"] >>> delta.apr = 1.0 >>> fluxes.originalinput = 0.5 >>> model.calc_adjustedinput_v1() >>> fluxes.adjustedinput adjustedinput(1.5)
- class hydpy.models.hbranch.hbranch_model.Calc_Outputs_V1[source]¶
Bases:
MethodPerform the actual interpolation or extrapolation.
- Requires the control parameters:
- Requires the derived parameters:
- Requires the flux sequence:
- Calculates the flux sequence:
Examples:
As a simple example, assume a weir directing all discharge into branch1 until reaching the capacity limit of 2 m³/s.
hbranch_v1redirects the discharge exceeding this threshold to branch2:>>> from hydpy.models.hbranch import * >>> parameterstep() >>> xpoints(0.0, 2.0, 4.0) >>> ypoints(branch1=[0.0, 2.0, 2.0], ... branch2=[0.0, 0.0, 2.0]) >>> derived.nmbbranches.update() >>> derived.nmbpoints.update()
Low discharge example (linear interpolation between the first two supporting point pairs):
>>> fluxes.adjustedinput = 1. >>> model.calc_outputs_v1() >>> fluxes.outputs outputs(branch1=1.0, branch2=0.0)
Medium discharge example (linear interpolation between the second two supporting point pairs):
>>> fluxes.adjustedinput = 3.0 >>> model.calc_outputs_v1() >>> print(fluxes.outputs) outputs(branch1=2.0, branch2=1.0)
High discharge example (linear extrapolation beyond the second two supporting point pairs):
>>> fluxes.adjustedinput = 5.0 >>> model.calc_outputs_v1() >>> fluxes.outputs outputs(branch1=2.0, branch2=3.0)
Non-monotonous relationships and balance violations are allowed:
>>> xpoints(0.0, 2.0, 4.0, 6.0) >>> ypoints(branch1=[0.0, 2.0, 0.0, 0.0], ... branch2=[0.0, 0.0, 2.0, 4.0]) >>> derived.nmbbranches.update() >>> derived.nmbpoints.update() >>> fluxes.adjustedinput = 7.0 >>> model.calc_outputs_v1() >>> fluxes.outputs outputs(branch1=0.0, branch2=5.0)
Parameter Features¶
Control parameters¶
- class hydpy.models.hbranch.ControlParameters(master: Parameters, cls_fastaccess: Type[FastAccessParameter] | None = None, cymodel: CyModelProtocol | None = None)
Bases:
SubParametersControl parameters of model hbranch.
- The following classes are selected:
Delta()Monthly varying difference for increasing or decreasing the input [e.g. m³/s].Minimum()The allowed minimum value of the adjusted input [e.g. m³/s].XPoints()Supporting points for the independent input variable [e.g. m³/s].YPoints()Supporting points for the dependent output variables [e.g. m³/s].
- class hydpy.models.hbranch.hbranch_control.Delta(subvars: SubParameters)[source]¶
Bases:
MonthParameterMonthly varying difference for increasing or decreasing the input [e.g. m³/s].
- Required by the method:
- class hydpy.models.hbranch.hbranch_control.Minimum(subvars: SubParameters)[source]¶
Bases:
ParameterThe allowed minimum value of the adjusted input [e.g. m³/s].
- Required by the method:
- class hydpy.models.hbranch.hbranch_control.XPoints(subvars: SubParameters)[source]¶
Bases:
ParameterSupporting points for the independent input variable [e.g. m³/s].
- Required by the method:
There must be at least two supporting points, and they must be strictly monotonous. If not,
XPointsraises the following errors:>>> from hydpy.models.hbranch import * >>> parameterstep() >>> xpoints(1.0, 2.0) >>> xpoints xpoints(1.0, 2.0)
>>> xpoints(1.0) Traceback (most recent call last): ... ValueError: Branching via linear interpolation requires at least two supporting points, but parameter `xpoints` of element `?` received 1 value(s).
>>> xpoints(1.0, 2.0, 2.0, 3.0) Traceback (most recent call last): ... ValueError: The values of parameter `xpoints` of element `?` must be arranged strictly monotonous, which is not the case for the given values `1.0, 2.0, 2.0, and 3.0`.
- class hydpy.models.hbranch.hbranch_control.YPoints(subvars: SubParameters)[source]¶
Bases:
ParameterSupporting points for the dependent output variables [e.g. m³/s].
- Required by the method:
Preparing parameter
YPointsrequires consistency with parameterXPointsand the currently availableNodeobjects.>>> from hydpy.models.hbranch import * >>> parameterstep("1d") >>> ypoints ypoints(?)
You need to prepare the parameter
XPointsfirst:>>> ypoints(1.0, 2.0) Traceback (most recent call last): ... RuntimeError: The shape of parameter `ypoints` of element `?` depends on the shape of parameter `xpoints`, which has not been defined so far.
>>> xpoints(1.0, 2.0, 3.0)
You need to supply the names of the output
Nodeobjects as keyword arguments:>>> ypoints(1.0, 2.0) Traceback (most recent call last): ... ValueError: For parameter `ypoints` of element `?` no branches are defined. Do this via keyword arguments as explained in the documentation.
The number of x and y supporting points must agree for all branches:
>>> ypoints(branch1=[1.0, 2.0], ... branch2=[2.0, 4.0]) Traceback (most recent call last): ... ValueError: Each branch requires the same number of supporting points as given for parameter `xpoints`, which is 3, but for branch `branch1` of parameter `ypoints` of element `?` 2 values are given.
>>> xpoints(1.0, 2.0)
When working in on actual project (indicated by a predefined project name), each branch name must correspond to a
Nodename:>>> from hydpy import pub, Nodes >>> pub.projectname = "test" >>> nodes = Nodes("branch1") >>> ypoints(branch1=[1.0, 2.0], ... branch2=[2.0, 4.0]) Traceback (most recent call last): ... RuntimeError: Parameter `ypoints` of element `?` is supposed to branch to node `branch2`, but such a node is not available.
We use the following general exception message for some unexpected errors:
>>> nodes = Nodes("branch1", "branch2") >>> ypoints(branch1=[1.0, 2.0], ... branch2="xy") Traceback (most recent call last): ... ValueError: While trying to set the values for branch `branch2` of parameter `ypoints` of element `?`, the following error occurred: could not convert string to float: 'xy'
Changing the number of branches during runtime might result in erroneous connections to the
Nodeobjects:>>> ypoints(branch1=[1.0, 2.0], ... branch2=[2.0, 4.0]) >>> ypoints ypoints(branch1=[1.0, 2.0], branch2=[2.0, 4.0]) >>> ypoints(branch1=[1.0, 2.0]) Traceback (most recent call last): ... RuntimeError: The number of branches of the hbranch model should not be changed during run time. If you really need to do this, first initialize a new `branched` sequence and connect it to the respective outlet nodes properly.
Derived parameters¶
- class hydpy.models.hbranch.DerivedParameters(master: Parameters, cls_fastaccess: Type[FastAccessParameter] | None = None, cymodel: CyModelProtocol | None = None)
Bases:
SubParametersDerived parameters of model hbranch.
- The following classes are selected:
MOY()References the “global” month of the year index array [-].NmbBranches()The number of branches [-].NmbPoints()The number of supporting points for linear interpolation [-].
- class hydpy.models.hbranch.hbranch_derived.MOY(subvars: SubParameters)[source]¶
Bases:
MOYParameterReferences the “global” month of the year index array [-].
- Required by the method:
- class hydpy.models.hbranch.hbranch_derived.NmbBranches(subvars: SubParameters)[source]¶
Bases:
ParameterThe number of branches [-].
- Required by the methods:
- class hydpy.models.hbranch.hbranch_derived.NmbPoints(subvars: SubParameters)[source]¶
Bases:
ParameterThe number of supporting points for linear interpolation [-].
- Required by the method:
Sequence Features¶
Flux sequences¶
- class hydpy.models.hbranch.FluxSequences(master: Sequences, cls_fastaccess: Type[TypeFastAccess_co] | None = None, cymodel: CyModelProtocol | None = None)
Bases:
FluxSequencesFlux sequences of model hbranch.
- The following classes are selected:
OriginalInput()Unadjusted total input [e.g. m³/s].AdjustedInput()Adjusted total input [e.g. m³/s].Outputs()Branched outputs [e.g. m³/s].
- class hydpy.models.hbranch.hbranch_fluxes.OriginalInput(subvars: ModelSequences[ModelSequence, FastAccess])[source]¶
Bases:
FluxSequenceUnadjusted total input [e.g. m³/s].
- Calculated by the method:
- Required by the method:
- class hydpy.models.hbranch.hbranch_fluxes.AdjustedInput(subvars: ModelSequences[ModelSequence, FastAccess])[source]¶
Bases:
FluxSequenceAdjusted total input [e.g. m³/s].
- Calculated by the method:
- Required by the method:
- class hydpy.models.hbranch.hbranch_fluxes.Outputs(subvars: ModelSequences[ModelSequence, FastAccess])[source]¶
Bases:
FluxSequenceBranched outputs [e.g. m³/s].
- Calculated by the method:
- Required by the method:
Inlet sequences¶
- class hydpy.models.hbranch.InletSequences(master: Sequences, cls_fastaccess: Type[TypeFastAccess_co] | None = None, cymodel: CyModelProtocol | None = None)
Bases:
InletSequencesInlet sequences of model hbranch.
- The following classes are selected:
Total()Total input [e.g. m³/s].
- class hydpy.models.hbranch.hbranch_inlets.Total(subvars: ModelSequences[ModelSequence, FastAccess])[source]¶
Bases:
InletSequenceTotal input [e.g. m³/s].
- Required by the method:
Outlet sequences¶
- class hydpy.models.hbranch.OutletSequences(master: Sequences, cls_fastaccess: Type[TypeFastAccess_co] | None = None, cymodel: CyModelProtocol | None = None)
Bases:
OutletSequencesOutlet sequences of model hbranch.
- The following classes are selected:
Branched()Branched outputs [e.g. m³/s].
- class hydpy.models.hbranch.hbranch_outlets.Branched(subvars: ModelSequences[ModelSequence, FastAccess])[source]¶
Bases:
OutletSequenceBranched outputs [e.g. m³/s].
- Calculated by the method:
- class hydpy.models.hbranch.ControlParameters(master: Parameters, cls_fastaccess: Type[FastAccessParameter] | None = None, cymodel: CyModelProtocol | None = None)¶
Bases:
SubParametersControl parameters of model hbranch.
- The following classes are selected:
Delta()Monthly varying difference for increasing or decreasing the input [e.g. m³/s].Minimum()The allowed minimum value of the adjusted input [e.g. m³/s].XPoints()Supporting points for the independent input variable [e.g. m³/s].YPoints()Supporting points for the dependent output variables [e.g. m³/s].
- class hydpy.models.hbranch.DerivedParameters(master: Parameters, cls_fastaccess: Type[FastAccessParameter] | None = None, cymodel: CyModelProtocol | None = None)¶
Bases:
SubParametersDerived parameters of model hbranch.
- The following classes are selected:
MOY()References the “global” month of the year index array [-].NmbBranches()The number of branches [-].NmbPoints()The number of supporting points for linear interpolation [-].
- class hydpy.models.hbranch.FluxSequences(master: Sequences, cls_fastaccess: Type[TypeFastAccess_co] | None = None, cymodel: CyModelProtocol | None = None)¶
Bases:
FluxSequencesFlux sequences of model hbranch.
- The following classes are selected:
OriginalInput()Unadjusted total input [e.g. m³/s].AdjustedInput()Adjusted total input [e.g. m³/s].Outputs()Branched outputs [e.g. m³/s].
- class hydpy.models.hbranch.InletSequences(master: Sequences, cls_fastaccess: Type[TypeFastAccess_co] | None = None, cymodel: CyModelProtocol | None = None)¶
Bases:
InletSequencesInlet sequences of model hbranch.
- The following classes are selected:
Total()Total input [e.g. m³/s].
- class hydpy.models.hbranch.OutletSequences(master: Sequences, cls_fastaccess: Type[TypeFastAccess_co] | None = None, cymodel: CyModelProtocol | None = None)¶
Bases:
OutletSequencesOutlet sequences of model hbranch.
- The following classes are selected:
Branched()Branched outputs [e.g. m³/s].