Skip to content

Commit aae4279

Browse files
committed
BUG: Fix gridproperty unrst importing non-str date
1 parent 56a2ac9 commit aae4279

File tree

5 files changed

+49
-11
lines changed

5 files changed

+49
-11
lines changed

src/xtgeo/grid3d/_find_gridprop_in_eclrun.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import operator
44
import pathlib
55
import warnings
6-
from typing import Dict, List, Union
6+
from typing import Dict, List, Optional, Union
77

88
import ecl_data_io as eclio
99
import numpy as np
@@ -349,7 +349,7 @@ def make_gridprop_values(values, grid, fracture):
349349
return np.ma.masked_where(grid.get_actnum().values < 1, values)
350350

351351

352-
def date_from_intehead(intehead):
352+
def date_from_intehead(intehead: InteHead) -> Optional[int]:
353353
"""Returns date format for use in GridProperty name given intehead."""
354354
if any(val is None for val in [intehead.day, intehead.month, intehead.year]):
355355
return None
@@ -360,7 +360,7 @@ def gridprop_params(values, name, date, grid, fracture):
360360
"""Make dictionary of GridProperty parameters from imported values."""
361361
result = dict()
362362
result["name"] = name
363-
result["date"] = date
363+
result["date"] = str(date) if date is not None else None
364364
result["fracture"] = fracture
365365

366366
result["ncol"], result["nrow"], result["nlay"] = grid.dimensions

src/xtgeo/grid3d/grid_property.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,12 +656,12 @@ def roxar_dtype(self, dtype):
656656
)
657657

658658
@property
659-
def date(self):
660-
"""Returns or rename the property date on YYYYMMDD numerical format."""
659+
def date(self) -> Optional[str]:
660+
"""Returns or rename the property date as string on YYYYMMDD format."""
661661
return self._date
662662

663663
@date.setter
664-
def date(self, date):
664+
def date(self, date: Optional[str]):
665665
self._date = date
666666

667667
@property

tests/test_grid3d/test_eclrun.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ def test_roundtrip_satnum(fformat, tmp_path, ecl_runs):
8080

8181
def test_first_and_last_dates(ecl_runs):
8282
po = ecl_runs.get_property_from_restart("PRESSURE", date="first")
83-
assert po.date == min(ecl_runs.expected_dates)
83+
assert int(po.date) == min(ecl_runs.expected_dates)
8484

8585
px = ecl_runs.get_property_from_restart("PRESSURE", date="last")
86-
assert px.date == max(ecl_runs.expected_dates)
86+
assert int(px.date) == max(ecl_runs.expected_dates)
8787

8888

8989
def test_dual_runs_general_grid(tmpdir, dual_runs):

tests/test_grid3d/test_gridprop_import_eclrun.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,44 @@ def test_pick_dualporo_values():
243243
)
244244

245245

246+
@pytest.mark.parametrize("discrete, dtype", [(True, np.int32), (False, np.float64)])
247+
def test_gridprop_params(discrete, dtype):
248+
grid = xtgeo.create_box_grid((2, 5, 1))
249+
params = xtg_im_ecl.gridprop_params(
250+
values=np.zeros(10, dtype=dtype),
251+
name="myprop",
252+
date=19991231,
253+
grid=grid,
254+
fracture=False,
255+
)
256+
257+
assert params["name"] == "myprop"
258+
assert params["date"] == "19991231"
259+
assert params["dualporo"] == grid.dualporo
260+
assert params["dualperm"] == grid.dualperm
261+
assert params["discrete"] is discrete
262+
assert params["values"].shape == (2, 5, 1)
263+
264+
265+
@pytest.mark.parametrize("discrete, dtype", [(True, np.int32), (False, np.float64)])
266+
def test_gridprop_params_no_date(discrete, dtype):
267+
grid = xtgeo.create_box_grid((2, 5, 1))
268+
params = xtg_im_ecl.gridprop_params(
269+
values=np.zeros(10, dtype=dtype),
270+
name="myprop",
271+
grid=grid,
272+
fracture=False,
273+
date=None,
274+
)
275+
276+
assert params["name"] == "myprop"
277+
assert date not in params
278+
assert params["dualporo"] == grid.dualporo
279+
assert params["dualperm"] == grid.dualperm
280+
assert params["discrete"] is discrete
281+
assert params["values"].shape == (2, 5, 1)
282+
283+
246284
def test_match_dualporo():
247285
grid = xtgeo.Grid()
248286
grid._dualporo = True
@@ -442,7 +480,7 @@ def test_gridprop_unrst_date_correct(ecl_run, use_alterate_date_form, use_first)
442480
)
443481

444482
assert gridprop.name == ecl_run.property_name + "_" + str(ecl_run.xtgeo_step_date)
445-
assert gridprop.date == ecl_run.xtgeo_step_date
483+
assert int(gridprop.date) == ecl_run.xtgeo_step_date
446484

447485

448486
@settings(deadline=None, suppress_health_check=[HealthCheck.function_scoped_fixture])

tests/test_opm_integration/test_gridprop_io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def test_init_props_reading(case):
242242
)
243243

244244
np.testing.assert_allclose(poro.values, case.poro)
245-
assert poro.date == 20000101
245+
assert poro.date == "20000101"
246246

247247

248248
@pytest.mark.requires_opm
@@ -261,4 +261,4 @@ def test_restart_prop_reading(case):
261261
)
262262

263263
assert pressure.name == "PRESSURE_20010101"
264-
assert pressure.date == 20010101
264+
assert pressure.date == "20010101"

0 commit comments

Comments
 (0)