@@ -17,6 +17,7 @@ def __init__(
1717 lensing_potential : np .ndarray ,
1818 image_plane_grid : aa .type .Grid2DLike ,
1919 mask : aa .type .Mask2D ,
20+ extrapolate : str = "nearest" ,
2021 Hy : Optional [spmatrix ] = None ,
2122 Hx : Optional [spmatrix ] = None ,
2223 Hyy : Optional [spmatrix ] = None ,
@@ -54,6 +55,14 @@ def __init__(
5455 ``aa.util.derivative.cleaned_mask_from``); its ``pixel_scale``
5556 sets the finite-difference step of the derived deflections and
5657 convergence.
58+ extrapolate
59+ The extrapolation behaviour outside the unmasked pixels' convex
60+ hull: ``"nearest"`` (default; the field continues beyond the
61+ grid) or ``"zero"`` (the field vanishes outside it — required
62+ when the profile represents a localized correction on a
63+ sub-region of a larger grid, e.g. an arc-restricted dpsi mesh,
64+ where nearest extrapolation would produce spurious constant
65+ deflections everywhere else).
5766 Hy
5867 The sparse first-derivative operator along y of the mask; built
5968 from the mask if not input.
@@ -72,6 +81,7 @@ def __init__(
7281 self .lensing_potential = np .asarray (lensing_potential )
7382 self .image_plane_grid = np .asarray (image_plane_grid )
7483 self .mask = mask
84+ self .extrapolate = extrapolate
7585 self .Hy = Hy
7686 self .Hx = Hx
7787 self .Hyy = Hyy
@@ -96,10 +106,10 @@ def _build_interpolators(self):
96106 ) * 0.5
97107
98108 self .tri = Delaunay (np .fliplr (self .image_plane_grid ))
99- self .interp_psi = LinearNDInterpolatorExt (self .tri , self .lensing_potential )
100- self .interp_defl_y = LinearNDInterpolatorExt (self .tri , self .deflections_y )
101- self .interp_defl_x = LinearNDInterpolatorExt (self .tri , self .deflections_x )
102- self .interp_kappa = LinearNDInterpolatorExt (self .tri , self .convergence_slim )
109+ self .interp_psi = LinearNDInterpolatorExt (self .tri , fill = self . extrapolate , values = self .lensing_potential )
110+ self .interp_defl_y = LinearNDInterpolatorExt (self .tri , fill = self . extrapolate , values = self .deflections_y )
111+ self .interp_defl_x = LinearNDInterpolatorExt (self .tri , fill = self . extrapolate , values = self .deflections_x )
112+ self .interp_kappa = LinearNDInterpolatorExt (self .tri , fill = self . extrapolate , values = self .convergence_slim )
103113
104114 @aa .decorators .to_array
105115 def convergence_2d_from (self , grid : aa .type .Grid2DLike , xp = np , ** kwargs ):
0 commit comments