├── 001_3DSeismic_Pyvista.py ├── 002_Read_LAS.py ├── 003_Read_LAS_VARHEAD.py ├── 004_Read_LAS_LASIO.py ├── 005_LAS2Sqlite.py ├── 006_ReadSqlite.py ├── 007_FbPick.py ├── 008_segy2sqlite.py ├── 009_Well_Viz_Filled.py ├── DATA ├── F02-1_logs.las ├── F03-2_logs.las ├── seismic.db ├── shot.sgy └── volve.npy └── requirements.txt /001_3DSeismic_Pyvista.py: -------------------------------------------------------------------------------- 1 | import pyvista as pv 2 | import numpy as np 3 | 4 | values = np.load('./DATA/volvesmall.npy') 5 | 6 | grid = pv.UniformGrid() 7 | grid.dimensions = values.shape 8 | grid.origin = (0, 0, 0) 9 | grid.spacing = (1, 1, 1) # These are the cell sizes along each axis 10 | grid.point_arrays["Amplitudes"] = values.flatten(order="F") 11 | 12 | slices = grid.slice_orthogonal(x=50, y=50, z=50) 13 | slices.plot(cmap='RdGy', clim=[-5, 5]) -------------------------------------------------------------------------------- /002_Read_LAS.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | filename='./DATA/F02-1_logs.las' 4 | data = np.loadtxt(filename,skiprows=35) 5 | data[data==-999.2500]=np.nan 6 | DEPTH= data[:,0] 7 | DENS = data[:,1] 8 | SONIC = data[:,2] 9 | GR = data[:,3] 10 | 11 | plt.subplot(1,3,1) #row-col-colth 12 | plt.plot(DENS,DEPTH,'b') 13 | plt.ylim(max(DEPTH),min(DEPTH)) 14 | plt.xlabel('Density [kg/m3]') 15 | plt.ylabel('Measured Depth [m]') 16 | 17 | plt.subplot(1,3,2) #row-col-colth 18 | plt.plot(SONIC,DEPTH,'r') 19 | plt.ylim(max(DEPTH),min(DEPTH)) 20 | plt.xlabel('Sonic [us/m]') 21 | plt.ylabel('Measured Depth [m]') 22 | 23 | plt.subplot(1,3,3) #row-col-colth 24 | plt.plot(GR,DEPTH,'g') 25 | plt.ylim(max(DEPTH),min(DEPTH)) 26 | plt.xlabel('GR [API]') 27 | plt.ylabel('Measured Depth [m]') 28 | plt.show() 29 | -------------------------------------------------------------------------------- /003_Read_LAS_VARHEAD.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | 4 | filename='./DATA/F03-2_logs.las' 5 | mark = '~A' 6 | with open(filename) as myFile: 7 | for z, line in enumerate(myFile, 1): 8 | if mark in line: 9 | data = np.loadtxt(filename, skiprows=z) 10 | data[data == -999.2500] = np.nan 11 | DEPTH = data[:, 0] 12 | DENS = data[:, 1] 13 | SONIC = data[:, 2] 14 | GR = data[:, 3] 15 | 16 | plt.subplot(1, 3, 1) # row-col-colth 17 | plt.plot(DENS, DEPTH, 'b') 18 | plt.ylim(max(DEPTH), min(DEPTH)) 19 | plt.xlabel('Density [kg/m3]') 20 | plt.ylabel('Measured Depth [m]') 21 | 22 | plt.subplot(1, 3, 2) # row-col-colth 23 | plt.plot(SONIC, DEPTH, 'r') 24 | plt.ylim(max(DEPTH), min(DEPTH)) 25 | plt.xlabel('Sonic [us/m]') 26 | plt.ylabel('Measured Depth [m]') 27 | 28 | plt.subplot(1, 3, 3) # row-col-colth 29 | plt.plot(GR, DEPTH, 'g') 30 | plt.ylim(max(DEPTH), min(DEPTH)) 31 | plt.xlabel('GR [API]') 32 | plt.ylabel('Measured Depth [m]') 33 | plt.show() 34 | -------------------------------------------------------------------------------- /004_Read_LAS_LASIO.py: -------------------------------------------------------------------------------- 1 | import lasio 2 | import matplotlib.pyplot as plt 3 | 4 | filename = './DATA/F02-1_logs.las' 5 | data = lasio.read(filename) 6 | data = data.df() 7 | 8 | DEPTH = list(data.index.values) 9 | DT = (list(data['DT'.strip()])) 10 | 11 | plt.plot(DT,DEPTH) 12 | plt.grid() 13 | plt.ylim(1500,250) 14 | plt.show() -------------------------------------------------------------------------------- /005_LAS2Sqlite.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import sqlite3 3 | 4 | filename='./DATA/F03-2_logs.las' 5 | data = np.loadtxt(filename,skiprows=35) 6 | wellname ='F03' 7 | 8 | conn = sqlite3.connect('well.db') 9 | cursor = conn.cursor() 10 | cursor.execute('CREATE TABLE IF NOT EXISTS %s (DEPTH real, RHOB real,DT real, GR real, AI real, AIr real, PHI real)'%wellname) 11 | conn.commit() 12 | 13 | cursor.executemany('INSERT INTO %s VALUES(?,?,?,?,?,?,?)' %wellname,map(tuple,data.tolist())) 14 | conn.commit() 15 | 16 | 17 | 18 | 19 | cursor.close() 20 | conn.close() -------------------------------------------------------------------------------- /006_ReadSqlite.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | import numpy as np 3 | import pandas as pd 4 | 5 | conn = sqlite3.connect('well.db') 6 | c = conn.cursor() 7 | c.execute('SELECT * FROM F02 WHERE DEPTH > 1000') 8 | 9 | data = [row for row in c] 10 | data = np.array(data) 11 | data[data==-999.2500]=np.nan 12 | 13 | data = pd.DataFrame(data,columns=['DEPTH', 'RHOB', 'DT', 'GR', 'AI', 'AIr', 'PHI']) 14 | print(data) 15 | -------------------------------------------------------------------------------- /007_FbPick.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import sqlite3 3 | from numpy import array 4 | import numpy as np 5 | 6 | filename = './DATA/seismic.db' 7 | conn = sqlite3.connect(filename) 8 | c = conn.cursor() 9 | c.execute('SELECT * FROM mytable WHERE value3 =10') 10 | traces = [row[60:561] for row in c] 11 | traces=(array(traces)).T 12 | 13 | 14 | pol = 'Trough' 15 | 16 | if pol == 'Peak': 17 | template = np.concatenate([[0] * 8, [1] * 1, [0] * 8]) # [1] if peak [-1] if through 18 | elif pol == 'Trough': 19 | template = np.concatenate([[0] * 8, [-1] * 1, [0] * 8]) # [1] if peak [-1] if through 20 | elif pol == 'None': 21 | template = np.concatenate([[0] * 8, [1] * 1, [0] * 8]) # [1] if peak [-1] if through 22 | 23 | traces0=traces[:,0] 24 | time = np.linspace(0,len(traces0)-1,len(traces0))*0.004 25 | 26 | 27 | 28 | par4 = 0.1 29 | df=[] 30 | for i in range(60): 31 | trac=traces[:,i] 32 | trac = (trac - trac.mean()) / trac.std() 33 | try: 34 | corr_res = np.correlate(trac, template, mode='same') 35 | corr_res = corr_res / max(abs(corr_res)) 36 | x = np.arange(len(corr_res))[abs(corr_res) > par4] 37 | yf = x[0] 38 | except: 39 | yf = 0 40 | plt.plot(1000 * i + traces[:,i], time, 'k') 41 | plt.plot(1000 * i + 0, yf*0.004, 'r.') 42 | plt.ylim(2,0) 43 | plt.show() 44 | -------------------------------------------------------------------------------- /008_segy2sqlite.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import os 3 | import sqlite3 4 | import pyprind 5 | 6 | segy_binary_header_dtype = np.dtype([ 7 | ('binhdr1', '>i4'), 8 | ('binhdr2', '>i4'), 9 | ('binhdr3', '>i4'), 10 | ('binhdr4', '>i2'), 11 | ('binhdr5', '>i2'), 12 | ('binhdr6', '>u2'), 13 | ('binhdr7', '>u2'), 14 | ('binhdr8', '>u2'), 15 | ('binhdr9' , '>u2'), 16 | ('binhdr10' , '>i2'), 17 | ('binhdr11', '>i2'), 18 | ('binhdr12', '>i2'), 19 | ('binhdr13', '>i2'), 20 | ('binhdr14', '>i2'), 21 | ('binhdr15', '>i2'), 22 | ('binhdr16', '>i2'), 23 | ('binhdr17', '>i2'), 24 | ('binhdr18', '>i2'), 25 | ('binhdr19', '>i2'), 26 | ('binhdr20', '>i2'), 27 | ('binhdr21', '>i2'), 28 | ('binhdr22', '>i2'), 29 | ('binhdr23', '>i2'), 30 | ('binhdr24', '>i2'), 31 | ('binhdr25', '>i2'), 32 | ('binhdr26', '>i2'), 33 | ('binhdr27', '>i2'), 34 | ('binhdr28', '>i2'), 35 | ('binhdr29', '>i2'), 36 | ('binhdr30', '>i2'), 37 | ('binhdr31', '>i2'), 38 | ('binhdr32', '>i2'), 39 | ('binhdr33', '>i4'), 40 | ('binhdr34', '>i4'), 41 | ('binhdr35', '>i4'), 42 | ('binhdr36', '>i4'), 43 | ('binhdr37', '>i4'), 44 | ('binhdr38', '>i4'), 45 | ('binhdr39', '>i4'), 46 | ('binhdr40', '>i4'), 47 | ('binhdr41', '>i4'), 48 | ('binhdr42', '>i4'), 49 | ('binhdr43', '>i4'), 50 | ('binhdr44', '>i4'), 51 | ('binhdr45', '>i4'), 52 | ('binhdr46', '>i4'), 53 | ('binhdr47', '>i4'), 54 | ('binhdr48', '>i4'), 55 | ('binhdr49', '>i4'), 56 | ('binhdr50', '>i4'), 57 | ('binhdr51', '>i4'), 58 | ('binhdr52', '>i4'), 59 | ('binhdr53', '>i4'), 60 | ('binhdr54', '>i4'), 61 | ('binhdr55', '>i4'), 62 | ('binhdr56', '>i4'), 63 | ('binhdr57', '>i4'), 64 | ('binhdr58', '>i4'), 65 | ('binhdr59', '>i4'), 66 | ('binhdr60', '>i4'), 67 | ('binhdr61', '>i4'), 68 | ('binhdr62', '>i4'), 69 | ('binhdr63', '>i4'), 70 | ('binhdr64', '>i4'), 71 | ('binhdr65', '>i4'), 72 | ('binhdr66', '>i4'), 73 | ('binhdr67', '>i4'), 74 | ('binhdr68', '>i4'), 75 | ('binhdr69', '>i4'), 76 | ('binhdr70', '>i4'), 77 | ('binhdr71', '>i4'), 78 | ('binhdr72', '>i4'), 79 | ('binhdr73', '>i4'), 80 | ('binhdr74', '>i4'), 81 | ('binhdr75', '>i4'), 82 | ('binhdr76', '>i4'), 83 | ('binhdr77', '>i4'), 84 | ('binhdr78', '>i4'), 85 | ('binhdr79', '>i4'), 86 | ('binhdr80', '>i4'), 87 | ('binhdr81', '>i4'), 88 | ('binhdr82', '>i4'), 89 | ('binhdr83', '>i4'), 90 | ('binhdr84', '>i4'), 91 | ('binhdr85', '>i4'), 92 | ('binhdr86', '>i4'), 93 | ('binhdr87', '>i4'), 94 | ('binhdr88', '>i4'), 95 | ('binhdr89', '>i4'), 96 | ('binhdr90', '>i4'), 97 | ('binhdr91', '>i4'), 98 | ('binhdr92', '>i4'), 99 | ('binhdr93', '>i4'), 100 | ('binhdr94', '>i4'), 101 | ('binhdr95', '>i4'), 102 | ('binhdr96', '>i4'), 103 | ('binhdr97', '>i4'), 104 | ('binhdr98', '>i4'), 105 | ('binhdr99', '>i4'), 106 | ('binhdr100', '>i4'), 107 | ('binhdr101', '>i4'), 108 | ('binhdr102', '>i4'), 109 | ('binhdr103', '>i4'), 110 | ('binhdr104', '>i4'), 111 | ('binhdr105', '>i4'), 112 | ('binhdr106', '>i4'), 113 | ('binhdr107', '>i4'), 114 | ('binhdr108', '>i4'), 115 | ('binhdr109', '>i4'), 116 | ('binhdr110', '>i4'), 117 | ('binhdr111', '>i4'), 118 | ('binhdr112', '>i4'), 119 | ('binhdr113', '>i4'), 120 | ('binhdr114', '>i4'), 121 | ('binhdr115', '>i2'), 122 | ]) 123 | segy_trace_header_dtype = np.dtype([ 124 | ('th1', '>i4'), 125 | ('th2', '>i4'), 126 | ('th3', '>i4'), 127 | ('th4', '>i4'), 128 | ('th5', '>i4'), 129 | ('th6', '>i4'), 130 | ('th7', '>i4'), 131 | ('th8', '>i4'), 132 | ('th9', '>i4'), 133 | ('th10', '>i4'), 134 | ('th11', '>i4'), 135 | ('th12', '>i4'), 136 | ('th13', '>i4'), 137 | ('th14', '>i4'), 138 | ('th15', '>i4'), 139 | ('th16', '>i4'), 140 | ('th17', '>i4'), 141 | ('th18', '>i4'), 142 | ('th19', '>i4'), 143 | ('th20', '>i4'), 144 | ('th21', '>i4'), 145 | ('th22', '>i4'), 146 | ('th23', '>i4'), 147 | ('th24', '>i4'), 148 | ('th25', '>i4'), 149 | ('th26', '>i4'), 150 | ('th27', '>i4'), 151 | ('th28', '>i4'), 152 | ('th29', '>i4'), 153 | ('th30', '>i4'), 154 | ('th31', '>i4'), 155 | ('th32', '>i4'), 156 | ('th33', '>i4'), 157 | ('th34', '>i4'), 158 | ('th35', '>i4'), 159 | ('th36', '>i4'), 160 | ('th37', '>i4'), 161 | ('th38', '>i4'), 162 | ('th39', '>i4'), 163 | ('th40', '>i4'), 164 | ('th41', '>i4'), 165 | ('th42', '>i4'), 166 | ('th43', '>i4'), 167 | ('th44', '>i4'), 168 | ('th45', '>i4'), 169 | ('th46', '>i4'), 170 | ('th47', '>i4'), 171 | ('th48', '>i4'), 172 | ('th49', '>i4'), 173 | ('th50', '>i4'), 174 | ('th51', '>i4'), 175 | ('th52', '>i4'), 176 | ('th53', '>i4'), 177 | ('th54', '>i4'), 178 | ('th55', '>i4'), 179 | ('th56', '>i4'), 180 | ('th57', '>i4'), 181 | ('th58', '>i4'), 182 | ('th59', '>i4'), 183 | ('th60', '>i4'), 184 | ]) 185 | 186 | 187 | def read_EBCDIC(_file): 188 | with open(_file,'rb') as f: 189 | header = np.fromfile(f, dtype='u2', count=int(3200/2)) 190 | if np.any(np.diff(header)): 191 | f.seek(0) 192 | return f.read(3200).decode('EBCDIC-CP-BE').encode('ascii') 193 | else: 194 | return None 195 | 196 | def read_bheader(_file): 197 | with open(_file, 'rb') as f: 198 | f.seek(3200) 199 | binary = np.frombuffer(f.read(400), dtype=segy_binary_header_dtype) 200 | try: 201 | assert 0 < binary ['binhdr10'] < 9 202 | except AssertionError: 203 | binary = binary.byteswap() 204 | return binary 205 | 206 | def num_traces(_file, ns): 207 | with open(_file, 'rb') as f: 208 | f.seek(0, os.SEEK_END) 209 | size = f.tell() 210 | nt = (size - 3600.0) / (240.0 + ns * 4.0) 211 | assert nt % 1 == 0 212 | return nt 213 | 214 | 215 | from struct import Struct 216 | class StructIBM32(object): 217 | def __init__(self,size): 218 | self.p24 = float(pow(2,24)) 219 | self.unpack32int = Struct(">%sL" %size).unpack 220 | self.unpackieee = Struct(">%sf" % size).unpack 221 | def unpackibm(self,data): 222 | int32 = self.unpack32int(data) 223 | return [self.ibm2ieee(i) for i in int32] 224 | def unpackieee(self,data): 225 | ieee = self.unpackieee(data) 226 | return ieee 227 | def unpackedhdr(self,data): 228 | int32 = self.unpack32int(data) 229 | return int32 230 | def ibm2ieee(self,int32): 231 | if int32 == 0: 232 | return 0.0 233 | sign = int32 >> 31 & 0x01 234 | exponent = int32 >> 24 & 0x7f 235 | mantissa = (int32 & 0x00ffffff) / self.p24 236 | return (1-2*sign)*mantissa*pow(16, exponent - 64) 237 | 238 | 239 | filename = './DATA/shot.sgy' 240 | # ebcdic = read_EBCDIC(filename) 241 | # print(ebcdic) 242 | binhead=read_bheader(filename) 243 | 244 | f = open(filename,'rb') 245 | f.seek(3600) # to skip 3600 bytes i.e EBCDIC and BINARY Header 246 | ns = binhead[0][7] 247 | 248 | ntraces=int(num_traces(filename,ns)) 249 | 250 | def create_table(name,b): 251 | conn = sqlite3.connect(name) 252 | conn.execute('DROP TABLE IF EXISTS mytable') 253 | columns= ['value%d' % n for n in range(1,b)] 254 | columns_declaration=','.join('%s REAL' % c for c in columns) 255 | conn.execute("CREATE TABLE mytable (%s)" %columns_declaration) 256 | conn.commit() 257 | def insert_table(name,b,c): 258 | conn = sqlite3.connect(name) 259 | d = b -1 260 | placeholders = ', '.join(['?'] * d) 261 | conn.execute('''INSERT INTO mytable VALUES ({})'''.format(placeholders), c) 262 | conn.commit() 263 | 264 | 265 | n=ns+60 # 60 is no of trace header id 266 | tablename="shotdb.db" 267 | create_table(tablename,n+1) 268 | bar = pyprind.ProgBar(ntraces) 269 | traces=[] 270 | for i in range(ntraces): 271 | bar.update() 272 | data = f.read((n) * 4) 273 | hdr=list(np.array(list((np.frombuffer(data[0:240], dtype=segy_trace_header_dtype))[0]))+0.0) # trace header as float 274 | amp= StructIBM32(ns).unpackibm(data[240:(ns * 4) + 240]) 275 | headandtrace=hdr+amp #concatenate 276 | insert_table(tablename, n+1,headandtrace) -------------------------------------------------------------------------------- /009_Well_Viz_Filled.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | import pandas as pd 4 | file = './DATA/F02-1_logs.las' 5 | data = np.loadtxt(file,skiprows=35) 6 | data[data==-999.2500]=np.nan 7 | mneumonics = ['DEPTH', 'RHOB', 'DT', 'GR', 'AI', 'AI_rel', 'PHIE'] 8 | data = pd.DataFrame(data, columns=mneumonics) 9 | data = data[['DEPTH', 'RHOB', 'DT', 'GR']] 10 | tb= [0,464,539,612,635,687,702, 795, 814, 926, 949, 1026, 1053, 1095, 1133, 1270,1297, 1430,2000] 11 | f = [1,2,3,1,3,4,3,1,3,1,3,1,3,1,3,4,3,1] #FACIES NO 12 | depth = data.DEPTH.values 13 | facies=[] 14 | for i in range(len(depth)): 15 | for j in range(len(tb)-1): 16 | if depth[i] > tb[j] and depth[i] <=tb[j+1]: 17 | facies.append(f[j]) 18 | data['FACIES'] = facies 19 | 20 | print(data) 21 | data.to_csv('well1.csv', index=False) 22 | data = data.values 23 | mneumonics = [ 'RHOB', 'DT', 'GR', 'FACIES' ] 24 | rows,cols = 1,4 25 | fig,ax = plt.subplots(nrows=rows, ncols=cols, figsize=(12,10), sharey=True) 26 | for i in range(cols): 27 | if i < cols-1: 28 | ax[i].plot(data[:,i+1], data[:,0], linewidth = '0.5', color='b') 29 | ax[i].set_ylim(max(data[:,0]), min(data[:,0])) 30 | ax[i].set_title('%s' % mneumonics[i]) 31 | ax[i].minorticks_on() 32 | ax[i].grid(which='major', linestyle='-', linewidth='0.5', color='lime') 33 | ax[i].grid(which='minor', linestyle=':', linewidth='0.5', color='black') 34 | elif i==cols-1: 35 | F = np.vstack((facies,facies)).T 36 | ax[i].imshow(F, aspect='auto', extent=[0,1,max(data[:, 0]), min(data[:, 0])]) 37 | ax[i].set_title('%s' % mneumonics[i]) 38 | y2 = data[:,3] #GR 39 | y1 = y2*0+60 #60 API is Sand-Shale Boundary Line 40 | ax[2].fill_betweenx(data[:,0],y1,y2,where=(y1>=y2), color = 'gold', linewidth=0) 41 | ax[2].fill_betweenx(data[:,0],y1,y2,where=(y1