def open_files(data_path, event_file, db_path):
# Read all data
st = read(data_path)
# Fill stream with station coordinates (in SAC header)
st.get_station_coordinates()
# Read event file
try:
cat = obspy.read_events(event_file)
if len(cat) > 1:
msg = 'File %s contains more than one event. Dont know, which one\
to chose. Please provide QuakeML file with just one event.'
raise TypeError(msg)
event = cat[0]
except:
event = get_event_from_obspydmt(event_file)
origin = event.origins[0]
db = instaseis.open_db(db_path)
# Initialize with MT from event file
try:
tensor = event.focal_mechanisms[0].moment_tensor.tensor
except IndexError:
print('No moment tensor present, using explosion. Hilarity may ensue')
tensor = obspy.core.event.Tensor(m_rr=1e20, m_tt=1e20, m_pp=1e20,
m_rp=0.0, m_rt=0.0, m_tp=0.0)
# Init with Gaussian STF with a length T:
# log10 T propto 0.5*Magnitude
# Scaling is such that the 5.7 Virginia event takes 5 seconds
if len(event.magnitudes) > 0:
duration = 10 ** (0.5 * (event.magnitudes[0].mag / 5.7)) * 5.0 / 2
else:
duration = 2.5
print('Assuming duration of %8.1f sec' % duration)
stf = signal.gaussian(duration * 2, duration / 4 / db.info.dt)
return db, st, origin, tensor, stf
评论列表
文章目录