Skip to content

Commit

Permalink
FIX: Use lower case fluid types
Browse files Browse the repository at this point in the history
  • Loading branch information
mferrera committed Dec 18, 2024
1 parent 279fdb8 commit 4606f2c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
4 changes: 3 additions & 1 deletion src/fmu/dataio/_products/inplace_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from pydantic import BaseModel, Field, RootModel
from pydantic.json_schema import GenerateJsonSchema

from fmu.dataio.export._enums import InplaceVolumes

if TYPE_CHECKING:
from typing import Any, Mapping

Expand All @@ -23,7 +25,7 @@ class InplaceVolumesResultRow(BaseModel):
should increase the version number in a way that corresponds to the schema
versioning specification (i.e. they are a patch, minor, or major change)."""

FLUID: Literal["oil", "gas", "water"]
FLUID: InplaceVolumes.Fluid
ZONE: str
REGION: Optional[str] = Field(default=None)
FACIES: Optional[str] = Field(default=None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class InplaceVolumes:
"""Enumerations relevant to inplace volumes tables."""

class Fluid(str, Enum):
"""Fluid types"""
"""Fluid types used as values in the FLUID column."""

OIL = "OIL"
GAS = "GAS"
WATER = "WATER"
oil = "oil"
gas = "gas"
water = "water"

class TableIndexColumns(str, Enum):
"""The index columns for an inplace volumes table."""
Expand Down
21 changes: 13 additions & 8 deletions src/fmu/dataio/export/rms/inplace_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import fmu.dataio as dio
from fmu.dataio._logging import null_logger
from fmu.dataio._model.enums import Classification
from fmu.dataio.export import _enums
from fmu.dataio.export._decorators import experimental
from fmu.dataio.export._export_result import ExportResult, ExportResultItem
from fmu.dataio.export.rms import _enums
from fmu.dataio.export.rms._conditional_rms_imports import import_rms_package
from fmu.dataio.export.rms._utils import (
check_rmsapi_version,
Expand Down Expand Up @@ -154,19 +154,24 @@ def _transform_and_add_fluid_column_to_table(
]

tables = []
for fluid in [
_enums.InplaceVolumes.Fluid.GAS.value,
_enums.InplaceVolumes.Fluid.OIL.value,
]:
fluid_columns = [col for col in table.columns if col.endswith(f"_{fluid}")]
for fluid in (
_enums.InplaceVolumes.Fluid.gas.value,
_enums.InplaceVolumes.Fluid.oil.value,
):
fluid_suffix = fluid.upper()
fluid_columns = [
col for col in table.columns if col.endswith(f"_{fluid_suffix}")
]
if fluid_columns:
fluid_table = table[table_index + fluid_columns].copy()

# drop fluid suffix from columns to get standard names
fluid_table.columns = fluid_table.columns.str.replace(f"_{fluid}", "")
fluid_table.columns = fluid_table.columns.str.replace(
f"_{fluid_suffix}", ""
)

# add the fluid as column entry instead
fluid_table[_enums.InplaceVolumes.FLUID_COLUMN] = fluid.lower()
fluid_table[_enums.InplaceVolumes.FLUID_COLUMN] = fluid

tables.append(fluid_table)

Expand Down
8 changes: 2 additions & 6 deletions tests/test_export_rms/test_export_rms_volumetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
InplaceVolumesResultRow,
dump,
)
from fmu.dataio.export import _enums
from tests.utils import inside_rms

logger = null_logger(__name__)
Expand Down Expand Up @@ -94,8 +95,6 @@ def test_rms_volumetrics_export_class(exportvolumetrics):
def test_rms_volumetrics_export_class_table_index(voltable_standard, exportvolumetrics):
"""See mocks in local conftest.py"""

from fmu.dataio.export.rms import _enums

out = exportvolumetrics._export_volume_table()
metadata = dataio.read_metadata(out.items[0].absolute_path)

Expand All @@ -120,7 +119,6 @@ def test_convert_table_from_legacy_to_standard_format(
"""Test that a voltable with legacy format is converted to
the expected standard format"""

from fmu.dataio.export.rms import _enums
from fmu.dataio.export.rms.inplace_volumes import _ExportVolumetricsRMS

monkeypatch.chdir(rmssetup_with_fmuconfig)
Expand Down Expand Up @@ -299,7 +297,7 @@ def test_rms_volumetrics_export_function(
):
"""Test the public function."""

from fmu.dataio.export.rms import _enums, export_inplace_volumes
from fmu.dataio.export.rms import export_inplace_volumes
from fmu.dataio.export.rms.inplace_volumes import _ExportVolumetricsRMS

monkeypatch.chdir(rmssetup_with_fmuconfig)
Expand Down Expand Up @@ -360,8 +358,6 @@ def test_inplace_volumes_payload_validates_against_schema(
def test_inplace_volumes_export_and_result_columns_are_the_same(
mocked_rmsapi_modules,
) -> None:
from fmu.dataio.export.rms import _enums

assert _enums.InplaceVolumes.table_columns() == list(
InplaceVolumesResultRow.model_fields.keys()
)

0 comments on commit 4606f2c

Please sign in to comment.