diff --git a/wetb/prepost/Simulations.py b/wetb/prepost/Simulations.py index f79ef9a648e44833b0b43ad1e81594425d69ce77..7bc38aca3c8e7ef061817e22fff16882813d61fb 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 d2f3d49cf628288fa09db9084d8d27b8126e56dd..dc854aceb4f23e22243b2c9df2ce3d04d5e62672 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 afe37d1f0fa58d9a3fdeed12e70bc302ac8077f6..394d2fae3408449a55a6c7af9c61ede8627e89dd 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]'])