Skip to content

Commit 79a1b30

Browse files
committed
Adaptive grid for computation of LensingObject quantities implemented.
1 parent aafe773 commit 79a1b30

5 files changed

Lines changed: 56 additions & 13 deletions

File tree

autoarray/operators/inversion/regularization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def __init__(self):
123123
"""
124124

125125

126-
class instance(Regularization):
126+
class Constant(Regularization):
127127
def __init__(self, coefficient=1.0):
128128
"""A instance-regularization scheme (regularization is described in the *Regularization* class above).
129129
@@ -143,7 +143,7 @@ def __init__(self, coefficient=1.0):
143143
The regularization coefficient which controls the degree of smooth of the inversion reconstruction.
144144
"""
145145
self.coefficient = coefficient
146-
super(instance, self).__init__()
146+
super(Constant, self).__init__()
147147

148148
def regularization_weights_from_mapper(self, mapper):
149149
return self.coefficient * np.ones(mapper.pixelization_grid.pixels)

autoarray/structures/grids.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,21 @@ def uniform(cls, shape_2d, pixel_scales=None, sub_size=1, origin=(0.0, 0.0)):
506506
origin=origin,
507507
)
508508

509+
@classmethod
510+
def bounding_box(cls, bounding_box, shape_2d, sub_size=1):
511+
512+
y_max, y_min, x_max, x_min = bounding_box
513+
514+
pixel_scales = ((y_max - y_min) / (shape_2d[0] - 1), (x_max - x_min) / (shape_2d[1] - 1))
515+
origin = ((y_max + y_min) / 2.0, (x_max + x_min) / 2.0)
516+
517+
return cls.uniform(
518+
shape_2d=shape_2d,
519+
pixel_scales=pixel_scales,
520+
sub_size=sub_size,
521+
origin=origin,
522+
)
523+
509524
@classmethod
510525
def from_mask(cls, mask):
511526
"""Setup a sub-grid of the unmasked pixels, using a mask and a specified sub-grid size. The center of \
@@ -683,6 +698,9 @@ class IrregularMapping(object):
683698
def __init__(self):
684699
pass
685700

701+
def array_from_sub_array_1d(self, sub_array_1d):
702+
return sub_array_1d
703+
686704
def grid_from_sub_grid_1d(self, sub_grid_1d):
687705
return GridIrregular(grid=sub_grid_1d)
688706

test_autoarray/unit/operators/inversion/test_integration.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test__5_simple_grid__no_sub_grid(self):
6262
assert mapper.shape_2d == (3, 3)
6363
assert (mapper.hyper_image == np.ones((2, 2))).all()
6464

65-
reg = aa.reg.instance(coefficient=1.0)
65+
reg = aa.reg.Constant(coefficient=1.0)
6666
regularization_matrix = reg.regularization_matrix_from_mapper(mapper=mapper)
6767

6868
assert (
@@ -175,7 +175,7 @@ def test__15_grid__no_sub_grid(self):
175175
).all()
176176
assert mapper.shape_2d == (3, 3)
177177

178-
reg = aa.reg.instance(coefficient=1.0)
178+
reg = aa.reg.Constant(coefficient=1.0)
179179
regularization_matrix = reg.regularization_matrix_from_mapper(mapper=mapper)
180180

181181
assert (
@@ -287,7 +287,7 @@ def test__5_simple_grid__include_sub_grid(self):
287287
).all()
288288
assert mapper.shape_2d == (3, 3)
289289

290-
reg = aa.reg.instance(coefficient=1.0)
290+
reg = aa.reg.Constant(coefficient=1.0)
291291
regularization_matrix = reg.regularization_matrix_from_mapper(mapper=mapper)
292292

293293
assert (
@@ -372,7 +372,7 @@ def test__grid__requires_border_relocation(self):
372372
).all()
373373
assert mapper.shape_2d == (3, 3)
374374

375-
reg = aa.reg.instance(coefficient=1.0)
375+
reg = aa.reg.Constant(coefficient=1.0)
376376
regularization_matrix = reg.regularization_matrix_from_mapper(mapper=mapper)
377377

378378
assert (
@@ -432,7 +432,7 @@ def test__interferometer(self):
432432
grid=grid, sparse_grid=None, inversion_uses_border=False
433433
)
434434

435-
reg = aa.reg.instance(coefficient=0.0)
435+
reg = aa.reg.Constant(coefficient=0.0)
436436

437437
visibilities = aa.visibilities.manual_1d(
438438
visibilities=[
@@ -547,7 +547,7 @@ def test__3x3_simple_grid(self):
547547
)
548548
).all()
549549

550-
reg = aa.reg.instance(coefficient=1.0)
550+
reg = aa.reg.Constant(coefficient=1.0)
551551
regularization_matrix = reg.regularization_matrix_from_mapper(mapper=mapper)
552552

553553
assert (
@@ -639,7 +639,7 @@ def test__3x3_simple_grid__include_mask(self):
639639
)
640640
).all()
641641

642-
reg = aa.reg.instance(coefficient=1.0)
642+
reg = aa.reg.Constant(coefficient=1.0)
643643
regularization_matrix = reg.regularization_matrix_from_mapper(mapper=mapper)
644644

645645
assert (
@@ -748,7 +748,7 @@ def test__3x3_simple_grid__include_mask_and_sub_grid(self):
748748
)
749749
).all()
750750

751-
reg = aa.reg.instance(coefficient=1.0)
751+
reg = aa.reg.Constant(coefficient=1.0)
752752
regularization_matrix = reg.regularization_matrix_from_mapper(mapper=mapper)
753753

754754
assert (
@@ -838,7 +838,7 @@ def test__3x3_simple_grid__include_mask_with_offset_centre(self):
838838
)
839839
).all()
840840

841-
reg = aa.reg.instance(coefficient=1.0)
841+
reg = aa.reg.Constant(coefficient=1.0)
842842
regularization_matrix = reg.regularization_matrix_from_mapper(mapper=mapper)
843843

844844
assert (
@@ -896,7 +896,7 @@ def test__interferometer(self):
896896
grid=grid, sparse_grid=sparse_grid, inversion_uses_border=False
897897
)
898898

899-
reg = aa.reg.instance(coefficient=0.0)
899+
reg = aa.reg.Constant(coefficient=0.0)
900900

901901
visibilities = aa.visibilities.manual_1d(
902902
visibilities=[

test_autoarray/unit/operators/inversion/test_regularization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test__regularization_matrix__compare_to_regularization_util(self):
2929

3030
mapper = MockRegMapper(pixelization_grid=pixelization_grid)
3131

32-
reg = aa.reg.instance(coefficient=1.0)
32+
reg = aa.reg.Constant(coefficient=1.0)
3333
regularization_matrix = reg.regularization_matrix_from_mapper(mapper=mapper)
3434

3535
regularization_matrix_util = aa.util.regularization.instance_regularization_matrix_from_pixel_neighbors(

test_autoarray/unit/structures/test_grids.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,31 @@ def test__grid__makes_scaled_sub_grid_with_pixel_scale_and_sub_size(self):
240240
assert grid.origin == (0.0, 0.0)
241241
assert grid.sub_size == 2
242242

243+
class TestGridBoundingBox:
244+
def test__grid_bounding_box__uniform_box__makes_grid_with_correct_pixel_scales_and_origin(self):
245+
246+
grid = aa.grid.bounding_box(bounding_box=[2.0, -2.0, 2.0, -2.0], shape_2d=(3, 3))
247+
248+
assert (grid.in_1d == np.array([[2.0, -2.0], [2.0, 0.0], [2.0, 2.0],
249+
[0.0, -2.0], [0.0, 0.0], [0.0, 2.0],
250+
[-2.0, -2.0], [-2.0, 0.0], [-2.0, 2.0]])).all()
251+
assert grid.pixel_scales == (2.0, 2.0)
252+
assert grid.origin == (0.0, 0.0)
253+
254+
grid = aa.grid.bounding_box(bounding_box=[2.0, -2.0, 2.0, -2.0], shape_2d=(2, 3))
255+
256+
assert (grid.in_1d == np.array([[2.0, -2.0], [2.0, 0.0], [2.0, 2.0],
257+
[-2.0, -2.0], [-2.0, 0.0], [-2.0, 2.0]])).all()
258+
assert grid.pixel_scales == (4.0, 2.0)
259+
assert grid.origin == (0.0, 0.0)
260+
261+
grid = aa.grid.bounding_box(bounding_box=[10.0, 8.0, 3.0, -2.0], shape_2d=(3, 3))
262+
263+
assert grid.in_1d == pytest.approx(np.array([[10.0, -2.0], [10.0, 0.5], [10.0, 3.0],
264+
[9.0, -2.0], [9.0, 0.5], [9.0, 3.0],
265+
[8.0, -2.0], [8.0, 0.5], [8.0, 3.0]]), 1.0e-4)
266+
assert grid.pixel_scales == (1.0, 2.5)
267+
assert grid.origin == (9.0, 0.5)
243268

244269
class TestGridMaskedAPI:
245270
class TestManual:

0 commit comments

Comments
 (0)