def test__add_region_to_array_via_slice(self): array = aa.Array2D.manual(array=np.zeros((2, 2)), pixel_scales=1.0) array = array.native image = np.ones((2, 2)) region = aa.Region2D(region=(0, 1, 0, 1)) array[region.slice] += image[region.slice] assert (array == np.array([[1.0, 0.0], [0.0, 0.0]])).all() array = aa.Array2D.manual(array=np.ones((2, 2)), pixel_scales=1.0) array = array.native image = np.ones((2, 2)) region = aa.Region2D(region=(0, 1, 0, 1)) array[region.slice] += image[region.slice] assert (array == np.array([[2.0, 1.0], [1.0, 1.0]])).all() array = aa.Array2D.manual(array=np.ones((3, 3)), pixel_scales=1.0) array = array.native image = np.ones((3, 3)) region = aa.Region2D(region=(1, 3, 2, 3)) array[region.slice] += image[region.slice] assert (array == np.array([[1.0, 1.0, 1.0], [1.0, 1.0, 2.0], [1.0, 1.0, 2.0]])).all()
def test__parallel_side_nearest_read_out_region_from(self): region = aa.Region2D(region=(1, 3, 0, 5)) parallel_region = region.parallel_side_nearest_read_out_region_from( shape_2d=(5, 5), columns=(0, 1)) assert parallel_region == (0, 5, 0, 1) parallel_region = region.parallel_side_nearest_read_out_region_from( shape_2d=(4, 4), columns=(1, 3)) assert parallel_region == (0, 4, 1, 3) region = aa.Region2D(region=(1, 3, 2, 5)) parallel_region = region.parallel_side_nearest_read_out_region_from( shape_2d=(4, 4), columns=(1, 3)) assert parallel_region == (0, 4, 3, 5) region = aa.Region2D(region=(1, 3, 0, 5)) parallel_region = region.parallel_side_nearest_read_out_region_from( shape_2d=(2, 5), columns=(0, 1)) assert parallel_region == (0, 2, 0, 1)
def test__extraction_via_slice(self): array = aa.Array2D.manual( array=np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]), pixel_scales=1.0, ) region = aa.Region2D(region=(0, 2, 0, 2)) new_array = array.native[region.slice] assert (new_array == np.array([[1.0, 2.0], [4.0, 5.0]])).all() array = aa.Array2D.manual( array=np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]), pixel_scales=1.0, ) region = aa.Region2D(region=(1, 3, 0, 3)) new_array = array.native[region.slice] assert (new_array == np.array([[4.0, 5.0, 6.0], [7.0, 8.0, 9.0]])).all()
def test__sanity_check__first_row_or_column_equal_too_or_bigger_than_second__raise_errors( self): with pytest.raises(exc.RegionException): aa.Region2D(region=(2, 2, 1, 2)) with pytest.raises(exc.RegionException): aa.Region2D(region=(2, 1, 2, 2)) with pytest.raises(exc.RegionException): aa.Region2D(region=(2, 1, 1, 2)) with pytest.raises(exc.RegionException): aa.Region2D(region=(0, 1, 3, 2))
def test__sanity_check__negative_coordinates_raise_errors(self): with pytest.raises(exc.RegionException): aa.Region2D(region=(-1, 0, 1, 2)) with pytest.raises(exc.RegionException): aa.Region2D(region=(0, -1, 1, 2)) with pytest.raises(exc.RegionException): aa.Region2D(region=(0, 0, -1, 2)) with pytest.raises(exc.RegionException): aa.Region2D(region=(0, 1, 2, -1))
def extracted_layout_for_serial_calibration_from(self, new_shape_2d, rows): serial_prescan = ((0, new_shape_2d[0], self.serial_prescan[2], self.serial_prescan[3]) if self.serial_prescan is not None else None) serial_overscan = ((0, new_shape_2d[0], self.serial_overscan[2], self.serial_overscan[3]) if self.serial_overscan is not None else None) x0 = self.region_list[0][2] x1 = self.region_list[0][3] offset = 0 new_pattern_region_list_ci = [] for region in self.region_list: labelsize = rows[1] - rows[0] new_pattern_region_list_ci.append( aa.Region2D(region=(offset, offset + labelsize, x0, x1))) offset += labelsize new_layout_ci = deepcopy(self) new_layout_ci.region_list = new_pattern_region_list_ci new_layout_ci.serial_prescan = serial_prescan new_layout_ci.serial_overscan = serial_overscan return new_layout_ci
def test__set_region_to_zero_via_slice(self): array = aa.Array2D.manual(array=np.ones((2, 2)), pixel_scales=1.0) array = array.native region = aa.Region2D(region=(0, 1, 0, 1)) array[region.slice] = 0 assert (array == np.array([[0.0, 1.0], [1.0, 1.0]])).all() array = aa.Array2D.manual(array=np.ones((3, 3)), pixel_scales=1.0) array = array.native region = aa.Region2D(region=(1, 3, 2, 3)) array[region.slice] = 0 assert (array == np.array([[1.0, 1.0, 1.0], [1.0, 1.0, 0.0], [1.0, 1.0, 0.0]])).all()
def test__serial_entire_rows_of_regions__full_region_from_left_most_prescan_to_right_most_end_of_trails( self, ): region = aa.Region2D(region=(1, 3, 0, 5)) serial_region = region.serial_entire_rows_of_region_from(shape_2d=(5, 5)) assert serial_region == (1, 3, 0, 5) region = aa.Region2D(region=(1, 3, 0, 5)) serial_region = region.serial_entire_rows_of_region_from(shape_2d=(5, 25)) assert serial_region == (1, 3, 0, 25) region = aa.Region2D(region=(3, 5, 5, 30)) serial_region = region.serial_entire_rows_of_region_from(shape_2d=(8, 55)) assert serial_region == (3, 5, 0, 55)
def test__parallel_trails_of_region_from__extracts_rows_above_region(self): region = aa.Region2D( region=(0, 3, 0, 3)) # The trails are row 3 and above, so extract 3 -> 4 trails = region.parallel_trails_region_from(rows=(0, 1)) assert trails == (3, 4, 0, 3) # The trails are row 3 and above, so extract 3 -> 5 trails = region.parallel_trails_region_from(rows=(0, 2)) assert trails == (3, 5, 0, 3) # The trails are row 3 and above, so extract 4 -> 6 trails = region.parallel_trails_region_from(rows=(1, 3)) assert trails == (4, 6, 0, 3)
def test__serial_trails_of_regions__extracts_region_to_right_of_region( self): region = aa.Region2D( region=(0, 3, 0, 3)) # The trails are column 3 and above, so extract 3 -> 4 trails = region.serial_trails_region_from(columns=(0, 1)) assert trails == (0, 3, 3, 4) # The trails are column 3 and above, so extract 3 -> 5 trails = region.serial_trails_region_from(columns=(0, 2)) assert trails == (0, 3, 3, 5) # The trails are column 3 and above, so extract 4 -> 6 trails = region.serial_trails_region_from(columns=(1, 3)) assert trails == (0, 3, 4, 6)
def test__serial_front_edge_of_region__extracts_region_within_left_of_region( self): region = aa.Region2D(region=( 0, 3, 0, 3)) # Front edge is column 0, so for 1 column we extract 0 -> 1 front_edge = region.serial_front_edge_region_from(columns=(0, 1)) assert front_edge == (0, 3, 0, 1) # Front edge is column 0, so for 2 columns we extract 0 -> 2 front_edge = region.serial_front_edge_region_from(columns=(0, 2)) assert front_edge == (0, 3, 0, 2) # Front edge is column 0, so for these 2 columns we extract 1 ->2 front_edge = region.serial_front_edge_region_from(columns=(1, 3)) assert front_edge == (0, 3, 1, 3)
def test__parallel_front_edge_region_from__extracts_rows_within_bottom_of_region( self, ): region = aa.Region2D(region=(0, 3, 0, 3)) # Front edge is row 0, so for 1 row we extract 0 -> 1 front_edge = region.parallel_front_edge_region_from(rows=(0, 1)) assert front_edge == (0, 1, 0, 3) # Front edge is row 0, so for 2 rows we extract 0 -> 2 front_edge = region.parallel_front_edge_region_from(rows=(0, 2)) assert front_edge == (0, 2, 0, 3) # Front edge is row 0, so for these 2 rows we extract 1 ->2 front_edge = region.parallel_front_edge_region_from(rows=(1, 3)) assert front_edge == (1, 3, 0, 3)