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