Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrivenaes committed Jul 1, 2024
1 parent 1eac24f commit 2e5cb10
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 72 deletions.
11 changes: 2 additions & 9 deletions docs/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"
Expand Down
25 changes: 15 additions & 10 deletions src/fmu/dataio/export/rms/_conditional_rms_imports.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand All @@ -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)
66 changes: 13 additions & 53 deletions src/fmu/dataio/export/rms/volumetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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)
Expand All @@ -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")

Expand All @@ -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):
Expand All @@ -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."""
Expand Down Expand Up @@ -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")

Expand All @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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(
Expand All @@ -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()

0 comments on commit 2e5cb10

Please sign in to comment.