def get_xy_value_from_ij(self, iloc, jloc, zvalues=None): """Find X Y value from I J index""" if zvalues is None: zvalues = self.get_values1d() if 1 <= iloc <= self.ncol and 1 <= jloc <= self.nrow: ier, xval, yval, value = _cxtgeo.surf_xyz_from_ij( iloc, jloc, self.xori, self.xinc, self.yori, self.yinc, self.ncol, self.nrow, self._yflip, self.rotation, zvalues, 0, ) if ier != 0: raise XTGeoCLibError( f"Error in surf_xyz_from_ij, error code: {ier}") else: raise ValueError("Index i and/or j out of bounds") if value > xtgeo.UNDEF_LIMIT: value = None return xval, yval, value
def _export_segy_xtgeo(self, sfile): """Export SEGY via XTGeo internal C routine.""" values1d = self.values.reshape(-1) ilinesp = _cxtgeo.new_intarray(len(self._ilines)) xlinesp = _cxtgeo.new_intarray(len(self._xlines)) tracidp = _cxtgeo.new_intarray(self.ncol * self.nrow) ilns = self._ilines.astype(np.int32) xlns = self._xlines.astype(np.int32) trid = self._traceidcodes.flatten().astype(np.int32) _cxtgeo.swig_numpy_to_carr_i1d(ilns, ilinesp) _cxtgeo.swig_numpy_to_carr_i1d(xlns, xlinesp) _cxtgeo.swig_numpy_to_carr_i1d(trid, tracidp) status = _cxtgeo.cube_export_segy( sfile, self.ncol, self.nrow, self.nlay, values1d, self.xori, self.xinc, self.yori, self.yinc, self.zori, self.zinc, self.rotation, self.yflip, 1, ilinesp, xlinesp, tracidp, 0, ) if status != 0: raise XTGeoCLibError("Error when exporting to SEGY (xtgeo engine)") _cxtgeo.delete_intarray(ilinesp) _cxtgeo.delete_intarray(xlinesp)
def resample(self, other, sampling="nearest", outside_value=None): """Resample another cube to the current self""" # TODO: traceidcodes values1a = self.values.reshape(-1) values2a = other.values.reshape(-1) logger.info("Resampling, using %s...", sampling) ier = _cxtgeo.cube_resample_cube( self.ncol, self.nrow, self.nlay, self.xori, self.xinc, self.yori, self.yinc, self.zori, self.zinc, self.rotation, self.yflip, values1a, other.ncol, other.nrow, other.nlay, other.xori, other.xinc, other.yori, other.yinc, other.zori, other.zinc, other.rotation, other.yflip, values2a, 1 if sampling == "trilinear" else 0, 0 if outside_value is None else 1, 0 if outside_value is None else outside_value, ) if ier == -4: warnings.warn("Less than 10% of origonal cube sampled", RuntimeWarning) elif ier != 0: raise XTGeoCLibError("cube_resample_cube failed to complete")
def get_xy_value_from_ij(self, iloc, jloc, ixline=False, zerobased=False): """Find X Y value from I J index, or corresponding inline/xline""" # assumes that inline follows I and xlines follows J iuse = iloc juse = jloc if zerobased: iuse = iuse + 1 juse = juse + 1 if ixline: ilst = self.ilines.tolist() jlst = self.xlines.tolist() iuse = ilst.index(iloc) + 1 juse = jlst.index(jloc) + 1 if 1 <= iuse <= self.ncol and 1 <= juse <= self.nrow: ier, xval, yval = _cxtgeo.cube_xy_from_ij( iuse, juse, self.xori, self.xinc, self.yori, self.yinc, self.ncol, self.nrow, self._yflip, self.rotation, 0, ) if ier != 0: raise XTGeoCLibError( f"cube_xy_from_ij failed with error code: {ier}") else: raise ValueError("Index i and/or j out of bounds") return xval, yval
def point_in_tetrahedron(x0, y0, z0, vertices): """Check if point P0 is inside a tetrahedron. Args: x0 (double): X xoord of point P0 y0 (double): Y xoord of point P0 z0 (double): Z xoord of point P0 vertices (list-like): Vertices as e.g. numpy array [[x1, y1, z1], [x2, y2, ...] Returns: True of inside or on edge, False else """ vertices = np.array(vertices, dtype=np.float64) status = _cxtgeo.x_point_in_tetrahedron(x0, y0, z0, vertices) if status == 1: raise XTGeoCLibError("Error in x_point_in_tetrahedron") if status == 100: return True return False
def get_xy_values(self, order="C", asmasked=False): """Get X Y coordinate values as numpy 2D arrays.""" nno = self.ncol * self.nrow ier, xvals, yvals = _cxtgeo.surf_xy_as_values( self.xori, self.xinc, self.yori, self.yinc * self.yflip, self.ncol, self.nrow, self.rotation, nno, nno, 0, ) if ier != 0: raise XTGeoCLibError(f"Error in surf_xy_as_values, error code: {ier}") # reshape xvals = xvals.reshape((self.ncol, self.nrow)) yvals = yvals.reshape((self.ncol, self.nrow)) if order == "F": xvals = np.array(xvals, order="F") yvals = np.array(yvals, order="F") if asmasked: tmpv = ma.filled(self.values, fill_value=np.nan) tmpv = np.array(tmpv, order=order) tmpv = ma.masked_invalid(tmpv) mymask = ma.getmaskarray(tmpv) xvals = ma.array(xvals, mask=mymask, order=order) yvals = ma.array(yvals, mask=mymask, order=order) return xvals, yvals