def test_roffbin_import_v2_banal(): """Test roff binary import ROFF using new API, banal case""" t0 = xtg.timer() grd1 = Grid() grd1._xtgformat = 1 grd1.from_file(BANAL6) print("V1: ", xtg.timer(t0)) t0 = xtg.timer() grd2 = Grid() grd2._xtgformat = 2 grd2.from_file(BANAL6) print("V2: ", xtg.timer(t0)) t0 = xtg.timer() grd3 = Grid() grd3._xtgformat = 2 grd3.from_file(BANAL6) grd3._convert_xtgformat2to1() print("V3: ", xtg.timer(t0)) t0 = xtg.timer() grd4 = Grid() grd4._xtgformat = 1 grd4.from_file(BANAL6) grd4._convert_xtgformat1to2() print("V4: ", xtg.timer(t0)) for irange in range(grd1.ncol): for jrange in range(grd1.nrow): for krange in range(grd1.nlay): cell = (irange + 1, jrange + 1, krange + 1) xx1 = grd1.get_xyz_cell_corners(cell, activeonly=False) xx2 = grd2.get_xyz_cell_corners(cell, activeonly=False) xx3 = grd3.get_xyz_cell_corners(cell, activeonly=False) xx4 = grd4.get_xyz_cell_corners(cell, activeonly=False) assert np.allclose(np.array(xx1), np.array(xx2)) is True assert np.allclose(np.array(xx1), np.array(xx3)) is True assert np.allclose(np.array(xx1), np.array(xx4)) is True
def test_roffbin_export_v2_banal6(): """Test roff binary export v2 for banal no. 6 case""" # export grd1 = Grid() grd1._xtgformat = 2 grd1.from_file(BANAL6) logger.info("EXPORT") grd1.to_file(join(TMPDIR, "b6_export.roffasc"), fformat="roff_asc") grd1.to_file(join(TMPDIR, "b6_export.roffbin"), fformat="roff_bin") grd2 = Grid(join(TMPDIR, "b6_export.roffbin")) cell1 = grd1.get_xyz_cell_corners((2, 2, 2)) cell2 = grd2.get_xyz_cell_corners((2, 2, 2)) assert cell1 == cell2 reek = Grid() reek._xtgformat = 2 reek.from_file(REEKFIL4) reek.to_file("TMP/reek_xtgformat2", fformat="roff_ascii")
def test_roffbin_bigbox(tmpdir): """Test roff binary for bigbox, to monitor performance""" bigbox = os.path.join(tmpdir, "bigbox.roff") if not os.path.exists(bigbox): logger.info("Create tmp big roff grid file...") grd0 = Grid() grd0.create_box(dimension=(500, 500, 100)) grd0.to_file(bigbox) grd1 = Grid() t0 = xtg.timer() grd1._xtgformat = 1 grd1.from_file(bigbox) t_old = xtg.timer(t0) logger.info("Reading bigbox xtgeformat=1 took %s seconds", t_old) cell1 = grd1.get_xyz_cell_corners((13, 14, 15)) grd2 = Grid() t0 = xtg.timer() t1 = xtg.timer() grd2._xtgformat = 2 grd2.from_file(bigbox) t_new = xtg.timer(t0) logger.info("Reading bigbox xtgformat=2 took %s seconds", t_new) cell2a = grd2.get_xyz_cell_corners((13, 14, 15)) t0 = xtg.timer() grd2._convert_xtgformat2to1() cell2b = grd2.get_xyz_cell_corners((13, 14, 15)) logger.info("Conversion to xtgformat1 took %s seconds", xtg.timer(t0)) t_newtot = xtg.timer(t1) logger.info("Total run time xtgformat=2 + conv took %s seconds", t_newtot) logger.info("Speed gain new vs old: %s", t_old / t_new) logger.info("Speed gain new incl conv vs old: %s", t_old / t_newtot) assert cell1 == cell2a assert cell1 == cell2b
def test_to_from_grdeclgrid(grdecl_grid): xtggrid = Grid() xtggrid._actnumsv = grdecl_grid.xtgeo_actnum() xtggrid._coordsv = grdecl_grid.xtgeo_coord() xtggrid._zcornsv = grdecl_grid.xtgeo_zcorn() nx, ny, nz = grdecl_grid.dimensions xtggrid._ncol = nx xtggrid._nrow = ny xtggrid._nlay = nz xtggrid._xtgformat = 2 grdecl_grid2 = ggrid.GrdeclGrid.from_xtgeo_grid(xtggrid) assert grdecl_grid2.xtgeo_actnum().tolist() == xtggrid._actnumsv.tolist() assert grdecl_grid2.xtgeo_coord() == pytest.approx(xtggrid._coordsv, abs=0.02) assert grdecl_grid2.xtgeo_zcorn() == pytest.approx(xtggrid._zcornsv, abs=0.02)
def test_to_from_xtggrid_write(tmp_path, grdecl_grid): xtggrid = Grid() xtggrid._actnumsv = grdecl_grid.xtgeo_actnum() xtggrid._coordsv = grdecl_grid.xtgeo_coord() xtggrid._zcornsv = grdecl_grid.xtgeo_zcorn() nx, ny, nz = grdecl_grid.dimensions xtggrid._ncol = nx xtggrid._nrow = ny xtggrid._nlay = nz xtggrid._xtgformat = 2 xtggrid.to_file(tmp_path / "xtggrid.grdecl", fformat="grdecl") grdecl_grid2 = ggrid.GrdeclGrid.from_file(tmp_path / "xtggrid.grdecl") assert grdecl_grid.zcorn == pytest.approx(grdecl_grid2.zcorn, abs=0.02) assert grdecl_grid.xtgeo_coord() == pytest.approx( grdecl_grid2.xtgeo_coord(), abs=0.02) if grdecl_grid.actnum is None: assert grdecl_grid2.actnum is None or np.all(grdecl_grid2.actnum) else: assert grdecl_grid.actnum.tolist() == grdecl_grid2.actnum.tolist()
def test_roffbin_banal6(): """Test roff binary for banal no. 6 case.""" grd1 = Grid() grd1.from_file(BANAL6) grd2 = Grid() grd2._xtgformat = 2 grd2.from_file(BANAL6) assert grd1.get_xyz_cell_corners() == grd2.get_xyz_cell_corners() assert grd1.get_xyz_cell_corners((4, 2, 3)) == grd2.get_xyz_cell_corners( (4, 2, 3)) grd2._convert_xtgformat2to1() assert grd1.get_xyz_cell_corners((4, 2, 3)) == grd2.get_xyz_cell_corners( (4, 2, 3)) grd2._convert_xtgformat1to2() assert grd1.get_xyz_cell_corners((4, 2, 3)) == grd2.get_xyz_cell_corners( (4, 2, 3))