def load(self):
"""Load nodes and elements from all network files and return them in
a :class:`~hydpy.selectiontools.Selections` instance. Each single
network file defines a seperate
:class:`~hydpy.selectiontools.Selection` instance. Additionally, all
elements and nodes are bundled in a selection named `complete`.
"""
selections = selectiontools.Selections()
for (filename, path) in zip(self.filenames, self.filepaths):
# Ensure both `Node` and `Element`start with a `fresh` memory.
devicetools.Node.gather_new_nodes()
devicetools.Element.gather_new_elements()
try:
info = runpy.run_path(path)
except Exception:
prefix = 'While trying to load the network file `%s`' % path
objecttools.augmentexcmessage(prefix)
try:
selections += selectiontools.Selection(
filename.split('.')[0],
info['Node'].gather_new_nodes(),
info['Element'].gather_new_elements())
except KeyError as exc:
KeyError('The class `%s` cannot be loaded from the network '
'file `%s`. Please refer to the HydPy documentation '
'on how to prepare network files properly.'
% (exc.args[0], filename))
selections += selectiontools.Selection(
'complete',
info['Node'].registered_nodes(),
info['Element'].registered_elements())
return selections
评论列表
文章目录