Skip to content

Commit

Permalink
BUG: undef values in grdecl export shall be 0 or 1
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrivenaes committed Dec 5, 2024
1 parent 839503b commit 28f6930
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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

0 comments on commit 28f6930

Please sign in to comment.