Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_kw(self, array, kw_name, pack):
"""
Creates an EclKW instance based on existing 3D numpy object.
The method create3D() does the inverse operation; creating a
3D numpy object from an EclKW instance. If the argument @pack
is true the resulting keyword will have length 'nactive',
otherwise the element will have length nx*ny*nz.
"""
if array.ndim == 3:
dims = array.shape
if dims[0] == self.getNX() and dims[1] == self.getNY() and dims[2] == self.getNZ():
dtype = array.dtype
if dtype == numpy.int32:
type = EclDataType.ECL_INT
elif dtype == numpy.float32:
type = EclDataType.ECL_FLOAT
elif dtype == numpy.float64:
type = EclDataType.ECL_DOUBLE
else:
sys.exit("Do not know how to create ecl_kw from type:%s" % dtype)
if pack:
size = self.getNumActive()
else:
size = self.getGlobalSize()
if len(kw_name) > 8:
# Silently truncate to length 8 - ECLIPSE has it's challenges.
kw_name = kw_name[0:8]
cells are assumed to be active.
Slightly more exotic grid concepts like dual porosity, NNC
mapping, LGR and coarsened cells will be completely ignored;
if you need such concepts you must have an EGRID file and use
the default EclGrid() constructor - that is also considerably
faster.
"""
if os.path.isfile(filename):
with copen(filename) as f:
specgrid = EclKW.read_grdecl(f, "SPECGRID", ecl_type=EclDataType.ECL_INT, strict=False)
zcorn = EclKW.read_grdecl(f, "ZCORN")
coord = EclKW.read_grdecl(f, "COORD")
try:
actnum = EclKW.read_grdecl(f, "ACTNUM", ecl_type=EclDataType.ECL_INT)
except ValueError:
actnum = None
try:
mapaxes = EclKW.read_grdecl(f, "MAPAXES")
except ValueError:
mapaxes = None
return EclGrid.create(specgrid, zcorn, coord, actnum, mapaxes)
else:
raise IOError("No such file:%s" % filename)
def scale_kw( self , ecl_kw , scale , force_active = False):
"""
See usage documentation on iadd_kw().
"""
self.scalar_apply_kw( ecl_kw , scale , {EclDataType.ECL_INT : self._scale_kw_int,
EclDataType.ECL_FLOAT : self._scale_kw_float ,
EclDataType.ECL_DOUBLE : self._scale_kw_double} , force_active)
if kw:
if len(kw) > 8:
raise TypeError("Sorry keyword:%s is too long, must be eight characters or less." % kw)
if ecl_type is None:
if cls.int_kw_set.__contains__(kw):
ecl_type = EclDataType.ECL_INT
else:
ecl_type = EclDataType.ECL_FLOAT
ecl_type = warn_and_cast_data_type(ecl_type)
if not isinstance(ecl_type, EclDataType):
raise TypeError("Expected EclDataType, was: %s" % type(ecl_type))
if not ecl_type in [EclDataType.ECL_FLOAT, EclDataType.ECL_INT]:
raise ValueError("The type:%s is invalid when loading keyword:%s" % (ecl_type.type_name, kw))
return cls._load_grdecl(cfile, kw, strict, ecl_type)
files, malformed input might therefore pass unnoticed before
things blow up at a later stage.
[1]: It is possible, but not recommended, to pass in None for
@kw, in which case the method will load the first keyword
it finds in the file.
"""
cfile = CFILE(fileH)
if kw:
if len(kw) > 8:
raise TypeError("Sorry keyword:%s is too long, must be eight characters or less." % kw)
if ecl_type is None:
if cls.int_kw_set.__contains__(kw):
ecl_type = EclDataType.ECL_INT
else:
ecl_type = EclDataType.ECL_FLOAT
ecl_type = warn_and_cast_data_type(ecl_type)
if not isinstance(ecl_type, EclDataType):
raise TypeError("Expected EclDataType, was: %s" % type(ecl_type))
if not ecl_type in [EclDataType.ECL_FLOAT, EclDataType.ECL_INT]:
raise ValueError("The type:%s is invalid when loading keyword:%s" % (ecl_type.type_name, kw))
return cls._load_grdecl(cfile, kw, strict, ecl_type)
files, malformed input might therefore pass unnoticed before
things blow up at a later stage.
[1]: It is possible, but not recommended, to pass in None for
@kw, in which case the method will load the first keyword
it finds in the file.
"""
cfile = CFILE(fileH)
if kw:
if len(kw) > 8:
raise TypeError("Sorry keyword:%s is too long, must be eight characters or less." % kw)
if ecl_type is None:
if cls.int_kw_set.__contains__(kw):
ecl_type = EclDataType.ECL_INT
else:
ecl_type = EclDataType.ECL_FLOAT
ecl_type = warn_and_cast_data_type(ecl_type)
if not isinstance(ecl_type, EclDataType):
raise TypeError("Expected EclDataType, was: %s" % type(ecl_type))
if not ecl_type in [EclDataType.ECL_FLOAT, EclDataType.ECL_INT]:
raise ValueError("The type:%s is invalid when loading keyword:%s" % (ecl_type.type_name, kw))
return cls._load_grdecl(cfile, kw, strict, ecl_type)
def export_ACTNUM_kw(self):
actnum = EclKW("ACTNUM", self.getGlobalSize(), EclDataType.ECL_INT)
self._init_actnum(actnum.getDataPtr())
return actnum