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 authored and mferrera committed Jan 14, 2025
1 parent 0b6d638 commit a7688e7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 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
13 changes: 11 additions & 2 deletions src/fmu/dataio/export/rms/inplace_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,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 +268,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
3 changes: 1 addition & 2 deletions tests/test_export_rms/test_export_rms_volumetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,11 @@ def test_total_volumes_required(exportvolumetrics, voltable_legacy):
exportvolumetrics._compute_water_zone_volumes_from_totals(df)


@pytest.mark.parametrize("required_col", ["BULK", "PORV", "HCPV"])
@pytest.mark.parametrize("required_col", _enums.InplaceVolumes.required_columns())
def test_validate_table_required_col_missing(
exportvolumetrics, voltable_standard, required_col
):
"""Test that the job fails if a required volumetric column is missing"""

df = voltable_standard.drop(columns=required_col)
exportvolumetrics._dataframe = df

Expand Down

0 comments on commit a7688e7

Please sign in to comment.