Exemplo n.º 1
0
    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 )
Exemplo n.º 2
0
    def test_Heidrun(self):
        sum = EclSum( self.createTestPath("Equinor/ECLIPSE/Heidrun/Summary/FF12_2013B3_CLEAN_RS"))
        self.assertEqual( 452 , len(sum))
        self.assertFloatEqual( 1.8533144e+8 , sum.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 )
Exemplo n.º 3
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.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 )
Exemplo n.º 4
0
    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 ))
Exemplo n.º 5
0
    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 )
Exemplo n.º 6
0
class EclSumTest(EclTest):


    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, 1, 1, 0, 0, 0)
        with TestAreaContext("EclSum/csv_dump"):
            test_file_name = self.createTestPath("dump.csv")
            outputH = copen(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, lazy_load=True)
        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(), 19.50)

        sum = EclSum(case, lazy_load=False)
        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(), 19.50)
Exemplo n.º 7
0
class EclSumTest(EclTest):
    def setUp(self):
        self.test_file = self.createTestPath("Equinor/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, 1, 1, 0, 0, 0)
        with TestAreaContext("EclSum/csv_dump"):
            test_file_name = self.createTestPath("dump.csv")
            outputH = copen(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("Equinor/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("Equinor/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("Equinor/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("Equinor/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("Equinor/ECLIPSE/LabScale/HDMODEL")
        sum = EclSum(case, lazy_load=True)
        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(), 19.50)

        sum = EclSum(case, lazy_load=False)
        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(), 19.50)
Exemplo n.º 8
0
              "2014-11-01": 75.79,
              "2014-12-01": 59.29,
              "2015-01-01": 47.22,
              "2015-02-01": 50.58,
              "2015-03-01": 47.82,
              "2015-04-01": 54.45,
              "2015-05-01": 59.27,
              "2015-06-01": 59.82,
              "2015-07-01": 50.90,
              "2015-08-01": 42.87,
              "2015-09-01": 45.48}

if __name__ == '__main__':
    ecl_sum = EclSum("SNAKE_OIL_FIELD")
    start_time = ecl_sum.getStartTime()
    date_ranges = ecl_sum.timeRange(start_time, interval="1M")
    production_sums = ecl_sum.blockedProduction("FOPT", date_ranges)

    npv = 0.0
    for index in range(0, len(date_ranges) - 1):
        date = date_ranges[index + 1] # end of period
        production_sum = production_sums[index]

        oil_price = OIL_PRICES[date.date().strftime("%Y-%m-%d")]

        production_value = oil_price * production_sum
        npv += production_value

    with open("snake_oil_npv.txt", "w") as output_file:
        output_file.write("NPV %s\n" % npv)
Exemplo n.º 9
0
    "2014-12-01": 59.29,
    "2015-01-01": 47.22,
    "2015-02-01": 50.58,
    "2015-03-01": 47.82,
    "2015-04-01": 54.45,
    "2015-05-01": 59.27,
    "2015-06-01": 59.82,
    "2015-07-01": 50.90,
    "2015-08-01": 42.87,
    "2015-09-01": 45.48,
}

if __name__ == "__main__":
    ecl_sum = EclSum("SNAKE_OIL_FIELD")
    start_time = ecl_sum.getStartTime()
    date_ranges = ecl_sum.timeRange(start_time, interval="1M")
    production_sums = ecl_sum.blockedProduction("FOPT", date_ranges)

    npv = 0.0
    for index in range(0, len(date_ranges) - 1):
        date = date_ranges[index + 1]  # end of period
        production_sum = production_sums[index]

        oil_price = OIL_PRICES[date.date().strftime("%Y-%m-%d")]

        production_value = oil_price * production_sum
        npv += production_value

    with open("snake_oil_npv.txt", "w") as output_file:
        output_file.write("NPV %s\n" % npv)