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_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(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." )