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) if XTGSHOW: import matplotlib.pyplot as plt plt.figure() plt.plot(x, y) plt.gca().invert_yaxis() plt.show()
def test_cube_randomline(show_plot): """Import a cube, and compute a randomline given a simple Polygon""" incube = Cube(SFILE4) poly = xtgeo.Polygons() poly.from_list([[778133, 6737650, 2000, 1], [776880, 6738820, 2000, 1]]) logger.info("Generate random line...") hmin, hmax, vmin, vmax, random = incube.get_randomline(poly) assert hmin == pytest.approx(-15.7, 0.1) assert random.mean() == pytest.approx(-12.5, 0.1) if show_plot: import matplotlib.pyplot as plt plt.figure() plt.imshow( random, cmap="seismic", interpolation="sinc", extent=(hmin, hmax, vmax, vmin), ) plt.axis("tight") plt.colorbar() plt.show()
def get_polygons(self, skipname=False): """Return a Polygons object from the well trajectory. Args: skipname (bool): If True then name column is omitted .. versionadded:: 2.1 .. versionchanged:: 2.13 Added `skipname` key """ 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 if not skipname: dfr["NAME"] = self.xwellname poly = xtgeo.Polygons() poly.dataframe = dfr poly.name = self.xwellname return poly
def test_get_randomline_frompolygon(xtgshow): """Test randomline with both bilinear and nearest sampling for surfaces.""" fence = xtgeo.Polygons(FENCE1) xs = xtgeo.RegularSurface(TESTSET1) # get the polygon fspec = fence.get_fence(distance=10, nextend=2, asnumpy=False) assert_almostequal(fspec.dataframe[fspec.dhname][4], 10, 1) fspec = fence.get_fence(distance=20, nextend=5, asnumpy=True) arr1 = xs.get_randomline(fspec) arr2 = xs.get_randomline(fspec, sampling="nearest") x = arr1[:, 0] y1 = arr1[:, 1] y2 = arr2[:, 1] assert y1.mean() == pytest.approx(1706.7514, abs=0.001) assert y2.mean() == pytest.approx(1706.6995, abs=0.001) if xtgshow: import matplotlib.pyplot as plt plt.figure() plt.plot(x, y1) plt.plot(x, y2) plt.gca().invert_yaxis() plt.show()
def fixture_polygons(): """Create an xtgeo polygons.""" logger.info("Ran %s", inspect.currentframe().f_code.co_name) return xtgeo.Polygons([ [1, 22, 3, 0], [6, 25, 4, 0], [8, 27, 6, 0], [1, 22, 3, 0], ])
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 get_fencespec_from_polyline(coords: List, distance: float, atleast: int, nextend: Union[float, int]) -> np.ndarray: """Create a fence specification from polyline coordinates""" poly = xtgeo.Polygons() poly.dataframe = pd.DataFrame([{ "X_UTME": c[0], "Y_UTMN": c[1], "Z_TVDSS": 0, "POLY_ID": 1, "NAME": "polyline", } for c in coords]) return poly.get_fence(distance=distance, atleast=atleast, nextend=nextend, asnumpy=True)
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 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_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 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 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
def get_fencespec(polyline): """Create a XTGeo fence spec from polyline coordinates Args: polyline: Polyline drawn in map view Returns: XTGeo fence of polyline """ poly = xtgeo.Polygons() poly.dataframe = pd.DataFrame( [ { "X_UTME": coordinates[1], "Y_UTMN": coordinates[0], "Z_TVDSS": 0, "POLY_ID": 1, "NAME": "polyline", } for coordinates in polyline ] ) return poly.get_fence(asnumpy=True)
import xtgeo import matplotlib.pyplot as plt x = xtgeo.Polygons("../xtgeo-testdata/polygons/etc/well16.pol") y = x.copy() y.rescale(10) IDGROUPSX = x.dataframe.groupby(x.pname) IDGROUPSY = y.dataframe.groupby(y.pname) plt.figure(figsize=(7, 7)) for idx, grp in IDGROUPSX: plt.plot(grp[x.xname].values, grp[x.yname].values, label=str(idx)) for idx, grp in IDGROUPSY: plt.plot(grp[y.xname].values, grp[y.yname].values, label=str(idx)) plt.show() print(grp[y.dhname].min(), grp[y.dhname].max()) print(y.dataframe)
def test_reek1(tmpdir, generate_plot): """Test XSect for a Reek well.""" myfield = xtgeo.Polygons() myfield.from_file(USEFILE3, fformat="xyz") mywells = [] wnames = glob.glob(str(USEFILE4)) wnames.sort() for wname in wnames: mywell = xtgeo.Well(wname) mywells.append(mywell) logger.info("Wells are read...") mysurfaces = [] surfnames = glob.glob(str(USEFILE5)) surfnames.sort() for fname in surfnames: mysurf = xtgeo.RegularSurface() mysurf.from_file(fname) mysurfaces.append(mysurf) # Troll lobes mylobes = [] surfnames = glob.glob(str(USEFILE5)) surfnames.sort() for fname in surfnames: mysurf = xtgeo.RegularSurface() mysurf.from_file(fname) mylobes.append(mysurf) for wo in mywells: myplot = XSection( zmin=1500, zmax=1700, well=wo, surfaces=mysurfaces, zonelogshift=-1, outline=myfield, ) myplot.canvas( title=wo.truewellname, subtitle="Before my corrections", infotext="Heisan sveisan", figscaling=1.2, ) # myplot.colortable('xtgeo') myplot.plot_surfaces(fill=True) myplot.plot_surfaces( surfaces=mylobes, fill=False, linewidth=4, legendtitle="Lobes", fancyline=True, ) myplot.plot_well(zonelogname="Zonelog") myplot.plot_wellmap() myplot.plot_map() if generate_plot: myplot.savefig(join(tmpdir, "xsect2a.svg"), fformat="svg", last=False) myplot.savefig(join(tmpdir, "xsect2a.png"), fformat="png")