-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinv_dist_perm_linux_kNN2.py
201 lines (142 loc) · 7.35 KB
/
inv_dist_perm_linux_kNN2.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
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a script file.
"""
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import math
# =============================================================================
# # ===========================================================================
# # #--------------------------------------------------------------------------
# # #
# # # Read in CMR log data
# # #
# # #--------------------------------------------------------------------------
# # ===========================================================================
# =============================================================================
NMR_data = pd.read_csv('CMR.csv')
Dep = NMR_data['DEPTH']
Por = NMR_data['CMRP_3MS']
Cmff = NMR_data['CMFF']
#Bvi = NMR_data['BVI']
# =============================================================================
# # ===========================================================================
# # #--------------------------------------------------------------------------
# # # Read/Write Reference data (_r) using Excel spreadsheet
# # # Read in Core and NMR data which has Core Kair and Cpor
# # #--------------------------------------------------------------------------
# # ===========================================================================
# =============================================================================
core_NMR_data = pd.read_csv('RSWC_CMR.csv')
#core_NMR_data = pd.read_csv('RSWC_CMR.csv').to_numpy
# for index, row in core_NMR_data.iterrows():
# print(row['DEPTH'], row['Kair'], row['Cpor'])
Dep_r = core_NMR_data['DEPTH']
Por_r = core_NMR_data['CMRP_3ms']
Cmff_r = core_NMR_data['CMFF']
Bvi_r = core_NMR_data['BVI']
Kair_r = core_NMR_data['Kair']
Porosity_r = core_NMR_data['Cpor']
# =============================================================================
# # ===========================================================================
# # #--------------------------------------------------------------------------
# ##
# ## This is the beginnin of Inverse Distance^2
# ##
# # #--------------------------------------------------------------------------
# # ===========================================================================
# =============================================================================
# Min and Max of Porosity data used in normalization
Por_max = 0.5
Por_min = 0.0
deptharray = []
permarray = []
porarray = []
inv_dist_array = []
distance_knn_array = []
for k in range(0,len(NMR_data) ,1):
# Normalize the log data of por and ffi
por = ((Por[k] - Por_min)/(Por_max - Por_min))
ffi = ((Cmff[k] - Por_min)/(Por_max - Por_min))
dist_inv = []
dist_phi = []
dist_ffi = []
Perm_weight = []
Por_r_norm = []
Cmff_r_norm = []
dist_inv_total = 0
Perm_total = 0
# this is the core reference data being used
for i in range(0,len(core_NMR_data),1):
# Normalize the core reference data of Por_r and Cmff_r
Por_r_norm.append((Por_r[i] - Por_min)/(Por_max - Por_min))
Cmff_r_norm.append((Cmff_r[i] - Por_min)/(Por_max - Por_min))
# Compute Euclidian Distance inverse distance
dist_phi.append(abs(por - Por_r_norm[i]))
dist_ffi.append(abs(ffi - Cmff_r_norm[i]))
dist_inv.append(1/(math.sqrt(dist_phi[i]**2 + dist_ffi[i]**2) + 0.0000001))
# Calculalte inverse distance weights for perm
Perm_weight.append(dist_inv[i] * Kair_r[i])
inv_dist_array.append(dist_inv[i]); # add items
# =============================================================================
### KNN Array
# # ===========================================================================
# # #--------------------------------------------------------------------------
distance_knn_array = [dist_inv, Perm_weight]
#
# # #--------------------------------------------------------------------------
# # ===========================================================================
# =============================================================================
xnorm=np.array(Por_r)
ynorm=np.array(Cmff_r)
# =============================================================================
# # ===========================================================================
# # #--------------------------------------------------------------------------
# # #
# # # Transpose and Sort new kNN array
# # #
# # #--------------------------------------------------------------------------
# # ===========================================================================
# =============================================================================
#knn_array = np.transpose array
knn_array = np.transpose(distance_knn_array)
#matsor x[x[:,column].argsort()[::-1]] and -1 us reverse order
mat_sort = knn_array[knn_array[:,0].argsort()[::-1]] #firt column reverse sort (-1)
# =============================================================================
# # ===========================================================================
# # #--------------------------------------------------------------------------
# # #
# # # Calculate knn Thomeer Parameters
# # #
# # #--------------------------------------------------------------------------
# # ===========================================================================
# =============================================================================
#------------------------------------------------------------------------------
# Number of nearest Neighbors
#------------------------------------------------------------------------------
n_neighbors = 3
#------------------------------------------------------------------------------
dist_inv_total_knn = 0
Perm_total_knn = 0
#kNN Estimates for first 3 rows
for i in range(0,n_neighbors,1):
dist_inv_total_knn = dist_inv_total_knn + mat_sort[i][0]
Perm_total_knn = Perm_total_knn + mat_sort[i][1]
#back to k values and calculate estimations now
Perm_est_knn = Perm_total_knn / dist_inv_total_knn
deptharray.append(Dep[k]); #add items
permarray.append(Perm_est_knn); #add items
x=np.array(permarray)
y=np.array(deptharray)
plt.figure(figsize=(8,11))
plt.semilogx(x, y)
plt.semilogx(Kair_r, Dep_r, 'ro')
plt.xlim(0.01, 10000)
plt.gca().invert_yaxis()
plt.title("Permeability Estimation using kNN")
plt.ylabel('Depth (feet)')
plt.xlabel('kNN Estimated Perm')
plt.grid(True)
plt.show()