-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
169 lines (119 loc) · 5.97 KB
/
main.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
from ert_pygimli_functions import *
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
df = pd.read_excel('/Users/bart/Documents/Indépendant/Geophy/24IRCH_Modeling.xlsx')
method = 'slm' # schlumberger
WennerSchlum = pd.read_table('WennerSchlum.txt')
exportFile(WennerSchlum, 2.5, 'Array.ohm')
i = 0
# make a loop that itarates through the columns of the dataframe
for column_name, item in df.items():
if i == 0:
i += 1
continue
if i == 3:
break
rhomap, geom = implement_geometry(df.iloc[: ,i])
model_id = column_name
rho_min = df.iloc[2:5, i].min()
rho_max = df.iloc[2:5, i].max()
scheme = pg.load('Array.ohm', verbose=True, testAll=False, realName=None)
mesh = create_mesh(scheme, geom, rhomap, quality = 30)
data = generate_data(mesh, scheme, rhomap)
filename = 'data_synth/ert_' + str(model_id) + '.dat'
save_data(data, filename)
manager = initialize_ERTMANAGER(path=f'data_synth/ert_{model_id}.dat')
# mesh_inv = mt.createMesh(quality=25)
inv = invert_data(data, mesh, manager)
meshPD = generate_meshPD(manager)
# manager.showResultAndFit()
import matplotlib.pyplot as plt
import matplotlib as mpl
# Create figure and subplots with adjusted size
fig = plt.figure(figsize=(12, 6))
gs = fig.add_gridspec(2, 2, width_ratios=[1, 2], height_ratios=[1, 1])
axs = {
'Left': fig.add_subplot(gs[:, 0]), # Left subplot spanning both rows
'TopRight': fig.add_subplot(gs[0, 1]), # Top-right subplot
'BottomRight': fig.add_subplot(gs[1, 1])# , sharex=fig.add_subplot(gs[0, 1])) # Bottom-right subplot sharing x-axis
}
# Plot data
pg.show(data, ax=axs['Left'], cMap="jet", logScale=False, cMin=rho_min, cMax=rho_max, colorBar=False)
axs['Left'].set_title('Synthetic Data (WS)')
# Plot initial model
pg.show(mesh, rhomap, ax=axs['TopRight'], hold=True, cMap="jet", logScale=False, colorBar = False, cMin=rho_min, cMax=rho_max)
axs['TopRight'].set_xlim([0, 180])
axs['TopRight'].set_ylim([-40, 0])
axs['TopRight'].set_title('True model')
# Plot inverse model
manager.showResult(ax=axs['BottomRight'], cMap="jet", logScale=False, cMin=rho_min, cMax=rho_max, colorBar=False)
axs['BottomRight'].set_xlim([0, 180])
axs['BottomRight'].set_ylim([-40, 0])
axs['BottomRight'].set_title('Inversion unstructured grid')
# Create an axes for the colorbar
cbar_ax = fig.add_axes([.92, 0.15, 0.02, 0.4])
# Create the colorbar
cmap = mpl.cm.jet
norm = mpl.colors.Normalize(vmin=rho_min, vmax=rho_max)
cb1 = mpl.colorbar.ColorbarBase(cbar_ax, cmap=cmap, norm=norm, orientation='vertical')
# Add a label to the colorbar
cb1.set_label('Resistivity (Ohm.m)', rotation=90, labelpad=10)
fig.suptitle('Model ID : ' + column_name + ' - WS, 72 electrodes, 2.5m spacing')
fig.savefig('figure_results/' + column_name + '.png')
plt.close(fig)
# fig = plt.figure(constrained_layout=True, figsize=(11, 5.5))
# axs = fig.subplot_mosaic([['Left', 'TopRight'],['Left', 'BottomRight']],
# gridspec_kw={'height_ratios':[1, 2]}, width_ratios=[1, 2])
# # Plot data
# pg.show(data, ax=axs['Left'], cMap="jet", logScale=False, cMin=rho_min, cMax=rho_max, colorBar = False)
# axs['Left'].set_title('Synthetic Data (WS)')
# # Plot initial model
# pg.show(mesh, rhomap, ax=axs['TopRight'], hold=True, cMap="jet", logScale=False, colorBar = False, cMin=rho_min, cMax=rho_max)
# axs['TopRight'].set_xlim([0, 180])
# axs['TopRight'].set_ylim([-40, 0])
# axs['TopRight'].set_title('True model')
# # Plot inverse model
# manager.showResult(ax=axs['BottomRight'], cMap="jet", logScale=False, cMin=rho_min, cMax=rho_max, colorBar = False)
# # pg.show(inv, ax=axs['BottomRight'], cMap="jet", logScale=False, cMin=rho_min, cMax=rho_max, colorBar = False)
# axs['BottomRight'].set_xlim([0, 180])
# axs['BottomRight'].set_ylim([-40, 0])
# axs['BottomRight'].set_title('Inversion unstructured grid')
# axs['TopRight'].sharex(axs['BottomRight'])
# # Create an axes for the colorbar
# cbar_ax = fig.add_axes([1.0, 0.15, 0.02, 0.6])
# # Create the colorbar
# cmap = mpl.cm.jet
# norm = mpl.colors.Normalize(vmin=rho_min, vmax=rho_max)
# cb1 = mpl.colorbar.ColorbarBase(cbar_ax, cmap=cmap, norm=norm, orientation='vertical')
# # Add a label to the colorbar
# cb1.set_label('Resistivity (Ohm.m)', rotation=90, labelpad=10)
# fig.suptitle('Model ID : '+column_name+ ' - WS, 72 electrodes, 2.5m spacing')
# # plt.tight_layout()
# fig.savefig('figure_results/'+column_name+'.png')
# plt.close(fig)
# fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True, sharey=True, figsize = ((12, 7)))
# pg.show(mesh, rhomap, ax=ax1, hold=True, cMap="jet", logScale=False, colorBar = False, orientation=None, cMin=rho_min, cMax=rho_max)
# ax1.set_xlim([-0, 180])
# ax1.set_ylim([-40, 0])
# manager.showResult(ax=ax2, cMap="jet", logScale=False, cMin=rho_min, cMax=rho_max, colorBar = False)
# # pg.show(meshPD, inv, ax=ax2, hold=True, cMap="jet", logScale=False, colorBar = False, cMin=rho_min, cMax=rho_max)
# ax2.set_xlim([-0, 180])
# ax2.set_ylim([-40, 0])
# ax1.set_title('True model')
# ax2.set_title('Inversion unstructured grid')
# # Create an axes for the colorbar
# cbar_ax = fig.add_axes([0.92, 0.25, 0.02, 0.4])
# # Create the colorbar
# cmap = mpl.cm.jet
# norm = mpl.colors.Normalize(vmin=rho_min, vmax=rho_max)
# cb1 = mpl.colorbar.ColorbarBase(cbar_ax, cmap=cmap, norm=norm, orientation='vertical')
# # Add a label to the colorbar
# cb1.set_label('Resistivity (Ohm.m)', rotation=90, labelpad=10)
# fig.suptitle('Model ID : '+column_name+ ' - WS, 72 electrodes, 2.5m spacing')
# # plt.tight_layout()
# # plt.axis('equal')
# fig.savefig('figure_results/'+column_name+'.png')
# plt.close(fig)
# # break
i += 1