Skip to content

Commit 8d930a7

Browse files
authored
Merge pull request #217 from Jammy2211/feature/mesh_refactor
Feature/mesh refactor
2 parents 057f5e1 + 07b0447 commit 8d930a7

File tree

117 files changed

+2736
-2824
lines changed

Some content is hidden

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

117 files changed

+2736
-2824
lines changed

autoarray/__init__.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +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
30-
from .inversion.inversion.settings import SettingsInversion
29+
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.mapper_grids import MapperGrids
39-
from .inversion.pixelization.mappers.factory import mapper_from as Mapper
40-
from .inversion.pixelization.mappers.rectangular import MapperRectangular
41-
from .inversion.pixelization.mappers.delaunay import MapperDelaunay
42-
from .inversion.pixelization.mappers.rectangular_uniform import MapperRectangularUniform
43-
from .inversion.pixelization.image_mesh.abstract import AbstractImageMesh
44-
from .inversion.pixelization.mesh.abstract import AbstractMesh
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
4541
from .inversion.inversion.imaging.mapping import InversionImagingMapping
4642
from .inversion.inversion.imaging.sparse import InversionImagingSparse
4743
from .inversion.inversion.imaging.inversion_imaging_util import ImagingSparseOperator
@@ -77,9 +73,10 @@
7773
from .structures.grids.uniform_2d import Grid2D
7874
from .operators.over_sampling.over_sampler import OverSampler
7975
from .structures.grids.irregular_2d import Grid2DIrregular
80-
from .structures.mesh.rectangular_2d import Mesh2DRectangular
81-
from .structures.mesh.rectangular_2d_uniform import Mesh2DRectangularUniform
82-
from .structures.mesh.delaunay_2d import Mesh2DDelaunay
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
8380
from .structures.arrays.kernel_2d import Kernel2D
8481
from .structures.vectors.uniform import VectorYX2D
8582
from .structures.vectors.irregular import VectorYX2DIrregular

autoarray/config/general.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ inversion:
66
check_reconstruction: true # If True, the inversion's reconstruction is checked to ensure the solution of a meshs's mapper is not an invalid solution where the values are all the same.
77
use_positive_only_solver: true # If True, inversion's use a positive-only linear algebra solver by default, which is slower but prevents unphysical negative values in the reconstructed solutuion.
88
no_regularization_add_to_curvature_diag_value : 1.0e-3 # The default value added to the curvature matrix's diagonal when regularization is not applied to a linear object, which prevents inversion's failing due to the matrix being singular.
9-
positive_only_uses_p_initial: true # If True, the positive-only solver of an inversion's uses an initial guess of the reconstructed data's values as which values should be positive, speeding up the solver.
109
use_border_relocator: false # If True, by default a pixelization's border is used to relocate all pixels outside its border to the border.
1110
reconstruction_vmax_factor: 0.5 # Plots of an Inversion's reconstruction use the reconstructed data's bright value multiplied by this factor.
1211
numba:

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: 68 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,11 @@ def make_regularization_constant_split():
332332

333333

334334
def make_regularization_adaptive_brightness():
335-
return aa.reg.AdaptiveBrightness(
336-
inner_coefficient=0.1, outer_coefficient=10.0, signal_scale=0.5
337-
)
335+
return aa.reg.Adapt(inner_coefficient=0.1, outer_coefficient=10.0, signal_scale=0.5)
338336

339337

340338
def make_regularization_adaptive_brightness_split():
341-
return aa.reg.AdaptiveBrightnessSplit(
339+
return aa.reg.AdaptSplit(
342340
inner_coefficient=0.1, outer_coefficient=10.0, signal_scale=0.5
343341
)
344342

@@ -355,13 +353,44 @@ def make_regularization_matern_kernel():
355353
return aa.reg.MaternKernel(coefficient=1.0, scale=0.5, nu=0.7)
356354

357355

358-
def make_rectangular_mesh_grid_3x3():
359-
return aa.Mesh2DRectangular.overlay_grid(
360-
grid=make_grid_2d_sub_2_7x7().over_sampled, shape_native=(3, 3)
356+
def make_over_sampler_2d_7x7():
357+
return aa.OverSampler(mask=make_mask_2d_7x7(), sub_size=2)
358+
359+
360+
def make_border_relocator_2d_7x7():
361+
return aa.BorderRelocator(
362+
mask=make_mask_2d_7x7(), sub_size=np.array([2, 2, 2, 2, 2, 2, 2, 2, 2])
363+
)
364+
365+
366+
def make_rectangular_mapper_7x7_3x3():
367+
368+
from autoarray.inversion.mesh.mesh.rectangular_adapt_density import (
369+
overlay_grid_from,
361370
)
362371

372+
shape_native = (3, 3)
373+
374+
source_plane_mesh_grid = overlay_grid_from(
375+
shape_native=shape_native, grid=make_grid_2d_sub_2_7x7().over_sampled
376+
)
377+
378+
mesh = aa.mesh.RectangularUniform(shape=shape_native)
379+
380+
interpolator = mesh.interpolator_from(
381+
source_plane_data_grid=make_grid_2d_sub_2_7x7(),
382+
source_plane_mesh_grid=aa.Grid2DIrregular(source_plane_mesh_grid),
383+
adapt_data=aa.Array2D.ones(shape_native, pixel_scales=0.1),
384+
)
385+
386+
return aa.Mapper(
387+
interpolator=interpolator,
388+
regularization=make_regularization_constant(),
389+
)
390+
391+
392+
def make_delaunay_mapper_9_3x3():
363393

364-
def make_delaunay_mesh_grid_9():
365394
grid_9 = aa.Grid2D.no_mask(
366395
values=[
367396
[0.6, -0.3],
@@ -378,51 +407,51 @@ def make_delaunay_mesh_grid_9():
378407
pixel_scales=1.0,
379408
)
380409

381-
return aa.Mesh2DDelaunay(
382-
values=grid_9,
383-
source_plane_data_grid_over_sampled=make_grid_2d_sub_2_7x7().over_sampled,
384-
)
385-
386-
387-
def make_over_sampler_2d_7x7():
388-
return aa.OverSampler(mask=make_mask_2d_7x7(), sub_size=2)
410+
mesh = aa.mesh.Delaunay()
389411

390-
391-
def make_border_relocator_2d_7x7():
392-
return aa.BorderRelocator(
393-
mask=make_mask_2d_7x7(), sub_size=np.array([2, 2, 2, 2, 2, 2, 2, 2, 2])
394-
)
395-
396-
397-
def make_rectangular_mapper_7x7_3x3():
398-
mapper_grids = aa.MapperGrids(
399-
mask=make_mask_2d_7x7(),
412+
interpolator = mesh.interpolator_from(
400413
source_plane_data_grid=make_grid_2d_sub_2_7x7(),
401-
source_plane_mesh_grid=make_rectangular_mesh_grid_3x3(),
402-
image_plane_mesh_grid=None,
414+
source_plane_mesh_grid=grid_9,
403415
adapt_data=aa.Array2D.ones(shape_native=(3, 3), pixel_scales=0.1),
404416
)
405417

406-
return aa.MapperRectangularUniform(
407-
mapper_grids=mapper_grids,
408-
border_relocator=make_border_relocator_2d_7x7(),
418+
return aa.Mapper(
419+
interpolator=interpolator,
409420
regularization=make_regularization_constant(),
421+
image_plane_mesh_grid=aa.Grid2D.uniform(shape_native=(3, 3), pixel_scales=0.1),
410422
)
411423

412424

413-
def make_delaunay_mapper_9_3x3():
414-
mapper_grids = aa.MapperGrids(
415-
mask=make_mask_2d_7x7(),
425+
def make_knn_mapper_9_3x3():
426+
427+
grid_9 = aa.Grid2D.no_mask(
428+
values=[
429+
[0.6, -0.3],
430+
[0.5, -0.8],
431+
[0.2, 0.1],
432+
[0.0, 0.5],
433+
[-0.3, -0.8],
434+
[-0.6, -0.5],
435+
[-0.4, -1.1],
436+
[-1.2, 0.8],
437+
[-1.5, 0.9],
438+
],
439+
shape_native=(3, 3),
440+
pixel_scales=1.0,
441+
)
442+
443+
mesh = aa.mesh.KNearestNeighbor(split_neighbor_division=1)
444+
445+
interpolator = mesh.interpolator_from(
416446
source_plane_data_grid=make_grid_2d_sub_2_7x7(),
417-
source_plane_mesh_grid=make_delaunay_mesh_grid_9(),
418-
image_plane_mesh_grid=aa.Grid2D.uniform(shape_native=(3, 3), pixel_scales=0.1),
447+
source_plane_mesh_grid=grid_9,
419448
adapt_data=aa.Array2D.ones(shape_native=(3, 3), pixel_scales=0.1),
420449
)
421450

422-
return aa.MapperDelaunay(
423-
mapper_grids=mapper_grids,
424-
border_relocator=make_border_relocator_2d_7x7(),
451+
return aa.Mapper(
452+
interpolator=interpolator,
425453
regularization=make_regularization_constant(),
454+
image_plane_mesh_grid=aa.Grid2D.uniform(shape_native=(3, 3), pixel_scales=0.1),
426455
)
427456

428457

autoarray/inversion/inversion/abstract.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
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
14-
from autoarray.inversion.inversion.settings import SettingsInversion
14+
from autoarray.settings import Settings
1515
from autoarray.preloads import Preloads
1616
from autoarray.structures.arrays.uniform_2d import Array2D
1717
from autoarray.structures.grids.irregular_2d import Grid2DIrregular
@@ -26,7 +26,7 @@ def __init__(
2626
self,
2727
dataset: Union[Imaging, Interferometer, DatasetInterface],
2828
linear_obj_list: List[LinearObj],
29-
settings: SettingsInversion = SettingsInversion(),
29+
settings: Settings = None,
3030
preloads: Preloads = None,
3131
xp=np,
3232
):
@@ -72,7 +72,7 @@ def __init__(
7272

7373
self.linear_obj_list = linear_obj_list
7474

75-
self.settings = settings
75+
self.settings = settings or Settings()
7676

7777
self.preloads = preloads or Preloads()
7878

@@ -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/factory.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
from autoarray.inversion.inversion.imaging.sparse import (
2424
InversionImagingSparse,
2525
)
26-
from autoarray.inversion.inversion.settings import SettingsInversion
26+
from autoarray.settings import Settings
2727
from autoarray.preloads import Preloads
2828
from autoarray.structures.arrays.uniform_2d import Array2D
2929

3030

3131
def inversion_from(
3232
dataset: Union[Imaging, Interferometer, DatasetInterface],
3333
linear_obj_list: List[LinearObj],
34-
settings: SettingsInversion = SettingsInversion(),
34+
settings: Settings = None,
3535
preloads: Preloads = None,
3636
xp=np,
3737
):
@@ -80,7 +80,7 @@ def inversion_from(
8080
def inversion_imaging_from(
8181
dataset,
8282
linear_obj_list: List[LinearObj],
83-
settings: SettingsInversion = SettingsInversion(),
83+
settings: Settings = None,
8484
preloads: Preloads = None,
8585
xp=np,
8686
):
@@ -157,7 +157,7 @@ def inversion_imaging_from(
157157
def inversion_interferometer_from(
158158
dataset: Union[Interferometer, DatasetInterface],
159159
linear_obj_list: List[LinearObj],
160-
settings: SettingsInversion = SettingsInversion(),
160+
settings: Settings = None,
161161
xp=np,
162162
):
163163
"""

autoarray/inversion/inversion/imaging/abstract.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
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
10-
from autoarray.inversion.inversion.settings import SettingsInversion
10+
from autoarray.settings import Settings
1111
from autoarray.preloads import Preloads
1212

1313
from autoarray.inversion.inversion.imaging import inversion_imaging_util
@@ -18,7 +18,7 @@ def __init__(
1818
self,
1919
dataset: Union[Imaging, DatasetInterface],
2020
linear_obj_list: List[LinearObj],
21-
settings: SettingsInversion = SettingsInversion(),
21+
settings: Settings = None,
2222
preloads: Preloads = None,
2323
xp=np,
2424
):
@@ -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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
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
11-
from autoarray.inversion.inversion.settings import SettingsInversion
10+
from autoarray.inversion.mappers.abstract import Mapper
11+
from autoarray.settings import Settings
1212
from autoarray.preloads import Preloads
1313
from autoarray.structures.arrays.uniform_2d import Array2D
1414

@@ -21,7 +21,7 @@ def __init__(
2121
self,
2222
dataset: Union[Imaging, DatasetInterface],
2323
linear_obj_list: List[LinearObj],
24-
settings: SettingsInversion = SettingsInversion(),
24+
settings: Settings = None,
2525
preloads: Preloads = None,
2626
xp=np,
2727
):

0 commit comments

Comments
 (0)