Skip to content

Commit

Permalink
Rf quality filter (#241)
Browse files Browse the repository at this point in the history
* Minor bug fixes

* Minor improvement to rf plots
  • Loading branch information
geojunky committed Apr 8, 2022
1 parent 45e0ef7 commit ae5db59
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
6 changes: 5 additions & 1 deletion seismic/extract_event_traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from obspy.taup import TauPyModel

from PhasePApy.phasepapy.phasepicker import aicdpicker
from seismic.pick_harvester.utils import Event, Origin
from seismic.pick_harvester.utils import Event, Origin, Magnitude
from seismic.pick_harvester.pick import extract_p, extract_s
from seismic.stream_processing import zerophase_resample

Expand Down Expand Up @@ -273,6 +273,8 @@ def trim_inventory(inventory, network_list, station_list):
#end func

class Picker():
counter = 0 # static variable to count number of calls made

def __init__(self, taup_model_name):
self._taup_model = TauPyModel(model=taup_model_name)
self._picker_list_p = []
Expand All @@ -299,6 +301,8 @@ def pick(self, ztrace, ntrace, etrace, phase='P'):
ztrace.stats.event_depth)
event = Event()
event.preferred_origin = origin
event.public_id = Picker.counter; Picker.counter += 1
event.preferred_magnitude = Magnitude(mag=ztrace.stats.event_magnitude, mag_type='M')

result = None
if(phase == 'P'):
Expand Down
6 changes: 3 additions & 3 deletions seismic/pick_harvester/pick.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def extract_p(taupy_model, pickerlist, event, station_longitude, station_latitud
try:
snrst = st.slice(po.utctime + tat + win_start + buffer_start, po.utctime + tat + win_end + buffer_end)
snrst = snrst.copy()
zerophase_resample(snrst, resample_hz)
snrst.detrend('linear')
zerophase_resample(snrst, resample_hz)
except:
return None
# end try
Expand Down Expand Up @@ -178,14 +178,14 @@ def extract_s(taupy_model, pickerlist, event, station_longitude, station_latitud
try:
stn = stn.slice(po.utctime + tat + win_start + buffer_start, po.utctime + tat + win_end + buffer_end)
stn = stn.copy()
zerophase_resample(stn, resample_hz)
stn.detrend('linear')
zerophase_resample(stn, resample_hz)

if (ste):
ste = ste.slice(po.utctime + tat + win_start + buffer_start, po.utctime + tat + win_end + buffer_end)
ste = ste.copy()
zerophase_resample(ste, resample_hz)
ste.detrend('linear')
zerophase_resample(ste, resample_hz)
# end if

if (ste):
Expand Down
11 changes: 7 additions & 4 deletions seismic/receiver_fn/generate_rf.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,8 @@ def event_waveforms_to_rf(input_file, output_file, config, network_list='*', sta
logger.info('Rank {}: {}: Applying a baz correction '
'of {}'.format(rank,
nsl,
result['.'.join([net, sta])]['azimuth_correction']))
ned.apply(lambda st: correct_back_azimuth(None, st,
result['.'.join([net, sta])]['azimuth_correction']))
result[nsl]['azimuth_correction']))
ned.apply(lambda st: correct_back_azimuth(None, st, result[nsl]['azimuth_correction']))
except:
logger.warning('Channel rotation failed for {}. Moving along..'.format(nsl))
# end try
Expand Down Expand Up @@ -242,7 +241,11 @@ def event_waveforms_to_rf(input_file, output_file, config, network_list='*', sta
if(len(proc_rf_stream)):
for hdf_key in proc_hdfkeys[rank]:
# remove existing traces if there are any
remove_group(output_file, hdf_key, logger=logger)
try:
remove_group(output_file, hdf_key, logger=logger)
except Exception as e:
logger.warning(str(e))
# end try

logger.info("Writing RF stream(s) for {} on rank {}...".format(hdf_key, rank))
# end for
Expand Down
2 changes: 2 additions & 0 deletions seismic/receiver_fn/rf_plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def plot_rf_stack(rf_stream, time_window=(-10.0, 25.0), trace_height=0.2, stack_

rf_stream = revert_baz(rf_stream)

if(time_window): rf_stream = rf_stream.copy().slice2(*time_window, reftime='onset')

all_trace_lens = np.array([len(tr) for tr in rf_stream])
most_common_len, _ = stats.mode(all_trace_lens, axis=None)
stackable_stream = rf.RFStream([tr for tr in rf_stream if len(tr) == most_common_len])
Expand Down

0 comments on commit ae5db59

Please sign in to comment.