diff --git a/bbp/comps/lf_seismograms.py b/bbp/comps/lf_seismograms.py index 4e0e043..f704fb2 100644 --- a/bbp/comps/lf_seismograms.py +++ b/bbp/comps/lf_seismograms.py @@ -75,12 +75,14 @@ class LFSeismograms(object): tmpdir directory """ - def __init__(self, i_seis_dir, i_r_stations, sim_id=0): + def __init__(self, i_seis_dir, i_r_stations, + allow_negative_timestamps=False, sim_id=0): """ Initialize class variables """ self.seis_dir = i_seis_dir self.r_stations = i_r_stations + self.allow_negative_timestamps = allow_negative_timestamps self.sim_id = sim_id def run(self): @@ -108,4 +110,28 @@ def run(self): "%d.%s-lf.bbp" % (int(self.sim_id), station_name)) print("Copying LF file for station %s..." % (station_name)) - shutil.copy2(a_input_file, a_output_file) \ No newline at end of file + + if self.allow_negative_timestamps: + shutil.copy2(a_input_file, a_output_file) + else: + # Copy LF seismograms but remove points with t<0 + fp_in = open(a_input_file, 'r') + fp_out = open(a_output_file, 'w') + for line in fp_in: + pieces = line.split() + try: + if pieces[0] == '#' or pieces[0] == '%': + fp_out.write(line) + elif float(pieces[0]) < -0.0001: + continue + elif float(pieces[0]) < 0.0001: + fp_out.write("0.0\t%s\t%s\t%s\n" % (pieces[1], + pieces[2], + pieces[3])) + else: + fp_out.write(line) + except ValueError: + fp_out.write(line) + fp_in.close() + fp_out.flush() + fp_out.close()