forked from issp-center-dev/HPhi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AveSSrand.py
53 lines (45 loc) · 1.77 KB
/
AveSSrand.py
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
import sys
import os.path
import numpy as np
import argparse
parser = argparse.ArgumentParser(
prog='AveSSrand.py',
description='Tool for TPQ calculations.',
epilog='end',
add_help=True,
)
parser.add_argument('-n', action='store', dest='nsamples',
nargs='?', default=5, type=int, choices=None,
help=('Total number of samples.'),
metavar=None)
parser.add_argument('-o', action='store', dest='output',
nargs='?', default="ave_TPQ.dat", type=str, choices=None,
help=('Name of output file.'),
metavar=None)
args = parser.parse_args()
set_num=args.nsamples
np.zeros(set_num)
#Get sample size
str_ = "./output/SS_rand0.dat"
with open(str_, "r") as f:
lines = f.readlines()
DataTmp = np.zeros( (len(lines)-2, set_num) )
DataEne = np.zeros( (len(lines)-2, set_num) )
DataC = np.zeros( (len(lines)-2, set_num) )
for num in range(set_num):
str_ = "./output/SS_rand"+str(num)+".dat"
if os.path.isfile(str_) is not True:
print('The file {} does not exist.'.format(str_))
sys.exit()
with open(str_, "r") as f:
lines = f.readlines()
for count, line in enumerate(lines[2:]):
data = line.split()
DataTmp[count][num]=1.0/float(data[0])
DataEne[count][num]=float(data[1])
DataC[count][num]=pow(float(data[0]),2)*( float(data[2])-pow(float(data[1]),2) )
with open(args.output, "w") as f:
for count, datatmp in enumerate(DataTmp):
f.write("{} {} {} {} {} {}\n".format(datatmp.mean(), datatmp.std(), \
DataEne[count].mean(), DataEne[count].std(),\
DataC[count].mean(), DataC[count].std()))