Skip to content

Commit

Permalink
Use res2df instead of ecl2df
Browse files Browse the repository at this point in the history
  • Loading branch information
Yngve S. Kristiansen committed Dec 12, 2023
1 parent 2142fc5 commit 53d481b
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion docs/scripts/prtvol2csv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,5 @@ file has been supplied defining the map from zones and regions to FIPNUM:
See also
--------

* https://equinor.github.io/ecl2df/usage/fipreports.html can be used to extract
* https://equinor.github.io/res2df/usage/fipreports.html can be used to extract
more information from the PRT files.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dynamic = ["version"]
dependencies = [
"configsuite",
"resdata",
"ecl2df",
"res2df",
"ert>=2.38.0b7",
"fmu-tools",
"matplotlib",
Expand Down
34 changes: 17 additions & 17 deletions src/subscript/check_swatinit/check_swatinit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import sys
from typing import Any, Dict, List

import ecl2df
import numpy as np
import pandas as pd
import res2df
from matplotlib import pyplot

import subscript
Expand Down Expand Up @@ -58,7 +58,7 @@ def main() -> None:
if args.DATAFILE.endswith(".csv"):
qc_frame = pd.read_csv(args.DATAFILE)
else:
eclfiles = ecl2df.EclFiles(args.DATAFILE)
eclfiles = res2df.ResdataFiles(args.DATAFILE)

# Fail hard if the deck is not suitable for this tool or
# give warnings/hints to the user:
Expand Down Expand Up @@ -102,11 +102,11 @@ def main() -> None:
pyplot.savefig(args.plotfile)


def check_applicability(eclfiles: ecl2df.EclFiles) -> None:
def check_applicability(eclfiles: res2df.ResdataFiles) -> None:
"""Check that the input is relevant for usage with check_swatinit. This
function may raise exceptions, SystemExit or only give warnings"""

deck = eclfiles.get_ecldeck()
deck = eclfiles.get_deck()

init = eclfiles.get_initfile()
if (
Expand Down Expand Up @@ -212,15 +212,15 @@ def human_report_pc_scaling(qc_frame: pd.DataFrame) -> str:
return string


def make_qc_gridframe(eclfiles: ecl2df.EclFiles) -> pd.DataFrame:
def make_qc_gridframe(eclfiles: res2df.ResdataFiles) -> pd.DataFrame:
"""Construct a dataframe with needed information for swatinit qc from an
Eclipse run.
Makes a dataframe with one row for each active cell. Information from
satfunc and equil merged in.
"""

grid_df = ecl2df.grid.df(
grid_df = res2df.grid.df(
eclfiles,
vectors=[
# All of these are required.
Expand All @@ -242,22 +242,22 @@ def make_qc_gridframe(eclfiles: ecl2df.EclFiles) -> pd.DataFrame:
rstdates="first",
)

# Circumvent bug in ecl2df that will pick SWL from both INIT and restart file:
# Circumvent bug in res2df that will pick SWL from both INIT and restart file:
grid_df = grid_df.loc[:, ~grid_df.columns.duplicated()]

# Merge in PPCWMAX from the deck, it is not reported in binary output files:
if "PPCWMAX" in eclfiles.get_ecldeck():
if "PPCWMAX" in eclfiles.get_deck():
grid_df["PPCWMAX"] = ppcwmax_gridvector(eclfiles)

# This will be unneccessary from ecl2df 0.13.0:
# This will be unneccessary from res2df 0.13.0:
grid_df = grid_df.where(grid_df > -1e20 + 1e13)

if "SWL" not in grid_df:
logger.warning("SWL not found in model. Using SWL=0.")
logger.warning("Consider adding FILLEPS to the PROPS section")
grid_df["SWL"] = 0.0

deck = eclfiles.get_ecldeck()
deck = eclfiles.get_deck()
if "SWATINIT" in deck:
swatinit_deckdata = deck["SWATINIT"][0][0].get_raw_data_list()
# This list includes non-active cells, we must map via GLOBAL_INDEX:
Expand All @@ -280,12 +280,12 @@ def make_qc_gridframe(eclfiles: ecl2df.EclFiles) -> pd.DataFrame:
del grid_df["SWATINIT_DECK"] # This is not needed

# Exposed to issues with endpoint scaling in peculiar decks:
satfunc_df = ecl2df.satfunc.df(eclfiles)
satfunc_df = res2df.satfunc.df(eclfiles)

# Merge in the input pcmax pr. satnum for each cell:
grid_df = merge_pc_max(grid_df, satfunc_df)

grid_df = merge_equil(grid_df, ecl2df.equil.df(eclfiles, keywords=["EQUIL"]))
grid_df = merge_equil(grid_df, res2df.equil.df(eclfiles, keywords=["EQUIL"]))

grid_df = augment_grid_frame_qc_vectors(grid_df)

Expand Down Expand Up @@ -587,7 +587,7 @@ def compute_pc(qc_frame: pd.DataFrame, satfunc_df: pd.DataFrame) -> pd.Series:
return p_cap


def ppcwmax_gridvector(eclfiles: ecl2df.EclFiles) -> pd.Series:
def ppcwmax_gridvector(eclfiles: res2df.ResdataFiles) -> pd.Series:
"""Generate a vector of PPCWMAX data pr cell
PPCWMAX is pr. SATNUM in the input deck
Expand All @@ -596,11 +596,11 @@ def ppcwmax_gridvector(eclfiles: ecl2df.EclFiles) -> pd.Series:
eclfiles
Returns:
pd.Series, indexed according to ecl2df.grid.df(eclfiles)
pd.Series, indexed according to res2df.grid.df(eclfiles)
"""

satnum_df = ecl2df.grid.df(eclfiles, vectors="SATNUM")
deck = eclfiles.get_ecldeck()
satnum_df = res2df.grid.df(eclfiles, vectors="SATNUM")
deck = eclfiles.get_deck()
for satnum in satnum_df["SATNUM"].unique():
ppcwmax = deck["PPCWMAX"][satnum - 1][0].get_raw_data_list()[0]
satnum_df.loc[satnum_df["SATNUM"] == satnum, "PPCWMAX"] = ppcwmax
Expand All @@ -615,7 +615,7 @@ def merge_equil(grid_df: pd.DataFrame, equil_df: pd.DataFrame) -> pd.DataFrame:
assert "Z" in equil_df
assert "PRESSURE" in equil_df

# Be compatible with future change in ecl2df:
# Be compatible with future change in res2df:
equil_df.rename({"ACCURACY": "OIP_INIT"}, axis="columns", inplace=True)

contacts = list(set(["OWC", "GOC", "GWC"]).intersection(set(equil_df.columns)))
Expand Down
6 changes: 3 additions & 3 deletions src/subscript/interp_relperm/interp_relperm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import yaml
from configsuite import MetaKeys as MK # lgtm [py/import-and-import-from]
from configsuite import types # lgtm [py/import-and-import-from]
from ecl2df import satfunc
from res2df import satfunc

import subscript

Expand Down Expand Up @@ -397,10 +397,10 @@ def main() -> None:

logger.setLevel(logging.INFO)

# Mute expected warnings from ecl2df.inferdims, we get these
# Mute expected warnings from res2df.inferdims, we get these
# because we don't tell the module how many SATNUMs there are in
# input files, which is slightly fragile for opm to parse.
logging.getLogger("ecl2df.inferdims").setLevel(logging.ERROR)
logging.getLogger("res2df.inferdims").setLevel(logging.ERROR)

# parse the config file
if not Path(args.configfile).exists():
Expand Down
6 changes: 3 additions & 3 deletions src/subscript/presentvalue/presentvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from pathlib import Path
from typing import Dict, Optional

import ecl2df
import numpy as np
import pandas as pd
import res2df
import scipy.optimize

from subscript import __version__, getLogger
Expand Down Expand Up @@ -422,8 +422,8 @@ def get_yearly_summary(
vec.split(":")[0].endswith("T") for vec in [oilvector, gasvector, gasinjvector]
):
raise ValueError("Only cumulative Eclipse vectors can be used")
eclfiles = ecl2df.EclFiles(eclfile)
sum_df = ecl2df.summary.df(
eclfiles = res2df.ResdataFiles(eclfile)
sum_df = res2df.summary.df(
eclfiles, column_keys=[oilvector, gasvector, gasinjvector], time_index="yearly"
)
sum_df.rename(
Expand Down
6 changes: 3 additions & 3 deletions src/subscript/prtvol2csv/prtvol2csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from pathlib import Path
from typing import Optional

import ecl2df
import pandas as pd
import res2df
from fmu.tools.fipmapper.fipmapper import FipMapper

from subscript import __version__, getLogger
Expand Down Expand Up @@ -162,7 +162,7 @@ def currently_in_place_from_prt(
) -> pd.DataFrame:
"""Extracts currently-in-place volumes from a PRT file
This function uses ecl2df.fipreports, and slices its
This function uses res2df.fipreports, and slices its
output for the purpose here.
Args:
Expand All @@ -174,7 +174,7 @@ def currently_in_place_from_prt(
Returns:
pd.DataFrame
"""
inplace_df = ecl2df.fipreports.df(prt_file, fipname=fipname)
inplace_df = res2df.fipreports.df(prt_file, fipname=fipname)

available_dates = inplace_df.sort_values("DATE")["DATE"].unique()
if date is None or date == "first":
Expand Down
4 changes: 2 additions & 2 deletions src/subscript/sector2fluxnum/completions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ecl2df import EclFiles, compdat
from res2df import ResdataFiles, compdat


def get_completion_list(ecl_data_file_name):
Expand All @@ -14,7 +14,7 @@ def get_completion_list(ecl_data_file_name):
List of completions associated to well names
"""

ecl_file = EclFiles(ecl_data_file_name)
ecl_file = ResdataFiles(ecl_data_file_name)
compdat_df = compdat.df(ecl_file)

# Convert from ECL index
Expand Down
6 changes: 3 additions & 3 deletions tests/test_check_swatinit_simulators.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import time
from pathlib import Path

import ecl2df
import res2df
import numpy as np
import pandas as pd
import pytest
Expand Down Expand Up @@ -85,7 +85,7 @@ def run_reservoir_simulator(simulator, resmodel, perform_qc=True):
raise AssertionError(f"reservoir simulator failed in {os.getcwd()}")

if perform_qc:
return make_qc_gridframe(ecl2df.EclFiles("FOO.DATA"))
return make_qc_gridframe(res2df.ResdataFiles("FOO.DATA"))
return None


Expand Down Expand Up @@ -494,7 +494,7 @@ def test_swatinit_less_than_1_below_contact(simulator, tmp_path):
assert np.isclose(qc_frame["PC"], 0)
else:
# E100 will not report a PPCW in this case, libecl gives -1e20,
# which becomes a NaN through ecl2df and then NaN columns are dropped.
# which becomes a NaN through res2df and then NaN columns are dropped.
if "PPCW" in qc_frame:
assert pd.isnull(qc_frame["PPCW"][0])
if "PC_SCALING" in qc_frame:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_interp_relperm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pandas as pd
import pytest
import yaml
from ecl2df import satfunc
from res2df import satfunc
from pyscal import PyscalFactory
from pyscal.utils.testing import sat_table_str_ok

Expand Down Expand Up @@ -201,7 +201,7 @@ def test_garbled_base_input(tmp_path):

def test_parse_satfunc_files():
"""Test that tables in Eclipse format can be converted
into dataframes (using ecl2df)"""
into dataframes (using res2df)"""
swoffn = TESTDATA / "swof_base.inc"
sgoffn = TESTDATA / "sgof_base.inc"

Expand Down
8 changes: 4 additions & 4 deletions tests/test_presentvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess
from pathlib import Path

import ecl2df
import res2df
import numpy as np
import pandas as pd
import pytest
Expand Down Expand Up @@ -328,7 +328,7 @@ def test_no_gasinj(tmp_path):
)
smry["DATE"] = pd.to_datetime(smry["DATE"])
smry.set_index("DATE")
eclsum = ecl2df.summary.df2eclsum(smry, "NOGASINJ")
eclsum = res2df.summary.df2ressum(smry, "NOGASINJ")
Summary.fwrite(eclsum)
econ_df = presentvalue.prepare_econ_table(
oilprice=100, gasprice=0, usdtonok=10, discountrate=0
Expand All @@ -353,7 +353,7 @@ def test_no_gas(tmp_path):
)
smry["DATE"] = pd.to_datetime(smry["DATE"])
smry.set_index("DATE")
eclsum = ecl2df.summary.df2eclsum(smry, "NOGAS")
eclsum = res2df.summary.df2ressum(smry, "NOGAS")
Summary.fwrite(eclsum)
econ_df = presentvalue.prepare_econ_table(
oilprice=100, gasprice=0, usdtonok=10, discountrate=0
Expand All @@ -378,7 +378,7 @@ def test_no_oil(tmp_path):
)
smry["DATE"] = pd.to_datetime(smry["DATE"])
smry.set_index("DATE")
eclsum = ecl2df.summary.df2eclsum(smry, "NOOIL")
eclsum = res2df.summary.df2ressum(smry, "NOOIL")
Summary.fwrite(eclsum)
econ_df = presentvalue.prepare_econ_table(
oilprice=0, gasprice=10, usdtonok=10, discountrate=0
Expand Down

0 comments on commit 53d481b

Please sign in to comment.