-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdata_extraction.py
More file actions
192 lines (171 loc) · 5.93 KB
/
Copy pathdata_extraction.py
File metadata and controls
192 lines (171 loc) · 5.93 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
import os
import xml.etree.ElementTree as et
import pandas as pd
from datetime import datetime
#function to extract data from the daily drilling reports for the time/depth curve
def get_timevsdepth(well):
report_list = os.listdir('Reports')
time = []
md = []
section = []
summary = []
df = pd.DataFrame(
list(zip(
time,
md,
section,
summary
)),
columns = [
'Time',
'MD (m)',
'Section (in)',
'Summary'
])
os.chdir('Reports')
for file in report_list:
if file[:-15] == well:
report_tree = et.parse(file)
report_root = report_tree.getroot()
time = []
md = []
section = []
summary = []
time_temp = True
md_temp = True
section_temp = True
summary_temp = True
for child in report_root:
for elem in child:
if elem.tag == '{http://www.witsml.org/schemas/1series}statusInfo':
for subelem in elem:
if subelem.tag == '{http://www.witsml.org/schemas/1series}dTim':
time.append(datetime.strptime(subelem.text[:16], '%Y-%m-%dT%H:%M'))
time_temp = False
elif subelem.tag == '{http://www.witsml.org/schemas/1series}md':
md.append(float(subelem.text) if float(subelem.text)>0 else 0)
md_temp = False
elif subelem.tag == '{http://www.witsml.org/schemas/1series}diaHole':
section.append(float(subelem.text))
section_temp = False
elif subelem.tag == '{http://www.witsml.org/schemas/1series}sum24Hr':
summary.append(subelem.text)
summary_temp = False
else:
pass
if time_temp:
time.append('None')
if md_temp:
md.append(0)
if section_temp:
section.append('-')
if summary_temp:
summary.append('-')
df = df.append(
pd.DataFrame(
list(zip(
time,
md,
section,
summary
)),
columns = [
'Time',
'MD (m)',
'Section (in)',
'Summary'
]),
ignore_index = True,
sort = False
)
df.sort_values(['Time'], inplace=True)
os.chdir('../')
return df
#function to extract data from the daily drilling reports for the operations timeline
def get_operations(well):
report_list = os.listdir('Reports')
start = []
end = []
md = []
operation = []
comment = []
duration = []
state = []
df = pd.DataFrame(
list(zip(
start,
end,
md,
duration,
operation,
comment,
state
)),
columns = [
'Start',
'End',
'MD (m)',
'Duration',
'Operation',
'Comment',
'State'
])
os.chdir('Reports')
for file in report_list:
if file[:-15] == well:
report_tree = et.parse(file)
report_root = report_tree.getroot()
start = []
end = []
md = []
operation = []
comment = []
duration = []
state = []
for child in report_root:
for elem in child:
if elem.tag == '{http://www.witsml.org/schemas/1series}activity':
for subelem in elem:
if 'dTimStart' in subelem.tag:
start.append(datetime.strptime(subelem.text[:16], '%Y-%m-%dT%H:%M'))
start_temp = datetime.strptime(subelem.text[:16], '%Y-%m-%dT%H:%M')
elif 'dTimEnd' in subelem.tag:
end.append(datetime.strptime(subelem.text[:16], '%Y-%m-%dT%H:%M'))
end_temp = datetime.strptime(subelem.text[:16], '%Y-%m-%dT%H:%M')
elif 'md' in subelem.tag:
md.append(subelem.text)
elif 'proprietaryCode' in subelem.tag:
operation.append(subelem.text)
elif 'comments' in subelem.tag:
comment.append(subelem.text)
elif 'stateDetailActivity' in subelem.tag:
state.append(subelem.text)
else:
pass
duration.append((end_temp-start_temp))
df = df.append(
pd.DataFrame(
list(zip(
start,
end,
md,
duration,
operation,
comment,
state
)),
columns = [
'Start',
'End',
'MD (m)',
'Duration',
'Operation',
'Comment',
'State'
]),
ignore_index = True,
sort = False
)
df.sort_values(['Start'], inplace=True)
os.chdir('../')
return df