-
Notifications
You must be signed in to change notification settings - Fork 0
/
cbl_to_waf.py
127 lines (98 loc) · 2.89 KB
/
cbl_to_waf.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
from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np
import TotalDepth
from TotalDepth.LIS.core import File, FileIndexer
import sys
lis_filename = Path(sys.argv[1])
file = File.FileRead(str(lis_filename))
file_idx = FileIndexer.FileIndex(file)
log_passes = [lp for lp in file_idx.genLogPasses()]
log_passes[0].logPass.setFrameSet(file)
sc = [sc for sc in log_passes[0].logPass.genFrameSetScNameUnit()]
data = log_passes[0].logPass.frameSet.frames
block_idx = {}
n = 0
for block in log_passes[0].logPass._dfsr.dsbBlocks:
block_name = block.mnem.strip().decode()
k = block.values()
block_idx[block_name] = (n, n + k, k)
n += k
block_idx
curve_logs = {name: block_idx[name][0] for name, (i0, i1, k) in block_idx.items() if k == 1}
arr_logs = {name: block_idx[name] for name, (i0, i1, k) in block_idx.items() if k > 1}
null = -999.25
data[data == null] = np.nan
data_extr = {}
for name, idx in curve_logs.items():
data_extr[name] = data[:, idx]
for name, (i0, i1, k) in arr_logs.items():
data_extr[name] = data[:, i0: i1]
indices = {
'map': {
'w5': 'w5_idx',
'w3': 'w3_idx',
'ws1': 'ws_idx',
'ws2': 'ws_idx',
'ws3': 'ws_idx',
'ws4': 'ws_idx',
'ws5': 'ws_idx',
'ws6': 'ws_idx',
'WVFC': 'wcal_idx',
},
'data': {
'w3_idx': np.linspace(0, 500, 250 + 1)[1:],
'w5_idx': np.linspace(0, 1500, 750 + 1)[1:],
'ws_idx': np.linspace(0, 300, 150 + 1)[1:],
'wcal_idx': np.linspace(0, 600, 200 + 1)[1:],
},
'units': {
'w3_idx': 'us',
'w5_idx': 'us',
'ws_idx': 'us',
'wcal_idx': 'us',
}
}
def get_index_for(name):
index_name = indices['map'][name]
return {
'data': indices['data'][index_name],
'unit': indices['units'][index_name],
}
import lasio
import pandas as pd
index_data = None
filename = f"{lis_filename.stem}_curves.las"
names = [n for n in curve_logs.keys()]
df = pd.DataFrame({name: data_extr[name] for name in names})
df = df.set_index('DEPT')
las = lasio.LASFile()
las.well.WELL = lis_filename.name
las.set_data_from_df(df)
with open(filename, "w") as f:
las.write(f)
log_aliases = {
'w3': 'wvf_3ft',
'w5': 'wvf_5ft',
'ws1': 'wvf_18in_s1',
'ws2': 'wvf_18in_s2',
'ws3': 'wvf_18in_s3',
'ws4': 'wvf_18in_s4',
'ws5': 'wvf_18in_s5',
'ws6': 'wvf_18in_s6',
'WVFC': 'wvf_cal'
}
import wellcadformats
for name in arr_logs.keys():
alias = log_aliases[name]
filename = f"{lis_filename.stem}_{alias}.waf"
arr_data = data_extr[name]
arr_idx_data = get_index_for(name)
log = wellcadformats.WAF()
log.generate(arr_data, depths=data_extr['DEPT'], times=arr_idx_data['data'])
fig = plt.figure()
ax = fig.add_subplot(111)
log.imshow(ax=ax)
ax.set_title(filename)
with open(filename, 'w') as f:
log.to_file(f)