def test_gridprop_export_import_many():
    """Test exporting etc to xtgcpprop format."""
    prop1 = xtgeo.GridProperty(REEKPROP1)

    print(prop1.values1d)

    nrange = 50

    fformat = "xtgcpprop"

    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)
        prop1.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.GridProperty()
        grid2.from_file(fname, fformat=fformat)

    logger.info("Timing import %s gridgeom with %s: %s", nrange, fformat, xtg.timer(t1))
def test_gridprop_partial_read_smallcase():
    """Read a partial property based on ijrange from file."""
    vals = np.zeros((5, 7, 3), dtype=np.float32)
    prp = xtgeo.GridProperty(ncol=5, nrow=7, nlay=3, values=vals)
    prp.values[0, 0, 0:3] = 33
    prp.values[1, 0, 0:3] = 66
    prp.values[1, 1, 0:3] = 44
    print(prp.values)
    fname = TMPD / "grdprop.xtgcpprop"
    prp.to_file(fname, fformat="xtgcpprop")

    # import partial
    prp3 = xtgeo.GridProperty()
    prp3.from_file(fname, fformat="xtgcpprop", ijrange=(1, 2, 1, 2))
    assert prp3.values.all() == prp.values[0:2, 0:2, :].all()
Beispiel #3
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_gridprop_partial_read_bigcase():
    """Read a partial property based on ijrange from file, big case measure speed."""
    vals = np.zeros((400, 500, 300), dtype=np.float32)
    prp = xtgeo.GridProperty(ncol=400, nrow=500, nlay=300, values=vals)
    prp.values[0, 0, 0:3] = 33
    prp.values[1, 0, 0:3] = 66
    prp.values[1, 1, 0:3] = 44
    fname = TMPD / "grdprop2.xtgcpprop"
    prp.to_file(fname, fformat="xtgcpprop")

    t0 = xtg.timer()
    for _ in range(10):
        prp.from_file(fname, fformat="xtgcpprop")
    t1 = xtg.timer(t0)
    logger.info("Timing from whole grid IJ 400 x 500: %s", t1)
    grdsize1 = prp.values.size
    # read a subpart and measure time
    t0 = xtg.timer()
    for _ in range(10):
        prp.from_file(fname, fformat="xtgcpprop", ijrange=(350, 400, 1, 50))
    t2 = xtg.timer(t0)
    logger.info("Timing from subrange IJ 50 x 50 : %s", t2)
    grdsize2 = prp.values.size
    gridratio = grdsize2 / grdsize1
    readratio = t2 / t1

    logger.info("Timing: speedratio vs gridsizeratio %s %s", readratio, gridratio)
    assert readratio < 0.5
def test_convert_grid_format_restart(tmpdir, mocker):
    """Convert an ECLIPSE SOIL from restart to roff"""

    outfile = tmpdir / "reek_grid.roff"

    mocker.patch(
        "sys.argv",
        [
            "convert_grid_format",
            "--file",
            str(RFILE2),
            "--output",
            str(outfile),
            "--mode",
            "restart",
            "--propnames",
            "SOIL",
            "--dates",
            "20000701",
            "--standardfmu",
        ],
    )
    cgf.main()

    actual_outfile = tmpdir / "reek_grid--soil--20000701.roff"

    gprop = xtgeo.GridProperty(str(actual_outfile))

    assert gprop.values.mean() == pytest.approx(0.0857, abs=0.001)
Beispiel #6
0
def create_small_prop(testpath):
    vals = np.zeros((5, 7, 3), dtype=np.float32)
    prp = xtgeo.GridProperty(ncol=5, nrow=7, nlay=3, values=vals)
    prp.values[0, 0, 0:3] = 33
    prp.values[1, 0, 0:3] = 66
    prp.values[1, 1, 0:3] = 44
    return prp
Beispiel #7
0
def create_big_prop(testpath):
    vals = np.zeros(BIGBOX_DIMENSIONS, dtype=np.float32)
    ncol, nrow, nlay = BIGBOX_DIMENSIONS
    prp = xtgeo.GridProperty(ncol=ncol, nrow=nrow, nlay=nlay, values=vals)
    prp.values[0, 0, 0:3] = 33
    prp.values[1, 0, 0:3] = 66
    prp.values[1, 1, 0:3] = 44
    return prp
def test_create_from_gridproperty():
    """Create a simple property from grid"""

    gg = Grid(TESTFILE5, fformat="egrid")
    poro = GridProperty(gg, name="poro", values=0.33)
    assert poro.ncol == gg.ncol

    # create from gridproperty
    faci = xtgeo.GridProperty(poro, name="FAC", values=1, discrete=True)
    assert faci.nlay == gg.nlay
    assert faci.values.mean() == 1

    assert faci.values.dtype.kind == "i"

    some = xtgeo.GridProperty(faci, name="SOME", values=22)
    assert some.values.mean() == 22.0
    assert some.isdiscrete is False
    some.values = np.where(some.values == 0, 0, 1)
    assert some.isdiscrete is False
Beispiel #9
0
def test_benchmark_gridprop_import_partial(benchmark, tmp_path, benchmark_gridprop):
    """Test exporting etc to xtgcpprop format."""

    fname = tmp_path / "benchmark.xtgcpprop"

    benchmark_gridprop.to_file(fname, fformat="xtgcpprop")

    prop2 = xtgeo.GridProperty()

    @benchmark
    def read():
        prop2.from_file(fname, fformat="xtgcpprop", ijrange=(1, 2, 1, 2))

    assert benchmark_gridprop.values[0:2, 0:2, :].all() == prop2.values.all()
Beispiel #10
0
def test_create_from_grid():
    """Create a simple property from grid"""

    gg = Grid(testfile5, fformat="egrid")
    poro = GridProperty(gg, name="poro", values=0.33)
    assert poro.ncol == gg.ncol
    assert poro.values.mean() == 0.33

    assert poro.values.dtype.kind == "f"

    faci = xtgeo.GridProperty(gg, name="FAC", values=1, discrete=True)
    assert faci.nlay == gg.nlay
    assert faci.values.mean() == 1

    assert faci.values.dtype.kind == "i"
Beispiel #11
0
def get_gridquality_properties(self):
    """Get the grid quality properties"""

    numqual = 10

    self._xtgformat2()

    fresults = np.ones((numqual, self.ncol * self.nrow * self.nlay),
                       dtype=np.float32)

    _cxtgeo.grdcp3d_quality_indicators(
        self.ncol,
        self.nrow,
        self.nlay,
        self._coordsv,
        self._zcornsv,
        self._actnumsv,
        fresults,
    )
    qcnames = {
        0: "minangle_topbase",
        1: "maxangle_topbase",
        2: "minangle_topbase_proj",
        3: "maxangle_topbase_proj",
        4: "minangle_sides",
        5: "maxangle_sides",
        6: "collapsed",
        7: "faulted",
        8: "negative_thickness",
        9: "concave_proj",
    }

    # some of the properties shall be discrete:
    qcdiscrete = [6, 7, 8, 9]

    grdprops = xtgeo.GridProperties()

    for num, name in qcnames.items():
        prop = xtgeo.GridProperty(self, name=name)
        dtype = np.float32
        if num in qcdiscrete:
            dtype = np.int32
            prop.isdiscrete = True
            prop.codes = {0: "None", 1: name}
        prop.values = fresults[num, :].astype(dtype)
        grdprops.append_props([prop])

    return grdprops
Beispiel #12
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
Beispiel #13
0
    return prp


def create_small_prop(testpath):
    vals = np.zeros((5, 7, 3), dtype=np.float32)
    prp = xtgeo.GridProperty(ncol=5, nrow=7, nlay=3, values=vals)
    prp.values[0, 0, 0:3] = 33
    prp.values[1, 0, 0:3] = 66
    prp.values[1, 1, 0:3] = 44
    return prp


@pytest.fixture(
    name="benchmark_gridprop",
    params=[
        lambda tp: xtgeo.GridProperty(join(tp, "3dgrids/reek2/geogrid--poro.roff")),
        create_big_prop,
        create_small_prop,
    ],
    ids=["reek poro", "small prop", "big prop"],
)
def benchmark_gridprop_fixture(request, testpath):
    return request.param(testpath)


@pytest.mark.benchmark()
def test_benchmark_gridprop_export(benchmark, tmp_path, benchmark_gridprop):

    fname = tmp_path / "benchmark.xtgcpprop"

    @benchmark
Beispiel #14
0
def fixture_gridproperty():
    """Create an xtgeo gridproperty instance."""
    logger.info("Ran %s", inspect.currentframe().f_code.co_name)
    return xtgeo.GridProperty(ncol=3, nrow=7, nlay=3, values=123.0)