Ejemplo 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)
Ejemplo n.º 2
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 )
Ejemplo n.º 3
0
    def test_contains_time(self):
        start = datetime.datetime(2010, 1, 1, 0, 0, 0)
        end = datetime.datetime(2010, 2, 1, 0, 0, 0)
        other = datetime.datetime(2010, 1, 15, 0, 0, 0)

        tv = TimeVector()
        tv.append(start)
        tv.append(end)

        self.assertTrue(start in tv)
        self.assertTrue(end in tv)
        self.assertTrue(other not in tv)
Ejemplo n.º 4
0
    def test_resample(self):
        time_points = TimeVector()
        start_time = self.ecl_sum.get_data_start_time()
        end_time = self.ecl_sum.get_end_time()
        delta = end_time - start_time
        N = 25
        time_points.initRange(
            CTime(start_time),
            CTime(end_time),
            CTime(int(delta.total_seconds() / (N - 1))),
        )
        time_points.append(CTime(end_time))
        resampled = self.ecl_sum.resample("OUTPUT_CASE", time_points)

        for key in self.ecl_sum.keys():
            self.assertIn(key, resampled)

        self.assertEqual(
            self.ecl_sum.get_data_start_time(), resampled.get_data_start_time()
        )
        delta = self.ecl_sum.get_end_time() - resampled.get_end_time()
        self.assertTrue(delta.total_seconds() <= 1)

        keys = ["FOPT", "FOPR", "BPR:15,28,1", "WGOR:OP_1"]
        for key in keys:
            for time_index, t in enumerate(time_points):
                self.assertFloatEqual(
                    resampled.iget(key, time_index),
                    self.ecl_sum.get_interp_direct(key, t),
                )
Ejemplo n.º 5
0
    def test_resample(self):
        time_points = TimeVector()
        start_time = self.ecl_sum.get_data_start_time()
        end_time = self.ecl_sum.get_end_time()
        delta = end_time - start_time
        N = 25
        time_points.initRange( CTime(start_time),
                               CTime(end_time),
                               CTime(int(delta.total_seconds()/(N - 1))))
        time_points.append(CTime(end_time))
        resampled = self.ecl_sum.resample( "OUTPUT_CASE", time_points )

        for key in self.ecl_sum.keys():
            self.assertIn( key, resampled )

        self.assertEqual(self.ecl_sum.get_data_start_time(), resampled.get_data_start_time())
        delta = self.ecl_sum.get_end_time() - resampled.get_end_time()
        self.assertTrue( delta.total_seconds() <= 1 )

        keys = ["FOPT", "FOPR", "BPR:15,28,1", "WGOR:OP_1"]
        for key in keys:
            for time_index,t in enumerate(time_points):
                self.assertFloatEqual(resampled.iget( key, time_index), self.ecl_sum.get_interp_direct( key, t))
Ejemplo n.º 6
0
    def test_resample_extrapolate(self):
        """
        Test resampling of summary with extrapolate option of lower and upper boundaries enabled
        """
        from ecl.util.util import TimeVector, CTime

        time_points = TimeVector()

        path = os.path.join(self.TESTDATA_ROOT,
                            "local/ECLIPSE/cp_simple3/SIMPLE_SUMMARY3")
        ecl_sum = EclSum(path, lazy_load=True)

        start_time = ecl_sum.get_data_start_time() - datetime.timedelta(
            seconds=86400)
        end_time = ecl_sum.get_end_time() + datetime.timedelta(seconds=86400)
        delta = end_time - start_time

        N = 25
        time_points.initRange(CTime(start_time), CTime(end_time),
                              CTime(int(delta.total_seconds() / (N - 1))))
        time_points.append(CTime(end_time))
        resampled = ecl_sum.resample("OUTPUT_CASE",
                                     time_points,
                                     lower_extrapolation=True,
                                     upper_extrapolation=True)

        for key in ecl_sum.keys():
            self.assertIn(key, resampled)

        self.assertEqual(
            ecl_sum.get_data_start_time() - datetime.timedelta(seconds=86400),
            resampled.get_data_start_time())

        key_not_rate = "FOPT"
        for time_index, t in enumerate(time_points):
            if t < ecl_sum.get_data_start_time():
                self.assertFloatEqual(resampled.iget(key_not_rate, time_index),
                                      ecl_sum._get_first_value(key_not_rate))
            elif t > ecl_sum.get_end_time():
                self.assertFloatEqual(resampled.iget(key_not_rate, time_index),
                                      ecl_sum.get_last_value(key_not_rate))
            else:
                self.assertFloatEqual(
                    resampled.iget(key_not_rate, time_index),
                    ecl_sum.get_interp_direct(key_not_rate, t))

        key_rate = "FOPR"
        for time_index, t in enumerate(time_points):
            if t < ecl_sum.get_data_start_time():
                self.assertFloatEqual(resampled.iget(key_rate, time_index), 0)
            elif t > ecl_sum.get_end_time():
                self.assertFloatEqual(resampled.iget(key_rate, time_index), 0)
            else:
                self.assertFloatEqual(resampled.iget(key_rate, time_index),
                                      ecl_sum.get_interp_direct(key_rate, t))
Ejemplo n.º 7
0
 def test_slicing(self):
     dv = DoubleVector(initial_size=10)
     for i in range(10):
         dv[i] = 1.0 / (1 + i)
     self.dotest_slicing(dv)
     iv = IntVector(initial_size=10)
     for i in range(10):
         iv[i] = i**3
     self.dotest_slicing(iv)
     bv = BoolVector(initial_size=10)
     for i in range(0, 10, 3):
         bv[i] = True
     self.dotest_slicing(bv)
     tv = TimeVector(initial_size=10)
     for i in range(10):
         tv[i] = CTime(datetime.datetime(2016, 12, i + 3, 0, 0, 0))
     self.dotest_slicing(tv)
Ejemplo n.º 8
0
    def test_contains_time(self):
        start = datetime.datetime(2010, 1, 1, 0, 0, 0)
        end = datetime.datetime(2010, 2, 1, 0, 0, 0)
        other = datetime.datetime(2010, 1, 15, 0, 0, 0)

        tv = TimeVector()
        tv.append(start)
        tv.append(end)

        self.assertTrue(start in tv)
        self.assertTrue(end in tv)
        self.assertTrue(other not in tv)
Ejemplo n.º 9
0
    def test_time_vector(self):
        time_vector = TimeVector()

        time1 = CTime(datetime.datetime(2013, 8, 13, 0, 0, 0))
        time2 = CTime(datetime.datetime(2013, 8, 13, 1, 0, 0))

        time_vector.setDefault(time2)

        time_vector.append(time1)
        time_vector[2] = time2

        self.assertEqual(time_vector[0], time1)
        self.assertEqual(time_vector[1], time2)
        self.assertEqual(time_vector[2], time2)

        tv1 = TimeVector(default_value=datetime.date(2000, 1, 1), initial_size=2)
        self.assertEqual(tv1[0], datetime.date(2000, 1, 1))

        tv2 = TimeVector()
        tv2.append(time2)
Ejemplo n.º 10
0
    def test_time_vector_regular(self):
        start = datetime.datetime(2010, 1, 1, 0, 0, 0)
        end = datetime.datetime(2010, 2, 1, 0, 0, 0)

        with self.assertRaises(ValueError):
            trange = TimeVector.createRegular(end, start, "1X")

        with self.assertRaises(TypeError):
            trange = TimeVector.createRegular(start, end, "1X")

        with self.assertRaises(TypeError):
            trange = TimeVector.createRegular(start, end, "1")

        with self.assertRaises(TypeError):
            trange = TimeVector.createRegular(start, end, "X")

        with self.assertRaises(TypeError):
            trange = TimeVector.createRegular(start, end, "1.5Y")

        trange = TimeVector.createRegular(start, end, "d")
        trange = TimeVector.createRegular(start, end, "D")
        trange = TimeVector.createRegular(start, end, "1d")
        self.assertEqual(trange[0].datetime(), start)
        self.assertEqual(trange[-1].datetime(), end)
        date = start
        delta = datetime.timedelta(days=1)
        for t in trange:
            self.assertEqual(t, date)
            date += delta

        end = datetime.datetime(2010, 1, 10, 0, 0, 0)
        trange = TimeVector.createRegular(start, end, "2d")
        self.assertEqual(trange[-1].datetime(),
                         datetime.datetime(2010, 1, 9, 0, 0, 0))
        self.assertEqual(5, len(trange))

        end = datetime.datetime(2012, 1, 10, 0, 0, 0)
        trange = TimeVector.createRegular(start, end, "3M")
        self.assertTrue(trange[-1] == datetime.datetime(2012, 1, 1, 0, 0, 0))
        self.assertTrue(trange[1] == datetime.datetime(2010, 4, 1, 0, 0, 0))
        self.assertTrue(trange[2] == datetime.datetime(2010, 7, 1, 0, 0, 0))
        self.assertTrue(trange[3] == datetime.datetime(2010, 10, 1, 0, 0, 0))
        self.assertTrue(trange[4] == datetime.datetime(2011, 1, 1, 0, 0, 0))

        start = datetime.datetime(1980, 1, 1, 0, 0, 0)
        end = datetime.datetime(2020, 1, 1, 0, 0, 0)
        trange = TimeVector.createRegular(start, end, "2Y")
        for (y, t) in zip(six.moves.xrange(1980, 2022, 2), trange):
            self.assertTrue(t == datetime.datetime(y, 1, 1, 0, 0, 0))

        trange = TimeVector.createRegular(start, datetime.date(2050, 1, 1),
                                          "1Y")
Ejemplo n.º 11
0
    def test_time_vector(self):
        time_vector = TimeVector()

        time1 = CTime(datetime.datetime(2013, 8, 13, 0, 0, 0))
        time2 = CTime(datetime.datetime(2013, 8, 13, 1, 0, 0))

        time_vector.setDefault(time2)

        time_vector.append(time1)
        time_vector[2] = time2

        self.assertEqual(time_vector[0], time1)
        self.assertEqual(time_vector[1], time2)
        self.assertEqual(time_vector[2], time2)

        tv1 = TimeVector(default_value=datetime.date(2000, 1, 1),
                         initial_size=2)
        self.assertEqual(tv1[0], datetime.date(2000, 1, 1))

        tv2 = TimeVector()
        tv2.append(time2)
Ejemplo n.º 12
0
    def test_time_vector_regular(self):
        start = datetime.datetime(2010, 1, 1, 0, 0, 0)
        end = datetime.datetime(2010, 2, 1, 0, 0, 0)

        with self.assertRaises(ValueError):
            trange = TimeVector.createRegular(end, start, "1X")

        with self.assertRaises(TypeError):
            trange = TimeVector.createRegular(start, end, "1X")

        with self.assertRaises(TypeError):
            trange = TimeVector.createRegular(start, end, "1")

        with self.assertRaises(TypeError):
            trange = TimeVector.createRegular(start, end, "X")

        with self.assertRaises(TypeError):
            trange = TimeVector.createRegular(start, end, "1.5Y")

        trange = TimeVector.createRegular(start, end, "d")
        trange = TimeVector.createRegular(start, end, "D")
        trange = TimeVector.createRegular(start, end, "1d")
        self.assertEqual(trange[0].datetime(), start)
        self.assertEqual(trange[-1].datetime(), end)
        date = start
        delta = datetime.timedelta(days=1)
        for t in trange:
            self.assertEqual(t, date)
            date += delta

        end = datetime.datetime(2010, 1, 10, 0, 0, 0)
        trange = TimeVector.createRegular(start, end, "2d")
        self.assertEqual(trange[-1].datetime(), datetime.datetime(2010, 1, 9, 0, 0, 0))
        self.assertEqual(5, len(trange))

        end = datetime.datetime(2012, 1, 10, 0, 0, 0)
        trange = TimeVector.createRegular(start, end, "3M")
        self.assertTrue(trange[-1] == datetime.datetime(2012, 1, 1, 0, 0, 0))
        self.assertTrue(trange[1] == datetime.datetime(2010, 4, 1, 0, 0, 0))
        self.assertTrue(trange[2] == datetime.datetime(2010, 7, 1, 0, 0, 0))
        self.assertTrue(trange[3] == datetime.datetime(2010, 10, 1, 0, 0, 0))
        self.assertTrue(trange[4] == datetime.datetime(2011, 1, 1, 0, 0, 0))

        start = datetime.datetime(1980, 1, 1, 0, 0, 0)
        end = datetime.datetime(2020, 1, 1, 0, 0, 0)
        trange = TimeVector.createRegular(start, end, "2Y")
        for (y, t) in zip(six.moves.xrange(1980, 2022, 2), trange):
            self.assertTrue(t == datetime.datetime(y, 1, 1, 0, 0, 0))

        trange = TimeVector.createRegular(start, datetime.date(2050, 1, 1), "1Y")
Ejemplo n.º 13
0
    def time_range(self,
                   start=None,
                   end=None,
                   interval="1Y",
                   num_timestep=None,
                   extend_end=True):
        """Will create a vector of timepoints based on the current case.

        By default the timepoints will be regularly sampled based on the
        interval given by the @interval string. Alternatively the total number
        of timesteps can be specified, if the @num_timestep option is specified
        that will take presedence.
        """
        (num, timeUnit) = TimeVector.parseTimeUnit(interval)

        if start is None:
            start = self.getDataStartTime()
        else:
            if isinstance(start, datetime.date):
                start = datetime.datetime(start.year, start.month, start.day,
                                          0, 0, 0)

            if start < self.getDataStartTime():
                start = self.getDataStartTime()

        if end is None:
            end = self.getEndTime()
        else:
            if isinstance(end, datetime.date):
                end = datetime.datetime(end.year, end.month, end.day, 0, 0, 0)

            if end > self.getEndTime():
                end = self.getEndTime()

        if end < start:
            raise ValueError("Invalid time interval start after end")

        if not num_timestep is None:
            return TimeVector.create_linear(CTime(start), CTime(end),
                                            num_timestep)

        range_start = start
        range_end = end
        if not timeUnit == "d":
            year1 = start.year
            year2 = end.year
            month1 = start.month
            month2 = end.month
            day1 = start.day
            day2 = end.day
            if extend_end:
                if timeUnit == 'm':
                    if day2 > 1:
                        month2 += 1
                        if month2 == 13:
                            year2 += 1
                            month2 = 1
                elif timeUnit == "y":
                    month1 = 1
                    if year2 > 1 or day2 > 1:
                        year2 += 1
                        month2 = 1
            day1 = 1
            day2 = 1

            range_start = datetime.date(year1, month1, day1)
            range_end = datetime.date(year2, month2, day2)

        trange = TimeVector.createRegular(range_start, range_end, interval)

        # If the simulation does not start at the first of the month
        # the start value will be before the simulation start; we
        # manually shift the first element in the trange to the start
        # value; the same for the end of list.

        if trange[-1] < end:
            if extend_end:
                trange.appendTime(num, timeUnit)
            else:
                trange.append(end)

        data_start = self.getDataStartTime()
        if trange[0] < data_start:
            trange[0] = CTime(data_start)

        return trange