How to use the xtgeo.grid3d.Grid function in xtgeo

To help you get started, we’ve selected a few xtgeo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github equinor / xtgeo / tests / test_grid3d / test_grid_properties.py View on Github external
def test_import_init():
    """Import INIT Reek"""

    g = Grid()
    g.from_file(GFILE1, fformat="egrid")

    x = GridProperties()

    names = ['PORO', 'PORV']
    x.from_file(IFILE1, fformat="init",
                names=names, grid=g)

    # get the object
    poro = x.get_prop_by_name('PORO')
    logger.info("PORO avg {}".format(poro.values.mean()))

    porv = x.get_prop_by_name('PORV')
    logger.info("PORV avg {}".format(porv.values.mean()))
    assert poro.values.mean() == pytest.approx(0.1677402, abs=0.00001)
github equinor / xtgeo / tests / test_grid3d / test_grid.py View on Github external
def test_eclgrid_import2():
    """Eclipse EGRID import, also change ACTNUM."""
    grd = Grid()
    logger.info("Import Eclipse GRID...")
    grd.from_file(REEKFILE, fformat="egrid")

    tsetup.assert_equal(grd.ncol, 40, txt="EGrid NX from Eclipse")
    tsetup.assert_equal(grd.nrow, 64, txt="EGrid NY from Eclipse")
    tsetup.assert_equal(grd.nactive, 35838, txt="EGrid NTOTAL from Eclipse")
    tsetup.assert_equal(grd.ntotal, 35840, txt="EGrid NACTIVE from Eclipse")

    actnum = grd.get_actnum()
    print(actnum.values[12:13, 22:24, 5:6])
    tsetup.assert_equal(actnum.values[12, 22, 5], 0, txt="ACTNUM 0")

    actnum.values[:, :, :] = 1
    actnum.values[:, :, 4:6] = 0
    grd.set_actnum(actnum)
    newactive = grd.ncol * grd.nrow * grd.nlay - 2 * (grd.ncol * grd.nrow)
github equinor / xtgeo / tests / test_grid3d / test_grid_vs_poly.py View on Github external
def test_grid_inactivate_outside():
    """Inactivate a grid outside polygons"""
    g1 = xtgeo.grid3d.Grid(reekgrid)

    p1 = xtgeo.xyz.Polygons(reekpoly)

    act1 = g1.get_actnum().values3d
    n1 = act1[3, 56, 1]
    assert n1 == 1

    try:
        g1.inactivate_outside(p1, layer_range=(1, 4))
    except RuntimeError as rw:
        print(rw)

    g1.to_file(os.path.join(td, 'reek_inact_out_pol.roff'))

    act2 = g1.get_actnum().values3d
    n2 = act2[3, 56, 1]
github equinor / xtgeo / tests / test_grid3d / test_grid.py View on Github external
def test_xyz_cell_corners():
    """Test xyz variations"""

    grd = Grid(DUALFIL1)

    allcorners = grd.get_xyz_corners()
    assert len(allcorners) == 24
    assert allcorners[0].get_npvalues1d()[0] == 0.0
    assert allcorners[23].get_npvalues1d()[-1] == 1001.0
github equinor / xtgeo / tests / test_grid3d / test_grid.py View on Github external
def test_activate_all_cells():
    """Make the grid active for all cells"""

    grid = Grid(EMEGFILE)
    logger.info("Number of active cells %s before", grid.nactive)
    grid.activate_all()
    logger.info("Number of active cells %s after", grid.nactive)

    assert grid.nactive == grid.ntotal
    grid.to_file(join(TMPDIR, "emerald_all_active.roff"))
github equinor / xtgeo / tests / test_grid3d / test_grid.py View on Github external
def test_pathlib():
    """Import and export via pathlib"""

    pfile = pathlib.Path(DUALFIL1)
    grd = Grid()
    grd.from_file(pfile)

    assert grd.dimensions == (5, 3, 1)

    out = pathlib.Path() / TMPDIR / "grdpathtest.roff"
    grd.to_file(out, fformat="roff")

    with pytest.raises(OSError):
        out = pathlib.Path() / "nosuchdir" / "grdpathtest.roff"
        grd.to_file(out, fformat="roff")
github equinor / xtgeo / tests / test_grid3d / test_grid.py View on Github external
def test_eclgrid_import3():
    """Eclipse GRDECL import and translate"""

    grd = Grid(BRILGRDECL, fformat="grdecl")

    mylist = grd.get_geometrics()

    xori1 = mylist[0]

    # translate the coordinates
    grd.translate_coordinates(translate=(100, 100, 10), flip=(1, 1, 1))

    mylist = grd.get_geometrics()

    xori2 = mylist[0]

    # check if origin is translated 100m in X
    tsetup.assert_equal(xori1 + 100, xori2, txt="Translate X distance")

    grd.to_file(os.path.join(TMPDIR, "g1_translate.roff"), fformat="roff_binary")
github equinor / xtgeo / src / xtgeo / grid3d / grid_property.py View on Github external
self._geometry = kwargs.get("grid", None)
        self._fracture = kwargs.get("fracture", False)

        self._dualporo = kwargs.get("dualporo", False)
        self._dualperm = kwargs.get("dualperm", False)
        self._codes = kwargs.get("codes", dict())  # code dictionary (for discrete)
        self._filesrc = None
        self._actnum_indices = None
        self._roxorigin = False  # true if the object comes from the ROXAPI
        self._roxar_dtype = kwargs.get("roxar_dtype", np.float32)

        self._values = kwargs.get("values", None)

        if len(args) == 1:
            # make instance through grid instance or file import
            if isinstance(args[0], xtgeo.grid3d.Grid):
                linkgeometry = kwargs.get("linkgeometry", False)
                _gridprop_etc.gridproperty_fromgrid(
                    self, args[0], linkgeometry=linkgeometry
                )

            elif isinstance(args[0], str):
                _gridprop_etc.gridproperty_fromfile(self, args[0], **kwargs)

        else:
            # make instance purely from kwargs spec
            _gridprop_etc.gridproperty_fromspec(self, **kwargs)
github equinor / xtgeo / examples / grid3d_print_init_csv.py View on Github external
def all_init_as_csv():
    """Get dataframes, print as CSV."""

    print("Loading Eclipse data {}".format(GRIDFILEROOT))
    grd = xtgeo.grid3d.Grid()
    grd.from_file(GRIDFILEROOT, fformat="eclipserun", initprops=INITPROPS)
    print("Get dataframes...")
    dfr = grd.dataframe(activeonly=True)

    print(dfr.head())
    print("Filter out columns with constant values...")
    dfr = dfr.iloc[:, ~np.isclose(0, dfr.var())]
    print(dfr.head())
    print("Write to file...")
    dfr.to_csv("mycsvdump.csv", index=False)