Skip to content

Commit 07b0447

Browse files
Jammy2211Jammy2211
authored andcommitted
mega refactor done
1 parent 4cc87d4 commit 07b0447

File tree

73 files changed

+384
-885
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+384
-885
lines changed

autoarray/__init__.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,21 @@
2323
from .fit.fit_imaging import FitImaging
2424
from .fit.fit_interferometer import FitInterferometer
2525
from .geometry.geometry_2d import Geometry2D
26-
from .inversion.pixelization.mappers.abstract import AbstractMapper
27-
from .inversion.pixelization import mesh
28-
from .inversion.pixelization import image_mesh
26+
from .inversion.mesh import mesh
27+
from .inversion.mesh import image_mesh
2928
from .inversion import regularization as reg
3029
from .settings import Settings
3130
from .inversion.inversion.abstract import AbstractInversion
3231
from .inversion.regularization.abstract import AbstractRegularization
3332
from .inversion.inversion.factory import inversion_from as Inversion
3433
from .inversion.inversion.dataset_interface import DatasetInterface
35-
from .inversion.pixelization.border_relocator import BorderRelocator
36-
from .inversion.pixelization.pixelization import Pixelization
37-
from .inversion.pixelization.mappers.abstract import AbstractMapper
38-
from .inversion.pixelization.mappers.rectangular import MapperRectangular
39-
from .inversion.pixelization.mappers.delaunay import MapperDelaunay
40-
from .inversion.pixelization.mappers.rectangular_uniform import MapperRectangularUniform
41-
from .inversion.pixelization.mappers.knn import MapperKNNInterpolator
42-
from .inversion.pixelization.image_mesh.abstract import AbstractImageMesh
43-
from .inversion.pixelization.mesh.abstract import AbstractMesh
44-
from .inversion.pixelization.interpolator.rectangular import InterpolatorRectangular
45-
from .inversion.pixelization.interpolator.delaunay import InterpolatorDelaunay
34+
from .inversion.mesh.border_relocator import BorderRelocator
35+
from .inversion.pixelization import Pixelization
36+
from .inversion.mappers.abstract import Mapper
37+
from .inversion.mesh.image_mesh.abstract import AbstractImageMesh
38+
from .inversion.mesh.mesh.abstract import AbstractMesh
39+
from .inversion.mesh.interpolator.rectangular import InterpolatorRectangular
40+
from .inversion.mesh.interpolator.delaunay import InterpolatorDelaunay
4641
from .inversion.inversion.imaging.mapping import InversionImagingMapping
4742
from .inversion.inversion.imaging.sparse import InversionImagingSparse
4843
from .inversion.inversion.imaging.inversion_imaging_util import ImagingSparseOperator
@@ -78,10 +73,10 @@
7873
from .structures.grids.uniform_2d import Grid2D
7974
from .operators.over_sampling.over_sampler import OverSampler
8075
from .structures.grids.irregular_2d import Grid2DIrregular
81-
from .inversion.pixelization.mesh_geometry.rectangular import MeshGeometryRectangular
82-
from .inversion.pixelization.mesh_geometry.delaunay import MeshGeometryDelaunay
83-
from .inversion.pixelization.interpolator.rectangular import InterpolatorRectangular
84-
from .inversion.pixelization.interpolator.delaunay import InterpolatorDelaunay
76+
from .inversion.mesh.mesh_geometry.rectangular import MeshGeometryRectangular
77+
from .inversion.mesh.mesh_geometry.delaunay import MeshGeometryDelaunay
78+
from .inversion.mesh.interpolator.rectangular import InterpolatorRectangular
79+
from .inversion.mesh.interpolator.delaunay import InterpolatorDelaunay
8580
from .structures.arrays.kernel_2d import Kernel2D
8681
from .structures.vectors.uniform import VectorYX2D
8782
from .structures.vectors.irregular import VectorYX2DIrregular

autoarray/dataset/grids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from autoarray.structures.arrays.kernel_2d import Kernel2D
66
from autoarray.structures.grids.uniform_2d import Grid2D
77

8-
from autoarray.inversion.pixelization.border_relocator import BorderRelocator
8+
from autoarray.inversion.mesh.border_relocator import BorderRelocator
99

1010
from autoarray import exc
1111

autoarray/fixtures.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ def make_border_relocator_2d_7x7():
365365

366366
def make_rectangular_mapper_7x7_3x3():
367367

368-
from autoarray.inversion.pixelization.mesh.rectangular_adapt_density import (
368+
from autoarray.inversion.mesh.mesh.rectangular_adapt_density import (
369369
overlay_grid_from,
370370
)
371371

@@ -377,13 +377,14 @@ def make_rectangular_mapper_7x7_3x3():
377377

378378
mesh = aa.mesh.RectangularUniform(shape=shape_native)
379379

380-
return mesh.mapper_from(
381-
mask=make_mask_2d_7x7(),
380+
interpolator = mesh.interpolator_from(
382381
source_plane_data_grid=make_grid_2d_sub_2_7x7(),
383382
source_plane_mesh_grid=aa.Grid2DIrregular(source_plane_mesh_grid),
384-
image_plane_mesh_grid=None,
385383
adapt_data=aa.Array2D.ones(shape_native, pixel_scales=0.1),
386-
border_relocator=None,
384+
)
385+
386+
return aa.Mapper(
387+
interpolator=interpolator,
387388
regularization=make_regularization_constant(),
388389
)
389390

@@ -408,14 +409,16 @@ def make_delaunay_mapper_9_3x3():
408409

409410
mesh = aa.mesh.Delaunay()
410411

411-
return mesh.mapper_from(
412-
mask=make_mask_2d_7x7(),
412+
interpolator = mesh.interpolator_from(
413413
source_plane_data_grid=make_grid_2d_sub_2_7x7(),
414414
source_plane_mesh_grid=grid_9,
415-
image_plane_mesh_grid=aa.Grid2D.uniform(shape_native=(3, 3), pixel_scales=0.1),
416415
adapt_data=aa.Array2D.ones(shape_native=(3, 3), pixel_scales=0.1),
417-
border_relocator=None,
416+
)
417+
418+
return aa.Mapper(
419+
interpolator=interpolator,
418420
regularization=make_regularization_constant(),
421+
image_plane_mesh_grid=aa.Grid2D.uniform(shape_native=(3, 3), pixel_scales=0.1),
419422
)
420423

421424

@@ -439,14 +442,16 @@ def make_knn_mapper_9_3x3():
439442

440443
mesh = aa.mesh.KNearestNeighbor(split_neighbor_division=1)
441444

442-
return mesh.mapper_from(
443-
mask=make_mask_2d_7x7(),
445+
interpolator = mesh.interpolator_from(
444446
source_plane_data_grid=make_grid_2d_sub_2_7x7(),
445447
source_plane_mesh_grid=grid_9,
446-
image_plane_mesh_grid=aa.Grid2D.uniform(shape_native=(3, 3), pixel_scales=0.1),
447448
adapt_data=aa.Array2D.ones(shape_native=(3, 3), pixel_scales=0.1),
448-
border_relocator=None,
449+
)
450+
451+
return aa.Mapper(
452+
interpolator=interpolator,
449453
regularization=make_regularization_constant(),
454+
image_plane_mesh_grid=aa.Grid2D.uniform(shape_native=(3, 3), pixel_scales=0.1),
450455
)
451456

452457

autoarray/inversion/inversion/abstract.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from autoarray.dataset.interferometer.dataset import Interferometer
1010
from autoarray.inversion.inversion.dataset_interface import DatasetInterface
1111
from autoarray.inversion.linear_obj.linear_obj import LinearObj
12-
from autoarray.inversion.pixelization.mappers.abstract import AbstractMapper
12+
from autoarray.inversion.mappers.abstract import Mapper
1313
from autoarray.inversion.regularization.abstract import AbstractRegularization
1414
from autoarray.settings import Settings
1515
from autoarray.preloads import Preloads
@@ -143,7 +143,7 @@ def param_range_list_from(self, cls: Type) -> List[List[int]]:
143143
- The first `Mapper` values are in the entries `[3:103]`.
144144
- The second `Mapper` values are in the entries `[103:303]
145145
146-
For this example, `param_range_list_from(cls=AbstractMapper)` therefore returns the
146+
For this example, `param_range_list_from(cls=Mapper)` therefore returns the
147147
list `[[3, 103], [103, 303]]`.
148148
149149
Parameters
@@ -239,7 +239,7 @@ def mapper_indices(self) -> np.ndarray:
239239

240240
mapper_indices = []
241241

242-
param_range_list = self.param_range_list_from(cls=AbstractMapper)
242+
param_range_list = self.param_range_list_from(cls=Mapper)
243243

244244
for param_range in param_range_list:
245245

@@ -713,7 +713,7 @@ def regularization_weights_from(self, index: int) -> np.ndarray:
713713
def regularization_weights_mapper_dict(self) -> Dict[LinearObj, np.ndarray]:
714714
regularization_weights_dict = {}
715715

716-
for index, mapper in enumerate(self.cls_list_from(cls=AbstractMapper)):
716+
for index, mapper in enumerate(self.cls_list_from(cls=Mapper)):
717717
regularization_weights_dict[mapper] = self.regularization_weights_from(
718718
index=index,
719719
)
@@ -773,7 +773,7 @@ def max_pixel_list_from(
773773
-------
774774
775775
"""
776-
mapper = self.cls_list_from(cls=AbstractMapper)[mapper_index]
776+
mapper = self.cls_list_from(cls=Mapper)[mapper_index]
777777
reconstruction = self.reconstruction_dict[mapper]
778778

779779
max_pixel_list = []
@@ -818,7 +818,7 @@ def max_pixel_centre(self, mapper_index: int = 0) -> Grid2DIrregular:
818818
-------
819819
The centre of the brightest pixel in the mapper values.
820820
"""
821-
mapper = self.cls_list_from(cls=AbstractMapper)[mapper_index]
821+
mapper = self.cls_list_from(cls=Mapper)[mapper_index]
822822
reconstruction = self.reconstruction_dict[mapper]
823823

824824
max_pixel = np.argmax(reconstruction)

autoarray/inversion/inversion/imaging/abstract.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from autoarray.dataset.imaging.dataset import Imaging
55
from autoarray.inversion.inversion.dataset_interface import DatasetInterface
66
from autoarray.inversion.linear_obj.func_list import AbstractLinearObjFuncList
7-
from autoarray.inversion.pixelization.mappers.abstract import AbstractMapper
7+
from autoarray.inversion.mappers.abstract import Mapper
88
from autoarray.inversion.inversion.abstract import AbstractInversion
99
from autoarray.inversion.linear_obj.linear_obj import LinearObj
1010
from autoarray.settings import Settings
@@ -255,7 +255,7 @@ def mapper_operated_mapping_matrix_dict(self) -> Dict:
255255
"""
256256
mapper_operated_mapping_matrix_dict = {}
257257

258-
for mapper in self.cls_list_from(cls=AbstractMapper):
258+
for mapper in self.cls_list_from(cls=Mapper):
259259
operated_mapping_matrix = self.psf.convolved_mapping_matrix_from(
260260
mapping_matrix=mapper.mapping_matrix, mask=self.mask, xp=self._xp
261261
)

autoarray/inversion/inversion/imaging/mapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from autoarray.inversion.inversion.dataset_interface import DatasetInterface
88
from autoarray.inversion.inversion.imaging.abstract import AbstractInversionImaging
99
from autoarray.inversion.linear_obj.linear_obj import LinearObj
10-
from autoarray.inversion.pixelization.mappers.abstract import AbstractMapper
10+
from autoarray.inversion.mappers.abstract import Mapper
1111
from autoarray.settings import Settings
1212
from autoarray.preloads import Preloads
1313
from autoarray.structures.arrays.uniform_2d import Array2D

autoarray/inversion/inversion/imaging/sparse.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from autoarray.inversion.linear_obj.linear_obj import LinearObj
1010
from autoarray.settings import Settings
1111
from autoarray.inversion.linear_obj.func_list import AbstractLinearObjFuncList
12-
from autoarray.inversion.pixelization.mappers.abstract import AbstractMapper
12+
from autoarray.inversion.mappers.abstract import Mapper
1313
from autoarray.preloads import Preloads
1414
from autoarray.structures.arrays.uniform_2d import Array2D
1515

@@ -72,13 +72,13 @@ def _data_vector_mapper(self) -> np.ndarray:
7272
in the inversion, and is separated into a separate method to enable preloading of the mapper `data_vector`.
7373
"""
7474

75-
if not self.has(cls=AbstractMapper):
75+
if not self.has(cls=Mapper):
7676
return None
7777

7878
data_vector = self._xp.zeros(self.total_params)
7979

80-
mapper_list = self.cls_list_from(cls=AbstractMapper)
81-
mapper_param_range = self.param_range_list_from(cls=AbstractMapper)
80+
mapper_list = self.cls_list_from(cls=Mapper)
81+
mapper_param_range = self.param_range_list_from(cls=Mapper)
8282

8383
for mapper_index, mapper in enumerate(mapper_list):
8484

@@ -121,7 +121,7 @@ def data_vector(self) -> np.ndarray:
121121
"""
122122
if self.has(cls=AbstractLinearObjFuncList):
123123
return self._data_vector_func_list_and_mapper
124-
elif self.total(cls=AbstractMapper) == 1:
124+
elif self.total(cls=Mapper) == 1:
125125
return self._data_vector_x1_mapper
126126
return self._data_vector_multi_mapper
127127

@@ -158,7 +158,7 @@ def _data_vector_multi_mapper(self) -> np.ndarray:
158158

159159
data_vector_list = []
160160

161-
for mapper in self.cls_list_from(cls=AbstractMapper):
161+
for mapper in self.cls_list_from(cls=Mapper):
162162

163163
rows, cols, vals = mapper.sparse_triplets_data
164164

@@ -243,7 +243,7 @@ def curvature_matrix(self) -> np.ndarray:
243243
"""
244244
if self.has(cls=AbstractLinearObjFuncList):
245245
curvature_matrix = self._curvature_matrix_func_list_and_mapper
246-
elif self.total(cls=AbstractMapper) == 1:
246+
elif self.total(cls=Mapper) == 1:
247247
curvature_matrix = self._curvature_matrix_x1_mapper
248248
else:
249249
curvature_matrix = self._curvature_matrix_multi_mapper
@@ -276,13 +276,13 @@ def _curvature_matrix_mapper_diag(self) -> Optional[np.ndarray]:
276276
other calculations to enable preloading of this calculation.
277277
"""
278278

279-
if not self.has(cls=AbstractMapper):
279+
if not self.has(cls=Mapper):
280280
return None
281281

282282
curvature_matrix = self._xp.zeros((self.total_params, self.total_params))
283283

284-
mapper_list = self.cls_list_from(cls=AbstractMapper)
285-
mapper_param_range_list = self.param_range_list_from(cls=AbstractMapper)
284+
mapper_list = self.cls_list_from(cls=Mapper)
285+
mapper_param_range_list = self.param_range_list_from(cls=Mapper)
286286

287287
for i in range(len(mapper_list)):
288288
mapper_i = mapper_list[i]
@@ -304,13 +304,13 @@ def _curvature_matrix_mapper_diag(self) -> Optional[np.ndarray]:
304304
else:
305305
curvature_matrix = curvature_matrix.at[start:end, start:end].set(diag)
306306

307-
if self.total(cls=AbstractMapper) == 1:
307+
if self.total(cls=Mapper) == 1:
308308
return curvature_matrix
309309

310310
return curvature_matrix
311311

312312
def _curvature_matrix_off_diag_from(
313-
self, mapper_0: AbstractMapper, mapper_1: AbstractMapper
313+
self, mapper_0: Mapper, mapper_1: Mapper
314314
) -> np.ndarray:
315315
"""
316316
The `curvature_matrix` is a 2D matrix which uses the mappings between the data and the linear objects to
@@ -362,11 +362,11 @@ def _curvature_matrix_multi_mapper(self) -> np.ndarray:
362362

363363
curvature_matrix = self._curvature_matrix_mapper_diag
364364

365-
if self.total(cls=AbstractMapper) == 1:
365+
if self.total(cls=Mapper) == 1:
366366
return curvature_matrix
367367

368-
mapper_list = self.cls_list_from(cls=AbstractMapper)
369-
mapper_param_range_list = self.param_range_list_from(cls=AbstractMapper)
368+
mapper_list = self.cls_list_from(cls=Mapper)
369+
mapper_param_range_list = self.param_range_list_from(cls=Mapper)
370370

371371
for i in range(len(mapper_list)):
372372
mapper_i = mapper_list[i]
@@ -401,8 +401,8 @@ def _curvature_matrix_func_list_and_mapper(self) -> np.ndarray:
401401

402402
curvature_matrix = self._curvature_matrix_multi_mapper
403403

404-
mapper_list = self.cls_list_from(cls=AbstractMapper)
405-
mapper_param_range_list = self.param_range_list_from(cls=AbstractMapper)
404+
mapper_list = self.cls_list_from(cls=Mapper)
405+
mapper_param_range_list = self.param_range_list_from(cls=Mapper)
406406

407407
linear_func_list = self.cls_list_from(cls=AbstractLinearObjFuncList)
408408
linear_func_param_range_list = self.param_range_list_from(
@@ -491,7 +491,7 @@ def _mapped_reconstructed_data_dict_from(
491491
"""
492492
Shared implementation for mapping a reconstruction to image-plane arrays for each linear object.
493493
494-
For AbstractMapper objects this uses the sparse operator mapping, and optionally applies the PSF.
494+
For Mapper objects this uses the sparse operator mapping, and optionally applies the PSF.
495495
For linear-func objects this uses either the operated or unoperated mapping matrix dict.
496496
"""
497497
mapped_dict = {}
@@ -504,7 +504,7 @@ def _mapped_reconstructed_data_dict_from(
504504

505505
reconstruction = reconstruction_dict[linear_obj]
506506

507-
if isinstance(linear_obj, AbstractMapper):
507+
if isinstance(linear_obj, Mapper):
508508

509509
rows, cols, vals = linear_obj.sparse_triplets_curvature
510510

0 commit comments

Comments
 (0)