def test_local_field(self): with ErtTestContext('python/enkf/data/local_config', self.field_config) as test_context: main = test_context.getErt() local_config = main.getLocalConfig() # Creating dataset data_scale = local_config.createDataset('DATA_SCALE') grid = local_config.getGrid() ecl_reg = EclRegion(grid, False) ecl_reg.select_islice(10, 20) data_scale.addField('PERMX', ecl_reg) self.assertEqual(1, len(data_scale))
def test_slice(self): reg = EclRegion(self.grid, False) reg.select_islice(0, 5) OK = True global_list = reg.getGlobalList() self.assertEqual(global_list.parent(), reg) for gi in global_list: (i, j, k) = self.grid.get_ijk(global_index=gi) if i > 5: OK = False self.assertTrue(OK) self.assertTrue(self.grid.getNY() * self.grid.getNZ() * 6 == len(reg.getGlobalList())) reg.select_jslice(7, 8, intersect=True) OK = True for gi in reg.getGlobalList(): (i, j, k) = self.grid.get_ijk(global_index=gi) if i > 5: OK = False if j < 7 or j > 8: OK = False self.assertTrue(OK) self.assertTrue(2 * self.grid.getNZ() * 6 == len(reg.getGlobalList())) reg2 = EclRegion(self.grid, False) reg2.select_kslice(3, 5) reg &= reg2 OK = True for gi in reg.getGlobalList(): (i, j, k) = self.grid.get_ijk(global_index=gi) if i > 5: OK = False if j < 7 or j > 8: OK = False if k < 3 or k > 5: OK = False self.assertTrue(OK) self.assertTrue(2 * 3 * 6 == len(reg.getGlobalList()))
def filter_region_ijk(grid, i, j, k, combine_operator="intersect"): # Filter out the selected grid cells region = EclRegion(grid, False) region1 = EclRegion(grid, False) region_i = EclRegion(grid, False) region_j = EclRegion(grid, False) region_k = EclRegion(grid, False) # Create selected regions for each filter type if i: for i_slice in unpack_filter(i): region_i.select_islice(i_slice - 1, i_slice - 1) # -1 because ert defines i=1 as i=0 else: region_i.select_all() if j: for j_slice in unpack_filter(j): region_j.select_jslice(j_slice - 1, j_slice - 1) # -1 because ert defines j=1 as j=0 else: region_j.select_all() if k: for k_slice in unpack_filter(k): region_k.select_kslice(k_slice - 1, k_slice - 1) # -1 because ert defines j=1 as j=0 else: region_k.select_all() # Combine regions by if (combine_operator == "intersect" or combine_operator == "" or combine_operator is None): # Intersection region.select_all() region = region & region_i & region_j & region_k return region elif combine_operator == "union": # Union region1.select_active() region2 = region_i | region_j | region_k region = region1 & region2 return region else: raise Exception( "ERROR: '%s' is not a valid operator to combine regions." % combine_operator)
def test_local_field(self): with ErtTestContext("python/enkf/data/local_config", self.field_config) as test_context: main = test_context.getErt() local_config = main.getLocalConfig() # Creating dataset data_scale = local_config.createDataset("DATA_SCALE") grid = local_config.getGrid() ecl_reg = EclRegion(grid, False) ecl_reg.select_islice(10, 20) data_scale.addField("PERMX", ecl_reg) self.assertEqual(1, len(data_scale)) # A totally invalid key -> KeyError exception with self.assertRaises(KeyError): data_scale.row_scaling("NO_SUCH_KEY") row_scaling = data_scale.row_scaling("PERMX")
def test_equal(self): reg1 = EclRegion(self.grid , False) reg2 = EclRegion(self.grid , False) self.assertTrue( reg1 == reg2 ) reg1.select_islice(4 , 6) self.assertFalse( reg1 == reg2 ) reg2.select_islice(4,7) self.assertFalse( reg1 == reg2 ) reg1.select_islice(7,7) self.assertTrue( reg1 == reg2 )
def test_equal(self): reg1 = EclRegion(self.grid, False) reg2 = EclRegion(self.grid, False) self.assertTrue(reg1 == reg2) reg1.select_islice(4, 6) self.assertFalse(reg1 == reg2) reg2.select_islice(4, 7) self.assertFalse(reg1 == reg2) reg1.select_islice(7, 7) self.assertTrue(reg1 == reg2)
def test_index_list(self): reg = EclRegion(self.grid, False) reg.select_islice(0, 5) active_list = reg.getActiveList() global_list = reg.getGlobalList()
def filter_region(grid, idx_i, idx_j, idx_k, fipnum, fipnum_kw, combine_operator="intersect"): # Filter out the selected grid cells region = EclRegion(grid, False) region1 = EclRegion(grid, False) region_i = EclRegion(grid, False) region_j = EclRegion(grid, False) region_k = EclRegion(grid, False) region_fip = EclRegion(grid, False) # Create selected regions for each filter type if idx_i: for i_slice in unpack_filter(idx_i): region_i.select_islice(i_slice - 1, i_slice - 1) # -1 because ert defines i=1 as i=0 else: region_i.select_all() if idx_j: for j_slice in unpack_filter(idx_j): region_j.select_jslice(j_slice - 1, j_slice - 1) # -1 because ert defines j=1 as j=0 else: region_j.select_all() if idx_k: for k_slice in unpack_filter(idx_k): region_k.select_kslice(k_slice - 1, k_slice - 1) # -1 because ert defines j=1 as j=0 else: region_k.select_all() if fipnum: for fip in unpack_filter(fipnum): region_fip.select_equal(fipnum_kw, fip) else: region_fip.select_all() # Combine regions by if (combine_operator == "intersect" or combine_operator == "" or combine_operator is None): # Intersection region.select_all() # region.select_active() region = region & region_i & region_j & region_k & region_fip return region if combine_operator == "union": # Union region1.select_active() region2 = region_i | region_j | region_k | region_fip region = region1 & region2 return region raise Exception( f"ERROR: '{combine_operator}' is not a valid operator to combine regions." )