@@ -105,7 +105,7 @@ def compute_fas(acc1, acc2, dt):
105105def 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
151153class 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
0 commit comments