From 27d7bbbd5fcfd5efee1532a07802c1ef27414bf3 Mon Sep 17 00:00:00 2001 From: dave <dave@dtu.dk> Date: Tue, 2 Aug 2016 15:05:54 +0200 Subject: [PATCH] prepost: run checklogs after HAWC2 on the node --- wetb/prepost/Simulations.py | 14 +++++++++++++- wetb/prepost/statsdel.py | 14 ++++++++++++++ wetb/prepost/windIO.py | 5 ++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/wetb/prepost/Simulations.py b/wetb/prepost/Simulations.py index f79ef9a..7bc38ac 100755 --- a/wetb/prepost/Simulations.py +++ b/wetb/prepost/Simulations.py @@ -2541,6 +2541,8 @@ class PBS(object): self.pbs += ' echo "POST-PROCESSING"\n' self.pbs += ' source activate %s\n' % self.pyenv self.pbs += " " + self.checklogs() + self.pbs += " " self.postprocessing() self.pbs += ' source deactivate\n' self.pbs += "else\n" @@ -2549,6 +2551,8 @@ class PBS(object): self.pbs += " %s %s ./%s %s \n" % param self.pbs += ' echo "POST-PROCESSING"\n' self.pbs += " " + self.checklogs() + self.pbs += " " self.postprocessing() self.pbs += "fi\n" @@ -2880,6 +2884,13 @@ class PBS(object): self.pbs += ' find .\n' self.pbs += '# ' + '-'*78 + '\n' + def checklogs(self): + """ + """ + self.pbs += 'python -c "from wetb.prepost import statsdel; ' + rpl = (os.path.join(self.logs_dir, self.case+'.log')) + self.pbs += 'statsdel.logcheck(\'%s\')"\n' % rpl + def postprocessing(self): """Run post-processing just after HAWC2 has ran """ @@ -2968,11 +2979,12 @@ class ErrorLogs(windIO.LogFile): def __init__(self, silent=False, cases=None, resultfile='ErrorLog.csv'): # call init from base class - super(ErrorLogs, self).__init__(silent=silent) + super(ErrorLogs, self).__init__() self.PathToLogs = '' self.ResultFile = resultfile self.cases = cases + self.silent = silent # TODO: save this not a csv text string but a df_dict, and save as excel # and DataFrame! diff --git a/wetb/prepost/statsdel.py b/wetb/prepost/statsdel.py index d2f3d49..dc854ac 100644 --- a/wetb/prepost/statsdel.py +++ b/wetb/prepost/statsdel.py @@ -23,6 +23,20 @@ import os from wetb.prepost import windIO +def logcheck(fname, fsave=None, mode='w'): + """Check the log file of a single HAWC2 simulation and save results to + textfile. + """ + + logf = windIO.LogFile() + logf.readlog(fname) + contents = logf._msglistlog2csv('') + if fsave is None: + fsave = fname.replace('.log', '.csv') + with open(fsave, mode) as f: + f.write(contents) + + def calc(fpath, no_bins=46, m=[3, 4, 6, 8, 10, 12], neq=None, i0=0, i1=None, ftype=False, fsave=False): """ diff --git a/wetb/prepost/windIO.py b/wetb/prepost/windIO.py index afe37d1..394d2fa 100755 --- a/wetb/prepost/windIO.py +++ b/wetb/prepost/windIO.py @@ -45,9 +45,8 @@ class LogFile(object): """Check a HAWC2 log file for errors. """ - def __init__(self, silent=False): + def __init__(self): - self.silent = silent # the total message list log: self.MsgListLog = [] # a smaller version, just indication if there are errors: @@ -324,7 +323,7 @@ class LogFile(object): # save the iterations in the results folder if save_iter: - fiter = fname.replace('.log', '.iter') + fiter = os.path.basename(fname).replace('.log', '.iter') fmt = ['%12.06f', '%4i', '%4i'] if case is not None: fpath = os.path.join(case['[run_dir]'], case['[iter_dir]']) -- GitLab