Skip to content

Commit b169cbc

Browse files
committed
Miscellaneous Changes
* Distance along seismic line is now calculated based on coordinates inWGS84 in segy.py * Minor changes in extract_event_traces.py
1 parent 8fd7d6f commit b169cbc

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed

seismic/extract_event_traces.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ def extract_data(catalog, inventory, waveform_getter, event_trace_datafile,
526526

527527
# resample after lowpass @ resample_rate / 2 Hz
528528
for tr in out_stream:
529+
tr.detrend()
530+
tr.taper(max_percentage=0.05, max_length=5)
529531
zerophase_resample(tr, resample_hz)
530532

531533
tr.stats.update({'wave_type':wave})

utils/segy.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import numpy as np
1616
import pyproj
1717
from obspy.io.segy import segy
18+
from pyproj import Geod
1819

1920
class DepthMigratedSegy:
2021
def __init__(self, segy_fn,
@@ -44,6 +45,7 @@ def __init__(self, segy_fn,
4445
identifying problematic station-coordinates
4546
:param flip: Flip horizontally
4647
'''
48+
self.output_epsg = 4326
4749
self.sfn = segy_fn
4850
self.coords_file = coords_file
4951
self.depth_zero_km = depth_zero_km
@@ -56,6 +58,7 @@ def __init__(self, segy_fn,
5658
self.flip = flip
5759
# transformer to go from segy projection to wgs84
5860
self.transformer = pyproj.Transformer.from_crs(self.epsg_code, 4326)
61+
self.geod = Geod(ellps='WGS84')
5962

6063
# Read traces
6164
self.samples = [] # trace samples
@@ -100,34 +103,28 @@ def __init__(self, segy_fn,
100103
self.xs = np.array(self.xs)
101104
self.ys = np.array(self.ys)
102105
self.cdps = np.array(self.cdps)
103-
self.station_spacing = np.sqrt((self.xs[:-1] - self.xs[1:]) ** 2 +
104-
(self.ys[:-1] - self.ys[1:]) ** 2)
105-
self.station_spacing = np.concatenate([[0], self.station_spacing])
106106

107107
# use station-spacing to weed out traces with incorrect coordinates
108-
bad_indices = np.zeros(self.station_spacing.shape, dtype='?')
109108
if(self.filter_coordinates):
110-
median_spacing = np.median(self.station_spacing)
111-
bad_indices = np.fabs(self.station_spacing - median_spacing) > \
109+
station_spacing = np.sqrt((self.xs[:-1] - self.xs[1:]) ** 2 +
110+
(self.ys[:-1] - self.ys[1:]) ** 2)
111+
station_spacing = np.concatenate([[0], station_spacing])
112+
median_spacing = np.median(station_spacing)
113+
bad_indices = np.fabs(station_spacing - median_spacing) > \
112114
self.filter_coordinates_factor * median_spacing
113115
print('Warning: removing {} traces (~{:.3f}%) with '
114116
'bad coordinates..'.format(np.sum(bad_indices),
115117
np.sum(bad_indices)/self.ntraces*100))
118+
self.ns = self.ns[~bad_indices]
119+
self.si = self.si[~bad_indices]
120+
self.xs = self.xs[~bad_indices]
121+
self.ys = self.ys[~bad_indices]
122+
self.cdps = self.cdps[~bad_indices]
123+
124+
self.ntraces -= np.sum(bad_indices)
125+
self.samples = self.samples[:, ~bad_indices]
116126
# end if
117127

118-
self.ns = self.ns[~bad_indices]
119-
self.si = self.si[~bad_indices]
120-
self.xs = self.xs[~bad_indices]
121-
self.ys = self.ys[~bad_indices]
122-
self.cdps = self.cdps[~bad_indices]
123-
self.station_spacing= self.station_spacing[~bad_indices]
124-
self.ntraces -= np.sum(bad_indices)
125-
self.samples = self.samples[:, ~bad_indices]
126-
127-
# compute euclidean distance along profile
128-
self.ds = np.array([np.sum(self.station_spacing[:i])
129-
for i in range(len(self.station_spacing))]) / 1e3 # km
130-
131128
self.times = np.linspace(0, (np.max(self.ns) - 1) * np.max(self.si),
132129
np.max(self.ns))
133130
# depths
@@ -136,6 +133,14 @@ def __init__(self, segy_fn,
136133

137134
# convert x and y coordinates to lons and lats
138135
self.lats, self.lons = self.transformer.transform(self.xs, self.ys)
136+
137+
# compute euclidean distances along profile
138+
self.ds = [0.0]
139+
for i in range(1, len(self.lons)):
140+
_, _, dist = self.geod.inv(self.lons[i-1], self.lats[i-1], self.lons[i], self.lats[i])
141+
self.ds.append(self.ds[-1] + dist)
142+
# end for
143+
self.ds = np.array(self.ds) / 1e3 # in kms
139144
# end func
140145

141146
def getAttribute(self, key, d):
@@ -244,7 +249,6 @@ def augment(self, other, prepend=False):
244249
if (prepend):
245250
self.xs = np.hstack([other.xs, self.xs])
246251
self.ys = np.hstack([other.ys, self.ys])
247-
self.station_spacing = np.hstack([other.station_spacing, self.station_spacing])
248252

249253
result = np.zeros((self.samples.shape[0],
250254
self.samples.shape[1] + other.samples.shape[1]))
@@ -258,7 +262,6 @@ def augment(self, other, prepend=False):
258262
else:
259263
self.xs = np.hstack([self.xs, other.xs])
260264
self.ys = np.hstack([self.ys, other.ys])
261-
self.station_spacing = np.hstack([self.station_spacing, other.station_spacing])
262265

263266
result = np.zeros((self.samples.shape[0],
264267
self.samples.shape[1] + other.samples.shape[1]))
@@ -271,12 +274,16 @@ def augment(self, other, prepend=False):
271274
self.samples = result
272275
# end if
273276

274-
# recompute euclidean distance along profile
275-
self.ds = np.array([np.sum(self.station_spacing[:i])
276-
for i in range(len(self.station_spacing))]) / 1e3 # km
277-
278277
# convert x and y coordinates to lons and lats
279278
self.lats, self.lons = self.transformer.transform(self.xs, self.ys)
279+
280+
# recompute euclidean distance along profile
281+
self.ds = [0.0]
282+
for i in range(1, len(self.lons)):
283+
_, _, dist = self.geod.inv(self.lons[i-1], self.lats[i-1], self.lons[i], self.lats[i])
284+
self.ds.append(self.ds[-1] + dist)
285+
# end for
286+
self.ds = np.array(self.ds) / 1e3 # in kms
280287
# end if
281288
# end func
282289
# end class

0 commit comments

Comments
 (0)