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
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"""
|
|
2
|
+
API endpoints for lithology-related calculations: SSC, Vsh from GR, and hydrocarbon correction.
|
|
3
|
+
Optimized for readability, reliability, and maintainability.
|
|
4
|
+
|
|
5
|
+
Input Pydantic Models:
|
|
6
|
+
- estimate_ssc: LithologySSCInput (see quick_pp.api.schemas.lithology_ssc.LithologySSCInput)
|
|
7
|
+
- estimate_vsh_gr: LithologyVshGRInput (see quick_pp.api.schemas.lithology_vsh_gr.LithologyVshGRInput)
|
|
8
|
+
- estimate_hc_correction: LithologyHCCorrectionInput \
|
|
9
|
+
(see quick_pp.api.schemas.lithology_hc_correction.LithologyHCCorrectionInput)
|
|
10
|
+
"""
|
|
11
|
+
from fastapi import APIRouter
|
|
12
|
+
import pandas as pd
|
|
13
|
+
|
|
14
|
+
from quick_pp.api.schemas.lithology_ssc import LithologySSCInput
|
|
15
|
+
from quick_pp.api.schemas.lithology_vsh_gr import LithologyVshGRInput
|
|
16
|
+
from quick_pp.api.schemas.lithology_hc_correction import LithologyHCCorrectionInput
|
|
17
|
+
|
|
18
|
+
from quick_pp.lithology.sand_silt_clay import SandSiltClay
|
|
19
|
+
from quick_pp.lithology import gr_index
|
|
20
|
+
from quick_pp.qaqc import neu_den_xplot_hc_correction
|
|
21
|
+
|
|
22
|
+
router = APIRouter(prefix="/lithology", tags=["Lithology"])
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _validate_points(input_dict, required_points):
|
|
26
|
+
"""
|
|
27
|
+
Validate that all required endpoint keys in input_dict are present and contain two elements (NPHI, RHOB),
|
|
28
|
+
and that required points are not None or contain None values.
|
|
29
|
+
Raises ValueError if validation fails.
|
|
30
|
+
"""
|
|
31
|
+
for k in [key for key in input_dict if key.endswith('_point')]:
|
|
32
|
+
if not (isinstance(input_dict[k], (list, tuple)) and len(input_dict[k]) == 2):
|
|
33
|
+
raise ValueError(f"'{k}' must be a tuple/list of length 2 (NPHI, RHOB). Got: {input_dict[k]}")
|
|
34
|
+
for k in required_points:
|
|
35
|
+
if not all(input_dict.get(k, ())):
|
|
36
|
+
raise ValueError(f"'{k}' point must not be None or contain None values.")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _to_dataframe(data, columns=None):
|
|
40
|
+
"""
|
|
41
|
+
Convert a list of dicts to a pandas DataFrame and check for required columns.
|
|
42
|
+
Raises ValueError if any required columns are missing.
|
|
43
|
+
"""
|
|
44
|
+
df = pd.DataFrame.from_records(data)
|
|
45
|
+
if columns:
|
|
46
|
+
missing = set(columns) - set(df.columns)
|
|
47
|
+
if missing:
|
|
48
|
+
raise ValueError(f"Missing columns in input data: {missing}")
|
|
49
|
+
return df
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@router.post(
|
|
53
|
+
"/ssc",
|
|
54
|
+
summary="Estimate Sand, Silt, and Clay (SSC) Volume Fractions",
|
|
55
|
+
description=(
|
|
56
|
+
"""
|
|
57
|
+
Estimate sand, silt, and clay (SSC) volume fractions based on a multi-endpoint lithology model.
|
|
58
|
+
Input model: LithologySSCInput (see quick_pp.api.schemas.lithology_ssc.LithologySSCInput).
|
|
59
|
+
Request body must be a JSON object with the following fields:
|
|
60
|
+
- dry_sand_point: [float, float] (required)
|
|
61
|
+
- dry_silt_point: [float, float] or [null, null] (optional)
|
|
62
|
+
- dry_clay_point: [float, float] or [null, null] (optional)
|
|
63
|
+
- fluid_point: [float, float] (required)
|
|
64
|
+
- wet_clay_point: [float, float] or [null, null] (optional)
|
|
65
|
+
- method: string (optional)
|
|
66
|
+
- silt_line_angle: float (required)
|
|
67
|
+
- data: list of objects, each with keys 'nphi' (float) and 'rhob' (float) (required)
|
|
68
|
+
Example:
|
|
69
|
+
{
|
|
70
|
+
'dry_sand_point': [0.1, 2.65],
|
|
71
|
+
'dry_silt_point': [0.2, 2.5],
|
|
72
|
+
'dry_clay_point': [0.3, 2.4],
|
|
73
|
+
'fluid_point': [1.0, 1.0],
|
|
74
|
+
'wet_clay_point': [0.5, 2.2],
|
|
75
|
+
'method': 'default',
|
|
76
|
+
'silt_line_angle': 35.0,
|
|
77
|
+
'data': [{'nphi': 0.25, 'rhob': 2.45}, ... ]
|
|
78
|
+
}
|
|
79
|
+
"""
|
|
80
|
+
),
|
|
81
|
+
operation_id="estimate_sand_silt_clay_lithology",
|
|
82
|
+
)
|
|
83
|
+
async def estimate_ssc(inputs: LithologySSCInput):
|
|
84
|
+
"""
|
|
85
|
+
Estimate sand, silt, and clay (SSC) volume fractions from well log data using a multi-endpoint lithology model.
|
|
86
|
+
|
|
87
|
+
Parameters
|
|
88
|
+
----------
|
|
89
|
+
inputs : LithologySSCInput
|
|
90
|
+
Pydantic model containing:
|
|
91
|
+
- dry_sand_point: Tuple[float, float]
|
|
92
|
+
- dry_silt_point: Tuple[Optional[float], Optional[float]]
|
|
93
|
+
- dry_clay_point: Tuple[Optional[float], Optional[float]]
|
|
94
|
+
- fluid_point: Tuple[float, float]
|
|
95
|
+
- wet_clay_point: Tuple[Optional[float], Optional[float]]
|
|
96
|
+
- method: str
|
|
97
|
+
- silt_line_angle: float
|
|
98
|
+
- data: List[dict] with 'nphi' and 'rhob' keys
|
|
99
|
+
|
|
100
|
+
Returns
|
|
101
|
+
-------
|
|
102
|
+
List[dict]
|
|
103
|
+
List of dictionaries, each containing the estimated volume fractions:
|
|
104
|
+
- 'VSAND': float (sand fraction)
|
|
105
|
+
- 'VSILT': float (silt fraction)
|
|
106
|
+
- 'VCLD': float (clay fraction)
|
|
107
|
+
|
|
108
|
+
Raises
|
|
109
|
+
------
|
|
110
|
+
ValueError
|
|
111
|
+
If endpoint validation fails or required data columns are missing.
|
|
112
|
+
|
|
113
|
+
Technical Details
|
|
114
|
+
----------------
|
|
115
|
+
- Validates endpoint coordinates for completeness and correct dimensionality.
|
|
116
|
+
- Constructs a SandSiltClay model using the provided endpoints and silt line angle.
|
|
117
|
+
- Estimates lithology fractions for each input data point using neutron porosity and bulk density logs.
|
|
118
|
+
- Returns results as a list of dictionaries, preserving input order.
|
|
119
|
+
"""
|
|
120
|
+
input_dict = inputs.model_dump()
|
|
121
|
+
_validate_points(input_dict, required_points=['dry_sand_point', 'fluid_point'])
|
|
122
|
+
df = _to_dataframe(input_dict['data'], columns=['nphi', 'rhob'])
|
|
123
|
+
ssc_model = SandSiltClay(
|
|
124
|
+
dry_sand_point=input_dict['dry_sand_point'],
|
|
125
|
+
dry_silt_point=input_dict['dry_silt_point'],
|
|
126
|
+
dry_clay_point=input_dict['dry_clay_point'],
|
|
127
|
+
fluid_point=input_dict['fluid_point'],
|
|
128
|
+
wet_clay_point=input_dict['wet_clay_point'],
|
|
129
|
+
silt_line_angle=input_dict['silt_line_angle']
|
|
130
|
+
)
|
|
131
|
+
vsand, vsilt, vcld, _ = ssc_model.estimate_lithology(df['nphi'], df['rhob'])
|
|
132
|
+
return pd.DataFrame({'VSAND': vsand, 'VSILT': vsilt, 'VCLD': vcld}, index=df.index).to_dict(orient='records')
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
@router.post(
|
|
136
|
+
"/vsh_gr",
|
|
137
|
+
summary="Estimate Volume of Shale (Vsh) from Gamma Ray Log Data",
|
|
138
|
+
description=(
|
|
139
|
+
"""
|
|
140
|
+
Estimate volume of shale (Vsh) using gamma ray log data. Requires gamma ray (GR) measurements.
|
|
141
|
+
Input model: LithologyVshGRInput (see quick_pp.api.schemas.lithology_vsh_gr.LithologyVshGRInput).
|
|
142
|
+
Request body must be a JSON object with the following field:
|
|
143
|
+
- data: list of objects, each with key 'gr' (float) (required)
|
|
144
|
+
Example:
|
|
145
|
+
{'data': [{'gr': 85.0}, {'gr': 110.0}, ... ]}
|
|
146
|
+
"""
|
|
147
|
+
),
|
|
148
|
+
operation_id="estimate_vshale_gamma_ray",
|
|
149
|
+
)
|
|
150
|
+
async def estimate_vsh_gr(inputs: LithologyVshGRInput):
|
|
151
|
+
"""
|
|
152
|
+
Estimate the volume of shale (Vsh) from gamma ray (GR) log data.
|
|
153
|
+
|
|
154
|
+
Parameters
|
|
155
|
+
----------
|
|
156
|
+
inputs : LithologyVshGRInput
|
|
157
|
+
Pydantic model containing:
|
|
158
|
+
- data: List[dict] with 'gr' key (gamma ray log values)
|
|
159
|
+
|
|
160
|
+
Returns
|
|
161
|
+
-------
|
|
162
|
+
List[dict]
|
|
163
|
+
List of dictionaries, each with a single key 'GR'.
|
|
164
|
+
Each value represents the estimated volume of shale for the corresponding input record.
|
|
165
|
+
|
|
166
|
+
Raises
|
|
167
|
+
------
|
|
168
|
+
ValueError
|
|
169
|
+
If required data columns are missing.
|
|
170
|
+
|
|
171
|
+
Technical Details
|
|
172
|
+
----------------
|
|
173
|
+
- Converts input data to a DataFrame and checks for the 'gr' column.
|
|
174
|
+
- Applies the gamma ray index calculation using the gr_index function.
|
|
175
|
+
- Returns the result as a list of dictionaries, preserving input order.
|
|
176
|
+
"""
|
|
177
|
+
input_dict = inputs.model_dump()
|
|
178
|
+
df = _to_dataframe(input_dict['data'], columns=['gr'])
|
|
179
|
+
vsh_gr = gr_index(df['gr'])
|
|
180
|
+
return pd.DataFrame({'GR': vsh_gr.ravel()}, index=df.index).to_dict(orient='records')
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
@router.post(
|
|
184
|
+
"/hc_corr",
|
|
185
|
+
summary="Estimate Hydrocarbon Correction and Lithology Fractions",
|
|
186
|
+
description=(
|
|
187
|
+
"""
|
|
188
|
+
Estimate hydrocarbon correction and lithology fractions from well log data.
|
|
189
|
+
Requires neutron porosity (NPHI) and bulk density (RHOB) measurements,
|
|
190
|
+
along with reference points for dry sand, silt, clay, and fluid as well as correction angle.
|
|
191
|
+
Input model: LithologyHCCorrectionInput
|
|
192
|
+
(see quick_pp.api.schemas.lithology_hc_correction.LithologyHCCorrectionInput).
|
|
193
|
+
Request body must be a JSON object with the following fields:
|
|
194
|
+
- dry_sand_point: [float, float] (required)
|
|
195
|
+
- dry_silt_point: [float, float] or [null, null] (optional)
|
|
196
|
+
- dry_clay_point: [float, float] or [null, null] (required)
|
|
197
|
+
- fluid_point: [float, float] (required)
|
|
198
|
+
- wet_clay_point: [float, float] or [null, null] (optional)
|
|
199
|
+
- method: string (optional)
|
|
200
|
+
- silt_line_angle: float (required)
|
|
201
|
+
- corr_angle: float (required)
|
|
202
|
+
- data: list of objects, each with keys 'nphi' (float) and 'rhob' (float) (required)
|
|
203
|
+
Example:
|
|
204
|
+
{
|
|
205
|
+
'dry_sand_point': [0.1, 2.65],
|
|
206
|
+
'dry_silt_point': [0.2, 2.5],
|
|
207
|
+
'dry_clay_point': [0.3, 2.4],
|
|
208
|
+
'fluid_point': [1.0, 1.0],
|
|
209
|
+
'wet_clay_point': [0.5, 2.2],
|
|
210
|
+
'method': 'default',
|
|
211
|
+
'silt_line_angle': 35.0,
|
|
212
|
+
'corr_angle': 12.0,
|
|
213
|
+
'data': [{'nphi': 0.25, 'rhob': 2.45}, ... ]
|
|
214
|
+
}
|
|
215
|
+
"""
|
|
216
|
+
),
|
|
217
|
+
operation_id="estimate_hydro_carbon_correction",
|
|
218
|
+
)
|
|
219
|
+
async def estimate_hc_correction(inputs: LithologyHCCorrectionInput):
|
|
220
|
+
"""
|
|
221
|
+
Estimate hydrocarbon correction and lithology fractions from input data.
|
|
222
|
+
|
|
223
|
+
Parameters
|
|
224
|
+
----------
|
|
225
|
+
inputs : LithologyHCCorrectionInput
|
|
226
|
+
Pydantic model containing:
|
|
227
|
+
- dry_sand_point: Tuple[float, float]
|
|
228
|
+
- dry_silt_point: Tuple[Optional[float], Optional[float]]
|
|
229
|
+
- dry_clay_point: Tuple[Optional[float], Optional[float]]
|
|
230
|
+
- fluid_point: Tuple[float, float]
|
|
231
|
+
- wet_clay_point: Tuple[Optional[float], Optional[float]]
|
|
232
|
+
- method: str
|
|
233
|
+
- silt_line_angle: float
|
|
234
|
+
- corr_angle: float
|
|
235
|
+
- data: List[dict] with 'nphi' and 'rhob' keys
|
|
236
|
+
|
|
237
|
+
Returns
|
|
238
|
+
-------
|
|
239
|
+
List[dict]
|
|
240
|
+
List of dictionaries, each containing the estimated volume fractions:
|
|
241
|
+
- 'VSAND': float (sand fraction)
|
|
242
|
+
- 'VSILT': float (silt fraction)
|
|
243
|
+
- 'VCLD': float (clay fraction)
|
|
244
|
+
|
|
245
|
+
Raises
|
|
246
|
+
------
|
|
247
|
+
ValueError
|
|
248
|
+
If endpoint validation fails or required data columns are missing.
|
|
249
|
+
|
|
250
|
+
Technical Details
|
|
251
|
+
----------------
|
|
252
|
+
- Validates endpoint coordinates for completeness and correct dimensionality.
|
|
253
|
+
- Applies hydrocarbon correction to neutron porosity and bulk density logs using neu_den_xplot_hc_correction,
|
|
254
|
+
which rotates the crossplot by the specified correction angle.
|
|
255
|
+
- Constructs a SandSiltClay model using the provided endpoints and silt line angle.
|
|
256
|
+
- Estimates lithology fractions for each corrected data point.
|
|
257
|
+
- Returns results as a list of dictionaries, preserving input order.
|
|
258
|
+
"""
|
|
259
|
+
input_dict = inputs.model_dump()
|
|
260
|
+
_validate_points(input_dict, required_points=['dry_sand_point', 'dry_clay_point', 'fluid_point'])
|
|
261
|
+
df = _to_dataframe(input_dict['data'], columns=['nphi', 'rhob'])
|
|
262
|
+
nphihc, rhobhc, _ = neu_den_xplot_hc_correction(
|
|
263
|
+
df['nphi'], df['rhob'],
|
|
264
|
+
dry_min1_point=input_dict['dry_sand_point'],
|
|
265
|
+
dry_clay_point=input_dict['dry_clay_point'],
|
|
266
|
+
corr_angle=input_dict['corr_angle']
|
|
267
|
+
)
|
|
268
|
+
df_corr = pd.DataFrame({'NPHI': nphihc, 'RHOB': rhobhc}).astype(float)
|
|
269
|
+
ssc_model = SandSiltClay(
|
|
270
|
+
dry_sand_point=input_dict['dry_sand_point'],
|
|
271
|
+
dry_silt_point=input_dict['dry_silt_point'],
|
|
272
|
+
dry_clay_point=input_dict['dry_clay_point'],
|
|
273
|
+
fluid_point=input_dict['fluid_point'],
|
|
274
|
+
wet_clay_point=input_dict['wet_clay_point'],
|
|
275
|
+
silt_line_angle=input_dict['silt_line_angle']
|
|
276
|
+
)
|
|
277
|
+
vsand, vsilt, vcld, _ = ssc_model.estimate_lithology(df_corr['NPHI'], df_corr['RHOB'])
|
|
278
|
+
return pd.DataFrame({'VSAND': vsand, 'VSILT': vsilt, 'VCLD': vcld}, index=df.index).to_dict(orient='records')
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
from fastapi import APIRouter, HTTPException
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from typing import List, Dict
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
from quick_pp.api.schemas.permeability_choo import InputData as PermChInputData
|
|
7
|
+
from quick_pp.api.schemas.permeability_others import InputData as PermOthersInputData
|
|
8
|
+
from quick_pp.permeability import (
|
|
9
|
+
choo_permeability, timur_permeability, coates_permeability, kozeny_carman_permeability, tixier_permeability
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
router = APIRouter(prefix="/permeability", tags=["Permeability"])
|
|
13
|
+
logger = logging.getLogger("api.services.permeability")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@router.post(
|
|
17
|
+
"/choo",
|
|
18
|
+
summary="Estimate Choo permeability",
|
|
19
|
+
description=(
|
|
20
|
+
"Estimate permeability using the Choo empirical model. "
|
|
21
|
+
"Requires volume of clay (vcld), volume of silt (vsilt), and total porosity (phit) measurements.\n"
|
|
22
|
+
"Input model: PermChInputData (see quick_pp.api.schemas.permeability_choo.InputData).\n"
|
|
23
|
+
"Request body must be a JSON object with the following field:\n"
|
|
24
|
+
"- data: list of objects, each with keys 'vcld', 'vsilt', 'phit' (all float, required)\n"
|
|
25
|
+
"Example (truncated): { 'data': [ {'vcld': 0.25, 'vsilt': 0.10, 'phit': 0.18}, ... ] }"
|
|
26
|
+
),
|
|
27
|
+
operation_id="estimate_choo_permeability",
|
|
28
|
+
)
|
|
29
|
+
async def estimate_perm_choo(inputs: PermChInputData) -> List[Dict[str, float]]:
|
|
30
|
+
"""
|
|
31
|
+
Estimate permeability using the Choo empirical model.
|
|
32
|
+
|
|
33
|
+
This endpoint receives input data for multiple samples, including volume of clay (vcld),
|
|
34
|
+
volume of silt (vsilt), and total porosity (phit), and computes the permeability for each
|
|
35
|
+
sample using the Choo permeability correlation.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
inputs (PermChInputData): Pydantic model containing a list of input records under the
|
|
39
|
+
'data' key. Each record must include 'vcld', 'vsilt', and 'phit' fields.
|
|
40
|
+
Returns:
|
|
41
|
+
List[Dict[str, float]]: A list of dictionaries, each containing the estimated permeability
|
|
42
|
+
('PERM') for the corresponding input sample.
|
|
43
|
+
Technical Details:
|
|
44
|
+
- The input data is converted into a pandas DataFrame for vectorized processing.
|
|
45
|
+
- The `choo_permeability` function is applied to the input columns to compute permeability
|
|
46
|
+
values for all samples in a vectorized manner.
|
|
47
|
+
- The result is reshaped and returned as a list of dictionaries, suitable for JSON
|
|
48
|
+
serialization and API response.
|
|
49
|
+
- This endpoint is asynchronous and designed for use with FastAPI.
|
|
50
|
+
- Any errors during processing are logged and returned as HTTP 400 errors.
|
|
51
|
+
"""
|
|
52
|
+
try:
|
|
53
|
+
input_dict = inputs.model_dump()
|
|
54
|
+
input_df = pd.DataFrame.from_records(input_dict['data'])
|
|
55
|
+
perm = choo_permeability(
|
|
56
|
+
input_df['vcld'], input_df['vsilt'], input_df['phit']
|
|
57
|
+
)
|
|
58
|
+
df_result = pd.DataFrame({'PERM': perm.ravel()})
|
|
59
|
+
# Ensure output is List[Dict[str, float]]
|
|
60
|
+
return [
|
|
61
|
+
{str(k): float(v) for k, v in row.items()}
|
|
62
|
+
for row in df_result.to_dict(orient='records')
|
|
63
|
+
]
|
|
64
|
+
except Exception as e:
|
|
65
|
+
logger.error(f"Error in estimate_perm_choo: {e}")
|
|
66
|
+
raise HTTPException(status_code=400, detail=str(e))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@router.post(
|
|
70
|
+
"/timur",
|
|
71
|
+
summary="Estimate Timur permeability",
|
|
72
|
+
description=(
|
|
73
|
+
"Estimate permeability using the Timur empirical model. "
|
|
74
|
+
"Requires porosity (phit) and irreducible water saturation (swirr) measurements.\n"
|
|
75
|
+
"Input model: PermOthersInputData (see quick_pp.api.schemas.permeability_others.InputData).\n"
|
|
76
|
+
"Request body must be a JSON object with the following field:\n"
|
|
77
|
+
"- data: list of objects, each with keys 'phit' (float, required) and 'swirr' (float, required)\n"
|
|
78
|
+
"Example (truncated): { 'data': [ {'phit': 0.18, 'swirr': 0.25}, ... ] }"
|
|
79
|
+
),
|
|
80
|
+
operation_id="estimate_timur_permeability",
|
|
81
|
+
)
|
|
82
|
+
async def estimate_perm_timur(inputs: PermOthersInputData) -> List[Dict[str, float]]:
|
|
83
|
+
"""
|
|
84
|
+
Estimate permeability using the Timur empirical equation.
|
|
85
|
+
|
|
86
|
+
This endpoint receives input data containing porosity (phit) and irreducible water saturation (swirr) values,
|
|
87
|
+
applies the Timur permeability estimation method, and returns the calculated permeability values.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
inputs (PermOthersInputData): Input data model containing a list of records with 'phit' and 'swirr'.
|
|
91
|
+
Returns:
|
|
92
|
+
List[Dict[str, float]]: A list of dictionaries, each containing the estimated permeability value
|
|
93
|
+
under the key 'PERM'.
|
|
94
|
+
Technical Details:
|
|
95
|
+
- The Timur equation is an empirical relationship used in petrophysics to estimate permeability from
|
|
96
|
+
porosity and irreducible water saturation.
|
|
97
|
+
- The function expects the input data to be structured as a list of records, each with 'phit' (porosity)
|
|
98
|
+
and 'swirr' (irreducible water saturation).
|
|
99
|
+
- The permeability calculation is performed using the `timur_permeability` function, which should
|
|
100
|
+
implement the Timur equation in a vectorized fashion for performance.
|
|
101
|
+
- The result is formatted as a list of dictionaries for API response compatibility.
|
|
102
|
+
- Errors are logged and returned as HTTP 400 errors.
|
|
103
|
+
"""
|
|
104
|
+
try:
|
|
105
|
+
input_dict = inputs.model_dump()
|
|
106
|
+
input_df = pd.DataFrame.from_records(input_dict['data'])
|
|
107
|
+
perm = timur_permeability(input_df['phit'], input_df['swirr'])
|
|
108
|
+
df_result = pd.DataFrame({'PERM': perm.ravel()})
|
|
109
|
+
return [
|
|
110
|
+
{str(k): float(v) for k, v in row.items()}
|
|
111
|
+
for row in df_result.to_dict(orient='records')
|
|
112
|
+
]
|
|
113
|
+
except Exception as e:
|
|
114
|
+
logger.error(f"Error in estimate_perm_timur: {e}")
|
|
115
|
+
raise HTTPException(status_code=400, detail=str(e))
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@router.post(
|
|
119
|
+
"/tixier",
|
|
120
|
+
summary="Estimate Tixier permeability",
|
|
121
|
+
description=(
|
|
122
|
+
"Estimate permeability using the Tixier empirical model. "
|
|
123
|
+
"Requires porosity (phit) and irreducible water saturation (swirr) measurements.\n"
|
|
124
|
+
"Input model: PermOthersInputData (see quick_pp.api.schemas.permeability_others.InputData).\n"
|
|
125
|
+
"Request body must be a JSON object with the following field:\n"
|
|
126
|
+
"- data: list of objects, each with keys 'phit' (float, required) and 'swirr' (float, required)\n"
|
|
127
|
+
"Example (truncated): { 'data': [ {'phit': 0.18, 'swirr': 0.25}, ... ] }"
|
|
128
|
+
),
|
|
129
|
+
operation_id="estimate_tixier_permeability",
|
|
130
|
+
)
|
|
131
|
+
async def estimate_perm_tixier(inputs: PermOthersInputData) -> List[Dict[str, float]]:
|
|
132
|
+
"""
|
|
133
|
+
Estimate permeability using the Tixier empirical correlation.
|
|
134
|
+
|
|
135
|
+
This endpoint receives input data containing porosity (phit) and irreducible water saturation (swirr),
|
|
136
|
+
applies the Tixier permeability estimation method, and returns the calculated permeability values.
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
inputs (PermOthersInputData): Input data model containing a list of records with 'phit' and 'swirr'.
|
|
140
|
+
Returns:
|
|
141
|
+
List[Dict[str, float]]: A list of dictionaries, each containing the estimated permeability ('PERM')
|
|
142
|
+
for the corresponding input record.
|
|
143
|
+
Technical Details:
|
|
144
|
+
- The input data is converted to a pandas DataFrame for processing.
|
|
145
|
+
- The `tixier_permeability` function is used to compute permeability based on the Tixier empirical formula.
|
|
146
|
+
- The result is formatted as a list of dictionaries for API response compatibility.
|
|
147
|
+
- Errors are logged and returned as HTTP 400 errors.
|
|
148
|
+
"""
|
|
149
|
+
try:
|
|
150
|
+
input_dict = inputs.model_dump()
|
|
151
|
+
input_df = pd.DataFrame.from_records(input_dict['data'])
|
|
152
|
+
perm = tixier_permeability(input_df['phit'], input_df['swirr'])
|
|
153
|
+
df_result = pd.DataFrame({'PERM': perm.ravel()})
|
|
154
|
+
return [
|
|
155
|
+
{str(k): float(v) for k, v in row.items()}
|
|
156
|
+
for row in df_result.to_dict(orient='records')
|
|
157
|
+
]
|
|
158
|
+
except Exception as e:
|
|
159
|
+
logger.error(f"Error in estimate_perm_tixier: {e}")
|
|
160
|
+
raise HTTPException(status_code=400, detail=str(e))
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
@router.post(
|
|
164
|
+
"/coates",
|
|
165
|
+
summary="Estimate Coates permeability",
|
|
166
|
+
description=(
|
|
167
|
+
"Estimate permeability using the Coates empirical model. "
|
|
168
|
+
"Requires porosity (phit) and irreducible water saturation (swirr) measurements.\n"
|
|
169
|
+
"Input model: PermOthersInputData (see quick_pp.api.schemas.permeability_others.InputData).\n"
|
|
170
|
+
"Request body must be a JSON object with the following field:\n"
|
|
171
|
+
"- data: list of objects, each with keys 'phit' (float, required) and 'swirr' (float, required)\n"
|
|
172
|
+
"Example (truncated): { 'data': [ {'phit': 0.18, 'swirr': 0.25}, ... ] }"
|
|
173
|
+
),
|
|
174
|
+
operation_id="estimate_coates_permeability",
|
|
175
|
+
)
|
|
176
|
+
async def estimate_perm_coates(inputs: PermOthersInputData) -> List[Dict[str, float]]:
|
|
177
|
+
"""
|
|
178
|
+
Estimate permeability using the Coates method.
|
|
179
|
+
|
|
180
|
+
This endpoint receives input data containing porosity (phit) and irreducible water saturation (swirr) values,
|
|
181
|
+
applies the Coates permeability estimation algorithm, and returns the calculated permeability values.
|
|
182
|
+
|
|
183
|
+
Args:
|
|
184
|
+
inputs (PermOthersInputData): Input data model containing a list of records with 'phit' and 'swirr'.
|
|
185
|
+
Returns:
|
|
186
|
+
List[Dict[str, float]]: A list of dictionaries, each containing the estimated permeability ('PERM')
|
|
187
|
+
for the corresponding input record.
|
|
188
|
+
Technical Details:
|
|
189
|
+
- The function extracts the input data, constructs a pandas DataFrame, and computes permeability using the
|
|
190
|
+
`coates_permeability` function, which implements the Coates empirical relationship for permeability
|
|
191
|
+
estimation in a vectorized manner.
|
|
192
|
+
- The results are formatted as a list of dictionaries for API response.
|
|
193
|
+
- Errors are logged and returned as HTTP 400 errors.
|
|
194
|
+
"""
|
|
195
|
+
try:
|
|
196
|
+
input_dict = inputs.model_dump()
|
|
197
|
+
input_df = pd.DataFrame.from_records(input_dict['data'])
|
|
198
|
+
perm = coates_permeability(input_df['phit'], input_df['swirr'])
|
|
199
|
+
df_result = pd.DataFrame({'PERM': perm.ravel()})
|
|
200
|
+
return [
|
|
201
|
+
{str(k): float(v) for k, v in row.items()}
|
|
202
|
+
for row in df_result.to_dict(orient='records')
|
|
203
|
+
]
|
|
204
|
+
except Exception as e:
|
|
205
|
+
logger.error(f"Error in estimate_perm_coates: {e}")
|
|
206
|
+
raise HTTPException(status_code=400, detail=str(e))
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
@router.post(
|
|
210
|
+
"/kozeny_carman",
|
|
211
|
+
summary="Estimate Kozeny-Carman permeability",
|
|
212
|
+
description=(
|
|
213
|
+
"Estimate permeability using the Kozeny-Carman equation. "
|
|
214
|
+
"Requires porosity (phit) and irreducible water saturation (swirr) measurements.\n"
|
|
215
|
+
"Input model: PermOthersInputData (see quick_pp.api.schemas.permeability_others.InputData).\n"
|
|
216
|
+
"Request body must be a JSON object with the following field:\n"
|
|
217
|
+
"- data: list of objects, each with keys 'phit' (float, required) and 'swirr' (float, required)\n"
|
|
218
|
+
"Example (truncated): { 'data': [ {'phit': 0.18, 'swirr': 0.25}, ... ] }"
|
|
219
|
+
),
|
|
220
|
+
operation_id="estimate_kozeny_carman_permeability",
|
|
221
|
+
)
|
|
222
|
+
async def estimate_perm_kozeny_carman(inputs: PermOthersInputData) -> List[Dict[str, float]]:
|
|
223
|
+
"""
|
|
224
|
+
Estimate permeability using the Kozeny-Carman equation.
|
|
225
|
+
|
|
226
|
+
This endpoint receives input data containing porosity (phit) and irreducible water saturation (swirr) values,
|
|
227
|
+
applies the Kozeny-Carman permeability model to each record, and returns the estimated permeability values.
|
|
228
|
+
|
|
229
|
+
Args:
|
|
230
|
+
inputs (PermOthersInputData): Input data model containing a list of records with 'phit' and 'swirr'.
|
|
231
|
+
Returns:
|
|
232
|
+
List[Dict[str, float]]: A list of dictionaries, each containing the estimated permeability ('PERM')
|
|
233
|
+
for the corresponding input record.
|
|
234
|
+
Technical Details:
|
|
235
|
+
- The function expects a JSON body matching the PermOthersInputData schema.
|
|
236
|
+
- For each record in the input data, the Kozeny-Carman equation is applied via the
|
|
237
|
+
`kozeny_carman_permeability` function (applied row-wise, not vectorized).
|
|
238
|
+
- The results are returned as a list of dictionaries, suitable for API responses.
|
|
239
|
+
- Errors are logged and returned as HTTP 400 errors.
|
|
240
|
+
"""
|
|
241
|
+
try:
|
|
242
|
+
input_dict = inputs.model_dump()
|
|
243
|
+
input_df = pd.DataFrame.from_records(input_dict['data'])
|
|
244
|
+
perm = input_df.apply(lambda row: kozeny_carman_permeability(row['phit'], row['swirr']), axis=1)
|
|
245
|
+
df_result = pd.DataFrame({'PERM': perm.ravel()})
|
|
246
|
+
return [
|
|
247
|
+
{str(k): float(v) for k, v in row.items()}
|
|
248
|
+
for row in df_result.to_dict(orient='records')
|
|
249
|
+
]
|
|
250
|
+
except Exception as e:
|
|
251
|
+
logger.error(f"Error in estimate_perm_kozeny_carman: {e}")
|
|
252
|
+
raise HTTPException(status_code=400, detail=str(e))
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
from fastapi import APIRouter
|
|
2
|
+
from quick_pp.api.schemas.porosity import InputData
|
|
3
|
+
from quick_pp.lithology.sand_silt_clay import SandSiltClay
|
|
4
|
+
from quick_pp.porosity import neu_den_xplot_poro, density_porosity, rho_matrix
|
|
5
|
+
from typing import List, Dict
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
router = APIRouter(prefix="/porosity", tags=["Porosity"])
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _validate_points(input_dict: dict, required_points: List[str]):
|
|
12
|
+
for k in required_points:
|
|
13
|
+
if input_dict.get(k) is not None and len(input_dict[k]) != 2:
|
|
14
|
+
raise ValueError(
|
|
15
|
+
f"{k} must be a tuple of 2 elements: (neutron porosity, bulk density)"
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@router.post(
|
|
20
|
+
"/den",
|
|
21
|
+
summary="Estimate Density Porosity (PHID)",
|
|
22
|
+
description=(
|
|
23
|
+
"""
|
|
24
|
+
Estimate Density Porosity (PHID) using the density porosity method.
|
|
25
|
+
The `InputData` Pydantic model includes:
|
|
26
|
+
- data: List of measurement objects, each with:
|
|
27
|
+
- nphi (float): Neutron porosity value.
|
|
28
|
+
- rhob (float): Bulk density value.
|
|
29
|
+
- dry_sand_point: Tuple[float, float] - Reference point for dry sand (nphi, rhob).
|
|
30
|
+
- dry_silt_point: Tuple[float, float] - Reference point for dry silt (nphi, rhob).
|
|
31
|
+
- dry_clay_point: Tuple[float, float] - Reference point for dry clay (nphi, rhob).
|
|
32
|
+
- fluid_point: Tuple[float, float] - Reference point for fluid (nphi, rhob).
|
|
33
|
+
- wet_clay_point: Optional[Tuple[float, float]] - Reference point for wet clay (nphi, rhob), optional.
|
|
34
|
+
- silt_line_angle: float - Angle parameter for the silt line.
|
|
35
|
+
- method: Optional[str] - Crossplot model or method to use (used in /neu_den endpoint).
|
|
36
|
+
"""
|
|
37
|
+
),
|
|
38
|
+
operation_id="estimate_density_porosity",
|
|
39
|
+
)
|
|
40
|
+
async def estimate_phit_den(inputs: InputData) -> List[Dict[str, float]]:
|
|
41
|
+
"""
|
|
42
|
+
Estimates density porosity (PHID) for a set of input data using a sand-silt-clay (SSC) model.
|
|
43
|
+
This asynchronous function receives input containing neutron porosity (nphi) and bulk density (rhob) measurements,
|
|
44
|
+
along with reference points for dry sand, silt, clay, fluid, and optionally wet clay. It validates the input points,
|
|
45
|
+
constructs an SSC model, estimates lithology fractions (sand, silt, clay), computes matrix density, and finally
|
|
46
|
+
calculates density porosity for each data point.
|
|
47
|
+
Args:
|
|
48
|
+
inputs (InputData): Input data object containing:
|
|
49
|
+
- data: List of measurements, each with 'nphi' and 'rhob' attributes.
|
|
50
|
+
- dry_sand_point, dry_silt_point, dry_clay_point: Reference points for dry sand, silt, and clay (tuples).
|
|
51
|
+
- fluid_point: Reference point for fluid (tuple).
|
|
52
|
+
- wet_clay_point (optional): Reference point for wet clay (tuple or None).
|
|
53
|
+
- silt_line_angle: Angle parameter for the silt line.
|
|
54
|
+
- Other required fields as defined in InputData.
|
|
55
|
+
The request body is validated and an example is provided via the EXAMPLE constant.
|
|
56
|
+
Returns:
|
|
57
|
+
List[Dict[str, float]]: A list of dictionaries, each containing the estimated density porosity value
|
|
58
|
+
for a data point, with the key "PHID".
|
|
59
|
+
Raises:
|
|
60
|
+
ValidationError: If required reference points are missing or invalid.
|
|
61
|
+
Any exceptions raised by the SandSiltClay model or utility functions.
|
|
62
|
+
Technical Details:
|
|
63
|
+
- Uses the SandSiltClay model to estimate lithology fractions (vsand, vsilt, vcld) from input nphi and rhob.
|
|
64
|
+
- Computes matrix density (rho_ma) for each data point using the estimated lithology fractions.
|
|
65
|
+
- Calculates density porosity (PHID) using the measured bulk density (rhob), computed matrix density (rho_ma),
|
|
66
|
+
and the fluid density (from inputs.fluid_point[1]).
|
|
67
|
+
- Returns the results as a list of dictionaries, each with a single key "PHID" and its corresponding value.
|
|
68
|
+
"""
|
|
69
|
+
input_dict = inputs.model_dump()
|
|
70
|
+
_validate_points(input_dict, [k for k in input_dict if k.endswith('_point')])
|
|
71
|
+
|
|
72
|
+
nphi = np.array([d.nphi for d in inputs.data])
|
|
73
|
+
rhob = np.array([d.rhob for d in inputs.data])
|
|
74
|
+
|
|
75
|
+
ssc_model = SandSiltClay(
|
|
76
|
+
dry_sand_point=inputs.dry_sand_point,
|
|
77
|
+
dry_silt_point=inputs.dry_silt_point,
|
|
78
|
+
dry_clay_point=inputs.dry_clay_point,
|
|
79
|
+
fluid_point=inputs.fluid_point,
|
|
80
|
+
wet_clay_point=inputs.wet_clay_point if inputs.wet_clay_point is not None else (None, None),
|
|
81
|
+
silt_line_angle=inputs.silt_line_angle,
|
|
82
|
+
)
|
|
83
|
+
vsand, vsilt, vcld, _ = ssc_model.estimate_lithology(nphi, rhob)
|
|
84
|
+
rho_ma = [rho_matrix(vs, vsi, vc) for vs, vsi, vc in zip(vsand, vsilt, vcld)]
|
|
85
|
+
phid = [density_porosity(rhb, rhma, inputs.fluid_point[1]) for rhb, rhma in zip(rhob, rho_ma)]
|
|
86
|
+
return [{"PHID": float(val)} for val in phid]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@router.post(
|
|
90
|
+
"/neu_den",
|
|
91
|
+
summary="Estimate Total Porosity (PHIT)",
|
|
92
|
+
description=(
|
|
93
|
+
"""
|
|
94
|
+
Estimate Total Porosity (PHIT) using neutron-density crossplot analysis.
|
|
95
|
+
The `InputData` Pydantic model includes:
|
|
96
|
+
- data: List of measurement objects, each with:
|
|
97
|
+
- nphi (float): Neutron porosity value.
|
|
98
|
+
- rhob (float): Bulk density value.
|
|
99
|
+
- dry_sand_point: Tuple[float, float] - Reference point for dry sand (nphi, rhob).
|
|
100
|
+
- dry_silt_point: Tuple[float, float] - Reference point for dry silt (nphi, rhob).
|
|
101
|
+
- dry_clay_point: Tuple[float, float] - Reference point for dry clay (nphi, rhob).
|
|
102
|
+
- fluid_point: Tuple[float, float] - Reference point for fluid (nphi, rhob).
|
|
103
|
+
- wet_clay_point: Optional[Tuple[float, float]] - Reference point for wet clay (nphi, rhob), optional.
|
|
104
|
+
- silt_line_angle: float - Angle parameter for the silt line.
|
|
105
|
+
- method: Optional[str] - Crossplot model or method to use (used in /neu_den endpoint).
|
|
106
|
+
"""
|
|
107
|
+
),
|
|
108
|
+
operation_id="estimate_total_porosity",
|
|
109
|
+
)
|
|
110
|
+
async def estimate_phit_neu_den(inputs: InputData) -> List[Dict[str, float]]:
|
|
111
|
+
"""
|
|
112
|
+
This asynchronous endpoint receives input data containing neutron porosity (NPHI) and bulk density (RHOB)
|
|
113
|
+
measurements, along with reference points for dry sand, silt, clay, and fluid, and applies a crossplot
|
|
114
|
+
porosity estimation method.
|
|
115
|
+
Parameters:
|
|
116
|
+
inputs (InputData):
|
|
117
|
+
The input data object, expected as a request body, containing:
|
|
118
|
+
- data: List of measurement objects, each with 'nphi' (neutron porosity) and 'rhob' (bulk density).
|
|
119
|
+
- method: The crossplot model or method to use for porosity estimation.
|
|
120
|
+
- dry_sand_point: Reference point for dry sand in the crossplot.
|
|
121
|
+
- dry_silt_point: Reference point for dry silt in the crossplot.
|
|
122
|
+
- dry_clay_point: Reference point for dry clay in the crossplot.
|
|
123
|
+
- fluid_point: Reference point for fluid in the crossplot.
|
|
124
|
+
Returns:
|
|
125
|
+
List[Dict[str, float]]:
|
|
126
|
+
A list of dictionaries, each containing the estimated total porosity ('PHIT') value for the corresponding
|
|
127
|
+
input data point.
|
|
128
|
+
Raises:
|
|
129
|
+
ValidationError: If required reference points are missing or invalid in the input data.
|
|
130
|
+
Notes:
|
|
131
|
+
- The function validates that all required crossplot reference points are present.
|
|
132
|
+
- The porosity estimation is performed using the `neu_den_xplot_poro` function, which implements the
|
|
133
|
+
neutron-density crossplot algorithm.
|
|
134
|
+
- The output is formatted as a list of dictionaries for compatibility with API responses.
|
|
135
|
+
"""
|
|
136
|
+
input_dict = inputs.model_dump()
|
|
137
|
+
_validate_points(input_dict, [k for k in input_dict if k.endswith('_point')])
|
|
138
|
+
|
|
139
|
+
nphi = np.array([d.nphi for d in inputs.data])
|
|
140
|
+
rhob = np.array([d.rhob for d in inputs.data])
|
|
141
|
+
|
|
142
|
+
phit = neu_den_xplot_poro(
|
|
143
|
+
nphi,
|
|
144
|
+
rhob,
|
|
145
|
+
model=inputs.method,
|
|
146
|
+
dry_min1_point=inputs.dry_sand_point,
|
|
147
|
+
dry_silt_point=inputs.dry_silt_point,
|
|
148
|
+
dry_clay_point=inputs.dry_clay_point,
|
|
149
|
+
fluid_point=inputs.fluid_point,
|
|
150
|
+
)
|
|
151
|
+
return [{"PHIT": float(val)} for val in phit]
|