-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
163 lines (128 loc) · 5.04 KB
/
app.py
File metadata and controls
163 lines (128 loc) · 5.04 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 27 13:31:56 2025
@author: jennaeverard
"""
import pandas as pd
import numpy as np
from auth import AuthClient
from ocd import get_well_log, save_well_log
from config import INPUT_PATH, OUTPUT_CSV
def single_well_query(auth):
# Take user input of API
api = input("Enter the API number (i.e. 30-035-00008): ").strip()
print(f"Fetching well info for {api}")
data = get_well_log(auth, api, include_file_bytes=True)
# Save the well data we care about
well_type = data.get("WellType",{}).get("Description")
well_status = data.get("WellStatus",{}).get("StatusDescription")
well_id = data.get("WellIdn")
well_api = data.get("WellApi")
property_id = data.get("PropertyIdn")
property_name = data.get("PropertyName")
well_name = data.get("WellName")
operator_name = data.get('OperatorName')
latitude = data.get("Latitude")
longitude = data.get("Longitude")
county = data.get('CountyName')
# Print well data for user
print(f"""
Well API: {well_api}
Well ID: {well_id}
Well Name: {well_name}
Property ID: {property_id}
Property Name: {property_name}
Operator Name: {operator_name}
Well Type: {well_type}
Well Status: {well_status}
County: {county}
Latitude: {latitude}
Longitude: {longitude}
""")
# Download well logs and exit!
print("Downloading well logs...")
file_num = save_well_log(auth, data, data.get("WellApi"))
print(f"Saved {file_num} well logs")
print("Exiting!")
def bulk_query(auth):
# Arrays to keep track of all the well info we care about
well_api = []
well_id = []
well_name = []
property_id = []
property_name = []
operator_name = []
well_type = []
well_status = []
county = []
latitude = []
longitude = []
num_well_logs = []
savename = input("Run name (for saving summary file): ").strip()
filepath = input("Enter name of file containing well APIs: ")
# Try (and try again) to open file containing well APIs
valid_file = False
while not valid_file:
try:
data = pd.read_csv(INPUT_PATH + filepath, header=None)
valid_file = True
except FileNotFoundError:
print("***ERROR*** File Not Found")
filepath = input("Enter path to file containing well APIs: ")
except ValueError:
print("***ERROR*** Nonnumerical data in file")
filepath = input("Enter path to file containing well APIs: ")
except Exception as e:
print("***ERROR*** Unknown")
filepath = input("Enter path to file containing well APIs: ")
apis = np.array(data[0])
# Get well info and log for each API
for api in apis:
print(f"Fetching well info for {api}")
data = get_well_log(auth, api, include_file_bytes=True)
well_api.append(data.get("WellApi"))
well_id.append(data.get("WellIdn"))
well_name.append(data.get("WellName"))
property_id.append(data.get("PropertyIdn"))
property_name.append(data.get("PropertyName") )
operator_name.append(data.get('OperatorName'))
well_type.append(data.get("WellType",{}).get("Description"))
well_status.append(data.get("WellStatus",{}).get("StatusDescription"))
county.append(data.get('CountyName'))
latitude.append(data.get("Latitude"))
longitude.append(data.get("Longitude"))
file_num = save_well_log(auth, data, data.get("WellApi"))
num_well_logs.append(file_num)
# Save all well info to a csv in the output directory
df = pd.DataFrame({'Well API': well_api,
'Well ID': well_id,
'Well Name': well_name,
'Property ID': property_id,
'Property Name': property_name,
'Operator Name': operator_name,
'Well Type': well_type,
'Well Status': well_status,
'County': county,
'Latitude': latitude,
'Longitude': longitude,
'Well Log #': num_well_logs})
df.to_csv(OUTPUT_CSV + savename + '.csv', index=False)
def main():
auth = AuthClient()
print("Verifying user authentication...")
auth.login()
print("\n*** Welcome! ***\n")
print("Please enter a single digit to select your desired program:")
print("0 - query a single well by API")
print("1 - bulk query many well APIs (see GitHub for input format)")
selection = input("Enter Value: ")
if int(selection) == 0:
single_well_query(auth)
elif int(selection) == 1:
bulk_query(auth)
else:
print("!!! Invalid Input !!!")
print("Exiting...")
if __name__ == "__main__":
main()