rayoptics.elem.parttree module

Manage connectivity between sequence and element models using a tree.

class PartTree(opt_model, **kwargs)[source]

Bases: object

sync_to_restore(opt_model)[source]
update_model(**kwargs)[source]
is_empty()[source]
check_consistency(seq_model, ele_model)[source]
init_from_sequence(seq_model)[source]

Initialize part tree using a seq_model.

sort_tree_using_sequence(seq_model)[source]

Resequence part tree using a seq_model.

add_element_model_to_tree(ele_model)[source]
add_element_to_tree(e, **kwargs)[source]
remove_element_from_tree(e, **kwargs)[source]
node(obj)[source]

Return the node paired with obj.

obj_by_name(name)[source]

Return the node paired with obj.

trim_node(obj)[source]

Remove the branch where obj is the sole leaf.

parent_node(obj, tag='#element#space#dummyifc')[source]

Return the parent node for obj, filtered by tag.

parent_object(obj, tag='#element#space#dummyifc')[source]

Return the parent object (and node) for obj, filtered by tag.

get_child_filter(tag='#element#assembly', not_tag='')[source]

Returns a fct that filters a list of nodes to satisfy the tags

list_tree(*args, **kwargs)[source]

Print a graphical console representation of the tree.

The optional arguments are passed through to the by_attr filter. Useful examples or arguments include:

  • pt.list_tree(lambda node: f”{node.name}: {node.tag}”)

  • pt.list_tree(attrname=’tag’)

list_tree_full()[source]

Print a graphical console representation of the tree with tags.

nodes_with_tag(tag='#element', not_tag='', root=None, node_list=None)[source]

Return a list of nodes that contain the requested tag.

list_model(tag='#element#assembly#dummyifc')[source]
build_pt_sg_lists()[source]
list_pt_sg()[source]
sync_part_tree_on_update(ele_model, seq_model, root_node)[source]

Update node names to track element labels.

handle_object_image_tags(seq_model)[source]

Ensure nodes for object and image ifcs and gaps are tagged.

sync_part_tree_on_restore(opt_model, ele_model, seq_model, root_node)[source]
sync_part_tree_on_restore_idkey(opt_model, ele_model, seq_model, root_node)[source]
sequence_to_elements(seq_model, ele_model, part_tree)[source]

Parse the seq_model into elements and update ele_model accordingly.

find_ele_changes(seq_model, ele_model, part_tree, print_visit=False)[source]

Parse the seq_model into elements and categorize the changes.

Returns:

list of ele_defs in common between sm and pt added_ele: list of ele_defs for new elements to be created removed_ele: list of ele_defs to be removed modified_ele: list of existing elements to be updated from new ele_defs sme_list: ele_defs obtained by parsing the seq_model seq_str: character encoding of seq_model ifcs and gaps eme_list: ele_defs for current elements in the element model eme_dict: key: ele_def returns the value: element asm_list: ele_defs for current assemblies in the element/part model asm_dict: key: ele_def the value: assembly

Return type:

common_ele

part_list_from_seq(opt_model, idx1, idx2)[source]

Using the part_tree, return the parts for the input sequence range.

list_tree_all_from_node(node, **kwargs)[source]

List the tree from node with full node output.

list_tree_from_node(node, *args, **kwargs)[source]

List the tree from node with attribute filtering.

The optional arguments are passed through to the by_attr filter. Useful examples or arguments include:

  • pt.list_tree(lambda node: f”{node.name}: {node.tag}”)

  • pt.list_tree(attrname=’tag’)