Skip to content

Commit

Permalink
Replace ecl with resdata
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSava committed Nov 15, 2023
1 parent e4bad26 commit 5428b3e
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 91 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ classifiers = [
dynamic = ["version"]
dependencies = [
"configsuite",
"ecl",
"resdata",
"ecl2df",
"ert>=2.38.0b7",
"fmu-tools",
Expand Down
30 changes: 15 additions & 15 deletions src/subscript/co2_containment/co2_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import numpy as np
import xtgeo
from ecl.eclfile import EclFile
from ecl.grid import EclGrid
from resdata.grid import Grid
from resdata.resfile import ResdataFile

DEFAULT_CO2_MOLAR_MASS = 44.0
DEFAULT_WATER_MOLAR_MASS = 18.0
Expand Down Expand Up @@ -235,12 +235,12 @@ class Co2Data:
zone: Optional[np.ndarray] = None


def _try_prop(unrst: EclFile, prop_name: str):
def _try_prop(unrst: ResdataFile, prop_name: str):
"""
Function to determine if a property (prop_name) is part of an EclFile (unrst)
Function to determine if a property (prop_name) is part of an ResdataFile (unrst)
Args:
unrst (EclFile): EclFile to fetch property names from
unrst (ResdataFile): ResdataFile to fetch property names from
prop_name (str): The property name to be searched in unrst
Returns:
Expand All @@ -255,14 +255,14 @@ def _try_prop(unrst: EclFile, prop_name: str):


def _read_props(
unrst: EclFile,
unrst: ResdataFile,
prop_names: List,
) -> dict:
"""
Reads the properties in prop_names from an EclFile named unrst
Reads the properties in prop_names from an ResdataFile named unrst
Args:
unrst (EclFile): EclFile to read prop_names from
unrst (ResdataFile): ResdataFile to read prop_names from
prop_names (List): List with property names to be read
Returns:
Expand All @@ -275,14 +275,14 @@ def _read_props(


def _fetch_properties(
unrst: EclFile, properties_to_extract: List
unrst: ResdataFile, properties_to_extract: List
) -> Tuple[Dict[str, Dict[str, List[np.ndarray]]], List[str]]:
"""
Fetches the properties in properties_to_extract from an EclFile
Fetches the properties in properties_to_extract from an ResdataFile
named unrst
Args:
unrst (EclFile): EclFile to fetch properties_to_extract from
unrst (ResdataFile): ResdataFile to fetch properties_to_extract from
properties_to_extract: List with property names to be fetched
Returns:
Expand Down Expand Up @@ -362,7 +362,7 @@ def _extract_source_data(
) -> SourceData:
# pylint: disable-msg=too-many-locals
"""
Extracts the properties in properties_to_extract from EclGrid files
Extracts the properties in properties_to_extract from Grid files
Args:
grid_file (str): Path to EGRID-file
Expand All @@ -376,9 +376,9 @@ def _extract_source_data(
"""
print("Start extracting source data")
grid = EclGrid(grid_file)
unrst = EclFile(unrst_file)
init = EclFile(init_file)
grid = Grid(grid_file)
unrst = ResdataFile(unrst_file)
init = ResdataFile(init_file)
properties, dates = _fetch_properties(unrst, properties_to_extract)
print("Done fetching properties")

Expand Down
26 changes: 13 additions & 13 deletions src/subscript/restartthinner/restartthinner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import numpy
import pandas
from ecl.eclfile import EclFile
from resdata.resfile import ResdataFile

from subscript import __version__

Expand All @@ -26,8 +26,8 @@
"""


def find_libecl_app(toolname: str) -> str:
"""Locate path of apps in libecl.
def find_resdata_app(toolname: str) -> str:
"""Locate path of apps in resdata.
These have varying suffixes due through the history of libecl Makefiles.
Expand Down Expand Up @@ -61,10 +61,10 @@ def date_slicer(slicedates: list, restartdates: list, restartindices: list) -> d
return slicedatemap


def ecl_repacker(rstfilename: str, slicerstindices: list, quiet: bool) -> None:
def rd_repacker(rstfilename: str, slicerstindices: list, quiet: bool) -> None:
"""
Wrapper for ecl_unpack.x and ecl_pack.x utilities. These
utilities are from libecl.
utilities are from resdata.
First unpacking a UNRST file, then deleting dates the dont't want, then
pack the remainding files into a new UNRST file
Expand All @@ -79,11 +79,11 @@ def ecl_repacker(rstfilename: str, slicerstindices: list, quiet: bool) -> None:
out = ""
# Error early if libecl tools are not available
try:
find_libecl_app("ecl_unpack")
find_libecl_app("ecl_pack")
find_resdata_app("rd_unpack")
find_resdata_app("rd_pack")
except IOError:
sys.exit(
"ERROR: ecl_unpack.x and/or ecl_pack.x not found.\n"
"ERROR: rd_unpack.x and/or rd_pack.x not found.\n"
"These tools are required and must be installed separately"
)

Expand All @@ -99,13 +99,13 @@ def ecl_repacker(rstfilename: str, slicerstindices: list, quiet: bool) -> None:
)
os.chdir(tempdir)
os.system(
find_libecl_app("ecl_unpack") + " " + os.path.basename(rstfilename) + out
find_resdata_app("rd_unpack") + " " + os.path.basename(rstfilename) + out
)
unpackedfiles = glob.glob("*.X*")
for file in unpackedfiles:
if int(file.split(".X")[1]) not in slicerstindices:
os.remove(file)
os.system(find_libecl_app("ecl_pack") + " *.X*" + out)
os.system(find_resdata_app("rd_pack") + " *.X*" + out)
# We are inside the tmp directory, move file one step up:
os.rename(
os.path.join(os.getcwd(), os.path.basename(rstfilename)),
Expand All @@ -120,7 +120,7 @@ def get_restart_indices(rstfilename: str) -> list:
"""Extract a list of RST indices for a filename"""
if Path(rstfilename).exists():
# This function segfaults if file does not exist
return EclFile.file_report_list(str(rstfilename))
return ResdataFile.file_report_list(str(rstfilename))
raise FileNotFoundError(f"{rstfilename} not found")


Expand All @@ -134,7 +134,7 @@ def restartthinner(
"""
Thin an existing UNRST file to selected number of restarts.
"""
rst = EclFile(filename)
rst = ResdataFile(filename)
restart_indices = get_restart_indices(filename)
restart_dates = [
rst.iget_restart_sim_time(index) for index in range(0, len(restart_indices))
Expand Down Expand Up @@ -177,7 +177,7 @@ def restartthinner(
if not quiet:
print(f"Info: Backing up {filename} to {backupname}")
shutil.copyfile(filename, backupname)
ecl_repacker(filename, slicerstindices, quiet)
rd_repacker(filename, slicerstindices, quiet)
print(f"Written to {filename}")


Expand Down
28 changes: 14 additions & 14 deletions src/subscript/sector2fluxnum/flux_obj.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
import sys

from ecl import EclDataType
from ecl.eclfile import EclKW
from ecl.grid import EclRegion
from resdata import ResDataType
from resdata.grid import ResdataRegion
from resdata.resfile import ResdataKW

from subscript.sector2fluxnum import flux_util

Expand All @@ -20,9 +20,9 @@ def __init__(self, grid):
Creates a non-initialized FLUXNUM keyword
"""
int_type = EclDataType.ECL_INT
int_type = ResDataType.RD_INT
self.grid = grid
self.fluxnum_kw = EclKW("FLUXNUM", grid.getGlobalSize(), int_type)
self.fluxnum_kw = ResdataKW("FLUXNUM", grid.getGlobalSize(), int_type)
self.included_wells = []
self.dummy_lgr_cell = []
self.dummy_lgr_well = []
Expand All @@ -44,7 +44,7 @@ def set_inner_region(self):
Initializes inner region used to define the FLUXNUM
"""
self.inner_region = EclRegion(self.grid, False)
self.inner_region = ResdataRegion(self.grid, False)
self.inner_region.select_all()

def set_lgr_box_region(self, i, j, k):
Expand All @@ -54,7 +54,7 @@ def set_lgr_box_region(self, i, j, k):
Only works for Box regions
"""
self.lgr_region = EclRegion(self.grid, False)
self.lgr_region = ResdataRegion(self.grid, False)
ijk_list = flux_util.unpack_ijk(i, j, k)

# Drags lgr boundaries one cell from box region
Expand Down Expand Up @@ -91,11 +91,11 @@ def set_fluxnum_kw_from_file(self, fluxnum_file):
print("ERROR: FLUXNUM input file not found!")
sys.exit(1)

int_type = EclDataType.ECL_INT
int_type = ResDataType.RD_INT

with open(fluxnum_file, "r", encoding="utf8") as file_handle:
self.fluxnum_kw = EclKW.read_grdecl(
file_handle, "FLUXNUM", ecl_type=int_type
self.fluxnum_kw = ResdataKW.read_grdecl(
file_handle, "FLUXNUM", rd_type=int_type
)

def get_fluxnum_kw(self):
Expand Down Expand Up @@ -203,11 +203,11 @@ def __init__(self, grid, i_start, i_end, j_start, j_end, k_start=0, k_end=0):
self.set_outer_region(i_start, i_end, j_start, j_end, k_start, k_end)

def set_inner_region(self, i_start, i_end, j_start, j_end, k_start, k_end):
self.inner_region = EclRegion(self.grid, False)
self.inner_region = ResdataRegion(self.grid, False)
self.inner_region.select_box((i_start, j_start, k_start), (i_end, j_end, k_end))

def set_outer_region(self, i_start, i_end, j_start, j_end, k_start, k_end):
self.outer_region = EclRegion(self.grid, False)
self.outer_region = ResdataRegion(self.grid, False)
self.outer_region.select_box((i_start, j_start, k_start), (i_end, j_end, k_end))
self.outer_region.invert()

Expand Down Expand Up @@ -247,8 +247,8 @@ def set_inner_region(self, i, j, k, fipnum_region, fipnum_file):
raise Exception("ERROR: FIPNUM input file not found!")

with open(fipnum_file, "r", encoding="utf8") as file_handle:
fipnum = EclKW.read_grdecl(
file_handle, "FIPNUM", ecl_type=EclDataType.ECL_INT
fipnum = ResdataKW.read_grdecl(
file_handle, "FIPNUM", rd_type=ResDataType.RD_INT
)

else:
Expand Down
14 changes: 7 additions & 7 deletions src/subscript/sector2fluxnum/flux_util.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from ecl.grid import EclRegion
from resdata.grid import ResdataRegion


def filter_region(
grid, idx_i, idx_j, idx_k, fipnum, fipnum_kw, combine_operator="intersect"
):
# Filter out the selected grid cells
region = EclRegion(grid, False)
region1 = EclRegion(grid, False)
region_i = EclRegion(grid, False)
region_j = EclRegion(grid, False)
region_k = EclRegion(grid, False)
region_fip = EclRegion(grid, False)
region = ResdataRegion(grid, False)
region1 = ResdataRegion(grid, False)
region_i = ResdataRegion(grid, False)
region_j = ResdataRegion(grid, False)
region_k = ResdataRegion(grid, False)
region_fip = ResdataRegion(grid, False)

# Create selected regions for each filter type
if idx_i:
Expand Down
26 changes: 13 additions & 13 deletions src/subscript/sector2fluxnum/sector2fluxnum.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import os

import cwrap
from ecl.eclfile import EclFile, FortIO
from ecl.grid import EclGrid
from resdata.grid import Grid
from resdata.resfile import FortIO, ResdataFile

from subscript.sector2fluxnum import completions, datafile_obj, flux_obj, fluxfile_obj

Expand Down Expand Up @@ -105,11 +105,11 @@ def sector_to_fluxnum(args):
print("Reading grid ...")
if args.egrid:
args.egrid = os.path.abspath(args.egrid).split(".")[0:1]
grid = EclGrid(f"{args.egrid[0]}.EGRID")
grid = Grid(f"{args.egrid[0]}.EGRID")
else:
grid = EclGrid(f"{args.ECLIPSE_CASE[0]}.EGRID")
grid = Grid(f"{args.ECLIPSE_CASE[0]}.EGRID")

init = EclFile(f"{args.ECLIPSE_CASE[0]}.INIT")
init = ResdataFile(f"{args.ECLIPSE_CASE[0]}.INIT")

# Finding well completions
completion_list, well_list = completions.get_completion_list(
Expand Down Expand Up @@ -170,9 +170,9 @@ def sector_to_fluxnum(args):
# Needs the coordinates from the
print("Generating new FLUX file...")

grid_coarse = EclGrid(f"{args.test[0]}.EGRID")
grid_fine = EclGrid(f"{args.test[0]}.EGRID")
flux_fine = EclFile(f"{args.test[0]}.FLUX")
grid_coarse = Grid(f"{args.test[0]}.EGRID")
grid_fine = Grid(f"{args.test[0]}.EGRID")
flux_fine = ResdataFile(f"{args.test[0]}.FLUX")

else:
print("Executing DUMPFLUX NOSIM run ...")
Expand All @@ -187,15 +187,15 @@ def sector_to_fluxnum(args):
# Needs the coordinates from the
print("Generating new FLUX file...")

grid_coarse = EclGrid(f"DUMPFLUX_{eclipse_case_root}.EGRID")
grid_fine = EclGrid(f"DUMPFLUX_{eclipse_case_root}.EGRID")
flux_fine = EclFile(f"DUMPFLUX_{eclipse_case_root}.FLUX")
grid_coarse = Grid(f"DUMPFLUX_{eclipse_case_root}.EGRID")
grid_fine = Grid(f"DUMPFLUX_{eclipse_case_root}.EGRID")
flux_fine = ResdataFile(f"DUMPFLUX_{eclipse_case_root}.FLUX")

# Reads restart file
if args.restart:
rst_coarse = EclFile(f"{args.restart[0]}.UNRST")
rst_coarse = ResdataFile(f"{args.restart[0]}.UNRST")
else:
rst_coarse = EclFile(f"{args.ECLIPSE_CASE[0]}.UNRST")
rst_coarse = ResdataFile(f"{args.ECLIPSE_CASE[0]}.UNRST")

flux_object_fine = fluxfile_obj.Fluxfile(grid_fine, flux_fine)

Expand Down
Loading

0 comments on commit 5428b3e

Please sign in to comment.