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