How to use the xtgeo.xyz.Polygons 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_plot / test_map.py View on Github external
def test_more_features_plot():
    """Map with some more features added, such as label rotation."""

    mysurf = RegularSurface()
    mysurf.from_file(SFILE1)

    myfaults = Polygons(PFILE1)

    # just make the instance, with a lot of defaults behind the scene
    myplot = Map()
    myplot.canvas(title="Label rotation")
    myplot.colormap = "gist_rainbow_r"
    myplot.plot_surface(mysurf, minvalue=1250, maxvalue=2200, xlabelrotation=45)

    myplot.plot_faults(myfaults)

    myplot.savefig(TD + "/map_more1.png")
github equinor / xtgeo / tests / test_grid3d / test_grid_vs_poly.py View on Github external
def test_grid_inactivate_inside():
    """Inactivate a grid inside polygons"""
    g1 = xtgeo.grid3d.Grid(reekgrid)

    p1 = xtgeo.xyz.Polygons(reekpoly)

    act1 = g1.get_actnum().values3d
    n1 = act1[7, 55, 1]
    assert n1 == 1

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

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

    # geom = g1.get_geometrics(return_dict=True)

    # myprop = g1.get_actnum()
    # layslice = xtgeo.plot.Grid3DSlice()
github equinor / xtgeo / tests / test_xyz / test_points_poly.py View on Github external
def test_rescale_polygon():
    """Take a polygons set and rescale/resample"""

    pol = Polygons(POLSET4)

    oldpol = pol.copy()
    oldpol.name = "ORIG"
    pol.rescale(100)
    pol.hlen()

    pol2 = Polygons(POLSET4)

    pol2.rescale(100, kind="slinear")
    pol2.name = "slinear"
    pol2.hlen()

    arr1 = pol.dataframe[pol.dhname].values
    arr2 = pol2.dataframe[pol2.dhname].values

    logger.info(
        "avg, min, max: POL simple %s %s %s vs slinear %s %s %s",
        arr1.mean(),
        arr1.min(),
        arr1.max(),
        arr2.mean(),
        arr2.min(),
        arr2.max(),
github equinor / xtgeo / tests / test_xyz / test_points_poly.py View on Github external
def test_polygon_filter_byid():
    """Filter a Polygon by a list of ID's"""

    pol = Polygons(POLSET3)

    assert pol.dataframe["POLY_ID"].iloc[0] == 0
    assert pol.dataframe["POLY_ID"].iloc[-1] == 3

    pol.filter_byid()
    assert pol.dataframe["POLY_ID"].iloc[-1] == 0

    pol = Polygons(POLSET3)
    pol.filter_byid([1, 3])

    assert pol.dataframe["POLY_ID"].iloc[0] == 1
    assert pol.dataframe["POLY_ID"].iloc[-1] == 3

    pol = Polygons(POLSET3)
    pol.filter_byid(2)
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]
    assert n2 == 0
github equinor / xtgeo / tests / test_xyz / test_points_poly.py View on Github external
mypoly = Polygons()

    mypoly.from_file(PFILE, fformat="xyz")

    z0 = mypoly.dataframe["Z_TVDSS"].values[0]

    tsetup.assert_almostequal(z0, 2266.996338, 0.001)

    logger.debug(mypoly.dataframe)

    mypoly.dataframe["Z_TVDSS"] += 100

    mypoly.to_file(TMPD + "/polygon_export.xyz", fformat="xyz")

    # reimport and check
    mypoly2 = Polygons(TMPD + "/polygon_export.xyz")

    tsetup.assert_almostequal(z0 + 100, mypoly2.dataframe["Z_TVDSS"].values[0], 0.001)
github equinor / xtgeo / tests / test_grid3d / test_grid_property.py View on Github external
def test_values_in_polygon():
    """Test replace values in polygons"""

    xprop = GridProperty()
    logger.info("Import roff...")
    grid = Grid(TESTFILE5)
    xprop.from_file(TESTFILE1, fformat="roff", name="PORO", grid=grid)
    poly = Polygons(polyfile)
    xprop.geometry = grid
    xorig = xprop.copy()

    xprop.operation_polygons(poly, 99, inside=True)
    tsetup.assert_almostequal(xprop.values.mean(), 25.1788, 0.01)

    xp2 = xorig.copy()
    xp2.values *= 100
    xp2.continuous_to_discrete()
    xp2.set_inside(poly, 44)

    xp2.dtype = np.uint8
    xp2.set_inside(poly, 44)
    print(xp2.values)

    xp2.dtype = np.uint16
github equinor / xtgeo / tests / test_well / test_well_to_polygons.py View on Github external
def test_well_to_polygons():
    """Import well from file and amke a Polygons object"""

    mywell = xtgeo.Well(WFILE)

    poly = mywell.get_polygons()

    assert isinstance(poly, xtgeo.xyz.Polygons)
    print(poly.dataframe)

    assert mywell.dataframe["X_UTME"].mean() == poly.dataframe["X_UTME"].mean()
github equinor / xtgeo / src / xtgeo / plot / xsection.py View on Github external
ax.plot(self.fence[:, 0], self.fence[:, 1], linewidth=1, c="black")
            ax.annotate("A", xy=(self.fence[0, 0], self.fence[0, 1]), fontsize=8)
            ax.annotate("B", xy=(self.fence[-1, 0], self.fence[-1, 1]), fontsize=8)
            ax.set_aspect("equal", "datalim")

            left, right = ax.get_xlim()
            xdiff = right - left
            bottom, top = ax.get_ylim()
            ydiff = top - bottom

            ax.set_xlim(left - (expand - 1.0) * xdiff, right + (expand - 1.0) * xdiff)
            ax.set_ylim(bottom - (expand - 1.0) * ydiff, top + (expand - 1.0) * ydiff)
        if otherwells:
            for poly in otherwells:
                if not isinstance(poly, Polygons):
                    xtg.warn(
                        " not a Polygons instance, but "
                        "a {}".format(type(poly))
                    )
                    continue
                if poly.name == self._well.xwellname:
                    continue
                xwp = poly.dataframe[poly.xname].values
                ywp = poly.dataframe[poly.yname].values
                ax.plot(xwp, ywp, linewidth=1, c="grey")
                ax.annotate(poly.name, xy=(xwp[-1], ywp[-1]), color="grey", size=5)
github equinor / xtgeo / src / xtgeo / xyz / _xyz_oper.py View on Github external
'Inside' several polygons will become a union, while 'outside' polygons
    will be the intersection.

    The "where" filter is reserved for future use.
    """

    logger.warning("Where is not imeplented: %s", where)

    oper = {"set": 1, "add": 2, "sub": 3, "mul": 4, "div": 5, "eli": 11}

    insidevalue = 0
    if inside:
        insidevalue = 1

    logger.info("Operations of points inside polygon(s)...")
    if not isinstance(poly, xtgeo.xyz.Polygons):
        raise ValueError("The poly input is not a Polygons instance")

    idgroups = poly.dataframe.groupby(poly.pname)

    xcor = self._df[self.xname].values
    ycor = self._df[self.yname].values
    zcor = self._df[self.zname].values

    usepoly = False
    if isinstance(value, str) and value == "poly":
        usepoly = True

    for id_, grp in idgroups:
        pxcor = grp[poly.xname].values
        pycor = grp[poly.yname].values
        pvalue = value