quick-pp 0.2.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- quick_pp/__init__.py +0 -0
- quick_pp/api/__init__.py +0 -0
- quick_pp/api/exceptions.py +61 -0
- quick_pp/api/fastapi_mlflow/__init__.py +1 -0
- quick_pp/api/fastapi_mlflow/_mlflow_types.py +59 -0
- quick_pp/api/fastapi_mlflow/applications.py +72 -0
- quick_pp/api/fastapi_mlflow/exceptions.py +22 -0
- quick_pp/api/fastapi_mlflow/predictors.py +96 -0
- quick_pp/api/main.py +90 -0
- quick_pp/api/mlflow_model_deployment.py +99 -0
- quick_pp/api/qpp_assistant.py +160 -0
- quick_pp/api/router.py +18 -0
- quick_pp/api/schemas/lithology_hc_correction.py +39 -0
- quick_pp/api/schemas/lithology_ssc.py +37 -0
- quick_pp/api/schemas/lithology_vsh_gr.py +25 -0
- quick_pp/api/schemas/permeability_choo.py +25 -0
- quick_pp/api/schemas/permeability_others.py +24 -0
- quick_pp/api/schemas/porosity.py +22 -0
- quick_pp/api/schemas/ressum.py +29 -0
- quick_pp/api/schemas/saturation_archie.py +25 -0
- quick_pp/api/schemas/saturation_b.py +24 -0
- quick_pp/api/schemas/saturation_qv.py +26 -0
- quick_pp/api/schemas/saturation_rw.py +24 -0
- quick_pp/api/schemas/saturation_temp_grad.py +24 -0
- quick_pp/api/schemas/saturation_waxman_smits.py +28 -0
- quick_pp/api/services/las_handler.py +136 -0
- quick_pp/api/services/lithology.py +278 -0
- quick_pp/api/services/permeability.py +252 -0
- quick_pp/api/services/porosity.py +151 -0
- quick_pp/api/services/reservoir_summary.py +78 -0
- quick_pp/api/services/saturation.py +359 -0
- quick_pp/api/static/favicon.ico +0 -0
- quick_pp/api/static/logo.png +0 -0
- quick_pp/cli.py +118 -0
- quick_pp/config.py +94 -0
- quick_pp/core_calibration.py +394 -0
- quick_pp/fluid_type.py +128 -0
- quick_pp/geomechanics.py +195 -0
- quick_pp/las_handler.py +327 -0
- quick_pp/lithology/__init__.py +80 -0
- quick_pp/lithology/carbonate.py +166 -0
- quick_pp/lithology/multi_mineral.py +151 -0
- quick_pp/lithology/sand_shale.py +79 -0
- quick_pp/lithology/sand_silt_clay.py +131 -0
- quick_pp/logger.py +19 -0
- quick_pp/modelling/__init__.py +0 -0
- quick_pp/modelling/config.py +72 -0
- quick_pp/modelling/mock_data/mock_data.parquet +0 -0
- quick_pp/modelling/predict_pipeline.py +126 -0
- quick_pp/modelling/train_pipeline.py +220 -0
- quick_pp/modelling/utils.py +111 -0
- quick_pp/objects.py +177 -0
- quick_pp/permeability.py +151 -0
- quick_pp/plotter/__init__.py +0 -0
- quick_pp/plotter/plotter.py +315 -0
- quick_pp/plotter/well_log.py +187 -0
- quick_pp/plotter/well_log_config.py +409 -0
- quick_pp/porosity.py +341 -0
- quick_pp/qaqc.py +436 -0
- quick_pp/ressum.py +326 -0
- quick_pp/rock_type.py +499 -0
- quick_pp/saturation.py +455 -0
- quick_pp/utils.py +328 -0
- quick_pp-0.2.3.dist-info/METADATA +103 -0
- quick_pp-0.2.3.dist-info/RECORD +69 -0
- quick_pp-0.2.3.dist-info/WHEEL +4 -0
- quick_pp-0.2.3.dist-info/entry_points.txt +2 -0
- quick_pp-0.2.3.dist-info/licenses/AUTHORS.rst +13 -0
- quick_pp-0.2.3.dist-info/licenses/LICENSE +22 -0
quick_pp/geomechanics.py
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import math
|
|
3
|
+
|
|
4
|
+
from quick_pp.saturation import estimate_rt_water_trend
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def extrapolate_rhob(rhob, tvd, a, b):
|
|
8
|
+
"""Extrapolate density log to the surface using a power law model.
|
|
9
|
+
TODO: Revisit
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
rhob (float): Bulk density in g/cm^3.
|
|
13
|
+
tvd (float): True vertical depth in m.
|
|
14
|
+
a (float): _description_
|
|
15
|
+
b (float): _description_
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
float: Extrapolated density in g/cm^3.
|
|
19
|
+
"""
|
|
20
|
+
rhob_extrapolated = 1.8 + a * tvd**b
|
|
21
|
+
return np.append(rhob_extrapolated, rhob)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def estimate_gardner_density(vp, alpha=.23, beta=.25):
|
|
25
|
+
"""
|
|
26
|
+
Estimate density from vp using Gardner's relation.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
vp (float): P-wave velocity in ft/s.
|
|
30
|
+
alpha (float): Gardner's coefficient alpha. 1.75 for shale and 1.66 for sandstone.
|
|
31
|
+
beta (float): Gardner's coefficient beta. 0.265 for shale and 0.261 for sandstone.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
float: Estimated density in g/cm^3.
|
|
35
|
+
"""
|
|
36
|
+
return alpha * vp**beta
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def estimate_shear_wave_velocity(vp):
|
|
40
|
+
"""Estimate shear wave velocity from P-wave velocity using the empirical relation by Castagna et al. 1985.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
vp (float): P-wave velocity in m/s.
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
float: Estimated S-wave velocity in m/s.
|
|
47
|
+
"""
|
|
48
|
+
return 0.8043 * vp - 855.9
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def estimate_hydrostatic_pressure(tvd, rhob_water=1.0, g=9.81):
|
|
52
|
+
"""Estimate hydrostatic pressure from bulk density and true vertical.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
tvd (float): Depth in m.
|
|
56
|
+
rhob_water (float, optional): Bulk density of water in g/cm^3. Defaults to 1.0.
|
|
57
|
+
g (float, optional): Acceleration due to gravity in m/s^2. Defaults to 9.81.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
float: Estimated hydrostatic pressure in MPa.
|
|
61
|
+
"""
|
|
62
|
+
return 1000 * rhob_water * g * tvd
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def estimate_overburden_pressure(rhob, tvd, rhob_water=1.0, depth_water=0, g=9.81):
|
|
66
|
+
"""Estimate overburden pressure from bulk density and true vertical depth.
|
|
67
|
+
TODO: Revisit
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
rhob (float): Bulk density in g/cm^3.
|
|
71
|
+
tvd (float): Depth in m.
|
|
72
|
+
g (float, optional): Acceleration due to gravity in m/s^2. Defaults to 9.81.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
float: Estimated overburden pressure in MPa.
|
|
76
|
+
"""
|
|
77
|
+
return 1000 * (rhob_water * g * depth_water + np.cumsum(rhob) * g * tvd)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def estimate_pore_pressure_dt(s, p_hyd, dtc, dtc_shale, x=3.0):
|
|
81
|
+
"""Estimate pore pressure from sonic transit time and hydrostatic pressure.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
s (float): Overburden stress in MPa.
|
|
85
|
+
p_hyd (float): Hydrostatic pressure in MPa.
|
|
86
|
+
dtc (float): Compressional sonic transit time in us/ft.
|
|
87
|
+
dtc_shale (float): Compressional sonic transit time in us/ft for shale.
|
|
88
|
+
x (float, optional): Exponent for the empirical relation. Defaults to 3.0.
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
float: Estimated pore pressure in MPa.
|
|
92
|
+
"""
|
|
93
|
+
return s - (s - p_hyd) * (dtc_shale / dtc)**x
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def estimate_pore_pressure_res(s, p_hyd, res, res_shale=None, x=1.2):
|
|
97
|
+
"""Estimate pore pressure from resistivity and hydrostatic pressure.
|
|
98
|
+
|
|
99
|
+
Args:
|
|
100
|
+
s (float): Overburden stress in MPa.
|
|
101
|
+
p_hyd (float): Hydrostatic pressure in MPa.
|
|
102
|
+
res (float): Resistivity in ohm.m.
|
|
103
|
+
res_shale (float): Resistivity in ohm.m for shale.
|
|
104
|
+
x (float, optional): Exponent for the empirical relation. Defaults to 1.2.
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
float: Estimated pore pressure in MPa.
|
|
108
|
+
"""
|
|
109
|
+
res_shale = res_shale or estimate_rt_water_trend(res)
|
|
110
|
+
return s - (s - p_hyd) * (res_shale / res)**x
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def estimate_fracture_pressure(pp, tvd):
|
|
114
|
+
"""Estimate fracture pressure from pore pressure and true vertical depth.
|
|
115
|
+
TODO: Revisit
|
|
116
|
+
|
|
117
|
+
Args:
|
|
118
|
+
pp (float): Pore pressure in MPa.
|
|
119
|
+
tvd (float): True vertical depth in m.
|
|
120
|
+
|
|
121
|
+
Returns:
|
|
122
|
+
float: Estimated fracture pressure in MPa.
|
|
123
|
+
"""
|
|
124
|
+
return 1 / 3 * (1 + 2 * pp / tvd), 1 / 2 * (1 + 2 * pp / tvd)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def estimate_ucs(dtc):
|
|
128
|
+
"""Estimate Unconfined Compressive Strength (UCS) from dtc using the empirical relation by McNally 1987.
|
|
129
|
+
|
|
130
|
+
Args:
|
|
131
|
+
dtc (float): Compressional sonic transit time in us/ft.
|
|
132
|
+
|
|
133
|
+
Returns:
|
|
134
|
+
float: Estimated UCS in MPa.
|
|
135
|
+
"""
|
|
136
|
+
return 1200 * math.exp(-.036 * dtc)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def estimate_poisson_ratio(vp, vs):
|
|
140
|
+
"""Estimate Poisson's ratio from P-wave and S-wave velocities.
|
|
141
|
+
|
|
142
|
+
Args:
|
|
143
|
+
vp (float): P-wave velocity in m/s.
|
|
144
|
+
vs (float): S-wave velocity in m/s.
|
|
145
|
+
|
|
146
|
+
Returns:
|
|
147
|
+
float: Estimated Poisson's ratio.
|
|
148
|
+
"""
|
|
149
|
+
return (vp**2 - 2 * vs**2) / (2 * (vp**2 - vs**2))
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def estimate_shear_modulus(rhob, vs, a):
|
|
153
|
+
"""Estimate shear modulus from density, S-wave velocity and constant a.
|
|
154
|
+
Shear modulus is the shear stiffness of a material, which is the ratio of shear stress to shear strain.
|
|
155
|
+
Also known as the modulus of rigidity.
|
|
156
|
+
|
|
157
|
+
Args:
|
|
158
|
+
rhob (float): Bulk density in g/cm^3.
|
|
159
|
+
vs (float): S-wave velocity in m/s.
|
|
160
|
+
a (float): _description_
|
|
161
|
+
"""
|
|
162
|
+
return a * rhob / vs**2
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def estimate_young_modulus(rhob, vp, vs):
|
|
166
|
+
"""Estimate Young's modulus from density, P-wave and S-wave velocities.
|
|
167
|
+
Young's modulus is the measure of the resistance of a material to stress.
|
|
168
|
+
It quantifies the relationship between stress and strain in a material.
|
|
169
|
+
|
|
170
|
+
Args:
|
|
171
|
+
rhob (float): Bulk density in g/cm^3.
|
|
172
|
+
vp (float): P-wave velocity in m/s.
|
|
173
|
+
vs (float): S-wave velocity in m/s.
|
|
174
|
+
|
|
175
|
+
Returns:
|
|
176
|
+
float: Estimated Young's modulus in Pa.
|
|
177
|
+
"""
|
|
178
|
+
return rhob * 1000 * vp**2 * (3 * vp**2 - 4 * vs**2) / (vp**2 - vs**2)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def estimate_bulk_modulus(rhob, vp, vs, a):
|
|
182
|
+
"""Estimate Bulk modulus from density, P-wave and S-wave velocities.
|
|
183
|
+
Bulk modulus is the measure of resistance of a material to bulk compression.
|
|
184
|
+
It is the reciprocal of compressibility.
|
|
185
|
+
|
|
186
|
+
Args:
|
|
187
|
+
rhob (float): Bulk density in g/cm^3.
|
|
188
|
+
vp (float): P-wave velocity in m/s.
|
|
189
|
+
vs (float): S-wave velocity in m/s.
|
|
190
|
+
a (float): _description_
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
float: Estimated Bulk modulus in Pa.
|
|
194
|
+
"""
|
|
195
|
+
return a * rhob * (1 / vp**2 - 4 / (3 * vs**2))
|
quick_pp/las_handler.py
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import lasio
|
|
3
|
+
import os
|
|
4
|
+
import numpy as np
|
|
5
|
+
import pandas as pd
|
|
6
|
+
import mmap
|
|
7
|
+
import welly
|
|
8
|
+
import welly.las
|
|
9
|
+
|
|
10
|
+
from quick_pp.logger import logger
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def read_las_files(las_files):
|
|
14
|
+
"""
|
|
15
|
+
1. Return df and well_header as df from .las files
|
|
16
|
+
2. For every las files, curves_df, header_df, welly_object are returned through function "read_las_file"
|
|
17
|
+
3. curves_df from all files are appended into merged_data
|
|
18
|
+
4. header_df from all files are appended into header_data
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
las_files (list): list of las files opened as binary.
|
|
22
|
+
|
|
23
|
+
Returns:
|
|
24
|
+
pd.DataFrame: Merged data, header data.
|
|
25
|
+
"""
|
|
26
|
+
merged_data = pd.DataFrame()
|
|
27
|
+
header_data = pd.DataFrame()
|
|
28
|
+
|
|
29
|
+
for f in las_files:
|
|
30
|
+
try:
|
|
31
|
+
df, well_header = read_las_file_welly(f)
|
|
32
|
+
except Exception as e:
|
|
33
|
+
logger.error(f"[read_las_files] Exception for {f.name} | {e} ")
|
|
34
|
+
df, well_header, _ = read_las_file_mmap(f)
|
|
35
|
+
merged_data = pd.concat([merged_data, df], ignore_index=True)
|
|
36
|
+
header_data = pd.concat([header_data, well_header], ignore_index=True)
|
|
37
|
+
|
|
38
|
+
header_data_cols = header_data.columns
|
|
39
|
+
header_data = header_data.transpose()
|
|
40
|
+
header_data.rename({0: 'well_name'}, axis=1, inplace=True)
|
|
41
|
+
header_data.rename({x: v for x, v in enumerate(header_data_cols)}, axis=0, inplace=True)
|
|
42
|
+
|
|
43
|
+
merged_data.reset_index(inplace=True, drop=True)
|
|
44
|
+
|
|
45
|
+
return merged_data, header_data
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def read_las_file_mmap(file_object, required_sets=['PEP']): # noqa
|
|
49
|
+
"""Check LAS file and concat datasets if more than one.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
file_object (str): las file object.
|
|
53
|
+
required_sets (list, optional): Required param set to be extracted. Defaults to ['PEP'].
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
pd.Dataframe: well_df, header_df and welly_object
|
|
57
|
+
"""
|
|
58
|
+
fileno = file_object.fileno() # identifier for files
|
|
59
|
+
parameter_line_numbers = []
|
|
60
|
+
with mmap.mmap(fileno, length=0, access=mmap.ACCESS_READ) as mmap_obj:
|
|
61
|
+
all_text = mmap_obj.read()
|
|
62
|
+
set_count = len(re.findall(r'\b(SET)\s+', all_text.decode(), re.MULTILINE))
|
|
63
|
+
if set_count > 1:
|
|
64
|
+
well_count = 0
|
|
65
|
+
dataset_count = 0
|
|
66
|
+
line_number = 1
|
|
67
|
+
parameter_count = 0
|
|
68
|
+
mmap_obj.seek(0)
|
|
69
|
+
pointer = 0
|
|
70
|
+
while pointer < mmap_obj.size():
|
|
71
|
+
text = mmap_obj.readline()
|
|
72
|
+
pointer = (mmap_obj.tell()) # show current position of pointer
|
|
73
|
+
|
|
74
|
+
if b'~Well' in text:
|
|
75
|
+
well_count += 1
|
|
76
|
+
if b'~Curve' in text:
|
|
77
|
+
dataset_count += 1
|
|
78
|
+
if b'~P' in text or b'~Tops_Parameter' in text:
|
|
79
|
+
# Record parameter info in tuple:(parameter_count, parameter_set, pointer location, line number)
|
|
80
|
+
parameter_line_numbers.append((parameter_count, '', pointer, line_number))
|
|
81
|
+
parameter_count += 1
|
|
82
|
+
if re.compile(r'^\b(SET)\s+').search(text.decode()):
|
|
83
|
+
parameter_set = re.split(r'[\s+,.:]', text.decode().replace(' ', ''))[1]
|
|
84
|
+
temp_list_from_tuple = list(parameter_line_numbers[parameter_count - 1])
|
|
85
|
+
temp_list_from_tuple[1] = parameter_set
|
|
86
|
+
temp_list_from_tuple = tuple(temp_list_from_tuple)
|
|
87
|
+
parameter_line_numbers[parameter_count - 1] = temp_list_from_tuple
|
|
88
|
+
line_number += 1
|
|
89
|
+
|
|
90
|
+
# Record well header numbers in tuple: (0, '', pointer location, line number)
|
|
91
|
+
well_header_line_numbers = [(0, '', 0, 1), (0, '', parameter_line_numbers[0][2] - 1,
|
|
92
|
+
parameter_line_numbers[0][3] - 1)]
|
|
93
|
+
|
|
94
|
+
mmap_obj.seek(0) # Reset the pointer location
|
|
95
|
+
curves_df, header_df, welly_object = concat_datasets(
|
|
96
|
+
file_object=mmap_obj.read(), header_line_numbers=well_header_line_numbers,
|
|
97
|
+
parameter_line_numbers=parameter_line_numbers, required_sets=required_sets)
|
|
98
|
+
else:
|
|
99
|
+
well_count = 1
|
|
100
|
+
counter = 0
|
|
101
|
+
pointer_list = []
|
|
102
|
+
section_dict = {}
|
|
103
|
+
mmap_obj.seek(0)
|
|
104
|
+
pointer = 0
|
|
105
|
+
while pointer < mmap_obj.size():
|
|
106
|
+
text = mmap_obj.readline()
|
|
107
|
+
pointer = (mmap_obj.tell())
|
|
108
|
+
if pointer not in pointer_list:
|
|
109
|
+
pointer_list.append(pointer)
|
|
110
|
+
counter += 1
|
|
111
|
+
if b'~' in text:
|
|
112
|
+
section = text.decode().replace('~', '').rstrip().split(' ')[0].upper()
|
|
113
|
+
rename_set = {
|
|
114
|
+
'V': 'VERSION',
|
|
115
|
+
'W': 'WELL',
|
|
116
|
+
'P': 'PARAMETER',
|
|
117
|
+
'C': 'CURVE',
|
|
118
|
+
'O': 'OTHER',
|
|
119
|
+
'A': 'ASCII',
|
|
120
|
+
}
|
|
121
|
+
for initial, word in rename_set.items():
|
|
122
|
+
if section == initial:
|
|
123
|
+
section = section.replace(initial, word)
|
|
124
|
+
section_text = text
|
|
125
|
+
text = mmap_obj.readline()
|
|
126
|
+
pointer = (mmap_obj.tell())
|
|
127
|
+
if pointer not in pointer_list:
|
|
128
|
+
pointer_list.append(pointer)
|
|
129
|
+
counter += 1
|
|
130
|
+
while b'~' not in text and len(text) > 0:
|
|
131
|
+
section_text = section_text + text
|
|
132
|
+
text = mmap_obj.readline()
|
|
133
|
+
pointer = (mmap_obj.tell())
|
|
134
|
+
if pointer not in pointer_list:
|
|
135
|
+
pointer_list.append(pointer)
|
|
136
|
+
counter += 1
|
|
137
|
+
section_dict[section] = section_text
|
|
138
|
+
if len(text) > 0:
|
|
139
|
+
mmap_obj.seek(pointer_list[counter - 2])
|
|
140
|
+
|
|
141
|
+
mmap_obj.seek(0) # Reset the pointer location
|
|
142
|
+
curves_df, header_df, welly_object = extract_dataset(section_dict)
|
|
143
|
+
|
|
144
|
+
return curves_df, header_df, welly_object
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def read_las_file_welly(file_object):
|
|
148
|
+
welly_dataset = welly.las.from_las(file_object.name)
|
|
149
|
+
well_header = welly_dataset['Header']
|
|
150
|
+
welly_object = welly.well.Well.from_datasets(welly_dataset)
|
|
151
|
+
df = pre_process(welly_object)
|
|
152
|
+
return df, well_header
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def pre_process(welly_object):
|
|
156
|
+
"""Pre-process welly_object
|
|
157
|
+
|
|
158
|
+
1. Resample depth for welly_object
|
|
159
|
+
2. Replace NULL value with nan
|
|
160
|
+
3. Insert well name at first column
|
|
161
|
+
4. Insert field name at first column
|
|
162
|
+
|
|
163
|
+
Args:
|
|
164
|
+
welly_object (well object): Welly object for PEP dataset
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
pd.Dataframe: Processed data.
|
|
168
|
+
"""
|
|
169
|
+
# Convert index 'DEPTH' as column
|
|
170
|
+
data_df = welly_object.las[0]
|
|
171
|
+
data_df.index.rename('DEPTH', inplace=True)
|
|
172
|
+
data_df = data_df.reset_index(drop=False)
|
|
173
|
+
|
|
174
|
+
header_df = welly_object.header
|
|
175
|
+
nullValue = header_df[header_df['mnemonic'] == 'NULL']['value'].values[0] if \
|
|
176
|
+
header_df[header_df['mnemonic'] == 'NULL']['value'].values else -999.25
|
|
177
|
+
data_df = data_df.where(data_df >= nullValue, np.nan)
|
|
178
|
+
# Insert well name
|
|
179
|
+
well_name = header_df[
|
|
180
|
+
(header_df['mnemonic'] == 'WELL') | (header_df['descr'].str.upper() == 'WELL')
|
|
181
|
+
]['value'].values[0]
|
|
182
|
+
if 'WELL_NAME' not in data_df.columns:
|
|
183
|
+
data_df.insert(0, 'WELL_NAME', well_name)
|
|
184
|
+
# Insert UWI if available
|
|
185
|
+
if 'UWI' in header_df['mnemonic'].values:
|
|
186
|
+
uwi = header_df[
|
|
187
|
+
(header_df['mnemonic'] == 'UWI') | (header_df['descr'].str.upper() == 'UNIQUE WELL ID')
|
|
188
|
+
]['value'].values[0]
|
|
189
|
+
data_df.insert(0, 'UWI', uwi)
|
|
190
|
+
|
|
191
|
+
return data_df
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def extract_dataset(section_dict):
|
|
195
|
+
"""Extract dataset from section_dict. For only Las file with ONE (1) dataset
|
|
196
|
+
|
|
197
|
+
1. Assign well information section as header_bytes
|
|
198
|
+
2. Loop through parameter, curve, and ASCII sections, assign their section values into data_bytes
|
|
199
|
+
3. create file_object by decoding and concat header_bytes and data_bytes
|
|
200
|
+
4. Using lasio.read and welly.well.from_lasio, create welly_object & well_df from file_object
|
|
201
|
+
5. Through function "pre_process", return df with null replaced by nan, addition of column with well and field name
|
|
202
|
+
|
|
203
|
+
Args:
|
|
204
|
+
section_dict (dict): Dictionary containing the LAS file section values.
|
|
205
|
+
|
|
206
|
+
Returns:
|
|
207
|
+
pd.DataFrame, pd.DataFrame, welly_object: well_df, header_df and welly_object
|
|
208
|
+
"""
|
|
209
|
+
header_bytes = section_dict['WELL']
|
|
210
|
+
data_bytes = b''
|
|
211
|
+
for k, v in section_dict.items():
|
|
212
|
+
if k in ['PARAMETER', 'CURVE', 'ASCII']:
|
|
213
|
+
data_bytes = data_bytes + v
|
|
214
|
+
|
|
215
|
+
file_object = header_bytes.decode() + data_bytes.decode()
|
|
216
|
+
las_object = lasio.read(file_object, read_policy=())
|
|
217
|
+
|
|
218
|
+
# Fix las_object
|
|
219
|
+
df = las_object.df()
|
|
220
|
+
df = df.apply(pd.to_numeric, errors='coerce')
|
|
221
|
+
las_object.set_data_from_df(df)
|
|
222
|
+
|
|
223
|
+
welly_object = welly.Well.from_lasio(las_object)
|
|
224
|
+
well_df = pre_process(welly_object)
|
|
225
|
+
header_df = welly_object.header
|
|
226
|
+
|
|
227
|
+
return well_df, header_df, welly_object
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def concat_datasets(file_object, header_line_numbers, parameter_line_numbers, required_sets=['PEP']):
|
|
231
|
+
"""Concat required datasets in the LAS file.
|
|
232
|
+
|
|
233
|
+
1. Iterate through list of parameter_line_numbers, by extracting only param_set of 'PEP'
|
|
234
|
+
2. Through pointer position, subset and then concat well_info and file_object
|
|
235
|
+
3. Through function "pre_process", return df with null replaced by nan, addition of column with well and field name
|
|
236
|
+
|
|
237
|
+
Args:
|
|
238
|
+
file_object (object): File .read() object.
|
|
239
|
+
header_line_numbers (list of tuples): Pointer location and line number of the header information.
|
|
240
|
+
parameter_line_numbers (list of tuples): (parameter_count, parameter_set, pointer location, line number) of the
|
|
241
|
+
~Parameters in the LAS file.
|
|
242
|
+
required_sets (list): Required sets to be concatenated.
|
|
243
|
+
|
|
244
|
+
Returns:
|
|
245
|
+
pd.Dataframe, pd.Dataframe, welly_object: well_df, header_df and welly_object
|
|
246
|
+
"""
|
|
247
|
+
well_df = pd.DataFrame()
|
|
248
|
+
header_df = pd.DataFrame()
|
|
249
|
+
welly_object = welly.Well()
|
|
250
|
+
for i, (param_count, param_set, pointer, line_number) in enumerate(parameter_line_numbers):
|
|
251
|
+
# Currently only extracting one dataset: PEP
|
|
252
|
+
if param_set in required_sets:
|
|
253
|
+
well_info = file_object[header_line_numbers[0][2]: header_line_numbers[1][2] + 1].decode()
|
|
254
|
+
if i < len(parameter_line_numbers) - 1:
|
|
255
|
+
temp_file_object = file_object[pointer: parameter_line_numbers[i + 1][2]].decode()
|
|
256
|
+
else:
|
|
257
|
+
temp_file_object = file_object[pointer:].decode()
|
|
258
|
+
temp_file_object = well_info + temp_file_object
|
|
259
|
+
las_object = lasio.read(temp_file_object, read_policy=())
|
|
260
|
+
|
|
261
|
+
# Fix las_object
|
|
262
|
+
df = las_object.df()
|
|
263
|
+
df = df.apply(pd.to_numeric, errors='coerce')
|
|
264
|
+
las_object.set_data_from_df(df)
|
|
265
|
+
|
|
266
|
+
welly_object = welly.Well.from_lasio(las_object)
|
|
267
|
+
temp_well_df = pre_process(welly_object)
|
|
268
|
+
well_df = pd.concat([well_df, temp_well_df], axis=1)
|
|
269
|
+
header_df = welly_object.header
|
|
270
|
+
|
|
271
|
+
return well_df, header_df, welly_object
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def check_index_consistent(welly_object):
|
|
275
|
+
"""Check if index is consistent in welly_object
|
|
276
|
+
|
|
277
|
+
Args:
|
|
278
|
+
welly_object (object): Welly object
|
|
279
|
+
|
|
280
|
+
Returns:
|
|
281
|
+
bool: True if index is consistent
|
|
282
|
+
"""
|
|
283
|
+
try:
|
|
284
|
+
index_diff = np.diff(welly_object.las[0].index)
|
|
285
|
+
if all(index_diff == index_diff[0]) and all(index_diff > 0):
|
|
286
|
+
return True
|
|
287
|
+
else:
|
|
288
|
+
return False
|
|
289
|
+
except Exception as e:
|
|
290
|
+
logger.error(f"[las_handler] `check_index_consistent` Error | {e}")
|
|
291
|
+
return False
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def export_to_las(well_data, well_name, folder=''):
|
|
295
|
+
"""Export dataframe to las file. Expecting a DEPTH column in meters unit.
|
|
296
|
+
|
|
297
|
+
Args:
|
|
298
|
+
data_df (pd.DataFrame): data input
|
|
299
|
+
well_name (str): well name
|
|
300
|
+
"""
|
|
301
|
+
from .config import Config
|
|
302
|
+
units = Config.vars_units(well_data)
|
|
303
|
+
well_data.set_index('DEPTH', inplace=True, drop=True)
|
|
304
|
+
w = welly.Well().from_df(well_data, units=units, name=well_name)
|
|
305
|
+
|
|
306
|
+
w = w.from_df(well_data, units=units, name=well_name)
|
|
307
|
+
# Convert to lasio to handle index name
|
|
308
|
+
las = w.to_lasio()
|
|
309
|
+
las.curves[0].mnemonic = 'DEPTH'
|
|
310
|
+
# Write to LAS format
|
|
311
|
+
well_path = os.path.join(folder, f"{well_name}.las")
|
|
312
|
+
las.write(well_path)
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
if __name__ == '__main__':
|
|
316
|
+
from tkinter import Tk, filedialog
|
|
317
|
+
|
|
318
|
+
root = Tk()
|
|
319
|
+
file_objects = filedialog.askopenfiles(title='Choose well Log ASCII Standard (LAS) files to be combined',
|
|
320
|
+
filetypes=(('LAS Files', '*.LAS *.las'), ('All Files', '*.*')),
|
|
321
|
+
mode='rb')
|
|
322
|
+
root.destroy()
|
|
323
|
+
if file_objects:
|
|
324
|
+
# Test read_las_file function
|
|
325
|
+
merged_df, _ = read_las_files(file_objects)
|
|
326
|
+
fname = 'well_df.csv'
|
|
327
|
+
merged_df.to_csv(fname)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import statistics
|
|
3
|
+
from scipy.signal import detrend
|
|
4
|
+
from sklearn.preprocessing import MinMaxScaler
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def shale_volume_larinov_tertiary(igr):
|
|
8
|
+
"""
|
|
9
|
+
Computes shale volume from gamma ray using Larinov's method for tertiary rocks.
|
|
10
|
+
|
|
11
|
+
Parameters
|
|
12
|
+
----------
|
|
13
|
+
igr : float
|
|
14
|
+
Interval gamma ray [API].
|
|
15
|
+
|
|
16
|
+
Returns
|
|
17
|
+
-------
|
|
18
|
+
vshale : float
|
|
19
|
+
Shale volume [fraction].
|
|
20
|
+
|
|
21
|
+
"""
|
|
22
|
+
return 0.083 * (2**(3.7 * igr) - 1)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def shale_volume_larinov_older(igr):
|
|
26
|
+
"""
|
|
27
|
+
Computes shale volume from gamma ray using Larinov's method for older rocks.
|
|
28
|
+
|
|
29
|
+
Parameters
|
|
30
|
+
----------
|
|
31
|
+
igr : float
|
|
32
|
+
Interval gamma ray [API].
|
|
33
|
+
|
|
34
|
+
Returns
|
|
35
|
+
-------
|
|
36
|
+
vshale : float
|
|
37
|
+
Shale volume [fraction].
|
|
38
|
+
|
|
39
|
+
"""
|
|
40
|
+
return 0.33 * (2**(2 * igr) - 1)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def shale_volume_steiber(igr):
|
|
44
|
+
"""
|
|
45
|
+
Computes shale volume from gamma ray using Steiber's method.
|
|
46
|
+
|
|
47
|
+
Parameters
|
|
48
|
+
----------
|
|
49
|
+
igr : float
|
|
50
|
+
Interval gamma ray [API].
|
|
51
|
+
|
|
52
|
+
Returns
|
|
53
|
+
-------
|
|
54
|
+
vshale : float
|
|
55
|
+
Shale volume [fraction].
|
|
56
|
+
|
|
57
|
+
"""
|
|
58
|
+
return igr / (3 - 2 * igr)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def gr_index(gr):
|
|
62
|
+
"""
|
|
63
|
+
Computes gamma ray index from gamma ray.
|
|
64
|
+
|
|
65
|
+
Parameters
|
|
66
|
+
----------
|
|
67
|
+
gr : float
|
|
68
|
+
Gamma ray [API].
|
|
69
|
+
|
|
70
|
+
Returns
|
|
71
|
+
-------
|
|
72
|
+
gr_index : float
|
|
73
|
+
Gamma ray index [API].
|
|
74
|
+
|
|
75
|
+
"""
|
|
76
|
+
gr = np.where(np.isnan(gr), np.min(gr), gr)
|
|
77
|
+
dtr_gr = detrend(gr, axis=0) + statistics.mean(gr)
|
|
78
|
+
scaler = MinMaxScaler()
|
|
79
|
+
igr = scaler.fit_transform(dtr_gr.reshape(-1, 1))
|
|
80
|
+
return igr
|