class QueueConfig(BaseCClass): TYPE_NAME = "queue_config" _free = EnkfPrototype("void queue_config_free( queue_config )") _alloc_job_queue = EnkfPrototype( "job_queue_obj queue_config_alloc_job_queue( queue_config )") _alloc = EnkfPrototype("void* queue_config_alloc()", bind=False) _alloc_local_copy = EnkfPrototype( "queue_config_obj queue_config_alloc_local_copy( queue_config )") _has_job_script = EnkfPrototype( "bool queue_config_has_job_script( queue_config )") def __init__(self): c_ptr = self._alloc() super(QueueConfig, self).__init__(c_ptr) def create_job_queue(self): return self._alloc_job_queue() def create_local_copy(self): return self._alloc_local_copy() def has_job_script(self): return self._has_job_script() def free(self): self._free()
class RunArg(BaseCClass): TYPE_NAME = "run_arg" _alloc_ENSEMBLE_EXPERIMENT = EnkfPrototype( "run_arg_obj run_arg_alloc_ENSEMBLE_EXPERIMENT(char*, enkf_fs, int, int, char*)", bind=False) _free = EnkfPrototype("void run_arg_free(run_arg)") _get_queue_index = EnkfPrototype("int run_arg_get_queue_index(run_arg)") _is_submitted = EnkfPrototype("bool run_arg_is_submitted(run_arg)") _get_run_id = EnkfPrototype("char* run_arg_get_run_id(run_arg)") def __init__(self): raise NotImplementedError("Cannot instantiat RunArg directly!") @classmethod def createEnsembleExperimentRunArg(cls, run_id, fs, iens, runpath, iter=0): return cls._alloc_ENSEMBLE_EXPERIMENT(run_id, fs, iens, iter, runpath) def free(self): self._free() def getQueueIndex(self): return self._get_queue_index() def isSubmitted(self): return self._is_submitted() def __repr__(self): su = 'submitted' if self.isSubmitted() else 'not submitted' qi = self.getQueueIndex() return 'RunArg(queue_index = %d, %s) %s' % (qi, su, self._ad_str()) def get_run_id(self): return self._get_run_id()
class ForwardLoadContext(BaseCClass): TYPE_NAME = "forward_load_context" _alloc = EnkfPrototype( "void* forward_load_context_alloc( run_arg , bool , ecl_config , char* , stringlist )", bind=False) _select_step = EnkfPrototype( "void forward_load_context_select_step( forward_load_context , int )") _get_step = EnkfPrototype( "int forward_load_context_get_load_step( forward_load_context)") _free = EnkfPrototype( "void forward_load_context_free( forward_load_context)") def __init__(self, run_arg=None, load_summary=False, ecl_config=None, ecl_base=None, messages=None, report_step=None): c_ptr = self._alloc(run_arg, load_summary, ecl_config, ecl_base, messages) super(ForwardLoadContext, self).__init__(c_ptr) if not report_step is None: self.selectStep(report_step) def getLoadStep(self): return self._get_step() def selectStep(self, report_step): self._select_step(report_step) def free(self): self._free()
class EnsemblePlotDataVector(BaseCClass): TYPE_NAME = "ensemble_plot_data_vector" _size = EnkfPrototype( "int enkf_plot_tvector_size(ensemble_plot_data_vector)") _get_value = EnkfPrototype( "double enkf_plot_tvector_iget_value(ensemble_plot_data_vector, int)") _get_time = EnkfPrototype( "time_t enkf_plot_tvector_iget_time(ensemble_plot_data_vector, int)") _is_active = EnkfPrototype( "bool enkf_plot_tvector_iget_active(ensemble_plot_data_vector, int)") def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def __len__(self): """ @rtype: int """ return self._size() def getValue(self, index): """ @rtype: float """ return self._get_value(index) def getTime(self, index): """ @rtype: CTime """ return self._get_time(index) def isActive(self, index): """ @rtype: bool """ return self._is_active(index) def __repr__(self): return 'EnsemblePlotDataVector(size = %d) %s' % (len(self), self._ad_str())
class RNGConfig(BaseCClass): TYPE_NAME = "rng_config" _rng_alg_type = EnkfPrototype( "rng_alg_type_enum rng_config_get_type(rng_config)") _load_file = EnkfPrototype( "char* rng_config_get_seed_load_file(rng_config)") _store_file = EnkfPrototype( "char* rng_config_get_seed_store_file(rng_config)") def __init__(self, user_config_file): raise NotImplementedError("RNGConfig does not support " "initialization from Python.") @property def alg_type(self): return self._rng_alg_type() @property def load_filename(self): return self._load_file() @property def store_filename(self): return self._store_file()
class EnsemblePlotGenKWVector(BaseCClass): TYPE_NAME = "ensemble_plot_gen_kw_vector" _size = EnkfPrototype("int enkf_plot_gen_kw_vector_get_size(ensemble_plot_gen_kw_vector)") _get_value = EnkfPrototype("double enkf_plot_gen_kw_vector_iget(ensemble_plot_gen_kw_vector, int)") def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def __len__(self): """ @rtype: int """ return self._size() def getValue(self, index): """ @rtype: float """ return self[index] def __iter__(self): cur = 0 while cur < len(self): yield self[cur] cur += 1 def __getitem__(self, index): """ @rtype: float """ return self._get_value(index) def __repr__(self): return 'EnsemblePlotGenKWVector(size = %d) %s' % (len(self), self._ad_str())
class EnkfSimulationRunner(BaseCClass): TYPE_NAME = "enkf_simulation_runner" _create_run_path = EnkfPrototype( "bool enkf_main_create_run_path(enkf_simulation_runner, ert_run_context)" ) _run_simple_step = EnkfPrototype( "int enkf_main_run_simple_step(enkf_simulation_runner, job_queue, ert_run_context)" ) def __init__(self, enkf_main): assert isinstance(enkf_main, BaseCClass) super(EnkfSimulationRunner, self).__init__(enkf_main.from_param(enkf_main).value, parent=enkf_main, is_reference=True) self.ert = enkf_main """:type: res.enkf.EnKFMain """ def runSimpleStep(self, job_queue, run_context): """ @rtype: int """ return self._run_simple_step(job_queue, run_context) def createRunPath(self, run_context): """ @rtype: bool """ return self._create_run_path(run_context) def runEnsembleExperiment(self, job_queue, run_context): """ @rtype: int """ return self.runSimpleStep(job_queue, run_context) def runWorkflows(self, runtime): """:type res.enkf.enum.HookRuntimeEnum""" hook_manager = self.ert.getHookManager() hook_manager.runWorkflows(runtime, self.ert)
class ErtTemplates(BaseCClass): TYPE_NAME = "ert_templates" _free = EnkfPrototype("void ert_templates_free( ert_templates )") _alloc_list = EnkfPrototype( "stringlist_ref ert_templates_alloc_list(ert_templates)") _get_template = EnkfPrototype( "ert_template_ref ert_templates_get_template(ert_templates, char*)") _clear = EnkfPrototype("void ert_templates_clear(ert_templates)") _add_template = EnkfPrototype( "ert_template_ref ert_templates_add_template(ert_templates, char*, char*, char*, char*)" ) def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def getTemplateNames(self): """ @rtype: StringList """ return self._alloc_list().setParent(self) def clear(self): self._clear() def get_template(self, key): """ @rtype: ErtTemplate """ return self._get_template(key).setParent(self) def add_template(self, key, template_file, target_file, arg_string): """ @rtype: ErtTemplate """ return self._add_template(key, template_file, target_file, arg_string).setParent(self) def free(self): self._free()
class EnKFState(BaseCClass): TYPE_NAME = "enkf_state" _free = EnkfPrototype("void* enkf_state_free( enkf_state )") _get_ens_config = EnkfPrototype( "ens_config_ref enkf_state_get_ensemble_config( enkf_state )") _initialize = EnkfPrototype( "void enkf_state_initialize( enkf_state , enkf_fs , stringlist , enkf_init_mode_enum)" ) def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def free(self): self._free() def ensembleConfig(self): """ @rtype: EnsembleConfig """ return self._get_ens_config() def initialize(self, fs, param_list=None, init_mode=EnkfInitModeEnum.INIT_CONDITIONAL): if param_list is None: ens_config = self.ensembleConfig() param_list = ens_config.getKeylistFromVarType( EnkfVarType.PARAMETER) self._initialize(fs, param_list, init_mode)
class Field(BaseCClass): TYPE_NAME = "field" _free = EnkfPrototype("void field_free( field )") _ijk_get_double = EnkfPrototype( "double field_ijk_get_double(field, int, int, int)") _export = EnkfPrototype( "void field_export(field, char* , fortio , enkf_field_file_format_enum , bool , char*)" ) def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def ijk_get_double(self, i, j, k): return self._ijk_get_double(i, j, k) def export(self, filename, file_type=None, init_file=None): output_transform = False if file_type is None: try: file_type = FieldConfig.exportFormat(filename) except ValueError: sys.stderr.write( "Sorry - could not infer output format from filename:%s\n" % filename) return False self._export(filename, None, file_type, output_transform, init_file) return True def free(self): self._free()
class ErtTemplate(BaseCClass): TYPE_NAME = "ert_template" _free = EnkfPrototype("void ert_template_free( ert_template )") _get_template_file = EnkfPrototype( "char* ert_template_get_template_file(ert_template)") _get_target_file = EnkfPrototype( "char* ert_template_get_target_file(ert_template)") _get_args_as_string = EnkfPrototype( "char* ert_template_get_args_as_string(ert_template)") def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def get_template_file(self): """ @rtype: str """ return self._get_template_file() def get_target_file(self): """ @rtype: str """ return self._get_target_file() def get_args_as_string(self): """ @rtype: str """ return self._get_args_as_string() def free(self): self._free()
class HookManager(BaseCClass): TYPE_NAME = "hook_manager" _get_runpath_list_file = EnkfPrototype( "char* hook_manager_get_runpath_list_file(hook_manager)") _get_runpath_list = EnkfPrototype( "runpath_list_ref hook_manager_get_runpath_list(hook_manager)") _iget_hook_workflow = EnkfPrototype( "hook_workflow_ref hook_manager_iget_hook_workflow(hook_manager, int)") _size = EnkfPrototype("int hook_manager_get_size(hook_manager)") def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def __len__(self): """ @rtype: int """ return self._size() def __repr__(self): return 'HookManager(size = %d) %s' % (len(self), self._ad_str()) def __getitem__(self, index): """ @rtype: Hook workflow """ assert isinstance(index, int) if index < 0: index += len(self) if 0 <= index < len(self): return self._iget_hook_workflow(index) else: raise IndexError("Invalid index. Valid range: [0, %d)." % len(self)) def checkRunpathListFile(self): """ @rtype: bool """ runpath_list_file = self._get_runpath_list_file() if not os.path.exists(runpath_list_file): sys.stderr.write( "** Warning: the file: %s with a list of runpath directories was not found - hook workflow will probably fail.\n" % runpath_list_file) def getRunpathList(self): """ @rtype: RunpathList """ return self._get_runpath_list() def runWorkflows(self, run_time, ert_self): workflow_list = ert_self.getWorkflowList() for hook_workflow in self: if (hook_workflow.getRunMode() is not run_time): continue workflow = hook_workflow.getWorkflow() workflow.run(ert_self, context=workflow_list.getContext())
class EnsemblePlotData(BaseCClass): TYPE_NAME = "ensemble_plot_data" _alloc = EnkfPrototype("void* enkf_plot_data_alloc(enkf_config_node)", bind=False) _load = EnkfPrototype( "void enkf_plot_data_load(ensemble_plot_data, enkf_fs, char*, bool_vector)" ) _size = EnkfPrototype("int enkf_plot_data_get_size(ensemble_plot_data)") _get = EnkfPrototype( "ensemble_plot_data_vector_ref enkf_plot_data_iget(ensemble_plot_data, int)" ) _free = EnkfPrototype("void enkf_plot_data_free(ensemble_plot_data)") def __init__(self, ensemble_config_node, file_system=None, user_index=None, input_mask=None): assert isinstance(ensemble_config_node, EnkfConfigNode) c_pointer = self._alloc(ensemble_config_node) super(EnsemblePlotData, self).__init__(c_pointer) if not file_system is None: self.load(file_system, user_index, input_mask) def load(self, file_system, user_index=None, input_mask=None): assert isinstance(file_system, EnkfFs) if not input_mask is None: assert isinstance(input_mask, BoolVector) self._load(file_system, user_index, input_mask) def __len__(self): """ @rtype: int """ return self._size() def __getitem__(self, index): """ @rtype: EnsemblePlotDataVector """ return self._get(index) def __iter__(self): cur = 0 while cur < len(self): yield self[cur] cur += 1 def free(self): self._free() def __repr__(self): return 'EnsemblePlotData(size = %d) %s' % (len(self), self._ad_str())
class LocalObsdataNode(BaseCClass): TYPE_NAME = "local_obsdata_node" _alloc = EnkfPrototype("void* local_obsdata_node_alloc(char* , bool)", bind = False) _free = EnkfPrototype("void local_obsdata_node_free(local_obsdata_node)") _get_key = EnkfPrototype("char* local_obsdata_node_get_key(local_obsdata_node)") _add_range = EnkfPrototype("void local_obsdata_node_add_range(local_obsdata_node, int, int)") _add_step = EnkfPrototype("void local_obsdata_node_add_tstep(local_obsdata_node, int)") _tstep_active = EnkfPrototype("bool local_obsdata_node_tstep_active(local_obsdata_node, int)") _all_timestep_active = EnkfPrototype("bool local_obsdata_node_all_timestep_active(local_obsdata_node)") _set_all_timestep_active = EnkfPrototype("void local_obsdata_node_set_all_timestep_active(local_obsdata_node, bool)") _get_active_list = EnkfPrototype("active_list_ref local_obsdata_node_get_active_list(local_obsdata_node)") def __init__(self, obs_key , all_timestep_active = True): if isinstance(obs_key, str): c_ptr = self._alloc(obs_key , all_timestep_active) if c_ptr: super(LocalObsdataNode, self).__init__(c_ptr) else: raise ArgumentError('Unable to construct LocalObsdataNode with key = "%s".' % obs_key) else: raise TypeError('LocalObsdataNode needs string, not %s.' % str(type(obs_key))) def key(self): return self._get_key() def getKey(self): return self.key() def addRange(self, step_1, step_2): assert isinstance(step_1, int) assert isinstance(step_2, int) self._add_range(step_1, step_2) def addTimeStep(self , step): self._add_step( step ) def free(self): self._free() def __repr__(self): return 'LocalObsdataNode(key = %s) %s' % (self.key(), self._ad_str()) def tstepActive(self , tstep): return self._tstep_active(tstep) def getActiveList(self): return self._get_active_list() def allTimeStepActive(self): return self._all_timestep_active() def setAllTimeStepActive(self, flag): return self._set_all_timestep_active( flag )
class ESUpdate(BaseCClass): TYPE_NAME = "es_update" _smoother_update = EnkfPrototype( "bool enkf_main_smoother_update(es_update, enkf_fs, enkf_fs)") def __init__(self, ert): assert isinstance(ert, BaseCClass) super(ESUpdate, self).__init__(ert.from_param(ert).value, parent=ert, is_reference=True) self.ert = ert self.analysis_config = self.ert.analysisConfig() def hasModule(self, name): """ Will check if we have analysis module @name. """ return self.analysis_config.hasModule(name) def getModule(self, name): if self.hasModule(name): self.analysis_config.getModule(name) else: raise KeyError("No such module:%s " % name) def setGlobalStdScaling(self, weight): self.analysis_config.setGlobalStdScaling(weight) def smootherUpdate(self, run_context): data_fs = run_context.get_result_fs() target_fs = run_context.get_target_fs() return self._smoother_update(data_fs, target_fs)
class EnkfSimulationRunner(BaseCClass): TYPE_NAME = "enkf_simulation_runner" _create_run_path = EnkfPrototype( "bool enkf_main_create_run_path(enkf_simulation_runner, bool_vector, int)" ) _run_simple_step = EnkfPrototype( "int enkf_main_run_simple_step(enkf_simulation_runner, job_queue, bool_vector, enkf_init_mode_enum, int)" ) def __init__(self, enkf_main): assert isinstance(enkf_main, BaseCClass) super(EnkfSimulationRunner, self).__init__(enkf_main.from_param(enkf_main).value, parent=enkf_main, is_reference=True) self.ert = enkf_main """:type: res.enkf.EnKFMain """ def runSimpleStep(self, job_queue, active_realization_mask, initialization_mode, iter_nr): """ @rtype: int """ assert isinstance(active_realization_mask, BoolVector) assert isinstance(initialization_mode, EnkfInitModeEnum) return self._run_simple_step(job_queue, active_realization_mask, initialization_mode, iter_nr) def createRunPath(self, active_realization_mask, iter_nr): """ @rtype: bool """ assert isinstance(active_realization_mask, BoolVector) return self._create_run_path(active_realization_mask, iter_nr) def runEnsembleExperiment(self, job_queue, active_realization_mask=None): """ @rtype: int """ if active_realization_mask is None: count = self.ert.getEnsembleSize() active_realization_mask = BoolVector(default_value=True, initial_size=count) iter_nr = 0 return self.runSimpleStep(job_queue, active_realization_mask, EnkfInitModeEnum.INIT_CONDITIONAL, iter_nr) def runWorkflows(self, runtime): """:type res.enkf.enum.HookRuntimeEnum""" hook_manager = self.ert.getHookManager() hook_manager.runWorkflows(runtime, self.ert)
class QueueConfig(BaseCClass): TYPE_NAME = "queue_config" _free = EnkfPrototype("void queue_config_free( queue_config )") _alloc_job_queue = EnkfPrototype( "job_queue_obj queue_config_alloc_job_queue( queue_config )") _alloc = EnkfPrototype("void* queue_config_alloc_load(char*)", bind=False) _alloc_local_copy = EnkfPrototype( "queue_config_obj queue_config_alloc_local_copy( queue_config )") _has_job_script = EnkfPrototype( "bool queue_config_has_job_script( queue_config )") _get_job_script = EnkfPrototype( "char* queue_config_get_job_script(queue_config)") _max_submit = EnkfPrototype( "int queue_config_get_max_submit(queue_config)") _queue_name = EnkfPrototype( "char* queue_config_get_queue_name(queue_config)") _queue_driver = EnkfPrototype( "driver_ref queue_config_get_queue_driver(queue_config, char*)") def __init__(self, user_config_file=None): c_ptr = self._alloc(user_config_file) super(QueueConfig, self).__init__(c_ptr) def create_job_queue(self): return self._alloc_job_queue() def create_local_copy(self): return self._alloc_local_copy() def has_job_script(self): return self._has_job_script() def free(self): self._free() @property def max_submit(self): return self._max_submit() @property def queue_name(self): return self._queue_name() @property def driver(self): return self._queue_driver(self.queue_name).setParent(self) @property def job_script(self): return self._get_job_script()
class HookWorkflow(BaseCClass): TYPE_NAME = "hook_workflow" _get_workflow = EnkfPrototype( "workflow_ref hook_workflow_get_workflow(hook_workflow)") _get_runmode = EnkfPrototype( "hook_runtime_enum hook_workflow_get_run_mode(hook_workflow)") def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def getWorkflow(self): """ @rtype: Workflow """ return self._get_workflow() def getRunMode(self): return self._get_runmode()
class SummaryKeySet(BaseCClass): TYPE_NAME = "summary_key_set" _alloc = EnkfPrototype("void* summary_key_set_alloc()", bind=False) _alloc_from_file = EnkfPrototype( "void* summary_key_set_alloc_from_file(char*, bool)", bind=False) _free = EnkfPrototype("void summary_key_set_free(summary_key_set)") _size = EnkfPrototype("int summary_key_set_get_size(summary_key_set)") _add_key = EnkfPrototype( "bool summary_key_set_add_summary_key(summary_key_set, char*)") _has_key = EnkfPrototype( "bool summary_key_set_has_summary_key(summary_key_set, char*)") _keys = EnkfPrototype( "stringlist_obj summary_key_set_alloc_keys(summary_key_set)") _is_read_only = EnkfPrototype( "bool summary_key_set_is_read_only(summary_key_set)") _fwrite = EnkfPrototype( "void summary_key_set_fwrite(summary_key_set, char*)") def __init__(self, filename=None, read_only=False): if filename is None: c_ptr = self._alloc() else: c_ptr = self._alloc_from_file(filename, read_only) super(SummaryKeySet, self).__init__(c_ptr) def addSummaryKey(self, key): assert isinstance(key, str) return self._add_key(key) def __len__(self): return self._size() def __contains__(self, key): return self._has_key(key) def keys(self): """ @rtype: StringList """ return self._keys() def isReadOnly(self): """ @rtype: bool """ return self._is_read_only() def writeToFile(self, filename): assert isinstance(filename, str) self._fwrite(filename) def free(self): self._free()
class ErtLog(object): _init = EnkfPrototype("void ert_log_init_log(int, char*, bool)", bind=False) _write_log = EnkfPrototype("void ert_log_add_message_py(int, char*)", bind=False) _get_filename = EnkfPrototype("char* ert_log_get_filename()", bind=False) @classmethod def init(cls, log_level, log_filename, verbose): cls._init(log_level, log_filename, verbose) @classmethod def log(cls, log_level, message): cls._write_log(log_level, message) @classmethod def getFilename(cls): """ @rtype: string """ return cls._get_filename()
class QueueConfig(BaseCClass): TYPE_NAME = "queue_config" _free = EnkfPrototype("void queue_config_free( queue_config )") _alloc_job_queue = EnkfPrototype("job_queue_obj queue_config_alloc_job_queue( queue_config )") _alloc = EnkfPrototype("void* queue_config_alloc()" , bind = False) def __init__(self): c_ptr = self._alloc() super(QueueConfig, self).__init__(c_ptr) def alloc_job_queue(self): return self._alloc_job_queue() def free(self): self._free()
class ObsBlock(BaseCClass): TYPE_NAME = "obs_block" _alloc = EnkfPrototype("void* obs_block_alloc(char*, int, matrix, bool, double)", bind = False) _free = EnkfPrototype("void obs_block_free(obs_block)") _total_size = EnkfPrototype("int obs_block_get_size( obs_block )") _active_size = EnkfPrototype("int obs_block_get_active_size( obs_block )") _iset = EnkfPrototype("void obs_block_iset( obs_block , int , double , double)") _iget_value = EnkfPrototype("double obs_block_iget_value( obs_block , int)") _iget_std = EnkfPrototype("double obs_block_iget_std( obs_block , int)") def __init__(self , obs_key , obs_size , global_std_scaling=1.0): error_covar = None error_covar_owner = False c_pointer = self._alloc(obs_key , obs_size , error_covar , error_covar_owner, global_std_scaling) super(ObsBlock, self).__init__(c_pointer) def totalSize(self): return self._total_size() def activeSize(self): return self.active() def active(self): return self._active_size() def __len__(self): """Returns the total size""" return self.totalSize() def __setitem__(self , index , value): if len(value) != 2: raise TypeError("The value argument must be a two element tuple: (value , std)") d, std = value if isinstance(index , int): if index < 0: index += len(self) if 0 <= index < len(self): self._iset(index, d, std) else: raise IndexError("Invalid index: %d. Valid range: [0,%d)" % (index , len(self))) else: raise TypeError("The index item must be integer, not %s." % str(type(index))) def __getitem__(self , index): if isinstance(index , int): if index < 0: index += len(self) if 0 <= index < len(self): value = self._iget_value(index) std = self._iget_std(index) return (value,std) else: raise IndexError("Invalid index:%d - valid range: [0,%d)" % (index , len(self))) else: raise TypeError("The index item must be integer, not %s." % str(type(index))) def free(self): self._free()
class EnKFState(BaseCClass): TYPE_NAME = "enkf_state" _free = EnkfPrototype("void* enkf_state_free( enkf_state )") _add_subst_kw = EnkfPrototype("void enkf_state_add_subst_kw( enkf_state , char* , char* , char*)") _get_subst_list = EnkfPrototype("subst_list_ref enkf_state_get_subst_list( enkf_state )") _get_ens_config = EnkfPrototype("ens_config_ref enkf_state_get_ensemble_config( enkf_state )") _initialize = EnkfPrototype("void enkf_state_initialize( enkf_state , enkf_fs , stringlist , enkf_init_mode_enum)") def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def free(self): self._free( ) def addSubstKeyword(self , key , value): """ Will add a key -> value pair which can be used for search replace operations in the data file. Observe that the key will be surrounded by \'<\' and \'>\'. """ doc_string = None if isinstance(value , str): self._add_subst_kw( key , value , doc_string ) else: raise TypeError("The value argument must be a string") def getDataKW(self): """ Will return the substitution map for this realisation. """ return self._get_subst_list( ) def ensembleConfig(self): """ @rtype: EnsembleConfig """ return self._get_ens_config( ) def initialize( self , fs , param_list = None , init_mode = EnkfInitModeEnum.INIT_CONDITIONAL): if param_list is None: ens_config = self.ensembleConfig( ) param_list = ens_config.getKeylistFromVarType( EnkfVarType.PARAMETER ) self._initialize( fs , param_list , init_mode )
class ResConfig(BaseCClass): TYPE_NAME = "res_config" _alloc = EnkfPrototype("void* res_config_alloc_load(char*)", bind=False) _free = EnkfPrototype("void res_config_free(res_config)") _user_config_file = EnkfPrototype( "char* res_config_get_user_config_file(res_config)") _config_path = EnkfPrototype( "char* res_config_get_working_directory(res_config)") _site_config = EnkfPrototype( "site_config_ref res_config_get_site_config(res_config)") _analysis_config = EnkfPrototype( "analysis_config_ref res_config_get_analysis_config(res_config)") _subst_config = EnkfPrototype( "subst_config_ref res_config_get_subst_config(res_config)") def __init__(self, user_config_file): if user_config_file is not None and not isfile(user_config_file): raise IOError('No such configuration file "%s".' % user_config_file) c_ptr = self._alloc(user_config_file) if c_ptr: super(ResConfig, self).__init__(c_ptr) else: raise ValueError( 'Failed to construct EnkfConfig instance from config file %s.' % user_config_file) def free(self): self._free() @property def user_config_file(self): return self._user_config_file() @property def site_config_file(self): return self.site_config.config_file @property def site_config(self): return self._site_config() @property def analysis_config(self): return self._analysis_config() @property def config_path(self): return self._config_path() @property def subst_config(self): return self._subst_config()
class ActiveList(BaseCClass): TYPE_NAME = "active_list" _alloc = EnkfPrototype("void* active_list_alloc()", bind=False) _free = EnkfPrototype("void active_list_free(active_list)") _add_index = EnkfPrototype( "void active_list_add_index(active_list , int)") _asize = EnkfPrototype( "int active_list_get_active_size(active_list, int)") _get_mode = EnkfPrototype( "active_mode_enum active_list_get_mode(active_list)") def __init__(self): c_ptr = self._alloc() super(ActiveList, self).__init__(c_ptr) def getMode(self): return self._get_mode() def addActiveIndex(self, index): self._add_index(index) def getActiveSize(self, default_value): """In mode PARTLY_ACTIVE, we return the size of the active set; In mode INACTIVE 0 is returned and if the mode is ALL_ACTIVE, the input default_value is returned. """ mode = self.getMode() if mode == ActiveMode.PARTLY_ACTIVE: return self._asize(0) if mode == ActiveMode.INACTIVE: return 0 return default_value def free(self): self._free() def __repr__(self): size = '' if self.getMode() == ActiveMode.PARTLY_ACTIVE: size = ', active_size = %d' % self._asize(0) cnt = 'mode = %s%s' % (self.getMode(), size) return self._create_repr(cnt)
class ExtParamConfig(BaseCClass): TYPE_NAME = "ext_param_config" _alloc = EnkfPrototype( "void* ext_param_config_alloc( char*, stringlist )", bind=False) _size = EnkfPrototype( "int ext_param_config_get_data_size( ext_param_config )") _iget_key = EnkfPrototype( "char* ext_param_config_iget_key( ext_param_config , int)") _free = EnkfPrototype("void ext_param_config_free( ext_param_config )") _has_key = EnkfPrototype( "bool ext_param_config_has_key( ext_param_config , char* )") def __init__(self, key, input_keys): keys = StringList(initial=input_keys) c_ptr = self._alloc(key, keys) super(ExtParamConfig, self).__init__(c_ptr) def __len__(self): return self._size() def __contains__(self, key): return self._has_key(key) def __getitem__(self, index): if index < 0: index += len(self) if index >= len(self): raise IndexError("Invalid index:%d" % index) return self._iget_key(index) def keys(self): index = 0 while index < len(self): yield self[index] index += 1 def free(self): self._free()
class PcaPlotVector(BaseCClass): TYPE_NAME = "pca_plot_vector" _alloc = EnkfPrototype("void* pca_plot_vector_alloc(int, matrix, matrix)", bind=False) _size = EnkfPrototype("int pca_plot_vector_get_size(pca_plot_vector)") _get = EnkfPrototype( "double pca_plot_vector_iget_sim_value(pca_plot_vector, int)") _get_obs = EnkfPrototype( "double pca_plot_vector_get_obs_value(pca_plot_vector)") _get_singular_value = EnkfPrototype( "double pca_plot_vector_get_singular_value(pca_plot_vector)") _free = EnkfPrototype("void pca_plot_vector_free(pca_plot_vector)") def __init__(self, component, principal_component_matrix, observation_principal_component_matrix): assert isinstance(component, int) assert isinstance(principal_component_matrix, Matrix) assert isinstance(observation_principal_component_matrix, Matrix) c_pointer = self._alloc(component, principal_component_matrix, observation_principal_component_matrix) super(PcaPlotVector, self).__init__(c_pointer) def __len__(self): """ @rtype: int """ return self._size() def __getitem__(self, index): """ @type index: int @rtype: float """ assert isinstance(index, int) return self._get(index) def __iter__(self): cur = 0 while cur < len(self): yield self[cur] cur += 1 def getObservation(self): """ @rtype: float """ return self._get_obs() def getSingularValue(self): """ @rtype: float """ return self._get_singular_value() def free(self): self._free() def __repr__(self): si = len(self) ob = self.getObservation() sv = self.getSingularValue() ad = self._ad_str() fmt = 'PcaPlotVector(size = %d, observation = %f, singular = %f) %s' return fmt % (si, ob, sv, ad)
class GenData(BaseCClass): TYPE_NAME = "gen_data" _alloc = EnkfPrototype("void* gen_data_alloc()", bind=False) _free = EnkfPrototype("void gen_data_free(gen_data)") _size = EnkfPrototype("int gen_data_get_size(gen_data)") _iget = EnkfPrototype("double gen_data_iget_double(gen_data , int)") _export = EnkfPrototype( "void gen_data_export(gen_data , char*, gen_data_file_format_type, fortio)" ) _export_data = EnkfPrototype( "void gen_data_export_data(gen_data , double_vector)") def __init__(self): c_ptr = self._alloc() if c_ptr: super(GenData, self).__init__(c_ptr) else: raise ValueError('Unable to construct GenData object.') def __len__(self): """ @rtype: int """ return self._size() def free(self): self._free() def __repr__(self): return 'GenData(len = %d) %s' % (len(self), self._ad_str()) def export(self, file_name, file_format_type, fortio): """ @type: str @type: GenDataFileType @type: FortIO """ self._export(file_name, file_format_type, fortio) def getData(self): data = DoubleVector() self._export_data(data) return data def __getitem__(self, idx): """Returns an item, or a list if idx is a slice. Note: When idx is a slice it does not return a new GenData! """ ls = len(self) if isinstance(idx, int): if idx < 0: idx += ls if 0 <= idx < ls: return self._iget(idx) raise IndexError('List index out of range.') if isinstance(idx, slice): vec = self.getData() return [vec[i] for i in range(*idx.indices(ls))] raise TypeError('List indices must be integers, not %s.' % str(type(idx)))
class LogConfig(BaseCClass): TYPE_NAME = "log_config" _alloc = EnkfPrototype("void* log_config_alloc_load(char*)", bind=False) _free = EnkfPrototype("void log_config_free(log_config)") _log_file = EnkfPrototype("char* log_config_get_log_file(log_config)") _log_level = EnkfPrototype( "message_level_enum log_config_get_log_level(log_config)") def __init__(self, user_config_file): if user_config_file is not None and not isfile(user_config_file): raise IOError('No such configuration file "%s".' % user_config_file) c_ptr = self._alloc(user_config_file) if c_ptr: super(LogConfig, self).__init__(c_ptr) else: raise ValueError( 'Failed to construct LogConfig instance from config file %s.' % user_config_file) def __repr__(self): return "LogConfig(log_file=%s, log_level=%r)" % (self.log_file, self.log_level) def free(self): self._free() @property def log_file(self): return self._log_file() @property def log_level(self): return self._log_level()
class PlotSettings(ConfigSettings): TYPE_NAME = "plot_settings" _init = EnkfPrototype("void plot_settings_init(plot_settings)") def __init__(self): super(PlotSettings, self).__init__("PLOT_SETTING") self._init() def getPath(self): """ @rtype: str """ return self["PATH"] def setPath(self, path): self["PATH"] = path