How to use ert - 10 common examples

To help you get started, we’ve selected a few ert examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Ensembles / ert / devel / python / python / ert / enkf / ert_test_context.py View on Github external
def __enter__(self):
        return self.test_context
        
        
    def __exit__(self , exc_type, exc_val, exc_tb):
        del self.test_context
        return False

    
    def getErt(self):
        return self.test_context.getErt()



cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerType("ert_test", ErtTest)
cwrapper.registerType("ert_test_obj", ErtTest.createPythonObject)
cwrapper.registerType("ert_test_ref", ErtTest.createCReference)


ErtTest.cNamespace().alloc = cwrapper.prototype("c_void_p ert_test_context_alloc( char* , char* , char*)")
ErtTest.cNamespace().set_store = cwrapper.prototype("c_void_p ert_test_context_set_store( ert_test , bool)")
ErtTest.cNamespace().free = cwrapper.prototype("void ert_test_context_free( ert_test )")
ErtTest.cNamespace().get_enkf_main = cwrapper.prototype("enkf_main_ref ert_test_context_get_main( ert_test )")
github Ensembles / ert / python / python / ert / enkf / ecl_config.py View on Github external
_get_gridfile           = EnkfPrototype("char* ecl_config_get_gridfile(ecl_config)")
    _set_gridfile           = EnkfPrototype("void  ecl_config_set_grid(ecl_config, char*)")
    _validate_gridfile      = EnkfPrototype("ui_return_obj ecl_config_validate_grid(ecl_config, char*)")
    _get_grid               = EnkfPrototype("ecl_grid_ref ecl_config_get_grid(ecl_config)")
    _get_schedule_file      = EnkfPrototype("char* ecl_config_get_schedule_file(ecl_config)")
    _set_schedule_file      = EnkfPrototype("void  ecl_config_set_schedule_file(ecl_config, char*, char*)")
    _validate_schedule_file = EnkfPrototype("ui_return_obj ecl_config_validate_schedule_file(ecl_config, char*)")
    _get_sched_file         = EnkfPrototype("sched_file_ref ecl_config_get_sched_file(ecl_config)")
    _get_init_section       = EnkfPrototype("char* ecl_config_get_init_section(ecl_config)")
    _set_init_section       = EnkfPrototype("void  ecl_config_set_init_section(ecl_config, char*)")
    _validate_init_section  = EnkfPrototype("ui_return_obj ecl_config_validate_init_section(ecl_config, char*)")
    _get_refcase_name       = EnkfPrototype("char* ecl_config_get_refcase_name(ecl_config)")
    _get_refcase            = EnkfPrototype("ecl_sum_ref ecl_config_get_refcase(ecl_config)")
    _load_refcase           = EnkfPrototype("void  ecl_config_load_refcase(ecl_config, char*)")
    _validate_refcase       = EnkfPrototype("ui_return_obj ecl_config_validate_refcase(ecl_config, char*)")
    _has_refcase            = EnkfPrototype("bool  ecl_config_has_refcase(ecl_config)")
    _get_static_kw_list     = EnkfPrototype("stringlist_ref ecl_config_get_static_kw_list(ecl_config)")
    _clear_static_kw        = EnkfPrototype("void  ecl_config_clear_static_kw(ecl_config)")
    _add_static_kw          = EnkfPrototype("void  ecl_config_add_static_kw(ecl_config, char*)")
    _get_depth_unit         = EnkfPrototype("char* ecl_config_get_depth_unit(ecl_config)")
    _get_pressure_unit      = EnkfPrototype("char* ecl_config_get_pressure_unit(ecl_config)")

    def __init__(self):
        c_ptr = self._alloc()
        if c_ptr:
            super(EclConfig, self).__init__(c_ptr)
        else:
            raise RuntimeError('Internal error: Failed constructing EclConfig!')

    def free(self):
        self._free()
github OPM / ResInsight / ThirdParty / Ert / python / python / ert / enkf / site_config.py View on Github external
_get_rsh_command       = EnkfPrototype("char* site_config_get_rsh_command(site_config)")
    _set_rsh_command       = EnkfPrototype("void site_config_set_rsh_command(site_config, char*)")
    _get_max_running_rsh   = EnkfPrototype("int site_config_get_max_running_rsh(site_config)")
    _set_max_running_rsh   = EnkfPrototype("void site_config_set_max_running_rsh(site_config, int)")
    _get_rsh_host_list     = EnkfPrototype("integer_hash_ref site_config_get_rsh_host_list(site_config)")
    _clear_rsh_host_list   = EnkfPrototype("void site_config_clear_rsh_host_list(site_config)")
    _add_rsh_host          = EnkfPrototype("void site_config_add_rsh_host(site_config, char*, int)")
    _get_max_running_local = EnkfPrototype("int site_config_get_max_running_local(site_config)")
    _set_max_running_local = EnkfPrototype("void site_config_set_max_running_local(site_config, int)")
    _get_installed_jobs    = EnkfPrototype("ext_joblist_ref site_config_get_installed_jobs(site_config)")
    _get_max_submit        = EnkfPrototype("int site_config_get_max_submit(site_config)")
    _set_max_submit        = EnkfPrototype("void site_config_set_max_submit(site_config, int)")
    _get_license_root_path = EnkfPrototype("char* site_config_get_license_root_path(site_config)")
    _set_license_root_path = EnkfPrototype("void site_config_set_license_root_path(site_config, char*)")
    _get_job_script        = EnkfPrototype("char* site_config_get_job_script(site_config)")
    _set_job_script        = EnkfPrototype("void site_config_set_job_script(site_config, char*)")
    _get_env_hash          = EnkfPrototype("string_hash_ref site_config_get_env_hash(site_config)")
    _clear_env             = EnkfPrototype("void site_config_clear_env(site_config)")
    _setenv                = EnkfPrototype("void site_config_setenv(site_config, char*, char*)")
    _get_path_variables    = EnkfPrototype("stringlist_ref site_config_get_path_variables(site_config)")
    _get_path_values       = EnkfPrototype("stringlist_ref site_config_get_path_values(site_config)")
    _clear_pathvar         = EnkfPrototype("void site_config_clear_pathvar(site_config)")
    _update_pathvar        = EnkfPrototype("void site_config_update_pathvar(site_config, char*, char*)")
    _get_job_queue         = EnkfPrototype("job_queue_ref site_config_get_job_queue(site_config)")
    _queue_is_running      = EnkfPrototype("bool site_config_queue_is_running(site_config)")
    _get_location          = EnkfPrototype("char* site_config_get_location(site_config)")
    _has_driver            = EnkfPrototype("bool site_config_has_queue_driver(site_config, char*)")


    
    def __init__(self):
        raise NotImplementedError("Class can not be instantiated directly!")
github OPM / ResInsight / ThirdParty / Ert / devel / python / python / ert / ecl / ecl_sum.py View on Github external
_fread_alloc                   = EclPrototype("void*     ecl_sum_fread_alloc_case__( char* , char* , bool)" , bind = False )
    _create_writer                 = EclPrototype("ecl_sum_obj  ecl_sum_alloc_writer( char* , bool , bool , char* , time_t , bool , int , int , int)" , bind = False)
    _iiget                         = EclPrototype("double   ecl_sum_iget( ecl_sum , int , int)")
    _free                          = EclPrototype("void     ecl_sum_free( ecl_sum )")
    _data_length                   = EclPrototype("int      ecl_sum_get_data_length( ecl_sum )")
    _iget_sim_days                 = EclPrototype("double   ecl_sum_iget_sim_days( ecl_sum , int) ")
    _iget_report_step              = EclPrototype("int      ecl_sum_iget_report_step( ecl_sum , int) ")
    _iget_mini_step                = EclPrototype("int      ecl_sum_iget_mini_step( ecl_sum , int) ")
    _iget_sim_time                 = EclPrototype("time_t   ecl_sum_iget_sim_time( ecl_sum , int) ")
    _get_report_end                = EclPrototype("int      ecl_sum_iget_report_end( ecl_sum , int)")
    _get_general_var               = EclPrototype("double   ecl_sum_get_general_var( ecl_sum , int , char*)")
    _get_general_var_index         = EclPrototype("int      ecl_sum_get_general_var_params_index( ecl_sum , char*)")
    _get_general_var_from_sim_days = EclPrototype("double   ecl_sum_get_general_var_from_sim_days( ecl_sum , double , char*)")
    _get_general_var_from_sim_time = EclPrototype("double   ecl_sum_get_general_var_from_sim_time( ecl_sum , time_t , char*)")
    _get_first_gt                  = EclPrototype("int      ecl_sum_get_first_gt( ecl_sum , int , double )")
    _get_first_lt                  = EclPrototype("int      ecl_sum_get_first_lt( ecl_sum , int , double )")
    _get_start_date                = EclPrototype("time_t   ecl_sum_get_start_time( ecl_sum )")
    _get_end_date                  = EclPrototype("time_t   ecl_sum_get_end_time( ecl_sum )")
    _get_last_report_step          = EclPrototype("int      ecl_sum_get_last_report_step( ecl_sum )")
    _get_first_report_step         = EclPrototype("int      ecl_sum_get_first_report_step( ecl_sum )")
    _select_matching_keys          = EclPrototype("void     ecl_sum_select_matching_general_var_list( ecl_sum , char* , stringlist )")
    _has_key                       = EclPrototype("bool     ecl_sum_has_general_var( ecl_sum , char* )")
    _check_sim_time                = EclPrototype("bool     ecl_sum_check_sim_time( ecl_sum , time_t )")
    _check_sim_days                = EclPrototype("bool     ecl_sum_check_sim_days( ecl_sum , double )")
    _sim_length                    = EclPrototype("double   ecl_sum_get_sim_length( ecl_sum )")
    _get_first_day                 = EclPrototype("double   ecl_sum_get_first_day( ecl_sum )")
    _get_data_start                = EclPrototype("time_t   ecl_sum_get_data_start( ecl_sum )")
    _get_unit                      = EclPrototype("char*    ecl_sum_get_unit( ecl_sum , char*)")
    _get_simcase                   = EclPrototype("char*    ecl_sum_get_case( ecl_sum )")
    _get_base                      = EclPrototype("char*    ecl_sum_get_base( ecl_sum )")
    _get_path                      = EclPrototype("char*    ecl_sum_get_path( ecl_sum )")
    _get_abs_path                  = EclPrototype("char*    ecl_sum_get_abs_path( ecl_sum )")
github Ensembles / ert / devel / python / python / ert / util / version.py View on Github external
def cmp_method(method):
    def cmp_wrapper(self, other):
        if not isinstance(other, Version):
            other = Version(other[0], other[1], other[2])

        return method(self, other)

    return cmp_wrapper


class Version(object):
    _build_time = UtilPrototype("char* version_get_build_time()")
    _git_commit = UtilPrototype("char* version_get_git_commit()")
    _git_commit_short = UtilPrototype("char* version_get_git_commit_short()")
    _major_version = UtilPrototype("int version_get_major_ert_version()")
    _minor_version = UtilPrototype("int version_get_minor_ert_version()")
    _micro_version = UtilPrototype("char* version_get_micro_ert_version()")
    _is_devel = UtilPrototype("bool version_is_ert_devel_version()")

    def __init__(self, major, minor, micro):
        self.major = major
        self.minor = minor
        self.micro = micro
        try:
            self.micro_int = int(micro)
            self.is_devel = False
        except ValueError:
            self.micro_int = -1
            self.is_devel = True

    def isDevelVersion(self):
        return self.is_devel
github Ensembles / ert / devel / python / python / ert / enkf / model_config.py View on Github external
return ModelConfig.cNamespace().runpath_requires_iterations(self)

    def getJobnameFormat(self):
        """ @rtype: str """
        return ModelConfig.cNamespace().get_jobname_fmt(self)

    def getEnspath(self):
        """ @rtype: str """
        return ModelConfig.cNamespace().get_enspath(self)

    def getRunpathFormat(self):
        """ @rtype: PathFormat """
        return ModelConfig.cNamespace().get_runpath_fmt(self)


cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerObjectType("model_config", ModelConfig)

ModelConfig.cNamespace().free = cwrapper.prototype("void model_config_free( model_config )")
ModelConfig.cNamespace().get_forward_model = cwrapper.prototype("forward_model_ref model_config_get_forward_model(model_config)")
ModelConfig.cNamespace().get_max_internal_submit = cwrapper.prototype("int model_config_get_max_internal_submit(model_config)")
ModelConfig.cNamespace().set_max_internal_submit = cwrapper.prototype("void model_config_set_max_internal_submit(model_config, int)")
ModelConfig.cNamespace().get_case_table_file = cwrapper.prototype("char* model_config_get_case_table_file(model_config)")
ModelConfig.cNamespace().get_runpath_as_char = cwrapper.prototype("char* model_config_get_runpath_as_char(model_config)")
ModelConfig.cNamespace().select_runpath = cwrapper.prototype("bool model_config_select_runpath(model_config, char*)")
ModelConfig.cNamespace().set_runpath = cwrapper.prototype("void model_config_set_runpath(model_config, char*)")
ModelConfig.cNamespace().get_fs_type = cwrapper.prototype("enkf_fs_type_enum model_config_get_dbase_type(model_config)")

ModelConfig.cNamespace().get_history = cwrapper.prototype("history_ref model_config_get_history(model_config)")
ModelConfig.cNamespace().get_history_source = cwrapper.prototype("history_source_enum model_config_get_history_source(model_config)")
ModelConfig.cNamespace().select_history = cwrapper.prototype("bool model_config_select_history(model_config, history_source_enum, sched_file, ecl_sum)")
ModelConfig.cNamespace().has_history = cwrapper.prototype("bool model_config_has_history(model_config)")
github Ensembles / ert / devel / python / python / ert / job_queue / libjob_queue.py View on Github external
clib.load("libnsl.so.1")
    if LSF_LIBDIR:
        clib.load("%s/liblsf.so" % LSF_LIBDIR)
        clib.load("%s/libbat.so" % LSF_LIBDIR)
    else:
        clib.load( "liblsf.so" )
        clib.load( "libbat.so" )
    HAVE_LSF = True
except:
    HAVE_LSF = False


# 3: Loading the libjob_queue library, which might (depending on the
#    value of INCLUDE_LSF used when building) depend on the LSF
#    libraries we tried to load at the previous step.
clib.ert_load("libconfig.so" )
try:
    lib  = clib.ert_load("libjob_queue.so")
except:
    if HAVE_LSF == False:
        sys.stderr.write("** Failed to load the libjob_queue library, \n")
        sys.stderr.write("** have previosuly failed to load the LSF\n")
        sys.stderr.write("** libraries liblsf & libbat - that might be\n")
        sys.stderr.write("** the reason ... ")
        if LSF_LIBDIR:
            sys.stderr.write("** LSF_LIBDIR = %s\n" % LSF_LIBDIR)
        else:
            sys.stderr.write("** LSF_LIBDIR = \n")
    sys.exit("Failed to load library: libjob_queue")
github Ensembles / ert / devel / python / python / ert / ecl / ecl_grid.py View on Github external
The method create3D() does the inverse operation; creating a
        3D numpy object from an EclKW instance. If the argument @pack
        is true the resulting keyword will have length 'nactive',
        otherwise the element will have length nx*ny*nz.
        """
        if array.ndim == 3:
            dims = array.shape
            if dims[0] == self.getNX() and dims[1] == self.getNY() and dims[2] == self.getNZ():
                dtype = array.dtype
                if dtype == numpy.int32:
                    type = EclTypeEnum.ECL_INT_TYPE
                elif dtype == numpy.float32:
                    type = EclTypeEnum.ECL_FLOAT_TYPE
                elif dtype == numpy.float64:
                    type = EclTypeEnum.ECL_DOUBLE_TYPE
                else:
                    sys.exit("Do not know how to create ecl_kw from type:%s" % dtype)
  
                if pack:
                    size = self.getNumActive()
                else:
                    size = self.getGlobalSize()
                    
                if len(kw_name) > 8:
                    # Silently truncate to length 8 - ECLIPSE has it's challenges.
                    kw_name = kw_name[0:8]  

                kw = EclKW( kw_name , size , type )
                active_index = 0
                global_index = 0
                for k in range( self.nz ):
github OPM / ResInsight / ThirdParty / Ert / devel / python / python / ert / ecl / ecl_grid.py View on Github external
"""
        Creates an EclKW instance based on existing 3D numpy object.

        The method create3D() does the inverse operation; creating a
        3D numpy object from an EclKW instance. If the argument @pack
        is true the resulting keyword will have length 'nactive',
        otherwise the element will have length nx*ny*nz.
        """
        if array.ndim == 3:
            dims = array.shape
            if dims[0] == self.getNX() and dims[1] == self.getNY() and dims[2] == self.getNZ():
                dtype = array.dtype
                if dtype == numpy.int32:
                    type = EclTypeEnum.ECL_INT_TYPE
                elif dtype == numpy.float32:
                    type = EclTypeEnum.ECL_FLOAT_TYPE
                elif dtype == numpy.float64:
                    type = EclTypeEnum.ECL_DOUBLE_TYPE
                else:
                    sys.exit("Do not know how to create ecl_kw from type:%s" % dtype)
  
                if pack:
                    size = self.getNumActive()
                else:
                    size = self.getGlobalSize()
                    
                if len(kw_name) > 8:
                    # Silently truncate to length 8 - ECLIPSE has it's challenges.
                    kw_name = kw_name[0:8]  

                kw = EclKW( kw_name , size , type )
                active_index = 0
github Ensembles / ert / devel / python / python / ert / util / stat.py View on Github external
def polyfit(n, x, y, s=None):
    """
    @type n: int
    @type x: Matrix or Sequence
    @type y: Matrix or Sequence
    @type s: Matrix or Sequence or None
    @return: tuple
    """
    if _polyfit is None:
        raise NotImplementedError("Sorry - your ert distribution has been built without lapack support")

    if isinstance(x, Matrix):
        xm = x
    else:
        xm = Matrix(len(x), 1)
        for i in range(len(x)):
            xm[i, 0] = x[i]

    if isinstance(y, Matrix):
        ym = y
    else:
        ym = Matrix(len(y), 1)
        for i in range(len(y)):
            ym[i, 0] = y[i]

    if s:
        if isinstance(s, Matrix):
            sm = s