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.
Files changed (69) hide show
  1. quick_pp/__init__.py +0 -0
  2. quick_pp/api/__init__.py +0 -0
  3. quick_pp/api/exceptions.py +61 -0
  4. quick_pp/api/fastapi_mlflow/__init__.py +1 -0
  5. quick_pp/api/fastapi_mlflow/_mlflow_types.py +59 -0
  6. quick_pp/api/fastapi_mlflow/applications.py +72 -0
  7. quick_pp/api/fastapi_mlflow/exceptions.py +22 -0
  8. quick_pp/api/fastapi_mlflow/predictors.py +96 -0
  9. quick_pp/api/main.py +90 -0
  10. quick_pp/api/mlflow_model_deployment.py +99 -0
  11. quick_pp/api/qpp_assistant.py +160 -0
  12. quick_pp/api/router.py +18 -0
  13. quick_pp/api/schemas/lithology_hc_correction.py +39 -0
  14. quick_pp/api/schemas/lithology_ssc.py +37 -0
  15. quick_pp/api/schemas/lithology_vsh_gr.py +25 -0
  16. quick_pp/api/schemas/permeability_choo.py +25 -0
  17. quick_pp/api/schemas/permeability_others.py +24 -0
  18. quick_pp/api/schemas/porosity.py +22 -0
  19. quick_pp/api/schemas/ressum.py +29 -0
  20. quick_pp/api/schemas/saturation_archie.py +25 -0
  21. quick_pp/api/schemas/saturation_b.py +24 -0
  22. quick_pp/api/schemas/saturation_qv.py +26 -0
  23. quick_pp/api/schemas/saturation_rw.py +24 -0
  24. quick_pp/api/schemas/saturation_temp_grad.py +24 -0
  25. quick_pp/api/schemas/saturation_waxman_smits.py +28 -0
  26. quick_pp/api/services/las_handler.py +136 -0
  27. quick_pp/api/services/lithology.py +278 -0
  28. quick_pp/api/services/permeability.py +252 -0
  29. quick_pp/api/services/porosity.py +151 -0
  30. quick_pp/api/services/reservoir_summary.py +78 -0
  31. quick_pp/api/services/saturation.py +359 -0
  32. quick_pp/api/static/favicon.ico +0 -0
  33. quick_pp/api/static/logo.png +0 -0
  34. quick_pp/cli.py +118 -0
  35. quick_pp/config.py +94 -0
  36. quick_pp/core_calibration.py +394 -0
  37. quick_pp/fluid_type.py +128 -0
  38. quick_pp/geomechanics.py +195 -0
  39. quick_pp/las_handler.py +327 -0
  40. quick_pp/lithology/__init__.py +80 -0
  41. quick_pp/lithology/carbonate.py +166 -0
  42. quick_pp/lithology/multi_mineral.py +151 -0
  43. quick_pp/lithology/sand_shale.py +79 -0
  44. quick_pp/lithology/sand_silt_clay.py +131 -0
  45. quick_pp/logger.py +19 -0
  46. quick_pp/modelling/__init__.py +0 -0
  47. quick_pp/modelling/config.py +72 -0
  48. quick_pp/modelling/mock_data/mock_data.parquet +0 -0
  49. quick_pp/modelling/predict_pipeline.py +126 -0
  50. quick_pp/modelling/train_pipeline.py +220 -0
  51. quick_pp/modelling/utils.py +111 -0
  52. quick_pp/objects.py +177 -0
  53. quick_pp/permeability.py +151 -0
  54. quick_pp/plotter/__init__.py +0 -0
  55. quick_pp/plotter/plotter.py +315 -0
  56. quick_pp/plotter/well_log.py +187 -0
  57. quick_pp/plotter/well_log_config.py +409 -0
  58. quick_pp/porosity.py +341 -0
  59. quick_pp/qaqc.py +436 -0
  60. quick_pp/ressum.py +326 -0
  61. quick_pp/rock_type.py +499 -0
  62. quick_pp/saturation.py +455 -0
  63. quick_pp/utils.py +328 -0
  64. quick_pp-0.2.3.dist-info/METADATA +103 -0
  65. quick_pp-0.2.3.dist-info/RECORD +69 -0
  66. quick_pp-0.2.3.dist-info/WHEEL +4 -0
  67. quick_pp-0.2.3.dist-info/entry_points.txt +2 -0
  68. quick_pp-0.2.3.dist-info/licenses/AUTHORS.rst +13 -0
  69. quick_pp-0.2.3.dist-info/licenses/LICENSE +22 -0
quick_pp/ressum.py ADDED
@@ -0,0 +1,326 @@
1
+ import numpy as np
2
+ import pandas as pd
3
+ from scipy.stats import gmean, hmean
4
+ from scipy.stats import truncnorm
5
+ import random
6
+ import matplotlib.pyplot as plt
7
+ import ptitprince as pt
8
+ from SALib.analyze.sobol import analyze
9
+ from SALib.sample.sobol import sample
10
+
11
+
12
+ def calc_reservoir_summary(depth, vshale, phit, swt, perm, zones,
13
+ cutoffs=dict(VSHALE=0.4, PHIT=0.01, SWT=0.9), uom: str = 'ft'):
14
+ """Calculate reservoir summary based on cutoffs on vshale, phit, and swt.
15
+
16
+ Args:
17
+ depth (float): Depth either in MD or TVD.
18
+ vshale (float): Volume of shale in fraction.
19
+ phit (float): Total porosity in fraction.
20
+ swt (float): Total water saturation in fraction
21
+ zones (str): Zone names.
22
+ cutoffs (dict, optional): {VSHALE: x, PHIT: y, SWT: z}. Defaults to dict(VSHALE=0.4, PHIT=0.01, SWT=0.9).
23
+ uom (str, optional): Unit of measurement for depth. Defaults to 'ft'.
24
+
25
+ Returns:
26
+ pd.Dataframe: Reservoir summary in tabular format.
27
+ """
28
+ step = 0.1524 if uom == 'm' else 0.5
29
+ df = pd.DataFrame({'depth': depth, 'vshale': vshale, 'phit': phit, 'swt': swt, 'perm': perm, 'zones': zones})
30
+ df['bvo'] = df['phit'] * (1 - df['swt'])
31
+ df['rock_flag'], df['reservoir_flag'], df['pay_flag'] = flag_interval(df['vshale'], df['phit'], df['swt'], cutoffs)
32
+ df['all_flag'] = 1
33
+ ressum_df = pd.DataFrame()
34
+ for flag in ['all', 'rock', 'reservoir', 'pay']:
35
+ temp_df = pd.DataFrame()
36
+ # Calculate net thickness
37
+ temp_df[["zones", "net"]] = df.groupby(["zones"])[[f"{flag}_flag"]].agg(
38
+ lambda x: np.nansum(x) * step).reset_index()
39
+
40
+ # Average the properties and merge
41
+ flag_df = df[df[f"{flag}_flag"] == 1].copy()
42
+ avg_df = flag_df.groupby(["zones"]).agg({
43
+ "vshale": lambda x: np.nanmean(x),
44
+ "phit": lambda x: np.nanmean(x),
45
+ "swt": lambda x: np.nanmean(x),
46
+ "bvo": lambda x: np.nanmean(x)
47
+ }).reset_index().rename(columns={"vshale": "av_vshale", "phit": "av_phit", "swt": "av_swt", "bvo": "av_bvo"})
48
+ avg_df['perm_am'] = flag_df.groupby('zones')['perm'].agg('mean').reset_index(drop=True)
49
+ avg_df['perm_gm'] = flag_df.groupby('zones')['perm'].agg(gmean, nan_policy='omit').reset_index(drop=True)
50
+ avg_df['perm_hm'] = flag_df.groupby('zones')['perm'].agg(hmean, nan_policy='omit').reset_index(drop=True)
51
+ temp_df = temp_df.merge(avg_df, on=["zones"], how="left", validate="1:1")
52
+
53
+ # Calculate gross thickness
54
+ gross = df.groupby(["zones"])[["depth"]].agg(lambda x: np.nanmax(x) - np.nanmin(x)).reset_index().rename(
55
+ columns={"depth": "gross"})
56
+ temp_df = temp_df.merge(gross[["zones", 'gross']], on=["zones"], how="left", validate="1:1")
57
+ temp_df['ntg'] = temp_df['net'] / temp_df['gross']
58
+
59
+ # Set the maximum depth as bottom depth
60
+ bottom = df.groupby(["zones"])[["depth"]].agg(lambda x: np.nanmax(x)).reset_index().rename(
61
+ columns={"depth": "bottom"})
62
+ temp_df = temp_df.merge(bottom[["zones", 'bottom']], on=["zones"], how="left", validate="1:1")
63
+
64
+ # Set the minimum depth as top depth
65
+ top = df.groupby(["zones"])[["depth"]].agg(lambda x: np.nanmin(x)).reset_index().rename(
66
+ columns={"depth": "top"})
67
+ temp_df = temp_df.merge(top[["zones", 'top']], on=["zones"], how="left", validate="1:1")
68
+ temp_df['flag'] = flag
69
+
70
+ # Concat to ressum_df
71
+ ressum_df = pd.concat([ressum_df, temp_df], ignore_index=True)
72
+
73
+ ressum_df = ressum_df.round(3)
74
+ ressum_df = ressum_df.sort_values(by=['top'], ignore_index=True)
75
+
76
+ # Sort the columns
77
+ cols = ['zones', 'flag', 'top', 'bottom', 'gross', 'net', 'ntg',
78
+ 'av_vshale', 'av_phit', 'av_swt', 'av_bvo', 'perm_am', 'perm_gm', 'perm_hm']
79
+
80
+ return ressum_df[cols]
81
+
82
+
83
+ def flag_interval(vshale, phit, swt, cutoffs: dict):
84
+ """Flag interval based on cutoffs.
85
+
86
+ Args:
87
+ vshale (float): Vshale.
88
+ phit (float): Total porosity.
89
+ swt (float): Water saturation.
90
+ cutoffs (list, optional): List of cutoffs. Defaults to [].
91
+
92
+ Returns:
93
+ float: Flagged interval.
94
+ """
95
+ assert len(cutoffs) == 3, 'cutoffs must be 3 key-value pairs: {VSHALE: x, PHIT: y, SWT: z}.'
96
+ rock_flag = np.where(vshale < cutoffs['VSHALE'], 1, 0)
97
+ reservoir_flag = np.where(rock_flag == 1, np.where(phit > cutoffs['PHIT'], 1, 0), 0)
98
+ pay_flag = np.where(reservoir_flag == 1, np.where(swt < cutoffs['SWT'], 1, 0), 0)
99
+
100
+ return rock_flag, reservoir_flag, pay_flag
101
+
102
+
103
+ def volumetric_method(
104
+ area_bound: tuple,
105
+ thickness_bound: tuple,
106
+ porosity_bound: tuple,
107
+ water_saturation_bound: tuple,
108
+ volume_factor_bound: tuple,
109
+ recovery_factor_bound: tuple = (),
110
+ random_state=None
111
+ ):
112
+ """Calculate volume using the volumetric method.
113
+
114
+ Args:
115
+ area_bound (tuple): (min, max, mean, std) in acre.
116
+ - Truncated normal distribution parameters for area.
117
+ thickness_bound (tuple): (min, max, mean, std) in feet.
118
+ - Truncated normal distribution parameters for thickness.
119
+ porosity_bound (tuple): (min, max, mean, std) in fraction.
120
+ - Truncated normal distribution parameters for porosity.
121
+ water_saturation_bound (tuple): (min, max, mean, std) in fraction.
122
+ - Truncated normal distribution parameters for water saturation.
123
+ volume_factor_bound (tuple): (min, max) unitless.
124
+ - Uniform distribution parameters for volume factor.
125
+ recovery_factor_bound (tuple): (min, max, mean, std) in fraction.
126
+ - Truncated normal distribution parameters for RF.
127
+ random_state (int, optional): Random seed. Defaults to 123.
128
+
129
+ Returns:
130
+ float: Estimated volume in MM bbl.
131
+ """
132
+ random.seed(random_state)
133
+ a_min_transformed = (area_bound[0] - area_bound[2]) / area_bound[3]
134
+ a_max_transformed = (area_bound[1] - area_bound[2]) / area_bound[3]
135
+ a = truncnorm.rvs(a_min_transformed, a_max_transformed,
136
+ loc=area_bound[2], scale=area_bound[3], random_state=random_state)
137
+
138
+ h_min_transformed = (thickness_bound[0] - thickness_bound[2]) / thickness_bound[3]
139
+ h_max_transformed = (thickness_bound[1] - thickness_bound[2]) / thickness_bound[3]
140
+ h = truncnorm.rvs(h_min_transformed, h_max_transformed,
141
+ loc=thickness_bound[2], scale=thickness_bound[3], random_state=random_state)
142
+
143
+ poro_min_transformed = (porosity_bound[0] - porosity_bound[2]) / porosity_bound[3]
144
+ poro_max_transformed = (porosity_bound[1] - porosity_bound[2]) / porosity_bound[3]
145
+ poro = truncnorm.rvs(poro_min_transformed, poro_max_transformed,
146
+ loc=porosity_bound[2], scale=porosity_bound[3], random_state=random_state)
147
+ sw_min_transformed = (water_saturation_bound[0] - water_saturation_bound[2]) / water_saturation_bound[3]
148
+ sw_max_transformed = (water_saturation_bound[1] - water_saturation_bound[2]) / water_saturation_bound[3]
149
+ sw = truncnorm.rvs(sw_min_transformed, sw_max_transformed,
150
+ loc=water_saturation_bound[2], scale=water_saturation_bound[3], random_state=random_state)
151
+
152
+ bo = random.uniform(volume_factor_bound[0], volume_factor_bound[1])
153
+
154
+ if recovery_factor_bound is not None:
155
+ rf_min_transformed = (recovery_factor_bound[0] - recovery_factor_bound[2]) / recovery_factor_bound[3]
156
+ rf_max_transformed = (recovery_factor_bound[1] - recovery_factor_bound[2]) / recovery_factor_bound[3]
157
+ rf = truncnorm.rvs(rf_min_transformed, rf_max_transformed,
158
+ loc=recovery_factor_bound[2], scale=recovery_factor_bound[3], random_state=random_state)
159
+ else:
160
+ rf = 1.0
161
+ return a, h, poro, sw, bo, rf
162
+
163
+
164
+ def mc_volumetric_method(
165
+ area_bound: tuple,
166
+ thickness_bound: tuple,
167
+ porosity_bound: tuple,
168
+ water_saturation_bound: tuple,
169
+ volume_factor_bound: tuple,
170
+ n_try=10000, percentile=[10, 50, 90]
171
+ ):
172
+ """Monte Carlo simulation for volumetric method.
173
+
174
+ Args:
175
+ area_bound (tuple): (min, max, mean, std) in acre.
176
+ - Truncated normal distribution parameters for area.
177
+ thickness_bound (tuple): (min, max, mean, std) in feet.
178
+ - Truncated normal distribution parameters for thickness.
179
+ porosity_bound (tuple): (min, max, mean, std) in fraction.
180
+ - Truncated normal distribution parameters for porosity.
181
+ water_saturation_bound (tuple): (min, max, mean, std) in fraction.
182
+ - Truncated normal distribution parameters for water saturation.
183
+ volume_factor_bound (tuple): (min, max) unitless.
184
+ - Uniform distribution parameters for volume factor.
185
+ n_try (int, optional): Number of trials. Defaults to 10000.
186
+ percentile (list, optional): Percentiles to calculate. Defaults to [10, 50, 90].
187
+ """
188
+ area = np.empty(0)
189
+ thickness = np.empty(0)
190
+ porosity = np.empty(0)
191
+ water_saturation = np.empty(0)
192
+ volume_factor = np.empty(0)
193
+ volumes = np.empty(0)
194
+ for i in range(n_try):
195
+ a, h, poro, sw, bo, _ = volumetric_method(
196
+ area_bound=area_bound,
197
+ thickness_bound=thickness_bound,
198
+ porosity_bound=porosity_bound,
199
+ water_saturation_bound=water_saturation_bound,
200
+ volume_factor_bound=volume_factor_bound
201
+ )
202
+ area = np.append(area, a)
203
+ thickness = np.append(thickness, h)
204
+ porosity = np.append(porosity, poro)
205
+ water_saturation = np.append(water_saturation, sw)
206
+ volume_factor = np.append(volume_factor, bo)
207
+ result = (43560 * 0.1781) * a * h * poro * (1 - sw) / bo
208
+ volumes = np.append(volumes, result * 1e-6)
209
+
210
+ # Plot tornado chart
211
+ data = pd.DataFrame({
212
+ 'Area': area,
213
+ 'Thickness': thickness,
214
+ 'Porosity': porosity,
215
+ 'Water Saturation': water_saturation,
216
+ 'Volume Factor': volume_factor,
217
+ 'Volume': volumes
218
+ })
219
+ fig, axs = plt.subplots(5, 1, figsize=(7, 11), constrained_layout=True)
220
+ pt.RainCloud(data=data, y='Area', ax=axs[0], orient='h', bw=0.1, width_viol=0.5, alpha=0.6, dodge=True)
221
+ axs[0].set_ylabel('Area (acre)')
222
+ pt.RainCloud(data=data, y='Thickness', ax=axs[1], orient='h', bw=0.1, width_viol=0.5, alpha=0.6, dodge=True)
223
+ axs[1].set_ylabel('Thickness (ft)')
224
+ pt.RainCloud(data=data, y='Porosity', ax=axs[2], orient='h', bw=0.1, width_viol=0.5, alpha=0.6, dodge=True)
225
+ axs[2].set_ylabel('Porosity (frac)')
226
+ pt.RainCloud(data=data, y='Water Saturation', ax=axs[3], orient='h', bw=0.1, width_viol=0.5, alpha=0.6, dodge=True)
227
+ axs[3].set_ylabel('Water Saturation (frac)')
228
+ pt.RainCloud(data=data, y='Volume Factor', ax=axs[4], orient='h', bw=0.1, width_viol=0.5, alpha=0.6, dodge=True)
229
+ axs[4].set_ylabel('Volume Factor')
230
+ fig.set_facecolor('aliceblue')
231
+ fig.show()
232
+
233
+ plt.figure(figsize=(12, 6))
234
+ a = np.hstack(volumes.tolist())
235
+ _ = plt.hist(a, density=True, bins='auto') # arguments are passed to np.histogram
236
+ plt.title(f"Volume Estimation ({n_try} samples)")
237
+ plt.xlabel('Volume (MM bbl)')
238
+ for i, pct in enumerate(np.percentile(volumes, percentile)):
239
+ plt.axvline(x=pct, color='r', linestyle='dashed', label=f'P{percentile[i]}: {round(pct)} MM bbl')
240
+ plt.legend(bbox_to_anchor=(1.04, 1), loc="upper left")
241
+
242
+ return volumes, area, thickness, porosity, water_saturation, volume_factor
243
+
244
+
245
+ def calculate_volume(x, area, thickness, porosity, water_saturation, volume_factor, recovery_factor=1):
246
+ """Calculate volume using the volumetric method.
247
+
248
+ Args:
249
+ area (float): Area in acre.
250
+ thickness (float): Thickness in feet.
251
+ porosity (float): Porosity in fraction.
252
+ water_saturation (float): Water saturation in fraction.
253
+ volume_factor (float): Volume factor.
254
+ recovery_factor (float): Recovery factor in fraction.
255
+
256
+ Returns:
257
+ float: Estimated volume in MM bbl.
258
+ """
259
+ return x * (43560 * 0.1781) * area * thickness * porosity * (1 - water_saturation) / (
260
+ volume_factor) * recovery_factor * 1e-6
261
+
262
+
263
+ def sensitivity_analysis(
264
+ area_bound: tuple,
265
+ thickness_bound: tuple,
266
+ porosity_bound: tuple,
267
+ water_saturation_bound: tuple,
268
+ volume_factor_bound: tuple
269
+ ):
270
+ """Sensitivity analysis for volumetric method.
271
+
272
+ Args:
273
+ area_bound (tuple): (min, max, mean, std) in acre.
274
+ - Truncated normal distribution parameters for area.
275
+ thickness_bound (tuple): (min, max, mean, std) in feet.
276
+ - Truncated normal distribution parameters for thickness.
277
+ porosity_bound (tuple): (min, max, mean, std) in fraction.
278
+ - Truncated normal distribution parameters for porosity.
279
+ water_saturation_bound (tuple): (min, max, mean, std) in fraction.
280
+ - Truncated normal distribution parameters for water saturation.
281
+ volume_factor_bound (tuple): (min, max) unitless.
282
+ - Uniform distribution parameters for volume factor.
283
+ """
284
+ # Define the model inputs
285
+ problem = {
286
+ 'num_vars': 5,
287
+ 'names': ['area', 'thickness', 'porosity', 'water_saturation', 'volume_factor'],
288
+ 'bounds': [
289
+ [area_bound[0], area_bound[1]],
290
+ [thickness_bound[0], thickness_bound[1]],
291
+ [porosity_bound[0], porosity_bound[1]],
292
+ [water_saturation_bound[0], water_saturation_bound[1]],
293
+ [volume_factor_bound[0], volume_factor_bound[1]]
294
+ ]
295
+ }
296
+
297
+ # Generate samples
298
+ param_values = sample(problem, 2**10)
299
+
300
+ # evaluate
301
+ x = np.linspace(-1, 1, 100)
302
+ y = np.array([calculate_volume(x, *params) for params in param_values])
303
+
304
+ # analyse
305
+ Si = [analyze(problem, Y) for Y in y.T][0]
306
+
307
+ # Extract the sensitivity indices
308
+ S1 = Si['S1']
309
+ S1_conf = Si['S1_conf']
310
+ names = problem['names']
311
+
312
+ # Sort the indices for better visualization
313
+ sorted_indices = np.argsort(S1)
314
+ sorted_S1 = S1[sorted_indices]
315
+ sorted_S1_conf = S1_conf[sorted_indices]
316
+ sorted_names = [names[i] for i in sorted_indices]
317
+
318
+ # Plot the tornado chart
319
+ plt.figure(figsize=(10, 6))
320
+ plt.barh(range(len(sorted_S1)), sorted_S1, xerr=sorted_S1_conf,
321
+ align='center', alpha=0.7, color='blue', ecolor='black')
322
+ plt.yticks(range(len(sorted_S1)), sorted_names)
323
+ plt.xlabel('First-order Sensitivity Index')
324
+ plt.title('Tornado Chart of Sensitivity Indices')
325
+ plt.grid(True)
326
+ plt.show()