Skip to content

Commit

Permalink
an absolute residual cutoff should be considered
Browse files Browse the repository at this point in the history
  • Loading branch information
basaks committed Nov 26, 2017
1 parent 2dcdfd7 commit 1c48a1a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion seismic/cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ def sort(output_file, sorted_file, residual_cutoff):

cluster_data = pd.read_csv(output_file, header=None,
names=column_names)
cluster_data = cluster_data[cluster_data['residual'] < residual_cutoff]
cluster_data = cluster_data[abs(cluster_data['residual'])
< residual_cutoff]
cluster_data.sort_values(by=['source_block', 'station_block'],
inplace=True)
groups = cluster_data.groupby(by=['source_block', 'station_block'])
Expand Down
10 changes: 6 additions & 4 deletions tests/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ def test_single_event_arrivals(event_xml, arr_type):
assert outputs_s[0][-1] == 2


@pytest.fixture(params=[0, 1], name='residual_bool')
# a very large residual allowed, imply we are not really using the filter
@pytest.fixture(params=[1e6, 1], name='residual_bool')
def res_bool(request):
if request.param == 0:
if request.param == 1e6:
request.applymarker(pytest.mark.xfail)
return request.param

Expand Down Expand Up @@ -170,15 +171,16 @@ def _test_matched(outfile, wave_type):

def _test_sort_and_filtered(outfile, wave_type, residual_bool):
sorted_p_or_s = outfile + '_sorted_' + wave_type + '.csv'
residual = residual_bool*(5.0 if wave_type == 'P' or 'Pn' else 10.0)
p_s_res = 5.0 if wave_type == 'P' or 'Pn' else 10.0
residual = residual_bool*p_s_res
sort_p = ['cluster', 'sort', outfile + '_' + wave_type + '.csv',
str(residual), '-s', sorted_p_or_s]
check_call(sort_p)
assert os.path.exists(sorted_p_or_s)
p_df = pd.read_csv(sorted_p_or_s)

# tests for residual filter
assert all(p_df['residual'].values <= residual)
assert all(abs(p_df['residual'].values) < p_s_res)

# tests for median filter
# after sorting and filtering, every group should have one row
Expand Down

0 comments on commit 1c48a1a

Please sign in to comment.