From e83ae6f0330bac4f23e4350589b8b5df69b05f36 Mon Sep 17 00:00:00 2001 From: "Yngve S. Kristiansen" Date: Tue, 12 Dec 2023 08:30:22 +0100 Subject: [PATCH] Use res2df instead of ecl2df --- docs/scripts/prtvol2csv.rst | 2 +- pyproject.toml | 2 +- .../check_swatinit/check_swatinit.py | 34 +++++++++---------- .../interp_relperm/interp_relperm.py | 6 ++-- src/subscript/presentvalue/presentvalue.py | 6 ++-- src/subscript/prtvol2csv/prtvol2csv.py | 6 ++-- src/subscript/sector2fluxnum/completions.py | 4 +-- tests/test_check_swatinit_simulators.py | 6 ++-- tests/test_interp_relperm.py | 4 +-- tests/test_presentvalue.py | 8 ++--- 10 files changed, 39 insertions(+), 39 deletions(-) diff --git a/docs/scripts/prtvol2csv.rst b/docs/scripts/prtvol2csv.rst index a24fa7030..cd9c2c13f 100644 --- a/docs/scripts/prtvol2csv.rst +++ b/docs/scripts/prtvol2csv.rst @@ -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. diff --git a/pyproject.toml b/pyproject.toml index bf61616a4..9b71d8da3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,7 @@ dynamic = ["version"] dependencies = [ "configsuite", "resdata", - "ecl2df", + "res2df", "ert>=2.38.0b7", "fmu-tools", "matplotlib", diff --git a/src/subscript/check_swatinit/check_swatinit.py b/src/subscript/check_swatinit/check_swatinit.py index 8f292e057..a8a5b7656 100644 --- a/src/subscript/check_swatinit/check_swatinit.py +++ b/src/subscript/check_swatinit/check_swatinit.py @@ -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 @@ -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: @@ -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 ( @@ -212,7 +212,7 @@ 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. @@ -220,7 +220,7 @@ def make_qc_gridframe(eclfiles: ecl2df.EclFiles) -> pd.DataFrame: satfunc and equil merged in. """ - grid_df = ecl2df.grid.df( + grid_df = res2df.grid.df( eclfiles, vectors=[ # All of these are required. @@ -242,14 +242,14 @@ 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: @@ -257,7 +257,7 @@ def make_qc_gridframe(eclfiles: ecl2df.EclFiles) -> pd.DataFrame: 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: @@ -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) @@ -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 @@ -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 @@ -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))) diff --git a/src/subscript/interp_relperm/interp_relperm.py b/src/subscript/interp_relperm/interp_relperm.py index 1594d0c63..1f87b6c46 100755 --- a/src/subscript/interp_relperm/interp_relperm.py +++ b/src/subscript/interp_relperm/interp_relperm.py @@ -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 @@ -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(): diff --git a/src/subscript/presentvalue/presentvalue.py b/src/subscript/presentvalue/presentvalue.py index 4bfd6e0eb..7280f43b7 100755 --- a/src/subscript/presentvalue/presentvalue.py +++ b/src/subscript/presentvalue/presentvalue.py @@ -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 @@ -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( diff --git a/src/subscript/prtvol2csv/prtvol2csv.py b/src/subscript/prtvol2csv/prtvol2csv.py index 81757d8db..0c08c8a82 100644 --- a/src/subscript/prtvol2csv/prtvol2csv.py +++ b/src/subscript/prtvol2csv/prtvol2csv.py @@ -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 @@ -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: @@ -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": diff --git a/src/subscript/sector2fluxnum/completions.py b/src/subscript/sector2fluxnum/completions.py index d93ada8c9..f6cb8823c 100644 --- a/src/subscript/sector2fluxnum/completions.py +++ b/src/subscript/sector2fluxnum/completions.py @@ -1,4 +1,4 @@ -from ecl2df import EclFiles, compdat +from res2df import ResdataFiles, compdat def get_completion_list(ecl_data_file_name): @@ -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 diff --git a/tests/test_check_swatinit_simulators.py b/tests/test_check_swatinit_simulators.py index 89a1f993a..5d584a0d8 100644 --- a/tests/test_check_swatinit_simulators.py +++ b/tests/test_check_swatinit_simulators.py @@ -13,10 +13,10 @@ import time from pathlib import Path -import ecl2df import numpy as np import pandas as pd import pytest +import res2df from subscript.check_swatinit.check_swatinit import ( __HC_BELOW_FWL__, @@ -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 @@ -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: diff --git a/tests/test_interp_relperm.py b/tests/test_interp_relperm.py index fd10db13c..8e87a63f9 100644 --- a/tests/test_interp_relperm.py +++ b/tests/test_interp_relperm.py @@ -6,9 +6,9 @@ import pandas as pd import pytest import yaml -from ecl2df import satfunc from pyscal import PyscalFactory from pyscal.utils.testing import sat_table_str_ok +from res2df import satfunc from subscript.interp_relperm import interp_relperm @@ -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" diff --git a/tests/test_presentvalue.py b/tests/test_presentvalue.py index 6bde32b9b..c473c82c8 100644 --- a/tests/test_presentvalue.py +++ b/tests/test_presentvalue.py @@ -3,10 +3,10 @@ import subprocess from pathlib import Path -import ecl2df import numpy as np import pandas as pd import pytest +import res2df from resdata.summary import Summary from subscript.presentvalue import presentvalue @@ -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 @@ -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 @@ -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