@@ -64,6 +64,179 @@ def test__fast_chi_squared(
6464 assert inversion .fast_chi_squared == pytest .approx (chi_squared , 1.0e-4 )
6565
6666
67+ def test__operated_mapping_matrix_list__override_is_honored ():
68+ mask = aa .Mask2D (
69+ mask = [
70+ [True , True , True , True , True , True , True ],
71+ [True , True , True , True , True , True , True ],
72+ [True , True , True , False , True , True , True ],
73+ [True , True , False , False , False , True , True ],
74+ [True , True , True , False , True , True , True ],
75+ [True , True , True , True , True , True , True ],
76+ [True , True , True , True , True , True , True ],
77+ ],
78+ pixel_scales = 2.0 ,
79+ )
80+
81+ n_visibilities = 5
82+ rng = np .random .default_rng (seed = 0 )
83+ data = aa .Visibilities (
84+ visibilities = rng .normal (size = (n_visibilities , 2 )).astype (np .float64 )
85+ )
86+ noise_map = aa .VisibilitiesNoiseMap (
87+ visibilities = np .ones ((n_visibilities , 2 ), dtype = np .float64 )
88+ )
89+ uv_wavelengths = rng .normal (size = (n_visibilities , 2 )).astype (np .float64 )
90+
91+ dataset = aa .Interferometer (
92+ data = data ,
93+ noise_map = noise_map ,
94+ uv_wavelengths = uv_wavelengths ,
95+ real_space_mask = mask ,
96+ transformer_class = aa .TransformerDFT ,
97+ )
98+
99+ mapping_matrix = np .ones ((mask .pixels_in_mask , 1 ))
100+ override = (999.0 + 1.0j ) * np .ones ((n_visibilities , 1 ))
101+
102+ linear_obj_override = aa .m .MockLinearObjFuncList (
103+ parameters = 1 ,
104+ mapping_matrix = mapping_matrix ,
105+ operated_mapping_matrix_override = override ,
106+ )
107+ linear_obj_no_override = aa .m .MockLinearObjFuncList (
108+ parameters = 1 ,
109+ mapping_matrix = mapping_matrix ,
110+ )
111+
112+ inversion = aa .Inversion (
113+ dataset = dataset ,
114+ linear_obj_list = [linear_obj_override , linear_obj_no_override ],
115+ )
116+
117+ operated_mapping_matrix_list = inversion .operated_mapping_matrix_list
118+
119+ assert operated_mapping_matrix_list [0 ] == pytest .approx (override , 1.0e-8 )
120+
121+ transformed_mapping_matrix = dataset .transformer .transform_mapping_matrix (
122+ mapping_matrix = mapping_matrix
123+ )
124+
125+ assert operated_mapping_matrix_list [1 ] == pytest .approx (
126+ transformed_mapping_matrix , 1.0e-8
127+ )
128+
129+ assert inversion .operated_mapping_matrix [:, 0 ] == pytest .approx (
130+ override [:, 0 ], 1.0e-8
131+ )
132+ assert inversion .curvature_matrix .shape == (2 , 2 )
133+ assert inversion .data_vector .shape == (2 ,)
134+
135+
136+ def test__operated_mapping_matrix_override__wrong_shape_raises ():
137+ mask = aa .Mask2D (
138+ mask = [
139+ [True , True , True , True , True , True , True ],
140+ [True , True , True , True , True , True , True ],
141+ [True , True , True , False , True , True , True ],
142+ [True , True , False , False , False , True , True ],
143+ [True , True , True , False , True , True , True ],
144+ [True , True , True , True , True , True , True ],
145+ [True , True , True , True , True , True , True ],
146+ ],
147+ pixel_scales = 2.0 ,
148+ )
149+
150+ n_visibilities = 7
151+ rng = np .random .default_rng (seed = 0 )
152+ data = aa .Visibilities (
153+ visibilities = rng .normal (size = (n_visibilities , 2 )).astype (np .float64 )
154+ )
155+ noise_map = aa .VisibilitiesNoiseMap (
156+ visibilities = np .ones ((n_visibilities , 2 ), dtype = np .float64 )
157+ )
158+ uv_wavelengths = rng .normal (size = (n_visibilities , 2 )).astype (np .float64 )
159+
160+ dataset = aa .Interferometer (
161+ data = data ,
162+ noise_map = noise_map ,
163+ uv_wavelengths = uv_wavelengths ,
164+ real_space_mask = mask ,
165+ transformer_class = aa .TransformerDFT ,
166+ )
167+
168+ # A real-space shaped override (e.g. [total_mask_pixels, params]) is not valid for an
169+ # interferometer inversion, whose override must be in visibility space.
170+ linear_obj = aa .m .MockLinearObjFuncList (
171+ parameters = 1 ,
172+ mapping_matrix = np .ones ((mask .pixels_in_mask , 1 )),
173+ operated_mapping_matrix_override = np .ones ((mask .pixels_in_mask , 1 )),
174+ )
175+
176+ inversion = aa .Inversion (dataset = dataset , linear_obj_list = [linear_obj ])
177+
178+ with pytest .raises (aa .exc .InversionException ):
179+ inversion .operated_mapping_matrix_list
180+
181+
182+ def test__operated_mapping_matrix_override__sparse_operator_raises ():
183+ mask = aa .Mask2D (
184+ mask = [
185+ [True , True , True , True , True , True , True ],
186+ [True , True , True , True , True , True , True ],
187+ [True , True , True , False , True , True , True ],
188+ [True , True , False , False , False , True , True ],
189+ [True , True , True , False , True , True , True ],
190+ [True , True , True , True , True , True , True ],
191+ [True , True , True , True , True , True , True ],
192+ ],
193+ pixel_scales = 2.0 ,
194+ )
195+
196+ grid = aa .Grid2D .from_mask (mask = mask , over_sample_size = 1 )
197+
198+ mesh = aa .mesh .Delaunay (pixels = 9 )
199+ image_mesh = aa .image_mesh .Overlay (shape = (3 , 3 ))
200+ image_mesh_grid = image_mesh .image_plane_mesh_grid_from (mask = mask , adapt_data = None )
201+
202+ interpolator = mesh .interpolator_from (
203+ source_plane_data_grid = grid ,
204+ source_plane_mesh_grid = image_mesh_grid ,
205+ )
206+ mapper = aa .Mapper (interpolator = interpolator )
207+
208+ n_visibilities = 5
209+ rng = np .random .default_rng (seed = 0 )
210+ data = aa .Visibilities (
211+ visibilities = rng .normal (size = (n_visibilities , 2 )).astype (np .float64 )
212+ )
213+ noise_map = aa .VisibilitiesNoiseMap (
214+ visibilities = np .ones ((n_visibilities , 2 ), dtype = np .float64 )
215+ )
216+ uv_wavelengths = rng .normal (size = (n_visibilities , 2 )).astype (np .float64 )
217+
218+ dataset_sparse = aa .Interferometer (
219+ data = data ,
220+ noise_map = noise_map ,
221+ uv_wavelengths = uv_wavelengths ,
222+ real_space_mask = mask ,
223+ transformer_class = aa .TransformerDFT ,
224+ ).apply_sparse_operator (use_jax = False )
225+
226+ linear_obj = aa .m .MockLinearObjFuncList (
227+ parameters = 1 ,
228+ mapping_matrix = np .ones ((mask .pixels_in_mask , 1 )),
229+ operated_mapping_matrix_override = (999.0 + 1.0j )
230+ * np .ones ((n_visibilities , 1 )),
231+ )
232+
233+ with pytest .raises (aa .exc .InversionException ):
234+ aa .Inversion (
235+ dataset = dataset_sparse ,
236+ linear_obj_list = [mapper , linear_obj ],
237+ )
238+
239+
67240def test__curvature_matrix__interferometer_sparse_operator__delaunay__identical_to_mapping ():
68241 mask = aa .Mask2D (
69242 mask = [
0 commit comments