Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: undef values in grdecl export shall be 0 or 1 #1280

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/xtgeo/grid3d/_gridprop_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def _export_grdecl(
"""Export ascii or binary GRDECL"""
vals = gridprop.values.ravel(order="F")
if np.ma.isMaskedArray(vals):
vals = np.ma.filled(vals, gridprop.undef)
undef_export = 1 if gridprop.isdiscrete or "int" in str(dtype) else 0.0
vals = np.ma.filled(vals, fill_value=undef_export)

mode = "a" if append else "w"
if binary:
Expand Down
19 changes: 19 additions & 0 deletions tests/test_grid3d/test_grid_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,25 @@ def test_eclinit_simple_importexport(tmp_path, testdata_path):

p2 = xtgeo.gridproperty_from_file(tmp_path / "simple.grdecl", grid=gg, name="PORO2")
assert p2.name == "PORO2"
with open(tmp_path / "simple.grdecl") as f:
fields = f.read().split()
assert len(fields) == 17
assert fields[3] == "0.00000" # undef cell

# mark as discrete
po.values = 33
po.isdiscrete = True
po.to_file(
tmp_path / "simple_disc.grdecl",
fformat="grdecl",
dtype=np.int32,
name="SOMEDISK",
fmt="%12d",
)
with open(tmp_path / "simple_disc.grdecl") as f:
fields = f.read().split()
assert len(fields) == 17
assert fields[3] == "1" # undef cell for discrete


def test_grdecl_import_reek(tmp_path, testdata_path):
Expand Down
Loading