示例#1
0
    def test_save(self):
        #work_area = TestArea("python/ecl_file/save")
        with TestAreaContext("python/ecl_file/save",
                             store_area=False) as work_area:
            work_area.copy_file(self.test_file)
            rst_file = EclFile("ECLIPSE.UNRST",
                               flags=EclFileFlagEnum.ECL_FILE_WRITABLE)
            swat0 = rst_file["SWAT"][0]
            swat0.assign(0.75)
            rst_file.save_kw(swat0)
            rst_file.close()
            self.assertFilesAreNotEqual("ECLIPSE.UNRST", self.test_file)

            rst_file1 = EclFile(self.test_file)
            rst_file2 = EclFile("ECLIPSE.UNRST",
                                flags=EclFileFlagEnum.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.assertFilesAreEqual("ECLIPSE.UNRST", self.test_file)
示例#2
0
    def test_geertsma_kernel():
        grid = EclGrid.createRectangular(dims=(1, 1, 1), dV=(50, 50, 50))
        with TestAreaContext("Subsidence"):
            p1 = [1]
            create_restart(grid, "TEST", p1)
            create_init(grid, "TEST")

            init = EclFile("TEST.INIT")
            restart_file = EclFile("TEST.UNRST")

            restart_view1 = restart_file.restartView(
                sim_time=datetime.date(2000, 1, 1))

            subsidence = EclSubsidence(grid, init)
            subsidence.add_survey_PRESSURE("S1", restart_view1)

            youngs_modulus = 5E8
            poisson_ratio = 0.3
            seabed = 0
            above = 100
            topres = 2000
            receiver = (1000, 1000, 0)

            dz = subsidence.evalGeertsma("S1", None, receiver, youngs_modulus,
                                         poisson_ratio, seabed)
            np.testing.assert_almost_equal(dz, 3.944214576168326e-09)

            receiver = (1000, 1000, topres - seabed - above)

            dz = subsidence.evalGeertsma("S1", None, receiver, youngs_modulus,
                                         poisson_ratio, seabed)
            np.testing.assert_almost_equal(dz, 5.8160298201497136e-08)
示例#3
0
文件: test_grid.py 项目: kgreg1/ert
    def test_output_units(self):
        n = 10
        a = 1
        grid = GridGen.createRectangular( (n,n,n), (a,a,a))

        with TestAreaContext("python/ecl_grid/units"):
            grid.save_EGRID( "CASE.EGRID" , output_unit = EclUnitTypeEnum.ECL_FIELD_UNITS )
            f = EclFile("CASE.EGRID")
            g = f["GRIDUNIT"][0]
            self.assertEqual( g[0].strip( ) , "FEET" )
            g2 = EclGrid("CASE.EGRID")
            self.assertFloatEqual( g2.cell_volume( global_index = 0 ) , 3.28084*3.28084*3.28084)

            
            grid.save_EGRID( "CASE.EGRID" )
            f = EclFile("CASE.EGRID")
            g = f["GRIDUNIT"][0]
            self.assertEqual( g[0].strip( ) , "METRES" )
            
            grid.save_EGRID( "CASE.EGRID" , output_unit = EclUnitTypeEnum.ECL_LAB_UNITS)
            f = EclFile("CASE.EGRID")
            g = f["GRIDUNIT"][0]
            self.assertEqual( g[0].strip() , "CM" )
            g2 = EclGrid("CASE.EGRID")
            self.assertFloatEqual( g2.cell_volume( global_index = 0 ) , 100*100*100 )
 def test_compareRestartKeyword_identicaltuple_averagedeviationiszero(self):
     restart_file_A = EclFile("../testdata/SPE1AUTODIFF.UNRST")
     restart_file_B = EclFile("../testdata/SPE1AUTODIFF.UNRST")
     comparison_result = compareRestarts(restart_file_A, restart_file_B,
                                         "SGAS")
     self.assertEqual(0.0, comparison_result.getAverageAbsoluteDeviation())
     self.assertEqual(0.0, comparison_result.getAverageRelativeDeviation())
     self.assertEqual(0.0, comparison_result.getMedianAbsoluteDeviation())
     self.assertEqual(0.0, comparison_result.getMedianRelativeDeviation())
示例#5
0
    def test_dates(self):
        f = EclFile(self.u_file)
        dates = f.dates
        self.assertTrue(len(dates) == 63)

        f = EclFile(self.xfile0)
        dates = f.dates
        self.assertTrue(len(dates) == 1)
        self.assertTrue(dates[0] == datetime.datetime(2000, 1, 1))
示例#6
0
文件: wellviz.py 项目: pgdr/wellviz
def main():
    grid = EclGrid('/home/pgdr/statoil/norne/NORNE_ATW2013.EGRID')
    init = EclFile('/home/pgdr/statoil/norne/NORNE_ATW2013.INIT')
    rest = EclFile('/home/pgdr/statoil/norne/NORNE_ATW2013.UNRST')
    wp = Wpath('/home/pgdr/statoil/norne/norne-test-2-mid.w')
    swat, sgas = rest._iget_named_kw('SWAT', 0), rest._iget_named_kw('SGAS', 0)
    permx = init._iget_named_kw('PERMX', 0)

    wall = constructWall(grid, wp, swat, sgas, permx)
    drawWall(wall)
示例#7
0
    def test_truncated(self):
        with TestAreaContext("python/ecl_file/truncated") as work_area:
            work_area.copy_file(self.test_file)
            size = os.path.getsize("ECLIPSE.UNRST")
            with open("ECLIPSE.UNRST", "r+") as f:
                f.truncate(size / 2)

            with self.assertRaises(IOError):
                rst_file = EclFile("ECLIPSE.UNRST")

            with self.assertRaises(IOError):
                rst_file = EclFile("ECLIPSE.UNRST",
                                   flags=EclFileFlagEnum.ECL_FILE_WRITABLE)
示例#8
0
    def test_truncate(self):
        kw1 = EclKW("KW1", 2, EclTypeEnum.ECL_INT_TYPE)
        kw2 = EclKW("KW2", 2, EclTypeEnum.ECL_INT_TYPE)

        kw1[0] = 99
        kw1[1] = 77
        kw2[0] = 113
        kw2[1] = 335

        with TestAreaContext("python/fortio/ftruncate") as t:
            with openFortIO("file", mode=FortIO.WRITE_MODE) as f:
                kw1.fwrite(f)
                pos1 = f.getPosition()
                kw2.fwrite(f)

            t.sync()
            # Truncate file in read mode; should fail hard.
            with openFortIO("file") as f:
                with self.assertRaises(IOError):
                    f.truncate()

            with openFortIO("file", mode=FortIO.READ_AND_WRITE_MODE) as f:
                f.seek(pos1)
                f.truncate()

            f = EclFile("file")
            self.assertEqual(len(f), 1)
            kw1_ = f[0]
            self.assertEqual(kw1, kw1_)
示例#9
0
    def report_list_file_test(self, fname, rlist0):
        rlist = EclFile.file_report_list(fname)
        self.assertListEqual(rlist, rlist0)

        f = EclFile(fname)
        rlist = f.report_list
        self.assertListEqual(rlist, rlist0)
示例#10
0
def main( eclipse_file_location , opm_file_location ,  base_name , rel_tolerance, abs_tolerance):
    print "Using relative tolerance of: " + str(rel_tolerance)
    print "Using absolute tolerance of: " + str(abs_tolerance)

    eclipse_restart_file = EclFile(eclipse_file_location + base_name + ".UNRST")
    eclipse_grid_file = EclGrid(eclipse_file_location + base_name + ".EGRID")

    opm_restart_file = EclFile(opm_file_location + base_name + ".UNRST")
    opm_grid_file = EclGrid(opm_file_location + base_name + ".EGRID")

    grids_equal = eclipse_grid_file.equal(opm_grid_file, include_lgr=True, verbose=True)
    if not grids_equal:
        print("The grids in files {0} and {1} are not equal!".format(eclipse_grid_file.name, opm_grid_file.name))
        exit(1)

    compareRestartFiles(eclipse_restart_file, opm_restart_file, rel_tolerance, abs_tolerance)
示例#11
0
    def test_ecl_file_block(self):

        with TestAreaContext("name") as t:
            kw = EclKW("TEST", 3, EclDataType.ECL_INT)
            with openFortIO("TEST", mode=FortIO.WRITE_MODE) as f:
                kw.fwrite(f)

            t.sync()

            f = EclFile("TEST")
            with self.assertRaises(NotImplementedError):
                f.select_block("KW", 100)

            with self.assertRaises(NotImplementedError):
                f.select_global()

            with self.assertRaises(NotImplementedError):
                f.select_restart_section(index=None,
                                         report_step=None,
                                         sim_time=None)

            with self.assertRaises(NotImplementedError):
                f.select_restart_section()

            with self.assertRaises(NotImplementedError):
                EclFile.restart_block("TEST")
示例#12
0
def loadKeywords(name):
    kw_list = []
    f = EclFile(name)
    for kw in f:
        kw_list.append(kw)

    return kw_list
示例#13
0
    def test_EclFile_name_property(self):
        with TestAreaContext("name") as t:
            kw = EclKW("TEST", 3, EclDataType.ECL_INT)
            with openFortIO("TEST", mode=FortIO.WRITE_MODE) as f:
                kw.fwrite(f)

            t.sync()
            f = EclFile("TEST")
 def test_compareRestartKeyword_differentData_SGAS_deviationstats_are_correct(
         self):
     restart_file_A = EclFile("../testdata/SPE1AUTODIFF.UNRST")
     restart_file_B = EclFile("../testdata/SPE1ECLIPSE.UNRST")
     comparison_result = compareRestarts(restart_file_A, restart_file_B,
                                         "SGAS")
     self.assertAlmostEqual(0.00465,
                            comparison_result.getAverageAbsoluteDeviation(),
                            5)
     self.assertAlmostEqual(0.03575,
                            comparison_result.getAverageRelativeDeviation(),
                            4)
     self.assertAlmostEqual(0.0034,
                            comparison_result.getMedianAbsoluteDeviation(),
                            5)
     self.assertAlmostEqual(0.0117,
                            comparison_result.getMedianRelativeDeviation(),
                            3)
 def test_compareRestartKeyword_differentData_SWAT_deviationstats_are_correct(
         self):
     restart_file_A = EclFile("../testdata/SPE1AUTODIFF.UNRST")
     restart_file_B = EclFile("../testdata/SPE1ECLIPSE.UNRST")
     comparison_result = compareRestarts(restart_file_A, restart_file_B,
                                         "SWAT")
     self.assertAlmostEqual(2.7e-06,
                            comparison_result.getAverageAbsoluteDeviation(),
                            6)
     self.assertAlmostEqual(2.3e-05,
                            comparison_result.getAverageRelativeDeviation(),
                            6)
     self.assertAlmostEqual(2.44e-06,
                            comparison_result.getMedianAbsoluteDeviation(),
                            7)
     self.assertAlmostEqual(2.05e-05,
                            comparison_result.getMedianRelativeDeviation(),
                            7)
示例#16
0
    def test_EclFile_name_property(self):
        with TestAreaContext("name"):
            kw = EclKW("TEST", 3, EclTypeEnum.ECL_INT_TYPE)
            with openFortIO("TEST" , mode = FortIO.WRITE_MODE) as f:
                kw.fwrite( f )

            f = EclFile( "TEST" )
            with self.assertRaises(DeprecationWarning):
                name = f.name
示例#17
0
    def test_ecl_file_indexed_read(self):
        with TestAreaContext("ecl_file_indexed_read") as area:
            fortio = FortIO("ecl_file_index_test", mode=FortIO.WRITE_MODE)

            element_count = 100000
            ecl_kw_1 = EclKW("TEST1", element_count, EclDataType.ECL_INT)
            ecl_kw_2 = EclKW("TEST2", element_count, EclDataType.ECL_INT)

            for index in range(element_count):
                ecl_kw_1[index] = index
                ecl_kw_2[index] = index + 3

            ecl_kw_1.fwrite(fortio)
            ecl_kw_2.fwrite(fortio)

            fortio.close()

            ecl_file = EclFile("ecl_file_index_test")

            index_map = IntVector()
            index_map.append(2)
            index_map.append(3)
            index_map.append(5)
            index_map.append(7)
            index_map.append(11)
            index_map.append(13)
            index_map.append(313)
            index_map.append(1867)
            index_map.append(5227)
            index_map.append(7159)
            index_map.append(12689)
            index_map.append(18719)
            index_map.append(32321)
            index_map.append(37879)
            index_map.append(54167)
            index_map.append(77213)
            index_map.append(88843)
            index_map.append(99991)

            char_buffer_1 = ctypes.create_string_buffer(
                len(index_map) * ctypes.sizeof(ctypes.c_int))
            char_buffer_2 = ctypes.create_string_buffer(
                len(index_map) * ctypes.sizeof(ctypes.c_int))

            self._eclFileIndexedRead(ecl_file, "TEST2", 0, index_map,
                                     char_buffer_2)
            self._eclFileIndexedRead(ecl_file, "TEST1", 0, index_map,
                                     char_buffer_1)

            int_buffer_1 = ctypes.cast(char_buffer_1,
                                       ctypes.POINTER(ctypes.c_int))
            int_buffer_2 = ctypes.cast(char_buffer_2,
                                       ctypes.POINTER(ctypes.c_int))

            for index, index_map_value in enumerate(index_map):
                self.assertEqual(index_map_value, int_buffer_1[index])
                self.assertEqual(index_map_value, int_buffer_2[index] - 3)
示例#18
0
    def test_restart_view(self):
        f = EclFile(self.test_file)
        with self.assertRaises(ValueError):
            v = f.restartView()

        v = f.restartView(sim_days=274)
        v = f.restartView(sim_time=datetime.date(2004, 1, 1))
        v = f.restartView(report_step=30)
        v = f.restartView(seqnum_index=30)
示例#19
0
 def test_fwrite(self):
     #work_area = TestArea("python/ecl_file/fwrite")
     with TestAreaContext("python/ecl_file/fwrite"):
         rst_file = EclFile(self.test_file)
         fortio = FortIO("ECLIPSE.UNRST", FortIO.WRITE_MODE)
         rst_file.fwrite(fortio)
         fortio.close()
         rst_file.close()
         self.assertFilesAreEqual("ECLIPSE.UNRST", self.test_file)
示例#20
0
    def test_ix_case(self):
        # This should ideally load OK; the current assertRaises() test
        # is just to ensure that it does not go *completely* up in flames.
        with self.assertRaises(IOError):
            EclSum( self.createTestPath( "Statoil/ECLIPSE/ix/summary/Create_Region_Around_Well"))

        f = EclFile( self.createTestPath( "Statoil/ECLIPSE/ix/summary/Create_Region_Around_Well.SMSPEC")) 
        self.assertTrue( "KEYWORDS" in f )
        self.assertFalse( "NAMES" in f )
示例#21
0
    def test_fortio_size( self ):
        unrst_file_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST")
        unrst_file = EclFile(unrst_file_path)
        size = 0
        for kw in unrst_file:
            size += kw.fortio_size

        stat = os.stat(unrst_file_path)
        self.assertTrue(size == stat.st_size)
示例#22
0
    def test_EclFile_name_property(self):
        with TestAreaContext("name"):
            kw = EclKW.new("TEST", 3, EclTypeEnum.ECL_INT_TYPE)
            with openFortIO("TEST" , mode = FortIO.WRITE_MODE) as f:
                kw.fwrite( f )

            f = EclFile( "TEST" )
            with warnings.catch_warnings():
                name = f.name
 def test_compareRestartKeyword_differentData_PRESSURE_deviationstats_are_correct(
         self):
     restart_file_A = EclFile("../testdata/SPE1AUTODIFF.UNRST")
     restart_file_B = EclFile("../testdata/SPE1ECLIPSE.UNRST")
     comparison_result = compareRestarts(restart_file_A, restart_file_B,
                                         "PRESSURE")
     self.assertAlmostEqual(6e-04,
                            comparison_result.getAverageRelativeDeviation(),
                            4)
     self.assertAlmostEqual(3.76085,
                            comparison_result.getAverageAbsoluteDeviation(),
                            4)
     self.assertAlmostEqual(3.334,
                            comparison_result.getMedianAbsoluteDeviation(),
                            3)
     self.assertAlmostEqual(0.00052,
                            comparison_result.getMedianRelativeDeviation(),
                            5)
     comparison_result.printInformation(True)
示例#24
0
    def test_restart_days(self):
        rst_file = EclFile(self.test_file)
        self.assertAlmostEqual(0.0, rst_file.iget_restart_sim_days(0))
        self.assertAlmostEqual(31.0, rst_file.iget_restart_sim_days(1))
        self.assertAlmostEqual(274.0, rst_file.iget_restart_sim_days(10))

        with self.assertRaises(KeyError):
            rst_file.restart_get_kw("Missing", dtime=datetime.date(2004, 1, 1))

        with self.assertRaises(IndexError):
            rst_file.restart_get_kw("SWAT", dtime=datetime.date(1985, 1, 1))
示例#25
0
    def test_create(self):
        # The init file created here only contains a PORO field. More
        # properties must be added to this before it can be used for
        # any usefull gravity calculations.
        poro = EclKW( "PORO" , self.grid.getGlobalSize() , EclTypeEnum.ECL_FLOAT_TYPE )
        with TestAreaContext("grav_init"):
            with openFortIO( "TEST.INIT" , mode = FortIO.WRITE_MODE ) as f:
                poro.fwrite( f )
            self.init = EclFile( "TEST.INIT")

            grav = EclGrav( self.grid , self.init )
示例#26
0
    def test_report_list(self):
        rlist0 = range(63)
        self.report_list_file_test(self.u_file, rlist0)

        rlist0 = [0]
        self.report_list_file_test(self.xfile0, rlist0)

        f = EclFile(self.grid_file)
        with self.assertRaises(
                ArgumentError):  #argumentError wraps the expected TypeError
            EclFile.file_report_list(f)
示例#27
0
    def test_construction(self):
        grid_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID")
        rst_path_1 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0011")
        rst_path_2 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0022")
        rst_path_3 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0035")
        rst_path_4 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0061")

        grid = EclGrid(grid_path)

        def checkWellInfo(well_info, well_count, report_step_count):
            self.assertEqual(len(well_info), well_count)

            for index, well_time_line in enumerate(well_info):
                self.assertEqual(len(well_time_line), report_step_count[index])

        well_info = WellInfo(grid, rst_path_1)
        checkWellInfo(well_info, well_count=5, report_step_count=[1, 1, 1, 1, 1])

        well_info = WellInfo(grid, EclFile(rst_path_1))
        checkWellInfo(well_info, well_count=5, report_step_count=[1, 1, 1, 1, 1])

        well_info = WellInfo(grid, [rst_path_1, rst_path_2, rst_path_3])
        checkWellInfo(well_info, well_count=8, report_step_count=[3, 3, 3, 3, 3, 2, 2, 2])

        well_info = WellInfo(grid, [EclFile(rst_path_1), EclFile(rst_path_2), rst_path_3, EclFile(rst_path_4)])
        checkWellInfo(well_info, well_count=8, report_step_count=[4, 4, 4, 4, 4, 3, 3, 3])


        well_info = WellInfo(grid)
        well_info.addWellFile(rst_path_1, True)

        checkWellInfo(well_info, well_count=5, report_step_count=[1, 1, 1, 1, 1])

        well_info.addWellFile(EclFile(rst_path_2), True)
        checkWellInfo(well_info, well_count=8, report_step_count=[2, 2, 2, 2, 2, 1, 1, 1])

        well_info.addWellFile(EclFile(rst_path_3), True)
        checkWellInfo(well_info, well_count=8, report_step_count=[3, 3, 3, 3, 3, 2, 2, 2])

        well_info.addWellFile(rst_path_4, True)
        checkWellInfo(well_info, well_count=8, report_step_count=[4, 4, 4, 4, 4, 3, 3, 3])
示例#28
0
    def test_kw_write(self):
        with TestAreaContext("python/ecl_kw/writing"):

            data = [random.random() for i in range(10000)]

            kw = EclKW("TEST", len(data), EclTypeEnum.ECL_DOUBLE_TYPE)
            i = 0
            for d in data:
                kw[i] = d
                i += 1

            pfx = 'EclKW('
            self.assertEqual(pfx, repr(kw)[:len(pfx)])

            fortio = FortIO("ECL_KW_TEST", FortIO.WRITE_MODE)
            kw.fwrite(fortio)
            fortio.close()

            fortio = FortIO("ECL_KW_TEST")

            kw2 = EclKW.fread(fortio)

            self.assertTrue(kw.equal(kw2))

            ecl_file = EclFile("ECL_KW_TEST",
                               flags=EclFileFlagEnum.ECL_FILE_WRITABLE)
            kw3 = ecl_file["TEST"][0]
            self.assertTrue(kw.equal(kw3))
            ecl_file.save_kw(kw3)
            ecl_file.close()

            fortio = FortIO("ECL_KW_TEST", FortIO.READ_AND_WRITE_MODE)
            kw4 = EclKW.fread(fortio)
            self.assertTrue(kw.equal(kw4))
            fortio.seek(0)
            kw4.fwrite(fortio)
            fortio.close()

            ecl_file = EclFile("ECL_KW_TEST")
            kw5 = ecl_file["TEST"][0]
            self.assertTrue(kw.equal(kw5))
示例#29
0
    def test_kw(self):
        f = EclFile(self.u_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))

        with self.assertRaises(IndexError):
            kw4 = f.restart_get_kw("SWAT", datetime.datetime(2009, 3, 17))
示例#30
0
    def test_geertsma_kernel_2_source_points_2_vintages():
        grid = EclGrid.createRectangular(dims=(2, 1, 1), dV=(100, 100, 100))

        with TestAreaContext("Subsidence"):
            p1 = [1, 10]
            p2 = [10, 20]
            create_restart(grid, "TEST", p1, p2)
            create_init(grid, "TEST")

            init = EclFile("TEST.INIT")
            restart_file = EclFile("TEST.UNRST")

            restart_view1 = restart_file.restartView(
                sim_time=datetime.date(2000, 1, 1))
            restart_view2 = restart_file.restartView(
                sim_time=datetime.date(2010, 1, 1))

            subsidence = EclSubsidence(grid, init)
            subsidence.add_survey_PRESSURE("S1", restart_view1)
            subsidence.add_survey_PRESSURE("S2", restart_view2)

            youngs_modulus = 5E8
            poisson_ratio = 0.3
            seabed = 0
            receiver = (1000, 1000, 0)

            dz1 = subsidence.evalGeertsma("S1", None, receiver, youngs_modulus,
                                          poisson_ratio, seabed)
            np.testing.assert_almost_equal(dz1, 8.65322541521704e-07)

            dz2 = subsidence.evalGeertsma("S2", None, receiver, youngs_modulus,
                                          poisson_ratio, seabed)
            np.testing.assert_almost_equal(dz2, 2.275556615015282e-06)

            np.testing.assert_almost_equal(dz2 - dz1, 1.4102340734935779e-06)

            dz = subsidence.evalGeertsma("S1", "S2", receiver, youngs_modulus,
                                         poisson_ratio, seabed)
            np.testing.assert_almost_equal(dz, 1.4102340734935779e-06)