Exemplo n.º 1
0
    def test_c_time(self):
        c_time = ctime(0)
        self.assertEqual(str(c_time), "1970-01-01 01:00:00")

        date_time = ctime(datetime(1970, 1, 1, 1, 0, 0))
        self.assertEqual(c_time, date_time)

        date_time_after = ctime(datetime(1970, 1, 1, 1, 0, 5))

        self.assertTrue(date_time_after > date_time)
Exemplo n.º 2
0
    def test_time_vector(self):
        time_vector = TimeVector()

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

        time_vector.default = 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)
Exemplo n.º 3
0
    def get_interp( self , key , days = None , date = None):
        """
        Will lookup vector @key at time given by @days or @date.
        
        Requiers exactly one input argument @days or @date; will raise
        exception ValueError if this is not satisfied. 

        The method will check that the time argument is within the
        time limits of the simulation; if else the method will raise
        exception ValueError.

        Also available as method get_interp() on the EclSumVector
        class.
        """
        if days:
            if date:
                raise ValueError("Must supply either days or date")
            else:
                if EclSum.cNamespace().check_sim_days( self , days ):
                    return EclSum.cNamespace().get_general_var_from_sim_days( self , days , key )
                else:
                    raise ValueError("days:%s is outside range of simulation: [%g,%g]" % (days , self.first_day , self.sim_length))
        elif date:
            if self.check_sim_time( date ):
                return EclSum.cNamespace().get_general_var_from_sim_time( self , ctime(date) , key )
            else:
                raise ValueError("date:%s is outside range of simulation data" % date)
        else:
            raise ValueError("Must supply either days or date")
Exemplo n.º 4
0
    def restart_block( cls , filename , dtime = None , report_step = None):
        """
        Load one report step from unified restart file.

        Unified restart files can be prohibitively large; with this
        class method it is possible to load only one report
        step. Which report step you are interested in must be
        specified with either one of the optional arguments
        @report_step or @dtime. If present @dtime should be a normal
        python datetime instance:
        
            block1 = EclFile.restart_block( "ECLIPSE.UNRST" , dtime = datetime.datetime( year , month , day ))
            block2 = EclFile.restart_block( "ECLIPSE.UNRST" , report_step = 67 )

        If the block you are asking for can not be found the method
        will return None.
        """
        obj = EclFile( filename )
        
        if dtime:
            OK = cfunc.restart_block_time( obj , ctime( dtime ))
        elif not report_step is None:
            OK = cfunc.restart_block_step( obj , report_step )
        else:
            raise TypeError("restart_block() requires either dtime or report_step argument - none given.")
        
        if not OK:
            if dtime:
                raise ValueError("Could not locate date:%02d/%02d/%4d in restart file: %s." % (dtime.day , dtime.month , dtime.year , filename))
            else:
                raise ValueError("Could not locate report step:%d in restart file: %s." % (report_step , filename))
            
            
        return obj
Exemplo n.º 5
0
    def restart_get_kw( self , kw_name , dtime , copy = False):
        """
        Will return EclKW @kw_name from restart file at time @dtime.

        This function assumes that the current EclFile instance
        represents a restart file. It will then look for keyword
        @kw_name exactly at the time @dtime; @dtime is a datetime
        instance:

            file = EclFile( "ECLIPSE.UNRST" )
            swat2010 = file.restart_get_kw( "SWAT" , datetime.datetime( 2000 , 1 , 1 ))

        By default the returned kw instance is a reference to the
        ecl_kw still contained in the EclFile instance; i.e. the kw
        will become a dangling reference if the EclFile instance goes
        out of scope. If the optional argument @copy is True the
        returned kw will be a true copy.

        If the file does not have the keyword at the specified time the
        function will return None.
        """
        index = cfunc.get_restart_index( self , ctime( dtime ) )
        if index >= 0:
            kw = self.iget_named_kw( kw_name , index )
            if copy:
                return EclKW.copy( kw )
            else:
                return kw
        else:
            return None
Exemplo n.º 6
0
    def get(self , well_name , date ):
        """
        Will look up the RFT object corresponding to @well and @date.

        Returns None if no matching RFT can be found.
        """
        c_ptr = cfunc_file.get_rft( self , well_name , ctime( date )) 
        if c_ptr:
            return EclRFT( c_ptr , self)
        else:
            return None
Exemplo n.º 7
0
    def has_sim_time( self , dtime ):
        """
        Checks if the current EclFile has data for time @dtime.

        The implementation goes through all the INTEHEAD headers in
        the EclFile, i.e. it can be fooled (and probably crash and
        burn) if the EclFile instance in question is has INTEHEAD
        keyword(s), but is still not a restart file. The @dtime
        argument should be a normal python datetime instance.
        """
        return cfunc.has_sim_time( self , ctime(dtime) )    
Exemplo n.º 8
0
    def get_report( self , date = None , days = None):
        """
        Will return the report step corresponding to input @date or @days.

        If the input argument does not correspond to any report steps
        the function will return -1. Observe that the function
        requires strict equality.
        """
        if date:
            if days:
                raise ValueError("Must supply either days or date")
            step = EclSum.cNamespace().get_report_step_from_time( self , ctime(date))
        elif days:
            step = EclSum.cNamespace().get_report_step_from_days( self , days)
            
        return step
Exemplo n.º 9
0
    def size( self , well = None , date = None):
        """
        The number of elements in EclRFTFile container. 

        By default the size() method will return the total number of
        RFTs/PLTs in the container, but by specifying the optional
        arguments date and/or well the function will only count the
        number of well measurements matching that time or well
        name. The well argument can contain wildcards.

           rftFile = ecl.EclRFTFile( "ECLIPSE.RFT" )
           print "Total number of RFTs : %d" % rftFile.size( )
           print "RFTs matching OP*    : %d" % rftFile.size( well = "OP*" )
           print "RFTs at 01/01/2010   : %d" % rftFile.size( date = datetime.date( 2010 , 1 , 1 ))

        """
        if date:
            cdate = ctime( date )
        else:
            cdate = -1

        return cfunc_file.get_size( self , well , cdate)
Exemplo n.º 10
0
    def select_restart_section( self, index = None , report_step = None , sim_time = None):
        """
        Will select a restart section as the active section.
        
        You must specify a report step with the @report_step argument,
        a true time with the @sim_time argument or a plain index to
        select restart block. If none of arguments are given exception
        TypeError will be raised. If present the @sim_time argument
        should be a datetime instance.
        
        If the restart section you ask for can not be found the method
        will raise a ValueError exeception. To protect against this
        you can query first with the has_report_step(), 
        has_sim_time() or num_report_steps() methods.

        This method should be used when you have already loaded the
        complete file; if you only want to load a section from the
        file you can use the classmethod restart_block().

        The method will return 'self' which can be used to aid
        readability.
        """

        OK = False
        if report_step:
            OK = cfunc.restart_block_step( self , report_step )
        elif sim_time:
            OK = cfunc.restart_block_time( self , ctime( sim_time ) )
        elif index:
            OK = cfunc.restart_block_iselect( self, index )
        else:
            raise TypeError("select_restart_section() requires either dtime or report_step argument - none given")

        
        if not OK:
            raise TypeError("select_restart_section() Could not locate report_step/dtime")
        return self
Exemplo n.º 11
0
    def get_interp_vector( self , key , days_list = None , date_list = None):
        """
        Will return numpy vector with interpolated values.

        Requiers exactly one input argument @days or @date; will raise
        exception ValueError if this is not satisfied. 

        The method will check that the time arguments are within the
        time limits of the simulation; if else the method will raise
        exception ValueError.

        Also available as method get_interp_vector() on the
        EclSumVector class.
        """
        if days_list:
            if date_list:
                raise ValueError("Must supply either days_list or date_list")
            else:
                vector = numpy.zeros( len(days_list ))
                sim_length = self.sim_length
                sim_start  = self.first_day
                index = 0
                for days in days_list:
                    if (days >= sim_start) and (days < sim_length):
                        vector[index] = EclSum.cNamespace().get_general_var_from_sim_days( self , days , key)
                    else:
                        raise ValueError("Invalid days value")
                    index += 1
        elif date_list:
            start_time = self.data_start
            end_time   = self.end_date
            vector = numpy.zeros( len(date_list ))
            index = 0
            for date in date_list:
                if (date >= start_time) and (date <= end_time):
                    vector[index] =  EclSum.cNamespace().get_general_var_from_sim_time( self , ctime(date) , key)
                else:
                    raise ValueError("Invalid date value")
                index += 1
        else:
            raise ValueError("Must supply either days_list or date_list")
        return vector
Exemplo n.º 12
0
 def check_sim_time( self , date):
     """
     Will check if the input date is in the time span [sim_start , sim_end].
     """
     return EclSum.cNamespace().check_sim_time( self , ctime(date) )
Exemplo n.º 13
0
 def __init__(self, filename, start_time):
     c_ptr = SchedFile.cNamespace().parse(filename, ctime(start_time))
     super(SchedFile, self).__init__(c_ptr)