From ff1efd30961bfcb9b89a68b61771cd06e930a5c3 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Mon, 11 Oct 2021 13:51:11 +0100 Subject: [PATCH] formatting improvements --- .github/workflows/flake8.yml | 1 + pyerrors/input/hadrons.py | 4 +++- pyerrors/input/sfcf.py | 22 +++++++++++----------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.github/workflows/flake8.yml b/.github/workflows/flake8.yml index 91d2770e..d6efe561 100644 --- a/.github/workflows/flake8.yml +++ b/.github/workflows/flake8.yml @@ -18,4 +18,5 @@ jobs: with: ignore: "E501" exclude: "pyerrors/__init__.py" + exclude: "pyerrors/input/__init__.py" path: "pyerrors" diff --git a/pyerrors/input/hadrons.py b/pyerrors/input/hadrons.py index c70cc1e2..6254e912 100644 --- a/pyerrors/input/hadrons.py +++ b/pyerrors/input/hadrons.py @@ -32,8 +32,10 @@ def read_meson_hd5(path, filestem, ens_id, meson='meson_0', tree='meson'): if not files: raise Exception('No files starting with', filestem, 'in folder', path) + def get_cnfg_number(n): + return int(n[len(filestem) + 1:-3]) + # Sort according to configuration number - get_cnfg_number = lambda x: int(x[len(filestem) + 1:-3]) files.sort(key=get_cnfg_number) # Check that configurations are evenly spaced diff --git a/pyerrors/input/sfcf.py b/pyerrors/input/sfcf.py index b732ecda..7dd3544e 100644 --- a/pyerrors/input/sfcf.py +++ b/pyerrors/input/sfcf.py @@ -61,7 +61,7 @@ def read_sfcf(path, prefix, name, **kwargs): for i, item in enumerate(ls): print(item) sub_ls = [] - for (dirpath, dirnames, filenames) in os.walk(path+'/'+item): + for (dirpath, dirnames, filenames) in os.walk(path + '/' + item): sub_ls.extend(dirnames) break for exc in sub_ls: @@ -92,11 +92,11 @@ def read_sfcf(path, prefix, name, **kwargs): deltas[j].append(np.zeros(sublength)) for cnfg, subitem in enumerate(sub_ls): - with open(path + '/' + item + '/' + subitem + '/'+name) as fp: + with open(path + '/' + item + '/' + subitem + '/' + name) as fp: for k, line in enumerate(fp): if(k >= start and k < start + T): floats = list(map(float, line.split())) - deltas[k-start][i][cnfg] = floats[1 + im - single] + deltas[k - start][i][cnfg] = floats[1 + im - single] result = [] for t in range(T): @@ -143,7 +143,7 @@ def read_sfcf_c(path, prefix, name, quarks='.*', noffset=0, wf=0, wf2=0, **kwarg raise Exception('Error, directory not found') # Exclude folders with different names for exc in ls: - if not fnmatch.fnmatch(exc, prefix+'*'): + if not fnmatch.fnmatch(exc, prefix + '*'): ls = list(set(ls) - set([exc])) if len(ls) > 1: ls.sort(key=lambda x: int(re.findall(r'\d+', x[len(prefix):])[0])) # New version, to cope with ids, etc. @@ -157,11 +157,11 @@ def read_sfcf_c(path, prefix, name, quarks='.*', noffset=0, wf=0, wf2=0, **kwarg print('Read', part, 'part of', name, 'from', prefix[:-1], ',', replica, 'replica') for i, item in enumerate(ls): sub_ls = [] - for (dirpath, dirnames, filenames) in os.walk(path+'/'+item): + for (dirpath, dirnames, filenames) in os.walk(path + '/' + item): sub_ls.extend(filenames) break for exc in sub_ls: - if not fnmatch.fnmatch(exc, prefix+'*'): + if not fnmatch.fnmatch(exc, prefix + '*'): sub_ls = list(set(sub_ls) - set([exc])) sub_ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) @@ -182,7 +182,7 @@ def read_sfcf_c(path, prefix, name, quarks='.*', noffset=0, wf=0, wf2=0, **kwarg if b2b: pattern += '\nwf_2 ' + str(wf2) - with open(path+'/'+item+'/'+sub_ls[0], 'r') as file: + with open(path + '/' + item + '/' + sub_ls[0], 'r') as file: content = file.read() match = re.search(pattern, content) if match: @@ -203,14 +203,14 @@ def read_sfcf_c(path, prefix, name, quarks='.*', noffset=0, wf=0, wf2=0, **kwarg deltas[j].append(np.zeros(sublength)) for cfg in range(no_cfg): - with open(path+'/'+item+'/'+sub_ls[cfg]) as fp: + with open(path + '/' + item + '/' + sub_ls[cfg]) as fp: for k, line in enumerate(fp): if k == start_read - 5 - b2b: if line.strip() != 'name ' + name: raise Exception('Wrong format', sub_ls[cfg]) if(k >= start_read and k < start_read + T): floats = list(map(float, line.split())) - deltas[k-start_read][i][cfg] = floats[-2:][im] + deltas[k - start_read][i][cfg] = floats[-2:][im] result = [] for t in range(T): @@ -247,7 +247,7 @@ def read_qtop(path, prefix, **kwargs): # Exclude files with different names for exc in ls: - if not fnmatch.fnmatch(exc, prefix+'*'): + if not fnmatch.fnmatch(exc, prefix + '*'): ls = list(set(ls) - set([exc])) if len(ls) > 1: ls.sort(key=lambda x: int(re.findall(r'\d+', x[len(prefix):])[0])) # New version, to cope with ids, etc. @@ -258,7 +258,7 @@ def read_qtop(path, prefix, **kwargs): for rep in range(replica): tmp = [] - with open(path+'/'+ls[rep]) as fp: + with open(path + '/' + ls[rep]) as fp: for k, line in enumerate(fp): floats = list(map(float, line.split())) if full == 1: