mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-11-30 13:06:53 +01:00
Impr/fix refactor sfcf read (#164)
* refactor read_sfcf * adding tests for find_corr and read_compact_file * add necessary broken data for tests * fixed appended mode reading * factored out sort_names and find_files * now also using sort_files in sfcf.py * edited tests to fit with new structure * added find_files function * shifted helpfunctions to bottom of file * removed some debug lines * linting * Fixed requested changes, added silent mode * added Exception if correlator is not found by read_append_rep * use tmp_path fixture * linting silent keyword * try to fix testing for a_bb * tests: Exception testing in test_find_corr made more explicit. --------- Co-authored-by: Fabian Joswig <fabian.joswig@ed.ac.uk>
This commit is contained in:
parent
991199a680
commit
41fec09816
7 changed files with 880 additions and 315 deletions
|
|
@ -1,6 +1,51 @@
|
|||
import re
|
||||
"""Utilities for the input"""
|
||||
|
||||
|
||||
def sort_names(ll):
|
||||
"""Sorts a list of names of replika with searches for `r` and `id` in the replikum string.
|
||||
If this search fails, a fallback method is used,
|
||||
where the strings are simply compared and the first diffeing numeral is used for differentiation.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
ll: list
|
||||
list to sort
|
||||
|
||||
Returns
|
||||
-------
|
||||
ll: list
|
||||
sorted list
|
||||
"""
|
||||
if len(ll) > 1:
|
||||
r_pattern = r'r(\d+)'
|
||||
id_pattern = r'id(\d+)'
|
||||
|
||||
# sort list by id first
|
||||
if all([re.search(id_pattern, entry) for entry in ll]):
|
||||
ll.sort(key=lambda x: int(re.findall(id_pattern, x)[0]))
|
||||
# then by replikum
|
||||
if all([re.search(r_pattern, entry) for entry in ll]):
|
||||
ll.sort(key=lambda x: int(re.findall(r_pattern, x)[0]))
|
||||
# as the rearrangements by one key let the other key untouched, the list is sorted now
|
||||
|
||||
else:
|
||||
# fallback
|
||||
sames = ''
|
||||
if len(ll) > 1:
|
||||
for i in range(len(ll[0])):
|
||||
checking = ll[0][i]
|
||||
for rn in ll[1:]:
|
||||
is_same = (rn[i] == checking)
|
||||
if is_same:
|
||||
sames += checking
|
||||
else:
|
||||
break
|
||||
print("Using prefix:", ll[0][len(sames):])
|
||||
ll.sort(key=lambda x: int(re.findall(r'\d+', x[len(sames):])[0]))
|
||||
return ll
|
||||
|
||||
|
||||
def check_idl(idl, che):
|
||||
"""Checks if list of configurations is contained in an idl
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue