Skip to content

Commit 5d8d230

Browse files
committed
Added flags to fas.py to enable user to select output, removed redundant output files from fas_seas_gof.py
1 parent a93468b commit 5d8d230

13 files changed

Lines changed: 43 additions & 3914 deletions

gmsvtoolkit/metrics/fas.py

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def compute_fas(acc1, acc2, dt):
105105
def compute_station_fas(a_tmpdir, a_outdir_fas, acc_file,
106106
station_name, output_prefix,
107107
input_unit="cm/s/s", output_unit="cm/s/s",
108-
logfile=None):
108+
output_mode="both", logfile=None):
109109
"""
110110
Computes FAS for a station
111111
"""
@@ -127,26 +127,28 @@ def compute_station_fas(a_tmpdir, a_outdir_fas, acc_file,
127127
seas_freq, seas] = compute_fas(acc1, acc2, dt)
128128

129129
# Write file with FAS/EAS first
130-
output_basename = "%s.eas.fs.col" % (output_prefix)
131-
output_filename = os.path.join(a_outdir_fas, output_basename)
132-
output_file = open(output_filename, 'w')
133-
output_file.write("# Freq(Hz) FAS H1 (%s) FAS H2 (%s) EAS (%s)\n" %
134-
(output_unit, output_unit, output_unit))
135-
for f0, f1, f2, e0 in zip(fas_freq, fas_1, fas_2, eas):
136-
output_file.write("%2.7E\t%2.7E\t%2.7E\t%2.7E\n" %
137-
(f0, f1, f2, e0))
138-
output_file.close()
130+
if output_mode == "both" or output_mode == "fas":
131+
output_basename = "%s.eas.fs.col" % (output_prefix)
132+
output_filename = os.path.join(a_outdir_fas, output_basename)
133+
output_file = open(output_filename, 'w')
134+
output_file.write("# Freq(Hz) FAS H1 (%s) FAS H2 (%s) EAS (%s)\n" %
135+
(output_unit, output_unit, output_unit))
136+
for f0, f1, f2, e0 in zip(fas_freq, fas_1, fas_2, eas):
137+
output_file.write("%2.7E\t%2.7E\t%2.7E\t%2.7E\n" %
138+
(f0, f1, f2, e0))
139+
output_file.close()
139140

140141
# Now, we write the file with the SEAS
141-
output_basename = "%s.seas.fs.col" % (output_prefix)
142-
output_filename = os.path.join(a_outdir_fas, output_basename)
143-
output_file = open(output_filename, 'w')
144-
output_file.write("# Freq(Hz) Smoothed EAS (%s) b=%3.4f\n" %
145-
(output_unit, B_PARAM))
146-
for f0, s0 in zip(seas_freq, seas):
147-
output_file.write("%2.7E\t%2.7E\n" %
148-
(f0, s0))
149-
output_file.close()
142+
if output_mode == "both" or output_mode == "seas":
143+
output_basename = "%s.seas.fs.col" % (output_prefix)
144+
output_filename = os.path.join(a_outdir_fas, output_basename)
145+
output_file = open(output_filename, 'w')
146+
output_file.write("# Freq(Hz) Smoothed EAS (%s) b=%3.4f\n" %
147+
(output_unit, B_PARAM))
148+
for f0, s0 in zip(seas_freq, seas):
149+
output_file.write("%2.7E\t%2.7E\n" %
150+
(f0, s0))
151+
output_file.close()
150152

151153
class FAS(object):
152154
"""
@@ -177,6 +179,10 @@ def parse_arguments(self):
177179
help="input units: (g or cm/s/s)")
178180
parser.add_argument("--output-unit", dest="output_unit", default="cm/s/s",
179181
help="output units: (g or cm/s/s)")
182+
parser.add_argument("--fas-only", dest="fas_only", action="store_true",
183+
help="outputs only the FAS/EAS file, default is both FAS/EAS and SEAS files")
184+
parser.add_argument("--seas-only", dest="seas_only", action="store_true",
185+
help="outputs only the SEAS file, default is both FAS/EAS and SEAS files")
180186
parser.add_argument('input_dirs', nargs='*')
181187

182188
args = parser.parse_args()
@@ -198,6 +204,17 @@ def run(self):
198204
logfile = os.path.abspath(args.logfile)
199205
station_file = os.path.abspath(args.station_list)
200206

207+
# Find what users want to output
208+
if args.fas_only and args.seas_only:
209+
print("[ERROR]: Specify only one of --fas-only and --seas-only")
210+
sys.exit(-1)
211+
output_mode = "both"
212+
if args.fas_only:
213+
output_mode = "fas"
214+
if args.seas_only:
215+
output_mode = "seas"
216+
217+
# Figure out units
201218
input_unit = args.input_unit.lower()
202219
output_unit = args.output_unit.lower()
203220
if input_unit != "g" and input_unit != "cm/s/s":
@@ -221,11 +238,12 @@ def run(self):
221238
self.run_fas_seas(station_file, input_dirs, labels,
222239
output_dir, input_unit=input_unit,
223240
output_unit=output_unit,
241+
output_mode=output_mode,
224242
logfile=logfile, temp_dir=None)
225243

226244
def run_fas_seas(self, station_file, input_dirs, labels,
227245
output_dir, input_unit="cm/s/s",
228-
output_unit="cm/s/s",
246+
output_unit="cm/s/s", output_mode="both",
229247
logfile=None, temp_dir=None):
230248
"""
231249
Run FAS/SEAS analysis codes
@@ -272,7 +290,7 @@ def run_fas_seas(self, station_file, input_dirs, labels,
272290
compute_station_fas(temp_dir, output_dir, input_acc_file,
273291
station_name, output_prefix=output_prefix,
274292
input_unit=input_unit, output_unit=output_unit,
275-
logfile=logfile)
293+
output_mode=output_mode, logfile=logfile)
276294
t2 = time.time()
277295
print("%10.2f s" % (t2 - t1))
278296

gmsvtoolkit/stats/fas_eas_gof.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def __init__(self, comp_label=None, max_cutoff=MAX_CDST):
127127

128128
def summarize_fas(self, site_list, a_outdir):
129129
"""
130-
Summarizes all FAS data and creates the FAS GOF plot
130+
Summarizes all FAS/EAS data
131131
"""
132132
fas_residfile = os.path.join(a_outdir, "%s.fas-eas-resid.txt" %
133133
(self.comp_label))

gmsvtoolkit/stats/fas_seas_gof.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
# Some constants used in the code
5959
COMPS_FAS = ["seas1", "seas2", "seas"]
60+
COMPS_FAS_OUTPUT = ["seas"]
6061
MIN_CDST = 0
6162
MAX_CDST = 25
6263

@@ -127,11 +128,11 @@ def __init__(self, comp_label=None, max_cutoff=MAX_CDST):
127128

128129
def summarize_fas(self, site_list, a_outdir):
129130
"""
130-
Summarizes all FAS data and creates the FAS GOF plot
131+
Summarizes all FAS/SEAS data
131132
"""
132133
fas_residfile = os.path.join(a_outdir, "%s.fas-seas-resid.txt" %
133134
(self.comp_label))
134-
for comp in COMPS_FAS:
135+
for comp in COMPS_FAS_OUTPUT:
135136
# Build paths and check lengths
136137
fileroot = os.path.join(a_outdir, "%s_r%d-%d-fas-seas-%s" %
137138
(self.comp_label, MIN_CDST,

0 commit comments

Comments
 (0)