-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSWconnect.py
More file actions
208 lines (151 loc) · 6.39 KB
/
SWconnect.py
File metadata and controls
208 lines (151 loc) · 6.39 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
# -*- coding: utf-8 -*-
"""
This is a helper function for connecting to a SeisWare Project
"""
import SeisWare
import sys
#Pyproj for lat/long info
from pyproj import Proj
import numpy
import pandas as pd
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 SWprojlist():
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()
connection.ProjectManager().GetAll(project_list)
return project_list
def SWconnect(project_name):
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 getWell(uwi,login_instance):
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 getAllWells(login_instance):
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 wellstoDF(wells):
#Take a list of SeisWare Well Type objects and adds it to a dataframe
return welldf
'''
#Take grid name and return dataframe
def grid_to_dataframe(login_instance, grid_name):
"""
Use the login instance and grid name to return a dataframe containing XYZ values for grid data. Grab all grid list, select the grid by name string, populate the grid.
Write out a list of tuples containing XYZ 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 = []
gridDF = 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,
list(grid_values.Data())[counter]))
gridDF = pd.DataFrame(xyzcoords,columns=["Y","X","Z"])
return gridDF
def plotLog(uwi,log_curve_name,login_instance):
#Populate Log Curve List for given well
log_curve_list = SeisWare.LogCurveList()
well = getWell(uwi,login_instance)
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:
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)
return log_curve_values
def getlogcurve(well,log_curve_name,login_instance):
'''
Takes well, 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:
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])