15
15
import numpy as np
16
16
import pyproj
17
17
from obspy .io .segy import segy
18
+ from pyproj import Geod
18
19
19
20
class DepthMigratedSegy :
20
21
def __init__ (self , segy_fn ,
@@ -44,6 +45,7 @@ def __init__(self, segy_fn,
44
45
identifying problematic station-coordinates
45
46
:param flip: Flip horizontally
46
47
'''
48
+ self .output_epsg = 4326
47
49
self .sfn = segy_fn
48
50
self .coords_file = coords_file
49
51
self .depth_zero_km = depth_zero_km
@@ -56,6 +58,7 @@ def __init__(self, segy_fn,
56
58
self .flip = flip
57
59
# transformer to go from segy projection to wgs84
58
60
self .transformer = pyproj .Transformer .from_crs (self .epsg_code , 4326 )
61
+ self .geod = Geod (ellps = 'WGS84' )
59
62
60
63
# Read traces
61
64
self .samples = [] # trace samples
@@ -100,34 +103,28 @@ def __init__(self, segy_fn,
100
103
self .xs = np .array (self .xs )
101
104
self .ys = np .array (self .ys )
102
105
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 ])
106
106
107
107
# use station-spacing to weed out traces with incorrect coordinates
108
- bad_indices = np .zeros (self .station_spacing .shape , dtype = '?' )
109
108
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 ) > \
112
114
self .filter_coordinates_factor * median_spacing
113
115
print ('Warning: removing {} traces (~{:.3f}%) with '
114
116
'bad coordinates..' .format (np .sum (bad_indices ),
115
117
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 ]
116
126
# end if
117
127
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
-
131
128
self .times = np .linspace (0 , (np .max (self .ns ) - 1 ) * np .max (self .si ),
132
129
np .max (self .ns ))
133
130
# depths
@@ -136,6 +133,14 @@ def __init__(self, segy_fn,
136
133
137
134
# convert x and y coordinates to lons and lats
138
135
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
139
144
# end func
140
145
141
146
def getAttribute (self , key , d ):
@@ -244,7 +249,6 @@ def augment(self, other, prepend=False):
244
249
if (prepend ):
245
250
self .xs = np .hstack ([other .xs , self .xs ])
246
251
self .ys = np .hstack ([other .ys , self .ys ])
247
- self .station_spacing = np .hstack ([other .station_spacing , self .station_spacing ])
248
252
249
253
result = np .zeros ((self .samples .shape [0 ],
250
254
self .samples .shape [1 ] + other .samples .shape [1 ]))
@@ -258,7 +262,6 @@ def augment(self, other, prepend=False):
258
262
else :
259
263
self .xs = np .hstack ([self .xs , other .xs ])
260
264
self .ys = np .hstack ([self .ys , other .ys ])
261
- self .station_spacing = np .hstack ([self .station_spacing , other .station_spacing ])
262
265
263
266
result = np .zeros ((self .samples .shape [0 ],
264
267
self .samples .shape [1 ] + other .samples .shape [1 ]))
@@ -271,12 +274,16 @@ def augment(self, other, prepend=False):
271
274
self .samples = result
272
275
# end if
273
276
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
-
278
277
# convert x and y coordinates to lons and lats
279
278
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
280
287
# end if
281
288
# end func
282
289
# end class
0 commit comments