1515import glob
1616import re
1717import time
18+ import math
1819from subprocess import Popen , PIPE
1920
2021VERBOSE = False
@@ -318,11 +319,13 @@ def main(argv):
318319 parser_usage = "launch.py job_configfile minrun maxrun\n \n "
319320 parser_usage += "optional: -f file_num: file_num must be 3 digits, with leading 0's if necessary)\n "
320321 parser_usage += " but, it can be a search string for glob (e.g. first 5 files: -f '00[0-4]' (MUST include quotes!))\n \n "
322+ parser_usage += "optional: -s N: process N evenly-spaced files for each run\n \n "
321323 parser_usage += "optional: -v True: verbose output\n \n "
322324 parser = OptionParser (usage = parser_usage )
323325
324326 # PARSER OPTIONS
325327 parser .add_option ("-f" , "--file" , dest = "file" , help = "specify file(s) to run over" )
328+ parser .add_option ("-s" , "--space" , dest = "space" , help = "process N evenly-spaced files" )
326329 parser .add_option ("-v" , "--verbose" , dest = "verbose" , help = "verbose output" )
327330
328331 # GET ARGUMENTS
@@ -337,6 +340,7 @@ def main(argv):
337340 MAXRUN = int (args [2 ])
338341 VERBOSE = True if (options .verbose ) else False
339342 INPUT_FILE_NUM = options .file if (options .file ) else "*" #must be three digits, with leading 0's if necessary
343+ EVENLY_SPACED_FILES = int (options .space ) if (options .space ) else 0
340344
341345 # READ CONFIG
342346 config_dict = read_config (JOB_CONFIG_FILE )
@@ -378,6 +382,17 @@ def main(argv):
378382 if (VERBOSE == True ):
379383 print (str (len (file_list )) + " files found for run " + str (RUN ))
380384
385+ file_list .sort ()
386+
387+ # Remove elements ending with ".tar"
388+ file_list = [item for item in file_list if not item .endswith (".tar" )]
389+
390+ if (options .space ):
391+ # Select N evenly spaced entries
392+ step_size = max (1 ,int (math .ceil (len (file_list )/ EVENLY_SPACED_FILES ))) # Ensure the step size is at least 1
393+ #print(len(file_list),step_size)
394+ file_list = file_list [:step_size * EVENLY_SPACED_FILES :step_size ]
395+
381396 # Add jobs to workflow
382397 for FILEPATH in file_list :
383398 add_job (WORKFLOW , FILEPATH , config_dict )
0 commit comments