Skip to content

Commit

Permalink
Added flag to remove negative timestamps in LF 3D seismograms
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiolsilva committed Jan 22, 2024
1 parent 16946c3 commit 26d14a4
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions bbp/comps/lf_seismograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

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()

0 comments on commit 26d14a4

Please sign in to comment.