-
Notifications
You must be signed in to change notification settings - Fork 2
/
raw_pet_load_coarsen_kaolin.py
380 lines (304 loc) · 14.2 KB
/
raw_pet_load_coarsen_kaolin.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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 9 11:25:15 2021
@author: Czahasky
"""
# Only packages called in this script need to be imported
import os
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import scipy
from scipy import integrate
mpl.rcParams['figure.dpi'] = 300
plt.rcParams["font.family"] = "Times New Roman"
plt.rcParams.update({'font.size': 10})
# load data
# filename = '02May2022_F18_45min_1mL_ottawa_32_32_159_45.raw'
# img_dim = [32, 32, 159, 45]
# filename = '64Cu_55min_1mL_highSaline_kaolinite_32_32_159_55.raw'
# img_dim = [32, 32, 159, 55]
path2data = "C:\\Users\\colli\\Documents\\Research\\Manuscripts\\Kaolinite Multivalent Cations\\manuscript_data\\ottawaSand_kaolinite_PET_data\\" # VY PC - for May2022 exp
filename ='64Cu_120min_low_saline_transition_32_32_159_60.raw'
img_dim = [32, 32, 159, 60] #full PET
vox_size = [0.07763, 0.07763, 0.0796]
timestep_size = 60 # seconds
# timestep_size = 120 # seconds
# (easiest to just check in FIJI)
end_slice_locations = [27, 147]
def plot_2d(map_data, dx, dy, colorbar_label, cmap, *args):
r, c = np.shape(map_data)
x_coord = np.linspace(0, dx*c, c+1)
y_coord = np.linspace(0, dy*r, r+1)
X, Y = np.meshgrid(x_coord, y_coord)
# fig, ax = plt.figure(figsize=(10, 10) # adjust these numbers to change the size of your figure
# ax.axis('equal')
# fig2.add_subplot(1, 1, 1, aspect='equal')
# Use 'pcolor' function to plot 2d map of concentration
# Note that we are flipping map_data and the yaxis to so that y increases downward
plt.figure(figsize=(12, 4), dpi=200)
plt.pcolormesh(X, Y, map_data, cmap=cmap, shading = 'auto', edgecolor ='k', linewidth = 0.01)
plt.gca().set_aspect('equal')
# add a colorbar
cbar = plt.colorbar()
if args:
plt.clim(cmin, cmax)
# label the colorbar
cbar.set_label(colorbar_label)
# make colorbar font bigger
# cbar.ax.tick_params(labelsize= (fs-2))
# make axis fontsize bigger!
plt.tick_params(axis='both', which='major')
plt.xlim((0, dx*c))
plt.ylim((0, dy*r))
def coarsen_slices(array3d, coarseness):
array_size = array3d.shape
if len(array_size) ==3:
coarse_array3d = np.zeros((int(array_size[0]/coarseness), int(array_size[1]/coarseness), int(array_size[2]/coarseness)))
# for z in range(0, array_size[2]):
for z in range(0, int(array_size[2]/coarseness)):
sum_slices = np.zeros((int(array_size[0]/coarseness), int(array_size[1]/coarseness)))
for zf in range(0, coarseness-1):
array_slice = array3d[:,:, z*coarseness + zf]
# array_slice = array3d[:,:, z]
# coarsen in x-y plan
temp = array_slice.reshape((array_size[0] // coarseness, coarseness,
array_size[1] // coarseness, coarseness))
smaller_slice = np.mean(temp, axis=(1,3))
# record values for each slice to be averaged
sum_slices = sum_slices + smaller_slice
# after looping through slices to be averaged, calculate average and record values
coarse_array3d[:,:, z] = sum_slices/coarseness
elif len(array_size) == 4:
coarse_array3d = np.zeros((int(array_size[0]/coarseness),
int(array_size[1]/coarseness), int(array_size[2]/coarseness), int(array_size[3])))
print('coarsening data assuming time is 4th dimension, with no time averaging')
# loop through time
for t in range(0, int(array_size[3])):
for z in range(0, int(array_size[2]/coarseness)):
sum_slices = np.zeros((int(array_size[0]/coarseness), int(array_size[1]/coarseness)))
for zf in range(0, coarseness-1):
array_slice = array3d[:,:, z*coarseness + zf, t]
# array_slice = array3d[:,:, z]
# coarsen in x-y plan
temp = array_slice.reshape((array_size[0] // coarseness, coarseness,
array_size[1] // coarseness, coarseness))
smaller_slice = np.mean(temp, axis=(1,3))
# record values for each slice to be averaged
sum_slices = sum_slices + smaller_slice
# after looping through slices to be averaged, calculate average and record values
coarse_array3d[:,:, z, t] = sum_slices/coarseness
return coarse_array3d
raw_data = np.fromfile((path2data + '\\' + filename), dtype=np.float32)
raw_data = np.reshape(raw_data, (img_dim[3], img_dim[2], img_dim[1], img_dim[0]))
raw_data = np.transpose(raw_data, (2, 3, 1, 0))
# flip so that correctly oriented on slice plots with 0,0 in lower left
raw_data = np.flip(raw_data, axis=0)
# crop extra long timesteps
raw_data = raw_data[:,:,end_slice_locations[0]:end_slice_locations[1],:]
raw_data = np.flip(raw_data, axis=2)
coarse_PET = coarsen_slices(raw_data, 2)
coarse_PET = coarse_PET[:,:,:,:29]
colorbar_max = 0.05
plot_2d(raw_data[:,16,:,5], vox_size[1], vox_size[2], '[-]', cmap='viridis')
plt.clim(0.0, colorbar_max)
plot_2d(raw_data[:,:,10,5], vox_size[0], vox_size[1], '[-]', cmap='viridis')
plt.clim(0.0, colorbar_max)
plot_2d(coarse_PET[:,8,:,5], vox_size[1]*2, vox_size[2]*2, '[-]', cmap='viridis')
plt.clim(0.0, colorbar_max)
plot_2d(coarse_PET[:,:,5,5], vox_size[0]*2, vox_size[1]*2, '[-]', cmap='viridis')
plt.clim(0.0, colorbar_max)
# plot_2d(raw_data[15,:,46:120,-1], vox_size[0], vox_size[1], '[-]', cmap='viridis')
# plt.clim(0., 0.3)
## Define time array
time_array = np.arange(timestep_size/2, timestep_size*(img_dim[3]-2), timestep_size)
r,c,s,ts = raw_data.shape
z_coord = np.linspace(0, vox_size[2]*s, s)
#timesteps_to_plot = 60
timesteps_to_plot = 5 #for tracer
#timesteps_to_plot = 55 #for high saline
#timesteps_to_plot = 29 # for low saline
#tcolors = plt.cm.Greys(np.linspace(0,1,(timesteps_to_plot)))
tcolors = plt.cm.Reds(np.linspace(0,1,(timesteps_to_plot)))
#tcolors = plt.cm.Greys(np.linspace(0,1,(7)))
# Breakthrough curves
fig, axis = plt.subplots(1,1, figsize=(7,3), dpi=300)
ind = 0
# # loop through time and plot concentration profiles
# for ti in range(29, timesteps_to_plot):
# slice_average_concentration = np.sum(np.sum(raw_data[:,:,:, ti], axis=0), axis=0)
# plt.plot(z_coord, slice_average_concentration, color=tcolors[ind])
# ind +=1
# plt.xlabel('Distance from inlet [cm]')
# plt.title('High flow rate injection')
#pore volumes for time related x-axis for tracer
# poreV = np.linspace(0, time_array[-1]/60, 120)
# poreV = poreV/18.41
# loop through time and plot concentration profiles for tracer
#for ti in range(0, timesteps_to_plot,8):
# for ti in range(0, 44):
# slice_average_concentration = np.sum(np.sum(raw_data[:,:,:, ti], axis=0), axis=0)
# slice_average_concentration = slice_average_concentration
# pv = ti*2/18.41
# plt.plot(z_coord, slice_average_concentration, color=tcolors[ind+1], label='pv=%s' % pv)
# ind +=1
# plt.xlabel('Distance from inlet [cm]')
# plt.ylabel('Slice Average Radioconcentration')
# plt.title('Tracer injection')
# #plt.legend(prop={'size': 9})
# plt.savefig('tracerBTC.png', transparent=True)
# plt.close()
#####plots these specific lines
x = [0, 3, 9, 29]
labels1 = ["PV = 0", "PV = 0.22", 'PV = 0.49', "PV = 0.87"]
# loop through time and plot concentration profiles for tracer
ind = 0
for ti in x[:]:
slice_average_concentration = np.sum(np.sum(raw_data[:,:,:, ti], axis=0), axis=0)
slice_average_concentration = slice_average_concentration
pv = ti*2/18.41
# plt.plot(z_coord, slice_average_concentration, color=tcolors[ind+1], label='pv=%s' % pv)
plt.plot(z_coord, slice_average_concentration, color=tcolors[ind+1], label = labels1[ind])
ind +=1
plt.yscale("log")
plt.ylim(2.5, 1E3)
plt.xlabel('Distance from inlet [cm]')
#plt.ylabel('Slice Average Radioconcentration')
#plt.title('Radiotracer Injection')
plt.legend(loc='lower right', fontsize=12)
#plt.savefig('highSaline_may_BTC.png', transparent=True)
# plt.savefig('ottawa_PET_tracer_AGU2022.png', transparent=True)
plt.show(), plt.close()
# plt.legend()
a = (raw_data[:,:,:, -1])
from scipy import ndimage
cm = ndimage.center_of_mass(a)
fig, ax = plt.subplots(1,1)
colorbar_max = 0.05
# plot_2d(raw_data[:,16,:,5], vox_size[1], vox_size[2], '[-]', cmap='viridis')
# ax.imshow(raw_data[:,:,10,5])
# # plt.clim(0.0, colorbar_max)
# ax.scatter(cm[0], cm[1])
# plot_2d(raw_data[:,:,10,5], vox_size[0], vox_size[1], '[-]', cmap='viridis')
# plt.clim(0.0, colorbar_max)
ax.imshow(raw_data[:,16,:,29], origin = "lower")
# plt.clim(0.0, colorbar_max)
ax.scatter(cm[2], cm[0])
cmMM = 0.0796*cm[2]
# x = [3, 6, 12, 54]
# # loop through time and plot concentration profiles for tracer
# for ti in x[:]:
# slice_average_concentration = np.sum(np.sum(raw_data[:,:,:, ti], axis=0), axis=0)
# slice_average_concentration = slice_average_concentration
# pv = ti*2/18.41
# plt.plot(z_coord, slice_average_concentration, color=tcolors[ind+1], label='pv=%s' % pv)
# ind +=1
# plt.yscale("log")
# plt.xlabel('Distance from inlet [cm]')
# plt.ylabel('Slice Average Radioconcentration')
# plt.title('Radiolabeled Kaolinite + 100mM NaCl injection')
# #plt.savefig('highSaline_may_BTC.png', transparent=True)
# plt.show(), plt.close()
# # plt.legend()
# ind = 0
# x = [3, 6, 12, 59]
# # loop through time and plot concentration profiles for tracer
# for ti in x[:]:
# slice_average_concentration = np.sum(np.sum(raw_data[:,:,:, ti], axis=0), axis=0)
# slice_average_concentration = slice_average_concentration
# pv = ti*2/10.08
# plt.plot(z_coord, slice_average_concentration, color=tcolors[ind+1], label='pv=%s' % pv)
# ind +=1
# plt.yscale("log")
# plt.ylim(2.5, 1E3)
# plt.xlabel('Distance from inlet [cm]')
# plt.ylabel('Slice Average Radioconcentration')
# plt.title('1mM NaCl Transition Injection')
# #plt.savefig('highSaline_may_BTC.png', transparent=True)
# plt.show(), plt.close()
# plt.legend()
# plt.xlabel('Distance from inlet [cm]')
# plt.ylabel('Slice Average Radioconcentration')
# plt.title('Radiolabeled Kaolinite + 100mM NaCl injection')
# #plt.savefig('highSaline_may_BTC.png', transparent=True)
# plt.show(), plt.close()
####plot all tracer lines
# for ti in range(0, 44):
# slice_average_concentration = np.sum(np.sum(raw_data[:,:,:, ti], axis=0), axis=0)
# slice_average_concentration = slice_average_concentration
# pv = ti*2/18.41
# plt.plot(z_coord, slice_average_concentration, color=tcolors[ind+1], label='pv=%s' % pv)
# ind +=1
# plt.xlabel('Distance from inlet [cm]')
# plt.ylabel('Slice Average Radioconcentration')
# plt.title('Radiolabeled Kaolinite + 100mM NaCl injection')
# #plt.savefig('highSaline_may_BTC.png', transparent=True)
# plt.show(), plt.close()
# # plt.legend()
# loop through time and plot concentration profiles for low saline transition
# x = [3, 6, 12, 54]
# for ti in x[:]:
# slice_average_concentration = np.sum(np.sum(raw_data[:,:,:, ti], axis=0), axis=0)
# slice_average_concentration = slice_average_concentration/2
# pv = ti*2/10.08
# plt.plot(z_coord, slice_average_concentration, color=tcolors[ind+1], label='pv=%s' % pv)
# ind +=1
# plt.xlabel('Distance from inlet [cm]')
# plt.ylabel('Slice Average Radioconcentration')
# plt.title('1mM NaCl transition injection')
# plt.savefig('lowSaline_may_BTC.png', transparent=True)
# #plt.legend()
#####plot all lines
# plt.xlabel('Distance from inlet [cm]')
# plt.ylabel('Slice Average Radioconcentration')
# plt.title('Radiolabeled Kaolinite + 100mM NaCl injection')
# #plt.savefig('highSaline_may_BTC.png', transparent=True)
# plt.show(), plt.close()
# # plt.legend()
# # loop through time and plot concentration profiles for low saline transition
# for ti in range(0, 59):
# slice_average_concentration = np.sum(np.sum(raw_data[:,:,:, ti], axis=0), axis=0)
# slice_average_concentration = slice_average_concentration/2
# pv = ti*2/10.08
# plt.plot(z_coord, slice_average_concentration, color=tcolors[ind+1], label='pv=%s' % pv)
# ind +=1
# plt.xlabel('Distance from inlet [cm]')
# plt.ylabel('Slice Average Radioconcentration')
# plt.title('1mM NaCl transition injection')
# plt.savefig('lowSaline_may_BTC.png', transparent=True)
# #plt.legend()
# for ti in range(0, 3):
# slice_average_concentration = np.sum(np.sum(raw_data[:,:,:,ti], axis=0), axis=0)
# slice_average_concentration = slice_average_concentration/2
# pv = ti*2/10.08
# plt.plot(z_coord, slice_average_concentration, color=tcolors[ind+1], label='pv=%s' % pv)
# ind +=1
# plt.xlabel('Distance from inlet [cm]')
# plt.ylabel('Slice Average Radioconcentration')
# plt.title('1mM NaCl transition injection')
# plt.savefig('lowSaline_may_BTC.png', transparent=True)
# #plt.legend()
# axis[0].set_title('Homogeneous permeability')
# axis[0].set(ylabel='$C/C_0$ [-]',xlabel ='PV [-]')
# axis[0].set_ylim([0, 0.08])
# axis[0].set(ylabel='$C/C_0$ [-]',xlabel ='Time [minutes]', yscale='log')
# axis[0].set_ylim([1E-4, 1])
# axis[0].legend(loc ='upper right')
# ts = 60
# plot_2d(denoise3d[:,:,ts], vox_size[0], vox_size[1], 'denoise', cmap='viridis')
# plot_2d(raw_data[:,:,ts, -1], vox_size[0], vox_size[1], 'raw', cmap='viridis')
# plt.clim(400, 1600)
# data_size = Por.shape
# save_filename = 'D:\\Dropbox\\Codes\\Deep_learning\\Neural_network_inversion\\experimental_data_prep\\pet_data' + '\\' 'Navajo_porosity_coarsened.csv'
# save_data = np.append(Por.flatten('C'), [data_size, vox_size])
# np.savetxt(save_filename, save_data, delimiter=',')
# # # Breakthrough curves
# fig, axis = plt.subplots(1,1, figsize=(7,5), dpi=300)
# ind = 0
# # for i in range(img_dim[0]):
# i=7
# for j in range(img_dim[1]):
# btc = data[i,j,slice_test,:]
# smooth_data = signal.filtfilt(B,A, btc)
# plt.plot(time_array, smooth_data, color=tcolors[ind])
# ind +=1