Skip to content

Commit 2fcefec

Browse files
committed
Added options for user-specified src file and station list
1 parent e27f7b5 commit 2fcefec

1 file changed

Lines changed: 52 additions & 10 deletions

File tree

‎bbp/utils/batch/bbp_quakeworx_validation.py‎

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
BSD 3-Clause License
44
5-
Copyright (c) 2025, University of Southern California
5+
Copyright (c) 2026, University of Southern California
66
All rights reserved.
77
88
Redistribution and use in source and binary forms, with or without
@@ -200,7 +200,7 @@ def generate_xml(install, numsim, srcdir, xmldir,
200200
skip_rupgen, srf_prefix, only_rup,
201201
gmpe_group_name, allmetrics,
202202
site_response, multiseg, segment,
203-
source_file, fasgof):
203+
source_file, fasgof, station_list=None):
204204
"""
205205
Generates xml files in the xmldir for numsim simulations whose
206206
source files are in the srcdir using the validation event and
@@ -252,7 +252,13 @@ def generate_xml(install, numsim, srcdir, xmldir,
252252
optfile.write('n\n') # Skip rupture generator
253253
else:
254254
optfile.write('y\n') # Run rupture generator
255-
optfile.write('1\n') # All validation stations
255+
if station_list is None:
256+
optfile.write('1\n') # All validation stations
257+
else:
258+
# Use provided station list instead
259+
optfile.write('2\n') # Custom list
260+
optfile.write('2\n') # Enter path to station file
261+
optfile.write('%s\n' % (station_list)) # STL file
256262
if skip_rupgen:
257263
# We should provide SRF file
258264
optfile.write('2\n') # Enter path to src/srf file
@@ -390,6 +396,14 @@ def main():
390396
help="Use a site response module: %s" % (SITE_MODULES))
391397
parser.add_option("--fas", action="store_true", dest="fasgof",
392398
help="Run both FAS and PSA validations")
399+
parser.add_option("--src", "--source", type="string", action="store",
400+
dest="source",
401+
help="Use this source description file instead of the one "
402+
"provided in the validation package")
403+
parser.add_option("--stl", "--station-list", type="string", action="store",
404+
dest="station_list",
405+
help="Use this station list file instead of the one "
406+
"provided in the validation package")
393407

394408
(options, args) = parser.parse_args()
395409

@@ -499,12 +513,27 @@ def main():
499513
else:
500514
hypo_rand = False
501515

502-
try:
503-
source_file = val_obj.get_input(codebase, "source")
504-
except KeyError:
505-
print("Unable to get source file for event %s, codebase %s!" %
506-
(event, codebase))
507-
sys.exit(1)
516+
# Check if user provided a custom SRC file for this run
517+
source_file = options.source
518+
if source_file is not None:
519+
# Got a file from the user, parse the input
520+
521+
# First, we make a list
522+
pieces = source_file.split(",")
523+
pieces = [piece.strip() for piece in pieces]
524+
525+
# Check if single file or list of files
526+
if len(pieces) == 1:
527+
source_file = pieces[0]
528+
else:
529+
source_file = pieces
530+
else:
531+
try:
532+
source_file = val_obj.get_input(codebase, "source")
533+
except KeyError:
534+
print("Unable to get source file for event %s, codebase %s!" %
535+
(event, codebase))
536+
sys.exit(1)
508537
if not source_file:
509538
print("Source file for event %s, codebase %s not specified!" %
510539
(event, codebase))
@@ -587,6 +616,18 @@ def main():
587616
gmpe_group_index = gmpe_groups_available_lc.index(gmpe_group_name.lower())
588617
gmpe_group_name = gmpe_groups_available[gmpe_group_index]
589618

619+
# Check for user-provided station list
620+
station_list = options.station_list
621+
if station_list is not None:
622+
# Custom station list provided by the user
623+
# Make it a full path
624+
station_list = os.path.realpath(station_list)
625+
# Make sure station list exists and is readable
626+
if (not os.path.isfile(station_list) or
627+
not os.access(station_list, os.R_OK)):
628+
print("Station list does not seem to be accessible!")
629+
sys.exit(1)
630+
590631
# Make sure user has configured the setup_bbp_env.sh script
591632
setup_bbp_env = os.path.join(bbp_install.A_INSTALL_ROOT,
592633
"utils/batch/setup_bbp_env.sh")
@@ -622,7 +663,8 @@ def main():
622663
logsdir, event, codebase, prefix,
623664
skip_rupgen, srf_prefix, only_rup,
624665
gmpe_group_name, allmetrics, site_response,
625-
multiseg, segment, source_file, fasgof)
666+
multiseg, segment, source_file, fasgof,
667+
station_list)
626668

627669
# Write .info file
628670
info_file = open(os.path.join(simdir, "%s.info" % (prefix)), 'w')

0 commit comments

Comments
 (0)