More efficient ? .dat file reading

This commit is contained in:
Edgar P. Burkhart 2022-04-07 11:06:17 +02:00
parent 2eea373e79
commit a59bcccde7
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
2 changed files with 16 additions and 21 deletions

View file

@ -16,14 +16,12 @@ class ReadSwash:
@classmethod
def read_nohead(cls, path):
with tempfile.TemporaryFile(mode="w+t") as tmpfile:
log.info(f"Replacing \\s with \\n in '{path}'")
subprocess.run(("sed", r"s/\s\+/\n/g;/^$/d", path), stdout=tmpfile, text=True)
log.info(f"Loading '{path}'")
tmpfile.seek(0)
a = np.asarray(tmpfile.readlines(), dtype=float)
log.debug(f"path={a}")
return a
data = []
with path.open() as inp:
for line in inp:
data += line.split()
return np.asarray(data, dtype=float)
def read_time(self, path):
self._t = np.unique(self.read_nohead(path))