diff --git a/src/fmu/dataio/dataio.py b/src/fmu/dataio/dataio.py index c8d1120ec..0f7b47b3d 100644 --- a/src/fmu/dataio/dataio.py +++ b/src/fmu/dataio/dataio.py @@ -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, @@ -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") diff --git a/src/fmu/dataio/export/rms/inplace_volumes.py b/src/fmu/dataio/export/rms/inplace_volumes.py index 3e08daf4f..2f34d2d73 100644 --- a/src/fmu/dataio/export/rms/inplace_volumes.py +++ b/src/fmu/dataio/export/rms/inplace_volumes.py @@ -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 @@ -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.""" @@ -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) diff --git a/src/fmu/dataio/providers/objectdata/_base.py b/src/fmu/dataio/providers/objectdata/_base.py index cb965f39c..4dc1ef226 100644 --- a/src/fmu/dataio/providers/objectdata/_base.py +++ b/src/fmu/dataio/providers/objectdata/_base.py @@ -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, @@ -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 diff --git a/tests/test_export_rms/test_export_rms_volumetrics.py b/tests/test_export_rms/test_export_rms_volumetrics.py index 01e71c19b..c05e6ebc2 100644 --- a/tests/test_export_rms/test_export_rms_volumetrics.py +++ b/tests/test_export_rms/test_export_rms_volumetrics.py @@ -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, @@ -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 diff --git a/tests/test_units/test_dataio.py b/tests/test_units/test_dataio.py index e89a4e362..181d7d448 100644 --- a/tests/test_units/test_dataio.py +++ b/tests/test_units/test_dataio.py @@ -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 ):