generate.py 1.6 KB
Newer Older
1
2
3
4
5
6
import sys
sys.path.append('../')
import matplotlib.pyplot as plt

from netflow import *

sfritschi's avatar
sfritschi committed
7
from time import perf_counter
8
        
9
def main():
10
11
12
13
14
    if len(sys.argv) != 2:
        raise AssertionError("Usage: python3 generate.py <nthreads>")
    nthreads = int(sys.argv[1])
    
    print("Using %d threads" % nthreads)
15
    basenet = netflow.load_network_from('../netflow/network/network.h5')
16
    print("Network statistics:")
17
    print("Throats: %d" % len(basenet.throats))
sfritschi's avatar
sfritschi committed
18
19
20
21
    pore_throat_counts = [len(pore.throats) for pore in basenet.pores]
    print("Max. number of throats per pore: %d" % max(pore_throat_counts))
    print("Min. number of throats per pore: %d" % min(pore_throat_counts))
    print("Avg. number of throats per pore: %f" % (sum(pore_throat_counts) / len(pore_throat_counts)))
22
    
23
    target  = [3, 3, 3]
sfritschi's avatar
sfritschi committed
24
    print("Target size: {}".format(target))
25
26
    cutoff  = 0.5 * max([basenet.ub[i] - basenet.lb[i] \
                        for i in range(len(basenet.ub))])
27
    
sfritschi's avatar
sfritschi committed
28
    start = perf_counter()
29
    dendro = netflow.generate_dendrogram(basenet=basenet, targetsize=target, \
30
                                        cutoff=cutoff, sd=42, nthreads=nthreads, mute=False)
sfritschi's avatar
sfritschi committed
31
32
33
    end = perf_counter()
    elapsed = end - start
    print("Elapsed time: %e s" % elapsed)
sfritschi's avatar
sfritschi committed
34
    
sfritschi's avatar
sfritschi committed
35
    """
36
37
    _ = netgen.plot_network(dendro)
    plt.savefig('plots/dendro.png')
sfritschi's avatar
sfritschi committed
38
    """
sfritschi's avatar
sfritschi committed
39
40
41
    """
    netflow.save_network_to('../visualize/network/dendro.h5', dendro)
    """
sfritschi's avatar
sfritschi committed
42
43
44
45
    print("Generated network statistics:")
    print("Throats: %d" % len(dendro.throats))
    print("Pores:   %d" % len(dendro.pores))
    
46
47
if __name__ == '__main__':
    main()