This repository has been archived by the owner on Feb 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGriftpark_Model_half_extraction.py
281 lines (255 loc) · 9.33 KB
/
Griftpark_Model_half_extraction.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# Importing packages
from pathlib import Path # Filepath maniputlation
import flopy
import fiona
import gstools # GeoStat-tools
import matplotlib.path as mpth
import matplotlib.pyplot as plt
import numpy as np # Numeric array manipulation
import pandas as pd
import scipy.ndimage as si # Numpy array manipulation
# Local utility functions and definitions
from plot_tools import plot_model, xs_lines
from run_tools import run_flow_model, run_transport
from utils import StressPeriod
# Name and location
modelname = "Griftpark_halfQ"
model_workspace = Path(modelname)
model_output_dir = Path("output/halfQ")
if not model_output_dir.exists():
model_output_dir.mkdir()
layer_boundaries = [2.5, -2.5, -7.5, -32.5, -50, -60, -100]
n_sublayers = [1, 2, 10, 7, 4, 5]
wvp = np.repeat([1, 1, 1, 1, 2, 2], n_sublayers)
kh_park = np.repeat([10, 20, 80, 40, 1, 50], n_sublayers)
kh_buiten = np.repeat([1, 20, 80, 40, 1, 50], n_sublayers)
kv_park = np.repeat([1, 2, 8, 4, 10 / 100, 5], n_sublayers)
kv_buiten = np.repeat([0.1, 2, 8, 4, 10 / 2000, 5], n_sublayers)
x_zones = [136600, 137000, 137090, 137350, 137450, 138000]
ncol_zones = [8, 9, 52, 10, 11]
y_zones = [455600, 456550, 456670, 457170, 457250, 458200]
nrow_zones = [19, 12, 100, 8, 19]
model_extent = np.array(
[(min(x_zones), min(y_zones)), (max(x_zones), max(y_zones))],
dtype=[("X", np.float), ("Y", np.float)],
)
x_vertices = np.unique(
np.hstack(
[
np.linspace(x0, x1, nc + 1)
for x0, x1, nc in zip(x_zones[:-1], x_zones[1:], ncol_zones)
]
)
)
col_width = np.diff(x_vertices)
x = x_vertices[:-1] + col_width / 2
y_vertices = np.unique(
np.hstack(
[
np.linspace(y0, y1, nr + 1)
for y0, y1, nr in zip(y_zones[:-1], y_zones[1:], nrow_zones)
]
)
)[::-1]
row_height = -np.diff(y_vertices)
y = y_vertices[1:] + row_height / 2
x, y = np.meshgrid(x, y)
nov = pd.read_csv("data/neerslagoverschot.csv", index_col=0)
startjaar = 2019
nov.loc[startjaar, "NOV"] = nov.loc[nov.index <= startjaar, "NOV"].mean()
nov = nov.loc[startjaar:]
# stress_periods = [
# StressPeriod(
# period_length=(pd.Timestamp(f"{j+1}0401") - pd.Timestamp(f"{j}0401")).days,
# n_steps=(j == startjaar) + 12 * (j > startjaar),
# step_multiplier=1,
# steady_state=j == nov.index[0],
# )
# for j in nov.index
# ]
stress_periods = [
StressPeriod(
period_length=30 * 365, n_steps=1, step_multiplier=1, steady_state=True
)
]
with fiona.open("data/aquifers.shp") as src:
aquifers = list(src)
ibounds = np.ones((len(aquifers), *x.shape), dtype=np.bool)
const_heads = np.ones((len(aquifers), *x.shape), dtype=np.bool)
for ia, aq in enumerate(aquifers):
aq_path = mpth.Path(aq["geometry"]["coordinates"][0])
inside_aq = aq_path.contains_points(np.vstack((x.ravel(), y.ravel())).T)
inside_aq = np.reshape(inside_aq, x.shape)
ibounds[ia] = inside_aq
const_heads[ia] = ~inside_aq & ~si.binary_erosion(~inside_aq, border_value=False)
seed = gstools.random.MasterRNG(20190517)
with fiona.open("data/location_wells.shp", "r") as wellshp:
wells = [f["geometry"]["coordinates"] for f in wellshp]
with fiona.open("data/resistive_wall.shp", "r") as shapefile:
wall = [f["geometry"] for f in shapefile]
wall_path = mpth.Path(wall[0]["coordinates"][0])
inside_wall = wall_path.contains_points(np.vstack((x.ravel(), y.ravel())).T)
inside_wall = np.reshape(inside_wall, x.shape)
wall_mask = inside_wall & ~si.binary_erosion(inside_wall, border_value=False)
outside_wall_mask = ~inside_wall & ~si.binary_erosion(~inside_wall, border_value=True)
wall_mask_row, wall_mask_col = np.where(wall_mask)
hfb_conductance = 1 / 1000
hfb_data = []
for r, c in zip(wall_mask_row, wall_mask_col):
if outside_wall_mask[r, c - 1]:
# West boundary
for l in range(sum(wvp == 1)):
hfb_data.append([l, r, c - 1, r, c, hfb_conductance])
if outside_wall_mask[r, c + 1]:
# East boundary
for l in range(sum(wvp == 1)):
hfb_data.append([l, r, c, r, c + 1, hfb_conductance])
if outside_wall_mask[r - 1, c]:
# North boundary
for l in range(sum(wvp == 1)):
hfb_data.append([l, r - 1, c, r, c, hfb_conductance])
if outside_wall_mask[r + 1, c]:
# South boundary
for l in range(sum(wvp == 1)):
hfb_data.append([l, r, c, r + 1, c, hfb_conductance])
model_config = {
"layers": {
"boundaries": layer_boundaries,
"n_sublayers": n_sublayers,
"aquifer": wvp,
},
"grid": {
"extent": model_extent,
"col_width": col_width,
"row_height": row_height,
"x": x,
"y": y,
},
"time": {"startjaar": startjaar, "stress_periods": stress_periods},
"flow": {
"ibound": ibounds,
"const_heads": const_heads,
"generator": {"active": False, "seed": seed},
"k_h": {"regional": kh_buiten, "park": kh_park},
"k_v": {"regional": kv_buiten, "park": kv_park},
},
"wall": {"inside_wall": inside_wall, "hfb_data": hfb_data},
"wells": {"locations": wells, "discharge": -5 * 24 / len(wells)},
"recharge": nov,
}
mf = run_flow_model(modelname, model_workspace, model_config)
init_conc_PAH = np.zeros((mf.dis.nlay, mf.dis.nrow, mf.dis.ncol), dtype=np.float)
init_conc_cyanide = np.zeros((mf.dis.nlay, mf.dis.nrow, mf.dis.ncol), dtype=np.float)
with fiona.open("data/cyanide/cyanide_0_5.shp") as src:
contours = [mpth.Path(f["geometry"]["coordinates"][0]) for f in src]
init_conc_cyanide[0, :, :] = np.reshape(
np.sum(
np.vstack(
[
contour.contains_points(np.vstack((x.ravel(), y.ravel())).T)
for contour in contours
]
),
axis=0,
),
x.shape,
)
with fiona.open("data/PAK/PAK_0_5.shp") as src:
contours = [mpth.Path(f["geometry"]["coordinates"][0]) for f in src]
init_conc_PAH[0, :, :] = np.reshape(
np.sum(
np.vstack(
[
contour.contains_points(np.vstack((x.ravel(), y.ravel())).T)
for contour in contours
]
),
axis=0,
),
x.shape,
)
with fiona.open("data/PAK/PAK_5_15.shp") as src:
for contour in src:
# print(contour["properties"]["diepte"])
contour_path = mpth.Path(contour["geometry"]["coordinates"][0])
in_contour = contour_path.contains_points(np.vstack((x.ravel(), y.ravel())).T)
in_contour = np.reshape(in_contour, x.shape)
icr, icc = np.where(in_contour)
# print(layer_boundaries[0] - contour["properties"]["diepte"])
for r, c in zip(icr, icc):
l_top = mf.dis.get_layer(r, c, -2.51)
l_bottom = mf.dis.get_layer(
r, c, layer_boundaries[0] - contour["properties"]["diepte"] + 0.01
)
for l in range(l_top, l_bottom + 1):
init_conc_PAH[l, r, c] = 1
with fiona.open("data/PAK/PAK_15_23.shp") as src:
for contour in src:
contour_path = mpth.Path(contour["geometry"]["coordinates"][0])
in_contour = contour_path.contains_points(np.vstack((x.ravel(), y.ravel())).T)
in_contour = np.reshape(in_contour, x.shape)
icr, icc = np.where(in_contour)
for r, c in zip(icr, icc):
l_top = mf.dis.get_layer(r, c, -12.51)
l_bottom = mf.dis.get_layer(r, c, -20.49)
for l in range(l_top, l_bottom + 1):
init_conc_PAH[l, r, c] = 1
model_config["transport"] = {
"initial_conc": {"cyanide": init_conc_cyanide, "PAH": init_conc_PAH}
}
# mt = run_transport(mf, model_config)
mt = flopy.mt3d.Mt3dms.load(model_workspace / f"{modelname}_mt.nam")
plot_model(mf, mt, model_output_dir)
hds_file = flopy.utils.HeadFile(model_workspace / f"{modelname}.hds")
heads = hds_file.get_data()
cbc_file = flopy.utils.CellBudgetFile(model_workspace / f"{modelname}.cbc")
frf = cbc_file.get_data(text="FLOW RIGHT FACE")[0]
fff = cbc_file.get_data(text="FLOW FRONT FACE")[0]
flf = cbc_file.get_data(text="FLOW LOWER FACE")[0]
xs_lines_full = {
"A-A'": {
"line": {
"column": mf.dis.get_rc_from_node_coordinates(
*xs_lines["A-A'"]["line"]["line"][0], local=False
)[1]
},
"extent": (1000, 1600, -100, 2.5),
},
"B-B'": {
"line": {
"row": mf.dis.get_rc_from_node_coordinates(
*xs_lines["B-B'"]["line"]["line"][0], local=False
)[0]
},
"extent": (400, 780, -100, 2.5),
},
"C-C'": {
"line": {
"row": mf.dis.get_rc_from_node_coordinates(
*xs_lines["C-C'"]["line"]["line"][0], local=False
)[0]
},
"extent": (450, 780, -100, 2.5),
},
}
for line_title, xs_line in xs_lines_full.items():
fig, ax = plt.subplots(figsize=(16, 8))
ax.set_title(f"Head and flow vectors on transect {line_title}")
pxs = flopy.plot.PlotCrossSection(model=mf, ax=ax, **xs_line)
pxs.plot_grid(linewidths=0.5, alpha=0.5)
c = pxs.plot_array(heads, head=heads, masked_values=[-999.99])
plt.colorbar(c, ax=ax)
pxs.plot_bc("WEL")
pxs.plot_discharge(
frf=frf,
fff=fff,
flf=flf,
head=heads,
color="#ffffff",
normalize=True,
hstep=1,
kstep=1,
)
fig.tight_layout()
fig.savefig(model_output_dir / f"crosssection_flows_{line_title[0]}.png")
plt.close(fig)