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: _cxtgeo.grd3d_export_roff_pstart(mode, self._ncol, self._nrow, self._nlay, pfile, XTGDEBUG) 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, "int", carray, ptr_ddum, ncodes, codenames, ptr_codes, pfile, XTGDEBUG, ) if last: _cxtgeo.grd3d_export_roff_end(mode, pfile, XTGDEBUG) _gridprop_lowlevel.delete_carray(self, carray)
def _export_roff_v1(self, gfile, option): """Export grid to ROFF format (binary)""" self._xtgformat1() gfile = xtgeo._XTGeoFile(gfile, mode="wb") gfile.check_folder(raiseerror=OSError) 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], gx[7], self._coordsv, self._zcornsv, self._actnumsv, subgrd_v, gfile.name, ) # end tag _cxtgeo.grd3d_export_roff_end(option, gfile.name)
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], gx[7], self._p_coord_v, self._p_zcorn_v, self._p_actnum_v, subgrd_v, gfile, XTGDEBUG, ) # skip parameters for now (cf Perl code) # end tag _cxtgeo.grd3d_export_roff_end(option, gfile, XTGDEBUG)
def refine_vertically(self, rfactor, zoneprop=None): """Refine vertically, proportionally See details in caller. """ rfactord = OrderedDict() # case 1 rfactor as scalar value. if isinstance(rfactor, int): if self.subgrids: subgrids = self.get_subgrids() for i, _ in enumerate(self.subgrids.keys()): rfactord[i + 1] = rfactor else: rfactord[0] = rfactor subgrids = OrderedDict() subgrids[1] = self.nlay # case 2 rfactor is a dict else: rfactord = OrderedDict(sorted(rfactor.items())) # redefined to ordered # 2a: zoneprop is present if zoneprop is not None: oldsubgrids = None if self.subgrids: oldsubgrids = self.get_subgrids() subgrids = self.subgrids_from_zoneprop(zoneprop) if oldsubgrids: if subgrids.values() != oldsubgrids.values(): xtg.warn("ISSUES!!!") # 2b: zoneprop is not present elif zoneprop is None and self.subgrids: subgrids = self.get_subgrids() elif zoneprop is None and not self.subgrids: raise ValueError("You gave in a dict, but no zoneprops and " "subgrids are not preesent in the grid") else: raise ValueError("Some major unexpected issue in routine...") if len(subgrids) != len(rfactord): raise RuntimeError("Subgrids and refinements: different definition!") self.set_subgrids(subgrids) # Now, based on dict, give a value per subgrid for key, val in rfactor newsubgrids = OrderedDict() newnlay = 0 for (_x, rfi), (snam, sran) in zip(rfactord.items(), subgrids.items()): newsubgrids[snam] = sran * rfi newnlay += newsubgrids[snam] logger.debug("New layers: %s", newnlay) # rfac is an array with length nlay; has N refinements per single K layer rfac = _cxtgeo.new_intarray(self.nlay) totvector = [] for (_tmp1, rfi), (_tmp2, arr) in zip(rfactord.items(), self.subgrids.items()): for _elem in range(len(arr)): totvector.append(rfi) for inn, rfi in enumerate(totvector): _cxtgeo.intarray_setitem(rfac, inn, rfi) ref_num_act = _cxtgeo.new_intpointer() ref_p_zcorn_v = _cxtgeo.new_doublearray(self.ncol * self.nrow * (newnlay + 1) * 4) ref_p_actnum_v = _cxtgeo.new_intarray(self.ncol * self.nrow * newnlay) ier = _cxtgeo.grd3d_refine_vert( self.ncol, self.nrow, self.nlay, self._p_coord_v, self._p_zcorn_v, self._p_actnum_v, newnlay, ref_p_zcorn_v, ref_p_actnum_v, ref_num_act, rfac, 0, XTGDEBUG, ) if ier != 0: raise RuntimeError("An error occured in the C routine " "grd3d_refine_vert, code {}".format(ier)) # update instance: self._nlay = newnlay self._p_zcorn_v = ref_p_zcorn_v self._p_actnum_v = ref_p_actnum_v if self.subgrids is None or len(self.subgrids) <= 1: self.subgrids = None else: self.set_subgrids(newsubgrids) return self