1
Fork 0

Strong improvements to sws_npz conversion times

This commit is contained in:
Edgar P. Burkhart 2022-03-31 16:05:06 +02:00
parent 6ae1ea9899
commit 14cf8c4efe
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227

View file

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