The documentation for the each function in the ComputeMT.py file is below (in alphabetical order):

ComputeMergeTree(leaf_id)

This function computes the merge tree of a particular leaf in horizontal and vertical direction. Args: leaf_id: id of the leaf Returns: MT: dictionary containing the merge tree in horizontal and vertical direction

Source code in ComputeMT.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
def ComputeMergeTree(leaf_id: int) -> nx.Graph:
    ''' This function computes the merge tree of a particular leaf in horizontal and vertical direction.
        Args:
            leaf_id: id of the leaf
        Returns:
            MT: dictionary containing the merge tree in horizontal and vertical direction
    '''
    # Get the filtration in each direction
    hAngle = findFiltration(theta=0)
    vAngle = findFiltration(theta=90)

    G = LeaftoGraph(GetCoordinates(GetLeafData(leaf_id)))

    # Compute the merge tree in each direction
    hMergetree = buildMergeTreeAllPoints(
        g_orig=G, filtration=hAngle, show=False)
    vMergetree = buildMergeTreeAllPoints(
        g_orig=G, filtration=vAngle, show=False)

    # Compute the height matrix in each direction
    hHeight = getHeightMatrix(hMergetree)[0]
    vHeight = getHeightMatrix(vMergetree)[0]

    MTheight = [hHeight, vHeight]

    MT = dict(enumerate(MTheight))

    return MT

DataVisualization(leaf_id)

This function visualizes the data in the form of a graph. Args: leaf_id: id of the leaf Returns: none

Source code in ComputeMT.py
82
83
84
85
86
87
88
89
90
91
def DataVisualization(leaf_id):
    ''' This function visualizes the data in the form of a graph.
        Args:
            leaf_id: id of the leaf
        Returns:
            none
    '''
    G = LeaftoGraph(GetCoordinates(GetLeafData(leaf_id)))
    # Drawing the graph
    nx.draw(G, nx.get_node_attributes(G, 'pos'), with_labels=True)

DownloadDataset(dataset_url)

This function downloads the dataset from the given url and returns a pandas dataframe.

Parameters:

Name Type Description Default
dataset_url

url of the dataset

required

Returns: df: pandas dataframe containing the dataset

Source code in ComputeMT.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
def DownloadDataset(dataset_url):
    ''' This function downloads the dataset from the given url and returns a pandas dataframe.

        Args: 
            dataset_url: url of the dataset
        Returns:
            df: pandas dataframe containing the dataset

    '''
    df = pd.read_csv(dataset_url)
    return df

GetCoordinates(data)

This function extracts the coordinates of the leaf from the given data. Args: data: pandas dataframe containing the data of the leaf Returns:
n_pos: dictionary containing the coordinates of the leaf

Source code in ComputeMT.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def GetCoordinates(data):
    ''' This function extracts the coordinates of the leaf from the given data.
        Args:
            data: pandas dataframe containing the data of the leaf
        Returns:   
            n_pos: dictionary containing the coordinates of the leaf
    '''

    # Extracting the coordinates from the data in form of a list of tuples
    n_pos_list = list((data.iloc[i], data.iloc[i+1])
                      for i in range(6, (len(data)-1), 2))

    # Remove inner coordinates from the list
    for i in [1, 2, 3, 4]:
        del n_pos_list[1]

    # Converting the list of tuples into a dictionary with keys as the index of the tuple
    n_pos = dict(enumerate(n_pos_list))
    return n_pos

GetLeafData(leaf_id)

This function returns a pandas dataframe containing all the data of a particular leaf. It first downloads the dataset from passiflora_aligned.csv and then returns the data of the leaf with the given leaf_id. Args: leaf_id: id of the leaf Returns: leaf: pandas dataframe containing the data of the leaf with the given leaf_id

Source code in ComputeMT.py
19
20
21
22
23
24
25
26
27
28
29
30
def GetLeafData(leaf_id):
    ''' This function returns a pandas dataframe containing all the data of a particular leaf. It first downloads the dataset from passiflora_aligned.csv and then returns the data of the leaf with the given leaf_id.
        Args:
            leaf_id: id of the leaf
        Returns:
            leaf: pandas dataframe containing the data of the leaf with the given leaf_id
    '''
    data = DownloadDataset('passiflora_aligned.csv')

    # Get the data of a single leaf with the given leaf_id
    leaf = data.iloc[leaf_id]
    return leaf

LeaftoGraph(coordinate_dict)

This function visualizes the data in the form of a graph. Args: coordinate_dict: dictionary containing the coordinates of the leaf Returns: G: graph

Source code in ComputeMT.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def LeaftoGraph(coordinate_dict):
    ''' This function visualizes the data in the form of a graph.
        Args:
            coordinate_dict: dictionary containing the coordinates of the leaf
        Returns:
            G: graph
    '''
    G = nx.Graph()

    # Adding nodes to the graph
    G.add_nodes_from(coordinate_dict.keys())

    for n, p in coordinate_dict.items():
        G.nodes[n]['pos'] = p

    # Adding edges to the graph
    nodes = list(G.nodes)
    edges = []
    for p_node, c_node in zip(nodes, nodes[1:]):
        edges.append((p_node, c_node))

    edges.append((nodes[0], nodes[-1]))

    G.add_edges_from(edges)

    return G

The python file ComputeMT.py can be found here.