Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _scan_roff_keywords(pfile, maxkeys=100000, dataframe=False):
ultramax = int(1000000 / 9) # cf *swig_bnd_char_1m in cxtgeo.i
if maxkeys > ultramax:
raise ValueError("maxkeys value is too large, must be < {}".format(ultramax))
rectypes = _cxtgeo.new_intarray(maxkeys)
reclens = _cxtgeo.new_longarray(maxkeys)
recstarts = _cxtgeo.new_longarray(maxkeys)
cfhandle = pfile.get_cfhandle()
nkeys, _tmp1, keywords = _cxtgeo.grd3d_scan_roffbinary(
cfhandle, rectypes, reclens, recstarts, maxkeys
)
pfile.cfclose()
keywords = keywords.replace(" ", "")
keywords = keywords.split("|")
# record types translation (cf: grd3d_scan_eclbinary.c in cxtgeo)
rct = {
"1": "int",
"2": "float",
"3": "double",
"4": "char",
"5": "bool",
"6": "byte",
ptr_idum = _cxtgeo.new_intpointer()
mode = 0
if not binary:
mode = 1
if not append:
_cxtgeo.grd3d_export_roff_pstart(
mode, self._ncol, self._nrow, self._nlay, pfile
)
# now the actual data
nsub = 0
isub_to_export = 0
_cxtgeo.grd3d_export_roff_prop(
mode,
self._ncol,
self._nrow,
self._nlay,
nsub,
isub_to_export,
ptr_idum,
name,
"double",
ptr_idum,
carray,
0,
"",
ptr_idum,
pfile,
)
if "parameter!data" in items[0] and namefound:
dtype = kwtypedict.get(items[1])
reclen = items[2]
bytepos = items[3]
break
if dtype == 0:
raise ValueError("Cannot find property <{}> in file".format(name))
if reclen <= 1:
raise SystemError("Stuff is rotten here...")
inumpy = np.zeros(ncol * nrow * nlay, dtype=np.int32)
fnumpy = np.zeros(ncol * nrow * nlay, dtype=np.float32)
_cxtgeo.grd3d_imp_roffbin_arr(
gfile.get_cfhandle(), swap, ncol, nrow, nlay, bytepos, dtype, fnumpy, inumpy
)
gfile.cfclose()
if dtype == 1:
vals = inumpy
vals = ma.masked_greater(vals, xtgeo.UNDEF_INT_LIMIT)
del fnumpy
del inumpy
elif dtype == 2:
vals = fnumpy
vals = ma.masked_greater(vals, xtgeo.UNDEF_LIMIT)
vals = vals.astype(np.float64)
del fnumpy
del inumpy
for items in kws:
if name in items[0]:
dtype = kwtypedict.get(items[1])
reclen = items[2]
bytepos = items[3]
break
logger.debug("DTYPE is %s", dtype)
if dtype == 0:
raise ValueError("Cannot find property <{}> in file".format(name))
if reclen != 1:
raise SystemError("Stuff is rotten here...")
_cxtgeo.grd3d_imp_roffbin_data(
gfile.get_cfhandle(), swap, dtype, bytepos, iresult, presult
)
gfile.cfclose()
# -1 indicates that it is the swap flag which is looked for!
if dtype == 1:
xresult = _cxtgeo.intpointer_value(iresult)
if swap == -1:
if xresult == 1:
return 0
return 1
elif dtype == 2:
xresult = _cxtgeo.floatpointer_value(presult)
def update_values_from_carray(self, carray, dtype, delete=False):
"""Transfer values from SWIG 1D carray to numpy, 3D array"""
logger.debug("Update numpy from C array values")
nv = self.ntotal
self._isdiscrete = False
if dtype == np.float64:
logger.info("Entering conversion to numpy (float64) ...")
values1d = _cxtgeo.swig_carr_to_numpy_1d(nv, carray)
else:
logger.info("Entering conversion to numpy (int32) ...")
values1d = _cxtgeo.swig_carr_to_numpy_i1d(nv, carray)
self._isdiscrete = True
values = np.reshape(values1d, (self._ncol, self._nrow, self._nlay), order="F")
# make into C order as this is standard Python order...
values = np.asanyarray(values, order="C")
# make it float64 or whatever(?) and mask it
self._values = values
self.mask_undef()
# optionally delete the C array if needed
if delete:
def _export_irap_binary_cxtgeo(self, mfile):
"""Export to Irap binary using C backend
Args:
mfile (_XTGeoFile): xtgeo file instance
Raises:
RuntimeError: Export to Irap Binary went wrong...
"""
vals = self.get_values1d(fill_value=UNDEF_MAP_IRAPB, order="F")
ier = _cxtgeo.surf_export_irap_bin(
mfile.get_cfhandle(),
self._ncol,
self._nrow,
self._xori,
self._yori,
self._xinc,
self._yflip * self._yinc,
self._rotation,
vals,
0,
)
if ier != 0:
mfile.cfclose(strict=False) # strict False as C routine may have closed
raise RuntimeError("Export to Irap Binary went wrong, code is {}".format(ier))
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,
optmask = 0
if mask:
optmask = 1
if deadtraces:
# set dead traces to cxtgeo UNDEF -> special treatment in the C code
olddead = cube.values_dead_traces(xtgeo.UNDEF)
optnearest = 1
if sampling == "trilinear":
optnearest = 0
# cube and surf shall share same topology, e.g. cube.col == surf.ncol etc
# print(self.values.mask)
istat = _cxtgeo.surf_slice_cube_v3(
cube.ncol,
cube.nrow,
cube.nlay,
cube.zori,
cube.zinc,
cube.values,
other.values.data,
self.values.data,
self.values.mask,
optnearest,
optmask,
)
if istat != 0:
logger.warning("Problem, ISTAT = %s", istat)
def _export_roff_continuous(self, pfile, name, append=False, last=True, binary=True):
carray = _gridprop_lowlevel.update_carray(self, undef=-999.0)
ptr_idum = _cxtgeo.new_intpointer()
mode = 0
if not binary:
mode = 1
if not append:
_cxtgeo.grd3d_export_roff_pstart(
mode, self._ncol, self._nrow, self._nlay, pfile
)
# now the actual data
nsub = 0
isub_to_export = 0
_cxtgeo.grd3d_export_roff_prop(
mode,
self._ncol,
self._nrow,
self._nlay,
nsub,
isub_to_export,
ptr_idum,
name,