From 2e5cb10f955c3627311b88573b28f55b9c3e6d08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20C=2E=20Riven=C3=A6s?= Date: Mon, 1 Jul 2024 10:18:49 +0200 Subject: [PATCH] fixup --- docs/src/conf.py | 11 +--- .../export/rms/_conditional_rms_imports.py | 25 ++++--- src/fmu/dataio/export/rms/volumetrics.py | 66 ++++--------------- 3 files changed, 30 insertions(+), 72 deletions(-) diff --git a/docs/src/conf.py b/docs/src/conf.py index d2d78b7cd..2ff1446f5 100755 --- a/docs/src/conf.py +++ b/docs/src/conf.py @@ -69,8 +69,8 @@ def filter(self, record: logging.LogRecord) -> bool: # Sort members by input order in classes autodoc_member_order = "bysource" autodoc_default_flags = ["members", "show_inheritance"] -# Mocking ert, pydantic module -autodoc_mock_imports = ["ert", "pydantic"] +# Mocking ert, rms, pydantic module +autodoc_mock_imports = ["ert", "pydantic", "rmsapi", "_rmsapi", "roxar", "_roxar"] napoleon_include_special_with_doc = False @@ -86,13 +86,6 @@ def filter(self, record: logging.LogRecord) -> bool: copyright = f"Equinor {current_year} (fmu-dataio release {release})" -# Sort members by input order in classes -autodoc_member_order = "bysource" -autodoc_default_flags = ["members", "show_inheritance"] - -# Mocking ert and RMS modules -autodoc_mock_imports = ["ert", "rmsapi", "_rmsapi", "roxar", "_roxar"] - exclude_patterns = ["_build"] pygments_style = "sphinx" diff --git a/src/fmu/dataio/export/rms/_conditional_rms_imports.py b/src/fmu/dataio/export/rms/_conditional_rms_imports.py index 27868ae6e..ce66e95a2 100644 --- a/src/fmu/dataio/export/rms/_conditional_rms_imports.py +++ b/src/fmu/dataio/export/rms/_conditional_rms_imports.py @@ -1,22 +1,25 @@ """Handle rmsapi or roxar (deprecated version of rmsapi); only present inside RMS""" +from __future__ import annotations + import warnings -from typing import TYPE_CHECKING, Any, Dict, Optional +from typing import TYPE_CHECKING, Any + +from fmu.dataio._logging import null_logger -# mypy: ignore-errors +_logger = null_logger(__name__) -def import_rms_package() -> Optional[Dict[str, Any]]: +def import_rms_package() -> dict[str, Any] | None: """ Attempts to import the 'rmsapi' package first. If 'rmsapi' is not available, it attempts to import the 'roxar' package while suppressing deprecation warnings. Returns a dictionary with the imported modules or raises ImportError if neither is available. """ - # mypy: ignore-errors try: - import rmsapi # type: ignore[import] - import rmsapi.jobs as jobs # type: ignore[import] + import rmsapi + import rmsapi.jobs as jobs return {"rmsapi": rmsapi, "jobs": jobs} except ImportError: @@ -25,8 +28,8 @@ def import_rms_package() -> Optional[Dict[str, Any]]: warnings.filterwarnings( "ignore", category=DeprecationWarning, module="roxar" ) - import roxar as rmsapi # type: ignore[import] - import roxar.jobs as jobs # type: ignore[import] + import roxar as rmsapi + import roxar.jobs as jobs return {"rmsapi": rmsapi, "jobs": jobs} except ImportError: @@ -37,5 +40,7 @@ def import_rms_package() -> Optional[Dict[str, Any]]: if TYPE_CHECKING: - import rmsapi # type: ignore # noqa - import rmsapi.jobs # type: ignore # noqa + import rmsapi + import rmsapi.jobs + + _logger.debug("Importing both %s and %s", rmsapi, rmsapi.jobs) diff --git a/src/fmu/dataio/export/rms/volumetrics.py b/src/fmu/dataio/export/rms/volumetrics.py index a0f31bbf1..18adb1d0f 100644 --- a/src/fmu/dataio/export/rms/volumetrics.py +++ b/src/fmu/dataio/export/rms/volumetrics.py @@ -14,14 +14,10 @@ from ._conditional_rms_imports import import_rms_package -try: - modules = import_rms_package() - if modules: - rmsapi = modules["rmsapi"] - jobs = modules["jobs"] -except ImportError as ier: - print(ier) - raise +_modules = import_rms_package() +if _modules: + rmsapi = _modules["rmsapi"] + jobs = _modules["jobs"] _logger: Final = null_logger(__name__) @@ -65,9 +61,6 @@ class _ExportVolumetricsRMS: tagname: str = "vol" classification: str = "restricted" workflow: str = "rms volumetric run" - include_zone_maps: bool = False - include_total_maps: bool = False - include_3dgrid_properties: bool = False # internal storage instance variables _global_config: dict = field(default_factory=dict, init=False) @@ -84,7 +77,6 @@ def __post_init__(self) -> None: self._read_volume_table_name_from_rms() self._voltable_as_dataframe() self._set_units() - self._read_includes_etc() self._warn_if_forcefolder() _logger.debug("Process data... DONE") @@ -100,7 +92,6 @@ def _check_rmsapi_version() -> None: def _set_global_config(self) -> None: """Set the global config data by reading the file.""" - # TODO: This functionality should ideally be in fmu-config. _logger.debug("Set global config...") if isinstance(self.global_config, dict): @@ -110,15 +101,12 @@ def _set_global_config(self) -> None: global_config_path = Path(self.global_config) - if global_config_path.is_file(): - _logger.debug("Read config from yaml...") - self._global_config = yaml_load(global_config_path) - _logger.debug("Read config from yaml... DONE") - else: + if not global_config_path.is_file(): raise FileNotFoundError( f"Cannot find file for global config: {self.global_config}" ) - _logger.debug("Set global config (from file)... DONE!") + self._global_config = yaml_load(global_config_path) + _logger.debug("Read config from yaml... DONE") def _rms_volume_job_settings(self) -> None: """Get information out from the RMS job API.""" @@ -156,9 +144,9 @@ def _voltable_as_dataframe(self) -> None: .to_dict() ) _logger.debug("Dict values are: %s", dict_values) - self._dataframe = dfr = pd.DataFrame.from_dict(dict_values) - dfr.rename(columns=_RENAME_COLUMNS_FROM_RMS, inplace=True) - dfr.drop("REAL", axis=1, inplace=True, errors="ignore") + self._dataframe = pd.DataFrame.from_dict(dict_values) + self._dataframe.rename(columns=_RENAME_COLUMNS_FROM_RMS, inplace=True) + self._dataframe.drop("REAL", axis=1, inplace=True, errors="ignore") _logger.debug("Read values and convert to pandas dataframe... DONE") @@ -169,21 +157,6 @@ def _set_units(self) -> None: _logger.debug("Units are %s", units) self._units = str(units) - def _read_includes_etc(self) -> None: - """Handle other products (placeholder; in prep in the code).""" - if self.include_zone_maps: - raise NotImplementedError( - "Including zone maps is currently not implemented" - ) - if self.include_total_maps: - raise NotImplementedError( - "Including total maps is currently not implemented" - ) - if self.include_3dgrid_properties: - raise NotImplementedError( - "Including 3D parameters is currently not implemented" - ) - def _warn_if_forcefolder(self) -> None: if self.forcefolder: warn( @@ -194,8 +167,6 @@ def _warn_if_forcefolder(self) -> None: def _export_volume_table(self) -> dict[str, str]: """Do the actual volume table export using dataio setup.""" - # if self._dataframe.is_empty(): - # raise ValueError("No data in volume table.") edata = dio.ExportData( config=self._global_config, @@ -230,9 +201,6 @@ def export_rms_volumetrics( tagname: str = "", classification: str = "restricted", workflow: str = "rms volumetric run", - include_zone_maps: bool = False, - include_total_maps: bool = False, - include_3dgrid_properties: bool = False, ) -> dict[str, str]: """Simplified interface when exporting volume tables (and assosiated data) from RMS. @@ -246,24 +214,19 @@ def export_rms_volumetrics( volume_job_name: Name of the volume job. global_config: Optional. The global config can either point to the global_variables file, or it can be a dictionary. As default, it assumes - a path which is the current standard in FMU. + a the current standard in FMU: + ``'../../fmuconfig/output/global_variables.yml'`` forcefolder: Optional. As default, volume tables will be exported to the agreed file structure, and the folder name will be 'tables'. This can be overriden here, but there will be warnings. For optional assosiated volume maps and grids, the default folder names cannot be changed. + subfolder: Name of subfolder for local storage, below the standard folder. name: Optional. Name of export item. Is defaulted to name of grid + '_volumes'. tagname: Optional. Defaulted to 'vol' for this function. Tagnames are part of file names, and should not be applied as metadata. classification: Optional. Use 'internal' or 'restricted' (default). workflow: Optional. Information about the work flow; defaulted to 'rms volumetrics'. - include_zone_maps: Optional. If True, then all the zone maps that are toggled on - in the volume job are exported also (currently NOT implemented). - include_total_maps: Optional. If True, then all the total maps that are toggled - on in the volume job are exported also (currently NOT implemented). - include_3dgrid_propererties: Optional. If True, then all the 3D properties - (also called parameters) that are toggled on in the volume job are exported - also, together with the 3D grid geometry (currently NOT implemented). """ return _ExportVolumetricsRMS( @@ -277,7 +240,4 @@ def export_rms_volumetrics( tagname=tagname, classification=classification, workflow=workflow, - include_zone_maps=include_zone_maps, - include_total_maps=include_total_maps, - include_3dgrid_properties=include_3dgrid_properties, ).export()