def test_save_fmt(self): self.addFile("/tmp/ECLIPSE.FUNRST") shutil.copyfile(fmt_file, "/tmp/ECLIPSE.FUNRST") rst_file = ecl.EclFile("/tmp/ECLIPSE.FUNRST", flags=ecl.ECL_FILE_WRITABLE) swat0 = rst_file["SWAT"][0] swat0.assign(0.75) rst_file.save_kw(swat0) rst_file.close() self.assertFalse(file_equal("/tmp/ECLIPSE.FUNRST", fmt_file)) rst_file1 = ecl.EclFile(fmt_file) rst_file2 = ecl.EclFile("/tmp/ECLIPSE.FUNRST", flags=ecl.ECL_FILE_WRITABLE) swat1 = rst_file1["SWAT"][0] swat2 = rst_file2["SWAT"][0] swat2.assign(swat1) rst_file2.save_kw(swat2) self.assertTrue(swat1.equal(swat2)) rst_file1.close() rst_file2.close() # Random failure .... self.assertTrue(file_equal("/tmp/ECLIPSE.FUNRST", fmt_file))
def test_dates(self): f = ecl.EclFile(file) dates = f.dates self.assertTrue(len(dates) == 63) f = ecl.EclFile(xfile0) dates = f.dates self.assertTrue(len(dates) == 1) self.assertTrue(dates[0] == datetime.datetime(2000, 1, 1))
def test_report_list_file(self, fname, rlist0): rlist = ecl.EclFile.file_report_list(fname) self.assertTrue(approx_equalv(rlist, rlist0)) f = ecl.EclFile(fname) rlist = f.report_list self.assertTrue(approx_equalv(rlist, rlist0))
def test_fwrite(self): self.addFile("/tmp/ECLIPSE.UNRST") rst_file = ecl.EclFile(file) fortio = ecl.FortIO.writer("/tmp/ECLIPSE.UNRST") rst_file.fwrite(fortio) fortio.close() rst_file.close() self.assertTrue(file_equal("/tmp/ECLIPSE.UNRST", file))
def fortio_size(self): unrst_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST" file = ecl.EclFile(unrst_file) size = 0 for kw in file: size += kw.fortio_size stat = os.stat(unrst_file) self.assertTrue(size == stat.st_size)
def test_report_list(self): rlist0 = range(63) self.test_report_list_file(file, rlist0) rlist0 = [0] self.test_report_list_file(xfile0, rlist0) f = ecl.EclFile(grid_file) self.assertRaises(TypeError, ecl.EclFile.file_report_list)
def test_kw(self): f = ecl.EclFile(file) kw1 = f["SWAT"][40] kw2 = f.restart_get_kw("SWAT", datetime.datetime(2003, 3, 1)) kw3 = f.restart_get_kw("SWAT", datetime.datetime(2003, 3, 1), copy=True) self.assertTrue(kw1.equal(kw2)) self.assertTrue(kw1.equal(kw3)) kw4 = f.restart_get_kw("SWAT", datetime.datetime(2009, 3, 1)) self.assertTrue(kw4 is None)
def test_report_file(self, fname): self.assertTrue(ecl.EclFile.contains_report_step(fname, 4)) self.assertTrue(ecl.EclFile.contains_report_step(fname, 0)) self.assertTrue(ecl.EclFile.contains_report_step(fname, 62)) self.assertFalse(ecl.EclFile.contains_report_step(fname, -1)) self.assertFalse(ecl.EclFile.contains_report_step(fname, 100)) f = ecl.EclFile(fname) self.assertTrue(f.has_report_step(4)) self.assertTrue(f.has_report_step(0)) self.assertTrue(f.has_report_step(62)) self.assertFalse(f.has_report_step(-1)) self.assertFalse(f.has_report_step(100))
def test_date(self): f = ecl.EclFile(file) self.assertTrue(f.has_sim_time(datetime.datetime(2001, 6, 1))) self.assertFalse(f.has_sim_time(datetime.datetime(2005, 6, 1))) self.assertFalse(f.has_sim_time(datetime.datetime(1999, 6, 1))) self.assertFalse(f.has_sim_time(datetime.datetime(2001, 6, 11))) self.assertTrue( ecl.EclFile.contains_sim_time(file, datetime.datetime(2001, 6, 1))) self.assertFalse( ecl.EclFile.contains_sim_time(file, datetime.datetime(2005, 6, 1))) self.assertFalse( ecl.EclFile.contains_sim_time(file, datetime.datetime(1999, 6, 1))) self.assertFalse( ecl.EclFile.contains_sim_time(file, datetime.datetime(2001, 6, 11)))
def test_equal(self): kw1 = ecl.EclKW.new("TEST", 3, ecl.ECL_CHAR_TYPE) kw1[0] = "Test1" kw1[1] = "Test13" kw1[2] = "Test15" kw2 = ecl.EclKW.new("TEST", 3, ecl.ECL_CHAR_TYPE) kw2[0] = "Test1" kw2[1] = "Test13" kw2[2] = "Test15" self.assertTrue(kw1.equal(kw2)) self.assertTrue(kw1.equal_numeric(kw2)) kw2[2] = "Test15X" self.assertFalse(kw1.equal(kw2)) self.assertFalse(kw1.equal_numeric(kw2)) unrst_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST" file = ecl.EclFile(unrst_file) kw1 = file["PRESSURE"][0] kw2 = kw1.deep_copy() self.assertTrue(kw1.equal(kw2)) self.assertTrue(kw1.equal_numeric(kw2)) kw2 *= 1.00001 self.assertFalse(kw1.equal(kw2)) self.assertFalse(kw1.equal_numeric(kw2, epsilon=1e-8)) self.assertTrue(kw1.equal_numeric(kw2, epsilon=1e-2)) kw1 = file["ICON"][10] kw2 = kw1.deep_copy() self.assertTrue(kw1.equal(kw2)) self.assertTrue(kw1.equal_numeric(kw2)) kw1[-1] += 1 self.assertFalse(kw1.equal(kw2)) self.assertFalse(kw1.equal_numeric(kw2))
def testSubCopy(self): unrst_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST" file = ecl.EclFile(unrst_file) swat = file["SWAT"][0] swat1 = swat.sub_copy(0, -1) swat2 = swat.sub_copy(0, swat.size) self.assertTrue(swat.equal(swat1)) self.assertTrue(swat.equal(swat2)) swat3 = swat.sub_copy(20000, 100, new_header="swat") self.assertTrue(swat3.name == "swat") self.assertTrue(swat3.size == 100) equal = True for i in range(swat3.size): if swat3[i] != swat[i + 20000]: equal = False self.assertTrue(equal) self.assertRaises(IndexError, copy_long) self.assertRaises(IndexError, copy_offset)
def load_missing(): ecl.EclFile("No/Does/not/exist")
def test_name(self): f = ecl.EclFile(file) self.assertTrue(f.name == file) f = ecl.EclFile(xfile0) self.assertTrue(f.name == xfile0)
# (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 <http://www.gnu.org/licenses/gpl.html> # for more details. import datetime import ert.ecl.ecl as ecl # 1: We need the name of the GRID/EGRID file and the init file. Pass # these two filenames to the EclGrav() constructor. grid = ecl.EclGrid("data/eclipse/grav/TROLL.EGRID") init_file = ecl.EclFile("data/eclipse/grav/TROLL.INIT") grav = ecl.EclGrav(grid, init_file) # 2: We load the restart files for the times we are interested in, # this can be done in two different ways: # # a) In the case of non unified restart files you can just use the # EclFile() constructor to load the whole file: # # restart1 = ecl.EclFile("ECLIPSE.X0078") # # b) You can use the ecl.EclFile.restart_block() method to load # only one block from a unified restart file. In that case you # must use 'report_step = nnn' to specifiy which report_step you # are interested in. Alternatively you can use 'dtime = # datetime( year , month , day)' to specify which block are