Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify code to handle non-standard and time-varying component orientations #95

Merged
merged 13 commits into from
Jan 19, 2025
Merged
14 changes: 8 additions & 6 deletions seispy/eq.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ def __str__(self):
return '{}'.format(self.matchkey)

def rotateZNE(st):
"""Rotate Z, N, E components to Z, N, E components
"""Rotate non-standard components (e.g., 1, 2, Z) to N, E, Z components
and reorder the components to ensure that the final *.BHZ.SAC files have correct cmpaz (=0) and cmpinc (=0) headers.
"""
try:
zne = rotate2zne(
st[0], st[0].stats.sac.cmpaz, st[0].stats.sac.cmpinc,
st[1], st[1].stats.sac.cmpaz, st[1].stats.sac.cmpinc,
st[2], st[2].stats.sac.cmpaz, st[2].stats.sac.cmpinc)
st[0].data, st[0].stats.sac.cmpaz, st[0].stats.sac.cmpinc - 90,
st[1].data, st[1].stats.sac.cmpaz, st[1].stats.sac.cmpinc - 90,
st[2].data, st[2].stats.sac.cmpaz, st[2].stats.sac.cmpinc - 90)
nez = [zne[1], zne[2], zne[0]] # change order from ZNE to NEZ
except Exception as e:
raise ValueError('No specified cmpaz or cmpinc. {}'.format(e))
for tr, new_data, component in zip(st, zne, "ZNE"):
for tr, new_data, component in zip(st, nez, "NEZ"):
tr.data = new_data
tr.stats.channel = tr.stats.channel[:-1] + component

Expand Down Expand Up @@ -255,7 +257,7 @@ def search_baz(self, bazi, time_b=10, time_e=20, offset=90):
return corr_baz, ampt

def fix_channel_name(self):
"""Fix channel name for R, E, N components
"""Fix channel name for Z, E, N components
"""
if self.st.select(channel='??1') and self.st.select(channel='??Z') and hasattr(self.st.select(channel='*1')[0].stats.sac, 'cmpaz'):
if self.st.select(channel='*1')[0].stats.sac.cmpaz == 0:
Expand Down
6 changes: 4 additions & 2 deletions seispy/rf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ def _add_header(st, evt_time, stainfo):
header = SACTrace.from_obspy_trace(tr).to_obspy_trace().stats.sac
channel = tr.stats.channel
for ch in sta.channels:
if ch.code == channel:
if (ch.code == channel and ch.start_date <= tr.stats.starttime and
(tr.stats.endtime <= ch.end_date or ch.end_date is None)):
header.cmpaz = ch.azimuth
header.cmpinc = -ch.dip
header.cmpinc = ch.dip + 90
break
header.stla = stainfo.stla
header.stlo = stainfo.stlo
header.stel = stainfo.stel
Expand Down
Loading