def test__4x3_grid_of_pixel_grid__1_coordinate_in_each_pixel(self): # _ _ _ # |_|_|_| # |_|_|_| # |_|_|_| # |_|_|_| # Boundaries for column pixel 0 -1.0 to -(1/3) # Boundaries for column pixel 1 -(1/3) to (1/3) # Boundaries for column pixel 2 (1/3) to 1.0 # Bounadries for row pixel 0 -1.0 to -0.5 # Bounadries for row pixel 1 -0.5 to 0.0 # Bounadries for row pixel 2 0.0 to 0.5 # Bounadries for row pixel 3 0.5 to 1.0 pixelization_grid = np.array([ [1.0, -1.0], [1.0, 0.0], [1.0, 1.0], [0.5, -1.0], [-0.5, 1.0], [-1.0, 1.0], ]) pix = al.pixelizations.Rectangular(shape=(4, 3)) geometry = pix.geometry_from_grid(grid=pixelization_grid) grid = MockPixelizationGrid( pixelization_grid, sub_mask_1d_index_to_mask_1d_index=np.ones((1)), sub_size=1, ) pix = al.RectangularMapper( pixels=12, shape=(4, 3), grid=grid, pixelization_grid=pixelization_grid, geometry=geometry, ) assert (pix.sub_mask_1d_index_to_pixelization_1d_index == np.array( [0, 1, 2, 3, 8, 11])).all() assert pix.pixelization_1d_index_to_all_sub_mask_1d_indexes == [ [0], [1], [2], [3], [], [], [], [], [4], [], [], [5], ]
def test__3x3_pixelization__solution_vector_ascending(self): pixelization_grid = np.array([ [2.0, -1.0], [2.0, 0.0], [2.0, 1.0], [0.0, -1.0], [0.0, 0.0], [0.0, 1.0], [-2.0, -1.0], [-2.0, 0.0], [-2.0, 1.0], ]) pix = al.pixelizations.Rectangular(shape=(3, 3)) geometry = pix.geometry_from_grid(grid=pixelization_grid) pix = al.RectangularMapper( pixels=9, shape=(3, 3), grid=None, pixelization_grid=pixelization_grid, geometry=geometry, ) recon_pix = pix.reconstructed_pixelization_from_solution_vector( solution_vector=np.array( [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0])) assert (recon_pix == np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]])).all() assert recon_pix.pixel_scales == pytest.approx( (4.0 / 3.0, 2.0 / 3.0), 1e-2) assert recon_pix.origin == (0.0, 0.0)
def test__compare_to_imaging_util(self): pix = al.RectangularMapper( pixels=9, shape=(4, 3), grid=None, pixelization_grid=None, geometry=MockGeometry(), ) solution = np.array( [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 1.0, 2.0, 3.0]) recon_pix = pix.reconstructed_pixelization_from_solution_vector( solution_vector=solution) recon_pix_util = al.array_mapping_util.sub_array_2d_from_sub_array_1d_mask_and_sub_size( sub_array_1d=solution, mask=np.full(fill_value=False, shape=(4, 3)), sub_size=1, ) assert (recon_pix == recon_pix_util).all() assert recon_pix.shape == (4, 3) pix = al.RectangularMapper( pixels=9, shape=(3, 4), grid=None, pixelization_grid=None, geometry=MockGeometry(), ) solution = np.array( [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 1.0, 2.0, 3.0]) recon_pix = pix.reconstructed_pixelization_from_solution_vector( solution_vector=solution) recon_pix_util = al.array_mapping_util.sub_array_2d_from_sub_array_1d_mask_and_sub_size( sub_array_1d=solution, mask=np.full(fill_value=False, shape=(3, 4)), sub_size=1, ) assert (recon_pix == recon_pix_util).all() assert recon_pix.shape == (3, 4)
def test__3x3_grid_of_pixel_grid__1_coordinate_per_square_pixel__near_edges_of_pixels( self): # _ _ _ # |_|_|_| Boundaries for pixels x = 0 and y = 0 -1.0 to -(1/3) # |_|_|_| Boundaries for pixels x = 1 and y = 1 - (1/3) to (1/3) # |_|_|_| Boundaries for pixels x = 2 and y = 2 - (1/3)" to 1.0" pixelization_grid = np.array([ [1.0, -1.0], [1.0, 0.0], [1.0, 1.0], [-0.32, -1.0], [-0.32, 0.32], [0.0, 1.0], [-0.34, -0.34], [-0.34, 0.325], [-1.0, 1.0], ]) pix = al.pixelizations.Rectangular(shape=(3, 3)) geometry = pix.geometry_from_grid(grid=pixelization_grid) grid = MockPixelizationGrid( pixelization_grid, sub_mask_1d_index_to_mask_1d_index=np.ones((1)), sub_size=1, ) pix = al.RectangularMapper( pixels=9, shape=(3, 3), grid=grid, pixelization_grid=pixelization_grid, geometry=geometry, ) assert (pix.sub_mask_1d_index_to_pixelization_1d_index == np.array( [0, 1, 2, 3, 4, 5, 6, 7, 8])).all() assert pix.pixelization_1d_index_to_all_sub_mask_1d_indexes == [ [0], [1], [2], [3], [4], [5], [6], [7], [8], ]
def test__3x3_grid_of_pixel_grid__add_multiple_grid_to_1_pixel_pixel( self): # _ _ _ # -1.0 to -(1/3) |_|_|_| # -(1/3) to (1/3) |_|_|_| # (1/3) to 1.0 |_|_|_| pixelization_grid = np.array([ [1.0, -1.0], [0.0, 0.0], [1.0, 1.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [-1.0, -1.0], [0.0, 0.0], [-1.0, 1.0], ]) pix = al.pixelizations.Rectangular(shape=(3, 3)) geometry = pix.geometry_from_grid(grid=pixelization_grid) grid = MockPixelizationGrid( pixelization_grid, sub_mask_1d_index_to_mask_1d_index=np.ones((1)), sub_size=1, ) pix = al.RectangularMapper( pixels=9, shape=(3, 3), grid=grid, pixelization_grid=pixelization_grid, geometry=geometry, ) assert (pix.sub_mask_1d_index_to_pixelization_1d_index == np.array( [0, 4, 2, 4, 4, 4, 6, 4, 8])).all() assert pix.pixelization_1d_index_to_all_sub_mask_1d_indexes == [ [0], [], [2], [], [1, 3, 4, 5, 7], [], [6], [], [8], ]
def test__4x3_grid__change_arcsecond_dimensions__not_symmetric(self): # _ _ _ # |_|_|_| # |_|_|_| # |_|_|_| # |_|_|_| pixelization_grid = np.array([[1.0, -1.5], [1.0, -0.49], [0.49, -1.5], [-0.6, 0.0], [-1.0, 1.5]]) pix = al.pixelizations.Rectangular(shape=(4, 3)) geometry = pix.geometry_from_grid(grid=pixelization_grid) grid = MockPixelizationGrid( pixelization_grid, sub_mask_1d_index_to_mask_1d_index=np.ones((1)), sub_size=1, ) pix = al.RectangularMapper( pixels=12, shape=(4, 3), grid=grid, pixelization_grid=pixelization_grid, geometry=geometry, ) assert (pix.sub_mask_1d_index_to_pixelization_1d_index == np.array( [0, 1, 3, 10, 11])).all() assert pix.pixelization_1d_index_to_all_sub_mask_1d_indexes == [ [0], [1], [], [2], [], [], [], [], [], [], [3], [4], ]
def test__4x3_grid__non_symmetric_centre_shift(self): # _ _ _ # |_|_|_| # |_|_|_| # |_|_|_| # |_|_|_| pixelization_grid = np.array([[3.0, -0.5], [3.0, 0.51], [2.49, -0.5], [1.4, 1.0], [1.0, 2.5]]) pix = al.pixelizations.Rectangular(shape=(4, 3)) geometry = pix.geometry_from_grid(grid=pixelization_grid) grid = MockPixelizationGrid( pixelization_grid, sub_mask_1d_index_to_mask_1d_index=np.ones((1)), sub_size=1, ) pix = al.RectangularMapper( pixels=12, shape=(4, 3), grid=grid, pixelization_grid=pixelization_grid, geometry=geometry, ) assert (pix.sub_mask_1d_index_to_pixelization_1d_index == np.array( [0, 1, 3, 10, 11])).all() assert pix.pixelization_1d_index_to_all_sub_mask_1d_indexes == [ [0], [1], [], [2], [], [], [], [], [], [], [3], [4], ]
def test__3x3_grid__change_arcsecond_dimensions__not_symmetric(self): # _ _ _ # |_|_|_| Boundaries for pixels x = 0 and y = 0 -1.5 to -0.5 # |_|_|_| Boundaries for pixels x = 1 and y = 1 -0.5 to 0.5 # |_|_|_| Boundaries for pixels x = 2 and y = 2 0.5 to 1.5 pixelization_grid = np.array([[1.0, -1.5], [1.0, -0.49], [0.32, -1.5], [0.32, 0.51], [-1.0, 1.5]]) pix = al.pixelizations.Rectangular(shape=(3, 3)) geometry = pix.geometry_from_grid(grid=pixelization_grid) grid = MockPixelizationGrid( pixelization_grid, sub_mask_1d_index_to_mask_1d_index=np.ones((1)), sub_size=1, ) pix = al.RectangularMapper( pixels=9, shape=(3, 3), grid=grid, pixelization_grid=pixelization_grid, geometry=geometry, ) assert (pix.sub_mask_1d_index_to_pixelization_1d_index == np.array( [0, 1, 3, 5, 8])).all() assert pix.pixelization_1d_index_to_all_sub_mask_1d_indexes == [ [0], [1], [], [2], [], [3], [], [], [4], ]
def test__different_image_and_sub_grids(self): # _ _ _ # -1.0 to -(1/3) |_|_|_| # -(1/3) to (1/3) |_|_|_| # (1/3) to 1.0 |_|_|_| pixelization_grid = np.array([ [1.0, -1.0], [0.0, 0.0], [1.0, 1.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [-1.0, -1.0], [0.0, 0.0], [-1.0, 1.0], ]) pixelization_sub_grid = np.array([ [1.0, -1.0], [1.0, 0.0], [1.0, 1.0], [0.0, -1.0], [0.0, 0.0], [0.0, 1.0], [-1.0, -1.0], [-1.0, 0.0], [-1.0, 1.0], ]) pix = al.pixelizations.Rectangular(shape=(3, 3)) geometry = pix.geometry_from_grid(grid=pixelization_grid) grid = MockPixelizationGrid( pixelization_sub_grid, sub_mask_1d_index_to_mask_1d_index=np.ones((1)), sub_size=1, ) pix = al.RectangularMapper( pixels=9, shape=(3, 3), grid=grid, pixelization_grid=pixelization_grid, geometry=geometry, ) assert (pix.sub_mask_1d_index_to_pixelization_1d_index == np.array( [0, 1, 2, 3, 4, 5, 6, 7, 8])).all() assert pix.pixelization_1d_index_to_all_sub_mask_1d_indexes == [ [0], [1], [2], [3], [4], [5], [6], [7], [8], ]