def completeFIELD(self, text, line, begidx, endidx): arguments = splitArguments(line) if len(arguments) > 2 or len(arguments) == 2 and not text: return [] return autoCompleteList(text, self.supportedFIELDKeys())
def exportFIELD(self, line): arguments = splitArguments(line) if len(arguments) >= 1: ens_config = self.ert().ensembleConfig() key = arguments[0] if key in self.supportedFIELDKeys(): config_node = ens_config[key] if len(arguments) >= 2: path_fmt = arguments[1] else: path_fmt = Export.DEFAULT_EXPORT_PATH % (key, key) + ".grdecl" if len(arguments) >= 3: range_string = "".join(arguments[2:]) iens_list = IntVector.active_list(range_string) else: ens_size = self.ert().getEnsembleSize() iens_list = IntVector.createRange(0, ens_size, 1) fs_manager = self.ert().getEnkfFsManager() fs = fs_manager.getCurrentFileSystem() init_file = self.ert().fieldInitFile(config_node) if init_file: print('Using init file: %s' % init_file) EnkfNode.exportMany(config_node, path_fmt, fs, iens_list, arg=init_file) else: self.lastCommandFailed("No such FIELD node: %s" % key) else: self.lastCommandFailed("Expected at least one argument: <keyword> received: '%s'" % line)
def run(self, line): arguments = splitArguments(line) if len(arguments) < 1: print("Error: This keyword requires a name of a plugin to run.") else: plugin_name = arguments[0] plugin_job = self.getWorkflowJob(plugin_name) if plugin_job is not None: try: script = self.getScript(plugin_job) if len(arguments) > 1: arguments = arguments[1:] else: arguments = script.getArguments(None) now = time.time() result = plugin_job.run(self.ert(), arguments) self.shellContext()["debug"].setLastPluginResult(result) diff = time.time() - now print("Plugin running time: %d seconds" % int(diff)) print(result) except CancelPluginException: print("Plugin cancelled before execution!") else: self.lastCommandFailed("Unknown plugin: '%s'" % plugin_name)
def exportFIELD(self, line): arguments = splitArguments(line) if len(arguments) >= 1: ens_config = self.ert().ensembleConfig() key = arguments[0] if key in self.supportedFIELDKeys(): config_node = ens_config[key] if len(arguments) >= 2: path_fmt = arguments[1] else: path_fmt = Export.DEFAULT_EXPORT_PATH % (key, key) + ".grdecl" if len(arguments) >= 3: range_string = "".join(arguments[2:]) iens_list = IntVector.active_list(range_string) else: ens_size = self.ert().getEnsembleSize() iens_list = IntVector.createRange(0, ens_size, 1) fs_manager = self.ert().getEnkfFsManager() fs = fs_manager.getCurrentFileSystem() mc = self.ert().getModelConfig() init_file = config_node.getInitFile(mc.getRunpathFormat()) if init_file: print('Using init file: %s' % init_file) EnkfNode.exportMany(config_node, path_fmt, fs, iens_list, arg=init_file) else: self.lastCommandFailed("No such FIELD node: %s" % key) else: self.lastCommandFailed("Expected at least one argument: <keyword> received: '%s'" % line)
def update(self, line): arguments = splitArguments(line) if len(arguments) == 1: case_name = arguments[0] ert = self.ert() fs_manager = ert.getEnkfFsManager() ert.getEnkfSimulationRunner().runWorkflows(HookRuntime.PRE_UPDATE) es_update = ESUpdate( ert ) target_fs = fs_manager.getFileSystem(case_name) source_fs = fs_manager.getCurrentFileSystem( ) model_config = ert.getModelConfig( ) runpath_fmt = model_config.getRunpathFormat( ) subst_list = ert.getDataKW( ) mask = BoolVector( default_value = True, initial_size = ert.getEnsembleSize( ) ) run_context = ErtRunContext.ensemble_smoother( source_fs , target_fs , mask, runpath_fmt, subst_list, 0 ) success = es_update.smootherUpdate( run_context ) if not success: self.lastCommandFailed("Unable to perform update") ert.getEnkfSimulationRunner().runWorkflows(HookRuntime.POST_UPDATE) else: self.lastCommandFailed("Expected one argument: <target_fs> received: '%s'" % line)
def ls(self, line): arguments = splitArguments(line) if len(arguments) == 0: self.lastCommandFailed("A 'block file' is required.") else: block_file = arguments[0] pattern = None if len(arguments) == 1 else arguments[1] if not os.path.isfile(block_file): self.lastCommandFailed("The path: '%s' is not a file." % block_file) else: if not UTIL_LIB.block_fs_is_mount(block_file): _, filename = os.path.split(block_file) self.lastCommandFailed("The file: '%s' is not a block mount file." % filename) else: block_fs = UTIL_LIB.block_fs_mount(block_file, 1, 0, 1, 0, False, True, False) files = UTIL_LIB.block_fs_alloc_filelist(block_fs, pattern, OFFSET_SORT, False) file_count = UTIL_LIB.vector_get_size(files) if file_count > 0: fmt = " %-40s %10d %10d" print(" %-40s %10s %10s" % ("Keyword", "Size", "Offset")) for index in range(file_count): node = UTIL_LIB.vector_iget_const(files, index) node_filename = UTIL_LIB.user_file_node_get_filename(node) node_size = UTIL_LIB.user_file_node_get_data_size(node) node_offset = UTIL_LIB.user_file_node_get_node_offset(node) print(fmt % (node_filename, node_size, node_offset)) UTIL_LIB.vector_free(files) UTIL_LIB.block_fs_close(block_fs)
def update(self, line): arguments = splitArguments(line) if len(arguments) == 1: case_name = arguments[0] ert = self.ert() fs_manager = ert.getEnkfFsManager() ert.getEnkfSimulationRunner().runWorkflows(HookRuntime.PRE_UPDATE) es_update = ESUpdate(ert) target_fs = fs_manager.getFileSystem(case_name) source_fs = fs_manager.getCurrentFileSystem() model_config = ert.getModelConfig() runpath_fmt = model_config.getRunpathFormat() subst_list = ert.getDataKW() mask = BoolVector(default_value=True, initial_size=ert.getEnsembleSize()) run_context = ErtRunContext.ensemble_smoother( source_fs, target_fs, mask, runpath_fmt, subst_list, 0) success = es_update.smootherUpdate(run_context) if not success: self.lastCommandFailed("Unable to perform update") ert.getEnkfSimulationRunner().runWorkflows(HookRuntime.POST_UPDATE) else: self.lastCommandFailed( "Expected one argument: <target_fs> received: '%s'" % line)
def add_matcher(self, line): args = splitArguments(line) if len(args) < 1: self.lastCommandFailed("A Summary key is required.") return False self.ert().ensembleConfig().getSummaryKeyMatcher().addSummaryKey(args[0].strip())
def plotPathValidator(model, line): arguments = splitArguments(line) if len(arguments) == 1: return arguments[0] # todo: check if exists and is file or directory for example else: raise ValueError("Can only set one path. If you require spaces in your path, " "surround it with quotes: \"path with space\".")
def add_matcher(self, line): args = splitArguments(line) if len(args) < 1: self.lastCommandFailed("A Summary key is required.") return False self.ert().ensembleConfig().getSummaryKeyMatcher().addSummaryKey( args[0].strip())
def completeSet(self, text, line, begidx, endidx): arguments = splitArguments(line) if len(arguments) > 2 or len(arguments) == 2 and not text: return [] active_module = self.ert().analysisConfig().getActiveModule() variables = active_module.getVariableNames() return autoCompleteListWithSeparator(text, variables)
def completeLoad(self, text, line, begidx, endidx): arguments = splitArguments(line) if len(arguments) > 2 or len(arguments) == 2 and not text: return [] if not text: return ["0-%d" % self.ert().getEnsembleSize()] # todo should generate based on realization directories. return []
def create(self, line): arguments = splitArguments(line) if len(arguments) == 1: case_name = arguments[0] if case_name not in self.getFileSystemNames(): fs = self.ert().getEnkfFsManager().getFileSystem(case_name) self.ert().getEnkfFsManager().switchFileSystem(fs) else: self.lastCommandFailed("Case '%s' already exists!" % case_name) else: self.lastCommandFailed("Expected one argument: <case_name> received: '%s'" % line)
def create(self, line): arguments = splitArguments(line) if len(arguments) == 1: case_name = arguments[0] if case_name not in self.getFileSystemNames(): fs = self.ert().getEnkfFsManager().getFileSystem(case_name) self.ert().getEnkfFsManager().switchFileSystem(fs) else: self.lastCommandFailed("Case '%s' already exists!" % case_name) else: self.lastCommandFailed( "Expected one argument: <case_name> received: '%s'" % line)
def update(self, line): arguments = splitArguments(line) if len(arguments) == 1: case_name = arguments[0] target_fs = self.ert().getEnkfFsManager().getFileSystem(case_name) simulation_runner = EnkfSimulationRunner(self.ert()) success = simulation_runner.smootherUpdate(target_fs) if not success: self.lastCommandFailed("Unable to perform update") else: self.lastCommandFailed("Expected one argument: <target_fs> received: '%s'" % line)
def help(self, line): arguments = splitArguments(line) if len(arguments) < 1: self.lastCommandFailed("This keyword requires a name of a plugin to run.") else: plugin_name = arguments[0] plugin_job = self.getWorkflowJob(plugin_name) if plugin_job is not None: script = self.getScript(plugin_job) print(script.__doc__) else: self.lastCommandFailed("Unknown plugin: '%s'" % plugin_name)
def completeLs(self, text, line, begidx, endidx): arguments = splitArguments(line) last_argument = extractFullArgument(line, endidx) if len(arguments) == 1 and len(text) == 0: ert = self.ert() if ert is not None: return [ert.getModelConfig().getEnspath() + os.path.sep] else: return getPossibleFilenameCompletions("") elif len(arguments) == 2 and len(last_argument) > 0: return getPossibleFilenameCompletions(last_argument) elif len(arguments) == 3 and len(text) > 0: return [] # pattern completion... else: return []
def help(self, line): arguments = splitArguments(line) if len(arguments) < 1: self.lastCommandFailed( "This keyword requires a name of a plugin to run.") else: plugin_name = arguments[0] plugin_job = self.getWorkflowJob(plugin_name) if plugin_job is not None: script = self.getScript(plugin_job) print(script.__doc__) else: self.lastCommandFailed("Unknown plugin: '%s'" % plugin_name)
def update(self, line): arguments = splitArguments(line) if len(arguments) == 1: case_name = arguments[0] ert = self.ert() fs_manager = ert.getEnkfFsManager() es_update = ESUpdate( ert ) target_fs = fs_manager.getFileSystem(case_name) source_fs = fs_manager.getCurrentFileSystem( ) success = es_update.smootherUpdate( source_fs , target_fs ) if not success: self.lastCommandFailed("Unable to perform update") else: self.lastCommandFailed("Expected one argument: <target_fs> received: '%s'" % line)
def load(self, args): arguments = splitArguments(args) if len(arguments) < 1: self.lastCommandFailed("Loading requires a realization mask.") return False realization_count = self.ert().getEnsembleSize() mask = BoolVector(False, realization_count) mask_success = mask.updateActiveMask(arguments[0]) if not mask_success: self.lastCommandFailed("The realization mask: '%s' is not valid." % arguments[0]) return False fs = self.ert().getEnkfFsManager().getCurrentFileSystem() self.ert().loadFromForwardModel(mask, 0, fs)
def set(self, line): arguments = splitArguments(line) if len(arguments) > 1: active_module = self.ert().analysisConfig().getActiveModule() variables = active_module.getVariableNames() variable, argument = line.split(" ", 1) if not variable in variables: self.lastCommandFailed("Variable with name: %s, not available in analysis module!" % variable) else: variable_type = active_module.getVariableType(variable) try: value = variable_type(argument) active_module.setVar(variable, argument) except ValueError: self.lastCommandFailed("Unable to convert '%s' into to a: %s" % (argument, variable_type.__name__)) else: self.lastCommandFailed("This keyword requires a variable name and a value.")
def completeRun(self, text, line, begidx, endidx): arguments = splitArguments(line) if len(arguments) > 2 or len(arguments) == 2 and not text: return [] return autoCompleteList(text, self.getPluginNames())