Skip to content

Commit

Permalink
Merge branch 'main' into change-name-and-tagname-for-grids
Browse files Browse the repository at this point in the history
  • Loading branch information
equinor-ruaj committed Nov 27, 2024
2 parents 326f3ce + 85d7ec2 commit 20de570
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 453 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
17 changes: 2 additions & 15 deletions src/fmu/sumo/sim2sumo/grid3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ def upload_init(init_path, xtgeoegrid, config, dispatcher):
init_props = list(
eclrun.find_gridprop_from_init_file(init_path, "all", xtgeoegrid)
)
count = 0
for init_prop in init_props:
if init_prop["name"] in unwanted:
logger.warning("%s will not be exported", init_prop["name"])
Expand All @@ -152,9 +151,6 @@ def upload_init(init_path, xtgeoegrid, config, dispatcher):
)
continue
dispatcher.add(sumo_file)
count += 1
logger.info("%s properties set for upload", count)
return count


def upload_restart(restart_path, xtgeoegrid, time_steps, config, dispatcher):
Expand All @@ -169,7 +165,6 @@ def upload_restart(restart_path, xtgeoegrid, time_steps, config, dispatcher):
int: number of objects to export
"""
logger = logging.getLogger(__name__ + ".upload_restart")
count = 0
prop_names = ("SWAT", "SGAS", "SOIL", "PRESSURE", "SFIPOIL", "SFIPGAS")
for prop_name in prop_names:
for time_step in time_steps:
Expand All @@ -194,10 +189,6 @@ def upload_restart(restart_path, xtgeoegrid, time_steps, config, dispatcher):
)
continue
dispatcher.add(sumo_file)
count += 1
logger.info("%s properties uploaded", count)

return count


def upload_simulation_runs(datafiles, config, dispatcher):
Expand All @@ -220,7 +211,6 @@ def upload_simulation_run(datafile, config, dispatcher):
Args:
datafile (str): path to datafile
"""
logger = logging.getLogger(__name__ + ".upload_simulation_run")
datafile_path = Path(datafile).resolve()
init_path = str(datafile_path.with_suffix(".INIT"))
restart_path = str(datafile_path.with_suffix(".UNRST"))
Expand All @@ -233,11 +223,8 @@ def upload_simulation_run(datafile, config, dispatcher):
dispatcher.add(sumo_file)
time_steps = get_timesteps(restart_path, egrid)

count = upload_init(init_path, xtgeoegrid, config, dispatcher)
count += upload_restart(
restart_path, xtgeoegrid, time_steps, config, dispatcher
)
logger.info("Exported %s properties", count)
upload_init(init_path, xtgeoegrid, config, dispatcher)
upload_restart(restart_path, xtgeoegrid, time_steps, config, dispatcher)


def get_timesteps(restart_path, egrid):
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 pathlib import Path
Expand Down Expand Up @@ -148,9 +147,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 @@ -163,7 +159,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 20de570

Please sign in to comment.