def execute_for_all(resultspath, command): """Call a given python script with the simulation results data file as last command line argument. The script and the data file are specified by (relative) file system paths. :param resultspath: The path where to look for simulation data. :param command: The python script that gets called for all simulations. """ for simulationpath in get_result_dirs(resultspath): print(" Executing code for datafile in {}".format(simulationpath)) # The file(s) with the simulation data resfiles = get_results_file(simulationpath) # Handle case where multiple hdf5 files are found if type(resfiles) is list: print(" Warning: more than one results file found!") else: resfiles = [resfiles] # For each file call the given script for resfile in resfiles: sp.call(["python"] + command + [resfile]) # Move newly created files back to the simulation path. # NOTE: It is the responsability of the code in the # 'scriptcode' script to produce filenames that # do not yield collisions. Otherwise the files # will be overwritten without any warning! for ext in save_extensions: for afile in glob("*" + ext): sp.call(["mv", afile, simulationpath])
def execute_for_all(resultspath, scriptcode, scriptargs): """Call a given python script with the simulation results data file as first command line argument. The script and the data file are specified by (relative) file system paths. :param resultspath: The path where to look for simulation data. :param scriptcode: The python script that gets called for all simulations. :param scriptargs: Optional (constant) arguments to the script. """ # UNBUFFERED timelog file with open("logtime_forall", "w", 0) as timelog: for simulationpath in get_result_dirs(resultspath): starttime = time.time() timelog.writelines(["New script starting at: " + time.ctime(starttime) + "\n", "Executing code for datafile in " + simulationpath + "\n"]) print(" Executing code for datafile in " + simulationpath) # The file with the simulation data afile = get_results_file(simulationpath) # Call the given script sp.call(["python", scriptcode, afile] + scriptargs) endtime = time.time() timelog.writelines(["Script now finished at timestamp: " + time.ctime(endtime) + "\n", "Script took " + str(endtime-starttime) + " second to run\n\n"]) # Move newly created files back to the simulation path. # NOTE: It is the responsability of the code in the # 'scriptcode' script to produce filenames that # do not yield collisions. Otherwise the files # will beoverwritten without any warning! for ext in save_extensions: for afile in glob("*"+ext): sp.call(["mv", afile, simulationpath])