def swapaxes(self): """Swap the axes inline vs xline, keep origin.""" ncol = _cxtgeo.new_intpointer() nrow = _cxtgeo.new_intpointer() yflip = _cxtgeo.new_intpointer() xinc = _cxtgeo.new_doublepointer() yinc = _cxtgeo.new_doublepointer() rota = _cxtgeo.new_doublepointer() _cxtgeo.intpointer_assign(ncol, self._ncol) _cxtgeo.intpointer_assign(nrow, self._nrow) _cxtgeo.intpointer_assign(yflip, self._yflip) _cxtgeo.doublepointer_assign(xinc, self._xinc) _cxtgeo.doublepointer_assign(yinc, self._yinc) _cxtgeo.doublepointer_assign(rota, self._rotation) values1d = self.values.reshape(-1) traceid1d = self._traceidcodes.reshape(-1) ier = _cxtgeo.cube_swapaxes( ncol, nrow, self.nlay, yflip, self.xori, xinc, self.yori, yinc, rota, values1d, traceid1d, 0, ) if ier != 0: raise Exception self._ncol = _cxtgeo.intpointer_value(ncol) self._nrow = _cxtgeo.intpointer_value(nrow) self._yflip = _cxtgeo.intpointer_value(yflip) self._xinc = _cxtgeo.doublepointer_value(xinc) self._yinc = _cxtgeo.doublepointer_value(yinc) self._rotation = _cxtgeo.doublepointer_value(rota) ilines = self._xlines.copy() xlines = self._ilines.copy() self._xlines = xlines self._ilines = ilines self._traceidcodes = traceid1d.reshape((self._ncol, self._nrow)) self._values = values1d.reshape((self._ncol, self._nrow, self.nlay))
def swapaxes(self): """Swap the axes columns vs rows, keep origin. Will change yflip.""" ncol = _cxtgeo.new_intpointer() nrow = _cxtgeo.new_intpointer() yflip = _cxtgeo.new_intpointer() xinc = _cxtgeo.new_doublepointer() yinc = _cxtgeo.new_doublepointer() rota = _cxtgeo.new_doublepointer() _cxtgeo.intpointer_assign(ncol, self._ncol) _cxtgeo.intpointer_assign(nrow, self._nrow) _cxtgeo.intpointer_assign(yflip, self._yflip) _cxtgeo.doublepointer_assign(xinc, self._xinc) _cxtgeo.doublepointer_assign(yinc, self._yinc) _cxtgeo.doublepointer_assign(rota, self._rotation) val = self.get_values1d(fill_value=xtgeo.UNDEF) ier = _cxtgeo.surf_swapaxes( ncol, nrow, yflip, self.xori, xinc, self.yori, yinc, rota, val, 0 ) if ier != 0: raise RuntimeError( "Unspecied runtime error from {}: Code: {}".format(__name__, ier) ) self._ncol = _cxtgeo.intpointer_value(ncol) self._nrow = _cxtgeo.intpointer_value(nrow) self._yflip = _cxtgeo.intpointer_value(yflip) self._xinc = _cxtgeo.doublepointer_value(xinc) self._yinc = _cxtgeo.doublepointer_value(yinc) self._rotation = _cxtgeo.doublepointer_value(rota) ilines = self._xlines.copy() xlines = self._ilines.copy() self._ilines = ilines self._xlines = xlines self.values = val # reshaping and masking is done in self.values
def vectorinfo2(x1, x2, y1, y2, option=1): """ Get length and angles from 2 points in space (2D plane). Option = 1 gives normal school angle (counterclock from X) """ # _cxtgeo.xtg_verbose_file("NONE") lenp = _cxtgeo.new_doublepointer() radp = _cxtgeo.new_doublepointer() degp = _cxtgeo.new_doublepointer() _cxtgeo.x_vector_info2(x1, x2, y1, y2, lenp, radp, degp, option, DBG) llen = _cxtgeo.doublepointer_value(lenp) rad = _cxtgeo.doublepointer_value(radp) deg = _cxtgeo.doublepointer_value(degp) return llen, rad, deg
def _import_segy_xtgeo(sfile, scanheadermode=False, scantracemode=False, outfile=None): """Import SEGY via XTGeo's C library. OLD NOT UPDATED!! Args: sfile (str): File name of SEGY file scanheadermode (bool, optional): If true, will scan header scantracemode (bool, optional): If true, will scan trace headers outfile (str, optional): Output file for scan dump (default None) Returns: A dictionary with relevant data. """ # pylint: disable=too-many-statements, too-many-locals sdata = dict() logger.info("Import SEGY via XTGeo CLIB") if outfile is None: outfile = "/dev/null" ptr_gn_bitsheader = _cxtgeo.new_intpointer() ptr_gn_formatcode = _cxtgeo.new_intpointer() ptr_gf_segyformat = _cxtgeo.new_floatpointer() ptr_gn_samplespertrace = _cxtgeo.new_intpointer() ptr_gn_measuresystem = _cxtgeo.new_intpointer() option = 0 if scantracemode: option = 0 if scanheadermode: option = 1 _cxtgeo.cube_scan_segy_hdr( sfile, ptr_gn_bitsheader, ptr_gn_formatcode, ptr_gf_segyformat, ptr_gn_samplespertrace, ptr_gn_measuresystem, option, outfile, ) # get values gn_bitsheader = _cxtgeo.intpointer_value(ptr_gn_bitsheader) gn_formatcode = _cxtgeo.intpointer_value(ptr_gn_formatcode) gf_segyformat = _cxtgeo.floatpointer_value(ptr_gf_segyformat) gn_samplespertrace = _cxtgeo.intpointer_value(ptr_gn_samplespertrace) if scanheadermode: logger.info("Scan SEGY header ... %s bytes ... DONE", gn_bitsheader) return None # next is to scan first and last trace, in order to allocate # cube size ptr_ncol = _cxtgeo.new_intpointer() ptr_nrow = _cxtgeo.new_intpointer() ptr_nlay = _cxtgeo.new_intpointer() ptr_xori = _cxtgeo.new_doublepointer() ptr_yori = _cxtgeo.new_doublepointer() ptr_zori = _cxtgeo.new_doublepointer() ptr_xinc = _cxtgeo.new_doublepointer() ptr_yinc = _cxtgeo.new_doublepointer() ptr_zinc = _cxtgeo.new_doublepointer() ptr_rotation = _cxtgeo.new_doublepointer() ptr_minval = _cxtgeo.new_doublepointer() ptr_maxval = _cxtgeo.new_doublepointer() ptr_dummy = _cxtgeo.new_floatpointer() ptr_yflip = _cxtgeo.new_intpointer() ptr_zflip = _cxtgeo.new_intpointer() optscan = 1 if scantracemode: option = 1 logger.debug("Scan via C wrapper...") _cxtgeo.cube_import_segy( sfile, # input gn_bitsheader, gn_formatcode, gf_segyformat, gn_samplespertrace, # result (as pointers) ptr_ncol, ptr_nrow, ptr_nlay, ptr_dummy, ptr_xori, ptr_xinc, ptr_yori, ptr_yinc, ptr_zori, ptr_zinc, ptr_rotation, ptr_yflip, ptr_zflip, ptr_minval, ptr_maxval, # options optscan, option, outfile, ) logger.debug("Scan via C wrapper... done") ncol = _cxtgeo.intpointer_value(ptr_ncol) nrow = _cxtgeo.intpointer_value(ptr_nrow) nlay = _cxtgeo.intpointer_value(ptr_nlay) if scantracemode: return None nrcl = ncol * nrow * nlay ptr_cval_v = _cxtgeo.new_floatarray(nrcl) # next is to do the actual import of the cube optscan = 0 logger.debug("Import via C wrapper...") _cxtgeo.cube_import_segy( sfile, # input gn_bitsheader, gn_formatcode, gf_segyformat, gn_samplespertrace, # result (as pointers) ptr_ncol, ptr_nrow, ptr_nlay, ptr_cval_v, ptr_xori, ptr_xinc, ptr_yori, ptr_yinc, ptr_zori, ptr_zinc, ptr_rotation, ptr_yflip, ptr_zflip, ptr_minval, ptr_maxval, # options optscan, option, outfile, ) logger.debug("Import via C wrapper...") sdata["ncol"] = ncol sdata["nrow"] = nrow sdata["nlay"] = nlay sdata["xori"] = _cxtgeo.doublepointer_value(ptr_xori) sdata["yori"] = _cxtgeo.doublepointer_value(ptr_yori) sdata["zori"] = _cxtgeo.doublepointer_value(ptr_zori) sdata["xinc"] = _cxtgeo.doublepointer_value(ptr_xinc) sdata["yinc"] = _cxtgeo.doublepointer_value(ptr_yinc) sdata["zinc"] = _cxtgeo.doublepointer_value(ptr_zinc) sdata["yflip"] = _cxtgeo.intpointer_value(ptr_yflip) sdata["zflip"] = _cxtgeo.intpointer_value(ptr_zflip) sdata["rotation"] = _cxtgeo.doublepointer_value(ptr_rotation) sdata["minval"] = _cxtgeo.doublepointer_value(ptr_minval) sdata["maxval"] = _cxtgeo.doublepointer_value(ptr_maxval) sdata["zmin"] = sdata["zori"] sdata["zmax"] = sdata["zori"] + sdata["zflip"] * sdata["zinc"] * (nlay - 1) # the pointer to 1D C array sdata["cvalues"] = ptr_cval_v sdata["values"] = None return sdata
def _get_geometrics_v1(self, allcells=False, cellcenter=True, return_dict=False): ptr_x = [] for i in range(13): ptr_x.append(_cxtgeo.new_doublepointer()) option1 = 1 if allcells: option1 = 0 option2 = 1 if not cellcenter: option2 = 0 quality = _cxtgeo.grd3d_geometrics( self._ncol, self._nrow, self._nlay, self._coordsv, self._zcornsv, self._actnumsv, ptr_x[0], ptr_x[1], ptr_x[2], ptr_x[3], ptr_x[4], ptr_x[5], ptr_x[6], ptr_x[7], ptr_x[8], ptr_x[9], ptr_x[10], ptr_x[11], ptr_x[12], option1, option2, ) glist = [] for i in range(13): glist.append(_cxtgeo.doublepointer_value(ptr_x[i])) glist.append(quality) logger.info("Cell geometrics done") if return_dict: gdict = {} gkeys = [ "xori", "yori", "zori", "xmin", "xmax", "ymin", "ymax", "zmin", "zmax", "avg_rotation", "avg_dx", "avg_dy", "avg_dz", "grid_regularity_flag", ] for i, key in enumerate(gkeys): gdict[key] = glist[i] return gdict return tuple(glist)