summaryrefslogtreecommitdiff
path: root/utilities/Nerve_GIC/KeplerMapperVisuFromTxtFile.py
blob: c811f6102e67e968d595d63ea355a089d6998541 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python

import km
import numpy as np
from collections import defaultdict
import argparse

"""This file is part of the Gudhi Library. The Gudhi library
   (Geometric Understanding in Higher Dimensions) is a generic C++
   library for computational topology.

   Author(s):       Mathieu Carriere

   Copyright (C) 2017 INRIA

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

__author__ = "Mathieu Carriere"
__copyright__ = "Copyright (C) 2017 INRIA"
__license__ = "GPL v3"

parser = argparse.ArgumentParser(description='Creates an html Keppler Mapper '
                                 'file to visualize a SC.txt file.',
                                 epilog='Example: '
                                 './KeplerMapperVisuFromTxtFile.py '
                                 '-f ../../data/points/human.off_sc.txt'
                                 '- Constructs an human.off_sc.html file.')
parser.add_argument("-f", "--file", type=str, required=True)

args = parser.parse_args()

with open(args.file, 'r') as f:
    network = {}
    mapper = km.KeplerMapper(verbose=0)
    data = np.zeros((3,3))
    projected_data = mapper.fit_transform( data, projection="sum", scaler=None )

    nodes = defaultdict(list)
    links = defaultdict(list)
    custom = defaultdict(list)

    dat = f.readline()
    lens = f.readline()
    color = f.readline();
    param = [float(i) for i in f.readline().split(" ")]

    nums = [int(i) for i in f.readline().split(" ")]
    num_nodes = nums[0]
    num_edges = nums[1]

    for i in range(0,num_nodes):
        point = [float(j) for j in f.readline().split(" ")]
        nodes[  str(int(point[0]))  ] = [  int(point[0]), point[1], int(point[2])  ]
        links[  str(int(point[0]))  ] = []
        custom[  int(point[0])  ] = point[1]

    m = min([custom[i] for i in range(0,num_nodes)])
    M = max([custom[i] for i in range(0,num_nodes)])

    for i in range(0,num_edges):
        edge = [int(j) for j in f.readline().split(" ")]
        links[  str(edge[0])  ].append(  str(edge[1])  )
        links[  str(edge[1])  ].append(  str(edge[0])  )

    network["nodes"] = nodes
    network["links"] = links
    network["meta"] = lens

    html_output_filename = args.file.rsplit('.', 1)[0] + '.html'
    mapper.visualize(network, color_function = color, path_html=html_output_filename, title=dat,
    graph_link_distance=30, graph_gravity=0.1, graph_charge=-120, custom_tooltips=custom, width_html=0,
    height_html=0, show_tooltips=True, show_title=True, show_meta=True, res=param[0],gain=param[1], minimum=m,maximum=M)
    message = repr(html_output_filename) + " is generated. You can now use your favorite web browser to visualize it."
    print(message)


    f.close()