equinor / xtgeo

XTGeo Python class library for subsurface Surfaces, Cubes, Wells, Grids, Points, etc
https://xtgeo.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
109 stars 57 forks source link

Using create_box with negative increment crashes #508

Open eivindjahren opened 3 years ago

eivindjahren commented 3 years ago

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.

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