Skip to content

Commit

Permalink
ENH: Set Region required in inplace_volumes (equinor#948)
Browse files Browse the repository at this point in the history
  • Loading branch information
tnatt committed Jan 3, 2025
1 parent a6c4e28 commit 562850a
Show file tree
Hide file tree
Showing 5 changed files with 556 additions and 509 deletions.
2 changes: 1 addition & 1 deletion src/fmu/dataio/_products/inplace_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class InplaceVolumesResultRow(BaseModel):

FLUID: InplaceVolumes.Fluid
ZONE: str
REGION: Optional[str] = Field(default=None)
REGION: str
FACIES: Optional[str] = Field(default=None)
LICENSE: Optional[str] = Field(default=None)

Expand Down
1 change: 1 addition & 0 deletions src/fmu/dataio/export/_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def required_index_columns() -> list[str]:
return [
InplaceVolumes.TableIndexColumns.FLUID.value,
InplaceVolumes.TableIndexColumns.ZONE.value,
InplaceVolumes.TableIndexColumns.REGION.value,
]

@staticmethod
Expand Down
25 changes: 23 additions & 2 deletions src/fmu/dataio/export/rms/inplace_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ def _add_missing_columns_to_table(table: pd.DataFrame) -> pd.DataFrame:
table[col] = np.nan
return table

@staticmethod
def _set_net_equal_to_bulk_if_missing_in_table(table: pd.DataFrame) -> pd.DataFrame:
"""
Add a NET column to the table equal to the BULK column if NET is missing,
since the absence implies a net-to-gross ratio of 1.
"""
if _VolumetricColumns.NET.value not in table:
_logger.debug("NET column missing, setting NET equal BULK...")
table[_VolumetricColumns.NET.value] = table[_VolumetricColumns.BULK.value]
return table

@staticmethod
def _set_table_column_order(table: pd.DataFrame) -> pd.DataFrame:
"""Set the column order in the table."""
Expand Down Expand Up @@ -230,6 +241,7 @@ def _convert_table_from_legacy_to_standard_format(
]
table = self._compute_water_zone_volumes_from_totals(table)
table = self._transform_and_add_fluid_column_to_table(table, table_index)
table = self._set_net_equal_to_bulk_if_missing_in_table(table)
table = self._add_missing_columns_to_table(table)
return self._set_table_column_order(table)

Expand All @@ -240,10 +252,19 @@ def _is_column_missing_in_table(self, column: str) -> bool:
def _validate_table(self) -> None:
"""
Validate that the final table with volumes is according to the standard
defined for the inplace_volumes product.
defined for the inplace_volumes product. The table should have the required
index and value columns, and at least one of the main types 'oil' or 'gas'.
"""
_logger.debug("Validating the dataframe...")

# check that all required index columns are present
for col in _enums.InplaceVolumes.required_index_columns():
if self._is_column_missing_in_table(col):
raise RuntimeError(
f"Required index column {col} is missing in the volumetric table. "
"Please update and rerun the volumetric job before export."
)

has_oil = (
"oil" in self._dataframe[_enums.InplaceVolumes.FLUID_COLUMN.value].values
)
Expand All @@ -259,7 +280,7 @@ def _validate_table(self) -> None:
"before export."
)

# create list of missing or non-defined required columns
# check that all required value columns are present
missing_calculations = []
for col in _enums.InplaceVolumes.required_value_columns():
if self._is_column_missing_in_table(col):
Expand Down
Loading

0 comments on commit 562850a

Please sign in to comment.