@@ -200,3 +200,53 @@ def test__edges_transformed(mask_2d_7x7):
200200 ),
201201 abs = 1e-8 ,
202202 )
203+
204+
205+ def test__edges_transformed__aligned_with_interpolation_node_convention ():
206+ """
207+ Regression test for issue #372: the pcolormesh plotting path draws value
208+ (row r, col c) inside the cell bounded by edges_transformed — that cell
209+ must be centred on the interpolation mapper's node for that value, not on
210+ a uniform [0, 1] partition (which shifted plots by ~1.5 mesh pixels).
211+
212+ A delta function scattered through the mapper must land in plotted cells
213+ whose weighted centroid matches the input point to sub-cell precision.
214+ """
215+ from autoarray .inversion .mesh .interpolator .rectangular import (
216+ adaptive_rectangular_mappings_weights_via_interpolation_from ,
217+ adaptive_rectangular_transformed_grid_from ,
218+ )
219+
220+ n = 10
221+ rng = np .random .default_rng (0 )
222+ data_grid = rng .uniform (- 1.0 , 1.0 , (5000 , 2 ))
223+ test_point = np .array ([[0.3 , - 0.2 ]])
224+
225+ flat_indices , weights = (
226+ adaptive_rectangular_mappings_weights_via_interpolation_from (
227+ source_grid_size = n ,
228+ data_grid = data_grid ,
229+ data_grid_over_sampled = test_point ,
230+ )
231+ )
232+
233+ # The node-midpoint unit-space edges (what edges_transformed now builds),
234+ # pushed through the same CDF transform.
235+ rows = np .arange (n + 1 )
236+ edges_y = (n - rows - 0.5 ) / (n - 3 )
237+ edges_x = (rows - 1.5 ) / (n - 3 )
238+ edges = np .stack ([edges_y , edges_x ]).T
239+ edges_t = adaptive_rectangular_transformed_grid_from (data_grid , edges )
240+ y_edges , x_edges = edges_t .T
241+
242+ centroid_y = 0.0
243+ centroid_x = 0.0
244+ for flat , weight in zip (flat_indices [0 ], weights [0 ]):
245+ r , c = flat // n , flat % n
246+ centroid_y += weight * 0.5 * (y_edges [r ] + y_edges [r + 1 ])
247+ centroid_x += weight * 0.5 * (x_edges [c ] + x_edges [c + 1 ])
248+
249+ # Half a mesh cell in these units is ~0.15; the pre-fix uniform edges
250+ # missed by ~0.4 in y.
251+ assert centroid_y == pytest .approx (test_point [0 , 0 ], abs = 0.1 )
252+ assert centroid_x == pytest .approx (test_point [0 , 1 ], abs = 0.1 )
0 commit comments