cutcutcodec.core.edit.operation.remove.remove_elements
- cutcutcodec.core.edit.operation.remove.remove_elements(graph: MultiDiGraph, elements: Iterable[str | tuple[str, str, str]]) dict[str | tuple[str, str, str], None | tuple[str, str, str]][source]
Delete several nodes or edges from the graph.
Parameters
- graphnetwork.MultiDiGraph
The assembly graph containing the nodes and edges to be deleted. The operations on this graph will be performed in-place.
- elementstyping.Iterable[typing.Union[str, tuple[str, str, str]]]
The name of nodes and edges to delete from the graph.
Returns
- transformationsdict
Each old edge or node name is associated with its new name. If the new name is None, it means that the element has been deleted. This allows to be informed of all the operations performed.
Raises
- KeyError
If one of the elements is not in the graph.
Examples
>>> from pprint import pprint >>> from cutcutcodec.core.classes.container import ContainerOutput >>> from cutcutcodec.core.compilation.tree_to_graph import tree_to_graph >>> from cutcutcodec.core.edit.operation.remove import remove_elements >>> from cutcutcodec.core.io.read_ffmpeg import ContainerInputFFMPEG >>> with ( ... ContainerInputFFMPEG("cutcutcodec/examples/intro.webm") as container_1, ... ContainerInputFFMPEG("cutcutcodec/examples/intro.webm") as container_2, ... ): ... tree = ContainerOutput([*container_1.out_streams, *container_2.out_streams]) ... >>> graph = tree_to_graph(tree) >>> pprint(list(graph.edges)) [('container_input_ffmpeg_1', 'container_output_1', '0->0'), ('container_input_ffmpeg_1', 'container_output_1', '1->1'), ('container_input_ffmpeg_1', 'container_output_1', '2->2'), ('container_input_ffmpeg_1', 'container_output_1', '3->3'), ('container_input_ffmpeg_2', 'container_output_1', '0->4'), ('container_input_ffmpeg_2', 'container_output_1', '1->5'), ('container_input_ffmpeg_2', 'container_output_1', '2->6'), ('container_input_ffmpeg_2', 'container_output_1', '3->7')] >>> pprint(list(graph.nodes)) ['container_output_1', 'container_input_ffmpeg_1', 'container_input_ffmpeg_2'] >>> pprint(remove_elements( ... graph, ... ["container_input_ffmpeg_1", ('container_input_ffmpeg_2', 'container_output_1', '1->5')] ... )) {'container_input_ffmpeg_1': None, ('container_input_ffmpeg_1', 'container_output_1', '0->0'): None, ('container_input_ffmpeg_1', 'container_output_1', '1->1'): None, ('container_input_ffmpeg_1', 'container_output_1', '2->2'): None, ('container_input_ffmpeg_1', 'container_output_1', '3->3'): None, ('container_input_ffmpeg_2', 'container_output_1', '0->4'): ('container_input_ffmpeg_2', 'container_output_1', '0->0'), ('container_input_ffmpeg_2', 'container_output_1', '1->5'): None, ('container_input_ffmpeg_2', 'container_output_1', '2->6'): ('container_input_ffmpeg_2', 'container_output_1', '2->1'), ('container_input_ffmpeg_2', 'container_output_1', '3->7'): ('container_input_ffmpeg_2', 'container_output_1', '3->2')} >>> pprint(list(graph.edges)) [('container_input_ffmpeg_2', 'container_output_1', '0->0'), ('container_input_ffmpeg_2', 'container_output_1', '2->1'), ('container_input_ffmpeg_2', 'container_output_1', '3->2')] >>> pprint(list(graph.nodes)) ['container_output_1', 'container_input_ffmpeg_2'] >>>