|
11 | 11 | from obspy import read, read_events, read_inventory, Stream
|
12 | 12 | from obspy.io.sac.sactrace import SACTrace
|
13 | 13 | from pysep.utils.cap_sac import (append_sac_headers,
|
14 |
| - format_sac_header_w_taup_traveltimes) |
| 14 | + format_sac_header_w_taup_traveltimes, |
| 15 | + write_cap_weights_files) |
15 | 16 | from pysep.utils.curtail import (remove_for_clipped_amplitudes, rename_channels,
|
16 | 17 | remove_stations_for_missing_channels,
|
17 | 18 | remove_stations_for_insufficient_length,
|
@@ -101,6 +102,32 @@ def test_sac_header_correct_origin_time(tmpdir, test_st, test_inv, test_event):
|
101 | 102 | assert(sac.reftime == test_event.preferred_origin().time)
|
102 | 103 |
|
103 | 104 |
|
| 105 | +def test_write_cap_weights_files(tmpdir, test_st, test_inv, test_event): |
| 106 | + """ |
| 107 | + Test writing out CAP weight files and make sure sorting works for distance |
| 108 | + and code works as advertised. No testing for az sorting |
| 109 | + """ |
| 110 | + st = append_sac_headers(st=test_st, inv=test_inv, event=test_event) |
| 111 | + |
| 112 | + # Check sorting by dist |
| 113 | + write_cap_weights_files(st=st, path_out=tmpdir, order_by="dist") |
| 114 | + assert(os.path.exists(os.path.join(tmpdir, "weights.dat"))) |
| 115 | + dists = np.loadtxt(os.path.join(tmpdir, "weights.dat"), usecols=1) |
| 116 | + # Check that distances are in ascending order |
| 117 | + assert(np.all(np.diff(dists) >= 0)) |
| 118 | + |
| 119 | + # Remove so we know that new files are being made each time |
| 120 | + os.remove(os.path.join(tmpdir, "weights.dat")) |
| 121 | + |
| 122 | + # Check sorting by code |
| 123 | + write_cap_weights_files(st=st, path_out=tmpdir, order_by="code") |
| 124 | + assert(os.path.exists(os.path.join(tmpdir, "weights.dat"))) |
| 125 | + codes = np.loadtxt(os.path.join(tmpdir, "weights.dat"), usecols=0, |
| 126 | + dtype=str) |
| 127 | + # Check that distances are in ascending order |
| 128 | + assert(np.all(codes == np.sort(codes))) |
| 129 | + |
| 130 | + |
104 | 131 | def test_rename_channels(test_st):
|
105 | 132 | """
|
106 | 133 | Edit some waveforms to be obviously bad and make sure we can catch it
|
|
0 commit comments