-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_config_time_file.py
executable file
·137 lines (99 loc) · 3.7 KB
/
read_config_time_file.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
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
#!/usr/bin/env python
""" Code to read input in format
#update number 5
t1, data
t2, data
...
#update number 10
t1, data
t2, data
"""
import numpy as np
import configtimeobj
import correlator
import logging
def read_config_time_data_real_imag(filename, configs=None, times=None):
"""Takes a file ofr the form in the header of this source file and
returns a configtimeobject
"""
f = open(filename)
logging.info("reading data from %s", filename)
rawdata = np.genfromtxt(f, delimiter=",", comments="#", autostrip=True, dtype='int,float,float')
f.close()
if configs and times:
logging.info("using configs: %d and times: %d", configs, times)
else:
logging.debug("dimensions not set will guess from data")
times, configs = guess_dimensions(rawdata)
data = rawdata.reshape(configs, times)
return configtimeobj.Cfgtimeobj.fromListTuple(data)
def read_config_time_data_real(filename, configs=None, times=None):
"""Takes a file ofr the form in the header of this source file and
returns a configtimeobject
"""
return configtimeobj.Cfgtimeobj.fromListTuple(
read_config_time_data_real_dict(filename, configs, times))
def read_config_time_data_real_dict(filename, configs=None, times=None):
"""Takes a file ofr the form in the header of this source file and
returns a dict
"""
f = open(filename)
logging.info("reading data from %s", filename)
rawdata = np.genfromtxt(f, delimiter=",", comments="#",
autostrip=True, dtype='int,float', usecols=(0, 1))
f.close()
if configs and times:
logging.info("using configs: %d and times: %d", configs, times)
else:
logging.debug("dimensions not set will guess from data")
times, configs = guess_dimensions(rawdata)
data = rawdata.reshape(configs, times)
#data = data[:10]
return data
def read_correlator(filename, configs=None, times=None):
"""Takes a file ofr the form in the header of this source file and
returns a configtimeobject
"""
f = open(filename)
logging.info("reading data from %s", filename)
rawdata = np.genfromtxt(f, delimiter=",", comments="#",
autostrip=True, dtype='int,float', usecols=(0, 1))
f.close()
if configs and times:
logging.info("using configs: %d and times: %d", configs, times)
else:
logging.debug("dimensions not set will guess from data")
times, configs = guess_dimensions(rawdata)
data = rawdata.reshape(configs, times)
#data = data[:10]
return correlator.Correlator.fromListTuple(data)
def read_config_vev(filename, configs=None):
f = open(filename)
logging.info("reading vev from %s", filename)
rawdata = np.genfromtxt(f, delimiter=",", comments="#",
autostrip=True, dtype='float', usecols=0)
f.close()
if configs:
logging.info("using configs: %d", configs)
else:
logging.debug("vev dimensions not set will guess from data")
configs = len(rawdata)
# rawdata = rawdata[:10]
# configs = 10
vevdict = {}
for config in range(configs):
vevdict[config] = rawdata[config]
return vevdict
def guess_dimensions(rawdata):
if(rawdata[0][0] != 0):
raise Exception("does not start on time 0 can not guess")
time = 0
for datum in rawdata:
if(datum[0] == time):
time += 1
elif(datum[0] == 0):
configs = ((rawdata.shape[0]) / time)
logging.debug("guessing time = %d \tguessing configs = %d", time, configs)
return (time, configs)
else:
raise Exception("number of times could not be guessed")