Skip to content

utils

Utilities functions for the analysis

split_chunk(chunk)

Split a chunk if it is composed of multiple components.

If a chunk is composed of multiple connected components, we want to split them so some analysis may be performed.

Parameters:

Name Type Description Default
chunk Chunk

A chunk to split

required

Returns:

Type Description
Union[Chunk, SuperChunk]

Either a Chunk or a SuperChunk

Source code in quokka/analysis/utils.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def split_chunk(
    chunk: quokka.Chunk,
) -> Union[quokka.Chunk, quokka.SuperChunk]:
    """Split a chunk if it is composed of multiple components.

    If a chunk is composed of multiple connected components, we want to split them so
    some analysis may be performed.

    Arguments:
        chunk: A chunk to split

    Returns:
        Either a Chunk or a SuperChunk
    """
    components = list(nx.connected_components(nx.Graph(chunk.graph)))
    if len(components) <= 1:
        return chunk

    return quokka.function.SuperChunk(chunk, components)