当前位置: 首页>>代码示例>>Python>>正文


Python TimeVector.createRegular方法代码示例

本文整理汇总了Python中ert.util.TimeVector.createRegular方法的典型用法代码示例。如果您正苦于以下问题:Python TimeVector.createRegular方法的具体用法?Python TimeVector.createRegular怎么用?Python TimeVector.createRegular使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ert.util.TimeVector的用法示例。


在下文中一共展示了TimeVector.createRegular方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_regularProduction

# 需要导入模块: from ert.util import TimeVector [as 别名]
# 或者: from ert.util.TimeVector import createRegular [as 别名]
    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 )
开发者ID:agchitu,项目名称:ert,代码行数:33,代码来源:test_sum_statoil.py

示例2: timeRange

# 需要导入模块: from ert.util import TimeVector [as 别名]
# 或者: from ert.util.TimeVector import createRegular [as 别名]
    def timeRange(self , start = None , end = None , interval = "1Y", extend_end = True):
        (num , timeUnit) = TimeVector.parseTimeUnit( interval )

        if start is None:
            start = self.getDataStartTime( )
        if isinstance(start , datetime.date):
            start = datetime.datetime( start.year , start.month , start.day , 0 , 0 , 0 )
                
        if end is None:
            end = self.end_time
        if isinstance(end , datetime.date):
            end = datetime.datetime( end.year , end.month , end.day , 0 , 0 , 0 )
        
        if end < start:
            raise ValueError("Invalid time interval start after 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 )

        if trange[0] < start:
            trange[0] = CTime(start)
                
        return trange
开发者ID:bramirex,项目名称:ert,代码行数:61,代码来源:ecl_sum.py

示例3: timeRange

# 需要导入模块: from ert.util import TimeVector [as 别名]
# 或者: from ert.util.TimeVector import createRegular [as 别名]
    def timeRange(self , start = None , end = None , interval = "1Y", extend_end = True):
        (num , timeUnit) = TimeVector.parseTimeUnit( interval )

        if start is None:
            start = self.getDataStartTime( )
        if isinstance(start , datetime.date):
            start = datetime.datetime( start.year , start.month , start.day , 0 , 0 , 0 )
                
        if end is None:
            end = self.end_time
        if isinstance(end , datetime.date):
            end = datetime.datetime( end.year , end.month , end.day , 0 , 0 , 0 )
        
        if end < start:
            raise ValueError("Invalid time interval start after 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

            start = datetime.date( year1, month1 , day1)
            end =  datetime.date(year2 , month2 , day2)
                
        trange = TimeVector.createRegular(start , end , interval)
        if trange[-1] < end:
            if extend_end:
                trange.appendTime( num , timeUnit )
            else:
                trange.append( end )

        return trange
开发者ID:jonerduarte,项目名称:ert,代码行数:52,代码来源:ecl_sum.py

示例4: test_time_vector_regular

# 需要导入模块: from ert.util import TimeVector [as 别名]
# 或者: from ert.util.TimeVector import createRegular [as 别名]
    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(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")
开发者ID:YingfangZhou,项目名称:ert,代码行数:54,代码来源:test_vectors.py


注:本文中的ert.util.TimeVector.createRegular方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。