Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def getInit(self):
if self._init is None and self._initFile:
self._init = EclFile(self.initFile())
return self._init
# ERT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ERT is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.
#
# See the GNU General Public License at
# for more details.
from ecl.eclfile import EclFile, Ecl3DKW
class Ecl3DFile(EclFile):
def __init__(self, grid, filename, flags=0):
self.grid = grid
super(Ecl3DFile, self).__init__(filename, flags)
def __getitem__(self, index):
return_arg = super(Ecl3DFile, self).__getitem__(index)
if isinstance(return_arg,list):
kw_list = return_arg
else:
kw_list = [return_arg]
# Go through all the keywords and try inplace promotion to Ecl3DKW
for kw in kw_list:
try:
def __init__(self , grid , filename , flags = 0):
"""Will open an Eclipse restart file.
The EclRestartFile class will open an eclipse restart file, in
unified or non unified format. The constructor will infer the
file type based on the filename, and will raise a ValueError
exception if the file type is not ECL_RESTART_FILE or
ECL_UNIFIED_RESTART_FILE.
The EclRestartFile will use a grid reference to create Ecl3DKw
instances for all the keyword elements which have either
'nactive' or 'nx*ny*nz' elements.
"""
file_type , report_step , fmt_file = EclFile.getFileType( filename )
if not file_type in [EclFileEnum.ECL_RESTART_FILE, EclFileEnum.ECL_UNIFIED_RESTART_FILE]:
raise ValueError('The input filename "%s" does not correspond to a restart file. Please follow the Eclipse naming conventions'
% filename)
super(EclRestartFile , self).__init__( grid, filename , flags)
self.rst_headers = None
if file_type == EclFileEnum.ECL_RESTART_FILE:
self.is_unified = False
self.report_step = report_step
else:
self.is_unified = True
def rstdates(eclfiles):
"""Return a list of datetime objects for the available dates in the RST file"""
report_indices = EclFile.file_report_list(eclfiles.get_rstfilename())
logger.info(
"Restart report indices (count %s): %s",
str(len(report_indices)),
str(report_indices),
)
return [
eclfiles.get_rstfile().iget_restart_sim_time(index).date()
for index in range(0, len(report_indices))
]
def get_egridfile(self):
"""Find and return the EGRID file as a EclFile object
This gives access to data vectors defined on the grid."""
if not self._egridfile:
egridfilename = self._eclbase + ".EGRID"
if not os.path.exists(egridfilename):
raise FileNotFoundError(
errno.ENOENT, os.strerror(errno.ENOENT), egridfilename
)
logger.info("Opening data vectors from EGRID file: %s", egridfilename)
self._egridfile = EclFile(egridfilename)
return self._egridfile
def __init__(self, grid, filename, flags=0):
file_type, report_step, fmt_file = EclFile.getFileType(filename)
if file_type == EclFileEnum.ECL_INIT_FILE:
super(EclInitFile, self).__init__(grid, filename, flags)
else:
err = 'The input filename "%s" does not correspond to an init file.'
err += ' Please follow the Eclipse naming conventions.'
raise ValueError(err % filename)
def get_rftfile(self):
"""Find and return the RFT file as an EclFile object"""
if not self._rftfile:
rftfilename = self._eclbase + ".RFT"
if not os.path.exists(rftfilename):
raise FileNotFoundError(
errno.ENOENT, os.strerror(errno.ENOENT), rftfilename
)
logger.info("Opening RFT file: %s", rftfilename)
self._rftfile = EclFile(rftfilename)
return self._rftfile
if not region_id in result:
result[region_id] = [[],[],[]]
result[region_id][0].append(p1)
result[region_id][1].append(p2)
result[region_id][2].append(p3)
#-----------------------------------------------------------------
if __name__ == "__main__":
case = sys.argv[1]
grid = EclGrid("%s.EGRID" % case)
rst_file = EclRestartFile(grid, "%s.UNRST" % case)
init_file = EclFile("%s.INIT" % case)
# Create PORV keyword where all the inactive cells have been removed.
pv = grid.compressed_kw_copy( init_file["PORV"][0] )
# Extract an integer region keyword from the init file
region_kw = init_file["EQLNUM"][0]
sim_days = []
result = {}
for header in rst_file.headers():
line = {}
rst_block = rst_file.restart_view( report_step = header.get_report_step( ) )
p = rst_block["PRESSURE"][0]
sw = rst_block["SWAT"][0]
def getRestart(self):
if self._restart is None:
self._restart = EclFile(self.restartFile())
return self._restart
#!/usr/bin/env python
import sys
from operator import itemgetter
from ecl.eclfile import EclFile
from ecl.grid import EclGrid
if __name__ == "__main__":
case = sys.argv[1]
grid_file = EclFile("%s.EGRID" % case)
init_file = EclFile("%s.INIT" % case)
grid = EclGrid("%s.EGRID" % case)
nnc1 = grid_file["NNC1"][0]
nnc2 = grid_file["NNC2"][0]
tran = init_file["TRANNNC"][0]
nnc_list = []
for g1,g2,t in zip(nnc1,nnc2,tran):
nnc_list.append((g1,g2,t))
nnc_list = sorted(nnc_list, key = itemgetter(0))
for (g1,g2,T) in nnc_list:
# grid_ijk assumes 0-based indexing, g1/g2 are 1-based (FORTRAN)
# Convert them to zero based ones.
g1 = g1 - 1