selectiontools¶
This module implements tools for defining subsets of Node
and
Element
objects of large HydPy projects, called “selections”.
Module selectiontools
implements the following members:
Selections
Collection class forSelection
objects.
Selection
Handles and modifies combinations ofNode
andElement
objects.
-
class
hydpy.core.selectiontools.
Selections
(*selections: hydpy.core.selectiontools.Selection)[source]¶ Bases:
object
Collection class for
Selection
objects.You can pass an arbitrary number of
Selection
objects to the constructor of classSelections
:>>> sel1 = Selection("sel1", ["node1", "node2"], ["element1"]) >>> sel2 = Selection("sel2", ["node1", "node3"], ["element2"]) >>> selections = Selections(sel1, sel2) >>> selections Selections("sel1", "sel2")
Also, you can query, add, and remove
Selection
objects via attribute access:>>> selections.sel3 Traceback (most recent call last): ... AttributeError: The actual Selections object handles neither a normal attribute nor a Selection object called `sel3` that could be returned. >>> sel3 = Selection("sel3", ["node1", "node4"], ["element3"]) >>> selections.sel3 = sel3 >>> selections.sel3 Selection("sel3", nodes=("node1", "node4"), elements="element3") >>> "sel3" in dir(selections) True >>> del selections.sel3 >>> "sel3" in dir(selections) False >>> del selections.sel3 Traceback (most recent call last): ... AttributeError: The actual Selections object handles neither a normal attribute nor a Selection object called `sel3` that could be deleted.
Attribute names must be consistent with the name attribute of the respective
Selection
object:>>> selections.sel4 = sel3 Traceback (most recent call last): ... ValueError: To avoid inconsistencies when handling Selection objects as attributes of a Selections object, attribute name and Selection name must be identical. However, for selection `sel3` the given attribute name is `sel4`.
You can use item access alternatively:
>>> selections["sel4"] Traceback (most recent call last): ... KeyError: 'The actual Selections object does not handle a Selection object called `sel4` that could be returned.' >>> selections["sel4"] = Selection("sel4") >>> selections["sel4"] Selection("sel4", nodes=(), elements=()) >>> del selections["sel4"] >>> del selections["sel4"] Traceback (most recent call last): ... KeyError: 'The actual Selections object does not handle a Selection object called `sel4` that could be deleted.'
You can ask for the existence of a specific
Selection
objects within aSelections
object both via its name and via the object itself:>>> sel1 in selections True >>> "sel1" in selections True >>> sel3 in selections False >>> "sel3" in selections False
Class
Selections
supports both theiter()
andlen()
operator:>>> for selection in selections: ... print(selection.name) sel1 sel2 >>> len(selections) 2
For convenience, use the “+”, “-“, “+=”, and “-=” operators to compare and modify
Selections
objects either based on singleSelection
objects or collections ofSelection
objects>>> larger = selections + sel3 >>> smaller = selections - sel2 >>> sorted(selections.names) ['sel1', 'sel2'] >>> sorted(larger.names) ['sel1', 'sel2', 'sel3'] >>> smaller.names ('sel1',)
>>> smaller += larger >>> sorted(smaller.names) ['sel1', 'sel2', 'sel3'] >>> smaller -= sel1, sel2 >>> smaller.names ('sel3',)
Note that trying to remove non-existing
Selection
objects does not raise errors:>>> smaller -= sel2 >>> smaller.names ('sel3',) >>> smaller - (sel1, sel2, sel3) Selections()
The binary operators do not support other types than the mentioned ones:
>>> smaller -= "sel3" Traceback (most recent call last): ... TypeError: Binary operations on Selections objects are defined for other Selections objects, single Selection objects, or iterables containing `Selection` objects, but the type of the given argument is `str`. >>> smaller -= 1 Traceback (most recent call last): ... TypeError: ... is `int`.
Use the “==” operator to compare two
Selections
objects:>>> larger == smaller False >>> larger == (smaller + selections) True >>> larger == (sel1, sel2, sel3) False
-
property
names
¶ The names of the actual
Selection
objects.>>> from hydpy import Selection, Selections >>> selections = Selections( ... Selection("sel1", ["node1", "node2"], ["element1"]), ... Selection("sel2", ["node1", "node3"], ["element2"])) >>> sorted(selections.names) ['sel1', 'sel2']
-
property
nodes
¶ The
Node
objects of all handledSelection
objects.>>> from hydpy import Selection, Selections >>> selections = Selections( ... Selection("sel1", ["node1", "node2"], ["element1"]), ... Selection("sel2", ["node1", "node3"], ["element2"])) >>> selections.nodes Nodes("node1", "node2", "node3")
-
property
elements
¶ The
Element
objects of all handledSelection
objects.>>> from hydpy import Selection, Selections >>> selections = Selections( ... Selection("sel1", ["node1"], ["element1"]), ... Selection("sel2", ["node1"], ["element2", "element3"])) >>> selections.elements Elements("element1", "element2", "element3")
-
find
(device: DeviceType) → hydpy.core.selectiontools.Selections[source]¶ Return all
Selection
objects containing the givenNode
orElement
object.>>> from hydpy import Elements, Nodes, Selection, Selections >>> nodes = Nodes("n1", "n2", "n3") >>> elements = Elements("e1", "e2") >>> selections = Selections( ... Selection("s1", ["n1", "n2"], ["e1"]), ... Selection("s2", ["n1"])) >>> selections.find(nodes.n1) Selections("s1", "s2") >>> selections.find(nodes.n2) Selections("s1") >>> selections.find(nodes.n3) Selections() >>> selections.find(elements.e1) Selections("s1") >>> selections.find(elements.e2) Selections()
-
query_intersections
(selection2element: bool = True) → Union[Dict[hydpy.core.selectiontools.Selection, Dict[hydpy.core.selectiontools.Selection, hydpy.core.devicetools.Elements]], Dict[hydpy.core.devicetools.Element, hydpy.core.selectiontools.Selections]][source]¶ A dictionary covering all cases where one
Element
object is a member of multipleSelection
objects.The form of the dictionary depends on the value of the optional argument selection2element. See method
print_intersections()
for an example.
-
print_intersections
(selection2element: bool = True) → None[source]¶ Print the result of method
query_intersections()
.We use method
print_intersections()
to check if any combination of the following selections handles the same elements.>>> from hydpy import Selection, Selections >>> selections = Selections( ... Selection("s1", nodes="n1",elements=("e1", "e2", "e3")), ... Selection("s2", nodes="n1", elements=("e2", "e3", "e4")), ... Selection("s3", nodes="n1", elements="e3"), ... Selection("s4", nodes="n1", elements=("e5", "e6")), ... )
If we call method
print_intersections()
with argument selection2element beingTrue
, we find out which selection intersects with which other and which elements are affected:>>> selections.print_intersections() selection s1 intersects with... ...selection s2 due to the following elements: e2 and e3 ...selection s3 due to the following elements: e3 selection s2 intersects with... ...selection s1 due to the following elements: e2 and e3 ...selection s3 due to the following elements: e3 selection s3 intersects with... ...selection s1 due to the following elements: e3 ...selection s2 due to the following elements: e3
If we call method
print_intersections()
with argument selection2element beingFalse
, we find out which element occurs multiple times in which selections:>>> selections.print_intersections(selection2element=False) element e2 is a member of multiple selections: s1 and s2 element e3 is a member of multiple selections: s1, s2, and s3
-
property
-
class
hydpy.core.selectiontools.
Selection
(name: str, nodes: Optional[Union[Node, str, Iterable[Union[Node, str]]]] = None, elements: Optional[Union[Element, str, Iterable[Union[Element, str]]]] = None)[source]¶ Bases:
object
Handles and modifies combinations of
Node
andElement
objects.In HydPy
Node
andElement
objects are the fundamental means to structure projects. However, to keep the overview of huge projects involving thousands of nodes and elements requires additional strategies.One such strategy is to define different instances of class
Selection
for different aspects of a project. Often, a selection contains all nodes and elements of a certain subcatchment or all elements handling certain model types. Selections can be overlapping, meaning, for example, that an element can be part of a subcatchment selection and of model-type selection at the same time.Selections can be written to and read from individual network files, as explained in the documentation on class
NetworkManager
. Read selections are available via thepub
module. In most application scripts (e.g. for parameter calibration), one performs different operations on the nodes and elements of the different selections (e.g. change parameter “a” and “b” for models of selection “x” and “y”, respectively). However, classSelection
also provides features for creating combinations ofNode
andElement
objects suitable for different tasks, as explained in the documentation of the respective methods. Here we only show its basic usage with the help of the LahnH example project prepared by functionprepare_full_example_2()
:>>> from hydpy.examples import prepare_full_example_2 >>> _, pub, _ = prepare_full_example_2()
For example, LahnH defines a headwaters selection:
>>> pub.selections.headwaters Selection("headwaters", nodes=("dill", "lahn_1"), elements=("land_dill", "land_lahn_1"))
You can compare this selection with other new or already available selections, with “headwaters < complete” returning
True
meaning that all nodes and elements of the headwater catchments are also part of the entire catchment:>>> from hydpy import Selection >>> test = Selection("test", ... elements=("land_dill", "land_lahn_1"), ... nodes=("dill", "lahn_1")) >>> pub.selections.headwaters < test False >>> pub.selections.headwaters <= test True >>> pub.selections.headwaters == test True >>> pub.selections.headwaters != test False >>> pub.selections.headwaters >= test True >>> pub.selections.headwaters > test False >>> pub.selections.headwaters < pub.selections.complete True >>> pub.selections.headwaters <= pub.selections.complete True >>> pub.selections.headwaters == pub.selections.complete False >>> pub.selections.headwaters != pub.selections.complete True >>> pub.selections.headwaters >= pub.selections.complete False >>> pub.selections.headwaters > pub.selections.complete False
The
len()
operator returns the total number of handled node and element objects:>>> len(test) 4
Use the “+=” and “-=” operators to add or remove nodes and elements:
>>> test += pub.selections.complete >>> len(test) 11 >>> test -= pub.selections.complete >>> len(test) 0
Passing a wrong argument to the binary operators results in errors like the following:
>>> test += 1 Traceback (most recent call last): ... AttributeError: While trying to add selection `test` with object `1` of type `int`, the following error occurred: 'int' object has no attribute 'nodes' >>> test -= pub.selections.complete.nodes.dill Traceback (most recent call last): ... AttributeError: While trying to subtract selection `test` with object `dill` of type `Node`, the following error occurred: 'Node' object has no attribute 'nodes' >>> test < "wrong" Traceback (most recent call last): ... AttributeError: While trying to compare selection `test` with object `wrong` of type `str`, the following error occurred: 'str' object has no attribute 'nodes'
But as usual, checking for equality or inequality return
False
andTrue
for uncomparable objects:>>> test == "wrong" False >>> test != "wrong" True
Applying the
str
function only returns the selection name:>>> str(test) 'test'
-
elements
: hydpy.core.devicetools.Elements¶
-
search_upstream
(device: DeviceType, name: str = 'upstream') → hydpy.core.selectiontools.Selection[source]¶ Return the network upstream of the given starting point, including the starting point itself.
>>> from hydpy.examples import prepare_full_example_2 >>> hp, pub, _ = prepare_full_example_2()
You can pass both
Node
andElement
objects and, optionally, the name of the newly createdSelection
object:>>> test = pub.selections.complete.copy("test") >>> test.search_upstream(hp.nodes.lahn_2) Selection("upstream", nodes=("dill", "lahn_1", "lahn_2"), elements=("land_dill", "land_lahn_1", "land_lahn_2", "stream_dill_lahn_2", "stream_lahn_1_lahn_2")) >>> test.search_upstream( ... hp.elements.stream_lahn_1_lahn_2, "UPSTREAM") Selection("UPSTREAM", nodes="lahn_1", elements=("land_lahn_1", "stream_lahn_1_lahn_2"))
Wrong device specifications result in errors like the following:
>>> test.search_upstream(1) Traceback (most recent call last): ... TypeError: While trying to determine an upstream network of selection `test`, the following error occurred: Either a `Node` or an `Element` object is required as the "outlet device", but the given `device` value is of type `int`.
>>> pub.selections.headwaters.search_upstream(hp.nodes.lahn_3) Traceback (most recent call last): ... KeyError: "While trying to determine an upstream network of selection `headwaters`, the following error occurred: 'No device named `lahn_3` available.'"
Method
select_upstream()
restricts the current selection to the one determined with the methodsearch_upstream()
:>>> test.select_upstream(hp.nodes.lahn_2) Selection("test", nodes=("dill", "lahn_1", "lahn_2"), elements=("land_dill", "land_lahn_1", "land_lahn_2", "stream_dill_lahn_2", "stream_lahn_1_lahn_2"))
On the contrary, the method
deselect_upstream()
restricts the current selection to all devices not determined by methodsearch_upstream()
:>>> complete = pub.selections.complete.deselect_upstream( ... hp.nodes.lahn_2) >>> complete Selection("complete", nodes="lahn_3", elements=("land_lahn_3", "stream_lahn_2_lahn_3"))
If necessary, include the “outlet device” manually afterwards:
>>> complete.nodes += hp.nodes.lahn_2 >>> complete Selection("complete", nodes=("lahn_2", "lahn_3"), elements=("land_lahn_3", "stream_lahn_2_lahn_3"))
-
select_upstream
(device: DeviceType) → hydpy.core.selectiontools.Selection[source]¶ Restrict the current selection to the network upstream of the given starting point, including the starting point itself.
See the documentation on method
search_upstream()
for additional information.
-
deselect_upstream
(device: DeviceType) → hydpy.core.selectiontools.Selection[source]¶ Remove the network upstream of the given starting point from the current selection, including the starting point itself.
See the documentation on method
search_upstream()
for additional information.
-
search_downstream
(device: DeviceType, name: str = 'downstream') → hydpy.core.selectiontools.Selection[source]¶ Return the network downstream of the given starting point, including the starting point itself.
>>> from hydpy.examples import prepare_full_example_2 >>> hp, pub, _ = prepare_full_example_2()
You can pass both
Node
andElement
objects and, optionally, the name of the newly createdSelection
object:>>> test = pub.selections.complete.copy("test") >>> test.search_downstream(hp.nodes.lahn_1) Selection("downstream", nodes=("lahn_1", "lahn_2", "lahn_3"), elements=("stream_lahn_1_lahn_2", "stream_lahn_2_lahn_3")) >>> test.search_downstream( ... hp.elements.land_lahn_1, "DOWNSTREAM") Selection("DOWNSTREAM", nodes=("lahn_1", "lahn_2", "lahn_3"), elements=("land_lahn_1", "stream_lahn_1_lahn_2", "stream_lahn_2_lahn_3"))
Wrong device specifications result in errors like the following:
>>> test.search_downstream(1) Traceback (most recent call last): ... TypeError: While trying to determine a downstream network of selection `test`, the following error occurred: Either a `Node` or an `Element` object is required as the "inlet device", but the given `device` value is of type `int`.
>>> pub.selections.headwaters.search_downstream(hp.nodes.lahn_3) Traceback (most recent call last): ... KeyError: "While trying to determine a downstream network of selection `headwaters`, the following error occurred: 'No device named `lahn_3` available.'"
Method
select_downstream()
restricts the current selection to the one determined with the methodsearch_upstream()
:>>> test.select_downstream(hp.nodes.lahn_1) Selection("test", nodes=("lahn_1", "lahn_2", "lahn_3"), elements=("stream_lahn_1_lahn_2", "stream_lahn_2_lahn_3"))
On the contrary, the method
deselect_downstream()
restricts the current selection to all devices not determined by methodsearch_downstream()
:>>> complete = pub.selections.complete.deselect_downstream( ... hp.nodes.lahn_1) >>> complete Selection("complete", nodes="dill", elements=("land_dill", "land_lahn_1", "land_lahn_2", "land_lahn_3", "stream_dill_lahn_2"))
If necessary, include the “inlet device” manually afterwards:
>>> complete.nodes += hp.nodes.lahn_1 >>> complete Selection("complete", nodes=("dill", "lahn_1"), elements=("land_dill", "land_lahn_1", "land_lahn_2", "land_lahn_3", "stream_dill_lahn_2"))
-
select_downstream
(device: DeviceType) → hydpy.core.selectiontools.Selection[source]¶ Restrict the current selection to the network downstream of the given starting point, including the starting point itself.
See the documentation on method
search_downstream()
for additional information.
-
deselect_downstream
(device: DeviceType) → hydpy.core.selectiontools.Selection[source]¶ Remove the network downstream of the given starting point from the current selection, including the starting point itself.
See the documentation on method
search_downstream()
for additional information.
-
search_modeltypes
(*models: Union[hydpy.core.modeltools.Model, module, str], name: str = 'modeltypes') → hydpy.core.selectiontools.Selection[source]¶ Return a
Selection
object containing only the elements currently handling models of the given types.>>> from hydpy.examples import prepare_full_example_2 >>> hp, pub, _ = prepare_full_example_2()
You can pass both
Model
objects and names and, as a keyword argument, the name of the newly createdSelection
object:>>> test = pub.selections.complete.copy("test") >>> from hydpy import prepare_model >>> hland_v1 = prepare_model("hland_v1")
>>> test.search_modeltypes(hland_v1) Selection("modeltypes", nodes=(), elements=("land_dill", "land_lahn_1", "land_lahn_2", "land_lahn_3")) >>> test.search_modeltypes( ... hland_v1, "hstream_v1", "lland_v1", name="MODELTYPES") Selection("MODELTYPES", nodes=(), elements=("land_dill", "land_lahn_1", "land_lahn_2", "land_lahn_3", "stream_dill_lahn_2", "stream_lahn_1_lahn_2", "stream_lahn_2_lahn_3"))
Wrong model specifications result in errors like the following:
>>> test.search_modeltypes("wrong") Traceback (most recent call last): ... ModuleNotFoundError: While trying to determine the elements of selection `test` handling the model defined by the argument(s) `wrong` of type(s) `str`, the following error occurred: No module named 'hydpy.models.wrong'
Method
select_modeltypes()
restricts the current selection to the one determined with the method thesearch_modeltypes()
:>>> test.select_modeltypes(hland_v1) Selection("test", nodes=(), elements=("land_dill", "land_lahn_1", "land_lahn_2", "land_lahn_3"))
On the contrary, the method
deselect_upstream()
restricts the current selection to all devices not determined by method thesearch_upstream()
:>>> pub.selections.complete.deselect_modeltypes(hland_v1) Selection("complete", nodes=(), elements=("stream_dill_lahn_2", "stream_lahn_1_lahn_2", "stream_lahn_2_lahn_3"))
-
select_modeltypes
(*models: Union[hydpy.core.modeltools.Model, module, str]) → hydpy.core.selectiontools.Selection[source]¶ Restrict the current
Selection
object to all elements containing the given model types (removes all nodes).See the documentation on method
search_modeltypes()
for additional information.
-
deselect_modeltypes
(*models: Union[hydpy.core.modeltools.Model, module, str]) → hydpy.core.selectiontools.Selection[source]¶ Restrict the current selection to all elements not containing the given model types (removes all nodes).
See the documentation on method
search_modeltypes()
for additional information.
-
search_nodenames
(*substrings: str, name: str = 'nodenames') → hydpy.core.selectiontools.Selection[source]¶ Return a new selection containing all nodes of the current selection with a name containing at least one of the given substrings.
>>> from hydpy.examples import prepare_full_example_2 >>> hp, pub, _ = prepare_full_example_2()
Pass the (sub)strings as positional arguments and, optionally, the name of the newly created
Selection
object as a keyword argument:>>> test = pub.selections.complete.copy("test") >>> from hydpy import prepare_model >>> test.search_nodenames("dill", "lahn_1") Selection("nodenames", nodes=("dill", "lahn_1"), elements=())
Wrong string specifications result in errors like the following:
>>> test.search_nodenames(["dill", "lahn_1"]) Traceback (most recent call last): ... TypeError: While trying to determine the nodes of selection `test` with names containing at least one of the given substrings `['dill', 'lahn_1']`, the following error occurred: 'in <string>' requires string as left operand, not list
Method
select_nodenames()
restricts the current selection to the one determined with the the methodsearch_nodenames()
:>>> test.select_nodenames("dill", "lahn_1") Selection("test", nodes=("dill", "lahn_1"), elements=("land_dill", "land_lahn_1", "land_lahn_2", "land_lahn_3", "stream_dill_lahn_2", "stream_lahn_1_lahn_2", "stream_lahn_2_lahn_3"))
On the contrary, the method
deselect_nodenames()
restricts the current selection to all devices not determined by the methodsearch_nodenames()
:>>> pub.selections.complete.deselect_nodenames("dill", "lahn_1") Selection("complete", nodes=("lahn_2", "lahn_3"), elements=("land_dill", "land_lahn_1", "land_lahn_2", "land_lahn_3", "stream_dill_lahn_2", "stream_lahn_1_lahn_2", "stream_lahn_2_lahn_3"))
-
select_nodenames
(*substrings: str) → hydpy.core.selectiontools.Selection[source]¶ Restrict the current selection to all nodes with a name containing at least one of the given substrings (does not affect any elements).
See the documentation on method
search_nodenames()
for additional information.
-
deselect_nodenames
(*substrings: str) → hydpy.core.selectiontools.Selection[source]¶ Restrict the current selection to all nodes with a name not containing at least one of the given substrings (does not affect any elements).
See the documentation on method
search_nodenames()
for additional information.
-
search_elementnames
(*substrings: str, name: str = 'elementnames') → hydpy.core.selectiontools.Selection[source]¶ Return a new selection containing all elements of the current selection with a name containing at least one of the given substrings.
>>> from hydpy.examples import prepare_full_example_2 >>> hp, pub, _ = prepare_full_example_2()
Pass the (sub)strings as positional arguments and, optionally, the name of the newly created
Selection
object as a keyword argument:>>> test = pub.selections.complete.copy("test") >>> from hydpy import prepare_model >>> test.search_elementnames("dill", "lahn_1") Selection("elementnames", nodes=(), elements=("land_dill", "land_lahn_1", "stream_dill_lahn_2", "stream_lahn_1_lahn_2"))
Wrong string specifications result in errors like the following:
>>> test.search_elementnames(["dill", "lahn_1"]) Traceback (most recent call last): ... TypeError: While trying to determine the elements of selection `test` with names containing at least one of the given substrings `['dill', 'lahn_1']`, the following error occurred: 'in <string>' requires string as left operand, not list
Method
select_elementnames()
restricts the current selection to the one determined with the methodsearch_elementnames()
:>>> test.select_elementnames("dill", "lahn_1") Selection("test", nodes=("dill", "lahn_1", "lahn_2", "lahn_3"), elements=("land_dill", "land_lahn_1", "stream_dill_lahn_2", "stream_lahn_1_lahn_2"))
On the contrary, the method
deselect_elementnames()
restricts the current selection to all devices not determined by the methodsearch_elementnames()
:>>> pub.selections.complete.deselect_elementnames("dill", "lahn_1") Selection("complete", nodes=("dill", "lahn_1", "lahn_2", "lahn_3"), elements=("land_lahn_2", "land_lahn_3", "stream_lahn_2_lahn_3"))
-
select_elementnames
(*substrings: str) → hydpy.core.selectiontools.Selection[source]¶ Restrict the current selection to all elements with a name containing at least one of the given substrings (does not affect any nodes).
See the documentation on method
search_elementnames()
for additional information.
-
deselect_elementnames
(*substrings: str) → hydpy.core.selectiontools.Selection[source]¶ Restrict the current selection to all elements with a name not containing at least one of the given substrings. (does not affect any nodes).
See the documentation on method
search_elementnames()
for additional information.
-
copy
(name: str) → hydpy.core.selectiontools.Selection[source]¶ Return a new
Selection
object with the given name and copies of the handlesNodes
andElements
objects based on methodcopy()
.
-
save_networkfile
(filepath: Optional[str] = None, write_defaultnodes: bool = True) → None[source]¶ Save the selection as a network file.
>>> from hydpy.examples import prepare_full_example_2 >>> _, pub, TestIO = prepare_full_example_2()
In most cases, one should conveniently write network files via method
save_files()
of classNetworkManager
. However, using the methodsave_networkfile()
allows for additional configuration via the arguments filepath and write_defaultnodes:>>> with TestIO(): ... pub.selections.headwaters.save_networkfile() ... with open("headwaters.py") as networkfile: ... print(networkfile.read()) # -*- coding: utf-8 -*- from hydpy import Element, Node Node("dill", variable="Q", keywords="gauge") Node("lahn_1", variable="Q", keywords="gauge") Element("land_dill", outlets="dill", keywords="catchment") Element("land_lahn_1", outlets="lahn_1", keywords="catchment")
>>> with TestIO(): ... pub.selections.headwaters.save_networkfile( ... "test.py", write_defaultnodes=False) ... with open("test.py") as networkfile: ... print(networkfile.read()) # -*- coding: utf-8 -*- from hydpy import Element, Node Element("land_dill", outlets="dill", keywords="catchment") Element("land_lahn_1", outlets="lahn_1", keywords="catchment")
The write_defaultnodes argument does only affect nodes handling the default variable Q:
>>> from hydpy import FusedVariable, Node >>> from hydpy.inputs import hland_P, hland_T, lland_Nied >>> from hydpy.outputs import hland_Perc, hland_Q0, hland_Q1 >>> Precip = FusedVariable("Precip", hland_P, lland_Nied) >>> Runoff = FusedVariable("Runoff", hland_Q0, hland_Q1) >>> nodes = pub.selections.headwaters.nodes >>> nodes.add_device(Node("test1", variable="X")) >>> nodes.add_device(Node("test2", variable=hland_T)) >>> nodes.add_device(Node("test3", variable=Precip)) >>> nodes.add_device(Node("test4", variable=hland_Perc)) >>> nodes.add_device(Node("test5", variable=Runoff)) >>> with TestIO(): ... pub.selections.headwaters.save_networkfile( ... "test.py", write_defaultnodes=False) ... with open("test.py") as networkfile: ... print(networkfile.read()) # -*- coding: utf-8 -*- from hydpy import Element, FusedVariable, Node from hydpy.inputs import hland_P, hland_T, lland_Nied from hydpy.outputs import hland_Perc, hland_Q0, hland_Q1 Precip = FusedVariable("Precip", hland_P, lland_Nied) Runoff = FusedVariable("Runoff", hland_Q0, hland_Q1) Node("test1", variable="X") Node("test2", variable=hland_T) Node("test3", variable=Precip) Node("test4", variable=hland_Perc) Node("test5", variable=Runoff) Element("land_dill", outlets="dill", keywords="catchment") Element("land_lahn_1", outlets="lahn_1", keywords="catchment")
-