Example #1
0
def test_shoebox_xtgeo_vs_roff(tmp_path):
    """Test timing for xtgeo xtgcpgeom format vs roff vs egrid."""
    dimens = (20, 30, 50)

    grd = xtgeo.Grid()
    grd.create_box(dimension=dimens)
    grd._xtgformat2()
    t0 = xtg.timer()
    grd.to_xtgf(tmp_path / "show.xtgf")
    t1 = xtg.timer(t0)
    logger.info("TIME XTGEO %s", t1)
    t0 = xtg.timer()
    grd.to_file(tmp_path / "show.roff", fformat="roff")
    t1 = xtg.timer(t0)
    logger.info("TIME ROFF %s", t1)
    t0 = xtg.timer()
    grd.to_file(tmp_path / "show.egrid", fformat="egrid")
    t1 = xtg.timer(t0)
    logger.info("TIME EGRID (incl conv) %s", t1)

    t0 = xtg.timer()
    grd2 = xtgeo.Grid()
    grd2.from_xtgf(tmp_path / "show.xtgf")
    t1 = xtg.timer(t0)
    logger.info("TIME READ xtgeo %s", t1)

    t0 = xtg.timer()
    grd2 = xtgeo.Grid()
    grd2.from_file(tmp_path / "show.roff", fformat="roff")
    t1 = xtg.timer(t0)
    logger.info("TIME READ roff %s", t1)
def test_grid_export_import_many():
    """Test exporting etc to xtgcpgeom format."""
    grid1 = xtgeo.Grid(REEKGRID1)

    nrange = 50

    fformat = "xtgf"

    fnames = []

    # timing of writer
    t1 = xtg.timer()
    for _ in range(nrange):
        fname = uuid.uuid4().hex + "." + fformat
        fname = TMPD / fname
        fnames.append(fname)
        grid1.to_xtgf(fname)

    print(f"Export {nrange} grids using xtgf: ", xtg.timer(t1))

    # timing of reader
    t1 = xtg.timer()
    grid2 = None
    for fname in fnames:
        grid2 = xtgeo.Grid()
        grid2.from_xtgf(fname)

    print(f"Import {nrange} grids using xtgf: ", xtg.timer(t1))

    assert grid1._zcornsv.mean() == pytest.approx(grid2._zcornsv.mean())
    assert grid1._coordsv.mean() == pytest.approx(grid2._coordsv.mean())
    assert grid1._actnumsv.mean() == pytest.approx(grid2._actnumsv.mean())
Example #3
0
def test_grid_export_import_many():
    """Test exporting etc to xtgcpgeom format."""
    grid1 = xtgeo.Grid(REEKGRID1)

    nrange = 50

    fformat = "xtgcpgeom"

    fnames = []

    # timing of writer
    t1 = xtg.timer()
    for num in range(nrange):
        fname = uuid.uuid4().hex + "." + fformat
        fname = pathlib.Path(TMPD) / fname
        fnames.append(fname)
        grid1.to_file(fname, fformat=fformat)

    logger.info("Timing export %s gridgeom with %s: %s", nrange, fformat, xtg.timer(t1))

    # timing of reader
    t1 = xtg.timer()
    grid2 = None
    for fname in fnames:
        grid2 = xtgeo.Grid()
        grid2.from_file(fname, fformat=fformat)

    logger.info("Timing import %s gridgeom with %s: %s", nrange, fformat, xtg.timer(t1))

    assert grid1._zcornsv.mean() == pytest.approx(grid2._zcornsv.mean())
    assert grid1._coordsv.mean() == pytest.approx(grid2._coordsv.mean())
    assert grid1._actnumsv.mean() == pytest.approx(grid2._actnumsv.mean())
Example #4
0
def test_shoebox_xtgeo_vs_roff():
    """Test the egrid format for different grid sizes"""

    dimens = (20, 30, 50)

    grd = xtgeo.Grid()
    grd.create_box(dimension=dimens)
    grd._xtgformat2()
    t0 = xtg.timer()
    grd.to_file(join(TMPDIR, "show.xtgeogrid"), fformat="xtgeo")
    t1 = xtg.timer(t0)
    logger.info("TIME XTGEO %s", t1)
    t0 = xtg.timer()
    grd.to_file(join(TMPDIR, "show.roff"), fformat="roff")
    t1 = xtg.timer(t0)
    logger.info("TIME ROFF %s", t1)
    t0 = xtg.timer()
    grd.to_file(join(TMPDIR, "show.egrid"), fformat="egrid")
    t1 = xtg.timer(t0)
    logger.info("TIME EGRID (incl conv) %s", t1)

    t0 = xtg.timer()
    grd2 = xtgeo.Grid()
    grd2.from_file(join(TMPDIR, "show.xtgeogrid"), fformat="xtgeo")
    t1 = xtg.timer(t0)
    logger.info("TIME READ xtgeo %s", t1)

    t0 = xtg.timer()
    grd2 = xtgeo.Grid()
    grd2.from_file(join(TMPDIR, "show.roff"), fformat="roff")
    t1 = xtg.timer(t0)
    logger.info("TIME READ roff %s", t1)
Example #5
0
def test_shoebox_egrid():
    """Test the egrid format for different grid sizes."""
    dimens = [(1000, 1, 1), (1000, 1, 200), (300, 200, 30)]

    for dim in dimens:
        grd = xtgeo.Grid()
        grd.create_box(dimension=dim)
        grd.to_file(TMPDIR / "E1.EGRID", fformat="egrid")
        grd1 = xtgeo.Grid(TMPDIR / "E1.EGRID")
        assert grd1.dimensions == dim
Example #6
0
def test_point_in_cell_compare_rms():
    """Test IJK in cells, compare with a list made in RMS IPL"""

    # from RMS
    pointset = pd.read_csv(QCFIL1, skiprows=3)

    p1 = xtgeo.Points()
    attrs = {"IX": "I", "JY": "J", "KZ": "K"}
    p1.from_dataframe(pointset, east="X", north="Y", tvdmsl="Z", attributes=attrs)

    grd = xtgeo.Grid(QCGRID)
    dfr = grd.get_ijk_from_points(p1)

    for cname in ("IX", "JY", "KZ"):
        list1 = p1.dataframe[cname].tolist()
        list2 = dfr[cname].tolist()

        nall = len(list1)
        suc = 0
        for ino, item in enumerate(list1):
            if item == list2[ino]:
                suc += 1

        succesrate = suc / nall
        print(cname, succesrate, suc, nall)
Example #7
0
def test_x_cellangles():
    """Test x_minmax_cellangles* functions (lowlevel call)"""

    grd = xtgeo.Grid(TESTGRID)
    cell1 = grd.get_xyz_cell_corners((6, 4, 1))
    cell2 = grd.get_xyz_cell_corners((6, 3, 1))
    cell3 = grd.get_xyz_cell_corners((4, 7, 1))

    _ier, amin, amax = _cxtgeo.x_minmax_cellangles_topbase(cell1, 0, 1)

    assert amin == pytest.approx(71.329, abs=0.01)
    assert amax == pytest.approx(102.673, abs=0.01)

    # birdview
    _ier, amin, amax = _cxtgeo.x_minmax_cellangles_topbase(cell1, 1, 1)

    assert amin == pytest.approx(89.701, abs=0.01)
    assert amax == pytest.approx(90.274, abs=0.01)

    # side cells
    _ier, amin, amax = _cxtgeo.x_minmax_cellangles_sides(cell1, 1)

    _ier, amin, amax = _cxtgeo.x_minmax_cellangles_sides(cell2, 1)

    assert amin == pytest.approx(49.231, abs=0.01)
    assert amax == pytest.approx(130.77, abs=0.01)

    _ier, amin, amax = _cxtgeo.x_minmax_cellangles_sides(cell3, 1)

    assert amin == pytest.approx(75.05, abs=0.01)
    assert amax == pytest.approx(104.95, abs=0.01)
Example #8
0
def test_randomline_fence_from_well():
    """Import ROFF grid with props and make fences"""

    grd = xtgeo.Grid(REEKROOT, fformat="eclipserun", initprops=["PORO"])
    wll = xtgeo.Well(WELL1, zonelogname="Zonelog")

    print(grd.describe(details=True))

    # get the polygon for the well, limit it to 1200
    fspec = wll.get_fence_polyline(sampling=10, nextend=2, asnumpy=False, tvdmin=1200)
    print(fspec.dataframe)

    tsetup.assert_almostequal(fspec.dataframe[fspec.dhname][4], 12.6335, 0.001)
    logger.info(fspec.dataframe)

    fspec = wll.get_fence_polyline(sampling=10, nextend=2, asnumpy=True, tvdmin=1200)

    # get the "image", which is a 2D numpy that can be plotted with e.g. imgshow
    hmin, hmax, vmin, vmax, por = grd.get_randomline(
        fspec, "PORO", zmin=1600, zmax=1700, zincrement=1.0
    )

    if XTGSHOW:
        import matplotlib.pyplot as plt

        plt.figure()
        plt.imshow(
            por, cmap="rainbow", extent=(hmin, hmax, vmax, vmin)
        )
        plt.axis("tight")
        plt.colorbar()
        plt.show()
Example #9
0
def test_xsect_larger_geogrid(show_plot):
    """Test a larger xsection"""

    mygrid = xtgeo.Grid(BIGRGRID1)
    poro = xtgeo.GridProperty(BIGPROP1)
    mywell1 = xtgeo.Well(BIGWELL1)
    mywell2 = xtgeo.Well(BIGWELL2)

    fence1 = mywell1.get_fence_polyline(sampling=5, tvdmin=1750, asnumpy=True)

    (hmin1, hmax1, vmin1, vmax1, arr1) = mygrid.get_randomline(fence1,
                                                               poro,
                                                               zmin=1750,
                                                               zmax=2100,
                                                               zincrement=0.2)

    fence2 = mywell2.get_fence_polyline(sampling=5, tvdmin=1500, asnumpy=True)

    (hmin2, hmax2, vmin2, vmax2, arr2) = mygrid.get_randomline(fence2,
                                                               poro,
                                                               zmin=1500,
                                                               zmax=1850,
                                                               zincrement=0.2)

    if show_plot:
        plt.figure()
        plt.imshow(arr1, cmap="rainbow", extent=(hmin1, hmax1, vmax1, vmin1))
        plt.axis("tight")
        plt.figure()
        plt.imshow(arr2, cmap="rainbow", extent=(hmin2, hmax2, vmax2, vmin2))
        plt.axis("tight")
        plt.show()
def test_grid_export_import_bigcase():
    """Test io for big case if BIGBOX, and compare xtgf and h5 performance."""
    grid1 = xtgeo.Grid()

    dimens = (100, 100, 20)
    if BIGBOX:
        dimens = (1000, 1000, 100)

    grid1.create_box(dimens)

    grid2 = xtgeo.Grid()

    t1 = xtg.timer()
    fname = TMPD / "bigbox.xtgf"
    grid1.to_xtgf(fname)
    print("Export bigcase using xtgf: ", xtg.timer(t1))

    t1 = xtg.timer()
    fname = TMPD / "bigbox.xtgf"
    grid2.from_xtgf(fname, mmap=True)
    print("Import bigcase using xtgf and memory mapping: ", xtg.timer(t1))
    assert grid1._zcornsv.mean() == pytest.approx(grid2._zcornsv.mean())

    t1 = xtg.timer()
    fname = TMPD / "bigbox.xtgf"
    grid2.from_xtgf(fname)
    print("Import bigcase using xtgf: ", xtg.timer(t1))

    t1 = xtg.timer()
    fname = TMPD / "bigbox.h5"
    grid1.to_hdf(fname)
    print("Export bigcase using hdf5: ", xtg.timer(t1))

    t1 = xtg.timer()
    fname = TMPD / "bigbox.h5"
    grid2.from_hdf(fname)
    print("Import bigcase using h5: ", xtg.timer(t1))

    t1 = xtg.timer()
    fname = TMPD / "bigboxc.h5"
    grid1.to_hdf(fname, compression="blosc")
    print("Export bigcase using hdf5 with compression: ", xtg.timer(t1))

    t1 = xtg.timer()
    fname = TMPD / "bigboxc.h5"
    grid2.from_hdf(fname)
    print("Import bigcase using h5 with compression: ", xtg.timer(t1))
def test_grid_hdf5_export_import_many():
    """Test io to hdf5 format, including partial read."""
    grd1 = xtgeo.Grid(REEKGRID1)

    nrange = 50
    fnames = []

    # timing of writer
    t1 = xtg.timer()
    for _ in range(nrange):
        fname = "$md5sum.hdf"
        fname = TMPD / fname
        grd1._zcornsv += 1.0
        fna = grd1.to_hdf(fname, compression=None)
        fnames.append(fna)

    logger.info("Timing export %s gridgeom with h5: %s", nrange, xtg.timer(t1))
    print(f"Export {nrange} grids using hdf5: ", xtg.timer(t1))

    # timing of reader
    t1 = xtg.timer()
    grd2 = None
    for fname in fnames:
        grd2 = xtgeo.Grid()
        grd2.from_hdf(fname, ijkrange=(1, 20, 1, 20, "min", "max"))

    print(f"Import {nrange} grids using hdf5 ikjrange: ", xtg.timer(t1))
    assert grd2.ncol == 20
    assert grd2.nlay == grd1.nlay

    t1 = xtg.timer()
    grd2 = None
    for fname in fnames:
        grd2 = xtgeo.Grid()
        grd2.from_hdf(fname)

    print(f"Import {nrange} grids using hdf5 full: ", xtg.timer(t1))

    assert grd1._zcornsv.mean() == pytest.approx(grd2._zcornsv.mean())
    assert grd1._coordsv.mean() == pytest.approx(grd2._coordsv.mean())
    assert grd1._actnumsv.mean() == pytest.approx(grd2._actnumsv.mean())
Example #12
0
def test_grdecl_roundtrip(xtgeo_grid):
    grdecl_file = "xtg_grid.grdecl"
    xtgeo_grid.to_file(str(grdecl_file), fformat="grdecl")
    egrid_file = convert_to_egrid(xtgeo_grid.dimensions, grdecl_file)
    opm_grid = xtgeo.Grid(str(egrid_file), fformat="egrid")

    opm_grid._xtgformat2()
    xtgeo_grid._xtgformat2()
    assert opm_grid.dimensions == xtgeo_grid.dimensions
    assert_allclose(opm_grid._actnumsv, xtgeo_grid._actnumsv)
    assert_allclose(opm_grid._coordsv, xtgeo_grid._coordsv, atol=0.02)
    assert_allclose(opm_grid._zcornsv, xtgeo_grid._zcornsv, atol=0.02)
Example #13
0
def test_egrid_roundtrip(xtgeo_grid):
    egrid_file = "xtg_grid.egrid"
    xtgeo_grid.to_file(str(egrid_file), fformat="egrid")
    opm_egrid_file = read_write_egrid(xtgeo_grid.dimensions, egrid_file)
    opm_grid = xtgeo.Grid(str(opm_egrid_file), fformat="egrid")

    opm_grid._xtgformat2()
    xtgeo_grid._xtgformat2()
    assert opm_grid.dimensions == xtgeo_grid.dimensions
    assert_allclose(opm_grid._actnumsv, xtgeo_grid._actnumsv)
    assert_allclose(opm_grid._coordsv, xtgeo_grid._coordsv, atol=0.02)
    assert_allclose(opm_grid._zcornsv, xtgeo_grid._zcornsv, atol=0.02)
Example #14
0
def test_get_surfaces_from_3dgrid():
    """Create surfaces from a 3D grid."""
    mygrid = xtgeo.Grid(TESTSETG1)
    surfs = xtgeo.Surfaces()
    surfs.from_grid3d(mygrid, rfactor=2)
    surfs.describe()

    assert_almostequal(surfs.surfaces[-1].values.mean(), 1742.28, 0.04)
    assert_almostequal(surfs.surfaces[-1].values.min(), 1589.58, 0.04)
    assert_almostequal(surfs.surfaces[-1].values.max(), 1977.29, 0.04)
    assert_almostequal(surfs.surfaces[0].values.mean(), 1697.02, 0.04)

    for srf in surfs.surfaces:
        srf.to_file(join(TMPD, srf.name + ".gri"))
Example #15
0
def test_benchmark_grid_hdf5_import_partial(benchmark, tmp_path, benchmark_grid):
    fname = join(tmp_path, "reek_geo_grid.hdf")

    benchmark_grid._zcornsv += 1.0
    fna = benchmark_grid.to_hdf(fname, compression=None)

    grd2 = xtgeo.Grid()

    @benchmark
    def partial_read():
        grd2.from_hdf(fna, ijkrange=(1, 20, 1, 20, "min", "max"))

    assert grd2.ncol == 20
    assert grd2.nlay == benchmark_grid.nlay
Example #16
0
def test_benchmark_grid_xtgf_import(benchmark, tmp_path, benchmark_grid):
    fname = join(tmp_path, "reek_geo_grid.xtgf")

    benchmark_grid.to_xtgf(fname)

    grid2 = xtgeo.Grid()

    @benchmark
    def read():
        grid2.from_xtgf(fname)

    assert_allclose(benchmark_grid._zcornsv, grid2._zcornsv)
    assert_allclose(benchmark_grid._coordsv, grid2._coordsv)
    assert_allclose(benchmark_grid._actnumsv, grid2._actnumsv)
Example #17
0
def test_benchmark_grid_hdf5_import(benchmark, tmp_path, benchmark_grid):
    fname = join(tmp_path, "reek_geo_grid.hdf")

    benchmark_grid._zcornsv += 1.0
    fna = benchmark_grid.to_hdf(fname, compression=None)

    grd2 = xtgeo.Grid()

    @benchmark
    def read():
        grd2.from_hdf(fna)

    assert_allclose(benchmark_grid._zcornsv, grd2._zcornsv)
    assert_allclose(benchmark_grid._coordsv, grd2._coordsv)
    assert_allclose(benchmark_grid._actnumsv, grd2._actnumsv)
Example #18
0
def test_randomline_fence_calczminzmax():
    """Import ROFF grid with props and make fence from polygons, zmin/zmax auto"""

    grd = xtgeo.Grid(REEKROOT,
                     fformat="eclipserun",
                     initprops=["PORO", "PERMX"])
    fence = xtgeo.Polygons(FENCE1)

    fspec = fence.get_fence(distance=5, nextend=2, asnumpy=True)

    hmin, hmax, vmin, vmax, por = grd.get_randomline(fspec,
                                                     "PORO",
                                                     zmin=None,
                                                     zmax=None)
    tsetup.assert_almostequal(vmin, 1548.10098, 0.0001)
Example #19
0
def test_create_shoebox():
    """Make a shoebox grid from scratch"""

    grd = xtgeo.Grid()
    grd.create_box()
    grd.to_file(join(TMPDIR, "shoebox_default.roff"))

    grd.create_box(flip=-1)
    grd.to_file(join(TMPDIR, "shoebox_default_flipped.roff"))

    timer1 = xtg.timer()
    grd.create_box(origin=(0, 0, 1000),
                   dimension=(300, 200, 30),
                   increment=(20, 20, 1),
                   flip=-1)
    logger.info("Making a a 1,8 mill cell grid took %5.3f secs",
                xtg.timer(timer1))

    dx, dy = grd.get_dxdy()

    tsetup.assert_almostequal(dx.values.mean(), 20.0, 0.0001)
    tsetup.assert_almostequal(dy.values.mean(), 20.0, 0.0001)

    grd.create_box(origin=(0, 0, 1000),
                   dimension=(30, 30, 3),
                   rotation=45,
                   increment=(20, 20, 1))

    x, y, z = grd.get_xyz()

    tsetup.assert_almostequal(x.values1d[0], 0.0, 0.001)
    tsetup.assert_almostequal(y.values1d[0], 20 * math.cos(45 * math.pi / 180),
                              0.001)
    tsetup.assert_almostequal(z.values1d[0], 1000.5, 0.001)

    grd.create_box(
        origin=(0, 0, 1000),
        dimension=(30, 30, 3),
        rotation=45,
        increment=(20, 20, 1),
        oricenter=True,
    )

    x, y, z = grd.get_xyz()

    tsetup.assert_almostequal(x.values1d[0], 0.0, 0.001)
    tsetup.assert_almostequal(y.values1d[0], 0.0, 0.001)
    tsetup.assert_almostequal(z.values1d[0], 1000.0, 0.001)
Example #20
0
    def read_grid(self, gridname, reuse):
        """Read 3D grid (which is required), from file or RMS"""

        gridname = gridname if self._project is not None else join(
            self._path, gridname)
        CMN.print_debug(f"GRIDNAME: {gridname}")

        CMN.print_info("Reading grid geometry...")
        if ("grid" not in reuse) or (gridname not in self._xtgdata["grid"]):
            self._grid = (xtgeo.Grid(gridname) if self._project is None else
                          xtgeo.grid_from_roxar(self._project, gridname))
            self._xtgdata["grid"][gridname] = self._grid
            self._xtgdata["gridprops"][gridname] = {}
        else:
            CMN.print_info(f"Reusing grid {gridname}")
            self._grid = self._xtgdata["grid"][gridname]
Example #21
0
def _read_from_disk(self, data):

    _get_verbosity(self, data)

    if "path" in data.keys():

        self.print_debug("PATH: {}".format(data["path"]))
        self._path = data["path"]

    reuse_grid = False
    if "grid" in data.keys():

        gridpath = join(self._path, data["grid"])
        if gridpath == self._gridname:
            self.print_info("Grid is already loaded")
            reuse_grid = True
        else:
            self.print_debug("GRIDPATH: {}".format(gridpath))
            self._grid = xtgeo.Grid(gridpath)
            self._gridname = gridpath

    if "zone" in data.keys():
        zonedict = data["zone"]
        zonename, zonefile = _unpack_dict1(zonedict)

        zonefile = join(self._path, zonefile)

        # since grid can be different but zonefile may the same (rare for files...)
        if reuse_grid and zonefile == self._gridzonename:
            self.print_info("Grid zone is already loaded")
        else:
            self._gridzone = xtgeo.GridProperty(zonefile, name=zonename)
            self._gridzonename = zonefile

    if "wells" in data.keys():
        # fields may contain wildcards for "globbing"
        wdata = []
        if isinstance(data["wells"], list):
            for welldata in data["wells"]:
                abswelldata = join(self._path, welldata)
                for wellentry in glob(abswelldata):
                    wdata.append(xtgeo.Well(wellentry))
                    self.print_debug(wellentry)

        self._wells = xtgeo.Wells()
        self._wells.wells = wdata
Example #22
0
def test_randomline_fence_from_polygon():
    """Import ROFF grid with props and make fence from polygons"""

    grd = xtgeo.Grid(REEKROOT,
                     fformat="eclipserun",
                     initprops=["PORO", "PERMX"])
    fence = xtgeo.Polygons(FENCE1)

    # get the polygons
    fspec = fence.get_fence(distance=10, nextend=2, asnumpy=False)
    tsetup.assert_almostequal(fspec.dataframe[fspec.dhname][4], 10, 1)

    fspec = fence.get_fence(distance=5, nextend=2, asnumpy=True)

    # get the "image", which is a 2D numpy that can be plotted with e.g. imgshow
    logger.info("Getting randomline...")
    timer1 = xtg.timer()
    hmin, hmax, vmin, vmax, por = grd.get_randomline(fspec,
                                                     "PORO",
                                                     zmin=1680,
                                                     zmax=1750,
                                                     zincrement=0.5)
    logger.info("Getting randomline... took {0:5.3f} secs".format(
        xtg.timer(timer1)))

    timer1 = xtg.timer()
    hmin, hmax, vmin, vmax, perm = grd.get_randomline(fspec,
                                                      "PERMX",
                                                      zmin=1680,
                                                      zmax=1750,
                                                      zincrement=0.5)
    logger.info("Getting randomline (2 time)... took {0:5.3f} secs".format(
        xtg.timer(timer1)))

    if XTGSHOW:
        import matplotlib.pyplot as plt

        plt.figure()
        plt.imshow(por, cmap="rainbow", extent=(hmin, hmax, vmax, vmin))
        plt.axis("tight")
        plt.colorbar()
        plt.figure()
        plt.imshow(perm, cmap="rainbow", extent=(hmin, hmax, vmax, vmin))
        plt.axis("tight")
        plt.colorbar()
        plt.show()
def test_convert_grid_format_egrid(tmpdir, mocker):
    """Convert an ECLIPSE egrid to roff"""

    outfile = tmpdir / "reek_grid.roff"

    mocker.patch(
        "sys.argv",
        [
            "convert_grid_format",
            "--file",
            str(RFILE1),
            "--output",
            str(outfile),
            "--mode",
            "grid",
            "--standardfmu",
        ],
    )
    cgf.main()

    # check number of active cells
    geogrid = xtgeo.Grid(str(outfile))
    assert geogrid.nactive == 35817
Example #24
0
def test_from_grid3d_deprecation(default_surface):
    mygrid = xtgeo.Grid()
    surface = xtgeo.RegularSurface(**default_surface)
    surface.from_grid3d(mygrid)
Example #25
0
    BIGBOX_DIMENSIONS = (1000, 1000, 20)

# ======================================================================================
# Grid geometries:


def create_box(testpath):
    grid = xtgeo.Grid()
    grid.create_box(BIGBOX_DIMENSIONS)
    return grid


@pytest.fixture(
    name="benchmark_grid",
    params=[
        lambda tp: xtgeo.Grid(join(tp, "3dgrids/reek/reek_geo_grid.roff")),
        create_box,
    ],
    ids=["reek_grid", "big_box"],
)
def benchmark_grid_fixture(request, testpath):
    return request.param(testpath)


@pytest.mark.benchmark(group="import/export")
def test_benchmark_grid_xtgf_export(benchmark, tmp_path, benchmark_grid):
    fname = join(tmp_path, "reek_geo_grid.xtgf")

    @benchmark
    def write():
        benchmark_grid.to_xtgf(fname)
Example #26
0
def test_get_cell_volume():
    """Test hexahedron (cell) bulk volume valculation"""

    # box
    grd = xtgeo.Grid(TESTGRID3)

    vol1 = grd.get_cell_volume((1, 1, 1))
    assert vol1 == pytest.approx(3821600, rel=0.01)

    # banal6
    grd = xtgeo.Grid(TESTGRID2)

    vol1 = grd.get_cell_volume((1, 1, 1))
    vol2 = grd.get_cell_volume((4, 1, 1))
    vol3 = grd.get_cell_volume((1, 2, 1))
    vol4 = grd.get_cell_volume((3, 1, 2))

    assert vol1 == pytest.approx(1679.7, rel=0.01)
    assert vol2 == pytest.approx(2070.3, rel=0.01)
    assert vol3 == pytest.approx(1289.1, rel=0.01)
    assert vol4 == pytest.approx(593.75, rel=0.01)

    # gridqc1
    grd = xtgeo.Grid(TESTGRID)
    tbulk_rms = xtgeo.gridproperty_from_file(TESTGRID_TBULK)

    rmean = []
    for prec in [1, 2, 4]:
        ntot = 0
        nfail = 0
        ratioarr = []
        for icol in range(grd.ncol):
            for jrow in range(grd.nrow):
                for klay in range(grd.nlay):
                    vol1a = grd.get_cell_volume(
                        (icol, jrow, klay), zerobased=True, precision=prec
                    )
                    if vol1a is not None:
                        vol1b = tbulk_rms.values[icol, jrow, klay]
                        ratio = vol1a / vol1b
                        ratioarr.append(ratio)
                        ntot += 1
                        if ratio < 0.98 or ratio > 1.02:
                            nfail += 1
                            logger.info("%s %s %s:  %s", icol, jrow, klay, ratio)
                            logger.info("XTGeo vs RMS %s %s", vol1a, vol1b)
                        if prec > 1:
                            assert vol1a == pytest.approx(vol1b, 0.0001)

        rarr = np.array(ratioarr)
        rmean.append(rarr.mean())
        logger.info(
            "Prec: %s, Fails of total %s vs %s, mean/min/max: %s %s %s",
            prec,
            nfail,
            ntot,
            rarr.mean(),
            rarr.min(),
            rarr.max(),
        )
        if prec > 1:
            assert rarr == pytest.approx(1.0, 0.0001)
            assert nfail == 0

    # ensure that mean difference get closer to 1 with increasing precision?
    for ravg in rmean:
        diff = abs(1.0 - ravg)
        logger.info("Diff from 1: %s", diff)
Example #27
0
def create_box(testpath):
    grid = xtgeo.Grid()
    grid.create_box(BIGBOX_DIMENSIONS)
    return grid
Example #28
0
def test_shoebox_egrid(tmp_path, dimensions):
    grd = xtgeo.Grid()
    grd.create_box(dimension=dimensions)
    grd.to_file(tmp_path / "E1.EGRID", fformat="egrid")
    grd1 = xtgeo.Grid(tmp_path / "E1.EGRID")
    assert grd1.dimensions == dimensions
Example #29
0
def test_xtgeo_file_bad_alias(tmp_path):
    grd = xtgeo.Grid()
    with pytest.raises(ValueError, match="not a valid alias"):
        xtgeo._XTGeoFile(tmp_path / "$NO_ALIAS").resolve_alias(grd)