From 1af8dbbc2059cd78621a84aa220688ecc471b007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20C=2E=20Riven=C3=A6s?= Date: Thu, 5 Dec 2024 14:14:34 +0100 Subject: [PATCH] BUG: undef values in grdecl export shall be 0 or 1 --- src/xtgeo/grid3d/_gridprop_export.py | 3 ++- tests/test_grid3d/test_grid_property.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/xtgeo/grid3d/_gridprop_export.py b/src/xtgeo/grid3d/_gridprop_export.py index 882d957eb..08c474cba 100644 --- a/src/xtgeo/grid3d/_gridprop_export.py +++ b/src/xtgeo/grid3d/_gridprop_export.py @@ -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: diff --git a/tests/test_grid3d/test_grid_property.py b/tests/test_grid3d/test_grid_property.py index 881db74f5..02d1e1358 100644 --- a/tests/test_grid3d/test_grid_property.py +++ b/tests/test_grid3d/test_grid_property.py @@ -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):