Merge pull request #149 from jkuhl-uni/feat/read_ms5_xsf

fix for the case that there are multiple dots in file names
This commit is contained in:
Fabian Joswig 2023-02-07 13:00:40 +00:00 committed by GitHub
commit 2027f0003a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1061,6 +1061,10 @@ def read_ms5_xsf(path, prefix, qc, corr, sep="r", **kwargs):
found = [] found = []
files = [] files = []
names = [] names = []
if "names" in kwargs:
names = kwargs.get("names")
for (dirpath, dirnames, filenames) in os.walk(path + "/"): for (dirpath, dirnames, filenames) in os.walk(path + "/"):
found.extend(filenames) found.extend(filenames)
break break
@ -1068,16 +1072,17 @@ def read_ms5_xsf(path, prefix, qc, corr, sep="r", **kwargs):
for f in found: for f in found:
if fnmatch.fnmatch(f, prefix + "*.ms5_xsf_" + qc + ".dat"): if fnmatch.fnmatch(f, prefix + "*.ms5_xsf_" + qc + ".dat"):
files.append(f) files.append(f)
if not sep == "": if "names" not in kwargs:
names.append(prefix + "|r" + f.split(".")[0].split(sep)[1]) if not sep == "":
else: se = f.split(".")[0]
names.append(prefix) for s in f.split(".")[1:-1]:
files = sorted(files) se += "." + s
names.append(se.split(sep)[0] + "|r" + se.split(sep)[1])
else:
names.append(prefix)
if "names" in kwargs: names = sorted(names)
names = kwargs.get("names") files = sorted(files)
else:
names = sorted(names)
cnfgs = [] cnfgs = []
realsamples = [] realsamples = []