def main(): """ Parse command line options and create the needed files/directories """ # Detect BBP installation bbp_install = InstallCfg.getInstance() prog_base = os.path.basename(sys.argv[0]) usage = "usage: %s [options]" % (prog_base) parser = optparse.OptionParser(usage) parser.add_option("-c", "--codebase", type="string", action="store", dest="codebase", help="Codebase for the simulation: %s" % (CODEBASES)) parser.add_option("-v", "--velocity-model", type="string", action="store", dest="vmodel", help="Velocity model (region) for this simulation") parser.add_option("--src", "--source", type="string", action="store", dest="source", help="Source description file for the simulation") parser.add_option("--stl", "--station-list", type="string", action="store", dest="station_list", help="Station list file for the simulation") parser.add_option("--srf", "--srf-prefix", type="string", action="store", dest="srf_prefix", help="Prefix of SRF files to use, " "only for GP, SDSU and UCSB methods. " "Simulations begin after the rupture generator.") parser.add_option("-d", "--dir", type="string", action="store", dest="simdir", help="Simulation directory") parser.add_option("--hypo-rand", action="store_true", dest="hyporand", help="Enables hypocenter randomization") parser.add_option("--no-hypo-rand", action="store_false", dest="hyporand", help="Disables hypocenter randomization") parser.add_option("-n", "--num-simulations", type="int", action="store", dest="numsim", help="Number of simulations to run") parser.add_option("--email", type="string", action="store", dest="email", help="Email for job notifications") parser.add_option("-w", "--walltime", type="int", action="store", dest="walltime", help="Number of hours for walltime") parser.add_option("--new-nodes", action="store_true", dest="newnodes", help="Schedule the job in the new HPCC nodes") parser.add_option("--save-tmpdata", action="store_true", dest="savetemp", help="Save the contents of the tmpdata directory") parser.add_option("--hdd-min", type="float", action="store", dest="hdd_min", help="Min value for hypo down dip in randomization") parser.add_option("--hdd-max", type="float", action="store", dest="hdd_max", help="Max value for hypo down dip in randomization") parser.add_option("--has-min", type="float", action="store", dest="has_min", help="Min value for hypo along strike in randomization") parser.add_option("--has-max", type="float", action="store", dest="has_max", help="Max value for hypo along strike in randomization") parser.add_option("--only-rup", action="store_true", dest="only_rup", help="Only runs the rupture generator") parser.add_option("--var", "--variation", type="int", action="store", dest="variation", help="seed variation (default 1)") parser.add_option("--multiseg", action="store_true", dest="multiseg", help="Indicates simulation part of multiseg run") parser.add_option("--first-seg-dir", type="string", action="store", dest="first_seg_dir", help="required for multi-segment segments 2..n") parser.add_option("-s", "--site", action="store_true", dest="site_response", help="Use site response module") (options, _) = parser.parse_args() # Check if using new HPCC nodes if options.newnodes: newnodes = True else: newnodes = False # Check if multi-segment simulation if options.multiseg: multiseg = True else: multiseg = False # Check for first segment directory if options.first_seg_dir is not None: first_seg_dir = os.path.abspath(options.first_seg_dir) if not os.path.exists(first_seg_dir): print("First segment directory for exists: %s" % (first_seg_dir)) sys.exit(1) else: first_seg_dir = None # Check if user specified custom walltime if options.walltime: if options.walltime < 1: print("Walltime must be at least 1 hour!") sys.exit(1) walltime = options.walltime else: if newnodes: walltime = 24 else: walltime = 300 # Check for variation sequence if options.variation: variation = options.variation else: variation = 1 # Check if user wants to save the contents of tmpdata if options.savetemp: savetemp = True else: savetemp = False # Check if user wants to only run the rupture generator if options.only_rup: only_rup = True else: only_rup = False # Validate codebase to use codebase = options.codebase if codebase is None: print "Please specify a codebase!" sys.exit(1) codebase = codebase.lower() if codebase not in CODEBASES: print "Codebase needs to be one of: %s" % (CODEBASES) # Check for velocity model vmodel_names = velocity_models.get_all_names() vmodel = options.vmodel if vmodel is None: print "Please provide a velocity model (region) for this simulation!" print "Available options are: %s" % (vmodel_names) sys.exit(1) vmodels = [v_model.lower() for v_model in vmodel_names] if vmodel.lower() not in vmodels: print ("Velocity model %s does not appear to be available on BBP" % (vmodel)) print ("Available options are: %s" % (vmodel_names)) print "Please provide another velocity model or check your BBP installation." sys.exit(1) # Now get the name with the correct case vmodel = vmodel_names[vmodels.index(vmodel.lower())] # Check if users wants to run site response module if options.site_response: site_response = True if codebase not in CODEBASES_SITE: print "Cannot use site response with method: %s" % (codebase) sys.exit(1) else: site_response = False # Check for hypocenter randomization if options.hyporand is None: print "Please specify --hypo-rand or --no-hypo-rand!" sys.exit(1) if options.hyporand: hypo_rand = True else: hypo_rand = False # Define area where hypocenter will be randomized hypo_area = {} hypo_area["hdd_min"] = options.hdd_min hypo_area["hdd_max"] = options.hdd_max hypo_area["has_min"] = options.has_min hypo_area["has_max"] = options.has_max # Get the source file (SRC or SRFs) source_file = options.source srf_prefix = options.srf_prefix if source_file is None and srf_prefix is None: print ("Please provide either source description (src file) " "or a srf prefix!") sys.exit(1) # If user specified both a source file and a srf prefix, we abort! if source_file is not None and srf_prefix is not None: print "Cannot specify both srf_prefic and source_file!" sys.exit(1) # If user specified a source file if source_file is not None: # Make it a full path source_file = os.path.realpath(source_file) # Make sure source file is in the rcf-104 / scec-00 filesystem if not "rcf-104" in source_file and not "scec-00" in source_file: print "Source file should be in the rcf-104 / scec-00 filesystems!" sys.exit(1) # Make sure source file exists and is readable if (not os.path.isfile(source_file) or not os.access(source_file, os.R_OK)): print "Source file does not seem to be accessible!" sys.exit(1) # Create a prefix prefix = ("%s-%s" % (os.path.splitext(os.path.basename(source_file))[0], codebase.lower())) # If user specified a SRF prefix if srf_prefix is not None: # Make it a full path srf_prefix = os.path.realpath(srf_prefix) # Make sure source file is in the rcf-104 or scec-00 filesystems if not "rcf-104" in srf_prefix and not "scec-00" in srf_prefix: print "SRF files should be in the rcf-104 / scec-00 filesystems!" sys.exit(1) # Create a prefix prefix = os.path.splitext(os.path.basename(srf_prefix))[0] #prefix = prefix.rsplit("-", 1)[0] # Make sure we remove spaces from prefix prefix = prefix.replace(" ", '') # Get the station list station_list = options.station_list if station_list is None: print "Please provide a station list (stl file)!" sys.exit(1) # Make it a full path station_list = os.path.realpath(station_list) # Make sure station list is in the rcf-104 or scec-00 filesystems if not "rcf-104" in station_list and not "scec-00" in station_list: print "Station list should be in the rcf-104 / scec-00 filesystems!" sys.exit(1) # Make sure station list exists and is readable if (not os.path.isfile(station_list) or not os.access(station_list, os.R_OK)): print "Station list foes not seem to be accessible!" sys.exit(1) # Check for the simulation directory simdir = options.simdir if simdir is None: print "Please provide a simulation directory!" sys.exit(1) simdir = os.path.abspath(simdir) if os.path.exists(simdir): print "Simulation directory exists: %s" % (simdir) opt = raw_input("Do you want to delete its contents (y/n)? ") if opt.lower() != "y": print "Please provide another simulation directory!" sys.exit(1) opt = raw_input("ARE YOU SURE (y/n)? ") if opt.lower() != "y": print "Please provide another simulation directory!" sys.exit(1) # Delete existing directory (we already asked the user twice!!!) shutil.rmtree(simdir) # Pick up number of simulations to run numsim = options.numsim if numsim < 1 or numsim > MAX_SIMULATIONS: print ("Number of simulations should be between 1 and %d" % (MAX_SIMULATIONS)) sys.exit(1) # Check for e-mail address email = options.email if email is None: print "Please provide an e-mail address for job notifications" sys.exit(1) # Make sure user has configured the setup_bbp_env.sh script setup_bbp_env = os.path.join(bbp_install.A_INSTALL_ROOT, "utils/batch/setup_bbp_env.sh") if not os.path.exists(setup_bbp_env): print ("Cannot find setup_bbp_env.sh script!") print ("Expected at: %s" % (setup_bbp_env)) sys.exit(1) # Create simulation directories os.makedirs(simdir) indir = os.path.join(simdir, "Sims", "indata") outdir = os.path.join(simdir, "Sims", "outdata") tmpdir = os.path.join(simdir, "Sims", "tmpdata") logsdir = os.path.join(simdir, "Sims", "logs") xmldir = os.path.join(simdir, "Xml") srcdir = os.path.join(simdir, "Src") for mdir in [indir, outdir, tmpdir, logsdir, xmldir, srcdir]: os.makedirs(mdir) if srf_prefix is None: # Generate source files generate_src_files(numsim, source_file, srcdir, prefix, hypo_rand, hypo_area, variation, multiseg, first_seg_dir) # Generate xml files generate_xml(bbp_install, numsim, srcdir, xmldir, logsdir, vmodel, codebase, prefix, station_list, only_rup, srf_prefix, site_response) # Write pbs file write_pbs(bbp_install, numsim, simdir, xmldir, email, prefix, newnodes, walltime, savetemp) # Write .info file info_file = open(os.path.join(simdir, "%s.info" % (prefix)), 'w') info_file.write("# %s\n" % (" ".join(sys.argv))) info_file.close()
def main(): parser = optparse.OptionParser() parser.add_option("-x", "--xml-dir", dest="xmlDir", help="Output folder for XML files", metavar="XML_DIR") parser.add_option("-i", "--in-dir", dest="inDir", help="Input folder with run description files", metavar="IN_DIR") (options, args) = parser.parse_args() if not options.inDir: parser.error("Folder with run description files is required!") if os.path.exists(options.inDir): files = os.listdir(options.inDir) else: print "Invalid input dir: %s" % options.inDir sys.exit(1) if not files: print "No run description files were found in input dir: %s" % inDir sys.exit(1) if not options.xmlDir: cur_dir= os.getcwd() options.xmlDir = os.path.join(cur_dir, "run_xml") print ("Note: Output XML directory was not specified!\n" "XMLs will be written to %s" % options.xmlDir) if not os.path.exists(options.xmlDir): os.mkdir(options.xmlDir) required_keys = ["RUN_TAG", "VALIDATION_RUN", "VMODEL_NAME", "SOURCE_DESCRIPTION_FILE", "STATION_LIST_FILE", "RUPTURE_GENERATOR", "LOW_FREQUENCY_MODULE", "HIGH_FREQUENCY_MODULE", "SITE_RESPONSE_MODULE", "PLOT_VEL", "PLOT_ACC", "RUN_GOF", "GEN_HTML"] cfg = InstallCfg() valid_event = ['y', 'n'] available_vmodels = velocity_models.get_all_names() rupture_gen = ['y', 'n'] rup = ['GP', 'UCSB'] lf = ['GP', 'UCSB'] hf = ['GP', 'UCSB', 'SDSU'] site = ['GP', 'UCSB', 'SDSU', "None"] plotVel = ['y', 'n'] plotAcc = ['y', 'n'] doGof = ['y', 'n'] gof = ['GP', 'SDSU'] genHtml = ['y', 'n'] # Move out all the files we don't need from start dir for file in os.listdir(cfg.A_USER_DATA_DIR): if file.endswith(".srf") or file.endswith(".stl") or file.endswith(".src"): if not os.path.exists("%s/tmp" % cfg.A_USER_DATA_DIR): os.mkdir("%s/tmp" % cfg.A_USER_DATA_DIR) shutil.move("%s/%s" % (cfg.A_USER_DATA_DIR, file), "%s/tmp/%s" % (cfg.A_USER_DATA_DIR, file)) filecount = 0 for file in files: if file.endswith(".txt"): file_base = file[0:file.find(".txt")] #pieces = file_base.split("_") input_config = {} output_files = {} in_file = "%s/%s" % (options.inDir, file) fn = open(in_file, 'r') lines = fn.readlines() if not lines: print "Warning: Skipping empty input file: %s"% file continue for line in lines: key,value = line.strip().split("=") input_config[key.strip()] = value.strip() if not input_config: print "Warning: Skipping malformed input file: %s" % file continue input_keys = input_config.keys() if not set(input_keys) == set(required_keys): print "Warning: Skipping malformed input file: %s" % file print " Missing keys:", list(set(input_keys).symmetric_difference(set(required_keys))) continue valid = True try: simID = input_config["RUN_TAG"] if simID[0] == "0": print "Warning: RUN_TAG cannot start with '0'! RUN_TAG will be left-padded with '1'!" simID ="1%s" % simID simID = int(simID) except ValueError: print "Invalid value for RUN_TAG: %s, Integer value expected!" % input_config["RUN_TAG"] valid = False validation = input_config["VALIDATION_RUN"] if not validation in valid_event: print ("Invalid option for VALIDATION_RUN: %s, Expected: %s" % (validation, str(valid_event))) valid = False vel_model = input_config["VMODEL_NAME"] if not vel_model in available_vmodels: print ("Velocity model %s not available in the platform!" % (vel_model)) print available_vmodels valid = False if validation =='n': r_gen = input_config["RUPTURE_GENERATOR"] if not r_gen in rup: print "Invalid option for RUPTURE_GENERATOR: %s, Expected: %s" % (r_gen, str(rup)) valid = False rupture_generator = 'n' else: r_gen = rup.index(r_gen) +1 rupture_generator = 'y' lfm = input_config["LOW_FREQUENCY_MODULE"] if not lfm in lf: print "Invalid option for LOW_FREQUENCY_MODULE: %s, Expected: %s" % (lfm, str(lf)) valid = False else: lfm = lf.index(lfm) +1 hfm = input_config["HIGH_FREQUENCY_MODULE"] if not hfm in hf: print "Invalid option for HIGH_FREQUENCY_MODULE: %s, Expected: %s" % (hfm, str(hf)) valid = False else: hfm = hf.index(hfm) +1 srm = input_config["SITE_RESPONSE_MODULE"] if not srm in site: print "Invalid option for SITE_RESPONSE_MODULE: %s, Expected: %s"%(srm, str(site)) valid = False else: srm = site.index(srm) +1 plt_vel = input_config["PLOT_VEL"] if not validation in plotVel: print "Invalid option for PLOT_VEL: %s, Expected: %s"% (plt_vel, str(plotVel)) valid = False plt_acc= input_config["PLOT_ACC"] if not validation in plotAcc: print ("Invalid option for PLOT_ACC: %s, Expected: %s" % (plt_acc, str(plotAcc))) valid = False gof_opt = input_config["RUN_GOF"] if not validation in doGof: print ("Invalid option for RUN_GOF: %s, Expected: %s" % (gof_opt, str(doGof))) valid = False gen_html = input_config["GEN_HTML"] if not gen_html in genHtml: print ("Invalid option for GEN_HTML: %s, Expected: %s" % (gen_html, str(genHtml))) valid = False src_file = os.path.abspath(input_config["SOURCE_DESCRIPTION_FILE"]) if not os.path.exists(src_file): print "Unable to locate specified source file: %s" % src_file valid = False stat_file = os.path.abspath(input_config["STATION_LIST_FILE"]) if not os.path.exists(stat_file): print "Unable to locate stations file: %s" % stat_file valid = False if not valid: print "Skipping input file %s due to previous errors!" % file continue # Generate an options file optfilename = "%s/%s_%s.txt" % (options.xmlDir, str(simID), file_base) print "Generating options file %s" % optfilename fp = open(optfilename, 'w') fp.write("%s\n" % validation) fp.write("%s\n" % vel_model) fp.write("%s\n" % rupture_generator) if rupture_generator == 'y': fp.write("%d\n" % r_gen) fp.write("2\n") # Enter path to source file fp.write("%s\n" % (src_file)) else: # Need to write a path to a srf file pass fp.write("%d\n" % lfm) fp.write("2\n") # Enter path to station list fp.write("%s\n" % (stat_file)) fp.write("%d\n" % hfm) fp.write("%d\n" % srm) fp.write("%s\n" % plt_vel) fp.write("%s\n" % plt_acc) fp.write("%s\n" % gof_opt) if gof_opt == 'y': fp.write("1\n") #defualt to GP GOF module for now! fp.write("%s\n" % gen_html) fp.flush() fp.close() #copy src and stl files to start dir #shutil.copy2(src_file, "%s" % cfg.A_USER_DATA_DIR) #shutil.copy2(stat_file, "%s" % cfg.A_USER_DATA_DIR) #move bpp dirs with simID indatadir = "%s/%d" % (cfg.A_IN_DATA_DIR, simID) outdatadir = "%s/%d" % (cfg.A_OUT_DATA_DIR, simID) tmpdatadir = "%s/%d" % (cfg.A_TMP_DATA_DIR, simID) logdir = "%s/%d" % (cfg.A_OUT_LOG_DIR, simID) if os.path.exists(indatadir): shutil.move(indatadir, "%s_%s" % (indatadir, "bkp")) if os.path.exists(tmpdatadir): shutil.move(tmpdatadir, "%s_%s" % (tmpdatadir, "bkp")) if os.path.exists(outdatadir): shutil.move(outdatadir, "%s_%s" % (outdatadir, "bkp")) if os.path.exists(logdir): shutil.move(logdir, "%s_%s" % (logdir, "bkp")) #Generate XML #bband_utils.runprog("%s/run_bbp.py -o %s -s %d" % (cfg.A_COMP_DIR, filename, simID)) bband_utils.runprog("%s/run_bbp.py -o %s -s %d -g" % (cfg.A_COMP_DIR, optfilename, simID)) outdir = "%s/%d" % (cfg.A_OUT_DATA_DIR, simID) #Remove option file os.remove(optfilename) #Remove src and stl files from start dir #os.remove("%s/%s" % (cfg.A_USER_DATA_DIR, os.path.basename(src_file))) #os.remove("%s/%s" % (cfg.A_USER_DATA_DIR, os.path.basename(stat_file))) #move back bpp dirs with simID if os.path.exists("%s_%s" % (indatadir, "bkp")): shutil.move("%s_%s" % (indatadir, "bkp"), indatadir) else: shutil.rmtree(indatadir) if os.path.exists("%s_%s" % (tmpdatadir, "bkp")): shutil.move("%s_%s" % (tmpdatadir, "bkp"), tmpdatadir) else: shutil.rmtree(tmpdatadir) if os.path.exists("%s_%s" % (outdatadir, "bkp")): shutil.move("%s_%s" % (outdatadir, "bkp"), outdatadir) else: shutil.rmtree(outdatadir) if os.path.exists("%s_%s" % (logdir, "bkp")): shutil.move("%s_%s" % (logdir, "bkp"), logdir) else: shutil.rmtree(logdir) #Copy xml to xmlDir xmlfilename = "%s/%d_%s.xml" % (options.xmlDir, simID, file_base) if not os.path.exists("%s/%d.xml" % (cfg.A_XML_DIR, simID)): print "Failed to generate XML file for %s" % file continue shutil.copy2("%s/%d.xml" % (cfg.A_XML_DIR, simID), xmlfilename) #Fix path in XML file # xfn = open(xmlfilename, 'r') # xlines = xfn.readlines() # xfn.close() # # xfn=open(xmlfilename, 'w') # src_file_base = os.path.basename(src_file) # stat_file_base = os.path.basename(stat_file) # old_src_line = "$BBP_INSTALL/start/%s" % src_file_base # old_stat_line = "$BBP_INSTALL/start/%s" % stat_file_base # for xline in xlines: # if xline.strip().startswith(old_src_line): # xfn.write(xline.replace(old_src_line,src_file)) # elif xline.strip().startswith(old_stat_line): # xfn.write(xline.replace(old_stat_line,stat_file)) # else: # xfn.write(xline) # # xfn.flush() # xfn.close() filecount +=1 print "Processed %d files, skipped %d files!" % (filecount, len(files) - filecount)
def main(): """ Parse command line options and create the needed files/directories """ # Detect BBP installation bbp_install = InstallCfg.getInstance() prog_base = os.path.basename(sys.argv[0]) usage = "usage: %s [options]" % (prog_base) parser = optparse.OptionParser(usage) parser.add_option("-c", "--codebase", type="string", action="store", dest="codebase", help="Codebase for the simulation: %s" % (CODEBASES)) parser.add_option("-v", "--velocity-model", type="string", action="store", dest="vmodel", help="Velocity model (region) for this simulation") parser.add_option("--src", "--source", type="string", action="store", dest="source", help="Source description file for the simulation") parser.add_option("--stl", "--station-list", type="string", action="store", dest="station_list", help="Station list file for the simulation") parser.add_option("--srf", "--srf-prefix", type="string", action="store", dest="srf_prefix", help="Prefix of SRF files to use, " "only for GP, SDSU and UCSB methods. " "Simulations begin after the rupture generator.") parser.add_option("-d", "--dir", type="string", action="store", dest="simdir", help="Simulation directory") parser.add_option("--hypo-rand", action="store_true", dest="hyporand", help="Enables hypocenter randomization") parser.add_option("--no-hypo-rand", action="store_false", dest="hyporand", help="Disables hypocenter randomization") parser.add_option("-n", "--num-simulations", type="int", action="store", dest="numsim", help="Number of simulations to run") parser.add_option("--email", type="string", action="store", dest="email", help="Email for job notifications") parser.add_option("-w", "--walltime", type="int", action="store", dest="walltime", help="Number of hours for walltime") parser.add_option("--new-nodes", action="store_true", dest="newnodes", help="Schedule the job in the new HPCC nodes") parser.add_option("--save-tmpdata", action="store_true", dest="savetemp", help="Save the contents of the tmpdata directory") parser.add_option("--hdd-min", type="float", action="store", dest="hdd_min", help="Min value for hypo down dip in randomization") parser.add_option("--hdd-max", type="float", action="store", dest="hdd_max", help="Max value for hypo down dip in randomization") parser.add_option("--has-min", type="float", action="store", dest="has_min", help="Min value for hypo along strike in randomization") parser.add_option("--has-max", type="float", action="store", dest="has_max", help="Max value for hypo along strike in randomization") parser.add_option("--only-rup", action="store_true", dest="only_rup", help="Only runs the rupture generator") parser.add_option("--var", "--variation", type="int", action="store", dest="variation", help="seed variation (default 1)") parser.add_option("--multiseg", action="store_true", dest="multiseg", help="Indicates simulation part of multiseg run") parser.add_option("--first-seg-dir", type="string", action="store", dest="first_seg_dir", help="required for multi-segment segments 2..n") parser.add_option("-s", "--site", action="store_true", dest="site_response", help="Use site response module") (options, _) = parser.parse_args() # Check if using new HPCC nodes if options.newnodes: newnodes = True else: newnodes = False # Check if multi-segment simulation if options.multiseg: multiseg = True else: multiseg = False # Check for first segment directory if options.first_seg_dir is not None: first_seg_dir = os.path.abspath(options.first_seg_dir) if not os.path.exists(first_seg_dir): print("First segment directory for exists: %s" % (first_seg_dir)) sys.exit(1) else: first_seg_dir = None # Check if user specified custom walltime if options.walltime: if options.walltime < 1: print("Walltime must be at least 1 hour!") sys.exit(1) walltime = options.walltime else: if newnodes: walltime = 24 else: walltime = 300 # Check for variation sequence if options.variation: variation = options.variation else: variation = 1 # Check if user wants to save the contents of tmpdata if options.savetemp: savetemp = True else: savetemp = False # Check if user wants to only run the rupture generator if options.only_rup: only_rup = True else: only_rup = False # Validate codebase to use codebase = options.codebase if codebase is None: print "Please specify a codebase!" sys.exit(1) codebase = codebase.lower() if codebase not in CODEBASES: print "Codebase needs to be one of: %s" % (CODEBASES) # Check for velocity model vmodel_names = velocity_models.get_all_names() vmodel = options.vmodel if vmodel is None: print "Please provide a velocity model (region) for this simulation!" print "Available options are: %s" % (vmodel_names) sys.exit(1) vmodels = [v_model.lower() for v_model in vmodel_names] if vmodel.lower() not in vmodels: print("Velocity model %s does not appear to be available on BBP" % (vmodel)) print("Available options are: %s" % (vmodel_names)) print "Please provide another velocity model or check your BBP installation." sys.exit(1) # Now get the name with the correct case vmodel = vmodel_names[vmodels.index(vmodel.lower())] # Check if users wants to run site response module if options.site_response: site_response = True if codebase not in CODEBASES_SITE: print "Cannot use site response with method: %s" % (codebase) sys.exit(1) else: site_response = False # Check for hypocenter randomization if options.hyporand is None: print "Please specify --hypo-rand or --no-hypo-rand!" sys.exit(1) if options.hyporand: hypo_rand = True else: hypo_rand = False # Define area where hypocenter will be randomized hypo_area = {} hypo_area["hdd_min"] = options.hdd_min hypo_area["hdd_max"] = options.hdd_max hypo_area["has_min"] = options.has_min hypo_area["has_max"] = options.has_max # Get the source file (SRC or SRFs) source_file = options.source srf_prefix = options.srf_prefix if source_file is None and srf_prefix is None: print( "Please provide either source description (src file) " "or a srf prefix!") sys.exit(1) # If user specified both a source file and a srf prefix, we abort! if source_file is not None and srf_prefix is not None: print "Cannot specify both srf_prefic and source_file!" sys.exit(1) # If user specified a source file if source_file is not None: # Make it a full path source_file = os.path.realpath(source_file) # Make sure source file is in the rcf-104 / scec-00 filesystem if not "rcf-104" in source_file and not "scec-00" in source_file: print "Source file should be in the rcf-104 / scec-00 filesystems!" sys.exit(1) # Make sure source file exists and is readable if (not os.path.isfile(source_file) or not os.access(source_file, os.R_OK)): print "Source file does not seem to be accessible!" sys.exit(1) # Create a prefix prefix = ("%s-%s" % (os.path.splitext( os.path.basename(source_file))[0], codebase.lower())) # If user specified a SRF prefix if srf_prefix is not None: # Make it a full path srf_prefix = os.path.realpath(srf_prefix) # Make sure source file is in the rcf-104 or scec-00 filesystems if not "rcf-104" in srf_prefix and not "scec-00" in srf_prefix: print "SRF files should be in the rcf-104 / scec-00 filesystems!" sys.exit(1) # Create a prefix prefix = os.path.splitext(os.path.basename(srf_prefix))[0] #prefix = prefix.rsplit("-", 1)[0] # Make sure we remove spaces from prefix prefix = prefix.replace(" ", '') # Get the station list station_list = options.station_list if station_list is None: print "Please provide a station list (stl file)!" sys.exit(1) # Make it a full path station_list = os.path.realpath(station_list) # Make sure station list is in the rcf-104 or scec-00 filesystems if not "rcf-104" in station_list and not "scec-00" in station_list: print "Station list should be in the rcf-104 / scec-00 filesystems!" sys.exit(1) # Make sure station list exists and is readable if (not os.path.isfile(station_list) or not os.access(station_list, os.R_OK)): print "Station list foes not seem to be accessible!" sys.exit(1) # Check for the simulation directory simdir = options.simdir if simdir is None: print "Please provide a simulation directory!" sys.exit(1) simdir = os.path.abspath(simdir) if os.path.exists(simdir): print "Simulation directory exists: %s" % (simdir) opt = raw_input("Do you want to delete its contents (y/n)? ") if opt.lower() != "y": print "Please provide another simulation directory!" sys.exit(1) opt = raw_input("ARE YOU SURE (y/n)? ") if opt.lower() != "y": print "Please provide another simulation directory!" sys.exit(1) # Delete existing directory (we already asked the user twice!!!) shutil.rmtree(simdir) # Pick up number of simulations to run numsim = options.numsim if numsim < 1 or numsim > MAX_SIMULATIONS: print("Number of simulations should be between 1 and %d" % (MAX_SIMULATIONS)) sys.exit(1) # Check for e-mail address email = options.email if email is None: print "Please provide an e-mail address for job notifications" sys.exit(1) # Make sure user has configured the setup_bbp_env.sh script setup_bbp_env = os.path.join(bbp_install.A_INSTALL_ROOT, "utils/batch/setup_bbp_env.sh") if not os.path.exists(setup_bbp_env): print("Cannot find setup_bbp_env.sh script!") print("Expected at: %s" % (setup_bbp_env)) sys.exit(1) # Create simulation directories os.makedirs(simdir) indir = os.path.join(simdir, "Sims", "indata") outdir = os.path.join(simdir, "Sims", "outdata") tmpdir = os.path.join(simdir, "Sims", "tmpdata") logsdir = os.path.join(simdir, "Sims", "logs") xmldir = os.path.join(simdir, "Xml") srcdir = os.path.join(simdir, "Src") for mdir in [indir, outdir, tmpdir, logsdir, xmldir, srcdir]: os.makedirs(mdir) if srf_prefix is None: # Generate source files generate_src_files(numsim, source_file, srcdir, prefix, hypo_rand, hypo_area, variation, multiseg, first_seg_dir) # Generate xml files generate_xml(bbp_install, numsim, srcdir, xmldir, logsdir, vmodel, codebase, prefix, station_list, only_rup, srf_prefix, site_response) # Write pbs file write_pbs(bbp_install, numsim, simdir, xmldir, email, prefix, newnodes, walltime, savetemp) # Write .info file info_file = open(os.path.join(simdir, "%s.info" % (prefix)), 'w') info_file.write("# %s\n" % (" ".join(sys.argv))) info_file.close()
def main(): """ Parse command line options and create the needed files/directories """ # Detect BBP installation bbp_install = InstallCfg.getInstance() prog_base = os.path.basename(sys.argv[0]) usage = "usage: %s [options]" % (prog_base) parser = optparse.OptionParser(usage) parser.add_option("-c", "--codebase", type="string", action="store", dest="codebase", help="Codebase for the simulation: %s" % (CODEBASES)) parser.add_option("-v", "--velocity-model", type="string", action="store", dest="vmodel", help="Velocity model (region) for this simulation") parser.add_option("--src", "--source", type="string", action="store", dest="source", help="Source description file for the simulation") parser.add_option("--stl", "--station-list", type="string", action="store", dest="station_list", help="Station list file for the simulation") parser.add_option("-d", "--dir", type="string", action="store", dest="simdir", help="Simulation directory") parser.add_option("-n", "--num-stations", type="int", action="store", dest="numsta", help="Number of stations per run") parser.add_option("--seed", type="int", action="store", dest="new_seed", help="Overrides seed in SRC file") parser.add_option("--email", type="string", action="store", dest="email", help="Email for job notifications") parser.add_option("--new-nodes", action="store_true", dest="newnodes", help="Schedule the job in the new HPCC nodes") parser.add_option("--no-site-response", action="store_true", dest="nosite", help="Disable the site response module for GP/SDSU/UCSB") (options, _) = parser.parse_args() # Check if using new HPCC nodes if options.newnodes: newnodes = True else: newnodes = False # Check if not using site response if options.nosite: nosite = True else: nosite = False # Validate codebase to use codebase = options.codebase if codebase is None: print "Please specify a codebase!" sys.exit(1) codebase = codebase.lower() if codebase not in CODEBASES: print "Codebase needs to be one of: %s" % (CODEBASES) # Check for velocity model vmodel_names = velocity_models.get_all_names() vmodel = options.vmodel if vmodel is None: print "Please provide a velocity model (region) for this simulation!" print "Available options are: %s" % (vmodel_names) sys.exit(1) vmodels = [v_model.lower() for v_model in vmodel_names] if vmodel.lower() not in vmodels: print ("Velocity model %s does not appear to be available on BBP" % (vmodel)) print ("Available options are: %s" % (vmodel_names)) print "Please provide another velocity model or check your BBP installation." sys.exit(1) # Now get the name with the correct case vmodel = vmodel_names[vmodels.index(vmodel.lower())] # Get the source file source_file = options.source if source_file is None: print "Please provide a source description (src file)!" sys.exit(1) # Make it a full path source_file = os.path.realpath(source_file) # Make sure source file is in the rcf-104 filesystem if not "rcf-104" in source_file: print "Source file should be in the rcf-104 filesystem!" sys.exit(1) # Make sure source file exists and is readable if not os.path.isfile(source_file) or not os.access(source_file, os.R_OK): print "Source file does not seem to be accessible!" sys.exit(1) # Get the station list station_list = options.station_list if station_list is None: print "Please provide a station list (stl file)!" sys.exit(1) # Make it a full path station_list = os.path.realpath(station_list) # Make sure station list is in the rcf-104 filesystem if not "rcf-104" in station_list: print "Station list should be in the rcf-104 filesystem!" sys.exit(1) # Make sure station list exists and is readable if not os.path.isfile(station_list) or not os.access(station_list, os.R_OK): print "Station list foes not seem to be accessible!" sys.exit(1) # Check for the simulation directory simdir = options.simdir if simdir is None: print "Please provide a simulation directory!" sys.exit(1) simdir = os.path.abspath(simdir) if os.path.exists(simdir): print "Simulation directory exists: %s" % (simdir) opt = raw_input("Do you want to delete its contents (y/n)? ") if opt.lower() != "y": print "Please provide another simulation directory!" sys.exit(1) opt = raw_input("ARE YOU SURE (y/n)? ") if opt.lower() != "y": print "Please provide another simulation directory!" sys.exit(1) # Delete existing directory (we already asked the user twice!!!) shutil.rmtree(simdir) # Pick up number of simulations to run numsta = options.numsta if numsta < 1: print ("Number of stations should be greater than 0") sys.exit(1) # Check for user-provided seed for this simulation new_seed = options.new_seed # Check for e-mail address email = options.email if email is None: print "Please provide an e-mail address for job notifications" sys.exit(1) # Make sure user has configured the setup_bbp_env.sh script setup_bbp_env = os.path.join(bbp_install.A_INSTALL_ROOT, "utils/batch/setup_bbp_env.sh") if not os.path.exists(setup_bbp_env): print ("Cannot find setup_bbp_env.sh script!") print ("Expected at: %s" % (setup_bbp_env)) sys.exit(1) # Create simulation directories prefix = "%s-%s" % (os.path.splitext(os.path.basename(source_file))[0], codebase.lower()) # Make sure we remove spaces from prefix prefix = prefix.replace(" ", '') os.makedirs(simdir) indir = os.path.join(simdir, "Sims", "indata") outdir = os.path.join(simdir, "Sims", "outdata") tmpdir = os.path.join(simdir, "Sims", "tmpdata") logsdir = os.path.join(simdir, "Sims", "logs") xmldir = os.path.join(simdir, "Xml") srcdir = os.path.join(simdir, "Src") stldir = os.path.join(simdir, "Stl") for mdir in [indir, outdir, tmpdir, logsdir, xmldir, srcdir, stldir]: os.makedirs(mdir) # Generate station lists numsim, stlbase = generate_stl_files(station_list, numsta, stldir) if numsim > MAX_SIMULATIONS: print "Too many simulations requested!" print "Maximum number allowed is %d!" % (MAX_SIMULATIONS) print "Try requesting more stations per simulation..." sys.exit(1) # Generate source files generate_src_files(numsim, source_file, srcdir, prefix, new_seed) # Generate xml files generate_xml(bbp_install, numsim, srcdir, xmldir, logsdir, vmodel, codebase, prefix, stlbase, nosite) # Write pbs file write_pbs(bbp_install, numsim, simdir, xmldir, email, prefix, newnodes)
def main(): """ Parse command line options and create the needed files/directories """ # Detect BBP installation bbp_install = InstallCfg.getInstance() prog_base = os.path.basename(sys.argv[0]) usage = "usage: %s [options]" % (prog_base) parser = optparse.OptionParser(usage) parser.add_option("-c", "--codebase", type="string", action="store", dest="codebase", help="Codebase for the simulation: %s" % (CODEBASES)) parser.add_option("-v", "--velocity-model", type="string", action="store", dest="vmodel", help="Velocity model (region) for this simulation") parser.add_option("--src", "--source", type="string", action="store", dest="source", help="Source description file for the simulation") parser.add_option("--stl", "--station-list", type="string", action="store", dest="station_list", help="Station list file for the simulation") parser.add_option("-d", "--dir", type="string", action="store", dest="simdir", help="Simulation directory") parser.add_option("--hypo-rand", action="store_true", dest="hyporand", help="Enables hypocenter randomization") parser.add_option("--no-hypo-rand", action="store_false", dest="hyporand", help="Disables hypocenter randomization") parser.add_option("-n", "--num-simulations", type="int", action="store", dest="numsim", help="Number of simulations to run") parser.add_option("--email", type="string", action="store", dest="email", help="Email for job notifications") (options, _) = parser.parse_args() # Validate codebase to use codebase = options.codebase if codebase is None: print "Please specify a codebase!" sys.exit(1) codebase = codebase.lower() if codebase not in CODEBASES: print "Codebase needs to be one of: %s" % (CODEBASES) # Check for velocity model vmodel_names = velocity_models.get_all_names() vmodel = options.vmodel if vmodel is None: print "Please provide a velocity model (region) for this simulation!" print "Available options are: %s" % (vmodel_names) sys.exit(1) vmodels = [v_model.lower() for v_model in vmodel_names] if vmodel.lower() not in vmodels: print("Velocity model %s does not appear to be available on BBP" % (vmodel)) print("Available options are: %s" % (vmodel_names)) print "Please provide another velocity model or check your BBP installation." sys.exit(1) # Now get the name with the correct case vmodel = vmodel_names[vmodels.index(vmodel.lower())] # Check for hypocenter randomization if options.hyporand is None: print "Please specify --hypo-rand or --no-hypo-rand!" sys.exit(1) if options.hyporand: hypo_rand = True else: hypo_rand = False # Get the source file source_file = options.source if source_file is None: print "Please provide a source description (src file)!" sys.exit(1) # Make it a full path source_file = os.path.realpath(source_file) # Make sure source file exists and is readable if not os.path.isfile(source_file) or not os.access(source_file, os.R_OK): print "Source file does not seem to be accessible!" sys.exit(1) # Get the station list station_list = options.station_list if station_list is None: print "Please provide a station list (stl file)!" sys.exit(1) # Make it a full path station_list = os.path.realpath(station_list) # Make sure station list exists and is readable if not os.path.isfile(station_list) or not os.access( station_list, os.R_OK): print "Station list foes not seem to be accessible!" sys.exit(1) # Check for the simulation directory simdir = options.simdir if simdir is None: print "Please provide a simulation directory!" sys.exit(1) simdir = os.path.abspath(simdir) if os.path.exists(simdir): print "Simulation directory exists: %s" % (simdir) opt = raw_input("Do you want to delete its contents (y/n)? ") if opt.lower() != "y": print "Please provide another simulation directory!" sys.exit(1) opt = raw_input("ARE YOU SURE (y/n)? ") if opt.lower() != "y": print "Please provide another simulation directory!" sys.exit(1) # Delete existing directory (we already asked the user twice!!!) shutil.rmtree(simdir) # Pick up number of simulations to run numsim = options.numsim if numsim < 1 or numsim > MAX_SIMULATIONS: print("Number of simulations should be between 1 and %d" % (MAX_SIMULATIONS)) sys.exit(1) # Check for e-mail address email = options.email if email is None: print "Please provide an e-mail address for job notifications" sys.exit(1) # Make sure user has configured the setup_bbp_epicenter_env.sh script setup_bbp_env = os.path.join(bbp_install.A_INSTALL_ROOT, "utils/batch/setup_bbp_epicenter_env.sh") if not os.path.exists(setup_bbp_env): print("Cannot find setup_bbp_epicenter_env.sh script!") print("Expected at: %s" % (setup_bbp_env)) sys.exit(1) # Create simulation directories prefix = "%s-%s" % (os.path.splitext( os.path.basename(source_file))[0], codebase.lower()) # Make sure we remove spaces from prefix prefix = prefix.replace(" ", '') os.makedirs(simdir) indir = os.path.join(simdir, "Sims", "indata") outdir = os.path.join(simdir, "Sims", "outdata") tmpdir = os.path.join(simdir, "Sims", "tmpdata") logsdir = os.path.join(simdir, "Sims", "logs") xmldir = os.path.join(simdir, "Xml") srcdir = os.path.join(simdir, "Src") for mdir in [indir, outdir, tmpdir, logsdir, xmldir, srcdir]: os.makedirs(mdir) # Generate source files generate_src_files(numsim, source_file, srcdir, prefix, hypo_rand) # Generate xml files generate_xml(bbp_install, numsim, srcdir, xmldir, logsdir, vmodel, codebase, prefix, station_list) # Write pbs file write_pbs(bbp_install, numsim, simdir, xmldir, email, prefix)