/
gauss.py
executable file
·65 lines (45 loc) · 1.66 KB
/
gauss.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
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
import sys
import os
import numpy as np
import json
__copyright__ = """
Copyright 2018 Robin A. Richardson, David W. Wright
This file is part of EasyVVUQ
EasyVVUQ is free software: you can redistribute it and/or modify
it under the terms of the Lesser GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
EasyVVUQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Lesser GNU General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
__license__ = "LGPL"
if len(sys.argv) != 2:
sys.exit("Usage: python3 gauss.py JSONIN")
json_input = sys.argv[1]
if not os.path.isfile(json_input):
sys.exit(json_input + " does not exist.")
with open(json_input, "r") as f:
inputs = json.load(f)
mu = float(inputs['mu'])
sigma = float(inputs['sigma'])
num_steps = int(inputs['num_steps'])
output_filename = inputs['outfile']
if 'biasfile' in inputs:
with open(inputs['biasfile']) as fin:
line = fin.readline()
bias = float(line.split()[0])
else:
bias = 0
if num_steps <= 0:
sys.exit("num_steps should be > 0")
numbers = np.random.normal(mu, sigma, num_steps)
numbers += bias
numbers_out = np.array(list(enumerate(numbers)))
header = 'Step,Value'
fmt = '%i,%f'
np.savetxt(output_filename, numbers_out, fmt=fmt, header=header, comments='')