Data structure for model hierarchy¶
model Module¶
Classes for representing the model.
- class nsdf.model.ModelComponent(name, uid=None, parent=None, attrs=None, hdfgroup=None)[source]¶
Bases: object
Tree node for model tree.
- parent¶
ModelComponent
parent of this component.
- children¶
dict
dict of child components - name is key and ModelComponent is value.
- attrs¶
dict
attributes of the component. These become HDF5 attributes when it is written to file.
- hdfgroup¶
hdf5 Group
the group that this component corresponds to in NSDF file.
- add_child(child)[source]¶
Add a child component under this model component.
Parameters: child (ModelComponent) – child component to add to this component Returns: None Raises: TypeError –
- add_children(children)[source]¶
Add a list of children to current component.
Parameters: children (list) – list of children to be added. Returns: None Raises: TypeError –
- check_uid(uid_dict)[source]¶
Check that uid are indeed unique.
Parameters: uid_dict (dict) – an empty dict for storing the uids Note
If any uid is not set, this function as a side effect creates the uids in the form parentuid/name - similar to unix file paths.
- get_id_path_dict()[source]¶
Return a dictionary mapping the unique id of the model components to their path in modeltree.
See also
update_id_path_dict
- get_node(path)[source]¶
Get node at path relative to this node.
Parameters: path (str) – path obtained by concatenating component names with / as separator. Returns: ModelComponent at the specified path Raises: KeyError if there is no element at the specified path. –
- print_tree(indent='')[source]¶
Recursively print subtree rooted at this component.
Parameters: indent (str) – indentation. Returns: None