mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-03-15 06:40:24 +01:00
flake8 formatting improvements
This commit is contained in:
parent
863ce6ae73
commit
d4eaf3f48a
3 changed files with 27 additions and 34 deletions
|
@ -53,7 +53,7 @@ def read_pbp(path, prefix, **kwargs):
|
|||
else:
|
||||
r_stop = [None] * replica
|
||||
|
||||
print('Read <bar{psi}\psi> from', prefix[:-1], ',', replica, 'replica', end='')
|
||||
print(r'Read <bar{psi}\psi> from', prefix[:-1], ',', replica, 'replica', end='')
|
||||
|
||||
print_err = 0
|
||||
if 'print_err' in kwargs:
|
||||
|
@ -64,10 +64,10 @@ def read_pbp(path, prefix, **kwargs):
|
|||
|
||||
for rep in range(replica):
|
||||
tmp_array = []
|
||||
with open(path+ '/' + ls[rep], 'rb') as fp:
|
||||
with open(path + '/' + ls[rep], 'rb') as fp:
|
||||
|
||||
#header
|
||||
t = fp.read(4) # number of reweighting factors
|
||||
# header
|
||||
t = fp.read(4) # number of reweighting factors
|
||||
if rep == 0:
|
||||
nrw = struct.unpack('i', t)[0]
|
||||
for k in range(nrw):
|
||||
|
@ -85,7 +85,7 @@ def read_pbp(path, prefix, **kwargs):
|
|||
for i in range(nrw):
|
||||
t = fp.read(4)
|
||||
nfct.append(struct.unpack('i', t)[0])
|
||||
print('nfct: ', nfct) # Hasenbusch factor, 1 for rat reweighting
|
||||
print('nfct: ', nfct) # Hasenbusch factor, 1 for rat reweighting
|
||||
else:
|
||||
for i in range(nrw):
|
||||
nfct.append(1)
|
||||
|
@ -95,7 +95,7 @@ def read_pbp(path, prefix, **kwargs):
|
|||
t = fp.read(4)
|
||||
nsrc.append(struct.unpack('i', t)[0])
|
||||
|
||||
#body
|
||||
# body
|
||||
while 0 < 1:
|
||||
t = fp.read(4)
|
||||
if len(t) < 4:
|
||||
|
@ -118,7 +118,7 @@ def read_pbp(path, prefix, **kwargs):
|
|||
for k in range(nrw):
|
||||
deltas[k].append(tmp_array[k][r_start[rep]:r_stop[rep]])
|
||||
|
||||
print(',', nrw, '<bar{psi}\psi> with', nsrc, 'sources')
|
||||
print(',', nrw, r'<bar{psi}\psi> with', nsrc, 'sources')
|
||||
result = []
|
||||
for t in range(nrw):
|
||||
result.append(Obs(deltas[t], [(w.split('.'))[0] for w in ls]))
|
||||
|
|
|
@ -23,8 +23,7 @@ def read_rwms(path, prefix, version='2.0', names=None, **kwargs):
|
|||
r_stop -- list which contains the last config to be read for each replicum
|
||||
postfix -- postfix of the file to read, e.g. '.ms1' for openQCD-files
|
||||
"""
|
||||
#oqcd versions implemented in this method
|
||||
known_oqcd_versions = ['1.4','1.6','2.0']
|
||||
known_oqcd_versions = ['1.4', '1.6', '2.0']
|
||||
if not (version in known_oqcd_versions):
|
||||
raise Exception('Unknown openQCD version defined!')
|
||||
print("Working with openQCD version " + version)
|
||||
|
@ -42,12 +41,10 @@ def read_rwms(path, prefix, version='2.0', names=None, **kwargs):
|
|||
|
||||
# Exclude files with different names
|
||||
for exc in ls:
|
||||
if not fnmatch.fnmatch(exc, prefix + '*'+postfix+'.dat'):
|
||||
if not fnmatch.fnmatch(exc, prefix + '*' + postfix + '.dat'):
|
||||
ls = list(set(ls) - set([exc]))
|
||||
if len(ls) > 1:
|
||||
ls.sort(key=lambda x: int(re.findall(r'\d+', x[len(prefix):])[0]))
|
||||
#ls = fnames
|
||||
#print(ls)
|
||||
replica = len(ls)
|
||||
|
||||
if 'r_start' in kwargs:
|
||||
|
@ -77,18 +74,18 @@ def read_rwms(path, prefix, version='2.0', names=None, **kwargs):
|
|||
|
||||
for rep in range(replica):
|
||||
tmp_array = []
|
||||
with open(path+ '/' + ls[rep], 'rb') as fp:
|
||||
with open(path + '/' + ls[rep], 'rb') as fp:
|
||||
|
||||
#header
|
||||
t = fp.read(4) # number of reweighting factors
|
||||
# header
|
||||
t = fp.read(4) # number of reweighting factors
|
||||
if rep == 0:
|
||||
nrw = struct.unpack('i', t)[0]
|
||||
if version == '2.0':
|
||||
nrw = int(nrw/2)
|
||||
nrw = int(nrw / 2)
|
||||
for k in range(nrw):
|
||||
deltas.append([])
|
||||
else:
|
||||
if ((nrw != struct.unpack('i', t)[0] and (not verion == '2.0')) or (nrw != struct.unpack('i', t)[0]/2 and version == '2.0')):# little weird if-clause due to the /2 operation needed.
|
||||
if ((nrw != struct.unpack('i', t)[0] and (not version == '2.0')) or (nrw != struct.unpack('i', t)[0] / 2 and version == '2.0')): # little weird if-clause due to the /2 operation needed.
|
||||
raise Exception('Error: different number of reweighting factors for replicum', rep)
|
||||
|
||||
for k in range(nrw):
|
||||
|
@ -96,11 +93,11 @@ def read_rwms(path, prefix, version='2.0', names=None, **kwargs):
|
|||
|
||||
# This block is necessary for openQCD1.6 and openQCD2.0 ms1 files
|
||||
nfct = []
|
||||
if version in ['1.6','2.0']:
|
||||
if version in ['1.6', '2.0']:
|
||||
for i in range(nrw):
|
||||
t = fp.read(4)
|
||||
nfct.append(struct.unpack('i', t)[0])
|
||||
#print('nfct: ', nfct) # Hasenbusch factor, 1 for rat reweighting
|
||||
# print('nfct: ', nfct) # Hasenbusch factor, 1 for rat reweighting
|
||||
else:
|
||||
for i in range(nrw):
|
||||
nfct.append(1)
|
||||
|
@ -109,11 +106,11 @@ def read_rwms(path, prefix, version='2.0', names=None, **kwargs):
|
|||
for i in range(nrw):
|
||||
t = fp.read(4)
|
||||
nsrc.append(struct.unpack('i', t)[0])
|
||||
if version is '2.0':
|
||||
if version == '2.0':
|
||||
if not struct.unpack('i', fp.read(4))[0] == 0:
|
||||
print('something is wrong!')
|
||||
|
||||
#body
|
||||
# body
|
||||
while 0 < 1:
|
||||
t = fp.read(4)
|
||||
if len(t) < 4:
|
||||
|
@ -132,7 +129,7 @@ def read_rwms(path, prefix, version='2.0', names=None, **kwargs):
|
|||
print(config_no, i, j, np.mean(np.exp(-np.asarray(tmp_rw[j]))), np.std(np.exp(-np.asarray(tmp_rw[j]))))
|
||||
print('Sources:', np.exp(-np.asarray(tmp_rw[j])))
|
||||
print('Partial factor:', tmp_nfct)
|
||||
elif version is '1.6' or version is '1.4':
|
||||
elif version == '1.6' or version == '1.4':
|
||||
tmp_nfct = 1.0
|
||||
for j in range(nfct[i]):
|
||||
t = fp.read(8 * nsrc[i])
|
||||
|
@ -151,7 +148,7 @@ def read_rwms(path, prefix, version='2.0', names=None, **kwargs):
|
|||
print(',', nrw, 'reweighting factors with', nsrc, 'sources')
|
||||
result = []
|
||||
for t in range(nrw):
|
||||
if names == None:
|
||||
if names is None:
|
||||
result.append(Obs(deltas[t], [w.split(".")[0] for w in ls]))
|
||||
else:
|
||||
print(names)
|
||||
|
@ -159,8 +156,6 @@ def read_rwms(path, prefix, version='2.0', names=None, **kwargs):
|
|||
return result
|
||||
|
||||
|
||||
|
||||
|
||||
def extract_t0(path, prefix, dtr_read, xmin, spatial_extent, fit_range=5, **kwargs):
|
||||
"""Extract t0 from given .ms.dat files. Returns t0 as Obs.
|
||||
|
||||
|
@ -290,16 +285,16 @@ def _parse_array_openQCD2(d, n, size, wa, quadrupel=False):
|
|||
arr = []
|
||||
if d == 2:
|
||||
tot = 0
|
||||
for i in range(n[d-1]-1):
|
||||
for i in range(n[d - 1] - 1):
|
||||
if quadrupel:
|
||||
tmp = wa[tot:n[d-1]]
|
||||
tmp = wa[tot:n[d - 1]]
|
||||
tmp2 = []
|
||||
for i in range(len(tmp)):
|
||||
if i % 2 == 0:
|
||||
tmp2.append(tmp[i])
|
||||
arr.append(tmp2)
|
||||
else:
|
||||
arr.append(np.asarray(wa[tot:n[d-1]]))
|
||||
arr.append(np.asarray(wa[tot:n[d - 1]]))
|
||||
return arr
|
||||
|
||||
|
||||
|
@ -312,7 +307,7 @@ def _parse_array_openQCD2(d, n, size, wa, quadrupel=False):
|
|||
def _read_array_openQCD2(fp):
|
||||
t = fp.read(4)
|
||||
d = struct.unpack('i', t)[0]
|
||||
t = fp.read(4*d)
|
||||
t = fp.read(4 * d)
|
||||
n = struct.unpack('%di' % (d), t)
|
||||
t = fp.read(4)
|
||||
size = struct.unpack('i', t)[0]
|
||||
|
@ -325,10 +320,10 @@ def _read_array_openQCD2(fp):
|
|||
else:
|
||||
print('Type not known!')
|
||||
m = n[0]
|
||||
for i in range(1,d):
|
||||
for i in range(1, d):
|
||||
m *= n[i]
|
||||
|
||||
t = fp.read(m*size)
|
||||
t = fp.read(m * size)
|
||||
tmp = struct.unpack('%d%s' % (m, types), t)
|
||||
|
||||
arr = _parse_array_openQCD2(d, n, size, tmp, quadrupel=True)
|
||||
|
|
|
@ -134,9 +134,7 @@ def read_sfcf_c(path, prefix, name, quarks='.*', noffset=0, wf=0, wf2=0, **kwarg
|
|||
else:
|
||||
b2b = 0
|
||||
|
||||
read = 0
|
||||
T = 0
|
||||
start = 0
|
||||
ls = []
|
||||
for (dirpath, dirnames, filenames) in os.walk(path):
|
||||
ls.extend(dirnames)
|
||||
|
@ -189,7 +187,7 @@ def read_sfcf_c(path, prefix, name, quarks='.*', noffset=0, wf=0, wf2=0, **kwarg
|
|||
match = re.search(pattern, content)
|
||||
if match:
|
||||
start_read = content.count('\n', 0, match.start()) + 5 + b2b
|
||||
end_match = re.search('\n\s*\n', content[match.start():])
|
||||
end_match = re.search(r'\n\s*\n', content[match.start():])
|
||||
T = content[match.start():].count('\n', 0, end_match.start()) - 4 - b2b
|
||||
assert T > 0
|
||||
print(T, 'entries, starting to read in line', start_read)
|
||||
|
|
Loading…
Add table
Reference in a new issue