quick-pp 0.2.69__tar.gz → 0.2.70__tar.gz

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 (79) hide show
  1. {quick_pp-0.2.69 → quick_pp-0.2.70}/PKG-INFO +1 -1
  2. {quick_pp-0.2.69 → quick_pp-0.2.70}/pyproject.toml +1 -1
  3. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/__init__.py +1 -1
  4. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/config.py +24 -72
  5. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/lithology/multi_mineral.py +65 -84
  6. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/porosity.py +66 -31
  7. {quick_pp-0.2.69 → quick_pp-0.2.70}/.gitignore +0 -0
  8. {quick_pp-0.2.69 → quick_pp-0.2.70}/LICENSE +0 -0
  9. {quick_pp-0.2.69 → quick_pp-0.2.70}/README.md +0 -0
  10. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/__init__.py +0 -0
  11. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/exceptions.py +0 -0
  12. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/fastapi_mlflow/__init__.py +0 -0
  13. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/fastapi_mlflow/_mlflow_types.py +0 -0
  14. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/fastapi_mlflow/applications.py +0 -0
  15. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/fastapi_mlflow/exceptions.py +0 -0
  16. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/fastapi_mlflow/predictors.py +0 -0
  17. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/main.py +0 -0
  18. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/mlflow_model_deployment.py +0 -0
  19. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/router.py +0 -0
  20. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/schemas/lithology_hc_correction.py +0 -0
  21. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/schemas/lithology_ssc.py +0 -0
  22. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/schemas/lithology_vsh_gr.py +0 -0
  23. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/schemas/permeability_choo.py +0 -0
  24. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/schemas/permeability_others.py +0 -0
  25. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/schemas/porosity.py +0 -0
  26. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/schemas/ressum.py +0 -0
  27. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/schemas/saturation_archie.py +0 -0
  28. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/schemas/saturation_b.py +0 -0
  29. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/schemas/saturation_qv.py +0 -0
  30. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/schemas/saturation_rw.py +0 -0
  31. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/schemas/saturation_temp_grad.py +0 -0
  32. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/schemas/saturation_waxman_smits.py +0 -0
  33. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/services/chat.py +0 -0
  34. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/services/las_handler.py +0 -0
  35. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/services/lithology.py +0 -0
  36. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/services/permeability.py +0 -0
  37. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/services/porosity.py +0 -0
  38. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/services/reservoir_summary.py +0 -0
  39. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/services/saturation.py +0 -0
  40. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/static/favicon.ico +0 -0
  41. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/static/logo.png +0 -0
  42. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/template/chat.html +0 -0
  43. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/api/template/home.html +0 -0
  44. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/cli.py +0 -0
  45. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/core_calibration.py +0 -0
  46. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/database/__init__.py +0 -0
  47. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/database/db_connector.py +0 -0
  48. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/database/models.py +0 -0
  49. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/database/objects.py +0 -0
  50. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/database/setup_postgresql_db.sql +0 -0
  51. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/database/setup_sqlite_db.sql +0 -0
  52. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/fluid_type.py +0 -0
  53. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/las_handler.py +0 -0
  54. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/lithology/__init__.py +0 -0
  55. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/lithology/carbonate.py +0 -0
  56. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/lithology/sand_shale.py +0 -0
  57. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/lithology/sand_silt_clay.py +0 -0
  58. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/lithology/thin_beds.py +0 -0
  59. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/machine_learning/__init__.py +0 -0
  60. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/machine_learning/config.py +0 -0
  61. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/machine_learning/feature_engineering.py +0 -0
  62. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/machine_learning/mock_data/mock_data.parquet +0 -0
  63. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/machine_learning/predict_pipeline.py +0 -0
  64. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/machine_learning/train_pipeline.py +0 -0
  65. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/machine_learning/utils.py +0 -0
  66. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/permeability.py +0 -0
  67. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/plotter/__init__.py +0 -0
  68. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/plotter/plotter.py +0 -0
  69. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/plotter/well_log.py +0 -0
  70. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/plotter/well_log_config.py +0 -0
  71. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/qaqc.py +0 -0
  72. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/ressum.py +0 -0
  73. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/rock_physics/__init__.py +0 -0
  74. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/rock_physics/geomechanics.py +0 -0
  75. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/rock_physics/geophysics.py +0 -0
  76. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/rock_physics/rpm.py +0 -0
  77. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/rock_type.py +0 -0
  78. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/saturation.py +0 -0
  79. {quick_pp-0.2.69 → quick_pp-0.2.70}/quick_pp/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quick-pp
3
- Version: 0.2.69
3
+ Version: 0.2.70
4
4
  Summary: Python package to assist in providing quick-look/ preliminary petrophysical estimation.
5
5
  Project-URL: Homepage, https://github.com/imranfadhil/quick_pp
6
6
  Author-email: Imran Fadhil <imranfadhil@gmail.com>
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "quick-pp"
7
- version = "0.2.69"
7
+ version = "0.2.70"
8
8
  description = "Python package to assist in providing quick-look/ preliminary petrophysical estimation."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -20,4 +20,4 @@ logging.getLogger("mlflow").setLevel(logging.WARNING)
20
20
 
21
21
  __author__ = """Imran Fadhil"""
22
22
  __email__ = 'imranfadhil@gmail.com'
23
- __version__ = '0.2.69' # Need to be updated manually when releasing a new version/ change in pyproject.toml
23
+ __version__ = '0.2.70' # Need to be updated manually when releasing a new version/ change in pyproject.toml
@@ -57,79 +57,31 @@ class Config(object):
57
57
  )
58
58
 
59
59
  MINERALS_LOG_VALUE = {
60
- 'GR_QUARTZ': 0.0,
61
- 'NPHI_QUARTZ': -0.02,
62
- 'RHOB_QUARTZ': 2.64,
63
- 'DTC_QUARTZ': 52.9,
64
- 'PEF_QUARTZ': 1.8,
65
-
66
- 'GR_CALCITE': 0.0,
67
- 'NPHI_CALCITE': 0.0,
68
- 'RHOB_CALCITE': 2.71,
69
- 'DTC_CALCITE': 49.7,
70
- 'PEF_CALCITE': 5.1,
71
-
72
- 'GR_DOLOMITE': 0.0,
73
- 'NPHI_DOLOMITE': 0.01,
74
- 'RHOB_DOLOMITE': 2.85,
75
- 'DTC_DOLOMITE': 43.5,
76
- 'PEF_DOLOMITE': 3.1,
77
-
78
- # Generic Shale (e.g., Illite/Smectite mix)
79
- 'GR_SHALE': 150.0,
80
- 'NPHI_SHALE': 0.30,
81
- 'RHOB_SHALE': 2.55,
82
- 'DTC_SHALE': 120.0,
83
- 'PEF_SHALE': 3.5,
84
-
85
- # Kaolinite (as a separate mineral option)
86
- 'GR_KAOLINITE': 35.0,
87
- 'NPHI_KAOLINITE': 0.37,
88
- 'RHOB_KAOLINITE': 2.41,
89
- 'DTC_KAOLINITE': 143.0,
90
- 'PEF_KAOLINITE': 1.8,
91
-
92
- # Feldspar
93
- 'GR_FELDSPAR': 150.0,
94
- 'NPHI_FELDSPAR': 0.02,
95
- 'RHOB_FELDSPAR': 2.56,
96
- 'DTC_FELDSPAR': 70.0,
97
- 'PEF_FELDSPAR': 3.1,
98
-
99
- # Anhydrite
100
- 'GR_ANHYDRITE': 0.0,
101
- 'NPHI_ANHYDRITE': -0.02,
102
- 'RHOB_ANHYDRITE': 2.98,
103
- 'DTC_ANHYDRITE': 50.0,
104
- 'PEF_ANHYDRITE': 5.1,
105
-
106
- # Gypsum
107
- 'GR_GYPSUM': 0.0,
108
- 'NPHI_GYPSUM': 0.6,
109
- 'RHOB_GYPSUM': 2.35,
110
- 'DTC_GYPSUM': 52.0,
111
- 'PEF_GYPSUM': 4.0,
112
-
113
- # Halite
114
- 'GR_HALITE': 0.0,
115
- 'NPHI_HALITE': -0.03,
116
- 'RHOB_HALITE': 2.04,
117
- 'DTC_HALITE': 67.0,
118
- 'PEF_HALITE': 4.7,
119
-
120
- # Pyrite
121
- 'GR_PYRITE': 0.0,
122
- 'NPHI_PYRITE': -0.02,
123
- 'RHOB_PYRITE': 5.0,
124
- 'DTC_PYRITE': 65.0,
125
- 'PEF_PYRITE': 17.0,
60
+ 'QUARTZ': {'GR': 0.0, 'NPHI': -0.02, 'RHOB': 2.64, 'DTC': 52.9, 'PEF': 1.8},
61
+ 'CALCITE': {'GR': 0.0, 'NPHI': 0.0, 'RHOB': 2.71, 'DTC': 49.7, 'PEF': 5.1},
62
+ 'DOLOMITE': {'GR': 0.0, 'NPHI': 0.01, 'RHOB': 2.85, 'DTC': 43.5, 'PEF': 3.1},
63
+ 'SHALE': {'GR': 150.0, 'NPHI': 0.30, 'RHOB': 2.55, 'DTC': 120.0, 'PEF': 3.5},
64
+ 'KAOLINITE': {'GR': 35.0, 'NPHI': 0.37, 'RHOB': 2.41, 'DTC': 143.0, 'PEF': 1.8},
65
+ 'FELDSPAR': {'GR': 150.0, 'NPHI': 0.02, 'RHOB': 2.56, 'DTC': 70.0, 'PEF': 3.1},
66
+ 'ANHYDRITE': {'GR': 0.0, 'NPHI': -0.02, 'RHOB': 2.98, 'DTC': 50.0, 'PEF': 5.1},
67
+ 'GYPSUM': {'GR': 0.0, 'NPHI': 0.6, 'RHOB': 2.35, 'DTC': 52.0, 'PEF': 4.0},
68
+ 'HALITE': {'GR': 0.0, 'NPHI': -0.03, 'RHOB': 2.04, 'DTC': 67.0, 'PEF': 4.7},
69
+ 'PYRITE': {'GR': 0.0, 'NPHI': -0.02, 'RHOB': 5.0, 'DTC': 65.0, 'PEF': 17.0},
70
+ 'COAL': {'GR': 30.0, 'NPHI': 0.50, 'RHOB': 1.3, 'DTC': 150.0, 'PEF': 0.2},
71
+ }
126
72
 
127
- # Coal
128
- 'GR_COAL': 30.0,
129
- 'NPHI_COAL': 0.50,
130
- 'RHOB_COAL': 1.3,
131
- 'DTC_COAL': 150.0,
132
- 'PEF_COAL': 0.2,
73
+ MINERALS_NAME_MAPPING = {
74
+ 'QUARTZ': 'VSAND',
75
+ 'CALCITE': 'VCALC',
76
+ 'DOLOMITE': 'VDOLO',
77
+ 'SHALE': 'VCLAY',
78
+ 'KAOLINITE': 'VKAOL',
79
+ 'FELDSPAR': 'VFELD',
80
+ 'ANHYDRITE': 'VANHY',
81
+ 'GYPSUM': 'VGYPS',
82
+ 'HALITE': 'VHALI',
83
+ 'PYRITE': 'VPYRI',
84
+ 'COAL': 'VCOAL'
133
85
  }
134
86
 
135
87
  GEOMECHANICS_VALUE = dict(
@@ -14,16 +14,15 @@ class MultiMineral:
14
14
 
15
15
  def __init__(self, minerals: Optional[List[str]] = None,
16
16
  fluid_properties: Optional[Dict] = None,
17
- porosity_method: str = 'neutron_density',
17
+ porosity_method: str = 'density',
18
18
  porosity_endpoints: Optional[Dict] = None):
19
19
  """
20
20
  Initialize the MultiMineralOptimizer.
21
21
 
22
22
  Args:
23
23
  minerals: List of minerals to include in the optimization.
24
- If None, uses default minerals: ['QUARTZ', 'CALCITE', 'DOLOMITE', 'SHALE']
25
- Available options: 'QUARTZ', 'CALCITE', 'DOLOMITE', 'SHALE', 'ANHYDRITE',
26
- 'GYPSUM', 'HALITE', 'PYRITE', 'FELDSPAR', 'COAL'
24
+ If None, uses default minerals: ['QUARTZ', 'CALCITE', 'DOLOMITE', 'SHALE'].
25
+ Available minerals are dynamically loaded from `Config.MINERALS_LOG_VALUE`.
27
26
  fluid_properties: Dictionary containing fluid properties for oil, gas, and water.
28
27
  If None, uses default properties:
29
28
  {
@@ -34,10 +33,17 @@ class MultiMineral:
34
33
  porosity_method: Method for calculating porosity ('neutron_density', 'density', 'sonic')
35
34
  porosity_endpoints: Endpoints for porosity calculation (for neutron_density method)
36
35
  """
36
+ self.responses = Config.MINERALS_LOG_VALUE
37
+ available_minerals = list(self.responses.keys())
38
+
37
39
  # Default minerals if none specified
38
40
  if minerals is None:
39
41
  minerals = ['QUARTZ', 'CALCITE', 'DOLOMITE', 'SHALE']
40
42
 
43
+ for mineral in minerals:
44
+ if mineral not in available_minerals:
45
+ raise ValueError(f"Mineral '{mineral}' is not defined in Config.MINERALS_LOG_VALUE.")
46
+
41
47
  self.minerals = minerals
42
48
  self.porosity_method = porosity_method
43
49
  self.porosity_endpoints = porosity_endpoints or {}
@@ -49,25 +55,11 @@ class MultiMineral:
49
55
  'GAS': {'density': 0.2, 'nphi': 0.0, 'pef': 0.0, 'dtc': 400.0},
50
56
  'WATER': {'density': 1.0, 'nphi': 1.0, 'pef': 0.0, 'dtc': 190.0}
51
57
  }
52
-
53
58
  self.fluid_properties = fluid_properties
54
- self.rho_fluid = self.fluid_properties['WATER']['density'] # Assume water for fluid density
55
59
  self.fluids = ['OIL', 'GAS', 'WATER']
56
60
 
57
61
  # Define bounds for each mineral type
58
- mineral_bounds = {
59
- 'QUARTZ': (0, 1),
60
- 'CALCITE': (0, 1),
61
- 'DOLOMITE': (0, 1),
62
- 'SHALE': (0, 1),
63
- 'KAOLINITE': (0, 1),
64
- 'FELDSPAR': (0, 1),
65
- 'ANHYDRITE': (0, 1),
66
- 'GYPSUM': (0, 1),
67
- 'HALITE': (0, 1),
68
- 'PYRITE': (0, 1),
69
- 'COAL': (0, 1)
70
- }
62
+ mineral_bounds = {mineral: (0, 1) for mineral in available_minerals}
71
63
 
72
64
  # Define bounds for fluid volumes (0 to 1 for each fluid)
73
65
  fluid_bounds = {
@@ -85,52 +77,46 @@ class MultiMineral:
85
77
 
86
78
  # Constraint: sum of mineral volumes + fluid volumes must equal 1
87
79
  self.constraints = [{"type": "eq", "fun": self._volume_constraint}]
88
-
89
- # Mineral log responses from Config
90
- self.responses = Config.MINERALS_LOG_VALUE
91
-
92
- # Scaling factors for different log types to balance their contribution to the error
93
- self.scaling_factors = {
94
- 'GR': 1.0,
95
- 'NPHI': 300.0,
96
- 'RHOB': 100.0,
97
- 'PEF': 30.0,
98
- 'DTC': 1.0
99
- }
80
+ self.scaling_factors = {}
100
81
 
101
82
  def _volume_constraint(self, volumes: np.ndarray) -> float:
102
83
  """Constraint function ensuring mineral volumes + fluid volumes sum to 1."""
103
84
  return np.sum(volumes) - 1
104
85
 
105
- def _calculate_porosity(self, nphi: float, rhob: float, dtc: Optional[float] = None,
106
- volumes: Optional[np.ndarray] = None) -> float:
86
+ def _calculate_porosity(self, nphi: float, rhob: float, dtc: Optional[float] = None) -> float:
107
87
  """Calculate porosity using the specified method."""
108
- if self.porosity_method == 'neutron_density':
88
+ if self.porosity_method == 'density':
89
+ # Calculate an initial rho_ma based on the selected minerals
90
+ initial_rho_ma = sum(
91
+ self.responses[mineral].get('RHOB', 0) for mineral in self.minerals if mineral in self.responses
92
+ )
93
+ count_minerals_with_density = sum(
94
+ 1 for mineral in self.minerals if mineral in self.responses and 'RHOB' in self.responses[mineral]
95
+ )
96
+
97
+ if count_minerals_with_density > 0:
98
+ rho_ma = initial_rho_ma / count_minerals_with_density
99
+ else:
100
+ rho_ma = 2.65 # Default matrix density (Quartz)
101
+
102
+ # Calculate average fluid density for porosity calculation
103
+ rho_fluid_avg = np.mean([prop['density'] for prop in self.fluid_properties.values()])
104
+
105
+ return density_porosity(rhob, rho_ma, rho_fluid_avg)
106
+
107
+ elif self.porosity_method == 'neutron_density':
109
108
  # Use neutron-density crossplot porosity
110
- dry_sand_point = self.porosity_endpoints.get('dry_sand_point', (-0.02, 2.65))
109
+ dry_min1_point = self.porosity_endpoints.get('dry_min1_point', (-0.02, 2.65))
111
110
  dry_clay_point = self.porosity_endpoints.get('dry_clay_point', (0.37, 2.41))
112
111
  fluid_point = self.porosity_endpoints.get('fluid_point', (1.0, 1.0))
113
112
 
114
113
  return neu_den_xplot_poro_pt(
115
114
  nphi, rhob, model='ss',
116
- dry_min1_point=dry_sand_point,
115
+ dry_min1_point=dry_min1_point,
117
116
  dry_clay_point=dry_clay_point,
118
117
  fluid_point=fluid_point,
119
118
  )
120
119
 
121
- elif self.porosity_method == 'density':
122
- if volumes is not None:
123
- # Calculate matrix density from the current mineral volumes during optimization
124
- mineral_vols = volumes[:len(self.minerals)]
125
- matrix_vol = np.sum(mineral_vols)
126
- if matrix_vol > 1e-3:
127
- rho_ma = self._calculate_matrix_density(mineral_vols) / matrix_vol
128
- else:
129
- rho_ma = 2.65 # Fallback if no matrix
130
- else:
131
- rho_ma = 2.65 # Default for initial guess if volumes are not provided
132
- return density_porosity(rhob, rho_ma, self.rho_fluid)
133
-
134
120
  elif self.porosity_method == 'sonic':
135
121
  # Sonic porosity calculation (simplified)
136
122
  if dtc is None:
@@ -142,14 +128,25 @@ class MultiMineral:
142
128
  else:
143
129
  raise ValueError(f"Unknown porosity method: {self.porosity_method}")
144
130
 
145
- def _calculate_matrix_density(self, volumes: np.ndarray) -> float:
131
+ def _calculate_matrix_density(self, mineral_volumes: np.ndarray) -> float:
146
132
  """Calculate matrix density from mineral volumes."""
147
133
  rho_ma = 0.0
134
+ total_mineral_vol = np.sum(mineral_volumes)
135
+ if total_mineral_vol < 1e-6:
136
+ return 2.65 # Return default if no minerals
137
+
148
138
  for i, mineral in enumerate(self.minerals):
149
- rho_key = f"RHOB_{mineral}"
150
- if rho_key in self.responses:
151
- rho_ma += volumes[i] * self.responses[rho_key]
152
- return rho_ma
139
+ if mineral in self.responses and 'RHOB' in self.responses[mineral]:
140
+ rho_ma += mineral_volumes[i] * self.responses[mineral]['RHOB']
141
+
142
+ return rho_ma / total_mineral_vol
143
+
144
+ def _calculate_fluid_density(self, fluid_volumes: np.ndarray) -> float:
145
+ """Calculate average fluid density from fluid volumes."""
146
+ rho_fluid = 0.0
147
+ for i, fluid in enumerate(self.fluids):
148
+ rho_fluid += fluid_volumes[i] * self.fluid_properties[fluid]['density']
149
+ return rho_fluid
153
150
 
154
151
  def _calculate_log_response(self, volumes: np.ndarray, log_type: str) -> float:
155
152
  """Calculate reconstructed log response for a given log type."""
@@ -158,9 +155,8 @@ class MultiMineral:
158
155
  # Add mineral contributions
159
156
  n_minerals = len(self.minerals)
160
157
  for i, mineral in enumerate(self.minerals):
161
- response_key = f"{log_type}_{mineral}"
162
- if response_key in self.responses:
163
- response += volumes[i] * self.responses[response_key]
158
+ if mineral in self.responses and log_type in self.responses[mineral]:
159
+ response += volumes[i] * self.responses[mineral][log_type]
164
160
 
165
161
  # Add fluid contributions
166
162
  for i, fluid in enumerate(self.fluids):
@@ -215,16 +211,18 @@ class MultiMineral:
215
211
  """
216
212
  total_error = 0.0
217
213
 
218
- # Porosity is the sum of fluid volumes
219
- porosity = np.sum(volumes[len(self.minerals):])
220
-
221
214
  for log_type, measured_value in log_values.items():
222
215
  if measured_value is not None and not np.isnan(measured_value):
216
+ # Special handling for RHOB when using density porosity method
223
217
  if self.porosity_method == 'density' and log_type == 'RHOB':
224
- # For density porosity, RHOB is reconstructed from porosity and matrix density
225
218
  mineral_vols = volumes[:len(self.minerals)]
219
+ fluid_vols = volumes[len(self.minerals):]
220
+ porosity = np.sum(fluid_vols)
221
+
222
+ # For density porosity, RHOB is reconstructed from porosity and matrix density
226
223
  rho_ma = self._calculate_matrix_density(mineral_vols)
227
- reconstructed_value = rho_ma * (1 - porosity) + self.rho_fluid * porosity
224
+ rho_fluid = self._calculate_fluid_density(fluid_vols)
225
+ reconstructed_value = rho_ma * (1 - porosity) + rho_fluid * porosity
228
226
  else:
229
227
  reconstructed_value = self._calculate_log_response(volumes, log_type)
230
228
 
@@ -256,21 +254,14 @@ class MultiMineral:
256
254
  rhob = log_values.get('RHOB', 2.65)
257
255
  dtc = log_values.get('DTC', None)
258
256
 
259
- # Initial guess: equal distribution among minerals and fluids
260
- n_minerals = len(self.minerals)
261
- n_fluids = len(self.fluids)
262
-
263
- # Create an initial guess for volumes to pass to porosity calculation
264
- initial_mineral_guess = np.full(n_minerals, (1.0 - 0.1) / n_minerals)
265
- initial_fluid_guess = np.full(n_fluids, 0.1 / n_fluids)
266
- initial_guess_for_poro = np.concatenate([initial_mineral_guess, initial_fluid_guess])
267
-
268
257
  if nphi is not None and rhob is not None:
269
- initial_porosity = self._calculate_porosity(nphi, rhob, dtc, volumes=initial_guess_for_poro)
258
+ initial_porosity = self._calculate_porosity(nphi, rhob, dtc)
270
259
  initial_porosity = max(0.0, min(0.4, initial_porosity)) # Constrain to reasonable range
271
260
  else:
272
- initial_porosity = 0.01 # Default porosity
261
+ initial_porosity = 0.1 # Default porosity
273
262
 
263
+ n_minerals = len(self.minerals)
264
+ n_fluids = len(self.fluids)
274
265
  # Distribute volume between minerals and fluids
275
266
  mineral_volume = (1.0 - initial_porosity) / n_minerals
276
267
  fluid_volume = initial_porosity / n_fluids
@@ -423,17 +414,7 @@ class MultiMineral:
423
414
 
424
415
  # Add mineral volumes with appropriate column names
425
416
  mineral_column_mapping = {
426
- 'QUARTZ': 'VSAND',
427
- 'CALCITE': 'VCALC',
428
- 'DOLOMITE': 'VDOLO',
429
- 'SHALE': 'VCLAY',
430
- 'KAOLINITE': 'VKAOL',
431
- 'FELDSPAR': 'VFELD',
432
- 'ANHYDRITE': 'VANHY',
433
- 'GYPSUM': 'VGYPS',
434
- 'HALITE': 'VHALI',
435
- 'PYRITE': 'VPYRI',
436
- 'COAL': 'VCOAL'
417
+ mineral: Config.MINERALS_NAME_MAPPING.get(mineral, f'V{mineral}') for mineral in self.minerals
437
418
  }
438
419
 
439
420
  for mineral in self.minerals:
@@ -23,6 +23,47 @@ def normalize_volumetric(phit, **volumetrics):
23
23
  return normalized_volumetrics
24
24
 
25
25
 
26
+ def unnormalize_volumetric(phit, **normalized_volumetrics):
27
+ """Unnormalize lithology given total porosity.
28
+
29
+ This is the reverse of normalize_volumetric. It calculates the matrix-relative
30
+ volumetrics from bulk-relative (normalized) volumetrics.
31
+
32
+ Args:
33
+ phit (np.ndarray or float): Total porosity in fraction (v/v).
34
+ **normalized_volumetrics: Keyword arguments representing normalized
35
+ volumetric fractions of the bulk volume (v/v).
36
+
37
+ Returns:
38
+ dict: Unnormalized volumetric fractions relative to the matrix volume.
39
+ """
40
+ logger.debug("Unnormalizing volumetrics with total porosity")
41
+ # Unnormalize the volumetrics
42
+ vmatrix = 1 - phit
43
+ # Use np.divide for safe division by zero, returning np.nan
44
+ unnormalized_volumetrics = {key: np.divide(value, vmatrix, out=np.full_like(value, np.nan), where=vmatrix != 0)
45
+ for key, value in normalized_volumetrics.items()}
46
+ logger.debug(f"Unnormalized volumetrics: {list(unnormalized_volumetrics.keys())}")
47
+ return unnormalized_volumetrics
48
+
49
+
50
+ def get_volumetric_dict(df):
51
+ """Given dataframe, return a dictionary of the key and values of lithology metrics in the data.
52
+
53
+ Args:
54
+ df (pd.DataFrame): Dataframe with well log data.
55
+
56
+ Returns:
57
+ dict: Dictionary of the key and values of lithology metrics in the data.
58
+ """
59
+ volumetric_dict = {}
60
+ for vol_log in Config.MINERALS_LOG_VALUE.keys():
61
+ vol_log = Config.MINERALS_NAME_MAPPING.get(vol_log, vol_log)
62
+ if vol_log in df.columns:
63
+ volumetric_dict[vol_log.lower()] = df[vol_log].values
64
+ return volumetric_dict
65
+
66
+
26
67
  def effective_porosity(phit, phi_shale, vshale):
27
68
  """
28
69
  Computes effective porosity from total porosity, total porosity of shale and shale volume.
@@ -81,42 +122,36 @@ def estimate_shale_porosity(nphi, phit):
81
122
  return np.where(phit_sh > 0, phit_sh, phit).clip(1e-2, 1.0)
82
123
 
83
124
 
84
- def rho_matrix(vsand=0, vsilt=0, vclay=0, vcalc=0, vdolo=0, vheavy=0,
85
- rho_sand: float = 0, rho_silt: float = 0, rho_clay: float = 0,
86
- rho_calc: float = 0, rho_dolo: float = 0, rho_heavy: float = 0):
87
- """Estimate average matrix density based on dry sand, dry silt, dry clay, dry calcite and
88
- dry dolomite volume and density of each.
125
+ def rho_matrix(**volumetrics):
126
+ """Estimate average matrix density based on mineral volumes and their densities from Config.
89
127
 
90
128
  Args:
91
- vsand (float): Volume of sand.
92
- vsilt (float): Volume of silt.
93
- vclay (float): Volume of clay.
94
- vcalc (float): Volume of calcite.
95
- vdolo (float): Volume of dolomite.
96
- vheavy (float): Volume of heavy minerals.
97
- rho_sand (float, optional): Density of sand in g/cc. Defaults to None.
98
- rho_silt (float, optional): Density of silt in g/cc. Defaults to None.
99
- rho_clay (float, optional): Density of clay in g/cc. Defaults to None.
100
- rho_calc (float, optional): Density of calcite in g/cc. Defaults to None.
101
- rho_dolo (float, optional): Density of dolomite in g/cc. Defaults to None.
102
- rho_heavy (float, optional): Density of heavy minerals in g/cc. Defaults to 0.
129
+ **volumetrics: Keyword arguments where keys are mineral volume names
130
+ (e.g., VSAND, VCLAY) and values are their volume fractions.
131
+
103
132
 
104
133
  Returns:
105
134
  float: Matrix density in g/cc.
106
135
  """
107
136
  logger.debug("Calculating matrix density from mineral volumes")
108
- minerals_log_value = Config.MINERALS_LOG_VALUE
109
- rho_sand = rho_sand or minerals_log_value['RHOB_QUARTZ']
110
- rho_silt = rho_silt or 2.68
111
- rho_clay = rho_clay or minerals_log_value['RHOB_SHALE']
112
- rho_calc = rho_calc or minerals_log_value['RHOB_CALCITE']
113
- rho_dolo = rho_dolo or minerals_log_value['RHOB_DOLOMITE']
137
+ rho_ma = 0.0
138
+ mineral_properties = Config.MINERALS_LOG_VALUE
139
+ # Create a reverse mapping from volume name (e.g., 'VSAND') to mineral name (e.g., 'QUARTZ')
140
+ name_to_mineral_map = {v: k for k, v in Config.MINERALS_NAME_MAPPING.items()}
141
+
142
+ for vol_name, vol_value in volumetrics.items():
143
+ # Find the mineral name (e.g., 'QUARTZ') from the volume name (e.g., 'VSAND')
144
+ mineral_name = name_to_mineral_map.get(vol_name.upper())
114
145
 
115
- rho_matrix = vsand * rho_sand + vsilt * rho_silt + vclay * rho_clay + \
116
- vcalc * rho_calc + vdolo * rho_dolo + vheavy * rho_heavy
146
+ if mineral_name and mineral_name in mineral_properties:
147
+ rho_mineral = mineral_properties[mineral_name].get('RHOB')
148
+ if rho_mineral is not None:
149
+ rho_ma += vol_value * rho_mineral
150
+ elif vol_name.upper() == 'VSILT': # Handle silt separately if not in main config
151
+ rho_ma += vol_value * 2.68
117
152
 
118
- logger.debug(f"Matrix density range: {rho_matrix.min():.3f} - {rho_matrix.max():.3f} g/cm³")
119
- return rho_matrix
153
+ logger.debug(f"Matrix density range: {np.nanmin(rho_ma):.3f} - {np.nanmax(rho_ma):.3f} g/cm³")
154
+ return rho_ma
120
155
 
121
156
 
122
157
  def density_porosity(rhob, rho_matrix, rho_fluid: float = 1.0):
@@ -160,10 +195,10 @@ def dt_matrix(vsand=0, vclay=0, vcalc=0, vdolo=0, vheavy=0,
160
195
  """
161
196
  logger.debug("Calculating matrix sonic transit time from mineral volumes")
162
197
  minerals_log_value = Config.MINERALS_LOG_VALUE
163
- dt_sand = dt_sand or minerals_log_value['DTC_QUARTZ']
164
- dt_clay = dt_clay or minerals_log_value['DTC_SHALE']
165
- dt_calc = dt_calc or minerals_log_value['DTC_CALCITE']
166
- dt_dolo = dt_dolo or minerals_log_value['DTC_DOLOMITE']
198
+ dt_sand = dt_sand or minerals_log_value['QUARTZ']['DTC']
199
+ dt_clay = dt_clay or minerals_log_value['SHALE']['DTC']
200
+ dt_calc = dt_calc or minerals_log_value['CALCITE']['DTC']
201
+ dt_dolo = dt_dolo or minerals_log_value['DOLOMITE']['DTC']
167
202
 
168
203
  dt_matrix = (vsand * dt_sand + vclay * dt_clay +
169
204
  vcalc * dt_calc + vdolo * dt_dolo + vheavy * dt_heavy)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes