コード例 #1
0
    def test_identify_var_type(self):
        self.assertEnumIsFullyDefined(EclSumVarType, "ecl_smspec_var_type",
                                      "libecl/include/ert/ecl/smspec_node.h")
        self.assertEqual(EclSum.varType("WWCT:OP_X"),
                         EclSumVarType.ECL_SMSPEC_WELL_VAR)
        self.assertEqual(EclSum.varType("RPR"),
                         EclSumVarType.ECL_SMSPEC_REGION_VAR)
        self.assertEqual(EclSum.varType("WNEWTON"),
                         EclSumVarType.ECL_SMSPEC_MISC_VAR)
        self.assertEqual(EclSum.varType("AARQ:4"),
                         EclSumVarType.ECL_SMSPEC_AQUIFER_VAR)

        case = createEclSum("CSV", [("FOPT", None, 0), ("FOPR", None, 0),
                                    ("AARQ", None, 10), ("RGPT", None, 1)])

        node = case.smspec_node("FOPT")
        self.assertEqual(node.varType(), EclSumVarType.ECL_SMSPEC_FIELD_VAR)

        node = case.smspec_node("AARQ:10")
        self.assertEqual(node.varType(), EclSumVarType.ECL_SMSPEC_AQUIFER_VAR)
        self.assertEqual(node.getNum(), 10)

        node = case.smspec_node("RGPT:1")
        self.assertEqual(node.varType(), EclSumVarType.ECL_SMSPEC_REGION_VAR)
        self.assertEqual(node.getNum(), 1)
        self.assertTrue(node.isTotal())
コード例 #2
0
 def test_segment(self):
     sum = EclSum(self.createTestPath("Statoil/ECLIPSE/Oseberg/F8MLT/F8MLT-F4"))
     segment_vars = sum.keys("SOFR:F-8:*")
     self.assertIn("SOFR:F-8:1", segment_vars)
     for var in segment_vars:
         tmp = var.split(":")
         nr = int(tmp[2])
         self.assertTrue(nr >= 0)
コード例 #3
0
    def test_restart(self):
        hist = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/history/T07-4A-W2011-18-P1"))
        base = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/prediction/BASECASE"))
        pred = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/prediction/BASECASE"), include_restart=False)

        self.assertIsNotNone(hist)
        self.assertIsNotNone(base)
        self.assertIsNotNone(pred)
コード例 #4
0
ファイル: test_sum_statoil.py プロジェクト: agchitu/ert
 def test_segment(self):
     sum = EclSum(self.createTestPath("Statoil/ECLIPSE/Oseberg/F8MLT/F8MLT-F4"))
     segment_vars = sum.keys("SOFR:F-8:*")
     self.assertIn("SOFR:F-8:1", segment_vars)
     for var in segment_vars:
         tmp = var.split(":")
         nr = int(tmp[2])
         self.assertTrue(nr >= 0)
コード例 #5
0
ファイル: test_sum_statoil.py プロジェクト: agchitu/ert
    def test_Heidrun(self):
        sum = EclSum( self.createTestPath("Statoil/ECLIPSE/Heidrun/Summary/FF12_2013B3_CLEAN_RS"))
        self.assertEqual( 452 , len(sum))
        self.assertFloatEqual( 1.8533144e+8 , sum.get_last_value("FOPT"))

        trange = sum.timeRange( start = datetime.date( 2015 , 1 , 1), interval = "1M")
        self.assertTrue( trange[0] == datetime.date( 2016 , 2 , 1 ))
        for t in trange:
            sum.get_interp( "FOPT" , date = t )
コード例 #6
0
ファイル: test_sum.py プロジェクト: flikka/ert
    def test_identify_var_type(self):
        self.assertEnumIsFullyDefined( EclSumVarType , "ecl_smspec_var_type" , "libecl/include/ert/ecl/smspec_node.h")
        self.assertEqual( EclSum.varType( "WWCT:OP_X") , EclSumVarType.ECL_SMSPEC_WELL_VAR )
        self.assertEqual( EclSum.varType( "RPR") , EclSumVarType.ECL_SMSPEC_REGION_VAR )
        self.assertEqual( EclSum.varType( "WNEWTON") , EclSumVarType.ECL_SMSPEC_MISC_VAR )
        case = createEclSum("CSV" , [("FOPT", None , 0) , ("FOPR" , None , 0)])
        node = case.smspec_node( "FOPT" )

        self.assertEqual( node.varType( ) , EclSumVarType.ECL_SMSPEC_FIELD_VAR )
コード例 #7
0
ファイル: test_sum_statoil.py プロジェクト: agchitu/ert
 def test_stringlist_setitem(self):
     sum = EclSum(self.case)
     wells = sum.wells()
     wells[0] = "Bjarne"
     well0 = wells[0]
     self.assertTrue(well0 == "Bjarne")
     self.assertTrue(wells[0] == "Bjarne")
     wells[0] = "XXX"
     self.assertTrue(well0 == "Bjarne")
     self.assertTrue(wells[0] == "XXX")
コード例 #8
0
ファイル: ecl_cmp.py プロジェクト: Ensembles/ert
class EclCase(object):
    def __init__(self , case):
        self.case = case

        self.grid = None
        self.restart = None
        self.init = None
        self.summary = None
        
        self.loadSummary( )


    def __contains__(self , key):
        return key in self.summary

    
    def keys(self):
        return self.summary.keys()


    def wells(self):
        return self.summary.wells( )
            
    def loadSummary(self):
        self.summary = EclSum( self.case )


    def startTimeEqual(self , other):
        if self.summary.getDataStartTime() == other.summary.getDataStartTime():
            return True
        else:
            return False

    def endTimeEqual(self , other):
        if self.summary.getEndTime() == other.summary.getEndTime():
            return True
        else:
            return False


    def cmpSummaryVector(self , other , key , sample = 100):
        if key in self and key in other:
            days_total = min( self.summary.getSimulationLength() , other.summary.getSimulationLength() )
            dt = days_total / (sample - 1)
            days = [ x * dt for x in range(sample) ]
            
            ref_data = self.summary.get_interp_vector( key , days_list = days )
            test_data = other.summary.get_interp_vector( key , days_list = days )
            diff_data = ref_data - test_data

            ref_sum = sum(ref_data)
            diff_sum = sum( abs(diff_data) )
            return (diff_sum , ref_sum)
        else:
            raise KeyError("Key:%s was not present in both cases" % key)
コード例 #9
0
class EclSumTest(ExtendedTestCase):
    def setUp(self):
        self.test_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.SMSPEC")
        self.ecl_sum = EclSum(self.test_file)

    def test_time_range_year(self):
        real_range = self.ecl_sum.timeRange(interval="1y", extend_end = False)
        extended_range = self.ecl_sum.timeRange(interval="1y", extend_end = True)
        assert real_range[-1] < extended_range[-1]

    def test_time_range_day(self):
        real_range = self.ecl_sum.timeRange(interval = "1d", extend_end = False)
        extended_range = self.ecl_sum.timeRange(interval = "1d", extend_end = True)
        assert real_range[-1] == extended_range[-1]

    def test_time_range_month(self):
        real_range = self.ecl_sum.timeRange(interval = "1m", extend_end = False)
        extended_range = self.ecl_sum.timeRange(interval = "1m", extend_end = True)
        assert real_range[-1] < extended_range[-1]

    def test_dump_csv_line(self):
        ecl_sum_vector = EclSumKeyWordVector(self.ecl_sum)
        ecl_sum_vector.addKeywords("F*")

        with self.assertRaises(KeyError):
            ecl_sum_vector.addKeyword("MISSING")

        dtime = datetime.datetime( 2002 , 01 , 01 , 0 , 0 , 0 )
        with TestAreaContext("EclSum/csv_dump"):
            test_file_name = self.createTestPath("dump.csv")
            outputH = open(test_file_name , "w")
            self.ecl_sum.dumpCSVLine( dtime, ecl_sum_vector, outputH)
            assert os.path.isfile(test_file_name)
コード例 #10
0
ファイル: test_enkf_obs.py プロジェクト: bramirex/ert
    def test_create(self):
        ensemble_config = EnsembleConfig()
        obs = EnkfObs(ensemble_config)
        self.assertEqual(len(obs), 0)
        self.assertFalse(obs.load(self.obs_config))
        self.assertEqual(len(obs), 0)

        time_map = TimeMap()
        obs = EnkfObs(ensemble_config, external_time_map=time_map)
        self.assertEqual(len(obs), 0)

        grid = EclGrid(self.grid)
        refcase = EclSum(self.refcase)

        history = History.alloc_from_refcase(refcase, False)
        obs = EnkfObs(ensemble_config, grid=grid, history=history)
        with self.assertRaises(IOError):
            obs.load("/does/not/exist")

        self.assertTrue(obs.load(self.obs_config))
        self.assertEqual(len(obs), 33)
        obs.clear()
        self.assertEqual(len(obs), 0)

        obs.load(self.obs_config)
        self.assertEqual(len(obs), 33)
        self.assertFalse("RFT2" in obs)
        obs.load(self.obs_config2)
        self.assertEqual(len(obs), 35)
        self.assertTrue("RFT2" in obs)
コード例 #11
0
ファイル: test_ecl_submit.py プロジェクト: danielfmva/ert
    def test_RSH_submit(self):
        root = os.path.join(self.nfs_work_path, getpass.getuser(),
                            "ert-test/python/ecl_submit/RSH")
        if not os.path.exists(root):
            os.makedirs(root)
        os.chdir(root)

        num_submit = 6
        host_list = []
        for h in self.rsh_servers.split():
            tmp = h.split(":")
            if len(tmp) > 1:
                num = int(tmp[1])
            else:
                num = 1
            host_list.append((tmp[0], num))

        queue = EclQueue(RSHDriver(3, host_list), size=num_submit)
        path_list = []

        for iens in (range(num_submit)):
            run_path = self.make_run_path(iens)
            path_list.append(run_path)
            job = queue.submitDataFile("%s/%s.DATA" % (run_path, base))

        while queue.isRunning():
            time.sleep(1)

        for path in path_list:
            sum = EclSum("%s/%s" % (path, base))
            self.assertIsInstance(sum, EclSum)
            self.assertEqual(2, sum.last_report)
コード例 #12
0
ファイル: test_ecl_submit.py プロジェクト: danielfmva/ert
    def test_LSF_submit(self):
        root = os.path.join(self.nfs_work_path, getpass.getuser(),
                            "ert-test/python/ecl_submit/LSF")
        if not os.path.exists(root):
            os.makedirs(root)
        os.chdir(root)

        num_submit = 6
        queue = EclQueue(driver_type=QueueDriverEnum.LSF_DRIVER,
                         max_running=4,
                         size=num_submit)
        path_list = []

        for iens in (range(num_submit)):
            run_path = self.make_run_path(iens, LSF=True)
            path_list.append(run_path)
            job = queue.submitDataFile("%s/%s.DATA" % (run_path, LSF_base))

        while queue.isRunning():
            time.sleep(1)

        for path in path_list:
            sum = EclSum("%s/%s" % (path, LSF_base))
            self.assertIsInstance(sum, EclSum)
            self.assertEqual(2, sum.last_report)
コード例 #13
0
ファイル: test_ecl_well3.py プロジェクト: stefoss23/ert
    def test_rates(self):
        grid_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID")
        rst_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST")
        sum_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.SMSPEC")

        grid = EclGrid(grid_path)
        well_info = WellInfo(grid, rst_path)
        sum = EclSum(sum_path)

        for wtl in well_info:
            for well_state in wtl:
                # print "%03d  %g   %g " % (R , well_state.oilRate(), sum.get_from_report( "WOPR:%s" % well , R))
                if wtl.getName() == "OP_4":
                    pass
                    # print well_state.oilRate(), well_state.waterRate(), well_state.gasRate(), well_state.volumeRate()
                    # print well_state.oilRateSI(), well_state.waterRateSI(), well_state.gasRateSI(), well_state.volumeRateSI()
                    self.assertEqual(well_state.oilRate(),
                                     well_state.oilRateSI())
                    self.assertEqual(well_state.waterRate(),
                                     well_state.waterRateSI())
                    self.assertEqual(well_state.gasRate(),
                                     well_state.gasRateSI())
                    self.assertEqual(well_state.volumeRate(),
                                     well_state.volumeRateSI())
                    # print sum.get_from_report("WOPR:%s" % wtl.getName(), 1)
                    # print sum.get_from_report( "WWPR:%s" % wtl.getName(), 30 )

                    for conn in well_state.globalConnections():
                        # print conn.gasRate(), conn.waterRate(), conn.oilRate()
                        # print conn.gasRateSI(), conn.waterRateSI(), conn.oilRateSI()
                        self.assertEqual(conn.gasRate(), conn.gasRateSI())
                        self.assertEqual(conn.waterRate(), conn.waterRateSI())
                        self.assertEqual(conn.oilRate(), conn.oilRateSI())
                        self.assertEqual(conn.volumeRate(),
                                         conn.volumeRateSI())
コード例 #14
0
ファイル: test_ecl_sum_tstep.py プロジェクト: Ensembles/ert
    def test_creation(self):
        ecl_sum = EclSum.writer("TEST", datetime(2010, 1, 1), 10, 10, 10)
        ecl_sum.addVariable("FOPT")
        ecl_sum.addVariable("FOPR")

        smspec = ecl_sum.cNamespace().get_smspec(ecl_sum)

        test_data = [(1, 0, 10), (1, 1, 20), (1, 2, 30), (2, 0, 40)]

        for report_step, mini_step, sim_days in test_data:
            ecl_sum_tstep = EclSumTStep(report_step, mini_step, sim_days, smspec)

            self.assertEqual(ecl_sum_tstep.getSimDays(), sim_days)
            self.assertEqual(ecl_sum_tstep.getReport(), report_step)
            self.assertEqual(ecl_sum_tstep.getMiniStep(), mini_step)

            self.assertTrue("FOPT" in ecl_sum_tstep)
            self.assertTrue("FOPR" in ecl_sum_tstep)
            self.assertFalse("WWCT" in ecl_sum_tstep)

            random_float = random.random()
            ecl_sum_tstep["FOPT"] = random_float
            ecl_sum_tstep["FOPR"] = random_float + 1

            self.assertAlmostEqual(random_float, ecl_sum_tstep["FOPT"], places=5)
            self.assertAlmostEqual(random_float + 1, ecl_sum_tstep["FOPR"], places=5)

            with self.assertRaises(KeyError):
                ecl_sum_tstep["FROPR"] = 2

            with self.assertRaises(KeyError):
                value = ecl_sum_tstep["FROPR"]
コード例 #15
0
    def test_writer(self):
        writer = EclSum.writer("CASE", datetime.date(2000, 1, 1), 10, 10, 5)
        self.assertIsInstance(self.ecl_sum, EclSum)

        writer.addVariable("FOPT")
        self.assertTrue(writer.has_key("FOPT"))

        writer.addTStep(1, 100)
コード例 #16
0
ファイル: test_sum.py プロジェクト: akva2/ert
    def test_writer(self):
        writer = EclSum.writer("CASE", datetime.date(2000, 1, 1), 10, 10, 5)
        self.assertIsInstance(self.ecl_sum, EclSum)

        writer.addVariable("FOPT")
        self.assertTrue(writer.has_key("FOPT"))

        writer.addTStep(1, 100)
コード例 #17
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 )
コード例 #18
0
 def test_case2( self ):
     cwd = os.getcwd()
     os.chdir(self.createTestPath(path))
     sum = EclSum(base)
     self.assertIsNone(sum.path)
     self.assertTrue(sum.base == base)
     self.assertTrue(sum.case == base)
     self.assertTrue(sum.abs_path == self.createTestPath(path))
     os.chdir(cwd)
コード例 #19
0
    def test_restart_mapping(self):
        history = EclSum( self.createTestPath( "Statoil/ECLIPSE/SummaryRestart/iter-1/NOR-2013A_R007-0") )
        total = EclSum( self.createTestPath( "Statoil/ECLIPSE/SummaryRestart/Prediction/NOR-2013A_R007_PRED-0") , include_restart = True)

        history_dates = history.get_dates( )
        total_dates = total.get_dates( )
        for i in range(len(history_dates)):
            self.assertEqual( history_dates[i] , total_dates[i] )

            
        keys = history.keys( pattern = "W*")
        for key in keys:
            if key in total:
                self.assertEqual( history.iget( key , 5 ) , total.iget( key , 5 ))

        self.assertFalse( "WGPR:NOT_21_D" in history )
        self.assertTrue( "WGPR:NOT_21_D" in total )

        self.assertEqual( total.iget( "WGPR:NOT_21_D", 5) , 0) # Default value
コード例 #20
0
ファイル: test_npv.py プロジェクト: Ensembles/ert
    def test_eval(self):
        npv = EclNPV(self.case)
        npv.compile("[FOPT]")
        npv1 = npv.evalNPV()

        npv2 = 0
        sum = EclSum(self.case)
        trange = sum.timeRange()
        fopr = sum.blockedProduction("FOPT" , trange)
        for v in fopr:
            npv2 += v
        self.assertAlmostEqual( npv1 , npv2 )
        
        npv.compile("[FOPT] - 0.5*[FOPT] - 0.5*[FOPT]")
        npv1 = npv.evalNPV()
        self.assertTrue( abs(npv1) < 1e-2 )

        npv.compile("[WOPT:OP_1] - 0.5*[WOPT:OP_1] - 0.5*[WOPT:OP_1]")
        npv1 = npv.evalNPV()
        self.assertTrue( abs(npv1) < 1e-2 )
コード例 #21
0
 def __init__(self, baseCase):
     sum = EclSum(baseCase)
     if sum:
         self.baseCase = sum
     else:
         raise Error("Failed to open ECLIPSE sumamry case:%s" % baseCase)
     self.expression = None
     self.keyList = {}
     self.start = None
     self.end = None
     self.interval = "1Y"
コード例 #22
0
ファイル: test_ecl_sum.py プロジェクト: blattms/ert-debian
 def test_truncated_smspec(self):
     with TestAreaContext("EclSum/truncated_smspec") as ta:
         ta.copy_file( self.test_file )
         ta.copy_file( self.createTestPath( "Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY" ))
         
         file_size = os.path.getsize( "ECLIPSE.SMSPEC")
         with open("ECLIPSE.SMSPEC","r+") as f:
             f.truncate( file_size / 2 )
             
         with self.assertRaises(IOError):
             EclSum( "ECLIPSE" )
コード例 #23
0
ファイル: test_sum.py プロジェクト: akva2/ert
    def test_timeRange(self):
        sum = EclSum(self.case)
        with self.assertRaises(TypeError):
            trange = sum.timeRange(interval="1")
            trange = sum.timeRange(interval="1X")
            trange = sum.timeRange(interval="YY")
            trange = sum.timeRange(interval="MY")

        with self.assertRaises(ValueError):
            trange = sum.timeRange(start=datetime.datetime(2000, 1, 1), end=datetime.datetime(1999, 1, 1))

        sim_start = datetime.datetime(2000, 1, 1, 0, 0, 0)
        sim_end = datetime.datetime(2004, 12, 31, 0, 0, 0)
        trange = sum.timeRange(interval="1Y")
        self.assertTrue(trange[0] == datetime.date(2000, 1, 1))
        self.assertTrue(trange[1] == datetime.date(2001, 1, 1))
        self.assertTrue(trange[2] == datetime.date(2002, 1, 1))
        self.assertTrue(trange[3] == datetime.date(2003, 1, 1))
        self.assertTrue(trange[4] == datetime.date(2004, 1, 1))
        self.assertTrue(trange[5] == datetime.date(2005, 1, 1))

        trange = sum.timeRange(interval="1M")
        self.assertTrue(trange[0] == datetime.date(2000, 1, 1))
        self.assertTrue(trange[-1] == datetime.date(2005, 1, 1))

        trange = sum.timeRange(start=datetime.date(2002, 1, 15), interval="1M")
        self.assertTrue(trange[0] == datetime.date(2002, 1, 1))
        self.assertTrue(trange[-1] == datetime.date(2005, 1, 1))

        trange = sum.timeRange(start=datetime.date(2002, 1, 15), end=datetime.date(2003, 1, 15), interval="1M")
        self.assertTrue(trange[0] == datetime.date(2002, 1, 1))
        self.assertTrue(trange[-1] == datetime.date(2003, 2, 1))

        trange = sum.timeRange(
            start=datetime.date(2002, 1, 15), end=datetime.datetime(2003, 1, 15, 0, 0, 0), interval="1M"
        )
        self.assertTrue(trange[0] == datetime.date(2002, 1, 1))
        self.assertTrue(trange[-1] == datetime.date(2003, 2, 1))
コード例 #24
0
    def test_Heidrun(self):
        sum = EclSum( self.createTestPath("Statoil/ECLIPSE/Heidrun/Summary/FF12_2013B3_CLEAN_RS"))
        self.assertEqual( 452 , len(sum))
        self.assertFloatEqual( 1.8533144e+8 , sum.get_last_value("FOPT"))

        trange = sum.timeRange( start = datetime.date( 2015 , 1 , 1), interval = "1M")
        self.assertTrue( trange[0] == datetime.date( 2016 , 2 , 1 ))
        for t in trange:
            sum.get_interp( "FOPT" , date = t )
コード例 #25
0
ファイル: test_sum_statoil.py プロジェクト: Thif/ert-1
    def test_Heidrun(self):
        sum = EclSum( self.createTestPath("Statoil/ECLIPSE/Heidrun/Summary/FF12_2013B3_CLEAN_RS"))
        self.assertEqual( 452 , len(sum))
        self.assertFloatEqual( 1.8533144e+8 , sum.get_last_value("FOPT"))

        trange = sum.timeRange( start = datetime.date( 2015 , 1 , 1), interval = "1M")
        self.assertTrue( trange[0] == datetime.date( 2016 , 2 , 1 ))
        for t in trange:
            sum.get_interp( "FOPT" , date = t )
        

        with TestAreaContext("csv/export"):
            sum.exportCSV("file.csv")
            input_file = csv.DictReader( open("file.csv"))
            for row in input_file:
                keys = sum.keys( pattern = "W*")
                keys |= sum.keys( pattern = "G")
                
                for key in keys:
                    self.assertTrue( key in row )
                break
コード例 #26
0
ファイル: test_ecl_sum.py プロジェクト: blattms/ert-debian
 def test_missing_smspec_keyword(self):
     with TestAreaContext("EclSum/truncated_data") as ta:
         ta.copy_file( self.test_file )
         ta.copy_file( self.createTestPath( "Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY" ))
     
         with openEclFile("ECLIPSE.SMSPEC") as f:
             kw_list = []
             for kw in f:
                 kw_list.append(EclKW.copy( kw ) )
         
         with openFortIO("ECLIPSE.SMSPEC" , mode = FortIO.WRITE_MODE) as f:
             for kw in kw_list:
                 if kw.getName() == "KEYWORDS":
                     continue
                 kw.fwrite(f)
         
         with self.assertRaises(IOError):
             EclSum( "ECLIPSE" )
コード例 #27
0
ファイル: ecl_sum_mock.py プロジェクト: Thif/ert-1
def createEclSum( case , keys , start = datetime.date(2010 , 1, 1) , sim_length_days = 5 * 365 , num_report_step = 5, num_mini_step = 10, dims = (20,10,5) , func_table = {}):
    ecl_sum = EclSum.writer(case , start , dims[0] , dims[1] , dims[2])
    var_list = []
    for (kw,wgname,num) in keys:
        var_list.append( ecl_sum.addVariable( kw , wgname = wgname , num = num) )

    report_step_length = sim_length_days / num_report_step
    mini_step_length = report_step_length / num_mini_step
    for report_step in range(num_report_step):
        for mini_step in range(num_mini_step):
            days = report_step * report_step_length + mini_step * mini_step_length
            t_step = ecl_sum.addTStep( report_step + 1 , sim_days = days )
                
            for var in var_list:
                key = var.getKey1( )
                if key in func_table:
                    t_step[key] = func( days )
                else:
                    t_step[key] = mock_func( ecl_sum , key , days)

    return ecl_sum
コード例 #28
0
ファイル: test_ecl_sum_vector.py プロジェクト: Ensembles/ert
class EclSumVectorTest(ExtendedTestCase):
    def setUp(self):
        self.test_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.SMSPEC")
        self.ecl_sum = EclSum(self.test_file)

    def test_reportOnly_warns(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            vector = EclSumVector(self.ecl_sum, "FOPT", True)
            assert len(w) == 1
            assert issubclass(w[-1].category, DeprecationWarning)

    def test_basic(self):
        self.assertEqual(512, len(self.ecl_sum.keys()))
        pfx = "EclSum(name"
        self.assertEqual(pfx, repr(self.ecl_sum)[: len(pfx)])
        it = iter(self.ecl_sum)
        t = self.ecl_sum[it.next()]  # EclSumVector
        self.assertEqual(63, len(t))
        self.assertEqual("BARSA", t.unit)
        pfx = "EclSumVector(key = "
        self.assertEqual(pfx, repr(t)[: len(pfx)])
コード例 #29
0
ファイル: test_ecl_submit.py プロジェクト: danielfmva/ert
    def test_LOCAL_submit(self):
        #work_area = TestArea("python/ecl_submit/LOCAL", True)

        with TestAreaContext("python/ecl_submit/LOCAL") as work_area:
            num_submit = 4
            queue = EclQueue(driver_type=QueueDriverEnum.LOCAL_DRIVER,
                             max_running=2)
            path_list = []

            for iens in range(num_submit):
                run_path = self.make_run_path(iens)
                path_list.append(run_path)
                job = queue.submitDataFile("%s/%s.DATA" % (run_path, base))

            queue.submit_complete()
            while queue.isRunning():
                time.sleep(1)

            for path in path_list:
                sum = EclSum("%s/%s" % (path, base))
                self.assertIsInstance(sum, EclSum)
                self.assertEqual(2, sum.last_report)
                shutil.rmtree(path)
コード例 #30
0
    def test_creation(self):
        ecl_sum = EclSum.writer("TEST", datetime(2010, 1, 1), 10, 10, 10)
        ecl_sum.addVariable("FOPT")
        ecl_sum.addVariable("FOPR")

        smspec = ecl_sum.cNamespace().get_smspec(ecl_sum)

        test_data = [(1, 0, 10), (1, 1, 20), (1, 2, 30), (2, 0, 40)]

        for report_step, mini_step, sim_days in test_data:
            ecl_sum_tstep = EclSumTStep(report_step, mini_step, sim_days,
                                        smspec)

            self.assertEqual(ecl_sum_tstep.getSimDays(), sim_days)
            self.assertEqual(ecl_sum_tstep.getReport(), report_step)
            self.assertEqual(ecl_sum_tstep.getMiniStep(), mini_step)

            self.assertTrue("FOPT" in ecl_sum_tstep)
            self.assertTrue("FOPR" in ecl_sum_tstep)
            self.assertFalse("WWCT" in ecl_sum_tstep)

            random_float = random.random()
            ecl_sum_tstep["FOPT"] = random_float
            ecl_sum_tstep["FOPR"] = random_float + 1

            self.assertAlmostEqual(random_float,
                                   ecl_sum_tstep["FOPT"],
                                   places=5)
            self.assertAlmostEqual(random_float + 1,
                                   ecl_sum_tstep["FOPR"],
                                   places=5)

            with self.assertRaises(KeyError):
                ecl_sum_tstep["FROPR"] = 2

            with self.assertRaises(KeyError):
                value = ecl_sum_tstep["FROPR"]
コード例 #31
0
class EclSumVectorTest(ExtendedTestCase):
    def setUp(self):
        self.test_file = self.createTestPath(
            "Statoil/ECLIPSE/Gurbat/ECLIPSE.SMSPEC")
        self.ecl_sum = EclSum(self.test_file)

    def test_reportOnly_warns(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            vector = EclSumVector(self.ecl_sum, "FOPT", True)
            assert len(w) == 1
            assert issubclass(w[-1].category, DeprecationWarning)

    def test_basic(self):
        self.assertEqual(512, len(self.ecl_sum.keys()))
        pfx = 'EclSum(name'
        self.assertEqual(pfx, repr(self.ecl_sum)[:len(pfx)])
        it = iter(self.ecl_sum)
        t = self.ecl_sum[it.next()]  # EclSumVector
        self.assertEqual(63, len(t))
        self.assertEqual('BARSA', t.unit)
        pfx = 'EclSumVector(key = '
        self.assertEqual(pfx, repr(t)[:len(pfx)])
コード例 #32
0
class EclSumTest(ExtendedTestCase):
    def setUp(self):
        self.test_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.SMSPEC")
        self.ecl_sum = EclSum(self.test_file)

    def test_time_range_year(self):
        real_range = self.ecl_sum.timeRange(interval="1y", extend_end = False)
        extended_range = self.ecl_sum.timeRange(interval="1y", extend_end = True)
        assert real_range[-1] < extended_range[-1]

    def test_time_range_day(self):
        real_range = self.ecl_sum.timeRange(interval = "1d", extend_end = False)
        extended_range = self.ecl_sum.timeRange(interval = "1d", extend_end = True)
        assert real_range[-1] == extended_range[-1]

    def test_time_range_month(self):
        real_range = self.ecl_sum.timeRange(interval = "1m", extend_end = False)
        extended_range = self.ecl_sum.timeRange(interval = "1m", extend_end = True)
        assert real_range[-1] < extended_range[-1]
コード例 #33
0
ファイル: test_sum_statoil.py プロジェクト: agchitu/ert
 def test_stringlist_reference(self):
     sum = EclSum(self.case)
     wells = sum.wells()
     self.assertListEqual([well for well in wells], ['OP_1', 'OP_2', 'OP_3', 'OP_4', 'OP_5', 'WI_1', 'WI_2', 'WI_3'])
     self.assertIsInstance(wells, StringList)
コード例 #34
0
ファイル: test_sum_statoil.py プロジェクト: agchitu/ert
 def test_LLINEAR(self):
     sum = EclSum( self.createTestPath("Statoil/ECLIPSE/Heidrun/LGRISSUE/EM-LTAA-ISEG_CARFIN_NWPROPS"))
     self.assertTrue( sum.has_key("LLINEARS") )
コード例 #35
0
ファイル: test_sum_statoil.py プロジェクト: agchitu/ert
 def test_stringlist_gc(self):
     sum = EclSum(self.case)
     wells = sum.wells()
     well1 = wells[0]
     del wells
     self.assertTrue(well1 == "OP_1")
コード例 #36
0
ファイル: test_ecl_sum.py プロジェクト: agchitu/ert
 def test_labscale(self):
     case = self.createTestPath("Statoil/ECLIPSE/LabScale/HDMODEL")
     sum = EclSum( case )
     self.assertEqual( sum.getStartTime( ) , datetime.datetime(2013,1,1,0,0,0))
     self.assertEqual( sum.getEndTime( )   , datetime.datetime(2013,1,1,19,30,0))
     self.assertFloatEqual( sum.getSimulationLength() , 0.8125 )
コード例 #37
0
def runSimulator(simulator, history_simulator, time_step_count):
    """ @rtype: EclSum """
    ecl_sum = EclSum.writer("SNAKE_OIL_FIELD", datetime(2010, 1, 1), 10, 10,
                            10)

    ecl_sum.addVariable("FOPT")
    ecl_sum.addVariable("FOPR")
    ecl_sum.addVariable("FGPT")
    ecl_sum.addVariable("FGPR")
    ecl_sum.addVariable("FWPT")
    ecl_sum.addVariable("FWPR")
    ecl_sum.addVariable("FGOR")
    ecl_sum.addVariable("FWCT")

    ecl_sum.addVariable("FOPTH")
    ecl_sum.addVariable("FOPRH")
    ecl_sum.addVariable("FGPTH")
    ecl_sum.addVariable("FGPRH")
    ecl_sum.addVariable("FWPTH")
    ecl_sum.addVariable("FWPRH")
    ecl_sum.addVariable("FGORH")
    ecl_sum.addVariable("FWCTH")

    ecl_sum.addVariable("WOPR", wgname="OP1")
    ecl_sum.addVariable("WOPR", wgname="OP2")
    ecl_sum.addVariable("WWPR", wgname="OP1")
    ecl_sum.addVariable("WWPR", wgname="OP2")
    ecl_sum.addVariable("WGPR", wgname="OP1")
    ecl_sum.addVariable("WGPR", wgname="OP2")
    ecl_sum.addVariable("WGOR", wgname="OP1")
    ecl_sum.addVariable("WGOR", wgname="OP2")
    ecl_sum.addVariable("WWCT", wgname="OP1")
    ecl_sum.addVariable("WWCT", wgname="OP2")

    ecl_sum.addVariable("WOPRH", wgname="OP1")
    ecl_sum.addVariable("WOPRH", wgname="OP2")
    ecl_sum.addVariable("WWPRH", wgname="OP1")
    ecl_sum.addVariable("WWPRH", wgname="OP2")
    ecl_sum.addVariable("WGPRH", wgname="OP1")
    ecl_sum.addVariable("WGPRH", wgname="OP2")
    ecl_sum.addVariable("WGORH", wgname="OP1")
    ecl_sum.addVariable("WGORH", wgname="OP2")
    ecl_sum.addVariable("WWCTH", wgname="OP1")
    ecl_sum.addVariable("WWCTH", wgname="OP2")

    ecl_sum.addVariable("BPR", num=globalIndex(5, 5, 5))
    ecl_sum.addVariable("BPR", num=globalIndex(1, 3, 8))

    time_map = []
    mini_step_count = 10
    total_step_count = time_step_count * mini_step_count

    for report_step in range(time_step_count):
        for mini_step in range(mini_step_count):
            t_step = ecl_sum.addTStep(report_step + 1,
                                      sim_days=report_step * mini_step_count +
                                      mini_step)

            time_map.append(
                t_step.getSimTime().datetime().strftime("%d/%m/%Y"))

            simulator.step(scale=1.0 / total_step_count)
            history_simulator.step(scale=1.0 / total_step_count)

            t_step["FOPR"] = simulator.fopr()
            t_step["FOPT"] = simulator.fopt()
            t_step["FGPR"] = simulator.fgpr()
            t_step["FGPT"] = simulator.fgpt()
            t_step["FWPR"] = simulator.fwpr()
            t_step["FWPT"] = simulator.fwpt()
            t_step["FGOR"] = simulator.fgor()
            t_step["FWCT"] = simulator.fwct()

            t_step["WOPR:OP1"] = simulator.opr("OP1")
            t_step["WOPR:OP2"] = simulator.opr("OP2")

            t_step["WGPR:OP1"] = simulator.gpr("OP1")
            t_step["WGPR:OP2"] = simulator.gpr("OP2")

            t_step["WWPR:OP1"] = simulator.wpr("OP1")
            t_step["WWPR:OP2"] = simulator.wpr("OP2")

            t_step["WGOR:OP1"] = simulator.gor("OP1")
            t_step["WGOR:OP2"] = simulator.gor("OP2")

            t_step["WWCT:OP1"] = simulator.wct("OP1")
            t_step["WWCT:OP2"] = simulator.wct("OP2")

            t_step["BPR:5,5,5"] = simulator.bpr("5,5,5")
            t_step["BPR:1,3,8"] = simulator.bpr("1,3,8")

            t_step["FOPRH"] = history_simulator.fopr()
            t_step["FOPTH"] = history_simulator.fopt()
            t_step["FGPRH"] = history_simulator.fgpr()
            t_step["FGPTH"] = history_simulator.fgpt()
            t_step["FWPRH"] = history_simulator.fwpr()
            t_step["FWPTH"] = history_simulator.fwpt()
            t_step["FGORH"] = history_simulator.fgor()
            t_step["FWCTH"] = history_simulator.fwct()

            t_step["WOPRH:OP1"] = history_simulator.opr("OP1")
            t_step["WOPRH:OP2"] = history_simulator.opr("OP2")

            t_step["WGPRH:OP1"] = history_simulator.gpr("OP1")
            t_step["WGPRH:OP2"] = history_simulator.gpr("OP2")

            t_step["WWPRH:OP1"] = history_simulator.wpr("OP1")
            t_step["WWPRH:OP2"] = history_simulator.wpr("OP2")

            t_step["WGORH:OP1"] = history_simulator.gor("OP1")
            t_step["WGORH:OP2"] = history_simulator.gor("OP2")

            t_step["WWCTH:OP1"] = history_simulator.wct("OP1")
            t_step["WWCTH:OP2"] = history_simulator.wct("OP2")

    return ecl_sum, time_map
コード例 #38
0
ファイル: test_sum.py プロジェクト: JacobStoren/ert
class SumTest(ExtendedTestCase):
    def setUp(self):
        self.case = self.createTestPath(case)
        self.ecl_sum = EclSum(self.case)

        self.assertIsInstance(self.ecl_sum, EclSum)

    def test_load(self):
        self.assertIsNotNone(self.ecl_sum, "Load failed")

    def test_interp(self):
        sum = self.ecl_sum

        self.assertAlmostEqual(sum.get_interp("WWCT:OP_3", days=750), 0.11719122)
        self.assertAlmostEqual(sum.get_interp("WWCT:OP_3", date=datetime.date(2004, 1, 1)), 0.603358387947)

        v = sum.get_interp_vector("WOPT:OP_1", days_list=[100, 200, 400, 800])
        self.assertAlmostEqualList([805817.11875, 1614955.34677419, 3289267.67857143, 6493021.6218035], v)

        v = sum.get_interp_vector(
            "WGPT:OP_2", date_list=[datetime.date(2002, 1, 1), datetime.date(2003, 1, 1), datetime.date(2004, 1, 1)]
        )
        self.assertAlmostEqualList(v, [8.20773632e08, 9.68444032e08, 1.02515213e09])

    def test_wells(self):
        wells = self.ecl_sum.wells()
        wells.sort()
        self.assertAlmostEqualList(wells, ["OP_1", "OP_2", "OP_3", "OP_4", "OP_5", "WI_1", "WI_2", "WI_3"])

        wells = self.ecl_sum.wells(pattern="*_3")
        wells.sort()
        self.assertAlmostEqualList(wells, ["OP_3", "WI_3"])

        groups = self.ecl_sum.groups()
        groups.sort()
        self.assertAlmostEqualList(groups, ["GMWIN", "OP", "WI"])

    def test_last(self):
        last = self.ecl_sum.get_last("FOPT")
        self.assertAlmostEqual(last.value, 38006336.0)
        self.assertAlmostEqual(last.days, 1826.0)
        self.assertEqual(last.date, datetime.datetime(2004, 12, 31, 0, 0, 0))

        self.assertAlmostEqual(self.ecl_sum.get_last_value("FGPT"), 6605249024.0)

    def test_dates(self):
        sum = self.ecl_sum
        d = sum.dates

        self.assertEqual(d[0], datetime.datetime(2000, 1, 1, 0, 0, 0))
        self.assertEqual(d[62], datetime.datetime(2004, 12, 31, 0, 0, 0))
        self.assertEqual(len(d), 63)
        self.assertEqual(d[25], datetime.datetime(2001, 12, 1, 0, 0, 0))
        self.assertEqual(sum.iget_date(25), datetime.datetime(2001, 12, 1, 0, 0, 0))

        mpl_dates = sum.mpl_dates
        self.assertAlmostEqual(mpl_dates[25], 730820)

        days = sum.days
        self.assertAlmostEqual(days[50], 1461)

        self.assertEqual(sum.start_time, datetime.datetime(2000, 1, 1, 0, 0, 0))
        self.assertEqual(sum.end_time, datetime.datetime(2004, 12, 31, 0, 0, 0))
        self.assertTrue(sum.check_sim_time(datetime.datetime(2004, 12, 31, 0, 0, 0)))

    def test_keys(self):
        sum = self.ecl_sum
        self.assertRaises(KeyError, sum.__getitem__, "BJARNE")

        v = sum["FOPT"]
        self.assertEqual(len(v), 63)

    def test_index(self):
        sum = self.ecl_sum
        index = sum.get_key_index("TCPUDAY")
        self.assertEqual(index, 10239)

    def test_report(self):
        sum = self.ecl_sum
        self.assertEqual(sum.get_report(date=datetime.date(2000, 10, 1)), 10)
        self.assertEqual(sum.get_report(date=datetime.date(2000, 10, 3)), -1)
        self.assertEqual(sum.get_report(date=datetime.date(1980, 10, 3)), -1)
        self.assertEqual(sum.get_report(date=datetime.date(2012, 10, 3)), -1)

        self.assertEqual(sum.get_report(days=91), 3)
        self.assertEqual(sum.get_report(days=92), -1)
        self.assertAlmostEqual(sum.get_interp("FOPT", days=91), sum.get_from_report("FOPT", 3))

        self.assertEqual(sum.first_report, 1)
        self.assertEqual(sum.last_report, 62)

        self.assertEqual(sum.get_report_time(10), datetime.date(2000, 10, 1))
        self.assertAlmostEqualScaled(sum.get_from_report("FOPT", 10), 6.67447e06)

    @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow test skipped")
    def test_fwrite(self):
        # todo: What is tested here?
        # work_area = TestArea("python/sum-test/fwrite", True)
        with TestAreaContext("python/sum-test/fwrite", True):
            self.ecl_sum.fwrite(ecl_case="CASE")
            self.assertTrue(True)

    def test_block(self):
        sum = self.ecl_sum
        index_ijk = sum.get_key_index("BPR:15,28,1")
        index_num = sum.get_key_index("BPR:1095")
        self.assertEqual(index_ijk, index_num)

    def test_restart(self):
        hist = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/history/T07-4A-W2011-18-P1"))
        base = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/prediction/BASECASE"))
        pred = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/prediction/BASECASE"), include_restart=False)

        self.assertIsNotNone(hist)
        self.assertIsNotNone(base)
        self.assertIsNotNone(pred)

    def test_case1(self):
        self.assertTrue(self.ecl_sum.path == self.createTestPath(path))
        self.assertTrue(self.ecl_sum.base == base)
        self.assertTrue(self.ecl_sum.case == self.createTestPath(case))
        self.assertTrue(self.ecl_sum.abs_path == self.createTestPath(path))

    def test_case2(self):
        cwd = os.getcwd()
        os.chdir(self.createTestPath(path))
        sum = EclSum(base)
        self.assertIsNone(sum.path)
        self.assertTrue(sum.base == base)
        self.assertTrue(sum.case == base)
        self.assertTrue(sum.abs_path == self.createTestPath(path))
        os.chdir(cwd)

    def test_var_properties(self):
        sum = self.ecl_sum
        self.assertRaises(KeyError, sum.smspec_node, "BJARNE")

        node = sum.smspec_node("FOPT")
        self.assertTrue(node.is_total)
        self.assertFalse(node.is_historical)

        node = sum.smspec_node("FOPR")
        self.assertFalse(node.is_total)
        self.assertFalse(node.is_historical)
        self.assertTrue(node.keyword == "FOPR")

        node = sum.smspec_node("FOPRH")
        self.assertFalse(node.is_total)
        self.assertTrue(node.is_historical)
        self.assertTrue(node.is_rate)
        self.assertTrue(node.keyword == "FOPRH")

        node = sum.smspec_node("WOPR:OP_1")
        self.assertFalse(node.is_total)
        self.assertTrue(node.is_rate)
        self.assertTrue(node.keyword == "WOPR")

        node = sum.smspec_node("WOPT:OP_1")
        self.assertTrue(node.is_total)
        self.assertFalse(node.is_rate)
        self.assertTrue(node.unit == "SM3")
        self.assertTrue(node.wgname == "OP_1")
        self.assertTrue(node.keyword == "WOPT")

        self.assertTrue(sum.unit("FOPR") == "SM3/DAY")

        node = sum.smspec_node("FOPTH")
        self.assertTrue(node.is_total)
        self.assertFalse(node.is_rate)
        self.assertIsNone(node.wgname)

        node = sum.smspec_node("FOPTH")
        self.assertIsNone(node.num)

        node = sum.smspec_node("BPR:1095")
        self.assertEquals(node.num, 1095)

    def test_stringlist_gc(self):
        sum = EclSum(self.case)
        wells = sum.wells()
        well1 = wells[0]
        del wells
        self.assertTrue(well1 == "OP_1")

    def test_stringlist_reference(self):
        sum = EclSum(self.case)
        wells = sum.wells()
        self.assertAlmostEqualList(wells, ["OP_1", "OP_2", "OP_3", "OP_4", "OP_5", "WI_1", "WI_2", "WI_3"])
        self.assertIsInstance(wells, StringList)

    def test_stringlist_setitem(self):
        sum = EclSum(self.case)
        wells = sum.wells()
        wells[0] = "Bjarne"
        well0 = wells[0]
        self.assertTrue(well0 == "Bjarne")
        self.assertTrue(wells[0] == "Bjarne")
        wells[0] = "XXX"
        self.assertTrue(well0 == "Bjarne")
        self.assertTrue(wells[0] == "XXX")

    def test_segment(self):
        sum = EclSum(self.createTestPath("Statoil/ECLIPSE/Oseberg/F8MLT/F8MLT-F4"))
        segment_vars = sum.keys("SOFR:F-8:*")
        self.assertIn("SOFR:F-8:1", segment_vars)
        for var in segment_vars:
            tmp = var.split(":")
            nr = int(tmp[2])
            self.assertTrue(nr >= 0)

    def test_return_types(self):
        self.assertIsInstance(self.ecl_sum.alloc_time_vector(True), TimeVector)
        key_index = self.ecl_sum.get_general_var_index("FOPT")
        self.assertIsInstance(self.ecl_sum.alloc_data_vector(key_index, True), DoubleVector)
コード例 #39
0
ファイル: test_ecl_sum.py プロジェクト: agchitu/ert
class EclSumTest(ExtendedTestCase):
    def setUp(self):
        self.test_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.SMSPEC")
        self.ecl_sum = EclSum(self.test_file)

    def test_time_range_year(self):
        real_range = self.ecl_sum.timeRange(interval="1y", extend_end = False)
        extended_range = self.ecl_sum.timeRange(interval="1y", extend_end = True)
        assert real_range[-1] < extended_range[-1]

    def test_time_range_day(self):
        real_range = self.ecl_sum.timeRange(interval = "1d", extend_end = False)
        extended_range = self.ecl_sum.timeRange(interval = "1d", extend_end = True)
        assert real_range[-1] == extended_range[-1]

    def test_time_range_month(self):
        real_range = self.ecl_sum.timeRange(interval = "1m", extend_end = False)
        extended_range = self.ecl_sum.timeRange(interval = "1m", extend_end = True)
        assert real_range[-1] < extended_range[-1]

    def test_dump_csv_line(self):
        ecl_sum_vector = EclSumKeyWordVector(self.ecl_sum)
        ecl_sum_vector.addKeywords("F*")

        with self.assertRaises(KeyError):
            ecl_sum_vector.addKeyword("MISSING")

        dtime = datetime.datetime( 2002 , 01 , 01 , 0 , 0 , 0 )
        with TestAreaContext("EclSum/csv_dump"):
            test_file_name = self.createTestPath("dump.csv")
            outputH = open(test_file_name , "w")
            self.ecl_sum.dumpCSVLine( dtime, ecl_sum_vector, outputH)
            assert os.path.isfile(test_file_name)


    def test_truncated_smspec(self):
        with TestAreaContext("EclSum/truncated_smspec") as ta:
            ta.copy_file( self.test_file )
            ta.copy_file( self.createTestPath( "Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY" ))
            
            file_size = os.path.getsize( "ECLIPSE.SMSPEC")
            with open("ECLIPSE.SMSPEC","r+") as f:
                f.truncate( file_size / 2 )
                
            with self.assertRaises(IOError):
                EclSum( "ECLIPSE" )


    def test_truncated_data(self):
        with TestAreaContext("EclSum/truncated_data") as ta:
            ta.copy_file( self.test_file )
            ta.copy_file( self.createTestPath( "Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY" ))

            
            file_size = os.path.getsize( "ECLIPSE.UNSMRY")
            with open("ECLIPSE.UNSMRY","r+") as f:
                f.truncate( file_size / 2 )
                
            with self.assertRaises(IOError):
                EclSum( "ECLIPSE" )


    def test_missing_smspec_keyword(self):
        with TestAreaContext("EclSum/truncated_data") as ta:
            ta.copy_file( self.test_file )
            ta.copy_file( self.createTestPath( "Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY" ))
        
            with openEclFile("ECLIPSE.SMSPEC") as f:
                kw_list = []
                for kw in f:
                    kw_list.append(EclKW.copy( kw ) )
            
            with openFortIO("ECLIPSE.SMSPEC" , mode = FortIO.WRITE_MODE) as f:
                for kw in kw_list:
                    if kw.getName() == "KEYWORDS":
                        continue
                    kw.fwrite(f)
            
            with self.assertRaises(IOError):
                EclSum( "ECLIPSE" )

    def test_missing_unsmry_keyword(self):
        with TestAreaContext("EclSum/truncated_data") as ta:
            ta.copy_file( self.test_file )
            ta.copy_file( self.createTestPath( "Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY" ))
        
            with openEclFile("ECLIPSE.UNSMRY") as f:
                kw_list = []
                for kw in f:
                    kw_list.append(EclKW.copy( kw ) )

            
            with openFortIO("ECLIPSE.UNSMRY" , mode = FortIO.WRITE_MODE) as f:
                c = 0
                for kw in kw_list:
                    if kw.getName() == "PARAMS":
                        if c % 5 == 0:
                            continue
                    c += 1
                    kw.fwrite(f)
            
            with self.assertRaises(IOError):
                EclSum( "ECLIPSE" )


    
                
    def test_labscale(self):
        case = self.createTestPath("Statoil/ECLIPSE/LabScale/HDMODEL")
        sum = EclSum( case )
        self.assertEqual( sum.getStartTime( ) , datetime.datetime(2013,1,1,0,0,0))
        self.assertEqual( sum.getEndTime( )   , datetime.datetime(2013,1,1,19,30,0))
        self.assertFloatEqual( sum.getSimulationLength() , 0.8125 )
コード例 #40
0
ファイル: test_sum_statoil.py プロジェクト: agchitu/ert
class SumTest(ExtendedTestCase):
    def setUp(self):
        self.case = self.createTestPath(case)
        self.ecl_sum = EclSum(self.case)

        self.assertIsInstance(self.ecl_sum, EclSum)


    def test_load(self):
        self.assertIsNotNone(self.ecl_sum, "Load failed")


    def test_invalid(self):
        with self.assertRaises(IOError):
            sum = EclSum("Does/not/exist")


    def test_KeyError(self):
        sum = self.ecl_sum
        with self.assertRaises(KeyError):
            v = sum["KeyMissing"]
        
        with self.assertRaises(KeyError):
            v = sum.get_interp("Missing" , days = 750)

        with self.assertRaises(KeyError):
            v = sum.get_interp_vector("Missing" , days_list = [750])



    def test_contains(self):
        self.assertTrue( "FOPT" in self.ecl_sum)
        self.assertFalse( "MISSING" in self.ecl_sum )


    def test_interp(self):
        sum = self.ecl_sum

        self.assertAlmostEqual(sum.get_interp("WWCT:OP_3", days=750), 0.11719122)
        self.assertAlmostEqual(sum.get_interp("WWCT:OP_3", date=datetime.date(2004, 1, 1)), 0.603358387947)

        v = sum.get_interp_vector("WOPT:OP_1", days_list=[100, 200, 400])
        self.assertAlmostEqualList([805817.11875, 1614955.34677419, 3289267.67857143 ], v)

        v = sum.get_interp_vector("WGPT:OP_2", date_list=[datetime.date(2002, 1, 1), datetime.date(2003, 1, 1), datetime.date(2004, 1, 1)])
        self.assertAlmostEqualList(v, [8.20773632e+08, 9.68444032e+08, 1.02515213e+09])

        self.assertEqual(sum.get_interp("FOPT" , days = 0) , 0)

        self.assertEqual(sum.get_interp("WOPR:OP_1" , days = 0) , 0)
        self.assertEqual(sum.get_interp("WOPR:OP_1" , date=datetime.date(2000,1,1)) , 0)

        self.assertEqual(sum.get_interp("WOPR:OP_1" , days = 31) , 7996)
        self.assertEqual(sum.get_interp("WOPR:OP_1" , date=datetime.date(2000,2,1)) , 7996)

        FPR = sum["FPR"]
        self.assertFloatEqual(sum.get_interp("FPR" , days = 0)  , FPR[0].value)
        self.assertFloatEqual(sum.get_interp("FPR" , days = 31) , FPR[1].value)

        with self.assertRaises(ValueError):
            sum.get_interp("WOPR:OP_1")

        with self.assertRaises(ValueError):
            sum.get_interp("WOPR:OP_1" , days=10 , date = datetime.date(2000,1,1))


    def test_LLINEAR(self):
        sum = EclSum( self.createTestPath("Statoil/ECLIPSE/Heidrun/LGRISSUE/EM-LTAA-ISEG_CARFIN_NWPROPS"))
        self.assertTrue( sum.has_key("LLINEARS") )

        

    def test_wells(self):
        wells = self.ecl_sum.wells()
        wells.sort()
        self.assertListEqual([well for well in wells], ["OP_1", "OP_2", "OP_3", "OP_4", "OP_5", "WI_1", "WI_2", "WI_3"])

        wells = self.ecl_sum.wells(pattern="*_3")
        wells.sort()
        self.assertListEqual([well for well in wells], ["OP_3", "WI_3"])

        groups = self.ecl_sum.groups()
        groups.sort()
        self.assertListEqual([group for group in groups], ['GMWIN', 'OP', 'WI'])


    def test_last( self ):
        last = self.ecl_sum.get_last("FOPT")
        self.assertFloatEqual(last.value, 38006336.0)
        self.assertFloatEqual(last.days, 1826.0)
        self.assertEqual(last.date, datetime.datetime(2004, 12, 31, 0, 0, 0))

        self.assertFloatEqual(self.ecl_sum.get_last_value("FGPT"), 6605249024.0)
        self.assertEqual( len(self.ecl_sum) , 63 )


    def test_dates( self ):
        sum = self.ecl_sum
        d = sum.dates

        self.assertEqual(d[0], datetime.datetime(2000, 1, 1, 0, 0, 0))
        self.assertEqual(d[62], datetime.datetime(2004, 12, 31, 0, 0, 0))
        self.assertEqual(len(d), 63)
        self.assertEqual(d[25], datetime.datetime(2001, 12, 1, 0, 0, 0))
        self.assertEqual(sum.iget_date(25), datetime.datetime(2001, 12, 1, 0, 0, 0))

        mpl_dates = sum.mpl_dates
        self.assertAlmostEqual(mpl_dates[25], 730820)

        days = sum.days
        self.assertAlmostEqual(days[50], 1461)

        self.assertEqual(sum.start_time, datetime.datetime(2000, 1, 1, 0, 0, 0))
        self.assertEqual(sum.end_time, datetime.datetime(2004, 12, 31, 0, 0, 0))
        self.assertTrue(sum.check_sim_time(datetime.datetime(2004, 12, 31, 0, 0, 0)))
        self.assertEqual(sum.end_date , datetime.date(2004, 12, 31))
        


    def test_dates2( self ):
        sum = EclSum(self.createTestPath("Statoil/ECLIPSE/FF12/FF12_2013B3_AMAP2"))
        self.assertEqual(sum.end_date , datetime.date(2045, 1, 1))





    def test_keys(self):
        sum = self.ecl_sum
        self.assertRaises(KeyError, sum.__getitem__, "BJARNE")

        v = sum["FOPT"]
        self.assertEqual(len(v), 63)


    def test_index(self):
        sum = self.ecl_sum
        index = sum.get_key_index("TCPUDAY")
        self.assertEqual(index, 10239)


    def test_report(self):
        sum = self.ecl_sum
        self.assertEqual(sum.get_report(date=datetime.date(2000, 10, 1)), 10)
        self.assertEqual(sum.get_report(date=datetime.date(2000, 10, 3)), -1)
        self.assertEqual(sum.get_report(date=datetime.date(1980, 10, 3)), -1)
        self.assertEqual(sum.get_report(date=datetime.date(2012, 10, 3)), -1)

        self.assertEqual(sum.get_report(days=91), 3)
        self.assertEqual(sum.get_report(days=92), -1)
        self.assertAlmostEqual(sum.get_interp("FOPT", days=91), sum.get_from_report("FOPT", 3))

        self.assertEqual(sum.first_report, 1)
        self.assertEqual(sum.last_report, 62)

        self.assertEqual(sum.get_report_time(10), datetime.date(2000, 10, 1))
        self.assertFloatEqual(sum.get_from_report("FOPT", 10), 6.67447e+06)


    @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow test skipped")
    def test_fwrite(self):
        # todo: What is tested here?
        # work_area = TestArea("python/sum-test/fwrite", True)
        with TestAreaContext("python/sum-test/fwrite") as work_area:
            self.ecl_sum.fwrite(ecl_case="CASE")
            self.assertTrue(True)


    def test_block(self):
        sum = self.ecl_sum
        index_ijk = sum.get_key_index("BPR:15,28,1")
        index_num = sum.get_key_index("BPR:1095")
        self.assertEqual(index_ijk, index_num)


    def test_restart(self):
        hist = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/history/T07-4A-W2011-18-P1"))
        base = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/prediction/BASECASE"))
        pred = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/prediction/BASECASE"), include_restart=False)

        self.assertIsNotNone(hist)
        self.assertIsNotNone(base)
        self.assertIsNotNone(pred)


    def test_case1(self ):
        self.assertTrue(self.ecl_sum.path == self.createTestPath(path))
        self.assertTrue(self.ecl_sum.base == base)
        self.assertTrue(self.ecl_sum.case == self.createTestPath(case))
        self.assertTrue(self.ecl_sum.abs_path == self.createTestPath(path))


    def test_case2( self ):
        cwd = os.getcwd()
        os.chdir(self.createTestPath(path))
        sum = EclSum(base)
        self.assertIsNone(sum.path)
        self.assertTrue(sum.base == base)
        self.assertTrue(sum.case == base)
        self.assertTrue(sum.abs_path == self.createTestPath(path))
        os.chdir(cwd)


    def test_var_properties( self ):
        sum = self.ecl_sum
        self.assertRaises(KeyError, sum.smspec_node, "BJARNE")

        node = sum.smspec_node("FOPT")
        self.assertTrue(node.is_total)
        self.assertFalse(node.is_historical)

        node = sum.smspec_node("FOPR")
        self.assertFalse(node.is_total)
        self.assertFalse(node.is_historical)
        self.assertTrue(node.keyword == "FOPR")

        node = sum.smspec_node("FOPRH")
        self.assertFalse(node.is_total)
        self.assertTrue(node.is_historical)
        self.assertTrue(node.is_rate)
        self.assertTrue(node.keyword == "FOPRH")

        node = sum.smspec_node("WOPR:OP_1")
        self.assertFalse(node.is_total)
        self.assertTrue(node.is_rate)
        self.assertTrue(node.keyword == "WOPR")

        node = sum.smspec_node("WOPT:OP_1")
        self.assertTrue(node.is_total)
        self.assertFalse(node.is_rate)
        self.assertTrue(node.unit == "SM3")
        self.assertTrue(node.wgname == "OP_1")
        self.assertTrue(node.keyword == "WOPT")

        self.assertTrue(sum.unit("FOPR") == "SM3/DAY")

        node = sum.smspec_node("FOPTH")
        self.assertTrue(node.is_total)
        self.assertFalse(node.is_rate)
        self.assertIsNone(node.wgname)

        node = sum.smspec_node("FOPTH")
        self.assertIsNone(node.num)

        node = sum.smspec_node("BPR:1095")
        self.assertEquals(node.num, 1095)

    def test_stringlist_gc(self):
        sum = EclSum(self.case)
        wells = sum.wells()
        well1 = wells[0]
        del wells
        self.assertTrue(well1 == "OP_1")


    def test_stringlist_reference(self):
        sum = EclSum(self.case)
        wells = sum.wells()
        self.assertListEqual([well for well in wells], ['OP_1', 'OP_2', 'OP_3', 'OP_4', 'OP_5', 'WI_1', 'WI_2', 'WI_3'])
        self.assertIsInstance(wells, StringList)


    def test_stringlist_setitem(self):
        sum = EclSum(self.case)
        wells = sum.wells()
        wells[0] = "Bjarne"
        well0 = wells[0]
        self.assertTrue(well0 == "Bjarne")
        self.assertTrue(wells[0] == "Bjarne")
        wells[0] = "XXX"
        self.assertTrue(well0 == "Bjarne")
        self.assertTrue(wells[0] == "XXX")


    def test_segment(self):
        sum = EclSum(self.createTestPath("Statoil/ECLIPSE/Oseberg/F8MLT/F8MLT-F4"))
        segment_vars = sum.keys("SOFR:F-8:*")
        self.assertIn("SOFR:F-8:1", segment_vars)
        for var in segment_vars:
            tmp = var.split(":")
            nr = int(tmp[2])
            self.assertTrue(nr >= 0)

    def test_return_types(self):
        self.assertIsInstance(self.ecl_sum.alloc_time_vector(True), TimeVector)
        key_index = self.ecl_sum.get_general_var_index("FOPT")
        self.assertIsInstance(self.ecl_sum.alloc_data_vector(key_index, True), DoubleVector)

    def test_timeRange(self):
        sum = EclSum(self.case)
        with self.assertRaises(TypeError):
            trange = sum.timeRange(interval = "1")
            trange = sum.timeRange(interval = "1X")
            trange = sum.timeRange(interval = "YY")
            trange = sum.timeRange(interval = "MY")

        with self.assertRaises(ValueError):
            trange = sum.timeRange( start = datetime.datetime(2000,1,1) , end = datetime.datetime(1999,1,1) )

        sim_start = datetime.datetime(2000, 1, 1, 0, 0, 0)
        sim_end = datetime.datetime(2004, 12, 31, 0, 0, 0)
        trange = sum.timeRange( interval = "1Y")
        self.assertTrue( trange[0] == datetime.date( 2000 , 1 , 1 ))
        self.assertTrue( trange[1] == datetime.date( 2001 , 1 , 1 ))
        self.assertTrue( trange[2] == datetime.date( 2002 , 1 , 1 ))
        self.assertTrue( trange[3] == datetime.date( 2003 , 1 , 1 ))
        self.assertTrue( trange[4] == datetime.date( 2004 , 1 , 1 ))
        self.assertTrue( trange[5] == datetime.date( 2005 , 1 , 1 ))

        trange = sum.timeRange( interval = "1M")
        self.assertTrue( trange[0] == datetime.date( 2000 , 1 , 1 ))
        self.assertTrue( trange[-1] == datetime.date( 2005 , 1 , 1 ))

        trange = sum.timeRange( start = datetime.date( 2002 , 1 , 15), interval = "1M")
        self.assertTrue( trange[0] == datetime.date( 2002 , 1 , 1 ))
        self.assertTrue( trange[-1] == datetime.date( 2005 , 1 , 1 ))

        trange = sum.timeRange( start = datetime.date( 2002 , 1 , 15) , end = datetime.date( 2003 , 1 , 15), interval = "1M")
        self.assertTrue( trange[0] == datetime.date( 2002 , 1 , 1 ))
        self.assertTrue( trange[-1] == datetime.date( 2003 , 2 , 1 ))

        trange = sum.timeRange( start = datetime.date( 2002 , 1 , 15) , end = datetime.datetime( 2003 , 1 , 15,0,0,0), interval = "1M")
        self.assertTrue( trange[0] == datetime.date( 2002 , 1 , 1 ))
        self.assertTrue( trange[-1] == datetime.date( 2003 , 2 , 1 ))



    # Loading this dataset is a test of loading a case where one report step is missing.
    def test_Heidrun(self):
        sum = EclSum( self.createTestPath("Statoil/ECLIPSE/Heidrun/Summary/FF12_2013B3_CLEAN_RS"))
        self.assertEqual( 452 , len(sum))
        self.assertFloatEqual( 1.8533144e+8 , sum.get_last_value("FOPT"))

        trange = sum.timeRange( start = datetime.date( 2015 , 1 , 1), interval = "1M")
        self.assertTrue( trange[0] == datetime.date( 2016 , 2 , 1 ))
        for t in trange:
            sum.get_interp( "FOPT" , date = t )
        


    def test_regularProduction(self):
        sum = EclSum(self.case)
        with self.assertRaises(TypeError):
            trange = TimeVector.createRegular( sum.start_time , sum.end_time , "1M" )
            prod = sum.blockedProduction("FOPR" , trange)
            
        with self.assertRaises(KeyError):
            trange = TimeVector.createRegular( sum.start_time , sum.end_time , "1M" )
            prod = sum.blockedProduction("NoNotThis" , trange)

        trange = sum.timeRange(interval = "2Y")
        self.assertTrue( trange[0]  == datetime.date( 2000 , 1 , 1 ))
        self.assertTrue( trange[-1] == datetime.date( 2006 , 1 , 1 ))

        trange = sum.timeRange(interval = "5Y")
        self.assertTrue( trange[0]  == datetime.date( 2000 , 1 , 1 ))
        self.assertTrue( trange[-1] == datetime.date( 2005 , 1 , 1 ))
        
        trange = sum.timeRange(interval = "6M")
        wprod1 = sum.blockedProduction("WOPT:OP_1" , trange)
        wprod2 = sum.blockedProduction("WOPT:OP_2" , trange)
        wprod3 = sum.blockedProduction("WOPT:OP_3" , trange)
        wprod4 = sum.blockedProduction("WOPT:OP_4" , trange)
        wprod5 = sum.blockedProduction("WOPT:OP_5" , trange)
    
        fprod = sum.blockedProduction("FOPT" , trange)
        gprod = sum.blockedProduction("GOPT:OP" , trange)
        wprod = wprod1 + wprod2 + wprod3 + wprod4 + wprod5
        for (w,f,g) in zip(wprod, fprod,gprod):
            self.assertFloatEqual( w , f )
            self.assertFloatEqual( w , g )



    def test_writer(self):
        writer = EclSum.writer("CASE" , datetime.date( 2000 , 1 , 1) , 10 , 10 , 5)
        self.assertIsInstance(self.ecl_sum, EclSum)

        
        writer.addVariable( "FOPT" )
        self.assertTrue( writer.has_key( "FOPT" ))
        
        writer.addTStep( 1 , 100 )
        
    def test_aquifer(self):
        case = EclSum( self.createTestPath( "Statoil/ECLIPSE/Aquifer/06_PRESSURE_R009-0"))
        self.assertTrue( "AAQR:2" in case )
コード例 #41
0
ファイル: snake_oil_simulator.py プロジェクト: stefoss23/ert
def runSimulator(simulator, history_simulator, time_step_count):
    """ @rtype: EclSum """
    ecl_sum = EclSum.writer("SNAKE_OIL_FIELD", datetime(2010, 1, 1), 10, 10,
                            10)

    ecl_sum.addVariable('FOPT', unit="SM3")
    ecl_sum.addVariable('FOPR', unit="SM3/DAY")
    ecl_sum.addVariable('FGPT', unit="SM3")
    ecl_sum.addVariable('FGPR', unit="SM3/DAY")
    ecl_sum.addVariable('FWPT', unit="SM3")
    ecl_sum.addVariable('FWPR', unit="SM3/DAY")
    ecl_sum.addVariable('FGOR', unit="SM3/SM3")
    ecl_sum.addVariable('FWCT', unit="SM3/SM3")

    ecl_sum.addVariable('FOIP', unit="SM3")
    ecl_sum.addVariable('FGIP', unit="SM3")
    ecl_sum.addVariable('FWIP', unit="SM3")

    ecl_sum.addVariable('FOPTH', unit="SM3")
    ecl_sum.addVariable('FOPRH', unit="SM3/DAY")
    ecl_sum.addVariable('FGPTH', unit="SM3")
    ecl_sum.addVariable('FGPRH', unit="SM3/DAY")
    ecl_sum.addVariable('FWPTH', unit="SM3")
    ecl_sum.addVariable('FWPRH', unit="SM3/DAY")
    ecl_sum.addVariable('FGORH', unit="SM3/SM3")
    ecl_sum.addVariable('FWCTH', unit="SM3/SM3")

    ecl_sum.addVariable('FOIPH', unit="SM3")
    ecl_sum.addVariable('FGIPH', unit="SM3")
    ecl_sum.addVariable('FWIPH', unit="SM3")

    ecl_sum.addVariable('WOPR', wgname='OP1', unit="SM3/DAY")
    ecl_sum.addVariable('WOPR', wgname='OP2', unit="SM3/DAY")
    ecl_sum.addVariable('WWPR', wgname='OP1', unit="SM3/DAY")
    ecl_sum.addVariable('WWPR', wgname='OP2', unit="SM3/DAY")
    ecl_sum.addVariable('WGPR', wgname='OP1', unit="SM3/DAY")
    ecl_sum.addVariable('WGPR', wgname='OP2', unit="SM3/DAY")
    ecl_sum.addVariable('WGOR', wgname='OP1', unit="SM3/SM3")
    ecl_sum.addVariable('WGOR', wgname='OP2', unit="SM3/SM3")
    ecl_sum.addVariable('WWCT', wgname='OP1', unit="SM3/SM3")
    ecl_sum.addVariable('WWCT', wgname='OP2', unit="SM3/SM3")

    ecl_sum.addVariable('WOPRH', wgname='OP1', unit="SM3/DAY")
    ecl_sum.addVariable('WOPRH', wgname='OP2', unit="SM3/DAY")
    ecl_sum.addVariable('WWPRH', wgname='OP1', unit="SM3/DAY")
    ecl_sum.addVariable('WWPRH', wgname='OP2', unit="SM3/DAY")
    ecl_sum.addVariable('WGPRH', wgname='OP1', unit="SM3/DAY")
    ecl_sum.addVariable('WGPRH', wgname='OP2', unit="SM3/DAY")
    ecl_sum.addVariable('WGORH', wgname='OP1', unit="SM3/SM3")
    ecl_sum.addVariable('WGORH', wgname='OP2', unit="SM3/SM3")
    ecl_sum.addVariable('WWCTH', wgname='OP1', unit="SM3/SM3")
    ecl_sum.addVariable('WWCTH', wgname='OP2', unit="SM3/SM3")

    ecl_sum.addVariable('BPR', num=globalIndex(5, 5, 5), unit="BARSA")
    ecl_sum.addVariable('BPR', num=globalIndex(1, 3, 8), unit="BARSA")

    time_map = []
    mini_step_count = 10
    total_step_count = time_step_count * mini_step_count

    for report_step in range(time_step_count):
        for mini_step in range(mini_step_count):
            t_step = ecl_sum.addTStep(report_step + 1,
                                      sim_days=report_step * mini_step_count +
                                      mini_step)

            time_map.append(
                t_step.getSimTime().datetime().strftime("%d/%m/%Y"))

            simulator.step(scale=1.0 / total_step_count)
            history_simulator.step(scale=1.0 / total_step_count)

            t_step['FOPR'] = simulator.fopr()
            t_step['FOPT'] = simulator.fopt()
            t_step['FGPR'] = simulator.fgpr()
            t_step['FGPT'] = simulator.fgpt()
            t_step['FWPR'] = simulator.fwpr()
            t_step['FWPT'] = simulator.fwpt()
            t_step['FGOR'] = simulator.fgor()
            t_step['FWCT'] = simulator.fwct()

            t_step['FOIP'] = simulator.foip()
            t_step['FGIP'] = simulator.fgip()
            t_step['FWIP'] = simulator.fwip()

            t_step['WOPR:OP1'] = simulator.opr('OP1')
            t_step['WOPR:OP2'] = simulator.opr('OP2')

            t_step['WGPR:OP1'] = simulator.gpr('OP1')
            t_step['WGPR:OP2'] = simulator.gpr('OP2')

            t_step['WWPR:OP1'] = simulator.wpr('OP1')
            t_step['WWPR:OP2'] = simulator.wpr('OP2')

            t_step['WGOR:OP1'] = simulator.gor('OP1')
            t_step['WGOR:OP2'] = simulator.gor('OP2')

            t_step['WWCT:OP1'] = simulator.wct('OP1')
            t_step['WWCT:OP2'] = simulator.wct('OP2')

            t_step['BPR:5,5,5'] = simulator.bpr('5,5,5')
            t_step['BPR:1,3,8'] = simulator.bpr('1,3,8')

            t_step['FOPRH'] = history_simulator.fopr()
            t_step['FOPTH'] = history_simulator.fopt()
            t_step['FGPRH'] = history_simulator.fgpr()
            t_step['FGPTH'] = history_simulator.fgpt()
            t_step['FWPRH'] = history_simulator.fwpr()
            t_step['FWPTH'] = history_simulator.fwpt()
            t_step['FGORH'] = history_simulator.fgor()
            t_step['FWCTH'] = history_simulator.fwct()
            t_step['FOIPH'] = history_simulator.foip()
            t_step['FGIPH'] = history_simulator.fgip()
            t_step['FWIPH'] = history_simulator.fwip()

            t_step['WOPRH:OP1'] = history_simulator.opr('OP1')
            t_step['WOPRH:OP2'] = history_simulator.opr('OP2')

            t_step['WGPRH:OP1'] = history_simulator.gpr('OP1')
            t_step['WGPRH:OP2'] = history_simulator.gpr('OP2')

            t_step['WWPRH:OP1'] = history_simulator.wpr('OP1')
            t_step['WWPRH:OP2'] = history_simulator.wpr('OP2')

            t_step['WGORH:OP1'] = history_simulator.gor('OP1')
            t_step['WGORH:OP2'] = history_simulator.gor('OP2')

            t_step['WWCTH:OP1'] = history_simulator.wct('OP1')
            t_step['WWCTH:OP2'] = history_simulator.wct('OP2')

    return ecl_sum, time_map
コード例 #42
0
class SumTest(ExtendedTestCase):
    def setUp(self):
        self.case = self.createTestPath(case)
        self.ecl_sum = EclSum(self.case)

        self.assertIsInstance(self.ecl_sum, EclSum)


    def test_load(self):
        self.assertIsNotNone(self.ecl_sum, "Load failed")


    def test_invalid(self):
        with self.assertRaises(IOError):
            sum = EclSum("Does/not/exist")


    def test_KeyError(self):
        sum = self.ecl_sum
        with self.assertRaises(KeyError):
            v = sum["KeyMissing"]
        
        with self.assertRaises(KeyError):
            v = sum.get_interp("Missing" , days = 750)

        with self.assertRaises(KeyError):
            v = sum.get_interp_vector("Missing" , days_list = [750])



    def test_contains(self):
        self.assertTrue( "FOPT" in self.ecl_sum)
        self.assertFalse( "MISSING" in self.ecl_sum )


    def test_interp(self):
        sum = self.ecl_sum

        self.assertAlmostEqual(sum.get_interp("WWCT:OP_3", days=750), 0.11719122)
        self.assertAlmostEqual(sum.get_interp("WWCT:OP_3", date=datetime.date(2004, 1, 1)), 0.603358387947)

        v = sum.get_interp_vector("WOPT:OP_1", days_list=[100, 200, 400])
        self.assertAlmostEqualList([805817.11875, 1614955.34677419, 3289267.67857143 ], v)

        v = sum.get_interp_vector("WGPT:OP_2", date_list=[datetime.date(2002, 1, 1), datetime.date(2003, 1, 1), datetime.date(2004, 1, 1)])
        self.assertAlmostEqualList(v, [8.20773632e+08, 9.68444032e+08, 1.02515213e+09])

        self.assertEqual(sum.get_interp("FOPT" , days = 0) , 0)

        self.assertEqual(sum.get_interp("WOPR:OP_1" , days = 0) , 0)
        self.assertEqual(sum.get_interp("WOPR:OP_1" , date=datetime.date(2000,1,1)) , 0)

        self.assertEqual(sum.get_interp("WOPR:OP_1" , days = 31) , 7996)
        self.assertEqual(sum.get_interp("WOPR:OP_1" , date=datetime.date(2000,2,1)) , 7996)

        FPR = sum["FPR"]
        self.assertFloatEqual(sum.get_interp("FPR" , days = 0)  , FPR[0].value)
        self.assertFloatEqual(sum.get_interp("FPR" , days = 31) , FPR[1].value)

        with self.assertRaises(ValueError):
            sum.get_interp("WOPR:OP_1")

        with self.assertRaises(ValueError):
            sum.get_interp("WOPR:OP_1" , days=10 , date = datetime.date(2000,1,1))


    def test_LLINEAR(self):
        sum = EclSum( self.createTestPath("Statoil/ECLIPSE/Heidrun/LGRISSUE/EM-LTAA-ISEG_CARFIN_NWPROPS"))
        self.assertTrue( sum.has_key("LLINEARS") )

        

    def test_wells(self):
        wells = self.ecl_sum.wells()
        wells.sort()
        self.assertListEqual([well for well in wells], ["OP_1", "OP_2", "OP_3", "OP_4", "OP_5", "WI_1", "WI_2", "WI_3"])

        wells = self.ecl_sum.wells(pattern="*_3")
        wells.sort()
        self.assertListEqual([well for well in wells], ["OP_3", "WI_3"])

        groups = self.ecl_sum.groups()
        groups.sort()
        self.assertListEqual([group for group in groups], ['GMWIN', 'OP', 'WI'])


    def test_last( self ):
        last = self.ecl_sum.get_last("FOPT")
        self.assertFloatEqual(last.value, 38006336.0)
        self.assertFloatEqual(last.days, 1826.0)
        self.assertEqual(last.date, datetime.datetime(2004, 12, 31, 0, 0, 0))

        self.assertFloatEqual(self.ecl_sum.get_last_value("FGPT"), 6605249024.0)
        self.assertEqual( len(self.ecl_sum) , 63 )


    def test_dates( self ):
        sum = self.ecl_sum
        d = sum.dates

        self.assertEqual(d[0], datetime.datetime(2000, 1, 1, 0, 0, 0))
        self.assertEqual(d[62], datetime.datetime(2004, 12, 31, 0, 0, 0))
        self.assertEqual(len(d), 63)
        self.assertEqual(d[25], datetime.datetime(2001, 12, 1, 0, 0, 0))
        self.assertEqual(sum.iget_date(25), datetime.datetime(2001, 12, 1, 0, 0, 0))

        mpl_dates = sum.mpl_dates
        self.assertAlmostEqual(mpl_dates[25], 730820)

        days = sum.days
        self.assertAlmostEqual(days[50], 1461)

        self.assertEqual(sum.start_time, datetime.datetime(2000, 1, 1, 0, 0, 0))
        self.assertEqual(sum.end_time, datetime.datetime(2004, 12, 31, 0, 0, 0))
        self.assertTrue(sum.check_sim_time(datetime.datetime(2004, 12, 31, 0, 0, 0)))
        self.assertEqual(sum.end_date , datetime.date(2004, 12, 31))
        


    def test_dates2( self ):
        sum = EclSum(self.createTestPath("Statoil/ECLIPSE/FF12/FF12_2013B3_AMAP2"))
        self.assertEqual(sum.end_date , datetime.date(2045, 1, 1))





    def test_keys(self):
        sum = self.ecl_sum
        self.assertRaises(KeyError, sum.__getitem__, "BJARNE")

        v = sum["FOPT"]
        self.assertEqual(len(v), 63)


    def test_index(self):
        sum = self.ecl_sum
        index = sum.get_key_index("TCPUDAY")
        self.assertEqual(index, 10239)


    def test_report(self):
        sum = self.ecl_sum
        self.assertEqual(sum.get_report(date=datetime.date(2000, 10, 1)), 10)
        self.assertEqual(sum.get_report(date=datetime.date(2000, 10, 3)), -1)
        self.assertEqual(sum.get_report(date=datetime.date(1980, 10, 3)), -1)
        self.assertEqual(sum.get_report(date=datetime.date(2012, 10, 3)), -1)

        self.assertEqual(sum.get_report(days=91), 3)
        self.assertEqual(sum.get_report(days=92), -1)
        self.assertAlmostEqual(sum.get_interp("FOPT", days=91), sum.get_from_report("FOPT", 3))

        self.assertEqual(sum.first_report, 1)
        self.assertEqual(sum.last_report, 62)

        self.assertEqual(sum.get_report_time(10), datetime.date(2000, 10, 1))
        self.assertFloatEqual(sum.get_from_report("FOPT", 10), 6.67447e+06)


    @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow test skipped")
    def test_fwrite(self):
        # todo: What is tested here?
        # work_area = TestArea("python/sum-test/fwrite", True)
        with TestAreaContext("python/sum-test/fwrite") as work_area:
            self.ecl_sum.fwrite(ecl_case="CASE")
            self.assertTrue(True)


    def test_block(self):
        sum = self.ecl_sum
        index_ijk = sum.get_key_index("BPR:15,28,1")
        index_num = sum.get_key_index("BPR:1095")
        self.assertEqual(index_ijk, index_num)


    def test_restart(self):
        hist = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/history/T07-4A-W2011-18-P1"))
        base = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/prediction/BASECASE"))
        pred = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/prediction/BASECASE"), include_restart=False)

        self.assertIsNotNone(hist)
        self.assertIsNotNone(base)
        self.assertIsNotNone(pred)


    def test_case1(self ):
        self.assertTrue(self.ecl_sum.path == self.createTestPath(path))
        self.assertTrue(self.ecl_sum.base == base)
        self.assertTrue(self.ecl_sum.case == self.createTestPath(case))
        self.assertTrue(self.ecl_sum.abs_path == self.createTestPath(path))


    def test_case2( self ):
        cwd = os.getcwd()
        os.chdir(self.createTestPath(path))
        sum = EclSum(base)
        self.assertIsNone(sum.path)
        self.assertTrue(sum.base == base)
        self.assertTrue(sum.case == base)
        self.assertTrue(sum.abs_path == self.createTestPath(path))
        os.chdir(cwd)


    def test_var_properties( self ):
        sum = self.ecl_sum
        self.assertRaises(KeyError, sum.smspec_node, "BJARNE")

        node = sum.smspec_node("FOPT")
        self.assertTrue(node.isTotal())
        self.assertFalse(node.isHistorical())

        node = sum.smspec_node("FOPR")
        self.assertFalse(node.isTotal())
        self.assertFalse(node.isHistorical())
        self.assertTrue(node.keyword == "FOPR")

        node = sum.smspec_node("FOPRH")
        self.assertFalse(node.isTotal())
        self.assertTrue(node.isHistorical())
        self.assertTrue(node.isRate())
        self.assertTrue(node.keyword == "FOPRH")

        node = sum.smspec_node("WOPR:OP_1")
        self.assertFalse(node.isTotal())
        self.assertTrue(node.isRate())
        self.assertTrue(node.keyword == "WOPR")

        node = sum.smspec_node("WOPT:OP_1")
        self.assertTrue(node.isTotal())
        self.assertFalse(node.isRate())
        self.assertTrue(node.unit == "SM3")
        self.assertTrue(node.wgname == "OP_1")
        self.assertTrue(node.keyword == "WOPT")

        self.assertTrue(sum.unit("FOPR") == "SM3/DAY")

        node = sum.smspec_node("FOPTH")
        self.assertTrue(node.isTotal())
        self.assertFalse(node.isRate())
        self.assertIsNone(node.wgname)

        node = sum.smspec_node("FOPTH")
        self.assertIsNone(node.num)

        node = sum.smspec_node("BPR:1095")
        self.assertEquals(node.num, 1095)

    def test_stringlist_gc(self):
        sum = EclSum(self.case)
        wells = sum.wells()
        well1 = wells[0]
        del wells
        self.assertTrue(well1 == "OP_1")


    def test_stringlist_reference(self):
        sum = EclSum(self.case)
        wells = sum.wells()
        self.assertListEqual([well for well in wells], ['OP_1', 'OP_2', 'OP_3', 'OP_4', 'OP_5', 'WI_1', 'WI_2', 'WI_3'])
        self.assertIsInstance(wells, StringList)


    def test_stringlist_setitem(self):
        sum = EclSum(self.case)
        wells = sum.wells()
        wells[0] = "Bjarne"
        well0 = wells[0]
        self.assertTrue(well0 == "Bjarne")
        self.assertTrue(wells[0] == "Bjarne")
        wells[0] = "XXX"
        self.assertTrue(well0 == "Bjarne")
        self.assertTrue(wells[0] == "XXX")


    def test_segment(self):
        sum = EclSum(self.createTestPath("Statoil/ECLIPSE/Oseberg/F8MLT/F8MLT-F4"))
        segment_vars = sum.keys("SOFR:F-8:*")
        self.assertIn("SOFR:F-8:1", segment_vars)
        for var in segment_vars:
            tmp = var.split(":")
            nr = int(tmp[2])
            self.assertTrue(nr >= 0)

    def test_return_types(self):
        self.assertIsInstance(self.ecl_sum.alloc_time_vector(True), TimeVector)
        key_index = self.ecl_sum.get_general_var_index("FOPT")
        self.assertIsInstance(self.ecl_sum.alloc_data_vector(key_index, True), DoubleVector)

    def test_timeRange(self):
        sum = EclSum(self.case)
        with self.assertRaises(TypeError):
            trange = sum.timeRange(interval = "1")
            trange = sum.timeRange(interval = "1X")
            trange = sum.timeRange(interval = "YY")
            trange = sum.timeRange(interval = "MY")

        with self.assertRaises(ValueError):
            trange = sum.timeRange( start = datetime.datetime(2000,1,1) , end = datetime.datetime(1999,1,1) )

        sim_start = datetime.datetime(2000, 1, 1, 0, 0, 0)
        sim_end = datetime.datetime(2004, 12, 31, 0, 0, 0)
        trange = sum.timeRange( interval = "1Y")
        self.assertTrue( trange[0] == datetime.date( 2000 , 1 , 1 ))
        self.assertTrue( trange[1] == datetime.date( 2001 , 1 , 1 ))
        self.assertTrue( trange[2] == datetime.date( 2002 , 1 , 1 ))
        self.assertTrue( trange[3] == datetime.date( 2003 , 1 , 1 ))
        self.assertTrue( trange[4] == datetime.date( 2004 , 1 , 1 ))
        self.assertTrue( trange[5] == datetime.date( 2005 , 1 , 1 ))

        trange = sum.timeRange( interval = "1M")
        self.assertTrue( trange[0] == datetime.date( 2000 , 1 , 1 ))
        self.assertTrue( trange[-1] == datetime.date( 2005 , 1 , 1 ))

        trange = sum.timeRange( start = datetime.date( 2002 , 1 , 15), interval = "1M")
        self.assertTrue( trange[0] == datetime.date( 2002 , 1 , 1 ))
        self.assertTrue( trange[-1] == datetime.date( 2005 , 1 , 1 ))

        trange = sum.timeRange( start = datetime.date( 2002 , 1 , 15) , end = datetime.date( 2003 , 1 , 15), interval = "1M")
        self.assertTrue( trange[0] == datetime.date( 2002 , 1 , 1 ))
        self.assertTrue( trange[-1] == datetime.date( 2003 , 2 , 1 ))

        trange = sum.timeRange( start = datetime.date( 2002 , 1 , 15) , end = datetime.datetime( 2003 , 1 , 15,0,0,0), interval = "1M")
        self.assertTrue( trange[0] == datetime.date( 2002 , 1 , 1 ))
        self.assertTrue( trange[-1] == datetime.date( 2003 , 2 , 1 ))



    # Loading this dataset is a test of loading a case where one report step is missing.
    def test_Heidrun(self):
        sum = EclSum( self.createTestPath("Statoil/ECLIPSE/Heidrun/Summary/FF12_2013B3_CLEAN_RS"))
        self.assertEqual( 452 , len(sum))
        self.assertFloatEqual( 1.8533144e+8 , sum.get_last_value("FOPT"))

        trange = sum.timeRange( start = datetime.date( 2015 , 1 , 1), interval = "1M")
        self.assertTrue( trange[0] == datetime.date( 2016 , 2 , 1 ))
        for t in trange:
            sum.get_interp( "FOPT" , date = t )
        


    def test_regularProduction(self):
        sum = EclSum(self.case)
        with self.assertRaises(TypeError):
            trange = TimeVector.createRegular( sum.start_time , sum.end_time , "1M" )
            prod = sum.blockedProduction("FOPR" , trange)
            
        with self.assertRaises(KeyError):
            trange = TimeVector.createRegular( sum.start_time , sum.end_time , "1M" )
            prod = sum.blockedProduction("NoNotThis" , trange)

        trange = sum.timeRange(interval = "2Y")
        self.assertTrue( trange[0]  == datetime.date( 2000 , 1 , 1 ))
        self.assertTrue( trange[-1] == datetime.date( 2006 , 1 , 1 ))

        trange = sum.timeRange(interval = "5Y")
        self.assertTrue( trange[0]  == datetime.date( 2000 , 1 , 1 ))
        self.assertTrue( trange[-1] == datetime.date( 2005 , 1 , 1 ))
        
        trange = sum.timeRange(interval = "6M")
        wprod1 = sum.blockedProduction("WOPT:OP_1" , trange)
        wprod2 = sum.blockedProduction("WOPT:OP_2" , trange)
        wprod3 = sum.blockedProduction("WOPT:OP_3" , trange)
        wprod4 = sum.blockedProduction("WOPT:OP_4" , trange)
        wprod5 = sum.blockedProduction("WOPT:OP_5" , trange)
    
        fprod = sum.blockedProduction("FOPT" , trange)
        gprod = sum.blockedProduction("GOPT:OP" , trange)
        wprod = wprod1 + wprod2 + wprod3 + wprod4 + wprod5
        for (w,f,g) in zip(wprod, fprod,gprod):
            self.assertFloatEqual( w , f )
            self.assertFloatEqual( w , g )



    def test_writer(self):
        writer = EclSum.writer("CASE" , datetime.date( 2000 , 1 , 1) , 10 , 10 , 5)
        self.assertIsInstance(self.ecl_sum, EclSum)

        
        writer.addVariable( "FOPT" )
        self.assertTrue( writer.has_key( "FOPT" ))
        
        writer.addTStep( 1 , 100 )

        
    def test_aquifer(self):
        case = EclSum( self.createTestPath( "Statoil/ECLIPSE/Aquifer/06_PRESSURE_R009-0"))
        self.assertTrue( "AAQR:2" in case )
コード例 #43
0
 def test_LLINEAR(self):
     sum = EclSum( self.createTestPath("Statoil/ECLIPSE/Heidrun/LGRISSUE/EM-LTAA-ISEG_CARFIN_NWPROPS"))
     self.assertTrue( sum.has_key("LLINEARS") )
コード例 #44
0
 def test_Heidrun(self):
     sum = EclSum(
         self.createTestPath(
             "Statoil/ECLIPSE/Heidrun/Summary/FF12_2013B3_CLEAN_RS"))
     self.assertEqual(452, len(sum))
     self.assertFloatEqual(1.8533144e+8, sum.get_last_value("FOPT"))
コード例 #45
0
ファイル: ecl_cmp.py プロジェクト: Ensembles/ert
 def loadSummary(self):
     self.summary = EclSum( self.case )
コード例 #46
0
ファイル: test_sum.py プロジェクト: JacobStoren/ert
 def test_stringlist_reference(self):
     sum = EclSum(self.case)
     wells = sum.wells()
     self.assertAlmostEqualList(wells, ["OP_1", "OP_2", "OP_3", "OP_4", "OP_5", "WI_1", "WI_2", "WI_3"])
     self.assertIsInstance(wells, StringList)
コード例 #47
0
#!/usr/bin/env python
from ert.ecl import EclSum

def writeDiff(filename, vector1, vector2):
    with open(filename, "w") as f:
        for index in range(len(vector1)):
            node1 = vector1[index]
            node2 = vector2[index]

            diff = node1.value - node2.value
            f.write("%f\n" % diff)


if __name__ == '__main__':
    ecl_sum = EclSum("SNAKE_OIL_FIELD")

    report_step = 199
    writeDiff("snake_oil_opr_diff_%d.txt" % report_step, ecl_sum["WOPR:OP1"], ecl_sum["WOPR:OP2"])
    writeDiff("snake_oil_wpr_diff_%d.txt" % report_step, ecl_sum["WWPR:OP1"], ecl_sum["WWPR:OP2"])
    writeDiff("snake_oil_gpr_diff_%d.txt" % report_step, ecl_sum["WGPR:OP1"], ecl_sum["WGPR:OP2"])




コード例 #48
0
    def getReportStepTimeFromRefcase(self, refcase, report_step):
        if not report_step in self.report_times:
            self.report_times[report_step] = EclSum.cNamespace().get_report_time(refcase, report_step).ctime()

        return self.report_times[report_step]
コード例 #49
0
class EclSumTest(ExtendedTestCase):
    def setUp(self):
        self.test_file = self.createTestPath(
            "Statoil/ECLIPSE/Gurbat/ECLIPSE.SMSPEC")
        self.ecl_sum = EclSum(self.test_file)

    def test_time_range_year(self):
        real_range = self.ecl_sum.timeRange(interval="1y", extend_end=False)
        extended_range = self.ecl_sum.timeRange(interval="1y", extend_end=True)
        assert real_range[-1] < extended_range[-1]

    def test_time_range_day(self):
        real_range = self.ecl_sum.timeRange(interval="1d", extend_end=False)
        extended_range = self.ecl_sum.timeRange(interval="1d", extend_end=True)
        assert real_range[-1] == extended_range[-1]

    def test_time_range_month(self):
        real_range = self.ecl_sum.timeRange(interval="1m", extend_end=False)
        extended_range = self.ecl_sum.timeRange(interval="1m", extend_end=True)
        assert real_range[-1] < extended_range[-1]

    def test_dump_csv_line(self):
        ecl_sum_vector = EclSumKeyWordVector(self.ecl_sum)
        ecl_sum_vector.addKeywords("F*")

        with self.assertRaises(KeyError):
            ecl_sum_vector.addKeyword("MISSING")

        dtime = datetime.datetime(2002, 01, 01, 0, 0, 0)
        with TestAreaContext("EclSum/csv_dump"):
            test_file_name = self.createTestPath("dump.csv")
            outputH = open(test_file_name, "w")
            self.ecl_sum.dumpCSVLine(dtime, ecl_sum_vector, outputH)
            assert os.path.isfile(test_file_name)

    def test_truncated_smspec(self):
        with TestAreaContext("EclSum/truncated_smspec") as ta:
            ta.copy_file(self.test_file)
            ta.copy_file(
                self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY"))

            file_size = os.path.getsize("ECLIPSE.SMSPEC")
            with open("ECLIPSE.SMSPEC", "r+") as f:
                f.truncate(file_size / 2)

            with self.assertRaises(IOError):
                EclSum("ECLIPSE")

    def test_truncated_data(self):
        with TestAreaContext("EclSum/truncated_data") as ta:
            ta.copy_file(self.test_file)
            ta.copy_file(
                self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY"))

            file_size = os.path.getsize("ECLIPSE.UNSMRY")
            with open("ECLIPSE.UNSMRY", "r+") as f:
                f.truncate(file_size / 2)

            with self.assertRaises(IOError):
                EclSum("ECLIPSE")

    def test_missing_smspec_keyword(self):
        with TestAreaContext("EclSum/truncated_data") as ta:
            ta.copy_file(self.test_file)
            ta.copy_file(
                self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY"))

            with openEclFile("ECLIPSE.SMSPEC") as f:
                kw_list = []
                for kw in f:
                    kw_list.append(EclKW.copy(kw))

            with openFortIO("ECLIPSE.SMSPEC", mode=FortIO.WRITE_MODE) as f:
                for kw in kw_list:
                    if kw.getName() == "KEYWORDS":
                        continue
                    kw.fwrite(f)

            with self.assertRaises(IOError):
                EclSum("ECLIPSE")

    def test_missing_unsmry_keyword(self):
        with TestAreaContext("EclSum/truncated_data") as ta:
            ta.copy_file(self.test_file)
            ta.copy_file(
                self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY"))

            with openEclFile("ECLIPSE.UNSMRY") as f:
                kw_list = []
                for kw in f:
                    kw_list.append(EclKW.copy(kw))

            with openFortIO("ECLIPSE.UNSMRY", mode=FortIO.WRITE_MODE) as f:
                c = 0
                for kw in kw_list:
                    if kw.getName() == "PARAMS":
                        if c % 5 == 0:
                            continue
                    c += 1
                    kw.fwrite(f)

            with self.assertRaises(IOError):
                EclSum("ECLIPSE")

    def test_labscale(self):
        case = self.createTestPath("Statoil/ECLIPSE/LabScale/HDMODEL")
        sum = EclSum(case)
        self.assertEqual(sum.getStartTime(),
                         datetime.datetime(2013, 1, 1, 0, 0, 0))
        self.assertEqual(sum.getEndTime(),
                         datetime.datetime(2013, 1, 1, 19, 30, 0))
        self.assertFloatEqual(sum.getSimulationLength(), 0.8125)
コード例 #50
0
 def test_dates2( self ):
     sum = EclSum(self.createTestPath("Statoil/ECLIPSE/FF12/FF12_2013B3_AMAP2"))
     self.assertEqual(sum.end_date , datetime.date(2045, 1, 1))
コード例 #51
0
ファイル: test_sum_statoil.py プロジェクト: agchitu/ert
    def test_regularProduction(self):
        sum = EclSum(self.case)
        with self.assertRaises(TypeError):
            trange = TimeVector.createRegular( sum.start_time , sum.end_time , "1M" )
            prod = sum.blockedProduction("FOPR" , trange)
            
        with self.assertRaises(KeyError):
            trange = TimeVector.createRegular( sum.start_time , sum.end_time , "1M" )
            prod = sum.blockedProduction("NoNotThis" , trange)

        trange = sum.timeRange(interval = "2Y")
        self.assertTrue( trange[0]  == datetime.date( 2000 , 1 , 1 ))
        self.assertTrue( trange[-1] == datetime.date( 2006 , 1 , 1 ))

        trange = sum.timeRange(interval = "5Y")
        self.assertTrue( trange[0]  == datetime.date( 2000 , 1 , 1 ))
        self.assertTrue( trange[-1] == datetime.date( 2005 , 1 , 1 ))
        
        trange = sum.timeRange(interval = "6M")
        wprod1 = sum.blockedProduction("WOPT:OP_1" , trange)
        wprod2 = sum.blockedProduction("WOPT:OP_2" , trange)
        wprod3 = sum.blockedProduction("WOPT:OP_3" , trange)
        wprod4 = sum.blockedProduction("WOPT:OP_4" , trange)
        wprod5 = sum.blockedProduction("WOPT:OP_5" , trange)
    
        fprod = sum.blockedProduction("FOPT" , trange)
        gprod = sum.blockedProduction("GOPT:OP" , trange)
        wprod = wprod1 + wprod2 + wprod3 + wprod4 + wprod5
        for (w,f,g) in zip(wprod, fprod,gprod):
            self.assertFloatEqual( w , f )
            self.assertFloatEqual( w , g )
コード例 #52
0
 def test_invalid(self):
     with self.assertRaises(IOError):
         sum = EclSum("Does/not/exist")
コード例 #53
0
ファイル: test_sum_statoil.py プロジェクト: agchitu/ert
    def setUp(self):
        self.case = self.createTestPath(case)
        self.ecl_sum = EclSum(self.case)

        self.assertIsInstance(self.ecl_sum, EclSum)
コード例 #54
0
 def setUp(self):
     self.test_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.SMSPEC")
     self.ecl_sum = EclSum(self.test_file)
コード例 #55
0
ファイル: snake_oil_simulator.py プロジェクト: Ensembles/ert
def runSimulator(simulator, history_simulator, time_step_count):
    """ @rtype: EclSum """
    ecl_sum = EclSum.writer("SNAKE_OIL_FIELD", datetime(2010, 1, 1), 10, 10, 10)

    ecl_sum.addVariable('FOPT', unit="SM3")
    ecl_sum.addVariable('FOPR', unit="SM3/DAY")
    ecl_sum.addVariable('FGPT', unit="SM3")
    ecl_sum.addVariable('FGPR', unit="SM3/DAY")
    ecl_sum.addVariable('FWPT', unit="SM3")
    ecl_sum.addVariable('FWPR', unit="SM3/DAY")
    ecl_sum.addVariable('FGOR', unit="SM3/SM3")
    ecl_sum.addVariable('FWCT', unit="SM3/SM3")

    ecl_sum.addVariable('FOIP', unit="SM3")
    ecl_sum.addVariable('FGIP', unit="SM3")
    ecl_sum.addVariable('FWIP', unit="SM3")

    ecl_sum.addVariable('FOPTH', unit="SM3")
    ecl_sum.addVariable('FOPRH', unit="SM3/DAY")
    ecl_sum.addVariable('FGPTH', unit="SM3")
    ecl_sum.addVariable('FGPRH', unit="SM3/DAY")
    ecl_sum.addVariable('FWPTH', unit="SM3")
    ecl_sum.addVariable('FWPRH', unit="SM3/DAY")
    ecl_sum.addVariable('FGORH', unit="SM3/SM3")
    ecl_sum.addVariable('FWCTH', unit="SM3/SM3")

    ecl_sum.addVariable('FOIPH', unit="SM3")
    ecl_sum.addVariable('FGIPH', unit="SM3")
    ecl_sum.addVariable('FWIPH', unit="SM3")

    ecl_sum.addVariable('WOPR', wgname='OP1', unit="SM3/DAY")
    ecl_sum.addVariable('WOPR', wgname='OP2', unit="SM3/DAY")
    ecl_sum.addVariable('WWPR', wgname='OP1', unit="SM3/DAY")
    ecl_sum.addVariable('WWPR', wgname='OP2', unit="SM3/DAY")
    ecl_sum.addVariable('WGPR', wgname='OP1', unit="SM3/DAY")
    ecl_sum.addVariable('WGPR', wgname='OP2', unit="SM3/DAY")
    ecl_sum.addVariable('WGOR', wgname='OP1', unit="SM3/SM3")
    ecl_sum.addVariable('WGOR', wgname='OP2', unit="SM3/SM3")
    ecl_sum.addVariable('WWCT', wgname='OP1', unit="SM3/SM3")
    ecl_sum.addVariable('WWCT', wgname='OP2', unit="SM3/SM3")

    ecl_sum.addVariable('WOPRH', wgname='OP1', unit="SM3/DAY")
    ecl_sum.addVariable('WOPRH', wgname='OP2', unit="SM3/DAY")
    ecl_sum.addVariable('WWPRH', wgname='OP1', unit="SM3/DAY")
    ecl_sum.addVariable('WWPRH', wgname='OP2', unit="SM3/DAY")
    ecl_sum.addVariable('WGPRH', wgname='OP1', unit="SM3/DAY")
    ecl_sum.addVariable('WGPRH', wgname='OP2', unit="SM3/DAY")
    ecl_sum.addVariable('WGORH', wgname='OP1', unit="SM3/SM3")
    ecl_sum.addVariable('WGORH', wgname='OP2', unit="SM3/SM3")
    ecl_sum.addVariable('WWCTH', wgname='OP1', unit="SM3/SM3")
    ecl_sum.addVariable('WWCTH', wgname='OP2', unit="SM3/SM3")

    ecl_sum.addVariable('BPR', num=globalIndex(5, 5, 5), unit="BARSA")
    ecl_sum.addVariable('BPR', num=globalIndex(1, 3, 8), unit="BARSA")

    time_map = []
    mini_step_count = 10
    total_step_count = time_step_count * mini_step_count

    for report_step in range(time_step_count):
        for mini_step in range(mini_step_count):
            t_step = ecl_sum.addTStep(report_step + 1, sim_days=report_step * mini_step_count + mini_step)

            time_map.append(t_step.getSimTime().datetime().strftime("%d/%m/%Y"))

            simulator.step(scale=1.0 / total_step_count)
            history_simulator.step(scale=1.0 / total_step_count)

            t_step['FOPR'] = simulator.fopr()
            t_step['FOPT'] = simulator.fopt()
            t_step['FGPR'] = simulator.fgpr()
            t_step['FGPT'] = simulator.fgpt()
            t_step['FWPR'] = simulator.fwpr()
            t_step['FWPT'] = simulator.fwpt()
            t_step['FGOR'] = simulator.fgor()
            t_step['FWCT'] = simulator.fwct()

            t_step['FOIP'] = simulator.foip()
            t_step['FGIP'] = simulator.fgip()
            t_step['FWIP'] = simulator.fwip()

            t_step['WOPR:OP1'] = simulator.opr('OP1')
            t_step['WOPR:OP2'] = simulator.opr('OP2')

            t_step['WGPR:OP1'] = simulator.gpr('OP1')
            t_step['WGPR:OP2'] = simulator.gpr('OP2')

            t_step['WWPR:OP1'] = simulator.wpr('OP1')
            t_step['WWPR:OP2'] = simulator.wpr('OP2')

            t_step['WGOR:OP1'] = simulator.gor('OP1')
            t_step['WGOR:OP2'] = simulator.gor('OP2')

            t_step['WWCT:OP1'] = simulator.wct('OP1')
            t_step['WWCT:OP2'] = simulator.wct('OP2')

            t_step['BPR:5,5,5'] = simulator.bpr('5,5,5')
            t_step['BPR:1,3,8'] = simulator.bpr('1,3,8')

            t_step['FOPRH'] = history_simulator.fopr()
            t_step['FOPTH'] = history_simulator.fopt()
            t_step['FGPRH'] = history_simulator.fgpr()
            t_step['FGPTH'] = history_simulator.fgpt()
            t_step['FWPRH'] = history_simulator.fwpr()
            t_step['FWPTH'] = history_simulator.fwpt()
            t_step['FGORH'] = history_simulator.fgor()
            t_step['FWCTH'] = history_simulator.fwct()
            t_step['FOIPH'] = history_simulator.foip()
            t_step['FGIPH'] = history_simulator.fgip()
            t_step['FWIPH'] = history_simulator.fwip()

            t_step['WOPRH:OP1'] = history_simulator.opr('OP1')
            t_step['WOPRH:OP2'] = history_simulator.opr('OP2')

            t_step['WGPRH:OP1'] = history_simulator.gpr('OP1')
            t_step['WGPRH:OP2'] = history_simulator.gpr('OP2')

            t_step['WWPRH:OP1'] = history_simulator.wpr('OP1')
            t_step['WWPRH:OP2'] = history_simulator.wpr('OP2')

            t_step['WGORH:OP1'] = history_simulator.gor('OP1')
            t_step['WGORH:OP2'] = history_simulator.gor('OP2')

            t_step['WWCTH:OP1'] = history_simulator.wct('OP1')
            t_step['WWCTH:OP2'] = history_simulator.wct('OP2')

    return ecl_sum, time_map
コード例 #56
0
ファイル: snake_oil_simulator.py プロジェクト: Ensembles/ert
def runSimulator(simulator, history_simulator, time_step_count):
    """ @rtype: EclSum """
    ecl_sum = EclSum.writer("SNAKE_OIL_FIELD", datetime(2010, 1, 1), 10, 10, 10)

    ecl_sum.addVariable("FOPT")
    ecl_sum.addVariable("FOPR")
    ecl_sum.addVariable("FGPT")
    ecl_sum.addVariable("FGPR")
    ecl_sum.addVariable("FWPT")
    ecl_sum.addVariable("FWPR")
    ecl_sum.addVariable("FGOR")
    ecl_sum.addVariable("FWCT")

    ecl_sum.addVariable("FOPTH")
    ecl_sum.addVariable("FOPRH")
    ecl_sum.addVariable("FGPTH")
    ecl_sum.addVariable("FGPRH")
    ecl_sum.addVariable("FWPTH")
    ecl_sum.addVariable("FWPRH")
    ecl_sum.addVariable("FGORH")
    ecl_sum.addVariable("FWCTH")

    ecl_sum.addVariable("WOPR", wgname="OP1")
    ecl_sum.addVariable("WOPR", wgname="OP2")
    ecl_sum.addVariable("WWPR", wgname="OP1")
    ecl_sum.addVariable("WWPR", wgname="OP2")
    ecl_sum.addVariable("WGPR", wgname="OP1")
    ecl_sum.addVariable("WGPR", wgname="OP2")
    ecl_sum.addVariable("WGOR", wgname="OP1")
    ecl_sum.addVariable("WGOR", wgname="OP2")
    ecl_sum.addVariable("WWCT", wgname="OP1")
    ecl_sum.addVariable("WWCT", wgname="OP2")

    ecl_sum.addVariable("WOPRH", wgname="OP1")
    ecl_sum.addVariable("WOPRH", wgname="OP2")
    ecl_sum.addVariable("WWPRH", wgname="OP1")
    ecl_sum.addVariable("WWPRH", wgname="OP2")
    ecl_sum.addVariable("WGPRH", wgname="OP1")
    ecl_sum.addVariable("WGPRH", wgname="OP2")
    ecl_sum.addVariable("WGORH", wgname="OP1")
    ecl_sum.addVariable("WGORH", wgname="OP2")
    ecl_sum.addVariable("WWCTH", wgname="OP1")
    ecl_sum.addVariable("WWCTH", wgname="OP2")

    ecl_sum.addVariable("BPR", num=globalIndex(5, 5, 5))
    ecl_sum.addVariable("BPR", num=globalIndex(1, 3, 8))

    time_map = []
    mini_step_count = 10
    total_step_count = time_step_count * mini_step_count

    for report_step in range(time_step_count):
        for mini_step in range(mini_step_count):
            t_step = ecl_sum.addTStep(report_step + 1, sim_days=report_step * mini_step_count + mini_step)

            time_map.append(t_step.getSimTime().datetime().strftime("%d/%m/%Y"))

            simulator.step(scale=1.0 / total_step_count)
            history_simulator.step(scale=1.0 / total_step_count)

            t_step["FOPR"] = simulator.fopr()
            t_step["FOPT"] = simulator.fopt()
            t_step["FGPR"] = simulator.fgpr()
            t_step["FGPT"] = simulator.fgpt()
            t_step["FWPR"] = simulator.fwpr()
            t_step["FWPT"] = simulator.fwpt()
            t_step["FGOR"] = simulator.fgor()
            t_step["FWCT"] = simulator.fwct()

            t_step["WOPR:OP1"] = simulator.opr("OP1")
            t_step["WOPR:OP2"] = simulator.opr("OP2")

            t_step["WGPR:OP1"] = simulator.gpr("OP1")
            t_step["WGPR:OP2"] = simulator.gpr("OP2")

            t_step["WWPR:OP1"] = simulator.wpr("OP1")
            t_step["WWPR:OP2"] = simulator.wpr("OP2")

            t_step["WGOR:OP1"] = simulator.gor("OP1")
            t_step["WGOR:OP2"] = simulator.gor("OP2")

            t_step["WWCT:OP1"] = simulator.wct("OP1")
            t_step["WWCT:OP2"] = simulator.wct("OP2")

            t_step["BPR:5,5,5"] = simulator.bpr("5,5,5")
            t_step["BPR:1,3,8"] = simulator.bpr("1,3,8")

            t_step["FOPRH"] = history_simulator.fopr()
            t_step["FOPTH"] = history_simulator.fopt()
            t_step["FGPRH"] = history_simulator.fgpr()
            t_step["FGPTH"] = history_simulator.fgpt()
            t_step["FWPRH"] = history_simulator.fwpr()
            t_step["FWPTH"] = history_simulator.fwpt()
            t_step["FGORH"] = history_simulator.fgor()
            t_step["FWCTH"] = history_simulator.fwct()

            t_step["WOPRH:OP1"] = history_simulator.opr("OP1")
            t_step["WOPRH:OP2"] = history_simulator.opr("OP2")

            t_step["WGPRH:OP1"] = history_simulator.gpr("OP1")
            t_step["WGPRH:OP2"] = history_simulator.gpr("OP2")

            t_step["WWPRH:OP1"] = history_simulator.wpr("OP1")
            t_step["WWPRH:OP2"] = history_simulator.wpr("OP2")

            t_step["WGORH:OP1"] = history_simulator.gor("OP1")
            t_step["WGORH:OP2"] = history_simulator.gor("OP2")

            t_step["WWCTH:OP1"] = history_simulator.wct("OP1")
            t_step["WWCTH:OP2"] = history_simulator.wct("OP2")

    return ecl_sum, time_map