def test_snap_to_surface(): """Import XYZ points from file.""" mypoints = xtgeo.Points(PFILE3) assert mypoints.nrow == 20 surf1 = xtgeo.RegularSurface(SFILE1A) mypoints.snap_surface(surf1) assert mypoints.nrow == 11 tsetup.assert_almostequal(mypoints.dataframe["Z_TVDSS"].mean(), 1661.45, 0.01) # repeat,using surface whithg rotaion and partial masks mypoints = xtgeo.Points(PFILE3) surf2 = xtgeo.RegularSurface(SFILE2A) mypoints.snap_surface(surf2) assert mypoints.nrow == 12 tsetup.assert_almostequal(mypoints.dataframe["Z_TVDSS"].mean(), 1687.45, 0.01) # alternative; keep values as is using activeobnly=False mypoints = xtgeo.Points(PFILE3) mypoints.snap_surface(surf2, activeonly=False) assert mypoints.nrow == 20 tsetup.assert_almostequal(mypoints.dataframe["Z_TVDSS"].mean(), 1012.47, 0.01) mypoints.to_file(join(TMPD, "snapped_point.poi"))
def test_get_ijk_from_points_banalcase2(): """Testing getting IJK coordinates from points on a perfect case case""" g1 = xtgeo.grid3d.Grid(BANALCASE2) pointset = [ (50, 50, -0.01), # -1, -1, -1 (50, 50, 0.000), # 1, 1, 1 (50, 50, 0.990), # 1, 1, 1 (50, 50, 1.200), # 1, 1, 1 # could be 1,1,2 (50, 50, 1.400), # 1, 1, 1 # could be 1,1,2 (50, 50, 1.600), # 1, 1, 1 # could be 1,1,2 (50, 50, 1.900), # 1, 1, 1 # could be 1,1,2 (50, 50, 2.100), # 1, 1, 3 (50, 50, 2.600), # 1, 1, 3 ] po = xtgeo.Points(pointset) ijk = g1.get_ijk_from_points(po) assert ijk["KZ"][2] == 1 pointset = [ (25, 25, -0.01), # -1, -1, -1 (25, 25, 0.000), # 1, 1, 1 (25, 25, 0.990), # 1, 1, 1 (25, 25, 1.200), # 1, 1, 2 (25, 25, 1.400), # 1, 1, 2 (25, 25, 1.600), # 1, 1, 2 (25, 25, 1.900), # 1, 1, 2 (25, 25, 2.100), # 1, 1, 3 (25, 25, 2.600), # 1, 1, 3 ] po = xtgeo.Points(pointset) ijk = g1.get_ijk_from_points(po) assert ijk["KZ"][5] == 2 pointset = [ (0, 0, -0.01), # -1, -1, -1 (0, 0, 0.000), # 1, 1, 1 (0, 0, 0.990), # 1, 1, 1 (0, 0, 1.200), # 1, 1, 2 (0, 0, 1.400), # 1, 1, 2 (0, 0, 1.600), # 1, 1, 2 (0, 0, 1.900), # 1, 1, 2 (0, 0, 2.100), # 1, 1, 3 (0, 0, 2.600), # 1, 1, 3 ] po = xtgeo.Points(pointset) ijk = g1.get_ijk_from_points(po) assert ijk["KZ"][7] == 3
def test_get_ijk_from_points_small(): """Test IJK getting in small grid, test for active or not cells""" g1 = xtgeo.grid3d.Grid(SMALL1) pointset = [ (1.5, 1.5, 1000.5), # 2, 2, 1 is active (3.5, 2.5, 1000.5), # 4, 3, 1 is inactive, but dualporo is active ] po = xtgeo.Points(pointset) ijk = g1.get_ijk_from_points(po) assert ijk["JY"][0] == 2 assert ijk["JY"][1] == -1 # activeonly False ijk = g1.get_ijk_from_points(po, activeonly=False) assert ijk["JY"][1] == 3 # dualporo grid g1 = xtgeo.grid3d.Grid(SMALL2) ijk = g1.get_ijk_from_points(po, activeonly=False) assert ijk["JY"][1] == 3
def test_point_in_cell_compare_rms(): """Test IJK in cells, compare with a list made in RMS IPL""" # from RMS pointset = pd.read_csv(QCFIL1, skiprows=3) p1 = xtgeo.Points() attrs = {"IX": "I", "JY": "J", "KZ": "K"} p1.from_dataframe(pointset, east="X", north="Y", tvdmsl="Z", attributes=attrs) grd = xtgeo.Grid(QCGRID) dfr = grd.get_ijk_from_points(p1) for cname in ("IX", "JY", "KZ"): list1 = p1.dataframe[cname].tolist() list2 = dfr[cname].tolist() nall = len(list1) suc = 0 for ino, item in enumerate(list1): if item == list2[ino]: suc += 1 succesrate = suc / nall print(cname, succesrate, suc, nall)
def make_map(): """Make a map of poro or perm in lowermost K layer of the grid""" # read grid grd = xtgeo.grid_from_file(GNAMEROOT + ".EGRID") _ = xtgeo.gridproperty_from_file(GNAMEROOT + ".INIT", name="PORO", grid=grd) df = grd.dataframe() # make a map from the grid geometry to be used as a template surf = xtgeo.RegularSurface() surf.from_grid3d(grd) # get only bottom layer: lastlayer = df["KZ"].max() df = df[df["KZ"] == lastlayer].reset_index() # prepare as input to a Points dataframe (3 columns X Y Z) df = df[["X_UTME", "Y_UTMN", "PORO"]].copy() points = xtgeo.Points() points.zname = "PORO" points.dataframe = df # do gridding: surf.gridding(points) # optional plot surf.quickplot()
def fixture_points(): """Create an xtgeo points instance.""" logger.info("Ran %s", inspect.currentframe().f_code.co_name) return xtgeo.Points( [ [1, 22, 3, "WELLA"], [6, 25, 4, "WELLB"], [8, 27, 6, "WELLB"], [1, 22, 3, "WELLC"], ], attributes={"WellName": "str"}, )
def get_surface_picks(self, surf): """get Surface picks""" xcor = self._df["X_UTME"].values ycor = self._df["Y_UTMN"].values zcor = self._df["Z_TVDSS"].values if self.mdlogname: mcor = self._df[self.mdlogname].values else: mcor = np.zeros(xcor.size, dtype=np.float64) + xtgeo.UNDEF nval, xres, yres, zres, mres, dres = _cxtgeo.well_surf_picks( xcor, ycor, zcor, mcor, surf.ncol, surf.nrow, surf.xori, surf.yori, surf.xinc, surf.yinc, surf.yflip, surf.rotation, surf.npvalues1d, xcor.size, xcor.size, xcor.size, xcor.size, xcor.size, ) if nval > 0: poi = xtgeo.Points() mres[mres > xtgeo.UNDEF_LIMIT] = np.nan res = OrderedDict() res[poi.xname] = xres[:nval] res[poi.yname] = yres[:nval] res[poi.zname] = zres[:nval] if self.mdlogname: res[self.mdlogname] = mres[:nval] res["DIRECTION"] = dres[:nval] res["WELLNAME"] = self.wellname poi.dataframe = pd.DataFrame.from_dict(res) return poi return None
def test_get_ijk_from_points_tricky(): """Testing getting IJK coordinates from points on a tricky case""" g1 = xtgeo.grid3d.Grid(DROGON) pointset = [ (465100.100000, 5931340.000000, 1681.28772), # 1, 2, 1 ] po = xtgeo.Points(pointset) ijk = g1.get_ijk_from_points(po) assert ijk["IX"][0] == 110 # 110 171/172 assert ijk["JY"][0] == 171 # 110 171/172
def test_get_ijk_from_points(): """Testing getting IJK coordinates from points""" g1 = xtgeo.grid3d.Grid(REEKGRID) pointset = [ (456620.790918, 5.935660e06, 1727.649124), # 1, 1, 1 (456620.806270, 5.935660e06, 1744.557755), # 1, 1, 5 (467096.108653, 5.930145e06, 1812.760864), # 40, 64, 14 (333333, 5555555, 1333), # outside (459168.0442550212, 5931614.347020548, 1715.4637298583984), # 2, 31, 14 (464266.1687414392, 5933844.674959661, 1742.2762298583984), # 36, 35, 11 ] po = xtgeo.Points(pointset) ijk = g1.get_ijk_from_points(po) print(ijk) assert ijk["IX"][0] == 1 assert ijk["IX"][1] == 1 assert ijk["IX"][2] == 40 assert ijk["JY"][0] == 1 assert ijk["KZ"][0] == 1 assert ijk["KZ"][1] == 5 assert ijk["KZ"][2] == 14 assert ijk["KZ"][3] == -1 assert ijk["KZ"][4] == 14 assert ijk["KZ"][5] == 11 if g1.ijk_handedness == "right": g1.ijk_handedness = "left" g1._tmp = {} ijk = g1.get_ijk_from_points(po) print(ijk) assert ijk["IX"][0] == 1 assert ijk["IX"][1] == 1 assert ijk["IX"][2] == 40 assert ijk["JY"][0] == 64
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 create_surf_distance_log(self, surf, name): """Create a log which is vertical distance from a RegularSurface.""" logger.info("Create a log which is distance to surface") if not isinstance(surf, xtgeo.RegularSurface): raise ValueError("Input surface is not a RegularSurface instance.") # make a Points instance since points has the snap zvalues = self.dataframe["Z_TVDSS"] points = xtgeo.Points() points.dataframe = self.dataframe.iloc[:, 0:3] points.snap_surface(surf) snapped = points.dataframe["Z_TVDSS"] diff = snapped - zvalues # create log (default is force overwrite if it exists) self.create_log(name) self.dataframe[name] = diff
def test_get_ijk_from_points_full(): """Testing getting IJK coordinates from points, for all cells""" g1 = xtgeo.grid3d.Grid(REEKGRID) df1 = g1.get_dataframe(ijk=True, xyz=False) df2 = g1.get_dataframe(ijk=False, xyz=True) po = xtgeo.Points() po.dataframe = df2 print(po.dataframe) print(df1) ijk = g1.get_ijk_from_points(po, includepoints=False) print(ijk) ijk_i = ijk["IX"].values.tolist() ijk_j = ijk["JY"].values.tolist() ijk_k = ijk["KZ"].values.tolist() df1_i = df1["IX"].values.tolist() df1_j = df1["JY"].values.tolist() df1_k = df1["KZ"].values.tolist() notok = 0 allc = 0 for inum, _val in enumerate(ijk_i): allc += 1 x = df2["X_UTME"].values[inum] y = df2["Y_UTMN"].values[inum] z = df2["Z_TVDSS"].values[inum] ijkt = tuple((ijk_i[inum], ijk_j[inum], ijk_k[inum])) df1t = tuple((df1_i[inum], df1_j[inum], df1_k[inum])) if ijkt != df1t: notok += 1 logger.info("%s %s %s: input %s vs output %s", x, y, z, ijkt, df1t) fails = notok / allc * 100 print("Percent failing: ", fails) assert fails < 0.5 # < 0.5% deviation; x_chk_in_cell ~4 % error!
def test_get_ijk_from_points_banalcase3(): """Testing getting IJK coordinates from points on a perfect case case""" g1 = xtgeo.grid3d.Grid(BANALCASE3) pointset = [ (50, 50, -0.01), # outside (50, 50, 0.000), # 1, 1, 1 (50, 50, 0.990), # 1, 1, 1 (50, 50, 1.200), # 1, 1, 1 (50, 50, 1.400), # 1, 1, 1 (50, 50, 1.600), # 1, 1, 2 (50, 50, 1.900), # 1, 1, 2 (50, 50, 2.100), # 1, 1, 3 (50, 50, 2.600), # 1, 1, 3 ] po = xtgeo.Points(pointset) ijk = g1.get_ijk_from_points(po) assert ijk["KZ"][7] == 3
def _make_ijk_from_grid_v2(self, grid, grid_id="", activeonly=True): """ Getting IJK from a grid and make as well logs. This is a newer version, using grid.get_ijk_from_points which in turn use the from C method x_chk_point_in_hexahedron, while v1 use the x_chk_point_in_cell. This one is believed to be more precise! """ # establish a Points instance and make points dataframe from well trajectory X Y Z wpoints = xtgeo.Points() wpdf = self.dataframe.loc[:, ["X_UTME", "Y_UTMN", "Z_TVDSS"]].copy() wpoints.dataframe = wpdf wpoints.dataframe.reset_index(inplace=True, drop=True) # column names cna = ("ICELL" + grid_id, "JCELL" + grid_id, "KCELL" + grid_id) df = grid.get_ijk_from_points( wpoints, activeonly=activeonly, zerobased=False, dataframe=True, includepoints=False, columnnames=cna, fmt="float", undef=np.nan, ) # The resulting df shall have same length as the well's dataframe, # but the well index may not start from one. So first ignore index, then # re-establish wellindex = self.dataframe.index newdf = pd.concat([self.dataframe.reset_index(drop=True), df], axis=1) newdf.index = wellindex self.dataframe = newdf