-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSWconnect.py
More file actions
351 lines (237 loc) · 10.9 KB
/
SWconnect.py
File metadata and controls
351 lines (237 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# -*- coding: utf-8 -*-
"""
This is a helper function for connecting to a SeisWare Project
"""
import SeisWare
import sys
import pandas as pd
import numpy as np
def handle_error(message, error):
"""
Helper function to print out the error message to stderr and exit the program.
"""
print(message, file=sys.stderr)
print("Error: %s" % (error), file=sys.stderr)
sys.exit(1)
def sw_project_list():
'''
Return a list of SeisWare projects
Values will be SeisWare Project objects
'''
connection = SeisWare.Connection()
try:
serverInfo = SeisWare.Connection.CreateServer()
connection.Connect(serverInfo.Endpoint(), 10000)
except RuntimeError as err:
handle_error("Failed to connect to the server", err)
project_list = SeisWare.ProjectList()
connection.ProjectManager().GetAll(project_list)
return project_list
def sw_connect(project_name):
'''
project_name : String containing project name
return : login_instance object used to access data within a project
Connect to a SeisWare project
'''
connection = SeisWare.Connection()
try:
serverInfo = SeisWare.Connection.CreateServer()
connection.Connect(serverInfo.Endpoint(), 5000)
except RuntimeError as err:
handle_error("Failed to connect to the server", err)
project_list = SeisWare.ProjectList()
try:
connection.ProjectManager().GetAll(project_list)
except RuntimeError as err:
handle_error("Failed to get the project list from the server", err)
projects = [project for project in project_list if project.Name() == project_name]
if not projects:
print("No project was found", file=sys.stderr)
sys.exit(1)
login_instance = SeisWare.LoginInstance()
try:
login_instance.Open(connection, projects[0])
except RuntimeError as err:
handle_error("Failed to connect to the project", err)
return login_instance
def get_well(login_instance,uwi):
'''
uwi : String containing well UWI
returns : SeisWare well object
'''
well_list = SeisWare.WellList()
try:
login_instance.WellManager().GetAll(well_list)
except RuntimeError as err:
handle_error("Failed to get all the wells from the project", err)
wells = [well for well in well_list if well.UWI() == uwi]
return wells[0]
def get_all_wells(login_instance):
'''
Returns all wells in a SeisWare project as a list of well objects
'''
well_list = SeisWare.WellList()
try:
login_instance.WellManager().GetAll(well_list)
except RuntimeError as err:
handle_error("Failed to get all the wells from the project", err)
wells = [well for well in well_list]
return wells
def get_filter_wells(login_instance,filter_name):
'''
filter_name: String containing filter name
Returns filtered wells in a SeisWare project as a list of well objects
'''
well_filter = SeisWare.FilterList()
login_instance.FilterManager().GetAll(well_filter)
well_filter = [i for i in well_filter if i.Name() == filter_name]
keys = SeisWare.IDSet()
failed_keys = SeisWare.IDSet()
well_list = SeisWare.WellList()
try:
login_instance.WellManager().GetKeysByFilter(well_filter[0],keys)
login_instance.WellManager().GetByKeys(keys,well_list,failed_keys)
except RuntimeError as err:
handle_error("Failed to get all the wells from the project", err)
wells = [well for well in well_list]
return wells
def get_grid(login_instance, grid_name):
'''
grid_name: String with grid name
returns: Dataframe containing X Y Z, where the header for Z is the Grid Name
Get a grid and return a dataframe with X Y Z values
'''
# Get the grids from the project
grid_list = SeisWare.GridList()
try:
login_instance.GridManager().GetAll(grid_list)
except RuntimeError as err:
handle_error("Failed to get the grids from the project", err)
# Get the grid we want
grids = [grid for grid in grid_list if grid.Name() == grid_name]
if not grids:
print("No grids were found", file=sys.stderr)
sys.exit(1)
# Populate the grid with it's values
try:
login_instance.GridManager().PopulateValues(grids[0])
except RuntimeError as err:
handle_error("Failed to populate the values of grid %s from the project" % (grid_name), err)
grid = grids[0]
# Get the values from the grid
grid_values = SeisWare.GridValues()
grid.Values(grid_values)
#Fill a DF with X,Y,Z values
#Make a list of tuples
xyzcoords = []
grid_values_list = list(grid_values.Data())
counter = 0
grid_df = pd.DataFrame()
for i in range(grid_values.Height()):
for j in range(grid_values.Width()):
xyzcoords.append((grid.Definition().RangeY().start+i*grid.Definition().RangeY().delta,
grid.Definition().RangeX().start+j*grid.Definition().RangeX().delta,
grid_values_list[counter]))
counter = counter + 1
#print(counter)
grid_df = pd.DataFrame(xyzcoords,columns=["Y","X",f"{grid.Name()}"])
return grid_df
def get_srvy(login_instance, well, depth_unit = SeisWare.Unit.Meter):
'''
well: SeisWare well object
depth_unit: Defaults to meter, alternatively can be SeisWare.Unit.Foot
Get the directional survey based on well, login_instance.
Will fail for well without Directional Survey.
Return directional survey as dataframe with
columns
UWI X Y TVDSS MD
'''
surfaceX = well.TopHole().x.Value(depth_unit)
surfaceY = well.TopHole().y.Value(depth_unit)
surfaceDatum = well.DatumElevation().Value(depth_unit)
dirsrvylist = SeisWare.DirectionalSurveyList()
login_instance.DirectionalSurveyManager().GetAllForWell(well.ID(),dirsrvylist)
#Select the directional survey if it exists
dirsrvy = [i for i in dirsrvylist if i.OffsetNorthType()>0]
login_instance.DirectionalSurveyManager().PopulateValues(dirsrvy[0])
srvypoints = SeisWare.DirectionalSurveyPointList()
dirsrvy[0].Values(srvypoints)
srvytable = []
for i in srvypoints:
srvytable.append((
well.Name(),
surfaceX + i.xOffset.Value(depth_unit),
surfaceY + i.yOffset.Value(depth_unit),
surfaceDatum - i.tvd.Value(depth_unit),
i.md.Value(depth_unit)))
return pd.DataFrame(srvytable, columns = ['UWI','X','Y','TVDSS','MD'])
def get_log_curve(login_instance,well,log_curve_name,depth_unit = SeisWare.Unit.Meter):
'''
Takes well object, log curve name, and login instance to return a dataframe containing
columns
MD curvevalue
'''
log_curve_list = SeisWare.LogCurveList()
try:
login_instance.LogCurveManager().GetAllForWell(well.ID(), log_curve_list)
except RuntimeError as err:
handle_error("Failed to get the log curves of well %s from the project" % (well.UWI()), err)
log_curves = [log_curve for log_curve in log_curve_list if log_curve.Name() == log_curve_name]
if not log_curves:
return pd.DataFrame(data=None,columns = ['MD',log_curve_name])
#print("No log curve was found", file=sys.stderr)
#sys.exit(1)
try:
login_instance.LogCurveManager().PopulateValues(log_curves[0])
except RuntimeError as err:
handle_error("Failed to populate the values of log curve %s of well %s from the project" % (log_curve_name, well.UWI()), err)
log_curve_values = SeisWare.DoublesList()
log_curves[0].Values(log_curve_values)
log_table = []
for i in range(len(log_curve_values)):
log_table.append(((log_curves[0].TopDepth()+log_curves[0].DepthInc()*i).Value(depth_unit),log_curve_values[i]))
return pd.DataFrame(log_table,columns = ['MD',log_curve_name])
def get_horizon(login_instance,seismic_name,horizon_name,proj_units = SeisWare.Unit.Meter):
'''
seismic_name : string containing seismic line name
horizon_name : string containing horizon name
proj_units : Coordinate system XY units. Defaults to meters. Can be changed to SeisWare.Unit.Foot
'''
surveys = SeisWare.SeismicSurveyList()
login_instance.SeismicSurveyManager().GetAll(surveys)
survey = [i for i in surveys if i.Name() == seismic_name]
horizons = SeisWare.HorizonList()
login_instance.HorizonManager().GetAll(horizons)
horizon = [i for i in horizons if i.Name() == horizon_name]
picks = SeisWare.HorizonPicksList()
# Horizon and Survey keys must be passed in as an IDPair list. The IDPair is created and then made into a single element list
login_instance.HorizonPicksManager().GetByHorizonAndSeismicSurveyKeys([SeisWare.IDPair(horizon[0].ID(),survey[0].ID())],picks)
# Populate the pick values
login_instance.HorizonPicksManager().PopulateValues(picks[0])
# Create an empty constructor
values = SeisWare.HorizonPickValues()
# Get the values from the picks and put them into the constructor
picks[0].Values(values)
# Get the values from the constructor and put them into a list
horizon_points = []
#inline_range = (survey[0].Survey().InlineRange().start,survey[0].Survey().InlineRange().start+survey[0].Survey().InlineRange().count*survey[0].Survey().InlineRange().delta-1)
#crossline_range = (survey[0].Survey().CrosslineRange().start,survey[0].Survey().CrosslineRange().start+survey[0].Survey().CrosslineRange().count*survey[0].Survey().CrosslineRange().delta-1)
fifc = (survey[0].Survey().CornerFiFc().x.Value(proj_units),survey[0].Survey().CornerFiFc().y.Value(proj_units))
filc = (survey[0].Survey().CornerFiLc().x.Value(proj_units),survey[0].Survey().CornerFiLc().y.Value(proj_units))
lifc = (survey[0].Survey().CornerLiFc().x.Value(proj_units),survey[0].Survey().CornerLiFc().y.Value(proj_units))
delta_x_il = (lifc[0] - fifc[0])/(survey[0].Survey().CrosslineRange().count-1)
delta_y_il = (lifc[1] - fifc[1])/(survey[0].Survey().CrosslineRange().count-1)
delta_x_xl = (filc[0] - fifc[0])/(survey[0].Survey().InlineRange().count-1)
delta_y_xl = (filc[1] - fifc[1])/(survey[0].Survey().InlineRange().count-1)
for i in range(values.InlineCount()):
for j in range(values.CrosslineCount()):
#print(i,j)
if values.IsPicked(SeisWare.GridIndex2(j,i)):
pick_ij = values.Pick(SeisWare.GridIndex2(j,i)).structure.Value(SeisWare.Unit.Millisecond)
pick_ij_amp = values.Pick(SeisWare.GridIndex2(j,i)).amplitude
else:
pick_ij = np.nan
x = fifc[0] + i*delta_x_il + j*delta_x_xl
y = fifc[1] + i*delta_y_il + j*delta_y_xl
horizon_points.append((x,y,pick_ij,pick_ij_amp,i,j))
return pd.DataFrame(horizon_points)