-
Notifications
You must be signed in to change notification settings - Fork 1
/
test
executable file
·222 lines (191 loc) · 6.09 KB
/
test
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/env python
import os
import json
import math
import time
from scipy.stats import t
import getopt, sys
import re
import numpy as np
a = [1,2,3,4,5,6,7,8,9]
print(a[-1])
print(np.asarray(tuple(a)))
print(type(5))
print(type(5) == int)
ind = np.arange(10)
#ind2 = np.arange('1', '2')
print(type(ind))
print(ind)
#print(ind2)
url = "abcde.com"
url = re.sub('\\.com$', '', url)
print(url)
def main():
print("range(len[1,2,3,4]):")
print(range(len([1,2,3,4])))
a = [4]
print("PMD0")
print('type of a: {0}. a = '.format(type(a)))
print("a is:", a)
a.append(5)
print("a is:", a)
print("Type of dict:")
print(type({}))
an_empty_dict = {}
print('(type(an_empty_dict) == dict) evaluates to {0}'.format(type({}) == dict))
try:
# In the list, the long options are defined.
# In the string (2nd argument), the options are listed as a string.
# The options that require an argument are followed by a colon.
opts, args = getopt.getopt(sys.argv[1:], "d:o:", ["help", "output="])
i = 0
except getopt.GetoptError as err:
# print help information and exit:
print str(err) # will print something like "option -a not recognized"
#usage()
sys.exit(2)
output = None
verbose = False
direction = ''
for o, a in opts:
if o == "-d":
if i == 0:
direction = []
i += 1
direction.append(a)
print("direction=")
print(direction)
elif o == "-v":
verbose = True
elif o in ("-h", "--help"):
#usage()
print("usage")
sys.exit()
elif o == "--output":
output = a
else:
assert False, "unhandled option"
if __name__ == "__main__":
main()
# dict4 = {}
# dict4[('1','2','3')]= "onetwothree"
# print(('1','2','3') in dict4.keys())
# print(('1','2','4') in dict4.keys())
# def read_json_file(filename):
# """ returns an array containing the content of the JSON file.
# keyword arguments:
# filename -- name of json file to interpret
# """
# with open(filename, "r") as file:
# return json.loads(file.read())
# def get_nth_moment (result_times, n):
# """
# Calculates the nth moment of a list.
# Keyword values:
# result_times -- list of result times (floats)
# n -- integer describing that statistical moment of result_times which is returned
# """
# suml = 0
# N = len(result_times)
# for i in range(N):
# suml += result_times[i]**n
# return (suml/float(N))
# def get_average_and_stddev_alt(result_times):
# avg = 0
# N = len(result_times)
# for i in range(N):
# avg += result_times[i]
# avg = avg/float(N)
# std_dev = 0
# for i in range(N):
# std_dev += (result_times[i]-avg)**2
# std_dev = math.sqrt(std_dev/float(N))
# return (avg, std_dev)
# def get_average_and_stddev (result_times):
# """ Returns average and stddev for a list.
# Keyword values:
# result_times -- list of result times (floats)
# """
# av = get_nth_moment(result_times, 1)
# return (av, math.sqrt(get_nth_moment(result_times, 2) - av**2))
# def get_average_and_var_alt(result_times):
# avg = 0
# N = len(result_times)
# for i in range(N):
# avg += result_times[i]
# avg = avg/N
# std_dev = 0
# for i in range(N):
# std_dev = (result_times[i]-avg)**2
# std_dev = std_dev/N
# return (avg, std_dev)
# def get_average_and_var (result_times):
# """ Returns average and stddev for a list.
# Keyword values:
# result_times -- list of result times (floats)
# """
# av = get_nth_moment(result_times, 1)
# return (av, get_nth_moment(result_times, 2) - av**2)
# a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
# av1, stddev1 = get_average_and_stddev(a)
# av2, stddev2 = get_average_and_stddev_alt(a)
# av3, var3 = get_average_and_var(a)
# av4, var4 = get_average_and_var_alt(a)
# print("standard: (%.2E, %.2E), alt: (%.2E, %.2E)" % (av1, stddev1, av2, stddev2))
# print("standard: (%.2E, %.2E), alt: (%.2E, %.2E)" % (av3, var3, av4, var4))
# print("1st moment: %.2E" % get_nth_moment(a, 1))
# e = get_nth_moment(a, 2)
# print("2nd moment: %.2E" % e)
# d = math.sqrt(e)
# print("sqrt 2nd moment: %.2E" % d)
# f = (e - get_nth_moment(a, 1)**2)
# print("2nd mom. minus av. squared: %.2E" % f)
# print("sqrt. above %.2E" % math.sqrt(f))
# dircontents = os.listdir(os.getcwd())
# print(dircontents)
# a = os.path.normpath(dircontents[0])
# b = os.path.normpath(dircontents[1])
# print(a)
# print(os.path.isdir(a))
# print(b)
# print(os.path.isdir(b))
# isdir = os.path.isdir("/home/thor/Documents/Uni/hiperfit/finpar/lib")
# print("isdir is: %s" % isdir)
# isdir2 = os.path.isdir("/home/thor/Documents/Uni/hiperfit/finpar/test123.txt")
# print("os.path.isdir called on non existent path returns %s." % isdir2)
# print("dircontents[0] is %s " % dircontents[0])
# print(int("5\n\r"))
# print(os.path.basename(os.path.normpath(os.getcwd())))
# ts = time.time()
# print(ts)
# ## TEST MAP FUNCTIONS
# a = [1,2,3,4,5]
# b = [x**2 for x in a]
# print(a)
# print(b)
# dict1 = {'1':'a', '2':'b'}
# dict2 = {'3':'c', '4':'d'}
# dict1.update(dict2)
# print(dict1)
# ## STATISTICAL FUNCTION
# def get_mean_and_unc(result_times):
# """ Returns mean and uncertainty of mean for a list.
# Keyword values:
# result_times -- list of result times (floats)
# """
# N = len(result_times)
# sample_mean = get_nth_moment(result_times, 1)
# sample_variance = sum([x**2-sample_mean**2 for x in result_times])/float(N - 1)
# estimated_std_err = math.sqrt(sample_variance) / math.sqrt(N)
# interval = t.interval(0.95, N - 1, loc = sample_mean, scale = estimated_std_err)
# unc = (interval[1] - interval[0])/2
# return (sample_mean, unc)
# a = t.interval(0.95, 10 - 1, loc = 5, scale = 10)
# print(a)
# print(a[0])
# obs = [2,3,5,6,9]
# mean, unc, interval = get_mean_and_unc(obs)
# print("observed data: ", obs)
# print("mean is: ", mean)
# print("unc is: ", unc)
# print("interval is: ", interval)