-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFWD_Model.py
183 lines (132 loc) · 5.92 KB
/
FWD_Model.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
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
import numpy as np
from tkinter import Tk # from tkinter import Tk for Python 3.x
from tkinter.filedialog import askopenfilename
from tkinter.filedialog import asksaveasfilename
from tabulate import tabulate
import art
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
# IMPORT FUNGSI YANG LAIN
from ambilmodel import ambilmodel
from buatmodel import buatmodel
from plotforward import plotforward
def main():
con = True
print('================================')
art.tprint('FORWARD \n MODELLING')
while con:
print('================================')
print('MENU FORWARD MODELLING')
print('Opsi:')
print('\t1. Open File')
print('\t2. Save Data')
print('\t3. Proses data')
print('\t4. Lihat Plot')
print('\t5. Properti Model')
print('================================')
opsi = int(input('Masukan pilihan yang diinginkan (keluar: 0): '))
if opsi == 0: #keluar
print('Keluar dari program...')
con = False
elif opsi == 1: # open file
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file
try:
print('Loading model...')
data, fdata = ambilmodel(filename)
# print(f'data = {data}')
# print(f'fdata = {fdata}')
print('STATUS: Model sudah dimasukkan.')
except:
pass
elif opsi == 2: # Save File
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
ftypes = [('Text document', '.txt')]
savefilename = asksaveasfilename(defaultextension=".txt", filetypes=ftypes, title='Save Data Hasil')
print(savefilename)
try:
writedata = [f'{_[0]:.6f}\t{_[1]:.6f}\t{_[2]:.6f}\n' for _ in np.transpose([fdata.frekuensi, rhoapp, fasa])]
print(writedata)
with open(savefilename, 'w') as f:
f.write('frekuensi\t Apparent Resistivity\t Fasa\n')
for wd in writedata:
f.write(wd)
pass
pass
except:
print('Error: Failed to save data')
pass
elif opsi == 3: # Proses Data
try:
rhop, kedalaman = buatmodel(data)
rhop = [float(_) for _ in rhop]
kedalaman = [float(_) for _ in kedalaman]
except:
print('ERROR: DATA BELUM ADA!')
try:
rhoapp, fasa, saturasi = plotforward(data, fdata, kedalaman, rhop)
#print(f'rhoapp = {rhoapp}')
#print(f'fasa = {fasa}')
except:
print('ERROR: PLOTFORWARD')
elif opsi == 4: # PLOT DATA
fig = plt.figure(constrained_layout=True)
gs = fig.add_gridspec(2,2)
ax1 = fig.add_subplot(gs[0,0])
ax2 = fig.add_subplot(gs[1,0])
ax3 = fig.add_subplot(gs[:,1])
#ax4 = fig.add_subplot(gs[:,2])
ax1.plot(fdata.frekuensi, rhoapp, 'r-', linewidth=3)
ax1.set_yscale('log')
ax1.set_xscale('log')
ax1.set_title('Apparent Resistivity')
ax1.set_xlabel('frekuensi (Hz)')
ax1.set_ylabel(r'$\rho_a$ ($\Omega$m)')
ax1.grid(True)
ax1.invert_xaxis()
ax1.set_xlim(min(fdata.frekuensi)/2, max(fdata.frekuensi))
ax1.set_ylim(min(rhoapp)/5, max(rhoapp)*5)
ax2.plot(fdata.frekuensi, fasa, 'r-', linewidth=3)
#ax2.set_yscale('log')
ax2.plot(fdata.frekuensi, np.ones(len(fdata.frekuensi))*45, 'k--', linewidth=5)
ax2.set_xscale('log')
ax2.set_title('Fasa')
ax2.set_xlabel('frekuensi (Hz)')
ax2.set_ylabel(r'$\phi$ ($\circ$)')
ax2.set_xlim(min(fdata.frekuensi)/2, max(fdata.frekuensi))
ax2.set_ylim(0, 90)
ax2.invert_xaxis()
ax2.grid(True)
ax3.plot(rhop, kedalaman, 'r-', linewidth=3)
ax3.set_xscale('log')
ax3.set_ylabel('Kedalaman (m)')
ax3.set_xlabel(r'Resistivity ($\Omega$m)')
ax3.set_xlim(min(rhop)/5, max(rhop)*5)
if len(kedalaman)>2:
ax3.set_ylim(0, max([abs(_) for _ in kedalaman[:-1]])*1.2)
ax3.invert_yaxis()
ax3.grid(True)
ax3.set_title('Respon Resistivitas')
# ax4.plot(saturasi, kedalaman, 'r-', linewidth=3)
# ax4.set_xscale('log')
# ax4.set_ylabel('Kedalaman (m)')
# ax4.set_xlabel('Saturasi')
# ax4.set_xlim(min(saturasi)/5, max(saturasi)*5)
# if len(kedalaman)>2:
# ax4.set_ylim(0, max([abs(_) for _ in kedalaman[:-1]])*1.2)
# ax4.invert_yaxis()
# ax4.grid(True)
plt.tight_layout()
plt.show(block=False)
elif opsi == 5: #properti model
try:
print('MODEL PROPERTI')
print(f'Rentang Frekuensi: {min(fdata.frekuensi)} - {max(fdata.frekuensi)}')
modelprop = data
modelprop[-1][2] = 'homogeneus halfspace'
print(tabulate(modelprop, headers=['No', 'Resistivity', 'Ketebalan']))
except:
print('ERROR: Model Properti')
pass
if __name__ == '__main__':
main()