Esempio n. 1
0
def test_not_a_grid(roff_grid):
    buff = io.BytesIO()
    roff_grid.to_file(buff)
    buff.seek(0)
    values = roffio.read(buff)
    values["filedata"]["filetype"] = "notgrid"
    buff.seek(0)
    roffio.write(buff, values)
    buff.seek(0)
    with pytest.raises(ValueError, match="did not have filetype set to grid"):
        RoffGrid.from_file(buff)
Esempio n. 2
0
def roff_grids(draw, dim=dimensions):
    dims = draw(dim)
    corner_size = (dims[0] + 1) * (dims[1] + 1) * 6
    corner_lines = draw(
        arrays(
            shape=corner_size,
            dtype=np.float32,
            elements=finites,
        ))
    num_nodes = (dims[0] + 1) * (dims[1] + 1) * (dims[2] + 1)
    split_enz = draw(
        arrays(shape=num_nodes,
               dtype=np.int8,
               elements=st.sampled_from([1, 4]))).tobytes()
    if split_enz is not None:
        numz = sum(split_enz)
    else:
        numz = num_nodes
    zvals = draw(arrays(shape=int(numz), dtype=np.float32, elements=finites))
    active = draw(
        arrays(shape=dims[0] * dims[1] * dims[2],
               dtype=np.bool_,
               elements=st.just(True)))

    subs = draw(subgrids(dims[2]))

    rest = draw(st.tuples(*([finites] * 6)))
    return RoffGrid(*dims, corner_lines, zvals, split_enz, active, subs, *rest)
Esempio n. 3
0
def test_default_values(roff_grid):
    buff = io.BytesIO()
    roff_grid.to_file(buff)
    buff.seek(0)
    values = roffio.read(buff)

    del values["translate"]
    del values["scale"]
    if "subgrids" in values:
        del values["subgrids"]
    del values["active"]

    buff2 = io.BytesIO()
    roffio.write(buff2, values)
    buff2.seek(0)
    roff_grid2 = RoffGrid.from_file(buff2)

    assert roff_grid2.xoffset == 0.0
    assert roff_grid2.yoffset == 0.0
    assert roff_grid2.zoffset == 0.0

    assert roff_grid2.xscale == 1.0
    assert roff_grid2.yscale == 1.0
    assert roff_grid2.zscale == -1.0

    assert roff_grid2.subgrids is None

    assert np.array_equal(
        roff_grid2.active,
        np.ones(roff_grid.nx * roff_grid.ny * roff_grid.nz, dtype=np.bool_),
    )
Esempio n. 4
0
def test_to_from_xtgeogrid_format2(xtggrid):
    xtggrid._xtgformat2()
    roff_grid = RoffGrid.from_xtgeo_grid(xtggrid)

    assert_allclose(roff_grid.xtgeo_actnum(), xtggrid._actnumsv, atol=0.02)
    assert_allclose(roff_grid.xtgeo_coord(), xtggrid._coordsv, atol=0.02)
    assert_allclose(roff_grid.xtgeo_zcorn(), xtggrid._zcornsv, atol=0.02)
    assert roff_grid.xtgeo_subgrids() == xtggrid._subgrids
Esempio n. 5
0
def test_to_from_roffgrid(roff_grid):
    xtggrid = Grid()
    xtggrid._actnumsv = roff_grid.xtgeo_actnum()
    xtggrid._coordsv = roff_grid.xtgeo_coord()
    xtggrid._zcornsv = roff_grid.xtgeo_zcorn()
    xtggrid._subgrids = roff_grid.xtgeo_subgrids()
    xtggrid._ncol = roff_grid.nx
    xtggrid._nrow = roff_grid.ny
    xtggrid._nlay = roff_grid.nz

    roffgrid2 = RoffGrid.from_xtgeo_grid(xtggrid)
    assert same_geometry(roffgrid2, roff_grid)
    assert np.array_equal(roffgrid2.subgrids, roff_grid.subgrids)
Esempio n. 6
0
def single_cell_roff_grid():
    corner_lines = np.array(
        [
            [[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]],
            [[1.0, 0.0, 0.0], [1.0, 0.0, 1.0]],
            [[0.0, 1.0, 0.0], [0.0, 1.0, 1.0]],
            [[1.0, 1.0, 0.0], [1.0, 1.0, 1.0]],
        ],
        dtype=np.float32,
    ).ravel()
    splitenz = np.ones(8, dtype=np.uint8).tobytes()
    active = np.ones(1, dtype=bool)
    zvals = np.ones(1 * len(splitenz), dtype=np.float32)
    return RoffGrid(1, 1, 1, corner_lines, zvals, splitenz, active)
Esempio n. 7
0
def test_missing_non_optionals():
    buff = io.BytesIO()
    roffio.write(buff, {"filedata": {"filetype": "grid"}})
    buff.seek(0)
    with pytest.raises(ValueError, match="Missing non-optional"):
        RoffGrid.from_file(buff)
Esempio n. 8
0
def test_roff_grid_read_write(rgrid):
    buff = io.BytesIO()
    rgrid.to_file(buff)

    buff.seek(0)
    assert RoffGrid.from_file(buff) == rgrid