def getGenDataResult(self, target_case_name, iens, report_step, keyword): ensemble_config = self.ert.ensembleConfig() if not self.isRealizationFinished(iens): raise createFault( UserWarning, "The simulation with id: %d is still running." % iens) if keyword in ensemble_config: enkf_config_node = self.ert.ensembleConfig().getNode(keyword) node = EnkfNode(enkf_config_node) if not node.getImplType() == ErtImplType.GEN_DATA: raise createFault(UserWarning, "The keyword is not a GenData keyword.") gen_data = node.asGenData() fs = self.ert.getEnkfFsManager().getFileSystem(target_case_name) node_id = NodeId(report_step, iens) if node.tryLoad(fs, node_id): data = gen_data.getData() return data.asList() else: raise createFault( UserWarning, "Unable to load data for iens: %d report_step: %d kw: %s for case: %s" % (iens, report_step, keyword, target_case_name)) else: raise createFault(KeyError, "The keyword: %s is not recognized" % keyword)
def getCustomKWResult(self, target_case_name, iens, keyword): ensemble_config = self.ert.ensembleConfig() if not self.isRealizationFinished(iens): raise createFault( UserWarning, "The simulation with id: %d is still running." % iens) if keyword in ensemble_config: enkf_config_node = self.ert.ensembleConfig().getNode(keyword) node = EnkfNode(enkf_config_node) if not node.getImplType() == ErtImplType.CUSTOM_KW: raise createFault(UserWarning, "The keyword is not a CustomKW keyword.") custom_kw = node.asCustomKW() fs = self.ert.getEnkfFsManager().getFileSystem(target_case_name) node_id = NodeId(0, iens) if node.tryLoad(fs, node_id): config = custom_kw.getConfig() result = {} for key in config.getKeys(): result[key] = custom_kw[key] return result else: raise createFault( UserWarning, "Unable to load data for iens: %d kw: %s for case: %s" % (iens, keyword, target_case_name)) else: raise createFault(KeyError, "The keyword: %s is not recognized" % keyword)
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 test_field_export_many(self): with ErtTestContext("export_test", self.config_file) as test_context: ert = test_context.getErt() fs_manager = ert.getEnkfFsManager() ens_config = ert.ensembleConfig() config_node = ens_config["PERMX"] iens_list = IntVector() iens_list.append(0) iens_list.append(2) iens_list.append(4) fs = fs_manager.getCurrentFileSystem() # Filename without embedded %d - TypeError with self.assertRaises(TypeError): EnkfNode.exportMany(config_node, "export/with/path/PERMX.grdecl", fs, iens_list) EnkfNode.exportMany(config_node, "export/with/path/PERMX_%d.grdecl", fs, iens_list) self.assertTrue(os.path.isfile("export/with/path/PERMX_0.grdecl")) self.assertTrue(os.path.isfile("export/with/path/PERMX_2.grdecl")) self.assertTrue(os.path.isfile("export/with/path/PERMX_4.grdecl"))
def getCustomKWResult(self, target_case_name, iens, keyword): ensemble_config = self.ert.ensembleConfig() if not self.isRealizationFinished(iens): raise createFault(UserWarning, "The simulation with id: %d is still running." % iens) if keyword in ensemble_config: enkf_config_node = self.ert.ensembleConfig().getNode(keyword) node = EnkfNode(enkf_config_node) if not node.getImplType() == ErtImplType.CUSTOM_KW: raise createFault(UserWarning, "The keyword is not a CustomKW keyword.") custom_kw = node.asCustomKW() fs = self.ert.getEnkfFsManager().getFileSystem(target_case_name) node_id = NodeId(0, iens) if node.tryLoad(fs, node_id): config = custom_kw.getConfig() result = {} for key in config.getKeys(): result[key] = custom_kw[key] return result else: raise createFault(UserWarning, "Unable to load data for iens: %d kw: %s for case: %s" % (iens, keyword, target_case_name)) else: raise createFault(KeyError, "The keyword: %s is not recognized" % keyword)
def _initializeRealization(self, target_fs, geo_id, iens, keywords): ens_config = self.ert.ensembleConfig() for kw in ens_config.getKeylistFromVarType(EnkfVarType.PARAMETER): if not kw in keywords: config_node = ens_config[kw] data_node = EnkfNode( config_node ) init_id = NodeId(0, geo_id) run_id = NodeId(0, iens) data_node.load(self._getInitializationCase(), init_id) data_node.save(target_fs, run_id) for key, values in keywords.items(): config_node = ens_config[key] data_node = EnkfNode( config_node ) gen_kw = data_node.asGenKw() gen_kw.setValues(values) run_id = NodeId(0, iens) data_node.save(target_fs, run_id) target_fs.fsync() state_map = target_fs.getStateMap() state_map[iens] = RealizationStateEnum.STATE_INITIALIZED
def test_field_export(self): with ErtTestContext("export_test", self.config_file) as test_context: ert = test_context.getErt() fs_manager = ert.getEnkfFsManager( ) ens_config = ert.ensembleConfig() config_node = ens_config["PERMX"] data_node = EnkfNode( config_node ) node_id = NodeId( 0 , 0 , EnkfStateType.ANALYZED ) fs = fs_manager.getCurrentFileSystem( ) data_node.tryLoad( fs , node_id ) data_node.export("export/with/path/PERMX.grdecl") self.assertTrue( os.path.isfile("export/with/path/PERMX.grdecl") )
def storeSimulationData(self, target_case_name, group_name, keyword, value, sim_id): fs = self.ert.getEnkfFsManager().getFileSystem(target_case_name) enkf_config_node = self.ert.ensembleConfig().getNode(group_name) enkf_node = EnkfNode(enkf_config_node) self._updateCustomKWConfigSet(fs, enkf_config_node) self._storeData(enkf_node, fs, group_name, keyword, value, sim_id)
def storeGlobalData(self, target_case_name, group_name, keyword, value): fs = self.ert.getEnkfFsManager().getFileSystem(target_case_name) enkf_config_node = self.ert.ensembleConfig().getNode(group_name) enkf_node = EnkfNode(enkf_config_node) self._updateCustomKWConfigSet(fs, enkf_config_node) realizations = fs.realizationList(RealizationStateEnum.STATE_INITIALIZED | RealizationStateEnum.STATE_HAS_DATA) for realization_number in realizations: self._storeData(enkf_node, fs, group_name, keyword, value, realization_number)
def test_field_export_many(self): with ErtTestContext("export_test", self.config_file) as test_context: ert = test_context.getErt() fs_manager = ert.getEnkfFsManager( ) ens_config = ert.ensembleConfig() config_node = ens_config["PERMX"] iens_list = IntVector( ) iens_list.append(0) iens_list.append(2) iens_list.append(4) fs = fs_manager.getCurrentFileSystem( ) # Filename without embedded %d - TypeError with self.assertRaises(TypeError): EnkfNode.exportMany( config_node , "export/with/path/PERMX.grdecl" , fs , iens_list ) EnkfNode.exportMany( config_node , "export/with/path/PERMX_%d.grdecl" , fs , iens_list ) self.assertTrue( os.path.isfile("export/with/path/PERMX_0.grdecl") ) self.assertTrue( os.path.isfile("export/with/path/PERMX_2.grdecl") ) self.assertTrue( os.path.isfile("export/with/path/PERMX_4.grdecl") )
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 getGenDataResult(self, target_case_name, iens, report_step, keyword): ensemble_config = self.ert.ensembleConfig() if not self.isRealizationFinished(iens): raise createFault(UserWarning, "The simulation with id: %d is still running." % iens) if keyword in ensemble_config: enkf_config_node = self.ert.ensembleConfig().getNode(keyword) node = EnkfNode(enkf_config_node) if not node.getImplType() == ErtImplType.GEN_DATA: raise createFault(UserWarning, "The keyword is not a GenData keyword.") gen_data = node.asGenData() fs = self.ert.getEnkfFsManager().getFileSystem(target_case_name) node_id = NodeId(report_step, iens) if node.tryLoad(fs, node_id): data = gen_data.getData() return data.asList() else: raise createFault(UserWarning, "Unable to load data for iens: %d report_step: %d kw: %s for case: %s" % (iens, report_step, keyword, target_case_name)) else: raise createFault(KeyError, "The keyword: %s is not recognized" % keyword)
def test_field_export(self): with ErtTestContext("export_test", self.config_file) as test_context: ert = test_context.getErt() fs_manager = ert.getEnkfFsManager() ens_config = ert.ensembleConfig() config_node = ens_config["PERMX"] data_node = EnkfNode(config_node) node_id = NodeId(0, 0) fs = fs_manager.getCurrentFileSystem() data_node.tryLoad(fs, node_id) data_node.export("export/with/path/PERMX.grdecl") self.assertTrue(os.path.isfile("export/with/path/PERMX.grdecl"))
def load_active_masks(self, case1, case2 ): with ErtTestContext("gen_data_config_test", self.config_file) as test_context: ert = test_context.getErt() fs1 = ert.getEnkfFsManager().getFileSystem(case1) config_node = ert.ensembleConfig().getNode("TIMESHIFT") data_node = EnkfNode(config_node) data_node.tryLoad(fs1, NodeId(60, 0)) active_mask = get_active_mask( config_node.getDataModelConfig() ) first_active_mask_length = len(active_mask) self.assertEqual(first_active_mask_length, 2560) fs2 = ert.getEnkfFsManager().getFileSystem(case2) data_node = EnkfNode(config_node) data_node.tryLoad(fs2, NodeId(60, 0)) active_mask = get_active_mask( config_node.getDataModelConfig() ) second_active_mask_len = len(active_mask) self.assertEqual(second_active_mask_len, 2560) self.assertEqual(first_active_mask_length, second_active_mask_len) # Setting one element to False, load different case, check, reload, and check. self.assertTrue(active_mask[10]) active_mask_modified = active_mask.copy() active_mask_modified[10] = False updateMask(config_node.getDataModelConfig(), 60, fs2 , active_mask_modified) active_mask = get_active_mask( config_node.getDataModelConfig() ) self.assertFalse(active_mask[10]) #Load first - check element is true data_node = EnkfNode(config_node) data_node.tryLoad(fs1, NodeId(60, 0)) active_mask = get_active_mask( config_node.getDataModelConfig() ) self.assertTrue(active_mask[10]) # Reload second again, should now be false at 10, due to the update further up data_node = EnkfNode(config_node) data_node.tryLoad(fs2, NodeId(60, 0)) active_mask = get_active_mask( config_node.getDataModelConfig() ) self.assertFalse(active_mask[10])
def load_active_masks(self, case1, case2): with ErtTestContext("gen_data_config_test", self.config_file) as test_context: ert = test_context.getErt() fs1 = ert.getEnkfFsManager().getFileSystem(case1) config_node = ert.ensembleConfig().getNode("TIMESHIFT") data_node = EnkfNode(config_node) data_node.tryLoad(fs1, NodeId(60, 0)) active_mask = get_active_mask(config_node.getDataModelConfig()) first_active_mask_length = len(active_mask) self.assertEqual(first_active_mask_length, 2560) fs2 = ert.getEnkfFsManager().getFileSystem(case2) data_node = EnkfNode(config_node) data_node.tryLoad(fs2, NodeId(60, 0)) active_mask = get_active_mask(config_node.getDataModelConfig()) second_active_mask_len = len(active_mask) self.assertEqual(second_active_mask_len, 2560) self.assertEqual(first_active_mask_length, second_active_mask_len) # Setting one element to False, load different case, check, reload, and check. self.assertTrue(active_mask[10]) active_mask_modified = active_mask.copy() active_mask_modified[10] = False updateMask(config_node.getDataModelConfig(), 60, fs2, active_mask_modified) active_mask = get_active_mask(config_node.getDataModelConfig()) self.assertFalse(active_mask[10]) # Load first - check element is true data_node = EnkfNode(config_node) data_node.tryLoad(fs1, NodeId(60, 0)) active_mask = get_active_mask(config_node.getDataModelConfig()) self.assertTrue(active_mask[10]) # Reload second again, should now be false at 10, due to the update further up data_node = EnkfNode(config_node) data_node.tryLoad(fs2, NodeId(60, 0)) active_mask = get_active_mask(config_node.getDataModelConfig()) self.assertFalse(active_mask[10])
while True: print("Waiting:%d Running:%d Complete:%d/%d" % (queue_manager.getNumWaiting(), queue_manager.getNumRunning(), queue_manager.getNumSuccess(), queue_manager.getNumFailed())) if not queue_manager.isRunning(): break time.sleep(5) ens_config = ert.ensembleConfig() data_config = ens_config["SNAKE_OIL_OPR_DIFF"] param_config = ens_config["SNAKE_OIL_PARAM"] for iens in range(ert.getEnsembleSize()): data_id = NodeId(realization_number=iens, report_step=199) enkf_node1 = EnkfNode(data_config) enkf_node1.load(fs, data_id) gen_data = enkf_node1.asGenData() data = gen_data.getData() param_id = NodeId(realization_number=iens, report_step=0) enkf_node2 = EnkfNode(param_config) enkf_node2.load(fs, param_id) gen_kw = enkf_node2.asGenKw() print sum(data) for v in gen_kw: print v # Using the __getitem__() of GenData which was implemented
def _initializeRealization(self, target_fs, geo_id, iens, keywords): ens_config = self.ert.ensembleConfig() for kw in ens_config.getKeylistFromVarType(EnkfVarType.PARAMETER): if not kw in keywords: config_node = ens_config[kw] data_node = EnkfNode(config_node) init_id = NodeId(0, geo_id) run_id = NodeId(0, iens) data_node.load(self._getInitializationCase(), init_id) data_node.save(target_fs, run_id) for key, values in keywords.items(): config_node = ens_config[key] data_node = EnkfNode(config_node) gen_kw = data_node.asGenKw() gen_kw.setValues(values) run_id = NodeId(0, iens) data_node.save(target_fs, run_id) target_fs.fsync() state_map = target_fs.getStateMap() state_map[iens] = RealizationStateEnum.STATE_INITIALIZED
while True: print("Waiting:%d Running:%d Complete:%d/%d" % (queue_manager.getNumWaiting( ), queue_manager.getNumRunning( ) , queue_manager.getNumSuccess() , queue_manager.getNumFailed( ))) if not queue_manager.isRunning( ): break time.sleep( 5 ) ens_config = ert.ensembleConfig( ) data_config = ens_config["SNAKE_OIL_OPR_DIFF"] param_config = ens_config["SNAKE_OIL_PARAM"] for iens in range(ert.getEnsembleSize( )): data_id = NodeId( realization_number = iens, report_step = 199 ) enkf_node1 = EnkfNode( data_config ) enkf_node1.load( fs , data_id ) gen_data = enkf_node1.asGenData( ) data = gen_data.getData( ) param_id = NodeId( realization_number = iens, report_step = 0 ) enkf_node2 = EnkfNode( param_config ) enkf_node2.load( fs , param_id ) gen_kw = enkf_node2.asGenKw( ) print sum(data) for v in gen_kw: print v