Skip to content

Commit

Permalink
Remove md_log_file option for rft
Browse files Browse the repository at this point in the history
  • Loading branch information
equinor-ruaj committed Nov 21, 2024
1 parent 5b3878c commit 17804a9
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 438 deletions.
60 changes: 1 addition & 59 deletions src/fmu/sumo/sim2sumo/_special_treatments.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,34 +109,11 @@ def _define_submodules():
return tuple(submodules.keys()), submodules


def find_md_log(submod, options):
"""Search options for md_log_file
Args:
submod (str): submodule
options (dict): the dictionary to check
Returns:
str|None: whatever contained in md_log_file
"""
if submod != "rft":
return None
# Special treatment of argument md_log_file
md_log_file = options.get("md_log_file", None)
try:
del options["md_log_file"]
except KeyError:
pass # No md log provided

return md_log_file


def complete_rft(frame, md_log_file):
def tidy(frame):
"""Utility function to tidy up mess from res2df for rft
Args:
frame (pd.DataFrame): the dataframe fixed with no WELLETC
md_log_file (str): file with md log file
"""
# res2df creates three files for rft data, see unwanted list below
logger = logging.getLogger(__file__ + ".tidy")
Expand All @@ -153,9 +130,6 @@ def complete_rft(frame, md_log_file):
if "WELLETC" in frame.columns:
frame.drop(["WELLETC"], axis=1, inplace=True)

if md_log_file is not None:
frame = add_md_to_rft(frame, md_log_file)

return frame


Expand Down Expand Up @@ -187,35 +161,3 @@ def vfp_to_arrow_dict(datafile, options):
resdatafiles.get_deck(), keyword=keyword, vfpnumbers_str=vfpnumbers
)
return vfp_dict


def add_md_to_rft(rft_table, md_file_path):
"""Merge md data with rft table
Args:
rft_table (pd.DataFrame): the rft dataframe
md_file_path (str): path to file with md data
Raises:
FileNotFoundError: if md_file_path does not point to existing file
Returns:
pd.Dataframe: the merged results
"""
try:
md_table = pd.read_csv(md_file_path)
except FileNotFoundError as fnfe:
raise FileNotFoundError(
f"There is no md file called {md_file_path}"
) from fnfe

xtgeo_index_names = ["I_INDEX", "J_INDEX", "K_INDEX"]
rft_index_names = ["CONIPOS", "CONJPOS", "CONKPOS"]
# for grid indeces xtgeo starts from 0, res2df from 1
md_table[xtgeo_index_names] += 1
md_table[xtgeo_index_names] = md_table[xtgeo_index_names].astype(int)
xtgeo_to_rft_names = dict(zip(xtgeo_index_names, rft_index_names))
md_table.rename(xtgeo_to_rft_names, axis=1, inplace=True)
rft_table = pd.merge(rft_table, md_table, on=rft_index_names, how="left")

return rft_table
2 changes: 1 addition & 1 deletion src/fmu/sumo/sim2sumo/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def filter_options(submod, kwargs):
filtered = {
key: value
for key, value in kwargs.items()
if (key in submod_options) or key in ["arrow", "md_log_file"]
if (key in submod_options) or key == "arrow"
}
filtered["arrow"] = kwargs.get(
"arrow", True
Expand Down
8 changes: 2 additions & 6 deletions src/fmu/sumo/sim2sumo/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@

from ._special_treatments import (
SUBMOD_DICT,
complete_rft,
tidy,
convert_to_arrow,
vfp_to_arrow_dict,
find_md_log,
)
from .common import generate_meta

Expand Down Expand Up @@ -121,9 +120,6 @@ def get_table(
except KeyError:
pass # No arrow key to delete
output = None
# TODO: see if there is a cleaner way with rft, see functions
# find_md_log, and complete_rft, but needs really to be fixed in res2df
md_log_file = find_md_log(submod, kwargs)
try:
logger.info(
"Extracting data from %s with func %s for %s",
Expand All @@ -136,7 +132,7 @@ def get_table(
**kwargs,
)
if submod == "rft":
output = complete_rft(output, md_log_file)
output = tidy(output)
if arrow:
try:
convert_func = SUBMOD_DICT[submod]["arrow_convertor"]
Expand Down
5 changes: 0 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ def _fix_rft_reek():
)


@pytest.fixture(scope="session", name="drogonrft")
def _fix_rft_drogon():
return pd.read_csv(Path(__file__).parent / "data/drogon/rft.csv")


@pytest.fixture(scope="session", name="config")
def _fix_config():
return yaml_load(CONFIG_PATH)
Expand Down
Binary file not shown.

This file was deleted.

Loading

0 comments on commit 17804a9

Please sign in to comment.