Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_reek1():
"""Test XSect for a Reek well."""
myfield = xtgeo.Polygons()
myfield.from_file(USEFILE3, fformat="xyz")
mywells = []
wnames = glob.glob(USEFILE4)
wnames.sort()
for wname in wnames:
mywell = xtgeo.Well(wname)
mywells.append(mywell)
logger.info("Wells are read...")
mysurfaces = []
surfnames = glob.glob(USEFILE5)
surfnames.sort()
for fname in surfnames:
mysurf = xtgeo.RegularSurface()
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()
def test_get_randomline_frompolygon():
fence = xtgeo.Polygons(FENCE1)
xs = xtgeo.RegularSurface(TESTSET1)
# get the polygon
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=20, nextend=5, asnumpy=True)
arr = xs.get_randomline(fspec)
x = arr[:, 0]
y = arr[:, 1]
print(arr)
print(arr.shape)
def test_cube_randomline():
"""Import a cube, and compute a randomline given a simple Polygon"""
# import matplotlib.pyplot as plt
incube = Cube(SFILE4)
# make a polyline with two points
dfr = pd.DataFrame(
np.array([[778133, 6737650, 2000, 1], [776880, 6738820, 2000, 1]]),
columns=["X_UTME", "Y_UTMN", "Z_TVDSS", "POLY_ID"],
)
poly = xtgeo.Polygons()
poly.dataframe = dfr
logger.info("Generate random line...")
hmin, hmax, vmin, vmax, random = incube.get_randomline(poly)
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)
def get_fencespec(coords):
"""Create a XTGeo fence spec from polyline coordinates"""
poly = xtgeo.Polygons()
poly.dataframe = pd.DataFrame(
[
{
"X_UTME": c[1],
"Y_UTMN": c[0],
"Z_TVDSS": 0,
"POLY_ID": 1,
"NAME": "polyline",
}
for c in coords
]
)
return poly.get_fence(asnumpy=True)
def copy(self, stype):
"""Returns a a deep copy of an instance"""
if stype == "polygons":
mycopy = xtgeo.Polygons()
else:
mycopy = xtgeo.Points()
mycopy._df = self._df.copy()
mycopy._ispolygons = self._ispolygons
mycopy._xname = self._xname
mycopy._yname = self._yname
mycopy._zname = self._zname
mycopy._pname = self._pname
mycopy._mname = self._mname
mycopy._filescr = self._filesrc = None
mycopy._attrs = deepcopy(self._attrs)
return mycopy
def _generic_length(
self, gname="G_CUMLEN", dgname="G_DELTALEN", atindex=0, mode2d=True
):
"""Get the true or horizontal distance (cum/delta) between points in polygons.
The properties gname and ghname will be updated.
Note that Dxx at first location will be set equal to that of location 1
"""
# Potential todo: Add an option that dH never gets 0.0 to avoid numerical trouble
# for e.g. rescale?
if not isinstance(self, xtgeo.Polygons):
raise ValueError("Input object of wrong data type, must be Polygons")
# delete existing self.hname and self.dhname columns
self.delete_columns([gname, dgname])
idgroups = self._df.groupby(self.pname)
gdist = np.array([])
dgdist = np.array([])
for _id, grp in idgroups:
ier, tlenv, dtlenv, hlenv, dhlenv = _cxtgeo.pol_geometrics(
grp[self.xname].values,
grp[self.yname].values,
grp[self.zname].values,
len(grp),
len(grp),
def get_polygons(self):
"""Return a Polygons object from the well trajectory.
.. versionadded:: 2.1.0
"""
dfr = self._df.copy()
keep = ("X_UTME", "Y_UTMN", "Z_TVDSS")
for col in dfr.columns:
if col not in keep:
dfr.drop(labels=col, axis=1, inplace=True)
dfr["POLY_ID"] = 1
dfr["NAME"] = self.xwellname
poly = xtgeo.Polygons()
poly.dataframe = dfr
poly.name = self.xwellname
return poly