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 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 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 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 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 = self._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 = self._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 self.updateMask(config_node.getDataModelConfig(), 60, fs2, active_mask_modified) active_mask = self._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 = self._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 = self._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])
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)