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_ecl_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, keywords = _cxtgeo.grd3d_scan_eclbinary(
cfhandle, rectypes, reclens, recstarts, maxkeys
)
pfile.cfclose()
keywords = keywords.replace(" ", "")
keywords = keywords.split("|")
# record types translation (cf: grd3d_scan_eclbinary.c in cxtgeo)
rct = {
def _export_roff_discrete(self, pfile, name, append=False, last=True, binary=True):
carray = _gridprop_lowlevel.update_carray(self, undef=-999)
ptr_idum = _cxtgeo.new_intpointer()
ptr_ddum = _cxtgeo.new_doublepointer()
# codes:
ptr_codes = _cxtgeo.new_intarray(256)
ncodes = self.ncodes
codenames = ""
logger.info("Keys: %s", self.codes.keys())
for inum, ckey in enumerate(sorted(self.codes.keys())):
if ckey is not None:
codenames += str(self.codes[ckey])
codenames += "|"
_cxtgeo.intarray_setitem(ptr_codes, inum, int(ckey))
else:
logger.warning("For some odd reason, None is a key. Check!")
mode = 0
if not binary:
mode = 1
if not append:
self._ncodes = 1
self._codes = {0: "undef"}
logger.debug("Number of codes: %s", self._ncodes)
# allocate
if ptype == 1: # float, assign to double
ptr_pval_v = _cxtgeo.new_doublearray(ntot)
ptr_ival_v = _cxtgeo.new_intarray(1)
self._isdiscrete = False
self._dtype = "float64"
elif ptype > 1:
ptr_pval_v = _cxtgeo.new_doublearray(1)
ptr_ival_v = _cxtgeo.new_intarray(ntot)
self._isdiscrete = True
self._dtype = "int32"
# number of codes and names
ptr_ccodes_v = _cxtgeo.new_intarray(self._ncodes)
# NB! note the SWIG trick to return modified char values; use cstring.i
# inn the config and %cstring_bounded_output(char *p_codenames_v, NN);
# Then the argument for *p_codevalues_v in C is OMITTED here!
ier, cnames = _cxtgeo.grd3d_imp_prop_roffbin(
pfile.name,
1,
ptr_type,
ptr_ncol,
ptr_nrow,
def export_roff(self, gfile, option):
"""Export grid to ROFF format (binary)"""
logger.debug("Export to ROFF...")
nsubs = 0
if self.subgrids is None:
logger.debug("Create a pointer for subgrd_v ...")
subgrd_v = _cxtgeo.new_intpointer()
else:
nsubs = len(self.subgrids)
subgrd_v = _cxtgeo.new_intarray(nsubs)
for inum, (sname, sarray) in enumerate(self.subgrids.items()):
logger.info("INUM SUBGRID: %s %s", inum, sname)
_cxtgeo.intarray_setitem(subgrd_v, inum, len(sarray))
# get the geometrics list to find the xshift, etc
gx = self.get_geometrics()
_cxtgeo.grd3d_export_roff_grid(
option,
self._ncol,
self._nrow,
self._nlay,
nsubs,
0,
gx[3],
gx[5],
def _convert_np_carr_int(self, np_array):
"""Convert numpy 1D array to C array, assuming int type.
The numpy is always a double (float64), so need to convert first
"""
carr = _cxtgeo.new_intarray(self.nrow)
np_array = np_array.astype(np.int32)
_cxtgeo.swig_numpy_to_carr_i1d(np_array, carr)
return carr
if reclen <= 1:
raise SystemError("Stuff is rotten here...")
xvec = None
cfhandle = gfile.get_cfhandle()
if dtype == 1:
xvec = _cxtgeo.new_floatarray(reclen)
_cxtgeo.grd3d_imp_roffbin_ivec(cfhandle, swap, bytepos, xvec, reclen)
elif dtype == 2:
xvec = _cxtgeo.new_floatarray(reclen)
_cxtgeo.grd3d_imp_roffbin_fvec(cfhandle, swap, bytepos, xvec, reclen)
elif dtype >= 4:
xvec = _cxtgeo.new_intarray(reclen) # convert char/byte/bool to int
_cxtgeo.grd3d_imp_roffbin_bvec(cfhandle, swap, bytepos, xvec, reclen)
else:
gfile.cfclose()
raise ValueError("Unhandled dtype: {}".format(dtype))
gfile.cfclose()
return xvec
def _make_ijk_from_grid_v1(self, grid, grid_id=""):
"""
Getting IJK from a grid and make as well logs.
This is the first version, using _cxtgeo.grd3d_well_ijk from C
"""
logger.info("Using algorithm 1 in %s", __name__)
wxarr = self.get_carray("X_UTME")
wyarr = self.get_carray("Y_UTMN")
wzarr = self.get_carray("Z_TVDSS")
nlen = self.nrow
wivec = _cxtgeo.new_intarray(nlen)
wjvec = _cxtgeo.new_intarray(nlen)
wkvec = _cxtgeo.new_intarray(nlen)
onelayergrid = grid.copy()
onelayergrid.reduce_to_one_layer()
cstatus = _cxtgeo.grd3d_well_ijk(
grid.ncol,
grid.nrow,
grid.nlay,
grid._coordsv,
grid._zcornsv,
grid._actnumsv,
onelayergrid._zcornsv,
onelayergrid._actnumsv,
self.nrow,
wxarr,
raise SystemError("Stuff is rotten here...")
xvec = None
cfhandle = gfile.get_cfhandle()
logger.info("Reading %s from file...", name)
if dtype == 1:
xvec = _cxtgeo.new_intarray(reclen)
_cxtgeo.grd3d_imp_roffbin_ivec(cfhandle, swap, bytepos, xvec, reclen)
elif dtype == 2:
xvec = _cxtgeo.new_floatarray(reclen)
_cxtgeo.grd3d_imp_roffbin_fvec(cfhandle, swap, bytepos, xvec, reclen)
elif dtype >= 4:
xvec = _cxtgeo.new_intarray(reclen) # convert char/byte/bool to int
_cxtgeo.grd3d_imp_roffbin_bvec(cfhandle, swap, bytepos, xvec, reclen)
else:
gfile.cfclose()
raise ValueError("Unhandled dtype: {}".format(dtype))
logger.info("Reading %s from file done", name)
gfile.cfclose()
return xvec
def scan_dates(pfile, maxdates=1000, dataframe=False):
"""Quick scan dates in a simulation restart file.
Cf. grid_properties.py description
"""
seq = _cxtgeo.new_intarray(maxdates)
day = _cxtgeo.new_intarray(maxdates)
mon = _cxtgeo.new_intarray(maxdates)
yer = _cxtgeo.new_intarray(maxdates)
cfhandle = pfile.get_cfhandle()
nstat = _cxtgeo.grd3d_ecl_tsteps(cfhandle, seq, day, mon, yer, maxdates)
pfile.cfclose()
sq = []
da = []
for i in range(nstat):
sq.append(_cxtgeo.intarray_getitem(seq, i))
dday = _cxtgeo.intarray_getitem(day, i)
dmon = _cxtgeo.intarray_getitem(mon, i)