-
Notifications
You must be signed in to change notification settings - Fork 0
/
sag_corr_qc.py
149 lines (113 loc) · 4.33 KB
/
sag_corr_qc.py
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
"""
SAG CORRECTION QUALITY CONTROL
Loop through files in a directory, extract data, load into dataframe,
and export to a csv file.
Designed for use with corrected survey sheets collected from MagVar (Saphira).
Directories are defined by user. Make sure output files are saved in
a different location than survey sheets.
"""
# script and version info
script = 'sag_corr_qc.py'
version = '1.0.0'
author = 'S Kerstetter'
created = '2021-01-08'
last_modified = '2021-01-08'
# import modules
import pandas as pd
import datetime as dt
import os
# user-defined paths
directory = "C:\\Users\\kerst997\\Documents\\survey_sheets\\"
save_directory = "C:\\Users\\kerst997\\Documents\\sag_correction_reports\\"
# output file name
today = dt.date.today()
output_file = 'sag_correction_data_' + str(today) + ".csv"
# loop through files in a directory
def loop_files(directory):
output_df = pd.DataFrame(columns=['wellname', 'sag_corrected', 'start_location', 'start_md', 'tool_code', 'previous_svy', 'previous_code'])
for filename in os.listdir(directory):
# select file and extract data
target_file = os.path.join(filename)
extracted_data = extract_data(dirpath, target_file)
print(f"In file {target_file} we found: {extracted_data}")
# append extracted data to end of dataframe
end = len(output_df)
output_df.loc[end] = extracted_data
return output_df
# extract data from file, wellname and start of sag corrections
def extract_data(dirpath, file):
# extract well name
temp_df = pd.read_excel(dirpath+file, sheet_name='Minimum Curvature', header=None)
wellname = temp_df.loc[2,2]
# reload data with column headers, drop extraneous columns and rows
temp_df = pd.read_excel(dirpath+file, sheet_name='Minimum Curvature', header=5)
temp_df = temp_df.drop(['Azimuth', 'Vertical Depth', 'Northings Local', 'Eastings Local', 'Vertical Section', 'Dogleg Rate'], axis=1)
temp_df = temp_df.drop(0)
#extract data from file
for i in range (1, len(temp_df)):
if "SAG" in temp_df['Tool Code'][i]:
sag_corrected = True
start_md = temp_df['Measured Depth'][i]
tool_code = temp_df['Tool Code'][i]
previous_svy = temp_df['Measured Depth'][i-1]
previous_code = temp_df['Tool Code'][i-1]
break
else:
sag_corrected = False
# if well has any amount of sag correction, find location of sag correction and compile data.
# else compile compile well name and false sag correction
if sag_corrected is True:
start_location = find_hole_section(temp_df, start_md)
file_data = [wellname, sag_corrected, start_location, start_md, tool_code, previous_svy, previous_code]
else:
file_data = [wellname, sag_corrected, '', '', '', '', '']
return file_data
# determines position in curve via inc and neighboring surveys
def find_hole_section(df, md):
# collect KOP, LP, and TD values
kop, lp, td = find_kop_lp_td(df)
# using KOP, LP, and TD, determine where in well sag corrections began.
if md < kop and md >= 0:
hole_section = 'VERTICAL'
elif md == kop:
hole_section = 'KOP'
elif md == lp:
hole_section = 'LP'
elif md > kop and md < lp:
hole_section = 'CURVE'
elif md > lp and md < td:
hole_section = 'LATERAL'
else:
hole_section = "INVALID"
return hole_section
# determines location of KOP, LP, and TD
def find_kop_lp_td(df):
# find TD
end = len(df)
td = df['Measured Depth'][end]
# find KOP
while True:
if df['Inclination'][end] < 4:
kop = df['Measured Depth'][end]
break
end -= 1
# find LP
for i in range(1, len(df)):
if df['Inclination'][i] >= 88:
lp = df['Measured Depth'][i]
break
return kop, lp, td
# *** Start Script ****
print(f"""
SAG CORRECTION QUALITY CONTROL
Credits
Script: {script}
Date Created: {created}
Author: {author}
Version: {version}
Last Modified: {last_modified}
""")
print("Processing Feed:")
output_df = loop_files(dirpath)
output_df.head()
output_df.to_csv(save_directory+output_file)