equinor / equinor/xtgeo

Using create_box with negative increment crashes

Open
#508 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
122
Forks
67
Avg merge
1d 20h
Merged PRs (30d)
19

Description

`create_box` with negative increment seemingly creates a valid grid and writes it to file, but
the resulting file crashes with nonrecoverable critical error in `from_file`.

```python
from xtgeo import Grid, grid_from_file, create_box_grid

def test_negative_increment_create_box(tmp_path):
g = create_box_grid(dimension=(5,5,5), increment=(-1, 1, 1))
```

Results in the following error:

```
def test_negative_increment_create_box(tmp_path):
> g = create_box_grid(dimension=(5,5,5), increment=(-1, 1, 1))

test.py:4:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.../xtgeo/grid3d/grid.py:197: in create_box_grid
kwargs = _grid_etc1.create_box(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

dimension = (5, 5, 5), origin = (0.0, 0.0, 0.0), oricenter = False, increment = (-1, 1, 1), rotation = 0.0, flip = 1

def create_box(
dimension: Dimensions,
origin: tuple[float, float, float],
oricenter: bool,
increment: tuple[int, int, int],
rotation: float,
flip: Literal[1, -1],
) -> dict[str, np.ndarray]:
"""Create a shoebox grid from cubi'sh spec, xtgformat=2."""
ncol, nrow, nlay = dimension
nncol = ncol + 1
nnrow = nrow + 1
nnlay = nlay + 1

coordsv = np.zeros((nncol, nnrow, 6), dtype=np.float64)
zcornsv = np.zeros((nncol, nnrow, nnlay, 4), dtype=np.float32)
actnumsv = np.zeros((ncol, nrow, nlay), dtype=np.int32)

option = 0 if not oricenter else 1

> _cxtgeo.grdcp3d_from_cube(
ncol,
nrow,
nlay,
coordsv,
zcornsv,
actnumsv,
origin[0],
origin[1],
origin[2],
increment[0],
increment[1],
increment[2],
rotation,
flip,
option,
)
E _cxtgeo.XTGeoCLibError: Bug in: grdcp3d_from_cube

.../xtgeo/grid3d/_grid_etc1.py:55: XTGeoCLibError
```

Contributor guide

Open the contributing guide

Research direction

Start at xtgeo/grid3d/grid.py and xtgeo/grid3d/_grid_etc1.py, following create_box_grid into _cxtgeo.grdcp3d_from_cube. Reproduce the negative-increment case, then check that the generated grid can be written and read through from_file without a nonrecoverable error. Done means negative increments no longer crash this workflow.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.