Skip to content

Commit

Permalink
ENH: Add product to exported metadata for inplace_volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
tnatt committed Jan 6, 2025
1 parent f5dc107 commit 1ad67cb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/fmu/dataio/dataio.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from ._metadata import generate_export_metadata
from ._model import enums, global_configuration
from ._model.global_configuration import GlobalConfiguration
from ._model.product import Product
from ._utils import (
detect_inside_rms, # dataio_examples,
export_file,
Expand Down Expand Up @@ -398,6 +399,8 @@ class ExportData:
# << NB! storing ACTUAL casepath:
_rootpath: Path = field(default_factory=Path, init=False)

_product: Optional[Product] = None

def __post_init__(self) -> None:
assert isinstance(self.config, dict)
logger.info("Running __post_init__ ExportData")
Expand Down
10 changes: 9 additions & 1 deletion src/fmu/dataio/export/rms/inplace_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

import fmu.dataio as dio
from fmu.dataio._logging import null_logger
from fmu.dataio._model.enums import Classification
from fmu.dataio._model import product
from fmu.dataio._model.enums import Classification, ProductName
from fmu.dataio._products.inplace_volumes import InplaceVolumesResult
from fmu.dataio.export import _enums
from fmu.dataio.export._decorators import experimental
Expand Down Expand Up @@ -70,6 +71,11 @@ def __post_init__(self) -> None:
self._dataframe = self._get_table_with_volumes()
_logger.debug("Process data... DONE")

@property
def _product(self) -> product.InplaceVolumesProduct:
"""Product type for the exported data."""
return product.InplaceVolumesProduct(name=ProductName.inplace_volumes)

@property
def _classification(self) -> Classification:
"""Get default classification."""
Expand Down Expand Up @@ -316,6 +322,8 @@ def _export_volume_table(self) -> ExportResult:
table_index=_enums.InplaceVolumes.index_columns(),
)

edata._product = self._product

volume_table = pa.Table.from_pandas(self._dataframe)
absolute_export_path = edata.export(volume_table)

Expand Down
8 changes: 2 additions & 6 deletions src/fmu/dataio/providers/objectdata/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@

from fmu.dataio._definitions import ConfigurationError, ValidFormats
from fmu.dataio._logging import null_logger
from fmu.dataio._model.data import (
AnyData,
Time,
Timestamp,
)
from fmu.dataio._model.data import AnyData, Time, Timestamp
from fmu.dataio._model.enums import Content
from fmu.dataio._model.global_configuration import (
GlobalConfiguration,
Expand Down Expand Up @@ -83,7 +79,7 @@ def __post_init__(self) -> None:
metadata[usecontent] = getattr(
content_model.content_incl_specific, usecontent, None
)
metadata["product"] = None
metadata["product"] = self.dataio._product
metadata["tagname"] = self.dataio.tagname
metadata["format"] = self.fmt
metadata["layout"] = self.layout
Expand Down
15 changes: 15 additions & 0 deletions tests/test_export_rms/test_export_rms_volumetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

from fmu import dataio
from fmu.dataio._logging import null_logger
from fmu.dataio._model.enums import ProductName
from fmu.dataio._products.inplace_volumes import (
SCHEMA,
VERSION,
InplaceVolumesResult,
InplaceVolumesResultRow,
dump,
Expand Down Expand Up @@ -582,3 +585,15 @@ def test_that_required_columns_one_to_one_in_enums_and_schema() -> None:
if field_info.is_required():
schema_required_fields.append(field_name)
assert set(_enums.InplaceVolumes.required_columns()) == set(schema_required_fields)


def test_product_in_metadata(exportvolumetrics):
"""Test that the product is set correctly in the metadata"""

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

assert "product" in metadata["data"]
assert metadata["data"]["product"]["name"] == ProductName.inplace_volumes
assert metadata["data"]["product"]["file_schema"]["version"] == VERSION
assert metadata["data"]["product"]["file_schema"]["url"] == SCHEMA
7 changes: 7 additions & 0 deletions tests/test_units/test_dataio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,13 @@ def test_alias_as_none(globalconfig2, regsurf):
assert meta["data"]["alias"] == [name]


def test_product_not_present_in_generated_metadata(globalconfig1, regsurf):
"""Test that data.product is not set for regular exports through ExportData"""

meta = ExportData(config=globalconfig1, content="depth").generate_metadata(regsurf)
assert "product" not in meta["data"]


def test_ert_experiment_id_present_in_generated_metadata(
fmurun_w_casemetadata, monkeypatch, globalconfig1, regsurf
):
Expand Down

0 comments on commit 1ad67cb

Please sign in to comment.