Merge branch 'develop' into feat/typehints

This commit is contained in:
Justus Kuhlmann 2025-01-06 10:53:10 +01:00 committed by GitHub
commit dba277fbda
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 9 deletions

View file

@ -130,7 +130,8 @@ def read_sfcf_multi(path: str, prefix: str, name_list: list[str], quarks_list: l
check_configs: list[list[int]]
list of list of supposed configs, eg. [range(1,1000)]
for one replicum with 1000 configs
rep_string: str
Separator of ensemble name and replicum. Example: In "ensAr0", "r" would be the separator string.
Returns
-------
result: dict[list[Obs]]
@ -200,9 +201,9 @@ def read_sfcf_multi(path: str, prefix: str, name_list: list[str], quarks_list: l
else:
ens_name = kwargs.get("ens_name")
if not appended:
new_names = _get_rep_names(ls, ens_name)
new_names = _get_rep_names(ls, ens_name, rep_sep=(kwargs.get('rep_string', 'r')))
else:
new_names = _get_appended_rep_names(ls, prefix, name_list[0], ens_name)
new_names = _get_appended_rep_names(ls, prefix, name_list[0], ens_name, rep_sep=(kwargs.get('rep_string', 'r')))
new_names = sort_names(new_names)
idl: list[list[int]] = []
@ -649,22 +650,22 @@ def _read_append_rep(filename: str, pattern: str, b2b: bool, cfg_separator: str,
return T, rep_idl, final_data
def _get_rep_names(ls: list[str], ens_name: None=None) -> list[str]:
def _get_rep_names(ls: list[str], ens_name: None=None, rep_sep: str ='r') -> list[str]:
new_names = []
for entry in ls:
try:
idx = entry.index('r')
idx = entry.index(rep_sep)
except Exception:
raise Exception("Automatic recognition of replicum failed, please enter the key word 'names'.")
if ens_name:
new_names.append('ens_name' + '|' + entry[idx:])
new_names.append(ens_name + '|' + entry[idx:])
else:
new_names.append(entry[:idx] + '|' + entry[idx:])
return new_names
def _get_appended_rep_names(ls: list[str], prefix: str, name: str, ens_name: None=None) -> list[str]:
def _get_appended_rep_names(ls: list[str], prefix: str, name: str, ens_name: None=None, rep_sep: str ='r') -> list[str]:
new_names = []
for exc in ls:
if not fnmatch.fnmatch(exc, prefix + '*.' + name):
@ -673,12 +674,12 @@ def _get_appended_rep_names(ls: list[str], prefix: str, name: str, ens_name: Non
for entry in ls:
myentry = entry[:-len(name) - 1]
try:
idx = myentry.index('r')
idx = myentry.index(rep_sep)
except Exception:
raise Exception("Automatic recognition of replicum failed, please enter the key word 'names'.")
if ens_name:
new_names.append('ens_name' + '|' + entry[idx:])
new_names.append(ens_name + '|' + entry[idx:])
else:
new_names.append(myentry[:idx] + '|' + myentry[idx:])
return new_names

View file

@ -387,3 +387,33 @@ def test_find_correlator():
found_start, found_T = sfin._find_correlator(file, "2.0", "name f_A\nquarks lquark lquark\noffset 0\nwf 0", False, False)
assert found_start == 21
assert found_T == 3
def test_get_rep_name():
names = ['data_r0', 'data_r1', 'data_r2']
new_names = sfin._get_rep_names(names)
assert len(new_names) == 3
assert new_names[0] == 'data_|r0'
assert new_names[1] == 'data_|r1'
assert new_names[2] == 'data_|r2'
names = ['data_q0', 'data_q1', 'data_q2']
new_names = sfin._get_rep_names(names, rep_sep='q')
assert len(new_names) == 3
assert new_names[0] == 'data_|q0'
assert new_names[1] == 'data_|q1'
assert new_names[2] == 'data_|q2'
def test_get_appended_rep_name():
names = ['data_r0.f_1', 'data_r1.f_1', 'data_r2.f_1']
new_names = sfin._get_appended_rep_names(names, 'data', 'f_1')
assert len(new_names) == 3
assert new_names[0] == 'data_|r0'
assert new_names[1] == 'data_|r1'
assert new_names[2] == 'data_|r2'
names = ['data_q0.f_1', 'data_q1.f_1', 'data_q2.f_1']
new_names = sfin._get_appended_rep_names(names, 'data', 'f_1', rep_sep='q')
assert len(new_names) == 3
assert new_names[0] == 'data_|q0'
assert new_names[1] == 'data_|q1'
assert new_names[2] == 'data_|q2'