From a71146a6bda42129edb9cfead32f5f57264cbe3b Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Tue, 15 Mar 2022 10:43:29 +0100 Subject: [PATCH] Revert to separate npy outputs --- swash/processing/read_swash.py | 28 ++++++---------------------- swash/processing/sws_npz.py | 21 ++++++++++++++------- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/swash/processing/read_swash.py b/swash/processing/read_swash.py index 722ffec..53c82a9 100644 --- a/swash/processing/read_swash.py +++ b/swash/processing/read_swash.py @@ -10,11 +10,10 @@ class ReadSwash: self._n_t = None self._t = None self._x = None - self._data = {} @classmethod def read_nohead(cls, path): - with tempfile.NamedTemporaryFile(dir=path.parent) as tmpfile: + with tempfile.TemporaryFile() as tmpfile: with open(path) as file: subprocess.run(("tr", "-d", "\n"), stdin=file, stdout=tmpfile) tmpfile.seek(0) @@ -32,28 +31,17 @@ class ReadSwash: def read_scalar(self, path, const=False): if const: - self._data[path.stem] = self.read_nohead(path).reshape( - (self._n_t, self._n_x) - )[0, :] - return - self._data[path.stem] = self.read_nohead(path).reshape( - (self._n_t, self._n_x) - ) + return self.read_nohead(path).reshape((self._n_t, self._n_x))[0, :] + return self.read_nohead(path).reshape((self._n_t, self._n_x)) def read_vector(self, path): - self._data[path.stem] = self.read_nohead(path).reshape( - (self._n_t, 2, self._n_x) - ) + return self.read_nohead(path).reshape((self._n_t, 2, self._n_x)) def read_scalar_lay(self, path): - self._data[path.stem] = self.read_nohead(path).reshape( - (self._n_t, -1, self._n_x) - ) + return self.read_nohead(path).reshape((self._n_t, -1, self._n_x)) def read_vector_lay(self, path): - self._data[path.stem] = self.read_nohead(path).reshape( - (self._n_t, 2, -1, self._n_x) - ) + return self.read_nohead(path).reshape((self._n_t, 2, -1, self._n_x)) @property def t(self): @@ -62,7 +50,3 @@ class ReadSwash: @property def x(self): return self._x - - @property - def data(self): - return self._data diff --git a/swash/processing/sws_npz.py b/swash/processing/sws_npz.py index 0e12d5d..32622d4 100644 --- a/swash/processing/sws_npz.py +++ b/swash/processing/sws_npz.py @@ -27,20 +27,27 @@ rsws = ReadSwash() rsws.read_time(sws_out.joinpath("tsec.dat")) rsws.read_x(sws_out.joinpath("xp.dat")) +inp.mkdir(exist_ok=True) +log.info(f"Wrinting output in '{inp}'") log.info("Reading 'dep'") -rsws.read_scalar(sws_out.joinpath("dep.dat")) +np.save(inp.joinpath("dep"), rsws.read_scalar(sws_out.joinpath("dep.dat"))) log.info("Reading 'botl'") -rsws.read_scalar(sws_out.joinpath("botl.dat"), const=True) +np.save( + inp.joinpath("botl"), + rsws.read_scalar(sws_out.joinpath("botl.dat"), const=True), +) log.info("Reading 'watl'") -rsws.read_scalar(sws_out.joinpath("watl.dat")) +np.save(inp.joinpath("watl"), rsws.read_scalar(sws_out.joinpath("watl.dat"))) log.info("Reading 'vel'") -rsws.read_vector(sws_out.joinpath("vel.dat")) +np.save(inp.joinpath("vel"), rsws.read_vector(sws_out.joinpath("vel.dat"))) log.info("Reading 'press'") -rsws.read_scalar(sws_out.joinpath("press.dat")) +np.save(inp.joinpath("press"), rsws.read_scalar(sws_out.joinpath("press.dat"))) log.info("Reading 'zk'") -rsws.read_scalar_lay(sws_out.joinpath("zk.dat")) +np.save(inp.joinpath("zk"), rsws.read_scalar_lay(sws_out.joinpath("zk.dat"))) log.info("Reading 'velk'") -rsws.read_vector_lay(sws_out.joinpath("velk.dat")) +np.save( + inp.joinpath("velk"), rsws.read_vector_lay(sws_out.joinpath("velk.dat")) +) log.info(f"Writing npz file in '{inp}'") inp.mkdir(exist_ok=True)