diff --git a/src/fmu/dataio/export/rms/inplace_volumes.py b/src/fmu/dataio/export/rms/inplace_volumes.py index 9814575b5..0ec35a2c8 100644 --- a/src/fmu/dataio/export/rms/inplace_volumes.py +++ b/src/fmu/dataio/export/rms/inplace_volumes.py @@ -2,9 +2,11 @@ import warnings from dataclasses import dataclass +from enum import Enum from pathlib import Path from typing import Any, Final +import numpy as np import pandas as pd import fmu.dataio as dio @@ -23,8 +25,26 @@ _logger: Final = null_logger(__name__) +_FLUID_COLUMN: Final = "FLUID" +_TABLE_INDEX_COLUMNS: Final = [_FLUID_COLUMN, "ZONE", "REGION", "FACIES", "LICENSE"] +_VOLUMETRIC_COLUMNS: Final = [ + "BULK", + "PORV", + "HCPV", + "STOIIP", + "GIIP", + "ASSOCIATEDGAS", + "ASSOCIATEDOIL", +] + + +class _Fluid(str, Enum): + """Fluid types""" + + OIL = "OIL" + GAS = "GAS" + WATER = "WATER" -_TABLE_INDEX_COLUMNS: Final = ("ZONE", "REGION", "FACIES", "LICENCE") # rename columns to FMU standard _RENAME_COLUMNS_FROM_RMS: Final = { @@ -58,11 +78,11 @@ class _ExportVolumetricsRMS: volume_job_name: str def __post_init__(self) -> None: - _logger.debug("Process data, estiblish state prior to export.") + _logger.debug("Process data, establish state prior to export.") self._config = load_global_config() self._volume_job = self._get_rms_volume_job_settings() self._volume_table_name = self._read_volume_table_name_from_job() - self._dataframe = self._voltable_as_dataframe() + self._dataframe = self._get_table_with_volumes() _logger.debug("Process data... DONE") @property @@ -70,11 +90,6 @@ def _classification(self) -> Classification: """Get default classification.""" return Classification.restricted - @property - def _table_index(self) -> list[str]: - """Get index columns present in the dataframe.""" - return [col for col in _TABLE_INDEX_COLUMNS if col in self._dataframe] - def _get_rms_volume_job_settings(self) -> dict: """Get information out from the RMS job API.""" _logger.debug("RMS VOLJOB settings...") @@ -101,21 +116,90 @@ def _read_volume_table_name_from_job(self) -> str: _logger.debug("The volume table name is %s", volume_table_name) return volume_table_name - def _voltable_as_dataframe(self) -> pd.DataFrame: - """Convert table to pandas dataframe""" - _logger.debug("Read values and convert to pandas dataframe...") + def _get_table_with_volumes(self) -> pd.DataFrame: + """ + Get a volumetric table from RMS converted into a pandas + dataframe on standard format for the inplace_volumes product. + """ + table = self._get_table_from_rms() + table = self._convert_table_from_rms_to_legacy_format(table) + return self._convert_table_from_legacy_to_standard_format(table) - dict_values = ( - self.project.volumetric_tables[self._volume_table_name] - .get_data_table() - .to_dict() + def _get_table_from_rms(self) -> pd.DataFrame: + """Fetch volumetric table from RMS and convert to pandas dataframe""" + _logger.debug("Read values and convert to pandas dataframe...") + return pd.DataFrame.from_dict( + ( + self.project.volumetric_tables[self._volume_table_name] + .get_data_table() + .to_dict() + ) ) - return ( - pd.DataFrame.from_dict(dict_values) - .rename(columns=_RENAME_COLUMNS_FROM_RMS) - .drop("REAL", axis=1, errors="ignore") + + @staticmethod + def _convert_table_from_rms_to_legacy_format(table: pd.DataFrame) -> pd.DataFrame: + """Rename columns to legacy naming standard and drop REAL column if present.""" + _logger.debug("Converting dataframe from RMS to legacy format...") + return table.rename(columns=_RENAME_COLUMNS_FROM_RMS).drop( + columns="REAL", errors="ignore" ) + @staticmethod + def _add_missing_columns_to_table(table: pd.DataFrame) -> pd.DataFrame: + """Add columns with nan values if not present in table.""" + _logger.debug("Add table index columns to table if missing...") + for col in _TABLE_INDEX_COLUMNS + _VOLUMETRIC_COLUMNS: + if col not in table: + table[col] = np.nan + return table + + @staticmethod + def _set_table_column_order(table: pd.DataFrame) -> pd.DataFrame: + """Set the column order in the table.""" + _logger.debug("Settting the table column order...") + return table[_TABLE_INDEX_COLUMNS + _VOLUMETRIC_COLUMNS] + + @staticmethod + def _transform_and_add_fluid_column_to_table( + table: pd.DataFrame, table_index: list[str] + ) -> pd.DataFrame: + """ + Transformation of a dataframe containing fluid-specific column data into a + standardized format with unified column names, e.g. 'BULK_OIL' and 'PORV_OIL' + are renamed into 'BULK' and 'PORV' columns. To separate the data an additional + FLUID column is added that indicates the type of fluid the row represents. + """ + table_index = [col for col in _TABLE_INDEX_COLUMNS if col in table] + + tables = [] + for fluid in [_Fluid.GAS.value, _Fluid.OIL.value]: + fluid_columns = [col for col in table.columns if col.endswith(f"_{fluid}")] + 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}", "") + + # add the fluid as column entry instead + fluid_table[_FLUID_COLUMN] = fluid.lower() + + tables.append(fluid_table) + + return pd.concat(tables, ignore_index=True) if tables else pd.DataFrame() + + def _convert_table_from_legacy_to_standard_format( + self, table: pd.DataFrame + ) -> pd.DataFrame: + """ + Convert the table from legacy to standard format for the 'inplace_volumes' + product. The standard format has a fluid column, and all table_index and + volumetric columns are present with a standard order in the table. + """ + table_index = [col for col in _TABLE_INDEX_COLUMNS if col in table] + table = self._transform_and_add_fluid_column_to_table(table, table_index) + table = self._add_missing_columns_to_table(table) + return self._set_table_column_order(table) + def _export_volume_table(self) -> ExportResult: """Do the actual volume table export using dataio setup.""" @@ -129,7 +213,7 @@ def _export_volume_table(self) -> ExportResult: classification=self._classification, name=self.grid_name, rep_include=False, - table_index=self._table_index, + table_index=_TABLE_INDEX_COLUMNS, ) absolute_export_path = edata.export(self._dataframe) _logger.debug("Volume result to: %s", absolute_export_path) diff --git a/tests/data/drogon/tabular/volumes/geogrid.csv b/tests/data/drogon/tabular/volumes/geogrid.csv new file mode 100644 index 000000000..9702c8fe3 --- /dev/null +++ b/tests/data/drogon/tabular/volumes/geogrid.csv @@ -0,0 +1,337 @@ +FLUID,ZONE,REGION,FACIES,LICENSE,BULK,PORV,HCPV,STOIIP,GIIP,ASSOCIATEDGAS,ASSOCIATEDOIL +gas,Valysar,WestLowland,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,WestLowland,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,WestLowland,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,WestLowland,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,WestLowland,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,WestLowland,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,WestLowland,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,WestLowland,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralSouth,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralSouth,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralSouth,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralSouth,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralSouth,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralSouth,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralSouth,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralSouth,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralNorth,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralNorth,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralNorth,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralNorth,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralNorth,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralNorth,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralNorth,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralNorth,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,NorthHorst,Floodplain,,9323194.91862982,909349.666437149,183625.18690417332,,42703531.18437719,,6533.64030885516 +gas,Valysar,NorthHorst,Channel,,6156466.450169703,1677372.1650733948,1606572.138168335,,373621421.6464844,,57164.07783412933 +gas,Valysar,NorthHorst,Crevasse,,3463925.833353194,744850.3458938599,608149.9773368835,,141430225.06054688,,21638.82457304001 +gas,Valysar,NorthHorst,Coal,,5355015.062506426,0.0,0.0,,0.0,,0.0 +gas,Valysar,NorthHorst,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,NorthHorst,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,NorthHorst,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,NorthHorst,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralRamp,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralRamp,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralRamp,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralRamp,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralRamp,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralRamp,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralRamp,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralRamp,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralHorst,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralHorst,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralHorst,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralHorst,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralHorst,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralHorst,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralHorst,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,CentralHorst,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,EastLowland,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,EastLowland,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,EastLowland,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,EastLowland,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,EastLowland,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,EastLowland,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,EastLowland,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Valysar,EastLowland,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,WestLowland,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,WestLowland,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,WestLowland,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,WestLowland,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,WestLowland,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,WestLowland,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,WestLowland,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,WestLowland,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralSouth,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralSouth,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralSouth,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralSouth,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralSouth,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralSouth,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralSouth,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralSouth,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralNorth,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralNorth,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralNorth,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralNorth,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralNorth,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralNorth,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralNorth,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralNorth,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,NorthHorst,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,NorthHorst,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,NorthHorst,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,NorthHorst,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,NorthHorst,Calcite,,1451400.5470385076,0.0,0.0,,0.0,,0.0 +gas,Therys,NorthHorst,Offshore,,6145038.186677488,634731.3707326949,137305.86173312273,,31931595.268298388,,4885.534097255353 +gas,Therys,NorthHorst,Lowershoreface,,3066435.394596213,768750.8175201416,514720.3795967102,,119702412.1015625,,18314.46915364265 +gas,Therys,NorthHorst,Uppershoreface,,2802607.0354347867,923775.645843506,880271.0649414062,,204714197.953125,,31321.27242922783 +gas,Therys,CentralRamp,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralRamp,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralRamp,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralRamp,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralRamp,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralRamp,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralRamp,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralRamp,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralHorst,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralHorst,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralHorst,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralHorst,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralHorst,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralHorst,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralHorst,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,CentralHorst,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,EastLowland,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,EastLowland,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,EastLowland,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,EastLowland,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,EastLowland,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,EastLowland,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,EastLowland,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Therys,EastLowland,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,WestLowland,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,WestLowland,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,WestLowland,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,WestLowland,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,WestLowland,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,WestLowland,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,WestLowland,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,WestLowland,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralSouth,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralSouth,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralSouth,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralSouth,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralSouth,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralSouth,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralSouth,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralSouth,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralNorth,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralNorth,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralNorth,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralNorth,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralNorth,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralNorth,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralNorth,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralNorth,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,NorthHorst,Floodplain,,364343.864961229,37470.15803050995,0.0,,0.0,,0.0 +gas,Volon,NorthHorst,Channel,,1341698.4110712244,347524.8909626007,329044.31031417847,,76521931.53320312,,11707.85561132431 +gas,Volon,NorthHorst,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,NorthHorst,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,NorthHorst,Calcite,,210603.6138088575,0.0,0.0,,0.0,,0.0 +gas,Volon,NorthHorst,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,NorthHorst,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,NorthHorst,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralRamp,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralRamp,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralRamp,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralRamp,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralRamp,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralRamp,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralRamp,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralRamp,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralHorst,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralHorst,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralHorst,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralHorst,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralHorst,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralHorst,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralHorst,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,CentralHorst,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,EastLowland,Floodplain,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,EastLowland,Channel,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,EastLowland,Crevasse,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,EastLowland,Coal,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,EastLowland,Calcite,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,EastLowland,Offshore,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,EastLowland,Lowershoreface,,0.0,0.0,0.0,,0.0,,0.0 +gas,Volon,EastLowland,Uppershoreface,,0.0,0.0,0.0,,0.0,,0.0 +oil,Valysar,WestLowland,Floodplain,,10617054.238023624,1117607.4922103882,23227.239029206336,16197.517137739807,,2280610.458678603, +oil,Valysar,WestLowland,Channel,,8989826.157752592,2435860.422832489,2012285.9346637728,1403267.7670412064,,197580106.1011963, +oil,Valysar,WestLowland,Crevasse,,2020525.9672615,429215.15205192566,181178.26512646675,126344.67848229408,,17789331.124816895, +oil,Valysar,WestLowland,Coal,,1769264.7864318816,0.0,0.0,0.0,,0.0, +oil,Valysar,WestLowland,Calcite,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,WestLowland,Offshore,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,WestLowland,Lowershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,WestLowland,Uppershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralSouth,Floodplain,,31863784.14411839,3345458.0573444366,206238.0423533716,143820.1164221284,,20249872.8379792, +oil,Valysar,CentralSouth,Channel,,21994363.936110623,5877080.464912415,5392953.442474365,3760776.539276123,,529517348.359375, +oil,Valysar,CentralSouth,Crevasse,,9630347.8669113,2056704.3885498047,1442780.3943190577,1006123.0293889046,,141662125.7640381, +oil,Valysar,CentralSouth,Coal,,5338275.375811686,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralSouth,Calcite,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralSouth,Offshore,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralSouth,Lowershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralSouth,Uppershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralNorth,Floodplain,,5455000.771957926,547035.937215805,33501.11325807059,23362.004129663823,,3289370.2499630023, +oil,Valysar,CentralNorth,Channel,,12661320.607497867,3371248.566383362,3048553.6417999268,2125909.140953064,,299328013.6015625, +oil,Valysar,CentralNorth,Crevasse,,2463845.0492586843,511918.1171989441,334549.9238510132,233298.41764831543,,32848417.95166016, +oil,Valysar,CentralNorth,Coal,,925883.1887985412,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralNorth,Calcite,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralNorth,Offshore,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralNorth,Lowershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralNorth,Uppershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,NorthHorst,Floodplain,,1492595.392836864,140858.8151359558,3468.6073589362204,2130.594168940559,,417383.3846895695, +oil,Valysar,NorthHorst,Channel,,1135639.196565088,313550.8059043884,277676.2647705078,170562.81286239624,,33413253.935791016, +oil,Valysar,NorthHorst,Crevasse,,326485.32225101616,69718.73272323608,45057.70946121216,27676.72515106201,,5421870.28515625, +oil,Valysar,NorthHorst,Coal,,1039938.8123510056,0.0,0.0,0.0,,0.0, +oil,Valysar,NorthHorst,Calcite,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,NorthHorst,Offshore,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,NorthHorst,Lowershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,NorthHorst,Uppershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralRamp,Floodplain,,7066877.1281456165,719382.6530761719,98415.05608743428,68629.74765700102,,9663068.69365692, +oil,Valysar,CentralRamp,Channel,,2460994.7809819,668061.630859375,628712.5500488281,438432.7495117188,,61731332.515625, +oil,Valysar,CentralRamp,Crevasse,,2054966.4543136,440138.4622192383,338165.2594604492,235819.57247924805,,33203396.5625, +oil,Valysar,CentralRamp,Coal,,2036800.6100351969,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralRamp,Calcite,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralRamp,Offshore,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralRamp,Lowershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralRamp,Uppershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralHorst,Floodplain,,38292649.38000971,3703954.80210495,446058.3405727092,311058.82166106254,,43797083.065481424, +oil,Valysar,CentralHorst,Channel,,30297145.271267276,8469135.34267807,7995184.319991112,5575442.4639520645,,785022315.7198486, +oil,Valysar,CentralHorst,Crevasse,,9341141.57218151,1955937.425998688,1489946.327079773,1039014.197631836,,146293202.39746094, +oil,Valysar,CentralHorst,Coal,,9357644.562260604,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralHorst,Calcite,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralHorst,Offshore,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralHorst,Lowershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,CentralHorst,Uppershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,EastLowland,Floodplain,,1059572.596787264,101166.8919582367,1993.2023177444933,1389.9598031640053,,195706.34384155276, +oil,Valysar,EastLowland,Channel,,404126.44061334943,109690.4754333496,88208.29222106934,61512.06010437012,,8660898.25, +oil,Valysar,EastLowland,Crevasse,,374615.27393875417,78070.40096664429,43994.2154006958,30679.36980819702,,4319655.3740234375, +oil,Valysar,EastLowland,Coal,,46432.20856367124,0.0,0.0,0.0,,0.0, +oil,Valysar,EastLowland,Calcite,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,EastLowland,Offshore,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,EastLowland,Lowershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Valysar,EastLowland,Uppershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,WestLowland,Floodplain,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,WestLowland,Channel,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,WestLowland,Crevasse,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,WestLowland,Coal,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,WestLowland,Calcite,,554181.0156928146,0.0,0.0,0.0,,0.0, +oil,Therys,WestLowland,Offshore,,2761455.1479008426,307397.8189597428,34038.648537412286,23736.854428380728,,3342149.1755390167, +oil,Therys,WestLowland,Lowershoreface,,1687914.816969034,420328.8777313232,220817.89211940765,153987.37596940994,,21681423.068115234, +oil,Therys,WestLowland,Uppershoreface,,915271.210921567,294645.0403442383,240161.92266464236,167476.93749427795,,23580753.401611328, +oil,Therys,CentralSouth,Floodplain,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,CentralSouth,Channel,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,CentralSouth,Crevasse,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,CentralSouth,Coal,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,CentralSouth,Calcite,,3934426.742584882,0.0,0.0,0.0,,0.0, +oil,Therys,CentralSouth,Offshore,,3873337.6947715487,400129.8160417676,37208.57734657824,25947.40459401905,,3653394.6455631256, +oil,Therys,CentralSouth,Lowershoreface,,5748684.675103272,1503645.283993721,637981.0917649269,444896.1677324772,,62641381.82479858, +oil,Therys,CentralSouth,Uppershoreface,,7379720.778906669,2426547.158536704,2085643.826799402,1454423.8999371305,,204782889.85741255, +oil,Therys,CentralNorth,Floodplain,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,CentralNorth,Channel,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,CentralNorth,Crevasse,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,CentralNorth,Coal,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,CentralNorth,Calcite,,860942.6100305169,0.0,0.0,0.0,,0.0, +oil,Therys,CentralNorth,Offshore,,2757199.2122282274,298106.6772579551,29140.878550936468,20321.394132959656,,2861252.3559960723, +oil,Therys,CentralNorth,Lowershoreface,,3143611.625191472,789460.5284576416,350552.1605603695,244457.57868814468,,34419627.858688354, +oil,Therys,CentralNorth,Uppershoreface,,2612553.542526165,874353.4150161743,758773.818145752,529130.9870758057,,74501644.73046875, +oil,Therys,NorthHorst,Floodplain,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,NorthHorst,Channel,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,NorthHorst,Crevasse,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,NorthHorst,Coal,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,NorthHorst,Calcite,,1495481.8248747282,0.0,0.0,0.0,,0.0, +oil,Therys,NorthHorst,Offshore,,6622852.029896884,694637.8660972416,53459.55525428057,32837.56390105188,,6432878.569137573, +oil,Therys,NorthHorst,Lowershoreface,,1655350.917052068,409644.76972198486,208647.28194999692,128161.7182416916,,25106879.83251953, +oil,Therys,NorthHorst,Uppershoreface,,1257963.2949182668,413637.0375671387,360905.01068115234,221686.1196479797,,43428309.5703125, +oil,Therys,CentralRamp,Floodplain,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,CentralRamp,Channel,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,CentralRamp,Crevasse,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,CentralRamp,Coal,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,CentralRamp,Calcite,,593991.2908262819,0.0,0.0,0.0,,0.0, +oil,Therys,CentralRamp,Offshore,,1431340.869907574,148852.7599207759,24441.49147706479,17044.276120871305,,2399834.13234663, +oil,Therys,CentralRamp,Lowershoreface,,2304507.7517791702,613248.1231441498,334072.9804177284,232965.82205152512,,32801588.476470947, +oil,Therys,CentralRamp,Uppershoreface,,2962122.652400708,985600.809753418,903236.6296691896,629872.1402282715,,88685999.515625, +oil,Therys,CentralHorst,Floodplain,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,CentralHorst,Channel,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,CentralHorst,Crevasse,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,CentralHorst,Coal,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,CentralHorst,Calcite,,2552272.173556291,0.0,0.0,0.0,,0.0, +oil,Therys,CentralHorst,Offshore,,2255777.422510438,225787.63114789128,35396.17759407312,24683.52744662203,,3475440.7446291447, +oil,Therys,CentralHorst,Lowershoreface,,14719257.450895907,3734269.526997566,2161583.169389814,1507380.2072181404,,212239137.8198738, +oil,Therys,CentralHorst,Uppershoreface,,13596755.747001136,4630767.1332188845,4267965.924466312,2976266.397701025,,419058318.68291473, +oil,Therys,EastLowland,Floodplain,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,EastLowland,Channel,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,EastLowland,Crevasse,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,EastLowland,Coal,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,EastLowland,Calcite,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,EastLowland,Offshore,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,EastLowland,Lowershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Therys,EastLowland,Uppershoreface,,1131.7565990771675,332.6386880874634,228.3382232785225,159.2316775918007,,22419.820503234863, +oil,Volon,WestLowland,Floodplain,,270721.1994971532,27752.885511398315,0.0,0.0,,0.0, +oil,Volon,WestLowland,Channel,,984416.3740870258,254233.05933189392,218153.45304107663,152129.32889175415,,21419810.040039062, +oil,Volon,WestLowland,Crevasse,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,WestLowland,Coal,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,WestLowland,Calcite,,137817.83978332992,0.0,0.0,0.0,,0.0, +oil,Volon,WestLowland,Offshore,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,WestLowland,Lowershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,WestLowland,Uppershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralSouth,Floodplain,,9304415.72036617,955114.2467422484,0.0,0.0,,0.0, +oil,Volon,CentralSouth,Channel,,19653240.061673928,4962613.848018646,4160130.551491738,2901067.3908262253,,408470297.7477417, +oil,Volon,CentralSouth,Crevasse,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralSouth,Coal,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralSouth,Calcite,,4928005.891166749,0.0,0.0,0.0,,0.0, +oil,Volon,CentralSouth,Offshore,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralSouth,Lowershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralSouth,Uppershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralNorth,Floodplain,,1505175.9581942908,147403.83064460754,0.0,0.0,,0.0, +oil,Volon,CentralNorth,Channel,,1803989.3480120436,455273.9580001831,395467.70960998535,275779.4408721924,,38829746.041015625, +oil,Volon,CentralNorth,Crevasse,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralNorth,Coal,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralNorth,Calcite,,296676.11476945115,0.0,0.0,0.0,,0.0, +oil,Volon,CentralNorth,Offshore,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralNorth,Lowershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralNorth,Uppershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,NorthHorst,Floodplain,,848559.5087144992,80276.21952915192,0.0,0.0,,0.0, +oil,Volon,NorthHorst,Channel,,4029707.733865963,1024598.2204456328,876413.3120002747,538337.4026460648,,105460293.76904295, +oil,Volon,NorthHorst,Crevasse,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,NorthHorst,Coal,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,NorthHorst,Calcite,,436692.6384768367,0.0,0.0,0.0,,0.0, +oil,Volon,NorthHorst,Offshore,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,NorthHorst,Lowershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,NorthHorst,Uppershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralRamp,Floodplain,,2740706.434800088,296081.5480232239,0.0,0.0,,0.0, +oil,Volon,CentralRamp,Channel,,6164647.877096181,1567841.4377975464,1418719.958831787,989344.4829406738,,139299706.50585938, +oil,Volon,CentralRamp,Crevasse,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralRamp,Coal,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralRamp,Calcite,,1068693.408383527,0.0,0.0,0.0,,0.0, +oil,Volon,CentralRamp,Offshore,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralRamp,Lowershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralRamp,Uppershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralHorst,Floodplain,,18722381.21782312,1870368.050403595,0.0,0.0,,0.0, +oil,Volon,CentralHorst,Channel,,45714080.13706036,11649754.367343904,10682287.597171783,7449294.162065506,,1048860640.4580078, +oil,Volon,CentralHorst,Crevasse,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralHorst,Coal,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralHorst,Calcite,,6343476.620083108,0.0,0.0,0.0,,0.0, +oil,Volon,CentralHorst,Offshore,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralHorst,Lowershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,CentralHorst,Uppershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,EastLowland,Floodplain,,124830.97231758678,14356.808109283447,0.0,0.0,,0.0, +oil,Volon,EastLowland,Channel,,201354.6175916892,48221.91468048096,30157.843872070312,21030.57489013672,,2961105.01171875, +oil,Volon,EastLowland,Crevasse,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,EastLowland,Coal,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,EastLowland,Calcite,,86379.79939277154,0.0,0.0,0.0,,0.0, +oil,Volon,EastLowland,Offshore,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,EastLowland,Lowershoreface,,0.0,0.0,0.0,0.0,,0.0, +oil,Volon,EastLowland,Uppershoreface,,0.0,0.0,0.0,0.0,,0.0, diff --git a/tests/test_export_rms/conftest.py b/tests/test_export_rms/conftest.py index a95f223a2..e352ba0fc 100644 --- a/tests/test_export_rms/conftest.py +++ b/tests/test_export_rms/conftest.py @@ -1,7 +1,7 @@ """The conftest.py, providing magical fixtures to tests.""" import sys -from unittest.mock import MagicMock +from unittest.mock import MagicMock, patch import pytest @@ -191,32 +191,32 @@ } -@pytest.fixture(autouse=True) -def mock_rmsapi_package(monkeypatch): +@pytest.fixture +def mock_rmsapi(): # Create a mock rmsapi module mock_rmsapi = MagicMock() - monkeypatch.setitem(sys.modules, "rmsapi", mock_rmsapi) - mock_x_rmsapi = MagicMock() - monkeypatch.setitem(sys.modules, "_rmsapi", mock_x_rmsapi) mock_rmsapi.__version__ = "1.7" - mock_jobs_rmsapi = MagicMock() - monkeypatch.setitem(sys.modules, "rmsapi.jobs", mock_jobs_rmsapi) - mock_rmsapi.jobs.Job.get_job(...).get_arguments.return_value = VOLJOB_PARAMS - yield mock_rmsapi, mock_x_rmsapi, mock_jobs_rmsapi + yield mock_rmsapi -@pytest.fixture(autouse=True) -def mock_roxar_package(monkeypatch): - # Create a mock roxar module (roxar is renamed to rmsapi from RMS 14.x) - mock_roxar = MagicMock() - monkeypatch.setitem(sys.modules, "roxar", mock_roxar) - mock_x_roxar = MagicMock() - monkeypatch.setitem(sys.modules, "_roxar", mock_x_roxar) - mock_roxar.__version__ = "1.7" +@pytest.fixture +def mock_rmsapi_jobs(): + # Create a mock rmsapi.jobs module + mock_rmsapi_jobs = MagicMock() + yield mock_rmsapi_jobs - mock_roxar.jobs.Job.get_job(...).get_arguments.return_value = VOLJOB_PARAMS - yield mock_roxar, mock_x_roxar + +@pytest.fixture +def mocked_rmsapi_modules(mock_rmsapi, mock_rmsapi_jobs): + with patch.dict( + sys.modules, + { + "rmsapi": mock_rmsapi, + "rmsapi.jobs": mock_rmsapi_jobs, + }, + ) as mocked_modules: + yield mocked_modules @pytest.fixture(autouse=True) diff --git a/tests/test_export_rms/test_export_rms_volumetrics.py b/tests/test_export_rms/test_export_rms_volumetrics.py index 49c4f76d7..fe1e8644b 100644 --- a/tests/test_export_rms/test_export_rms_volumetrics.py +++ b/tests/test_export_rms/test_export_rms_volumetrics.py @@ -1,7 +1,9 @@ """Test the dataio running RMS spesici utility function for volumetrics""" +import unittest.mock as mock from pathlib import Path +import numpy as np import pandas as pd import pytest @@ -12,44 +14,62 @@ logger = null_logger(__name__) -VOLDATA = (Path("tests/data/drogon/tabular/geogrid--vol.csv")).absolute() -EXPECTED_TABLE_INDEX_COLUMNS = ["ZONE", "REGION", "FACIES"] +VOLDATA_LEGACY = Path("tests/data/drogon/tabular/geogrid--vol.csv").absolute() +VOLDATA_STANDARD = Path("tests/data/drogon/tabular/volumes/geogrid.csv").absolute() +EXPECTED_COLUMN_ORDER = [ + "FLUID", + "ZONE", + "REGION", + "FACIES", + "LICENSE", + "BULK", + "PORV", + "HCPV", + "STOIIP", + "GIIP", + "ASSOCIATEDGAS", + "ASSOCIATEDOIL", +] -@pytest.fixture -def voltable_as_dataframe(): - return pd.read_csv(VOLDATA) + +@pytest.fixture(scope="package") +def voltable_legacy(): + return pd.read_csv(VOLDATA_LEGACY) + + +@pytest.fixture(scope="package") +def voltable_standard(): + return pd.read_csv(VOLDATA_STANDARD) @inside_rms def test_rms_volumetrics_export_class( - mock_project_variable, voltable_as_dataframe, rmssetup_with_fmuconfig, monkeypatch + mock_project_variable, + mocked_rmsapi_modules, + voltable_standard, + rmssetup_with_fmuconfig, + monkeypatch, ): """See mocks in local conftest.py""" import rmsapi # type: ignore # noqa import rmsapi.jobs as jobs # type: ignore # noqa - from fmu.dataio.export.rms.inplace_volumes import ( - _ExportVolumetricsRMS, - _TABLE_INDEX_COLUMNS, - ) + from fmu.dataio.export.rms.inplace_volumes import _ExportVolumetricsRMS monkeypatch.chdir(rmssetup_with_fmuconfig) assert rmsapi.__version__ == "1.7" assert "Report" in jobs.Job.get_job("whatever").get_arguments.return_value - instance = _ExportVolumetricsRMS( - mock_project_variable, - "Geogrid", - "geogrid_vol", - ) + instance = _ExportVolumetricsRMS(mock_project_variable, "Geogrid", "geogrid_vol") - assert instance._volume_table_name == "geogrid_volumes" + # patch the dataframe otherwise will fail in table index validation in objdata + monkeypatch.setattr(instance, "_dataframe", voltable_standard) - # patch the dataframe which originally shall be retrieved from RMS - monkeypatch.setattr(instance, "_dataframe", voltable_as_dataframe) + # volume table name should be picked up by the mocked object + assert instance._volume_table_name == "geogrid_volumes" out = instance._export_volume_table() @@ -58,15 +78,129 @@ def test_rms_volumetrics_export_class( assert "volumes" in metadata["data"]["content"] assert metadata["access"]["classification"] == "restricted" + +@inside_rms +def test_rms_volumetrics_export_class_table_index( + mock_project_variable, + mocked_rmsapi_modules, + voltable_standard, + rmssetup_with_fmuconfig, + monkeypatch, +): + """See mocks in local conftest.py""" + + monkeypatch.chdir(rmssetup_with_fmuconfig) + + from fmu.dataio.export.rms.inplace_volumes import ( + _TABLE_INDEX_COLUMNS, + _ExportVolumetricsRMS, + ) + + instance = _ExportVolumetricsRMS(mock_project_variable, "Geogrid", "geogrid_vol") + + monkeypatch.setattr(instance, "_dataframe", voltable_standard) + + out = instance._export_volume_table() + metadata = dataio.read_metadata(out.items[0].absolute_path) + # check that the table index is set correctly - assert len(_TABLE_INDEX_COLUMNS) > len(EXPECTED_TABLE_INDEX_COLUMNS) - assert instance._table_index == EXPECTED_TABLE_INDEX_COLUMNS - assert metadata["data"]["table_index"] == EXPECTED_TABLE_INDEX_COLUMNS + assert metadata["data"]["table_index"] == _TABLE_INDEX_COLUMNS + + # should fail if missing table index + monkeypatch.setattr(instance, "_dataframe", voltable_standard.drop(columns="ZONE")) + with pytest.raises(KeyError, match="ZONE is not in table"): + instance._export_volume_table() + + +@inside_rms +def test_convert_table_from_legacy_to_standard_format( + mock_project_variable, + mocked_rmsapi_modules, + voltable_standard, + voltable_legacy, + rmssetup_with_fmuconfig, + monkeypatch, +): + """Test that a voltable with legacy format is converted to + the expected standard format""" + + from fmu.dataio.export.rms.inplace_volumes import ( + _FLUID_COLUMN, + _ExportVolumetricsRMS, + ) + + monkeypatch.chdir(rmssetup_with_fmuconfig) + + # set the return value to be the table with legacy format + # conversion to standard format should take place automatically + with mock.patch.object( + _ExportVolumetricsRMS, + "_convert_table_from_rms_to_legacy_format", + return_value=voltable_legacy, + ): + instance = _ExportVolumetricsRMS( + mock_project_variable, "Geogrid", "geogrid_vol" + ) + + # the _dataframe attribute should now have been converted to standard + pd.testing.assert_frame_equal(voltable_standard, instance._dataframe) + + # check that the exported table is equal to the expected + out = instance._export_volume_table() + exported_table = pd.read_csv(out.items[0].absolute_path) + pd.testing.assert_frame_equal(voltable_standard, exported_table) + + # check that the fluid column exists and contains oil and gas + assert _FLUID_COLUMN in exported_table + assert set(exported_table[_FLUID_COLUMN].unique()) == {"oil", "gas"} + + # check the column order + assert list(exported_table.columns) == EXPECTED_COLUMN_ORDER + + # check that the legacy format and the standard format gives + # the same sum for volumetric columns + assert np.isclose( + exported_table["STOIIP"].sum(), + voltable_legacy["STOIIP_OIL"].sum(), + ) + assert np.isclose( + exported_table["GIIP"].sum(), + voltable_legacy["GIIP_GAS"].sum(), + ) + assert np.isclose( + exported_table["BULK"].sum(), + (voltable_legacy["BULK_OIL"] + voltable_legacy["BULK_GAS"]).sum(), + ) + assert np.isclose( + exported_table["PORV"].sum(), + (voltable_legacy["PORV_OIL"] + voltable_legacy["PORV_GAS"]).sum(), + ) + assert np.isclose( + exported_table["HCPV"].sum(), + (voltable_legacy["HCPV_OIL"] + voltable_legacy["HCPV_GAS"]).sum(), + ) + + # make a random check for a particular row as well + filter_query = ( + "REGION == 'WestLowland' and ZONE == 'Valysar' and FACIES == 'Channel'" + ) + expected_bulk_for_filter = 8989826.15 + assert np.isclose( + exported_table.query(filter_query + " and FLUID == 'oil'")["BULK"], + expected_bulk_for_filter, + ) + assert np.isclose( + voltable_legacy.query(filter_query)["BULK_OIL"], + expected_bulk_for_filter, + ) @inside_rms def test_rms_volumetrics_export_config_missing( - mock_project_variable, rmssetup_with_fmuconfig, monkeypatch + mock_project_variable, + mocked_rmsapi_modules, + rmssetup_with_fmuconfig, + monkeypatch, ): """Test that an exception is raised if the config is missing.""" @@ -88,15 +222,28 @@ def test_rms_volumetrics_export_config_missing( @inside_rms def test_rms_volumetrics_export_function( - mock_project_variable, rmssetup_with_fmuconfig, monkeypatch + mock_project_variable, + mocked_rmsapi_modules, + voltable_standard, + rmssetup_with_fmuconfig, + monkeypatch, ): """Test the public function.""" from fmu.dataio.export.rms import export_inplace_volumes + from fmu.dataio.export.rms.inplace_volumes import ( + _TABLE_INDEX_COLUMNS, + _ExportVolumetricsRMS, + ) monkeypatch.chdir(rmssetup_with_fmuconfig) - result = export_inplace_volumes(mock_project_variable, "Geogrid", "geogrid_volume") + with mock.patch.object( + _ExportVolumetricsRMS, "_get_table_with_volumes", return_value=voltable_standard + ): + result = export_inplace_volumes( + mock_project_variable, "Geogrid", "geogrid_volume" + ) vol_table_file = result.items[0].absolute_path absoulte_path = ( @@ -112,3 +259,4 @@ def test_rms_volumetrics_export_function( assert "volumes" in metadata["data"]["content"] assert metadata["access"]["classification"] == "restricted" + assert metadata["data"]["table_index"] == _TABLE_INDEX_COLUMNS