def test__sanity_check__negative_coordinates_raise_errors(self): with pytest.raises(exc.RegionException): aa.Region1D(region=(-1, 0)) with pytest.raises(exc.RegionException): aa.Region1D(region=(0, -1))
def test__sanity_check__first_row_or_column_equal_too_or_bigger_than_second__raise_errors( self): with pytest.raises(exc.RegionException): aa.Region1D(region=(2, 2)) with pytest.raises(exc.RegionException): aa.Region1D(region=(2, 1))
def test__extraction_via_slice(self): arr_1d = aa.Array1D.manual_native(array=np.array( [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), pixel_scales=1.0) region = aa.Region1D(region=(0, 2)) new_arr_1d = arr_1d[region.slice] assert (new_arr_1d == np.array([1.0, 2.0])).all() region = aa.Region1D(region=(1, 3)) new_arr_1d = arr_1d[region.slice] assert (new_arr_1d == np.array([2.0, 3.0])).all()
def test__set_region_to_zero_via_slice(self): arr_1d = aa.Array1D.manual_native(array=np.array([1.0, 2.0, 3.0, 4.0]), pixel_scales=1.0) region = aa.Region1D(region=(0, 1)) arr_1d[region.slice] = 0 assert (arr_1d == np.array([0.0, 2.0, 3.0, 4.0])).all() arr_1d = aa.Array1D.manual_native(array=np.array([1.0, 2.0, 3.0, 4.0]), pixel_scales=1.0) region = aa.Region1D(region=(2, 4)) arr_1d[region.slice] = 0 assert (arr_1d == np.array([1.0, 2.0, 0.0, 0.0])).all()
def test__add_region_to_arr_1d_via_slice(self): arr_1d = aa.Array1D.manual_native(array=np.array([1.0, 2.0, 3.0, 4.0]), pixel_scales=1.0) image = aa.Array1D.full(fill_value=1.0, shape_native=6, pixel_scales=1.0) region = aa.Region1D(region=(0, 1)) arr_1d[region.slice] += image[region.slice] assert (arr_1d == np.array([2.0, 2.0, 3.0, 4.0])).all() arr_1d = aa.Array1D.manual_native(array=np.array([1.0, 2.0, 3.0, 4.0]), pixel_scales=1.0) region = aa.Region1D(region=(2, 4)) arr_1d[region.slice] += image[region.slice] assert (arr_1d == np.array([1.0, 2.0, 4.0, 5.0])).all()
def test__trails_region_from__extracts_pixels_after_region(self): region = aa.Region1D(region=(0, 3)) # Front edge ends pixel 3, so for 1 pixel we extract 3 -> 4 trails_region = region.trails_region_from(pixels=(0, 1)) assert trails_region == (3, 4) # Front edge ends pixel 3, so for 2 pixels we extract 3 -> 5 trails_region = region.trails_region_from(pixels=(0, 2)) assert trails_region == (3, 5) # Front edge ends pixel 3, so for these 2 pixels we extract 3 ->6 trails_region = region.trails_region_from(pixels=(1, 3)) assert trails_region == (4, 6)
def test__front_edge_region_from__extracts_rows_within_bottom_of_region( self, ): region = aa.Region1D(region=(0, 3)) # Front edge is row 0, so for 1 row we extract 0 -> 1 front_edge = region.front_edge_region_from(pixels=(0, 1)) assert front_edge == (0, 1) # Front edge is row 0, so for 2 pixels we extract 0 -> 2 front_edge = region.front_edge_region_from(pixels=(0, 2)) assert front_edge == (0, 2) # Front edge is row 0, so for these 2 pixels we extract 1 ->2 front_edge = region.front_edge_region_from(pixels=(1, 3)) assert front_edge == (1, 3)