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
@@ -0,0 +1,394 @@
1
+ from scipy.optimize import curve_fit
2
+ import matplotlib.pyplot as plt
3
+ import numpy as np
4
+ import plotly.graph_objects as go
5
+
6
+ from quick_pp.utils import power_law_func, inv_power_law_func
7
+ from quick_pp.logger import logger
8
+
9
+
10
+ plt.style.use('seaborn-v0_8-paper')
11
+ plt.rcParams.update(
12
+ {
13
+ 'axes.labelsize': 10,
14
+ 'xtick.labelsize': 10,
15
+ 'legend.fontsize': 'small'
16
+ }
17
+ )
18
+
19
+
20
+ # Cross plots
21
+ def poroperm_xplot(poro, perm, a=None, b=None, core_group=None, label='', log_log=False):
22
+ """Generate porosity-permeability cross plot.
23
+
24
+ Args:
25
+ poro (float): Core porosity (frac).
26
+ perm (float): Core permeability (mD).
27
+ a (float, optional): a constant in perm=a*poro^b. Defaults to None.
28
+ b (float, optional): b constant in perm=a*poro^b. Defaults to None.
29
+ label (str, optional): Label for the data group. Defaults to ''.
30
+ log_log (bool, optional): Whether to plot log-log or not. Defaults to False.
31
+ """
32
+ sc = plt.scatter(poro, perm, marker='.', c=core_group, cmap='Set1')
33
+ if core_group is not None:
34
+ for i, row in enumerate(zip(poro, perm, core_group)):
35
+ plt.annotate(row[2], (row[0], row[1]), fontsize=8, alpha=0.7)
36
+ if a and b:
37
+ line_color = sc.get_facecolors()[0]
38
+ line_color[-1] = 0.5
39
+ cpore = np.geomspace(0.01, 0.5, 30)
40
+ plt.plot(cpore, power_law_func(cpore, a, b), color=line_color, label=label, linestyle='dashed')
41
+ plt.legend(bbox_to_anchor=(1.04, 1), loc="upper left")
42
+ plt.xlabel('CPORE (frac)')
43
+ plt.xlim(0.001, 0.5)
44
+ plt.ylabel('CPERM (mD)')
45
+ plt.ylim(.001, 10000)
46
+ plt.yscale('log')
47
+ if log_log:
48
+ plt.xscale('log')
49
+
50
+
51
+ def bvw_xplot(bvw, pc, a=None, b=None, label=None, ylim=None, log_log=False):
52
+ """Generate bulk volume water-capillary pressure cross plot.
53
+
54
+ Args:
55
+ bvw (float): Calculated bulk volume water (frac) from core.
56
+ pc (float): Capillary pressure (psi) from core.
57
+ a (float, optional): a constant in pc=a*bvw^b. Defaults to None.
58
+ b (float, optional): b constant in pc=a*bvw^b. Defaults to None.
59
+ label (str, optional): Label for the data group. Defaults to ''.
60
+ ylim (tuple, optional): Range for the y axis in (min, max) format. Defaults to None.
61
+ log_log (bool, optional): Whether to plot log-log or not. Defaults to False.
62
+ """
63
+ sc = plt.plot(bvw, pc, marker='s', label=label)
64
+ if a is not None and b is not None:
65
+ line_color = sc[0].get_color() + '66' # Set opacity to 0
66
+ cbvw = np.linspace(0.05, 0.35, 30)
67
+ plt.scatter(cbvw, inv_power_law_func(cbvw, a, b), marker='x', color=line_color)
68
+ plt.xlabel('BVW (frac)')
69
+ plt.ylabel('Pc (psi)')
70
+ plt.ylim(ylim) if ylim else plt.ylim(0.01, plt.gca().get_lines()[-1].get_ydata().max())
71
+ if label:
72
+ plt.legend(bbox_to_anchor=(1.04, 1), loc="upper left")
73
+ if log_log:
74
+ plt.xscale('log')
75
+ plt.yscale('log')
76
+
77
+
78
+ def pc_xplot(sw, pc, label=None, ylim=None):
79
+ """Generate J-Sw cross plot.
80
+
81
+ Args:
82
+ sw (float): Core water saturation (frac).
83
+ j (float): Calculated J value (unitless).
84
+ a (float, optional): a constant in j=a*sw^b. Defaults to None.
85
+ b (float, optional): b constant in j=a*sw^b. Defaults to None.
86
+ label (str, optional): Label for the data group. Defaults to ''.
87
+ ylim (tuple, optional): Range for the y axis in (min, max) format. Defaults to None.
88
+ log_log (bool, optional): Whether to plot log-log or not. Defaults to False.
89
+ """
90
+ plt.plot(sw, pc, marker='.', label=label)
91
+ plt.xlabel('Sw (frac)')
92
+ plt.xlim(0.01, 1)
93
+ plt.ylabel('Pc (psi)')
94
+ plt.ylim(ylim) if ylim else plt.ylim(0.01, plt.gca().get_lines()[-1].get_ydata().max())
95
+ if label:
96
+ plt.legend(bbox_to_anchor=(1.04, 1), loc="upper left")
97
+
98
+
99
+ def pc_xplot_plotly(sw, pc, label=None, ylim=None, fig=go.Figure()):
100
+ """Generate J-Sw cross plot using Plotly.
101
+
102
+ Args:
103
+ sw (float): Core water saturation (frac).
104
+ pc (float): Capillary pressure (psi).
105
+ label (str, optional): Label for the data group. Defaults to ''.
106
+ ylim (tuple, optional): Range for the y axis in (min, max) format. Defaults to None.
107
+ """
108
+ fig.add_trace(go.Scatter(x=sw, y=pc, name=label))
109
+ fig.update_layout(
110
+ xaxis_title='Sw (frac)',
111
+ yaxis_title='Pc (psi)',
112
+ xaxis_range=[0, 1],
113
+ yaxis_range=[0, 50] if ylim is None else [ylim[0], ylim[1]],
114
+ legend=dict(x=1.04, y=1, traceorder='normal'),
115
+ height=500,
116
+ width=800
117
+ )
118
+ return fig
119
+
120
+
121
+ def j_xplot(sw, j, a=None, b=None, core_group=None, label=None, log_log=False, ax=None, ylim=None):
122
+ """Generate J-Sw cross plot.
123
+
124
+ Args:
125
+ sw (float): Core water saturation (frac).
126
+ j (float): Calculated J value (unitless).
127
+ a (float, optional): a constant in j=a*sw^b. Defaults to None.
128
+ b (float, optional): b constant in j=a*sw^b. Defaults to None.
129
+ label (str, optional): Label for the data group. Defaults to ''.
130
+ ylim (tuple, optional): Range for the y axis in (min, max) format. Defaults to None.
131
+ log_log (bool, optional): Whether to plot log-log or not. Defaults to False.
132
+ """
133
+ ax = ax or plt.gca()
134
+ scatter = ax.scatter(sw, j, marker='.', c=core_group, cmap='Set1')
135
+ if core_group is not None:
136
+ legend1 = ax.legend(*scatter.legend_elements(), title="Core Sample")
137
+ ax.add_artist(legend1)
138
+ if a is not None and b is not None:
139
+ csw = np.geomspace(0.01, 1.0, 20)
140
+ ax.plot(csw, inv_power_law_func(csw, a, b), label=label, linestyle='dashed')
141
+ ax.set_xlabel('Sw (frac)')
142
+ ax.set_xlim(0.01, 1)
143
+ ax.set_ylabel('J')
144
+ ax.set_ylim(ylim) if ylim else ax.set_ylim(0.01, max(ax.get_lines()[-1].get_ydata()))
145
+ if log_log:
146
+ ax.set_yscale('log')
147
+ ax.set_ylim(0.01, 100)
148
+ ax.set_xscale('log')
149
+ if label:
150
+ ax.legend(bbox_to_anchor=(1.04, 1), loc="upper left")
151
+ return ax
152
+
153
+
154
+ # Best-fit functions
155
+ def fit_j_curve(sw, j):
156
+ """Estimate a and b constants of best fit given core water saturation and J value.
157
+
158
+ Args:
159
+ sw (float): Core water saturation (frac).
160
+ j (float): Calculated J value (unitless).
161
+
162
+ Returns:
163
+ tuple: a and b constants from the best-fit curve.
164
+ """
165
+ try:
166
+ popt, _ = curve_fit(inv_power_law_func, sw, j, p0=[.01, 1])
167
+ a = [round(c, 3) for c in popt][0]
168
+ b = [round(c, 3) for c in popt][1]
169
+ return a, b
170
+ except Exception as e:
171
+ logger.error(e)
172
+ return 1, 1
173
+
174
+
175
+ def skelt_harrison_xplot(sw, pc, gw, ghc, a, b, c, d, core_group=None, label=None, ylim=None, ax=None):
176
+ """Generate Skelt-Harrison curve.
177
+
178
+ Args:
179
+ pc (float): Capillary pressure (psi).
180
+ sw (float): Core water saturation (frac).
181
+ h (float): Height above free water level (ft).
182
+ a (float): a constant from the best-fit curve. Related to Swirr.
183
+ b (float): b constant from the best-fit curve. Related to HAFWL.
184
+ c (float): c constant from the best-fit curve. Related to PTSD.
185
+ d (float): d constant from the best-fit curve. Related to entry pressure.
186
+ """
187
+ ax = ax or plt.gca()
188
+ ax.scatter(sw, pc, marker='.', c=core_group, cmap='Set1')
189
+ h = np.geomspace(.01, 10000, 100)
190
+ pci = h * (gw - ghc) * .433 # Convert g/cc to psi/ft
191
+ ax.plot(skelt_harrison_func(h, a, b, c, d), pci, label=label)
192
+ ax.set_ylabel('Pc (psi)')
193
+ ax.set_ylim(ylim) if ylim else ax.set_ylim(0.01, ax.get_lines()[-1].get_ydata().max())
194
+ ax.set_xlabel('Sw (frac)')
195
+ ax.set_xlim(0, 1)
196
+ ax.legend(bbox_to_anchor=(1.04, 1), loc="upper left")
197
+ return ax
198
+
199
+
200
+ def skelt_harrison_func(h, a, b, c, d):
201
+ return 1 - a * np.exp(-(b / (h + d))**c)
202
+
203
+
204
+ def fit_skelt_harrison_curve(sw, h):
205
+ """Estimate a and b constants of best fit given core water saturation and capillary pressure values.
206
+
207
+ Args:
208
+ sw (float): Core water saturation (frac).
209
+ h (float): Height above free water level (ft).
210
+
211
+ Returns:
212
+ tuple: a and b constants from the best-fit curve.
213
+ """
214
+ try:
215
+ popt, _ = curve_fit(skelt_harrison_func, h, sw, p0=[.9, 100, 1.5, 1.5])
216
+ a = [round(c, 3) for c in popt][0]
217
+ b = [round(c, 3) for c in popt][1]
218
+ c = [round(c, 3) for c in popt][2]
219
+ d = [round(c, 3) for c in popt][3]
220
+ return a, b, c, d
221
+ except Exception as e:
222
+ logger.error(e)
223
+ return 1, 1, 1, 1
224
+
225
+
226
+ def perm_transform(poro, a, b):
227
+ """Transform porosity to permeability using a and b constants.
228
+
229
+ Args:
230
+ poro (float): Core porosity (frac).
231
+ a (float): a constant from the best-fit curve.
232
+ b (float): b constant from the best-fit curve.
233
+
234
+ Returns:
235
+ float: Permeability (mD).
236
+ """
237
+ return a * poro**b
238
+
239
+
240
+ def fit_poroperm_curve(poro, perm):
241
+ """Estimate a and b constants of best fit given core porosity and permeability values.
242
+
243
+ Args:
244
+ poro (float): Core porosity (frac).
245
+ perm (float): Core permeability (mD).
246
+
247
+ Returns:
248
+ tuple: a and b constants from the best-fit curve.
249
+ """
250
+ try:
251
+ popt, _ = curve_fit(power_law_func, poro, perm, nan_policy='omit')
252
+ a = [round(c) for c in popt][0]
253
+ b = [round(c, 3) for c in popt][1]
254
+ return a, b
255
+ except Exception as e:
256
+ logger.error(e)
257
+ return 1, 1
258
+
259
+
260
+ def leverett_j(pc, ift, theta, perm, phit):
261
+ """ Estimate Leverett J.
262
+
263
+ Args:
264
+ pc (float): Capillary pressure (psi).
265
+ ift (float): Interfacial tension (dynes/cm).
266
+ theta (float): Wetting angle (degree).
267
+ perm (float): Permeability (mD).
268
+ phit (float): Total porosity (frac).
269
+
270
+ Returns:
271
+ float: Leverett J value.
272
+ """
273
+ return 0.21665 * pc / (ift * abs(np.cos(np.radians(theta)))) * (perm / phit)**(0.5)
274
+
275
+
276
+ def pseudo_leverett_j():
277
+ """TODO: Generate Pseudo-Leverett J based.
278
+
279
+ Args:
280
+ pc (float): Capillary pressure.
281
+ ift (float): Interfacial tension.
282
+ perm (float): Permeability.
283
+ phit (float): Total porosity.
284
+
285
+ Returns:
286
+ float: Pseudo-Leverett J function.
287
+ """
288
+ pass
289
+
290
+
291
+ def sw_skelt_harrison(depth, fwl, a, b, c, d):
292
+ """Estimate water saturation based on Skelt-Harrison.
293
+
294
+ Args:
295
+ depth (float): True vertical depth.
296
+ fwl (float): Free water level in true vertical depth.
297
+ a (float): a constant from the best-fit curve.
298
+ b (float): b constant from the best-fit curve.
299
+ c (float): c constant from the best-fit curve.
300
+ d (float): d constant from the best-fit curve.
301
+
302
+ Returns:
303
+ float: Water saturation.
304
+ """
305
+ h = fwl - depth
306
+ return skelt_harrison_func(h, a, b, c, d)
307
+
308
+
309
+ def sw_cuddy(phit, h, a, b):
310
+ """Estimate water saturation based on Cuddy's.
311
+
312
+ Args:
313
+ sw (float): Water saturation (frac).
314
+ phit (float): Total porosity (frac).
315
+ h (float): True vertical depth.
316
+ a (float): Cementation exponent.
317
+ b (float): Saturation exponent.
318
+
319
+ Returns:
320
+ float: Water saturation.
321
+ """
322
+ return a / phit * h**b
323
+
324
+
325
+ def sw_shf_leverett_j(perm, phit, depth, fwl, ift, theta, gw, ghc, a, b, phie=None):
326
+ """Estimate water saturation based on Leverett J function.
327
+
328
+ Args:
329
+ perm (float): Permeability (mD).
330
+ phit (float): Total porosity (frac).
331
+ depth (float): True vertical depth (ft).
332
+ fwl (float): Free water level in true vertical depth (ft).
333
+ ift (float): Interfacial tension (dynes/cm).
334
+ theta (float): Wetting angle (degree).
335
+ gw (float): Gas density (g/cc).
336
+ ghc (float): Gas height (g/cc).
337
+ a (float): A constant from J function.
338
+ b (float): B constant from J function.
339
+ phie (float): Effective porosity (frac), required for clay bound water calculation. Defaults to None.
340
+
341
+ Returns:
342
+ float: Water saturation from saturation height function.
343
+ """
344
+ h = fwl - depth
345
+ pc = h * (gw - ghc) * .433 # Convert g/cc to psi/ft
346
+ shf = (a / leverett_j(pc, ift, theta, perm, phit))**(1 / b)
347
+ return shf if not phie else shf * (1 - (phie / phit)) + (phie / phit)
348
+
349
+
350
+ def sw_shf_cuddy(phit, depth, fwl, gw, ghc, a, b):
351
+ """Estimate water saturation based on Cuddy's saturation height function.
352
+
353
+ Args:
354
+ phit (float): Porosity (frac).
355
+ depth (float): True vertical depth (ft).
356
+ fwl (float): Free water level in true vertical depth (ft).
357
+ gw (float): Gas density (g/cc).
358
+ ghc (float): Gas height (g/cc).
359
+ a (float): Cementation exponent.
360
+ b (float): Saturation exponent.
361
+
362
+ Returns:
363
+ float: Water saturation from saturation height function.
364
+ """
365
+ h = fwl - depth
366
+ shf = (h * (gw - ghc) * .433 / a)**(1 / b) / phit
367
+ return shf
368
+
369
+
370
+ def sw_shf_choo(perm, phit, phie, depth, fwl, ift, theta, gw, ghc, b0=0.4):
371
+ """Estimate water saturation based on Choo's saturation height function.
372
+
373
+ Args:
374
+ perm (float): Permeability (mD).
375
+ phit (float): Total porosity (frac).
376
+ phie (float): Effective porosity (frac).
377
+ depth (float): True vertical depth (ft).
378
+ fwl (float): Free water level in true vertical depth (ft).
379
+ ift (float): Interfacial tension (dynes/cm).
380
+ theta (float): Wetting angle (degree).
381
+ gw (float): Gas density (g/cc).
382
+ ghc (float): Gas height (g/cc).
383
+ b0 (float): _description_. Defaults to 0.4.
384
+
385
+ Returns:
386
+ float: Water saturation from saturation height function.
387
+ """
388
+ swb = 1 - (phie / phit)
389
+ h = fwl - depth
390
+ pc = h * (gw - ghc) * .433
391
+ shf = 10**((2 * b0 - 1) * np.log10(1 + swb**-1) + np.log10(1 + swb)) / (
392
+ (0.2166 * (pc / (ift * abs(np.cos(np.radians(theta))))) * (
393
+ perm / phit)**(0.5))**(b0 * np.log10(1 + swb**-1) / 3))
394
+ return shf
quick_pp/fluid_type.py ADDED
@@ -0,0 +1,128 @@
1
+ import pandas as pd
2
+ import numpy as np
3
+ import matplotlib.pyplot as plt
4
+ from scipy.optimize import curve_fit
5
+
6
+ from quick_pp.utils import straight_line_func as func
7
+
8
+ plt.style.use('seaborn-v0_8-paper')
9
+ plt.rcParams.update(
10
+ {
11
+ 'axes.labelsize': 10,
12
+ 'xtick.labelsize': 10,
13
+ 'legend.fontsize': 'small'
14
+ }
15
+ )
16
+
17
+
18
+ def fit_pressure_gradient(tvdss, formation_pressure):
19
+ """Fit pressure gradient from formation pressure and true vertical depth subsea.
20
+
21
+ Args:
22
+ tvdss (float): True vertical depth subsea.
23
+ formation_pressure (float): Formation pressure.
24
+
25
+ Returns:
26
+ tuple: Gradient and intercept of the best-fit line.
27
+ """
28
+ popt, _ = curve_fit(func, tvdss, formation_pressure)
29
+ return round(popt[0], 3), round(popt[1], 3)
30
+
31
+
32
+ def fluid_contact_plot(tvdss, formation_pressue, m, c, fluid_type: str = 'WATER',
33
+ ylim: tuple = (5000, 3000), xlim: tuple = (1000, 5000),
34
+ goc: float = 0, owc: float = 0, gwc: float = 0):
35
+ """Generate fluid contact plot which is used to determine the fluid contact in a well.
36
+
37
+ Args:
38
+ tvdss (float): True vertical depth subsea.
39
+ formation_pressure (float): Formation pressure.
40
+
41
+ Returns:
42
+ matplotlib.pyplot.Figure: Fluid contact plot.
43
+ """
44
+ color_dict = dict(
45
+ OIL=('green', 'o'),
46
+ GAS=('red', 'x'),
47
+ WATER=('blue', '^'),
48
+ HYDROSTATIC=('brown', 's')
49
+ )
50
+ marker = color_dict.get(fluid_type.upper(), ('black', 'o'))
51
+ label = f'{fluid_type} gradient: {round(m, 3)} psi/ft'
52
+ sc = plt.scatter(formation_pressue, tvdss, label=label, c=marker[0], marker=marker[1])
53
+
54
+ line_color = sc.get_facecolors()[0]
55
+ line_color[-1] = 0.5
56
+ tvd_pts = np.linspace(ylim[0] - 30, ylim[1] + 30, 30)
57
+ plt.plot(func(tvd_pts, m, c), tvd_pts, color=line_color)
58
+
59
+ plt.ylim(ylim)
60
+ plt.ylabel('TVDSS (ft)')
61
+ plt.xlim(xlim)
62
+ plt.xlabel('Formation Pressure (psi)')
63
+ plt.legend()
64
+ plt.title('Fluid Contact Plot')
65
+
66
+
67
+ def gas_composition_analysis(c1, c2, c3, ic4, nc4, ic5, nc5):
68
+ """Analyze hydrocarbon type based on gas composition (Haworth 1985).
69
+
70
+ Hydrocarbon type flag (HC_TYPE_FLAG) is classified into 6 categories:
71
+ 0: Non Representative Sample
72
+ 1: Non Productive Dry Gas
73
+ 2: Potentially Productive Gas
74
+ 3: Potentially Productive High GOR Oil
75
+ 4: Potentially Productive Condensate
76
+ 5: Potentially Productive Oil
77
+
78
+ Gas quality flag (GQ_FLAG) is classified into 2 categories:
79
+ 0: Not within the range of 0.8 to 1.2
80
+ 1: Within the range of 0.8 to 1.2
81
+
82
+ Args:
83
+ c1 (float): Concentration of methane in ppm.
84
+ c2 (float): Concentration of ethane in ppm.
85
+ c3 (float): Concentration of propane in ppm.
86
+ ic4 (float): Concentration of isobutane in ppm.
87
+ nc4 (float): Concentration of normal butane in ppm.
88
+ ic5 (float): Concentration of isopentane in ppm.
89
+ nc5 (float): Concentration of normal pentane in ppm.
90
+
91
+ Returns:
92
+ pd.DataFrame: Gas composition analysis.
93
+ """
94
+ total = c1 + c2 + c3 + ic4 + nc4 + ic5 + nc5
95
+ # Gas Quality Ratio and flag
96
+ gqr = total / (c1 + 2 * c2 + 3 * c3 + 4 * (ic4 + nc4) + 5 * (ic5 + nc5))
97
+ gq_flag = np.where((gqr > 0.8) & (gqr < 1.2), 1, 0)
98
+ # Wetness ratio
99
+ wh = (c2 + c3 + ic4 + nc4 + ic5 + nc5) / total * 100
100
+ # Balance ration
101
+ bal = (c1 + c2) / (c3 + ic4 + nc4 + ic5 + nc5)
102
+ # Character ratio
103
+ ch = (ic4 + nc4 + ic5 + nc5) / c3
104
+
105
+ hc_type_dict = {
106
+ 0: 'Non Representative Sample',
107
+ 1: 'Non Productive Dry Gas',
108
+ 2: 'Potentially Productive Gas',
109
+ 3: 'Potentially Productive High GOR Oil',
110
+ 4: 'Potentially Productive Condensate',
111
+ 5: 'Potentially Productive Oil',
112
+ }
113
+ hc_type = np.zeros(1 if isinstance(c1, int) else len(c1))
114
+ hc_type = np.where((wh < 5) & (bal > 100), 1, hc_type)
115
+ hc_type = np.where((wh > 5) & (wh < 17.5) & (wh < bal) & (bal < 100), 2, hc_type)
116
+ hc_type = np.where((wh > 5) & (wh < 17.5) & (wh > bal) & (ch > 0.5), 3, hc_type)
117
+ hc_type = np.where((wh > 5) & (wh < 17.5) & (wh > bal) & (ch < 0.5), 4, hc_type)
118
+ hc_type = np.where((wh > 17.5) & (wh < 40) & (wh > bal), 5, hc_type)
119
+
120
+ return pd.DataFrame({
121
+ 'Gas Quality Ratio': gqr,
122
+ 'GQ_FLAG': gq_flag,
123
+ 'Wetness Ratio': wh,
124
+ 'Balance Ratio': bal,
125
+ 'Character Ratio': ch,
126
+ 'Hydrocarbon Type': [hc_type_dict[x] for x in hc_type],
127
+ 'HC_TYPE_FLAG': hc_type
128
+ })