diff --git a/swash/processing/read_swash.py b/swash/processing/read_swash.py index 53c82a9..c8d0f36 100644 --- a/swash/processing/read_swash.py +++ b/swash/processing/read_swash.py @@ -31,17 +31,28 @@ class ReadSwash: def read_scalar(self, path, const=False): if const: - 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)) + 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) + ) def read_vector(self, path): - return self.read_nohead(path).reshape((self._n_t, 2, self._n_x)) + self._data[path.stem] = self.read_nohead(path).reshape( + (self._n_t, 2, self._n_x) + ) def read_scalar_lay(self, path): - return self.read_nohead(path).reshape((self._n_t, -1, self._n_x)) + self._data[path.stem] = self.read_nohead(path).reshape( + (self._n_t, -1, self._n_x) + ) def read_vector_lay(self, path): - return self.read_nohead(path).reshape((self._n_t, 2, -1, self._n_x)) + self._data[path.stem] = self.read_nohead(path).reshape( + (self._n_t, 2, -1, self._n_x) + ) @property def t(self): @@ -50,3 +61,7 @@ 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 11961bd..815d138 100644 --- a/swash/processing/sws_npz.py +++ b/swash/processing/sws_npz.py @@ -27,16 +27,15 @@ 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'") -np.save(inp.joinpath("dep"), rsws.read_scalar(sws_out.joinpath("dep.dat"))) +rsws.read_scalar(sws_out.joinpath("dep.dat")) log.info("Reading 'botl'") -np.save( - inp.joinpath("botl"), - rsws.read_scalar(sws_out.joinpath("botl.dat"), const=True), -) +rsws.read_scalar(sws_out.joinpath("botl.dat"), const=True) log.info("Reading 'watl'") -np.save(inp.joinpath("watl"), rsws.read_scalar(sws_out.joinpath("watl.dat"))) +rsws.read_scalar(sws_out.joinpath("watl.dat")) log.info("Reading 'vel'") -np.save(inp.joinpath("vel"), rsws.read_vector(sws_out.joinpath("vel.dat"))) +rsws.read_vector(sws_out.joinpath("vel.dat")) + +log.info(f"Writing npz file in '{inp}'") +inp.mkdir(exist_ok=True) +np.savez_compressed(inp.joinpath("sws"), t=rsws.t, x=rsws.x, **rsws.data)