Belle II Software development
convert_npz_to_ASCII.py
1
8"""
9---------------------------------------------------------------------------
10Script to convert plots from npz format to ASCII - used for the memory testing
11
12> cd ~arich/examples/
13> printenv | grep -i belle2
14> which basf2
15> which python3
16> b2code-memoryusage -h
17> b2code-memoryusage -m record -i 0.01 -p ARICHStandAlone_memory.npz basf2 -n 1000
18 ARICHStandAlone.py -- -b -m | tee ARICHStandAlone_memory.log
19> python3 ../utility/scripts/convert_npz_to_ASCII.py --npzfile=ARICHStandAlone_memory.npz --dump
20> python3 ../utility/scripts/convert_npz_to_ASCII.py --npzfile=ARICHStandAlone_memory.npz --arrayname total_memory
21> root -l ../utility/scripts/convert_npz_ASCII_to_root.C"(\"total_memory.dat\")"
22---------------------------------------------------------------------------
23"""
24
25from optparse import OptionParser
26import numpy as np
27
28parser = OptionParser()
29parser.add_option('-f', '--npzfile', dest='npzfile', default='ARICHStandAlone_memory.npz', help='Name of the input npz file')
30parser.add_option('-a', '--arrayname', dest='arrayname', default='total_memory',
31 help='Name of the array to convert in ASCII format')
32parser.add_option('-d', '--dump', action="store_true", dest='dump', default=False, help='Dump list of arrays')
33parser.add_option('-p', '--printv', dest='printv', default='', help='Name of the array to print')
34(options, args) = parser.parse_args()
35
36npzfile = np.load(options.npzfile)
37
38if(options.dump):
39 for myarr in npzfile.files:
40 print(myarr)
41
42if(len(options.arrayname) > 0):
43 outDatFile = options.arrayname + '.dat'
44 np.savetxt(outDatFile, npzfile[options.arrayname], delimiter=' ')
45
46if(len(options.printv) > 0):
47 print(npzfile[options.printv])