1
Fork 0

Processing update: fix empty file issue

This commit is contained in:
Edgar P. Burkhart 2022-03-15 10:21:09 +01:00
parent bb9dfe8603
commit 2d1c5683f2
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
2 changed files with 13 additions and 19 deletions

View file

@ -13,8 +13,10 @@ class ReadSwash:
@classmethod
def read_nohead(cls, path):
with open(path) as file, tempfile.TemporaryFile() as tmpfile:
subprocess.run(("tr", "-d", "\n"), stdin=file, stdout=tmpfile)
with tempfile.TemporaryFile() as tmpfile:
with open(path) as file:
subprocess.run(("tr", "-d", "\n"), stdin=file, stdout=tmpfile)
tmpfile.seek(0)
return np.loadtxt(tmpfile)
def read_time(self, path):
@ -29,27 +31,17 @@ 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)
)
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):
return 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):
return 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):
return 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):

View file

@ -32,8 +32,10 @@ log.info(f"Wrinting output in '{inp}'")
log.info("Reading 'dep'")
np.save(inp.joinpath("dep"), 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))
np.save(
inp.joinpath("botl"),
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")))
log.info("Reading 'vel'")