Skip to content

Commit

Permalink
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 1b858eb commit 222eb48
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ignore_missing_imports = True
[mypy-ecl.*]
ignore_missing_imports = True

[mypy-ecl_data_io.*]
[mypy-resfo.*]
ignore_missing_imports = True

[mypy-sortedcontainers.*]
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ dependencies=[
"pyyaml",
"qtpy",
"requests",
"resfo",
"scipy >= 1.10.1",
"sqlalchemy",
"uvicorn >= 0.17.0",
Expand All @@ -95,7 +96,6 @@ Repository = "https://github.com/equinor/ert"
dev = [
"click",
"decorator",
"ecl_data_io",
"furo",
"flaky",
"hypothesis<=6.83.0; python_version=='3.8'", # ipython pinned to 8.12.2 for python 3.8 support
Expand All @@ -116,6 +116,7 @@ dev = [
"pytest-xdist",
"pytest>6",
"requests",
"resfo",
"scikit-build",
"setuptools_scm",
"sortedcontainers",
Expand Down
6 changes: 3 additions & 3 deletions src/ert/field_utils/field_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, List, NamedTuple, Optional, Tuple, Union

import ecl_data_io
import numpy as np
import resfo

from .field_file_format import ROFF_FORMATS, FieldFileFormat
from .grdecl_io import export_grdecl, import_bgrdecl, import_grdecl
Expand Down Expand Up @@ -46,7 +46,7 @@ def read_mask(
actnum = None
actnum_coords: List[Tuple[int, int, int]] = []
with open(grid_path, "rb") as f:
for entry in ecl_data_io.lazy_read(f):
for entry in resfo.lazy_read(f):
if actnum is not None and shape is not None:
break

Expand Down Expand Up @@ -88,7 +88,7 @@ def get_shape(
) -> Optional[Shape]:
shape = None
with open(grid_path, "rb") as f:
for entry in ecl_data_io.lazy_read(f):
for entry in resfo.lazy_read(f):
keyword = str(entry.read_keyword()).strip()
if keyword == "GRIDHEAD":
arr = entry.read_array()
Expand Down
8 changes: 4 additions & 4 deletions src/ert/field_utils/grdecl_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from contextlib import contextmanager
from typing import Any, Iterator, List, TextIO, Tuple, Union

import ecl_data_io
import numpy as np
import numpy.typing as npt
import resfo


def _split_line(line: str) -> Iterator[str]:
Expand Down Expand Up @@ -196,11 +196,11 @@ def import_bgrdecl(
) -> npt.NDArray[np.float32]:
field_name = field_name.strip()
with open(file_path, "rb") as f:
for entry in ecl_data_io.lazy_read(f):
for entry in resfo.lazy_read(f):
keyword = str(entry.read_keyword()).strip()
if keyword == field_name:
values = entry.read_array()
if not isinstance(values, np.ndarray) and values == ecl_data_io.MESS:
if not isinstance(values, np.ndarray) and values == resfo.MESS:
raise ValueError(
f"{field_name} in {file_path} has MESS type"
" and not a real valued field"
Expand Down Expand Up @@ -231,7 +231,7 @@ def export_grdecl(
values = values.filled(np.nan) # type: ignore

if binary:
ecl_data_io.write(file_path, [(param_name.ljust(8), values.astype(np.float32))])
resfo.write(file_path, [(param_name.ljust(8), values.astype(np.float32))])
else:
with open(file_path, "w", encoding="utf-8") as fh:
fh.write(param_name + "\n")
Expand Down
10 changes: 5 additions & 5 deletions test-data/poly_template/poly_eval.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import datetime
import json
import os

import ecl_data_io as eclio
import resfo
import numpy as np
from ecl.summary import EclSum

Expand All @@ -29,7 +29,7 @@ def write_summary_spec(file, restarts, keywords):
("UNITS ", [f"{x: <8}" for x in ["DAYS"] + ["None"] * len(keywords)]),
("STARTDAT", [1, 1, 2010, 0, 0, 0]),
]
eclio.write(file, content)
resfo.write(file, content)


def write_summary_data(file, x_size, keywords, coeffs, update_steps):
Expand All @@ -48,7 +48,7 @@ def write_summary_data(file, x_size, keywords, coeffs, update_steps):
yield "MINISTEP", [step]
yield "PARAMS ", np.array([day] + values, dtype=np.float32)

eclio.write(file, content_generator())
resfo.write(file, content_generator())


def make_summary(count, x_size, coeffs, update_steps):
Expand All @@ -58,9 +58,9 @@ def make_summary(count, x_size, coeffs, update_steps):
if not os.path.exists("summary"):
os.mkdir("summary")

use_ecl_data_io = True
use_resfo = True

if use_ecl_data_io:
if use_resfo:
keywords = [f"PSUM{s}" for s in range(count)]
write_summary_spec("summary/POLY_SUMMARY.SMSPEC", x_size, keywords)
write_summary_data(
Expand Down
10 changes: 5 additions & 5 deletions tests/performance_tests/performance_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import sys
import tempfile

import ecl_data_io as eclio
import numpy
import py
import resfo
from ecl.summary import EclSum
from jinja2 import Environment, FileSystemLoader
from numpy import array
Expand All @@ -26,7 +26,7 @@ def write_summary_spec(file, keywords):
("UNITS ", [f"{x: <8}" for x in ["DAYS"] + ["None"] * len(keywords)]),
("STARTDAT", array([1, 1, 2010, 0, 0, 0], dtype=numpy.int32)),
]
eclio.write(file, content)
resfo.write(file, content)


def write_summary_data(file, x_size, keywords, update_steps):
Expand All @@ -42,7 +42,7 @@ def content_generator():
yield "MINISTEP", array([step], dtype=numpy.int32)
yield "PARAMS ", array([day] + values, dtype=numpy.float32)

eclio.write(file, content_generator())
resfo.write(file, content_generator())


def render_template(folder, template, target, **kwargs):
Expand Down Expand Up @@ -85,9 +85,9 @@ def make_poly_example(folder, source, **kwargs):
if not os.path.exists(folder / "refcase"):
os.mkdir(folder / "refcase")

use_ecl_data_io = True
use_resfo = True

if use_ecl_data_io:
if use_resfo:
keywords = [f"PSUM{s}" for s in range(summary_count)]
write_summary_spec(str(folder) + "/refcase/REFCASE.SMSPEC", keywords)
write_summary_data(
Expand Down
5 changes: 2 additions & 3 deletions tests/unit_tests/config/egrid_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from enum import Enum, auto, unique
from typing import Any, List, Optional, Tuple

import ecl_data_io as eclio
import hypothesis.strategies as st
import numpy as np
import resfo
from hypothesis.extra.numpy import arrays


Expand Down Expand Up @@ -275,12 +275,11 @@ def to_file(
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.
"""
contents = []
contents.append(("FILEHEAD", self.file_head.to_ecl()))
contents += self.global_grid.to_ecl()
eclio.write(filelike, contents)
resfo.write(filelike, contents)


finites = st.floats(
Expand Down
14 changes: 5 additions & 9 deletions tests/unit_tests/config/summary_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from enum import Enum, unique
from typing import Any, List, Tuple

import ecl_data_io
import hypothesis.strategies as st
import numpy as np
import resfo
from hypothesis.extra.numpy import from_dtype
from pydantic import PositiveInt, conint

Expand Down Expand Up @@ -148,10 +148,8 @@ def to_ecl(self) -> List[Tuple[str, Any]]:
("STARTDAT", np.array(self.start_date.to_ecl(), dtype=np.int32)),
]

def to_file(
self, filelike, file_format: ecl_data_io.Format = ecl_data_io.Format.UNFORMATTED
):
ecl_data_io.write(filelike, self.to_ecl(), file_format)
def to_file(self, filelike, file_format: resfo.Format = resfo.Format.UNFORMATTED):
resfo.write(filelike, self.to_ecl(), file_format)


positives = from_dtype(np.dtype(np.int32), min_value=1, max_value=10000)
Expand Down Expand Up @@ -235,10 +233,8 @@ def to_ecl(self):
a = [i for step in self.steps for i in step.to_ecl()]
return a

def to_file(
self, filelike, file_format: ecl_data_io.Format = ecl_data_io.Format.UNFORMATTED
):
ecl_data_io.write(filelike, self.to_ecl(), file_format)
def to_file(self, filelike, file_format: resfo.Format = resfo.Format.UNFORMATTED):
resfo.write(filelike, self.to_ecl(), file_format)


positive_floats = from_dtype(
Expand Down
8 changes: 4 additions & 4 deletions tests/unit_tests/field_utils/test_grdecl_io.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from string import ascii_letters

import ecl_data_io
import hypothesis.strategies as st
import numpy as np
import pytest
import resfo
from hypothesis import HealthCheck, given, settings
from hypothesis.extra.numpy import array_shapes, arrays
from numpy.testing import assert_allclose
Expand All @@ -12,13 +12,13 @@


def test_that_importing_mess_from_bgrdecl_raises_field_io_error(tmp_path):
ecl_data_io.write(tmp_path / "test.bgrdecl", [("FOPR ", ecl_data_io.MESS)])
resfo.write(tmp_path / "test.bgrdecl", [("FOPR ", resfo.MESS)])
with pytest.raises(ValueError, match="FOPR in .* has MESS type"):
import_bgrdecl(tmp_path / "test.bgrdecl", "FOPR ", (1, 1, 1))


def test_that_importing_discrete_from_bgrdecl_raises_field_io_error(tmp_path):
ecl_data_io.write(
resfo.write(
tmp_path / "test.bgrdecl", [("FOPR ", np.array([1, 2, 3], dtype=np.int32))]
)
with pytest.raises(
Expand Down Expand Up @@ -46,7 +46,7 @@ def test_that_importing_unterminated_grdecl_fails(tmp_path):


def test_that_importing_missing_keyword_in_bgrdecl_fails(tmp_path):
ecl_data_io.write(tmp_path / "test.bgrdecl", [("NOTTHIS ", ecl_data_io.MESS)])
resfo.write(tmp_path / "test.bgrdecl", [("NOTTHIS ", resfo.MESS)])
with pytest.raises(ValueError, match="Did not find field parameter FOPR"):
import_bgrdecl(tmp_path / "test.bgrdecl", "FOPR ", (1, 1, 1))

Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/storage/test_parameter_sample_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,13 +813,13 @@ def create_poly_with_field(field_dim: Tuple[int, int, int], realisations: int):
f"""#!/usr/bin/env python
import numpy as np
import os
import ecl_data_io
import resfo
if __name__ == "__main__":
if not os.path.exists("my_param.bgrdecl"):
values = np.random.standard_normal({grid_size})
ecl_data_io.write("my_param.bgrdecl", [("MY_PARAM", values)])
datas = ecl_data_io.read("my_param.bgrdecl")
resfo.write("my_param.bgrdecl", [("MY_PARAM", values)])
datas = resfo.read("my_param.bgrdecl")
assert datas[0][0] == "MY_PARAM"
a,b,c,*_ = datas[0][1]
Expand Down

0 comments on commit 222eb48

Please sign in to comment.