Skip to content

Commit

Permalink
FIX: Use renamed resfo (formerly known as ecl_data_io)
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Oct 24, 2023
1 parent 48eef4d commit abe3648
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 59 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ classifiers = [
dynamic = ["version"]
dependencies = [
"deprecation",
"ecl-data-io>=2.1",
"resfo>=4.0.0",
"h5py>=3",
"hdf5plugin>=2.3",
"matplotlib>=3.3",
Expand Down
8 changes: 4 additions & 4 deletions src/xtgeo/grid3d/_egrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
flow containing the grid geometry. The layout of cell data and units is similar
to grdecl files, but there is additional metadata.
The data is layed out similarly to other ecl output files, see the ecl_data_io
The data is layed out similarly to other ecl output files, see the resfo
module.
There is an alternate data layout (in addition to that of grdecl files), called
Expand Down Expand Up @@ -66,7 +66,7 @@
)

import numpy as np
from ecl_data_io import Format, lazy_read, write
from resfo import Format, lazy_read, write

from ._ecl_grid import (
CoordinateType,
Expand Down Expand Up @@ -649,7 +649,7 @@ def to_file(self, filelike, fileformat: str = "egrid"):
write the EGrid to file.
Args:
filelike (str,Path,stream): The egrid file to write to.
file_format (ecl_data_io.Format): The format of the file.
file_format (resfo.Format): The format of the file.
"""
file_format = None
if fileformat == "egrid":
Expand Down Expand Up @@ -767,7 +767,7 @@ class EGridReader:
Args:
filelike (str, Path, stream): The egrid file to read from.
file_format (None or ecl_data_io.Format): The format of the file,
file_format (None or resfo.Format): The format of the file,
None means guess.
"""
Expand Down
18 changes: 9 additions & 9 deletions src/xtgeo/grid3d/_find_gridprop_in_eclrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from pathlib import Path
from typing import Dict, List, Optional, Union

import ecl_data_io as eclio
import numpy as np
import resfo
from typing_extensions import Literal

import xtgeo
Expand Down Expand Up @@ -96,10 +96,10 @@ def remainder_saturations(saturations):


def peek_headers(generator):
"""Reads header from a ecl_data_io keyword generator without consuming keywords.
"""Reads header from a resfo keyword generator without consuming keywords.
Args:
generator: keyword generator such as returned by ecl_data_io.lazy_read
generator: keyword generator such as returned by resfo.lazy_read
Returns:
Tuple of inthead, logihead, and a modified generator which contains all original
Expand Down Expand Up @@ -393,7 +393,7 @@ def get_actnum_from_porv(init_filelike, grid):
Returns:
None
"""
generator = filter_lgr(eclio.lazy_read(init_filelike))
generator = filter_lgr(resfo.lazy_read(init_filelike))
intehead, logihead, generator = peek_headers(generator)

if "INTERSECT" not in str(intehead.simulator):
Expand Down Expand Up @@ -459,7 +459,7 @@ def find_gridprop_from_init_file(
get_actnum_from_porv(init_filelike, grid)
if init_stream:
init_filelike.seek(orig_pos, 0)
generator = filter_lgr(eclio.lazy_read(init_filelike))
generator = filter_lgr(resfo.lazy_read(init_filelike))
intehead, logihead, generator = peek_headers(generator)

check_grid_match(intehead, logihead, grid)
Expand Down Expand Up @@ -579,7 +579,7 @@ def find_gridprops_from_restart_file(
dates: Union[List[int], Literal["all", "first", "last"]],
grid,
fracture: bool = False,
fformat: eclio.Format = eclio.Format.UNFORMATTED,
fformat: resfo.Format = resfo.Format.UNFORMATTED,
) -> List[Dict]:
"""Finds all parameters in a restart file matching the given names and dates.
Expand All @@ -599,11 +599,11 @@ def find_gridprops_from_restart_file(
"""
close = False
if isinstance(restart_filelike, (pathlib.Path, str)):
if fformat == eclio.Format.UNFORMATTED:
if fformat == resfo.Format.UNFORMATTED:
filehandle = open(restart_filelike, "rb")
close = True
assume_init_file = (str(restart_filelike)).replace(".UNRST", ".INIT")
elif fformat == eclio.Format.FORMATTED:
elif fformat == resfo.Format.FORMATTED:
filehandle = open(restart_filelike, "rt", encoding="ascii")
close = True
assume_init_file = (str(restart_filelike)).replace(".FUNRST", ".FINIT")
Expand All @@ -622,7 +622,7 @@ def find_gridprops_from_restart_file(
filehandle = restart_filelike
close = False
try:
generator = section_generator(filter_lgr(eclio.lazy_read(filehandle)))
generator = section_generator(filter_lgr(resfo.lazy_read(filehandle)))
read_properties = find_gridprops_from_restart_file_sections(
generator,
names,
Expand Down
2 changes: 1 addition & 1 deletion src/xtgeo/grid3d/_grdecl_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from typing import Optional, Tuple

import numpy as np
from ecl_data_io import Format, lazy_read, write
from resfo import Format, lazy_read, write

from ._ecl_grid import (
CoordinateType,
Expand Down
8 changes: 4 additions & 4 deletions src/xtgeo/grid3d/_gridprop_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import json
import struct

import ecl_data_io as eclio
import numpy as np
import resfo
import roffio

import xtgeo
Expand Down Expand Up @@ -81,11 +81,11 @@ def export_grdecl(self, pfile, name, append=False, binary=False, dtype=None, fmt

with open(pfile, mode) as fh:
if dtype is not None:
eclio.write(fh, [(name.ljust(8), vals.astype(dtype))])
resfo.write(fh, [(name.ljust(8), vals.astype(dtype))])
elif self.isdiscrete:
eclio.write(fh, [(name.ljust(8), vals.astype(np.int32))])
resfo.write(fh, [(name.ljust(8), vals.astype(np.int32))])
else:
eclio.write(fh, [(name.ljust(8), vals.astype(np.float32))])
resfo.write(fh, [(name.ljust(8), vals.astype(np.float32))])

else:
mode = "w"
Expand Down
10 changes: 5 additions & 5 deletions src/xtgeo/grid3d/_gridprop_import_eclrun.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List, Union

import ecl_data_io as eclio
import resfo
from typing_extensions import Literal

from ._find_gridprop_in_eclrun import (
Expand Down Expand Up @@ -87,18 +87,18 @@ def sanitize_date(
return date


def sanitize_fformat(fformat: Literal["unrst", "funrst"]) -> eclio.Format:
"""Converts 'unrst' and 'funrst' to the corresponding eclio.Format.
def sanitize_fformat(fformat: Literal["unrst", "funrst"]) -> resfo.Format:
"""Converts 'unrst' and 'funrst' to the corresponding resfo.Format.
>>> sanitize_fformat('unrst')
<Format.UNFORMATTED: 2>
>>> sanitize_fformat('funrst')
<Format.FORMATTED: 1>
"""
if fformat == "unrst":
return eclio.Format.UNFORMATTED
return resfo.Format.UNFORMATTED
if fformat == "funrst":
return eclio.Format.FORMATTED
return resfo.Format.FORMATTED
raise ValueError(f"fformat must be either 'unrst' or 'funrst' got {fformat}")


Expand Down
4 changes: 2 additions & 2 deletions src/xtgeo/grid3d/_gridprop_import_grdecl.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Importing grid props from GRDECL, ascii or binary"""


import ecl_data_io as eclio
import numpy as np
import numpy.ma as ma
import resfo

import xtgeo

Expand Down Expand Up @@ -32,7 +32,7 @@ def import_bgrdecl_prop(pfile, name, grid):
result["name"] = name
result["filesrc"] = pfile

for entry in eclio.lazy_read(pfile.file):
for entry in resfo.lazy_read(pfile.file):
if match_keyword(entry.read_keyword(), name):
values = entry.read_array()
result["discrete"] = np.issubdtype(values.dtype, np.integer)
Expand Down
26 changes: 10 additions & 16 deletions tests/test_grid3d/test_ecl_simpleb8_cases.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test basic ecl_data_io wrt to xtgeo testdata and core ecl-data-io and xtgeo usage.
"""Test basic resfo wrt to xtgeo testdata and core resfo and xtgeo usage.
Based on 'simpleb8' and ran through various simulators in 2022 by V. Kippe (Equinor):
Expand All @@ -16,9 +16,9 @@
IX_COMP_GRIDREPORT: IX compositional, with EGRID from IX
"""
import ecl_data_io as eio
import numpy as np
import pytest
import resfo

import xtgeo

Expand Down Expand Up @@ -84,13 +84,11 @@
),
],
)
def test_ecl_data_io_read_grids(
ecl_like_file, some_valid_kwords, some_notpresent_kwords
):
def test_refo_read_grids(ecl_like_file, some_valid_kwords, some_notpresent_kwords):
"""Read grid data, different simulators."""
kwords = []
ktypes = []
for item in eio.lazy_read(SIMPLEB8_PATH / ecl_like_file):
for item in resfo.lazy_read(SIMPLEB8_PATH / ecl_like_file):
kwords.append(item.read_keyword().strip())
ktypes.append(item.read_type().strip())

Expand Down Expand Up @@ -121,13 +119,11 @@ def test_ecl_data_io_read_grids(
),
],
)
def test_ecl_data_io_read_init(
ecl_like_file, some_valid_kwords, some_notpresent_kwords
):
def test_refo_read_init(ecl_like_file, some_valid_kwords, some_notpresent_kwords):
"""Read INIT data, different simulators."""
kwords = []
ktypes = []
for item in eio.lazy_read(SIMPLEB8_PATH / ecl_like_file):
for item in resfo.lazy_read(SIMPLEB8_PATH / ecl_like_file):
kwords.append(item.read_keyword().strip())
ktypes.append(item.read_type().strip())

Expand Down Expand Up @@ -163,13 +159,11 @@ def test_ecl_data_io_read_init(
),
],
)
def test_ecl_data_io_read_restart(
ecl_like_file, some_valid_kwords, some_notpresent_kwords
):
def test_refo_read_restart(ecl_like_file, some_valid_kwords, some_notpresent_kwords):
"""Read UNRST data, different simulators."""
kwords = []
ktypes = []
for item in eio.lazy_read(SIMPLEB8_PATH / ecl_like_file):
for item in resfo.lazy_read(SIMPLEB8_PATH / ecl_like_file):
kwords.append(item.read_keyword().strip())
ktypes.append(item.read_type().strip())

Expand Down Expand Up @@ -238,7 +232,7 @@ def test_egrid_init_read_xtgeo(
):
"""Test reading properties from various simulators, egrid and init.
Internally, xtgeo uses ecl_data_io for Eclipse like data
Internally, xtgeo uses refo for Eclipse like data
"""
grid = xtgeo.grid_from_file(SIMPLEB8_PATH / ecl_like_grid)
actnum = grid.get_actnum_indices()
Expand Down Expand Up @@ -315,7 +309,7 @@ def test_egrid_unrst_read_xtgeo(
):
"""Test reading properties from various simulators, egrid and unrst
Internally, xtgeo uses ecl_data_io for Eclipse like data
Internally, xtgeo uses refo for Eclipse like data
"""
grid = xtgeo.grid_from_file(SIMPLEB8_PATH / ecl_like_grid)

Expand Down
16 changes: 8 additions & 8 deletions tests/test_grid3d/test_grid_egrid.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import io
import sys

import ecl_data_io as eclio
import hypothesis.strategies as st
import numpy as np
import pytest
import resfo
from hypothesis import HealthCheck, assume, given, settings

import xtgeo as xtg
Expand Down Expand Up @@ -189,7 +189,7 @@
)
def test_bad_keywords_raises(file_contents, bad_keyword):
buf = io.BytesIO()
eclio.write(buf, file_contents)
resfo.write(buf, file_contents)
buf.seek(0)
with pytest.raises(xtge.EGridFileFormatError, match=bad_keyword):
xtge.EGrid.from_file(buf)
Expand Down Expand Up @@ -288,7 +288,7 @@ def test_grid_head_error():

def test_read_duplicate_keyword_error():
buf = io.BytesIO()
eclio.write(buf, [("FILEHEAD", np.zeros((100,), dtype=np.int32))] * 2)
resfo.write(buf, [("FILEHEAD", np.zeros((100,), dtype=np.int32))] * 2)
buf.seek(0)
reader = xtge.EGridReader(buf)

Expand All @@ -298,7 +298,7 @@ def test_read_duplicate_keyword_error():

def test_read_bad_keyword_error():
buf = io.BytesIO()
eclio.write(buf, [("NTKEYWRD", np.zeros((100,), dtype=np.int32))] * 2)
resfo.write(buf, [("NTKEYWRD", np.zeros((100,), dtype=np.int32))] * 2)
buf.seek(0)
reader = xtge.EGridReader(buf)

Expand All @@ -308,7 +308,7 @@ def test_read_bad_keyword_error():

def test_read_mixed_gridhead():
buf = io.BytesIO()
eclio.write(
resfo.write(
buf,
[
("FILEHEAD", np.zeros((100,), dtype=np.int32)),
Expand All @@ -325,7 +325,7 @@ def test_read_mixed_gridhead():

def test_read_no_endgrid():
buf = io.BytesIO()
eclio.write(
resfo.write(
buf,
[
("FILEHEAD", np.zeros((100,), dtype=np.int32)),
Expand All @@ -344,7 +344,7 @@ def test_read_no_endgrid():

def test_read_unexpected_section():
buf = io.BytesIO()
eclio.write(
resfo.write(
buf,
[
("FILEHEAD", np.zeros((100,), dtype=np.int32)),
Expand All @@ -370,7 +370,7 @@ def test_read_multiple_amalgamations():
buf = io.BytesIO()

with pytest.warns(UserWarning):
eclio.write(
resfo.write(
buf,
[
("FILEHEAD", np.zeros((100,), dtype=np.int32)),
Expand Down
Loading

0 comments on commit abe3648

Please sign in to comment.