Пример #1
0
    def test_from_deck(self):
        with TestAreaContext("parse-test"):
            with open("test.DATA", "w") as fileH:
                fileH.write("RUNSPEC\n")
                fileH.write("DIMENS\n")
                fileH.write(" 10 10 10 /\n")
                fileH.write("SCHEDULE\n")
                fileH.write("TSTEP\n")
                fileH.write("  10 10 /\n")
                fileH.write("TSTEP\n")
                fileH.write("  20 20 /\n")
                fileH.write("DATES\n")
                fileH.write("  10 'MAY' 2017 /\n")
                fileH.write("  15 'MAY' 2017 /\n")
                fileH.write("/\n")
                
            p = Parser( )
            deck = p.parseFile("test.DATA")

        dates_kw = deck[-1]
        record = dates_kw[0]
        self.assertTrue( isinstance( record , DeckRecord ))
        self.assertEqual( len(record) , 4 )

        with self.assertRaises(IndexError):
            record[100]

        with self.assertRaises(KeyError):
            record["NO-NOT-THAT-ITEM"]

        self.assertTrue( "DAY" in record )
        self.assertFalse( "XXX" in record )
Пример #2
0
    def test_from_deck(self):
        with TestAreaContext("parse-test"):
            with open("test.DATA", "w") as fileH:
                fileH.write("RUNSPEC\n")
                fileH.write("DIMENS\n")
                fileH.write(" 10 10 10 /\n")
                fileH.write("SCHEDULE\n")
                fileH.write("TSTEP\n")
                fileH.write("  10 10 /\n")
                fileH.write("TSTEP\n")
                fileH.write("  20 20 /\n")
                fileH.write("DATES\n")
                fileH.write("  10 'MAY' 2017 /\n")
                fileH.write("  15 'MAY' 2017 /\n")
                fileH.write("/\n")
                
            p = Parser( )
            deck = p.parseFile("test.DATA")

        self.assertEqual( len(deck) , 6 )
        dates_kw = deck[-1]
        self.assertEqual( dates_kw.name() , "DATES")
        self.assertEqual( len(dates_kw) , 2 )
        runspec_kw = deck["RUNSPEC"][0]
        self.assertEqual( len(runspec_kw) , 0 )

        with self.assertRaises( IndexError ):
            runspec_kw[0]

        with self.assertRaises( IndexError ):
            dates_kw[2]

        record = dates_kw[0]
        self.assertTrue( isinstance( record , DeckRecord ))
Пример #3
0
    def test_create(self):
        with TestAreaContext("table-manager"):
            p = Parser()
            with open("test.DATA", "w") as fileH:
                fileH.write("""
TABDIMS
 2 /

SWOF
 1 2 3 4
 5 6 7 8 /
 9 10 11 12 /
""")

            deck = p.parseFile("test.DATA")
            table_manager = TableManager(deck)

            self.assertTrue(table_manager.hasTable("SWOF"))
            self.assertFalse(table_manager.hasTable("SGLF"))
            self.assertTrue("SWOF" in table_manager)
            self.assertFalse("SGLF" in table_manager)

            with self.assertRaises(KeyError):
                table_manager.getTable("SGFL")

            self.assertEqual(table_manager.numTables("SLGF"), 0)
            self.assertEqual(table_manager.numTables("SWOF"), 2)

            with self.assertRaises(IndexError):
                table = table_manager.getTable("SWOF", num=10)
Пример #4
0
    def test_from_deck(self):
        with TestAreaContext("parse-test"):
            with open("test.DATA", "w") as fileH:
                fileH.write("RUNSPEC\n")
                fileH.write("DIMENS\n")
                fileH.write(" 10 10 10 /\n")
                fileH.write("SCHEDULE\n")
                fileH.write("TSTEP\n")
                fileH.write("  10 10 /\n")
                fileH.write("TSTEP\n")
                fileH.write("  20 20 /\n")
                fileH.write("DATES\n")
                fileH.write("  10 'MAY' 2017 /\n")
                fileH.write("  15 'MAY' 2017 /\n")
                fileH.write("/\n")

            p = Parser()
            deck = p.parseFile("test.DATA")

        dates_kw = deck[-1]
        record = dates_kw[0]
        self.assertTrue(isinstance(record, DeckRecord))
        self.assertEqual(len(record), 4)

        with self.assertRaises(IndexError):
            record[100]

        with self.assertRaises(KeyError):
            record["NO-NOT-THAT-ITEM"]

        self.assertTrue("DAY" in record)
        self.assertFalse("XXX" in record)
Пример #5
0
    def test_from_deck(self):
        with TestAreaContext("parse-test"):
            with open("test.DATA", "w") as fileH:
                fileH.write("RUNSPEC\n")
                fileH.write("DIMENS\n")
                fileH.write(" 10 10 10 /\n")
                fileH.write("SCHEDULE\n")
                fileH.write("TSTEP\n")
                fileH.write("  10 10 /\n")
                fileH.write("TSTEP\n")
                fileH.write("  20 20 /\n")
                fileH.write("DATES\n")
                fileH.write("  10 'MAY' 2017 /\n")
                fileH.write("  15 'MAY' 2017 /\n")
                fileH.write("/\n")

            p = Parser()
            deck = p.parseFile("test.DATA")

        dates_kw = deck[-1]
        record = dates_kw[0]
        day_item = record[0]
        year_item = record["YEAR"]
        month_item = record[1]

        self.assertTrue(isinstance(day_item, DeckItem))
        self.assertTrue(isinstance(year_item, DeckItem))

        self.assertEqual(day_item[0], 10)
        self.assertEqual(month_item[0], "MAY")
        self.assertEqual(year_item[0], 2017)
Пример #6
0
    def test_table(self):
        with TestAreaContext("table-manager"):
            p = Parser()
            with open("test.DATA", "w") as fileH:
                fileH.write("""
TABDIMS
 2 /

SWOF
 1 2 3 4
 5 6 7 8 /
 9 10 11 12 /
""")

            deck = p.parseFile("test.DATA")
            table_manager = TableManager(deck)
            table = table_manager.getTable("SWOF")

            self.assertTrue("SW" in table)
            self.assertFalse(table.hasColumn("JOE"))

            with self.assertRaises(KeyError):
                table.getValue("NO_NOT_THIS", 1)

            with self.assertRaises(IndexError):
                table.getValue("SW", 100)

            self.assertEqual(table.getValue("SW", 0), 1)
            self.assertEqual(table.getValue("SW", 1), 5)

            self.assertEqual(table.evaluate("KRW", 1), 2)

            index = table.lookup(1)
            self.assertEqual(table.evaluate("KRW", index), 2)
Пример #7
0
    def test_from_deck(self):
        with TestAreaContext("parse-test"):
            with open("test.DATA", "w") as fileH:
                fileH.write("RUNSPEC\n")
                fileH.write("DIMENS\n")
                fileH.write(" 10 10 10 /\n")
                fileH.write("SCHEDULE\n")
                fileH.write("TSTEP\n")
                fileH.write("  10 10 /\n")
                fileH.write("TSTEP\n")
                fileH.write("  20 20 /\n")
                fileH.write("DATES\n")
                fileH.write("  10 'MAY' 2017 /\n")
                fileH.write("  15 'MAY' 2017 /\n")
                fileH.write("/\n")
                
            p = Parser( )
            deck = p.parseFile("test.DATA")

        dates_kw = deck[-1]
        record = dates_kw[0]
        day_item = record[0]
        year_item = record["YEAR"]
        month_item = record[1]
        
        self.assertTrue( isinstance( day_item , DeckItem ))
        self.assertTrue( isinstance( year_item , DeckItem ))

        self.assertEqual( day_item[0] , 10 )
        self.assertEqual( month_item[0] , "MAY")
        self.assertEqual( year_item[0] , 2017)
Пример #8
0
    def test_create(self):
        with TestAreaContext("table-manager"):
            p = Parser()
            with open("test.DATA", "w") as fileH:
                fileH.write("""
TABDIMS
 2 /

SWOF
 1 2 3 4
 5 6 7 8 /
 9 10 11 12 /
""")
            
            deck = p.parseFile( "test.DATA")
            table_manager = TableManager( deck )

            
            self.assertTrue(  table_manager.hasTable( "SWOF" ))
            self.assertFalse( table_manager.hasTable( "SGLF" ))
            self.assertTrue( "SWOF" in table_manager )
            self.assertFalse( "SGLF" in table_manager )

            with self.assertRaises(KeyError):
                table_manager.getTable("SGFL")

            self.assertEqual( table_manager.numTables("SLGF") , 0 )
            self.assertEqual( table_manager.numTables("SWOF") , 2 )

            with self.assertRaises(IndexError):
                table = table_manager.getTable("SWOF", num = 10)
Пример #9
0
    def test_table(self):
        with TestAreaContext("table-manager"):
            p = Parser()
            with open("test.DATA", "w") as fileH:
                fileH.write("""
TABDIMS
 2 /

SWOF
 1 2 3 4
 5 6 7 8 /
 9 10 11 12 /
""")
            
            deck = p.parseFile( "test.DATA")
            table_manager = TableManager( deck )
            table = table_manager.getTable("SWOF")

            self.assertTrue("SW" in table )
            self.assertFalse(table.hasColumn("JOE"))

            with self.assertRaises(KeyError):
                table.getValue("NO_NOT_THIS" , 1)

            with self.assertRaises(IndexError):
                table.getValue("SW" , 100)

            self.assertEqual( table.getValue("SW" , 0 ) , 1)
            self.assertEqual( table.getValue("SW" , 1 ) , 5)

            self.assertEqual( table.evaluate("KRW" , 1) , 2)

            index = table.lookup( 1 )
            self.assertEqual( table.evaluate("KRW" , index) , 2)
Пример #10
0
    def test_from_deck(self):
        with TestAreaContext("parse-test"):
            with open("test.DATA", "w") as fileH:
                fileH.write("RUNSPEC\n")
                fileH.write("DIMENS\n")
                fileH.write(" 10 10 10 /\n")
                fileH.write("SCHEDULE\n")
                fileH.write("TSTEP\n")
                fileH.write("  10 10 /\n")
                fileH.write("TSTEP\n")
                fileH.write("  20 20 /\n")
                fileH.write("DATES\n")
                fileH.write("  10 'MAY' 2017 /\n")
                fileH.write("  15 'MAY' 2017 /\n")
                fileH.write("/\n")

            p = Parser()
            deck = p.parseFile("test.DATA")

        self.assertEqual(len(deck), 6)
        dates_kw = deck[-1]
        self.assertEqual(dates_kw.name(), "DATES")
        self.assertEqual(len(dates_kw), 2)
        runspec_kw = deck["RUNSPEC"][0]
        self.assertEqual(len(runspec_kw), 0)

        with self.assertRaises(IndexError):
            runspec_kw[0]

        with self.assertRaises(IndexError):
            dates_kw[2]

        record = dates_kw[0]
        self.assertTrue(isinstance(record, DeckRecord))
Пример #11
0
 def test_parse(self):
     p = Parser()
     test_file = self.createPath(
         "integration_tests/GRID/CORNERPOINT_ACTNUM.DATA")
     deck = p.parseFile(test_file)
     grid = EclipseGrid(deck)
     tables = TableManager(deck)
     ecl_props = Eclipse3DProps(deck, tables, grid)
Пример #12
0
    def test_add_keyword(self):
        p = Parser()
        schema = {'name' : 'KEYWORD' , 'size' : 1 , 'items' : [{'name' : 'File' , 'value_type' : 'STRING'}] , 'sections' : ["SCHEDULE"]}
        p.addKeyword( schema )
        self.assertTrue("KEYWORD" in p)


        with TestAreaContext("parse-test2"):
            with open("test.DATA", "w") as fileH:
                fileH.write("KEYWORD\n")
                fileH.write(" ARG /\n")
                

            deck = p.parseFile( "test.DATA" )
            self.assertTrue( "KEYWORD" in deck )
Пример #13
0
    def test_parse(self):
        p = Parser()

        # This is slightly awkward; since only the deck based
        # constructor is wrapped in the grid case we need to different
        # input files to instantiate the Schedule and EclipseGrid
        # instances respectively.
        grid_file = self.createPath( "integration_tests/GRID/CORNERPOINT_ACTNUM.DATA" )
        grid_deck = p.parseFile( grid_file )
        grid = EclipseGrid(grid_deck)

        sched_file = self.createPath("integration_tests/SCHEDULE/SCHEDULE1")
        sched_deck = p.parseFile( sched_file )
        s = Schedule( grid , sched_deck )

        end = s.endTime()
        self.assertEqual( datetime.datetime( end.year , end.month , end.day) , datetime.datetime( 2008 , 8 , 10 ))
        #self.assertEqual( s.endTime( ) , datetime.datetime( 2008 , 8 , 10 ))

        start = s.startTime()
        self.assertEqual( datetime.datetime( start.year , start.month , start.day) , datetime.datetime( 2007 , 5 , 10 ))
Пример #14
0
    def test_deck(self):
        with TestAreaContext("parse-test"):
            with open("test.DATA", "w") as fileH:
                fileH.write("RUNSPEC\n")
                fileH.write("DIMENS\n")
                fileH.write(" 10 10 10 /\n")
                fileH.write("SCHEDULE\n")
                fileH.write("TSTEP\n")
                fileH.write("  10 10 /\n")
                fileH.write("TSTEP\n")
                fileH.write("  20 20 /\n")
                fileH.write("DATES\n")
                fileH.write("  10 'MAY' 2017 /\n")
                fileH.write("/\n")
                
            p = Parser( )
            deck = p.parseFile("test.DATA")
        self.assertEqual( len(deck) , 6 )
        self.assertEqual( 2 , deck.numKeywords("TSTEP"))
        tstep = deck["TSTEP"]
        self.assertEqual( len(tstep) , 2)

        slice_list = deck[0:2:6]
        self.assertEqual( len(slice_list) , 3)
        self.assertEqual( slice_list[0].name() , "RUNSPEC")
        self.assertEqual( slice_list[1].name() , "SCHEDULE")
        self.assertEqual( slice_list[2].name() , "TSTEP")

        dates_kw = deck[-1]
        self.assertEqual( dates_kw.name() , "DATES")
        
        with self.assertRaises(IndexError):
            deck["TSTEP" , 2]

        with self.assertRaises(TypeError):
            deck["TSTEP" , "X"]
        
        t0 = deck["TSTEP",0]
        t1 = deck["TSTEP",1]
        t1 = deck["TSTEP",-1]
Пример #15
0
    def test_deck(self):
        with TestAreaContext("parse-test"):
            with open("test.DATA", "w") as fileH:
                fileH.write("RUNSPEC\n")
                fileH.write("DIMENS\n")
                fileH.write(" 10 10 10 /\n")
                fileH.write("SCHEDULE\n")
                fileH.write("TSTEP\n")
                fileH.write("  10 10 /\n")
                fileH.write("TSTEP\n")
                fileH.write("  20 20 /\n")
                fileH.write("DATES\n")
                fileH.write("  10 'MAY' 2017 /\n")
                fileH.write("/\n")

            p = Parser()
            deck = p.parseFile("test.DATA")
        self.assertEqual(len(deck), 6)
        self.assertEqual(2, deck.numKeywords("TSTEP"))
        tstep = deck["TSTEP"]
        self.assertEqual(len(tstep), 2)

        slice_list = deck[0:2:6]
        self.assertEqual(len(slice_list), 3)
        self.assertEqual(slice_list[0].name(), "RUNSPEC")
        self.assertEqual(slice_list[1].name(), "SCHEDULE")
        self.assertEqual(slice_list[2].name(), "TSTEP")

        dates_kw = deck[-1]
        self.assertEqual(dates_kw.name(), "DATES")

        with self.assertRaises(IndexError):
            deck["TSTEP", 2]

        with self.assertRaises(TypeError):
            deck["TSTEP", "X"]

        t0 = deck["TSTEP", 0]
        t1 = deck["TSTEP", 1]
        t1 = deck["TSTEP", -1]
Пример #16
0
    def test_parse(self):
        p = Parser()

        # This is slightly awkward; since only the deck based
        # constructor is wrapped in the grid case we need to different
        # input files to instantiate the Schedule and EclipseGrid
        # instances respectively.
        grid_file = self.createPath(
            "integration_tests/GRID/CORNERPOINT_ACTNUM.DATA")
        grid_deck = p.parseFile(grid_file)
        grid = EclipseGrid(grid_deck)

        sched_file = self.createPath("integration_tests/SCHEDULE/SCHEDULE1")
        sched_deck = p.parseFile(sched_file)
        s = Schedule(grid, sched_deck)

        end = s.endTime()
        self.assertEqual(datetime.datetime(end.year, end.month, end.day),
                         datetime.datetime(2008, 8, 10))
        #self.assertEqual( s.endTime( ) , datetime.datetime( 2008 , 8 , 10 ))

        start = s.startTime()
        self.assertEqual(datetime.datetime(start.year, start.month, start.day),
                         datetime.datetime(2007, 5, 10))
Пример #17
0
    def test_parse(self):
        p = Parser()
        pm = ParseContext()
        with self.assertRaises(IOError):
            p.parseFile("does/not/exist" , pm)

        with TestAreaContext("parse-test"):
            with open("test.DATA", "w") as fileH:
                fileH.write("RUNSPEC\n")
                fileH.write("DIMENS\n")
                fileH.write(" 10 10 10 /\n")
        
            deck = p.parseFile( "test.DATA" , pm)
            self.assertEqual( len(deck) , 2 )

            deck = Parser.parseFile( "test.DATA" )
Пример #18
0
 def test_parse(self):
     p = Parser()
     test_file = self.createPath( "integration_tests/GRID/CORNERPOINT_ACTNUM.DATA" )
     deck = p.parseFile( test_file )
     grid = EclipseGrid( deck )