Skip to content

Commit 5fb8793

Browse files
committed
Updated all autolens workspace / pipelines / howtolens to new autofit API
1 parent 27906a7 commit 5fb8793

9 files changed

Lines changed: 90 additions & 45 deletions

File tree

autoarray/operators/inversion/pixelizations.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,24 @@ def __repr__(self):
2424

2525

2626
class Rectangular(Pixelization):
27-
def __init__(self, shape=(3, 3)):
27+
def __init__(self, shp=(3, 3)):
2828
"""A rectangular pixelization, where pixels are defined on a Cartesian and uniform grid of shape \
2929
(rows, columns).
3030
3131
Like structures, the indexing of the rectangular grid begins in the top-left corner and goes right and down.
3232
3333
Parameters
3434
-----------
35-
shape : (int, int)
35+
shp : (int, int)
3636
The dimensions of the rectangular grid of pixels (y_pixels, x_pixel)
3737
"""
3838

39-
if shape[0] <= 2 or shape[1] <= 2:
39+
if shp[0] <= 2 or shp[1] <= 2:
4040
raise exc.PixelizationException(
4141
"The rectangular pixelization must be at least dimensions 3x3"
4242
)
4343

44-
self.shape = (int(shape[0]), int(shape[1]))
44+
self.shape = (int(shp[0]), int(shp[1]))
4545
self.pixels = self.shape[0] * self.shape[1]
4646
super(Rectangular, self).__init__()
4747

@@ -140,18 +140,18 @@ def mapper_from_grid_and_sparse_grid(
140140

141141

142142
class VoronoiMagnification(Voronoi):
143-
def __init__(self, shape=(3, 3)):
143+
def __init__(self, shp=(3, 3)):
144144
"""A pixelization which adapts to the magnification pattern of a lens's mass model and uses a Voronoi \
145145
pixelization to discretize the grid into pixels.
146146
147147
Parameters
148148
----------
149-
shape : (int, int)
149+
shp : (int, int)
150150
The shape of the unmasked sparse-grid which is laid over the masked image, in order to derive the \
151151
adaptive-magnification pixelization (see *ImagePlanePixelization*)
152152
"""
153153
super(VoronoiMagnification, self).__init__()
154-
self.shape = (int(shape[0]), int(shape[1]))
154+
self.shape = (int(shp[0]), int(shp[1]))
155155
self.pixels = self.shape[0] * self.shape[1]
156156

157157
def sparse_grid_from_grid(self, grid, hyper_image=None, seed=1):

autoarray/plotters/plotter_util.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,7 @@ def quantity_and_annuli_radii_from_minimum_and_maximum_radii_and_radii_points(
231231
return quantity_radii, annuli_radii
232232

233233

234-
def get_critical_curve_and_caustic(
235-
obj, include_critical_curves, include_caustics
236-
):
234+
def get_critical_curve_and_caustic(obj, include_critical_curves, include_caustics):
237235

238236
if include_critical_curves:
239237
critical_curves = obj.critical_curves

autoarray/structures/grids.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,10 @@ def bounding_box(cls, bounding_box, shape_2d, sub_size=1):
511511

512512
y_max, y_min, x_max, x_min = bounding_box
513513

514-
pixel_scales = ((y_max - y_min) / (shape_2d[0] - 1), (x_max - x_min) / (shape_2d[1] - 1))
514+
pixel_scales = (
515+
(y_max - y_min) / (shape_2d[0] - 1),
516+
(x_max - x_min) / (shape_2d[1] - 1),
517+
)
515518
origin = ((y_max + y_min) / 2.0, (x_max + x_min) / 2.0)
516519

517520
return cls.uniform(

test_autoarray/unit/operators/inversion/test_integration.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test__5_simple_grid__no_sub_grid(self):
3434
# There is no sub-grid, so our grid are just the masked_image grid (note the NumPy weighted_data structure
3535
# ensures this has no sub-gridding)
3636

37-
pix = aa.pix.Rectangular(shape=(3, 3))
37+
pix = aa.pix.Rectangular(shp=(3, 3))
3838

3939
mapper = pix.mapper_from_grid_and_sparse_grid(
4040
grid=grid,
@@ -139,7 +139,7 @@ def test__15_grid__no_sub_grid(self):
139139
mask=mask,
140140
)
141141

142-
pix = aa.pix.Rectangular(shape=(3, 3))
142+
pix = aa.pix.Rectangular(shp=(3, 3))
143143

144144
mapper = pix.mapper_from_grid_and_sparse_grid(
145145
grid=grid, sparse_grid=None, inversion_uses_border=False
@@ -261,7 +261,7 @@ def test__5_simple_grid__include_sub_grid(self):
261261
mask=mask,
262262
)
263263

264-
pix = aa.pix.Rectangular(shape=(3, 3))
264+
pix = aa.pix.Rectangular(shp=(3, 3))
265265

266266
mapper = pix.mapper_from_grid_and_sparse_grid(
267267
grid=grid, sparse_grid=None, inversion_uses_border=False
@@ -346,7 +346,7 @@ def test__grid__requires_border_relocation(self):
346346
mask=mask,
347347
)
348348

349-
pix = aa.pix.Rectangular(shape=(3, 3))
349+
pix = aa.pix.Rectangular(shp=(3, 3))
350350

351351
mapper = pix.mapper_from_grid_and_sparse_grid(
352352
grid=grid, sparse_grid=None, inversion_uses_border=False
@@ -426,7 +426,7 @@ def test__interferometer(self):
426426

427427
grid = aa.masked.grid.from_mask(mask=mask)
428428

429-
pix = aa.pix.Rectangular(shape=(7, 7))
429+
pix = aa.pix.Rectangular(shp=(7, 7))
430430

431431
mapper = pix.mapper_from_grid_and_sparse_grid(
432432
grid=grid, sparse_grid=None, inversion_uses_border=False
@@ -503,7 +503,7 @@ def test__3x3_simple_grid(self):
503503

504504
grid = aa.masked.grid.manual_1d(grid=grid, mask=mask)
505505

506-
pix = aa.pix.VoronoiMagnification(shape=(3, 3))
506+
pix = aa.pix.VoronoiMagnification(shp=(3, 3))
507507
sparse_grid = grids.SparseGrid.from_grid_and_unmasked_2d_grid_shape(
508508
grid=grid, unmasked_sparse_shape=pix.shape
509509
)
@@ -603,7 +603,7 @@ def test__3x3_simple_grid__include_mask(self):
603603

604604
grid = aa.masked.grid.manual_1d(grid=grid, mask=mask)
605605

606-
pix = aa.pix.VoronoiMagnification(shape=(3, 3))
606+
pix = aa.pix.VoronoiMagnification(shp=(3, 3))
607607
sparse_grid = grids.SparseGrid.from_grid_and_unmasked_2d_grid_shape(
608608
grid=grid, unmasked_sparse_shape=pix.shape
609609
)
@@ -714,7 +714,7 @@ def test__3x3_simple_grid__include_mask_and_sub_grid(self):
714714

715715
grid = aa.masked.grid.manual_1d(grid=grid, mask=mask)
716716

717-
pix = aa.pix.VoronoiMagnification(shape=(3, 3))
717+
pix = aa.pix.VoronoiMagnification(shp=(3, 3))
718718
sparse_grid = grids.SparseGrid.from_grid_and_unmasked_2d_grid_shape(
719719
grid=grid, unmasked_sparse_shape=pix.shape
720720
)
@@ -802,7 +802,7 @@ def test__3x3_simple_grid__include_mask_with_offset_centre(self):
802802

803803
grid = aa.masked.grid.manual_1d(grid=grid, mask=mask)
804804

805-
pix = aa.pix.VoronoiMagnification(shape=(3, 3))
805+
pix = aa.pix.VoronoiMagnification(shp=(3, 3))
806806
sparse_grid = grids.SparseGrid.from_grid_and_unmasked_2d_grid_shape(
807807
grid=grid, unmasked_sparse_shape=pix.shape
808808
)
@@ -888,7 +888,7 @@ def test__interferometer(self):
888888

889889
grid = aa.masked.grid.from_mask(mask=mask)
890890

891-
pix = aa.pix.VoronoiMagnification(shape=(7, 7))
891+
pix = aa.pix.VoronoiMagnification(shp=(7, 7))
892892

893893
sparse_grid = pix.sparse_grid_from_grid(grid=grid)
894894

test_autoarray/unit/operators/inversion/test_pixelizations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ class TestRectangular:
77
class TestGridIrregular:
88
def test__pixelization_grid_returns_none_as_not_used(self, sub_grid_7x7):
99

10-
pix = aa.pix.Rectangular(shape=(3, 3))
10+
pix = aa.pix.Rectangular(shp=(3, 3))
1111

1212
assert pix.sparse_grid_from_grid(grid=sub_grid_7x7) == None
1313

1414

1515
class TestVoronoiMagnification:
1616
def test__number_of_pixels_setup_correct(self):
1717

18-
pix = aa.pix.VoronoiMagnification(shape=(3, 3))
18+
pix = aa.pix.VoronoiMagnification(shp=(3, 3))
1919

2020
assert pix.shape == (3, 3)
2121

2222
def test__pixelization_grid_returns_same_as_computed_from_grids_module(
2323
self, sub_grid_7x7
2424
):
2525

26-
pix = aa.pix.VoronoiMagnification(shape=(3, 3))
26+
pix = aa.pix.VoronoiMagnification(shp=(3, 3))
2727

2828
pixelization_grid = pix.sparse_grid_from_grid(grid=sub_grid_7x7)
2929

test_autoarray/unit/plotters/test_mapper_plotters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def make_grid():
3333

3434
@pytest.fixture(name="rectangular_pixelization")
3535
def make_rectangular_pixelization():
36-
return aa.pix.Rectangular(shape=(25, 25))
36+
return aa.pix.Rectangular(shp=(25, 25))
3737

3838

3939
@pytest.fixture(name="rectangular_mapper")

test_autoarray/unit/structures/test_grids.py

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,31 +241,77 @@ def test__grid__makes_scaled_sub_grid_with_pixel_scale_and_sub_size(self):
241241
assert grid.sub_size == 2
242242

243243
class TestGridBoundingBox:
244-
def test__grid_bounding_box__uniform_box__makes_grid_with_correct_pixel_scales_and_origin(self):
244+
def test__grid_bounding_box__uniform_box__makes_grid_with_correct_pixel_scales_and_origin(
245+
self
246+
):
245247

246-
grid = aa.grid.bounding_box(bounding_box=[2.0, -2.0, 2.0, -2.0], shape_2d=(3, 3))
248+
grid = aa.grid.bounding_box(
249+
bounding_box=[2.0, -2.0, 2.0, -2.0], shape_2d=(3, 3)
250+
)
247251

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()
252+
assert (
253+
grid.in_1d
254+
== np.array(
255+
[
256+
[2.0, -2.0],
257+
[2.0, 0.0],
258+
[2.0, 2.0],
259+
[0.0, -2.0],
260+
[0.0, 0.0],
261+
[0.0, 2.0],
262+
[-2.0, -2.0],
263+
[-2.0, 0.0],
264+
[-2.0, 2.0],
265+
]
266+
)
267+
).all()
251268
assert grid.pixel_scales == (2.0, 2.0)
252269
assert grid.origin == (0.0, 0.0)
253270

254-
grid = aa.grid.bounding_box(bounding_box=[2.0, -2.0, 2.0, -2.0], shape_2d=(2, 3))
271+
grid = aa.grid.bounding_box(
272+
bounding_box=[2.0, -2.0, 2.0, -2.0], shape_2d=(2, 3)
273+
)
255274

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()
275+
assert (
276+
grid.in_1d
277+
== np.array(
278+
[
279+
[2.0, -2.0],
280+
[2.0, 0.0],
281+
[2.0, 2.0],
282+
[-2.0, -2.0],
283+
[-2.0, 0.0],
284+
[-2.0, 2.0],
285+
]
286+
)
287+
).all()
258288
assert grid.pixel_scales == (4.0, 2.0)
259289
assert grid.origin == (0.0, 0.0)
260290

261-
grid = aa.grid.bounding_box(bounding_box=[10.0, 8.0, 3.0, -2.0], shape_2d=(3, 3))
291+
grid = aa.grid.bounding_box(
292+
bounding_box=[10.0, 8.0, 3.0, -2.0], shape_2d=(3, 3)
293+
)
262294

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)
295+
assert grid.in_1d == pytest.approx(
296+
np.array(
297+
[
298+
[10.0, -2.0],
299+
[10.0, 0.5],
300+
[10.0, 3.0],
301+
[9.0, -2.0],
302+
[9.0, 0.5],
303+
[9.0, 3.0],
304+
[8.0, -2.0],
305+
[8.0, 0.5],
306+
[8.0, 3.0],
307+
]
308+
),
309+
1.0e-4,
310+
)
266311
assert grid.pixel_scales == (1.0, 2.5)
267312
assert grid.origin == (9.0, 0.5)
268313

314+
269315
class TestGridMaskedAPI:
270316
class TestManual:
271317
def test__grid__makes_scaled_grid_with_pixel_scale(self):

test_autoarray/unit/test_files/config/general.ini

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ cache = True
1717
parallel = False
1818

1919
[calculation_grid]
20-
shape_2d = (101, 101)
21-
pixel_scales = 0.05
22-
sub_size = 4
20+
convergence_threshold = 0.05
21+
pixels = 401
2322

2423
[inversion]
2524
inversion_pixel_limit_overall = 3000

test_autoarray/unit/test_files/config/priors/default/pixelizations.ini

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
[Rectangular]
2-
shape_0 = u,20,45
3-
shape_1 = u,20,45
2+
shp_0 = u,20,45
3+
shp_1 = u,20,45
44

55
[VoronoiMagnification]
6-
shape_0 = u,20,45
7-
shape_1 = u,20,45
8-
6+
shp_0 = u,20,45
7+
shp_1 = u,20,45
98
[VoronoiBrightnessImage]
109
pixels = u,50,1500
1110
weight_floor = u,0.0,1.0

0 commit comments

Comments
 (0)