PlasmaCalcs.quantities.quant_tree.QuantTree

class PlasmaCalcs.quantities.quant_tree.QuantTree(obj, parent=None)

Bases: Tree

Tree of MatchedQuantity objects.
See QuantTree.display() for display options.
Most common use-case:
QuantTree.from_quantity_loader(quantity_loader, var)
will tell the QuantTree associated with loading that var from quantity_loader.
Result might depend on current values of quantity_loader attributes.
__init__(obj, parent=None)

Methods

__init__(obj[, parent])

add_child(child)

display([show_depth, max_depth, shorthand])

enumerate_flat(*[, include_self])

flat(*[, include_self])

flat_branches_until(branches_until, *[, ...])

flat_branches_until_vars(*[, include_self])

from_quantity_loader(quantity_loader, var, *)

html([show_depth, max_depth, shorthand])

loading_dims()

make_child(obj)

make_children(objs)

result_dims()

set_parent(parent, *[, _internal])

Attributes

DEFAULT_TREE_SHORTHAND

DEFAULT_TREE_SHOW_DEPTH

DEFAULT_TREE_SHOW_MAX_DEPTH

depth

height

parent

parent_ref

size

add_child(child)
adds this child (a Tree) to self.children. Also, child.set_parent(self).
returns the added child.
property depth
number of layers above self. (parent, parent’s parents, etc.)
depth = 0 for the node with parent = None.
display(show_depth=None, max_depth=None, *, shorthand=None)
display self in html. Includes self.html() and DEFAULTS.TREE_CSS.
show_depth: None or int
max number of layers of tree to show by default (i.e. “not hidden” by default)
None –> use self.DEFAULT_TREE_SHOW_DEPTH if defined else DEFAULTS.TREE_SHOW_DEPTH
max_depth: None or int
max number of layers of tree to render (even if all layers are “not hidden”).
Anything deeper will not be converted to html string.
None –> use self.DEFAULT_TREE_SHOW_MAX_DEPTH if defined else DEFAULTS.TREE_SHOW_MAX_DEPTH
shorthand: None or bool
whether to use shorthand for the “Tree([depth=N, height=N, size=N], obj=…)” part of the repr.
True –> use shorthand; replace that^ with: “((N, N, N)) …”
None –> use self.DEFAULT_TREE_SHORTHAND if defined else DEFAULTS.TREE_SHORTHAND
enumerate_flat(*, include_self=False)
returns a generator which iterates over all of self’s descendants, in depth-first order,
yielding (index, node) pairs, such that self[index] == node.
Note that index will be a tuple with length == node.depth.
if include_self, yield self first, as: ((), self)).
flat(*, include_self=False)
returns a generator which iterates over all of self’s descendants, in depth-first order.
if include_self, yield self first.
flat_branches_until(branches_until, *, include_self=False)
returns a generator which iterates over all of self’s descendants, in depth-first order,
but stop looking at descendants on a branch as soon as branches_until(node).
E.g. self.flat_branches_until(lambda node: node.obj==7) will be similar to flat,
but won’t go to any descendants for any node with obj==7.
if include self, yield self first, and check branches_until(self) before continuing.
otherwise, never check branches_until(self).
flat_branches_until_vars(*, include_self=False)
iterator over self and all descendants, but no descendants of MatchedVar nodes.
classmethod from_quantity_loader(quantity_loader, var, *, missing_ok=False, **kw_call_options)
returns a QuantTree from a QuantityLoader and var name.
This is the tree of MatchedQuantity objects which will all be loaded if loading var.
(MatchedQuantity objects consist of a var, a LoadableQuantity, and possibly a _match.)
quantity_loader: QuantityLoader instance or subclass
the loader containing info about var dependencies.
if class, might not be possible to get as many vars’ dependencies
(and will crash if need to know current values of attributes, to determine dependency list)
missing_ok: bool
whether to be lenient sometimes when missing details that would allow to fully determine deps.
see help(MatchedQuantity.dep_vars) for more details.
additional kwargs appearing in quantity_loader.kw_call_options()
will be passed to quantity_loader.using(**kw_call_options), if quantity_loader is a QuantityLoader instance.
If any additional kwargs don’t appear in kw_call_options(), crash.
property height
number of layers below self. (children, children’s children, etc.)
height = 0 for a node with no children.
html(show_depth=None, max_depth=None, *, shorthand=None)
returns html for displaying self and all of self’s children.
show_depth: None or int
max number of layers of tree to show by default (i.e. “not hidden” by default)
None –> use self.DEFAULT_TREE_SHOW_DEPTH if defined else DEFAULTS.TREE_SHOW_DEPTH
max_depth: None or int
max number of layers of tree to render (even if all layers are “not hidden”).
Anything deeper will not be converted to html string.
None –> use self.DEFAULT_TREE_SHOW_MAX_DEPTH if defined else DEFAULTS.TREE_SHOW_MAX_DEPTH
shorthand: None or bool
whether to use shorthand for the “Tree([depth=N, height=N, size=N], obj=…)” part of the repr.
True –> use shorthand; replace that^ with: “((N, N, N)) …”
None –> use self.DEFAULT_TREE_SHORTHAND if defined else DEFAULTS.TREE_SHORTHAND
loading_dims()
return a list of all the dims for loading across, as implied by this tree.
This is the set of quantity.dims for all quantities in this tree (self and all descendants), but:
- if quantity.ignores_dims is non-empty, exclude those dims for that node and all its descendants.
- if quantity.reduces_dims is non-empty, exclude those dims for the result
(even if a sybling node has a quantity that uses those dims).
make_child(obj)
makes a child of self, with obj as its stored object, and returns the child.
make_children(objs)
make_child(obj) for obj in objs; returns the list of newly made children.
property parent
parent node of self. None if self is root.
When set to a value, calls self.set_parent(value),
which also updates tracking info appropriately, and updates parent’s children.
property parent_ref
stores parent value, but internally uses weakref to avoid circular references.
Users should always use self.parent instead.
result_dims()
return a list of all the dims the result would have, as implied by this tree.
This is the set of quantity.dims for all quantities in this tree (self and all descendants), but:
- if quantity.ignores_dims is non-empty, exclude those dims for that node and all its descendants.
- if quantity.reduces_dims is non-empty, exclude those dims for that node and all its descendants,
(but not from the whole tree. See self.loading_dims() to exclude those from the whole tree.)
set_parent(parent, *, _internal=False)
sets self.parent = parent. Also, parent.add_child(self), unless _internal=True.
Users should use self.parent = parent instead of calling set_parent directly.
property size
number of nodes in this tree. (here and below)
size = 1 for a node with no children.