From 3c715265dcbdd07aa63b20587293796c5eeb5986 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Wed, 13 Dec 2023 15:05:24 +0000 Subject: [PATCH 1/5] black --- docs/overview/overview_5_pixelizations.rst | 2 +- docs/overview/overview_7_multi_wavelength.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/overview/overview_5_pixelizations.rst b/docs/overview/overview_5_pixelizations.rst index feafb838e..e53cb9dce 100644 --- a/docs/overview/overview_5_pixelizations.rst +++ b/docs/overview/overview_5_pixelizations.rst @@ -175,7 +175,7 @@ The pixelization mesh which tests have revealed performs best is the ``VoronoiNN mesh with a technique called natural neighbour interpolation (full details are provided in the **HowToLens** tutorials). -I recommend users always use these pixelizations, however they require a c library to be installed, thus they are +I recommend users use this pixelization, how it requires a c library to be installed, thus it is not the default pixelization used in this tutorial. If you want to use this pixelization, checkout the installation instructions here: diff --git a/docs/overview/overview_7_multi_wavelength.rst b/docs/overview/overview_7_multi_wavelength.rst index fc728a132..5c5a3add8 100644 --- a/docs/overview/overview_7_multi_wavelength.rst +++ b/docs/overview/overview_7_multi_wavelength.rst @@ -80,7 +80,7 @@ Here are the r-band images: :width: 800 :alt: Alternative text -We define a 3.0" circular mask, which includes the emission of the lens and source galaxies. +Define a 3.0" circular mask, which includes the emission of the lens and source galaxies. For multi-wavelength lens modeling, we use the same mask for every dataset whenever possible. This is not absolutely necessary, but provides a more reliable analysis. From f243bbc72f2c86832770c4a261ca839f7858ea67 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Wed, 13 Dec 2023 15:18:58 +0000 Subject: [PATCH 2/5] remove reference to Grid2DSparse --- autolens/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/autolens/__init__.py b/autolens/__init__.py index 15f5bec13..73878cd54 100644 --- a/autolens/__init__.py +++ b/autolens/__init__.py @@ -33,7 +33,6 @@ from autoarray.structures.arrays.irregular import ArrayIrregular from autoarray.structures.grids.uniform_1d import Grid1D from autoarray.structures.grids.uniform_2d import Grid2D -from autoarray.structures.grids.sparse_2d import Grid2DSparse from autoarray.structures.grids.iterate_2d import Grid2DIterate from autoarray.structures.grids.irregular_2d import Grid2DIrregular from autoarray.structures.grids.irregular_2d import Grid2DIrregularUniform From f6760d22bfc7175e3a4bf56deca03ca3dd5372d7 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Wed, 13 Dec 2023 16:55:54 +0000 Subject: [PATCH 3/5] fix to_inversion tests --- autolens/aggregator/fit_imaging.py | 8 +-- autolens/aggregator/fit_interferometer.py | 8 +-- autolens/analysis/analysis.py | 4 +- autolens/analysis/preloads.py | 46 ++++++++--------- autolens/imaging/mock/mock_fit_imaging.py | 2 +- autolens/lens/mock/mock_to_inversion.py | 8 +-- autolens/lens/mock/mock_tracer.py | 8 +-- autolens/lens/to_inversion.py | 62 +++++++++++------------ test_autolens/analysis/test_preloads.py | 38 +++++++------- test_autolens/lens/test_to_inversion.py | 44 ++++++++-------- 10 files changed, 114 insertions(+), 114 deletions(-) diff --git a/autolens/aggregator/fit_imaging.py b/autolens/aggregator/fit_imaging.py index 9982462f5..2df1d918c 100644 --- a/autolens/aggregator/fit_imaging.py +++ b/autolens/aggregator/fit_imaging.py @@ -72,19 +72,19 @@ def _fit_imaging_from( ) settings_inversion = settings_inversion or fit.value(name="settings_inversion") - sparse_grids_of_planes_list = agg_util.sparse_grids_of_planes_list_from( + mesh_grids_of_planes_list = agg_util.mesh_grids_of_planes_list_from( fit=fit, total_fits=len(dataset_list), use_preloaded_grid=use_preloaded_grid ) fit_dataset_list = [] - for dataset, tracer, sparse_grids_of_planes in zip( - dataset_list, tracer_list, sparse_grids_of_planes_list + for dataset, tracer, mesh_grids_of_planes in zip( + dataset_list, tracer_list, mesh_grids_of_planes_list ): preloads = agg_util.preloads_from( preloads_cls=Preloads, use_preloaded_grid=use_preloaded_grid, - sparse_grids_of_planes=sparse_grids_of_planes, + mesh_grids_of_planes=mesh_grids_of_planes, use_w_tilde=False, ) diff --git a/autolens/aggregator/fit_interferometer.py b/autolens/aggregator/fit_interferometer.py index c2881f716..1b9999191 100644 --- a/autolens/aggregator/fit_interferometer.py +++ b/autolens/aggregator/fit_interferometer.py @@ -75,19 +75,19 @@ def _fit_interferometer_from( ) settings_inversion = settings_inversion or fit.value(name="settings_inversion") - sparse_grids_of_planes_list = agg_util.sparse_grids_of_planes_list_from( + mesh_grids_of_planes_list = agg_util.mesh_grids_of_planes_list_from( fit=fit, total_fits=len(dataset_list), use_preloaded_grid=use_preloaded_grid ) fit_dataset_list = [] - for dataset, tracer, sparse_grids_of_planes in zip( - dataset_list, tracer_list, sparse_grids_of_planes_list + for dataset, tracer, mesh_grids_of_planes in zip( + dataset_list, tracer_list, mesh_grids_of_planes_list ): preloads = agg_util.preloads_from( preloads_cls=Preloads, use_preloaded_grid=use_preloaded_grid, - sparse_grids_of_planes=sparse_grids_of_planes, + mesh_grids_of_planes=mesh_grids_of_planes, use_w_tilde=False, ) diff --git a/autolens/analysis/analysis.py b/autolens/analysis/analysis.py index 85276517b..340c79678 100644 --- a/autolens/analysis/analysis.py +++ b/autolens/analysis/analysis.py @@ -320,9 +320,9 @@ def save_results(self, paths: af.DirectoryPaths, result: ResultDataset): if len(mesh_list) > 0: paths.save_json( - name="preload_sparse_grids_of_planes", + name="preload_mesh_grids_of_planes", object_dict=to_dict( - result.max_log_likelihood_fit.tracer_to_inversion.sparse_image_plane_grid_pg_list + result.max_log_likelihood_fit.tracer_to_inversion.image_plane_mesh_grid_pg_list ), ) diff --git a/autolens/analysis/preloads.py b/autolens/analysis/preloads.py index de72b181f..dc433e529 100644 --- a/autolens/analysis/preloads.py +++ b/autolens/analysis/preloads.py @@ -17,7 +17,7 @@ def __init__( use_w_tilde: Optional[bool] = None, blurred_image: Optional[aa.Array2D] = None, traced_grids_of_planes_for_inversion: Optional[aa.Grid2D] = None, - sparse_image_plane_grid_pg_list: Optional[List[List[aa.Grid2D]]] = None, + image_plane_mesh_grid_pg_list: Optional[List[List[aa.Grid2D]]] = None, relocated_grid: Optional[aa.Grid2D] = None, mapper_list: Optional[aa.AbstractMapper] = None, mapper_galaxy_dict: Optional[Dict[aa.AbstractMapper, ag.Galaxy]] = None, @@ -27,8 +27,8 @@ def __init__( mapper_operated_mapping_matrix_dict=None, regularization_matrix: Optional[np.ndarray] = None, log_det_regularization_matrix_term: Optional[float] = None, - traced_sparse_grids_list_of_planes=None, - sparse_image_plane_grid_list=None, + traced_mesh_grids_list_of_planes=None, + image_plane_mesh_grid_list=None, failed=False, ): """ @@ -56,7 +56,7 @@ def __init__( traced_grids_of_planes_for_inversion The two dimensional grids corresponding to the traced grids in a lens fit. This can be preloaded when no mass profiles in the model vary. - sparse_image_plane_grid_pg_list + image_plane_mesh_grid_pg_list The two dimensional grids corresponding to the sparse image plane grids in a lens fit, that is ray-traced to the source plane to form the source pixelization. This can be preloaded when no pixelizations in the model vary. @@ -80,7 +80,7 @@ def __init__( use_w_tilde=use_w_tilde, blurred_image=blurred_image, relocated_grid=relocated_grid, - sparse_image_plane_grid_pg_list=sparse_image_plane_grid_pg_list, + image_plane_mesh_grid_pg_list=image_plane_mesh_grid_pg_list, mapper_list=mapper_list, mapper_galaxy_dict=mapper_galaxy_dict, operated_mapping_matrix=operated_mapping_matrix, @@ -89,8 +89,8 @@ def __init__( mapper_operated_mapping_matrix_dict=mapper_operated_mapping_matrix_dict, regularization_matrix=regularization_matrix, log_det_regularization_matrix_term=log_det_regularization_matrix_term, - traced_sparse_grids_list_of_planes=traced_sparse_grids_list_of_planes, - sparse_image_plane_grid_list=sparse_image_plane_grid_list, + traced_mesh_grids_list_of_planes=traced_mesh_grids_list_of_planes, + image_plane_mesh_grid_list=image_plane_mesh_grid_list, ) self.traced_grids_of_planes_for_inversion = traced_grids_of_planes_for_inversion @@ -122,7 +122,7 @@ def setup_all_via_fits(cls, fit_0, fit_1) -> "Preloads": preloads.set_blurred_image(fit_0=fit_0, fit_1=fit_1) preloads.set_traced_grids_of_planes_for_inversion(fit_0=fit_0, fit_1=fit_1) - preloads.set_sparse_image_plane_grid_pg_list(fit_0=fit_0, fit_1=fit_1) + preloads.set_image_plane_mesh_grid_pg_list(fit_0=fit_0, fit_1=fit_1) preloads.set_relocated_grid(fit_0=fit_0, fit_1=fit_1) preloads.set_mapper_list(fit_0=fit_0, fit_1=fit_1) @@ -183,7 +183,7 @@ def set_traced_grids_of_planes_for_inversion(self, fit_0, fit_1): "PRELOADS - Traced grid of planes (for inversion) preloaded for this model-fit." ) - def set_sparse_image_plane_grid_pg_list(self, fit_0, fit_1): + def set_image_plane_mesh_grid_pg_list(self, fit_0, fit_1): """ If the `Pixelization`'s in a model are fixed their image-plane sparse grid (which defines the set of pixels that are ray-traced to construct the source-plane pixelization) do not change during the model=fit and @@ -203,33 +203,33 @@ def set_sparse_image_plane_grid_pg_list(self, fit_0, fit_1): The second fit corresponding to a model with a different set of unit-values. """ - self.sparse_image_plane_grid_pg_list = None + self.image_plane_mesh_grid_pg_list = None - sparse_image_plane_grid_pg_list_0 = ( - fit_0.tracer_to_inversion.sparse_image_plane_grid_pg_list + image_plane_mesh_grid_pg_list_0 = ( + fit_0.tracer_to_inversion.image_plane_mesh_grid_pg_list ) - sparse_image_plane_grid_pg_list_1 = ( - fit_1.tracer_to_inversion.sparse_image_plane_grid_pg_list + image_plane_mesh_grid_pg_list_1 = ( + fit_1.tracer_to_inversion.image_plane_mesh_grid_pg_list ) - if sparse_image_plane_grid_pg_list_0[-1] is not None: - if sparse_image_plane_grid_pg_list_0[-1][0] is not None: + if image_plane_mesh_grid_pg_list_0[-1] is not None: + if image_plane_mesh_grid_pg_list_0[-1][0] is not None: if ( - sparse_image_plane_grid_pg_list_0[-1][0].shape[0] - == sparse_image_plane_grid_pg_list_1[-1][0].shape[0] + image_plane_mesh_grid_pg_list_0[-1][0].shape[0] + == image_plane_mesh_grid_pg_list_1[-1][0].shape[0] ): if ( np.max( abs( - sparse_image_plane_grid_pg_list_0[-1][0] - - sparse_image_plane_grid_pg_list_1[-1][0] + image_plane_mesh_grid_pg_list_0[-1][0] + - image_plane_mesh_grid_pg_list_1[-1][0] ) ) < 1e-8 ): - self.sparse_image_plane_grid_pg_list = ( - sparse_image_plane_grid_pg_list_0 + self.image_plane_mesh_grid_pg_list = ( + image_plane_mesh_grid_pg_list_0 ) logger.info( @@ -252,7 +252,7 @@ def info(self) -> List[str]: f"Traced Grids of Planes (For LEq) = {self.traced_grids_of_planes_for_inversion is not None}\n" ] line += [ - f"Sparse Image-Plane Grids of Planes = {self.sparse_image_plane_grid_pg_list is not None}\n" + f"Sparse Image-Plane Grids of Planes = {self.image_plane_mesh_grid_pg_list is not None}\n" ] line += [f"Relocated Grid = {self.relocated_grid is not None}\n"] line += [f"Mapper = {self.mapper_list is not None}\n"] diff --git a/autolens/imaging/mock/mock_fit_imaging.py b/autolens/imaging/mock/mock_fit_imaging.py index 95804de8f..4bf9c218c 100644 --- a/autolens/imaging/mock/mock_fit_imaging.py +++ b/autolens/imaging/mock/mock_fit_imaging.py @@ -31,5 +31,5 @@ def tracer_to_inversion(self) -> MockTracerToInversion: return MockTracerToInversion( tracer=self.tracer, - sparse_image_plane_grid_pg_list=self.tracer.sparse_image_plane_grid_pg_list, + image_plane_mesh_grid_pg_list=self.tracer.image_plane_mesh_grid_pg_list, ) diff --git a/autolens/lens/mock/mock_to_inversion.py b/autolens/lens/mock/mock_to_inversion.py index b43c9b5e5..0bf39d6ec 100644 --- a/autolens/lens/mock/mock_to_inversion.py +++ b/autolens/lens/mock/mock_to_inversion.py @@ -5,14 +5,14 @@ class MockTracerToInversion: def __init__( self, tracer, - sparse_image_plane_grid_pg_list=None, + image_plane_mesh_grid_pg_list=None, run_time_dict: Optional[Dict] = None, ): self.tracer = tracer - self.sparse_image_plane_grid_pg_list = sparse_image_plane_grid_pg_list + self.image_plane_mesh_grid_pg_list = image_plane_mesh_grid_pg_list self.run_time_dict = run_time_dict - def sparse_image_plane_grid_pg_list(self): - return self.sparse_image_plane_grid_pg_list + def image_plane_mesh_grid_pg_list(self): + return self.image_plane_mesh_grid_pg_list diff --git a/autolens/lens/mock/mock_tracer.py b/autolens/lens/mock/mock_tracer.py index 332b30273..bb4cd52be 100644 --- a/autolens/lens/mock/mock_tracer.py +++ b/autolens/lens/mock/mock_tracer.py @@ -1,8 +1,8 @@ class MockTracer: def __init__( - self, traced_grid_2d_list_from=None, sparse_image_plane_grid_pg_list=None + self, traced_grid_2d_list_from=None, image_plane_mesh_grid_pg_list=None ): - self.sparse_image_plane_grid_pg_list = sparse_image_plane_grid_pg_list + self.image_plane_mesh_grid_pg_list = image_plane_mesh_grid_pg_list self._traced_grid_2d_list_from = traced_grid_2d_list_from def traced_grid_2d_list_from(self, grid): @@ -12,7 +12,7 @@ def traced_grid_2d_list_from(self, grid): class MockTracerPoint(MockTracer): def __init__( self, - sparse_image_plane_grid_pg_list=None, + image_plane_mesh_grid_pg_list=None, traced_grid=None, attribute=None, profile=None, @@ -21,7 +21,7 @@ def __init__( einstein_mass=None, ): super().__init__( - sparse_image_plane_grid_pg_list=sparse_image_plane_grid_pg_list + image_plane_mesh_grid_pg_list=image_plane_mesh_grid_pg_list ) self.positions = traced_grid diff --git a/autolens/lens/to_inversion.py b/autolens/lens/to_inversion.py index 2fb66b47f..8927c88b4 100644 --- a/autolens/lens/to_inversion.py +++ b/autolens/lens/to_inversion.py @@ -98,14 +98,14 @@ def adapt_galaxy_image_pg_list(self) -> List: @cached_property @aa.profile_func - def sparse_image_plane_grid_pg_list(self) -> List[List]: + def image_plane_mesh_grid_pg_list(self) -> List[List]: """ Specific pixelizations, like the `VoronoiMagnification`, begin by determining what will become its the source-pixel centres by calculating them in the image-plane. The `VoronoiBrightnessImage` pixelization performs a KMeans clustering. """ - sparse_image_plane_grid_list_of_planes = [] + image_plane_mesh_grid_list_of_planes = [] for plane in self.planes: plane_to_inversion = ag.PlaneToInversion( @@ -115,55 +115,55 @@ def sparse_image_plane_grid_pg_list(self) -> List[List]: noise_map=self.noise_map, ) - sparse_image_plane_grid_list = ( - plane_to_inversion.sparse_image_plane_grid_list + image_plane_mesh_grid_list = ( + plane_to_inversion.image_plane_mesh_grid_list ) - sparse_image_plane_grid_list_of_planes.append(sparse_image_plane_grid_list) + image_plane_mesh_grid_list_of_planes.append(image_plane_mesh_grid_list) - return sparse_image_plane_grid_list_of_planes + return image_plane_mesh_grid_list_of_planes @cached_property @aa.profile_func - def traced_sparse_grid_pg_list(self) -> Tuple[List[List], List[List]]: + def traced_mesh_grid_pg_list(self) -> Tuple[List[List], List[List]]: """ Ray-trace the sparse image plane grid used to define the source-pixel centres by calculating the deflection angles at (y,x) coordinate on the grid from the galaxy mass profiles and then ray-trace them from the image-plane to the source plane. """ if ( - self.preloads.sparse_image_plane_grid_pg_list is None + self.preloads.image_plane_mesh_grid_pg_list is None or self.settings_pixelization.is_stochastic ): - sparse_image_plane_grid_pg_list = self.sparse_image_plane_grid_pg_list + image_plane_mesh_grid_pg_list = self.image_plane_mesh_grid_pg_list else: - sparse_image_plane_grid_pg_list = ( - self.preloads.sparse_image_plane_grid_pg_list + image_plane_mesh_grid_pg_list = ( + self.preloads.image_plane_mesh_grid_pg_list ) - traced_sparse_grid_pg_list = [] + traced_mesh_grid_pg_list = [] for plane_index, plane in enumerate(self.planes): - if sparse_image_plane_grid_pg_list[plane_index] is None: - traced_sparse_grid_pg_list.append(None) + if image_plane_mesh_grid_pg_list[plane_index] is None: + traced_mesh_grid_pg_list.append(None) else: - traced_sparse_grids_list = [] + traced_mesh_grids_list = [] - for sparse_image_plane_grid in sparse_image_plane_grid_pg_list[ + for image_plane_mesh_grid in image_plane_mesh_grid_pg_list[ plane_index ]: try: - traced_sparse_grids_list.append( + traced_mesh_grids_list.append( self.tracer.traced_grid_2d_list_from( - grid=sparse_image_plane_grid + grid=image_plane_mesh_grid )[plane_index] ) except AttributeError: - traced_sparse_grids_list.append(None) + traced_mesh_grids_list.append(None) - traced_sparse_grid_pg_list.append(traced_sparse_grids_list) + traced_mesh_grid_pg_list.append(traced_mesh_grids_list) - return traced_sparse_grid_pg_list, sparse_image_plane_grid_pg_list + return traced_mesh_grid_pg_list, image_plane_mesh_grid_pg_list @cached_property def mapper_galaxy_dict(self) -> Dict[aa.AbstractMapper, ag.Galaxy]: @@ -176,16 +176,16 @@ def mapper_galaxy_dict(self) -> Dict[aa.AbstractMapper, ag.Galaxy]: self.preloads.traced_grids_of_planes_for_inversion ) - if self.preloads.traced_sparse_grids_list_of_planes is None: + if self.preloads.traced_mesh_grids_list_of_planes is None: ( - traced_sparse_grids_list_of_planes, - sparse_image_plane_grid_list, - ) = self.traced_sparse_grid_pg_list + traced_mesh_grids_list_of_planes, + image_plane_mesh_grid_list, + ) = self.traced_mesh_grid_pg_list else: - traced_sparse_grids_list_of_planes = ( - self.preloads.traced_sparse_grids_list_of_planes + traced_mesh_grids_list_of_planes = ( + self.preloads.traced_mesh_grids_list_of_planes ) - sparse_image_plane_grid_list = self.preloads.sparse_image_plane_grid_list + image_plane_mesh_grid_list = self.preloads.image_plane_mesh_grid_list for plane_index, plane in enumerate(self.planes): if plane.has(cls=aa.Pixelization): @@ -202,7 +202,7 @@ def mapper_galaxy_dict(self) -> Dict[aa.AbstractMapper, ag.Galaxy]: ) for mapper_index in range( - len(traced_sparse_grids_list_of_planes[plane_index]) + len(traced_mesh_grids_list_of_planes[plane_index]) ): pixelization_list = self.cls_pg_list_from(cls=aa.Pixelization) @@ -211,10 +211,10 @@ def mapper_galaxy_dict(self) -> Dict[aa.AbstractMapper, ag.Galaxy]: regularization=pixelization_list[plane_index][ mapper_index ].regularization, - source_plane_mesh_grid=traced_sparse_grids_list_of_planes[ + source_plane_mesh_grid=traced_mesh_grids_list_of_planes[ plane_index ][mapper_index], - image_plane_mesh_grid=sparse_image_plane_grid_list[plane_index][ + image_plane_mesh_grid=image_plane_mesh_grid_list[plane_index][ mapper_index ], adapt_galaxy_image=self.adapt_galaxy_image_pg_list[plane_index][ diff --git a/test_autolens/analysis/test_preloads.py b/test_autolens/analysis/test_preloads.py index ff278a84c..bb1e782b7 100644 --- a/test_autolens/analysis/test_preloads.py +++ b/test_autolens/analysis/test_preloads.py @@ -48,54 +48,54 @@ def test__set_traced_grids_of_planes(): assert (preloads.traced_grids_of_planes_for_inversion[1] == np.array([[1.0]])).all() -def test__set_sparse_grid_of_planes(): +def test__set_mesh_grid_of_planes(): # sparse image plane of grids is None so no Preloading. - tracer_0 = al.m.MockTracer(sparse_image_plane_grid_pg_list=[None, None]) - tracer_1 = al.m.MockTracer(sparse_image_plane_grid_pg_list=[None, None]) + tracer_0 = al.m.MockTracer(image_plane_mesh_grid_pg_list=[None, None]) + tracer_1 = al.m.MockTracer(image_plane_mesh_grid_pg_list=[None, None]) fit_0 = al.m.MockFitImaging(tracer=tracer_0) fit_1 = al.m.MockFitImaging(tracer=tracer_1) - preloads = al.Preloads(sparse_image_plane_grid_pg_list=1) - preloads.set_sparse_image_plane_grid_pg_list(fit_0=fit_0, fit_1=fit_1) + preloads = al.Preloads(image_plane_mesh_grid_pg_list=1) + preloads.set_image_plane_mesh_grid_pg_list(fit_0=fit_0, fit_1=fit_1) - assert preloads.sparse_image_plane_grid_pg_list is None + assert preloads.image_plane_mesh_grid_pg_list is None # sparse image plane of grids are different, indicating the model parameters change the grid, so no preloading. tracer_0 = al.m.MockTracer( - sparse_image_plane_grid_pg_list=[None, np.array([[1.0]])] + image_plane_mesh_grid_pg_list=[None, np.array([[1.0]])] ) tracer_1 = al.m.MockTracer( - sparse_image_plane_grid_pg_list=[None, np.array([[2.0]])] + image_plane_mesh_grid_pg_list=[None, np.array([[2.0]])] ) fit_0 = al.m.MockFitImaging(tracer=tracer_0) fit_1 = al.m.MockFitImaging(tracer=tracer_1) - preloads = al.Preloads(sparse_image_plane_grid_pg_list=1) - preloads.set_sparse_image_plane_grid_pg_list(fit_0=fit_0, fit_1=fit_1) + preloads = al.Preloads(image_plane_mesh_grid_pg_list=1) + preloads.set_image_plane_mesh_grid_pg_list(fit_0=fit_0, fit_1=fit_1) - assert preloads.sparse_image_plane_grid_pg_list is None + assert preloads.image_plane_mesh_grid_pg_list is None # sparse image plane of grids are the same meaning they are fixed in the model, so do preload. tracer_0 = al.m.MockTracer( - sparse_image_plane_grid_pg_list=[None, np.array([[1.0]])] + image_plane_mesh_grid_pg_list=[None, np.array([[1.0]])] ) tracer_1 = al.m.MockTracer( - sparse_image_plane_grid_pg_list=[None, np.array([[1.0]])] + image_plane_mesh_grid_pg_list=[None, np.array([[1.0]])] ) fit_0 = al.m.MockFitImaging(tracer=tracer_0) fit_1 = al.m.MockFitImaging(tracer=tracer_1) - preloads = al.Preloads(sparse_image_plane_grid_pg_list=1) - preloads.set_sparse_image_plane_grid_pg_list(fit_0=fit_0, fit_1=fit_1) + preloads = al.Preloads(image_plane_mesh_grid_pg_list=1) + preloads.set_image_plane_mesh_grid_pg_list(fit_0=fit_0, fit_1=fit_1) - assert preloads.sparse_image_plane_grid_pg_list[0] is None - assert (preloads.sparse_image_plane_grid_pg_list[1] == np.array([[1.0]])).all() + assert preloads.image_plane_mesh_grid_pg_list[0] is None + assert (preloads.image_plane_mesh_grid_pg_list[1] == np.array([[1.0]])).all() def test__info(): @@ -108,7 +108,7 @@ def test__info(): w_tilde=None, use_w_tilde=False, traced_grids_of_planes_for_inversion=None, - sparse_image_plane_grid_pg_list=None, + image_plane_mesh_grid_pg_list=None, relocated_grid=None, mapper_list=None, operated_mapping_matrix=None, @@ -158,7 +158,7 @@ def test__info(): use_w_tilde=True, traced_grids_of_planes_for_inversion=1, relocated_grid=1, - sparse_image_plane_grid_pg_list=1, + image_plane_mesh_grid_pg_list=1, mapper_list=1, operated_mapping_matrix=1, regularization_matrix=1, diff --git a/test_autolens/lens/test_to_inversion.py b/test_autolens/lens/test_to_inversion.py index fd70f99ac..10cf38612 100644 --- a/test_autolens/lens/test_to_inversion.py +++ b/test_autolens/lens/test_to_inversion.py @@ -207,11 +207,11 @@ def test__adapt_galaxy_image_pg_list(sub_grid_2d_7x7): assert tracer_to_inversion.adapt_galaxy_image_pg_list == [[], [1], [], [], [2, 3]] -def test__sparse_image_plane_grid_pg_list(masked_imaging_7x7): +def test__image_plane_mesh_grid_pg_list(masked_imaging_7x7): # Test Correct pixelization = al.m.MockPixelization( - mesh=al.m.MockMesh(image_plane_mesh_grid=np.array([[1.0, 1.0]])) + image_mesh=al.m.MockImageMesh(image_plane_mesh_grid=np.array([[1.0, 1.0]])) ) galaxy_pix = al.Galaxy(redshift=1.0, pixelization=pixelization) @@ -223,7 +223,7 @@ def test__sparse_image_plane_grid_pg_list(masked_imaging_7x7): tracer=tracer, dataset=masked_imaging_7x7 ) - mesh_grids = tracer_to_inversion.sparse_image_plane_grid_pg_list + mesh_grids = tracer_to_inversion.image_plane_mesh_grid_pg_list assert mesh_grids[0] == None assert (mesh_grids[1] == np.array([[1.0, 1.0]])).all() @@ -233,7 +233,7 @@ def test__sparse_image_plane_grid_pg_list(masked_imaging_7x7): galaxy_pix0 = al.Galaxy(redshift=1.0, pixelization=pixelization) pixelization = al.m.MockPixelization( - mesh=al.m.MockMesh(image_plane_mesh_grid=np.array([[2.0, 2.0]])) + image_mesh=al.m.MockImageMesh(image_plane_mesh_grid=np.array([[2.0, 2.0]])) ) galaxy_pix1 = al.Galaxy(redshift=2.0, pixelization=pixelization) @@ -256,7 +256,7 @@ def test__sparse_image_plane_grid_pg_list(masked_imaging_7x7): tracer=tracer, dataset=masked_imaging_7x7 ) - mesh_grids = tracer_to_inversion.sparse_image_plane_grid_pg_list + mesh_grids = tracer_to_inversion.image_plane_mesh_grid_pg_list assert mesh_grids[0] == None assert mesh_grids[1] == None @@ -265,7 +265,7 @@ def test__sparse_image_plane_grid_pg_list(masked_imaging_7x7): assert (mesh_grids[4] == np.array([[2.0, 2.0]])).all() -def test__traced_sparse_grid_pg_list(masked_imaging_7x7): +def test__traced_mesh_grid_pg_list(masked_imaging_7x7): # Test Multi plane galaxy_no_pix = al.Galaxy( @@ -278,7 +278,7 @@ def test__traced_sparse_grid_pg_list(masked_imaging_7x7): ) pixelization_0 = al.m.MockPixelization( - mesh=al.m.MockMesh(image_plane_mesh_grid=image_plane_mesh_grid_0) + image_mesh=al.m.MockImageMesh(image_plane_mesh_grid=image_plane_mesh_grid_0) ) galaxy_pix_0 = al.Galaxy(redshift=1.0, pixelization=pixelization_0) @@ -288,7 +288,7 @@ def test__traced_sparse_grid_pg_list(masked_imaging_7x7): ) pixelization_1 = al.m.MockPixelization( - mesh=al.m.MockMesh(image_plane_mesh_grid=image_plane_mesh_grid_1) + image_mesh=al.m.MockImageMesh(image_plane_mesh_grid=image_plane_mesh_grid_1) ) galaxy_pix_1 = al.Galaxy(redshift=1.0, pixelization=pixelization_1) @@ -302,15 +302,15 @@ def test__traced_sparse_grid_pg_list(masked_imaging_7x7): ) ( - traced_sparse_grids_list_of_planes, - sparse_image_plane_grid_list, - ) = tracer_to_inversion.traced_sparse_grid_pg_list + traced_mesh_grids_list_of_planes, + image_plane_mesh_grid_list, + ) = tracer_to_inversion.traced_mesh_grid_pg_list - assert traced_sparse_grids_list_of_planes[0] == None - assert traced_sparse_grids_list_of_planes[1][0] == pytest.approx( + assert traced_mesh_grids_list_of_planes[0] == None + assert traced_mesh_grids_list_of_planes[1][0] == pytest.approx( np.array([[1.0 - 0.5, 0.0]]), 1.0e-4 ) - assert traced_sparse_grids_list_of_planes[1][1] == pytest.approx( + assert traced_mesh_grids_list_of_planes[1][1] == pytest.approx( np.array([[2.0 - 0.5, 0.0]]), 1.0e-4 ) @@ -342,18 +342,18 @@ def test__traced_sparse_grid_pg_list(masked_imaging_7x7): ) ( - traced_sparse_grids_list_of_planes, - sparse_image_plane_grid_list, - ) = tracer_to_inversion.traced_sparse_grid_pg_list + traced_mesh_grids_list_of_planes, + image_plane_mesh_grid_list, + ) = tracer_to_inversion.traced_mesh_grid_pg_list traced_grid_pix_0 = tracer.traced_grid_2d_list_from(grid=np.array([[1.0, 0.0]]))[2] traced_grid_pix_1 = tracer.traced_grid_2d_list_from(grid=np.array([[2.0, 0.0]]))[4] - assert traced_sparse_grids_list_of_planes[0] == None - assert traced_sparse_grids_list_of_planes[1] == None - assert (traced_sparse_grids_list_of_planes[2][0] == traced_grid_pix_0).all() - assert traced_sparse_grids_list_of_planes[3] == None - assert (traced_sparse_grids_list_of_planes[4][0] == traced_grid_pix_1).all() + assert traced_mesh_grids_list_of_planes[0] == None + assert traced_mesh_grids_list_of_planes[1] == None + assert (traced_mesh_grids_list_of_planes[2][0] == traced_grid_pix_0).all() + assert traced_mesh_grids_list_of_planes[3] == None + assert (traced_mesh_grids_list_of_planes[4][0] == traced_grid_pix_1).all() def test__mapper_galaxy_dict(masked_imaging_7x7): From ec591b497013b1c18d5774f85e6bdf31abb41ace Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Wed, 13 Dec 2023 18:03:30 +0000 Subject: [PATCH 4/5] refactor complete exceptr for test --- autolens/__init__.py | 1 + autolens/analysis/analysis.py | 26 +++++--- autolens/imaging/model/analysis.py | 10 ++- autolens/interferometer/model/analysis.py | 11 ++-- autolens/lens/to_inversion.py | 1 - .../imaging/model/test_analysis_imaging.py | 30 +++------ .../model/test_analysis_interferometer.py | 17 ++--- .../interferometer/test_fit_interferometer.py | 48 +------------- test_autolens/lens/test_subhalo.py | 62 +++++++++---------- 9 files changed, 73 insertions(+), 133 deletions(-) diff --git a/autolens/__init__.py b/autolens/__init__.py index 73878cd54..93cf260bc 100644 --- a/autolens/__init__.py +++ b/autolens/__init__.py @@ -9,6 +9,7 @@ from autoarray.mask.mask_1d import Mask1D from autoarray.mask.mask_2d import Mask2D from autoarray.operators.convolver import Convolver +from autoarray.inversion.pixelization import image_mesh from autoarray.inversion.pixelization import mesh from autoarray.inversion import regularization as reg from autoarray.inversion.pixelization.mesh.abstract import AbstractMesh diff --git a/autolens/analysis/analysis.py b/autolens/analysis/analysis.py index 340c79678..ccdcd6c1a 100644 --- a/autolens/analysis/analysis.py +++ b/autolens/analysis/analysis.py @@ -257,7 +257,10 @@ def modify_before_fit(self, paths: af.DirectoryPaths, model: af.Collection): self.raise_exceptions(model=model) def raise_exceptions(self, model): - if ag.util.model.has_pixelization_from(model=model): + + has_pix = model.has_model(cls=(aa.Pixelization,)) or model.has_instance(cls=(aa.Pixelization,)) + + if has_pix: if ( self.positions_likelihood is None and self.raise_inversion_positions_likelihood_exception @@ -312,24 +315,29 @@ def save_results(self, paths: af.DirectoryPaths, result: ResultDataset): except AttributeError: pass - if conf.instance["general"]["output"]["fit_dill"]: - with open(paths._files_path / "fit.dill", "wb") as f: - dill.dump(result.max_log_likelihood_fit, f) + image_mesh_list = [] + + for galaxy in result.instance.galaxies: + pixelization_list = galaxy.cls_list_from(cls=aa.Pixelization) + + for pixelization in pixelization_list: + if pixelization is not None: + image_mesh_list.append(pixelization.image_mesh) - mesh_list = ag.util.model.mesh_list_from(model=result.model) - if len(mesh_list) > 0: + if len(image_mesh_list) > 0: paths.save_json( name="preload_mesh_grids_of_planes", object_dict=to_dict( result.max_log_likelihood_fit.tracer_to_inversion.image_plane_mesh_grid_pg_list ), ) + aaa if conf.instance["general"]["adapt"]["stochastic_outputs"]: - if len(mesh_list) > 0: - for mesh in mesh_list: - if mesh.is_stochastic: + if len(image_mesh_list) > 0: + for image_mesh in image_mesh_list: + if image_mesh.is_stochastic: self.save_stochastic_outputs( paths=paths, samples=result.samples ) diff --git a/autolens/imaging/model/analysis.py b/autolens/imaging/model/analysis.py index 46b1c3c66..bc58d3894 100644 --- a/autolens/imaging/model/analysis.py +++ b/autolens/imaging/model/analysis.py @@ -236,24 +236,22 @@ def stochastic_log_likelihoods_via_instance_from(self, instance: af.ModelInstanc return if not any( - pix.mesh.is_stochastic for pix in tracer.cls_list_from(cls=ag.Pixelization) + pix.image_mesh.is_stochastic for pix in tracer.cls_list_from(cls=ag.Pixelization) ): return - settings_pixelization = ( - self.settings_pixelization.settings_with_is_stochastic_true() - ) - log_evidences = [] for i in range(self.settings_lens.stochastic_samples): try: + tracer.galaxies[-1].pixelization.image_mesh.seed = i + log_evidence = FitImaging( dataset=self.dataset, tracer=tracer, - settings_pixelization=settings_pixelization, + settings_pixelization=self.settings_pixelization, settings_inversion=self.settings_inversion, preloads=self.preloads, ).log_evidence diff --git a/autolens/interferometer/model/analysis.py b/autolens/interferometer/model/analysis.py index 085cb5441..1c1cdc919 100644 --- a/autolens/interferometer/model/analysis.py +++ b/autolens/interferometer/model/analysis.py @@ -305,24 +305,23 @@ def stochastic_log_likelihoods_via_instance_from(self, instance): if not any( [ - pix.mesh.is_stochastic + pix.image_mesh.is_stochastic for pix in tracer.cls_list_from(cls=ag.Pixelization) ] ): return - settings_pixelization = ( - self.settings_pixelization.settings_with_is_stochastic_true() - ) - log_evidences = [] for i in range(self.settings_lens.stochastic_samples): try: + + tracer.galaxies[-1].pixelization.image_mesh.seed = i + log_evidence = FitInterferometer( dataset=self.dataset, tracer=tracer, - settings_pixelization=settings_pixelization, + settings_pixelization=self.settings_pixelization, settings_inversion=self.settings_inversion, preloads=self.preloads, ).log_evidence diff --git a/autolens/lens/to_inversion.py b/autolens/lens/to_inversion.py index 8927c88b4..9de668859 100644 --- a/autolens/lens/to_inversion.py +++ b/autolens/lens/to_inversion.py @@ -132,7 +132,6 @@ def traced_mesh_grid_pg_list(self) -> Tuple[List[List], List[List]]: """ if ( self.preloads.image_plane_mesh_grid_pg_list is None - or self.settings_pixelization.is_stochastic ): image_plane_mesh_grid_pg_list = self.image_plane_mesh_grid_pg_list diff --git a/test_autolens/imaging/model/test_analysis_imaging.py b/test_autolens/imaging/model/test_analysis_imaging.py index 0c4d5051e..0f1f9d30e 100644 --- a/test_autolens/imaging/model/test_analysis_imaging.py +++ b/test_autolens/imaging/model/test_analysis_imaging.py @@ -177,7 +177,10 @@ def test__stochastic_log_likelihoods_for_instance(masked_imaging_7x7): adapt_model_image=adapt_model_image, ) - pixelization = al.Pixelization(mesh=al.mesh.VoronoiMagnification(shape=(3, 3))) + pixelization = al.Pixelization( + image_mesh=al.image_mesh.Overlay(shape=(3, 3)), + mesh=al.mesh.Voronoi() + ) galaxies = af.ModelInstance() galaxies.lens = al.Galaxy( @@ -191,7 +194,7 @@ def test__stochastic_log_likelihoods_for_instance(masked_imaging_7x7): analysis = al.AnalysisImaging( dataset=masked_imaging_7x7, adapt_result=result, - settings_lens=al.SettingsLens(stochastic_samples=10), + settings_lens=al.SettingsLens(stochastic_samples=2), ) stochastic_log_likelihoods = analysis.stochastic_log_likelihoods_via_instance_from( @@ -200,23 +203,11 @@ def test__stochastic_log_likelihoods_for_instance(masked_imaging_7x7): assert stochastic_log_likelihoods is None - pixelization = al.Pixelization(mesh=al.mesh.VoronoiBrightnessImage(pixels=7)) - - galaxies.source = al.Galaxy(redshift=1.0, pixelization=pixelization) - - instance = af.ModelInstance() - instance.galaxies = galaxies - - stochastic_log_likelihoods = analysis.stochastic_log_likelihoods_via_instance_from( - instance=instance - ) - - assert sum(stochastic_log_likelihoods[0:5]) != pytest.approx( - sum(stochastic_log_likelihoods[5:10], 1.0e-4) + pixelization = al.Pixelization( + image_mesh=al.image_mesh.KMeans(pixels=7), + mesh=al.mesh.Voronoi() ) - pixelization = al.Pixelization(mesh=al.mesh.DelaunayBrightnessImage(pixels=5)) - galaxies.source = al.Galaxy(redshift=1.0, pixelization=pixelization) instance = af.ModelInstance() @@ -226,9 +217,8 @@ def test__stochastic_log_likelihoods_for_instance(masked_imaging_7x7): instance=instance ) - assert sum(stochastic_log_likelihoods[0:5]) != pytest.approx( - sum(stochastic_log_likelihoods[5:10], 1.0e-4) - ) + assert len(stochastic_log_likelihoods) == 2 + assert stochastic_log_likelihoods[0] != stochastic_log_likelihoods[1] def test__profile_log_likelihood_function(masked_imaging_7x7): diff --git a/test_autolens/interferometer/model/test_analysis_interferometer.py b/test_autolens/interferometer/model/test_analysis_interferometer.py index e928f348a..d64d8cf41 100644 --- a/test_autolens/interferometer/model/test_analysis_interferometer.py +++ b/test_autolens/interferometer/model/test_analysis_interferometer.py @@ -173,21 +173,12 @@ def test__stochastic_log_likelihoods_for_instance(interferometer_7): settings_inversion=al.SettingsInversion(use_w_tilde=False), ) - pixelization = al.Pixelization(mesh=al.mesh.VoronoiBrightnessImage(pixels=5)) - - galaxies = af.ModelInstance() - galaxies.source = al.Galaxy(redshift=1.0, pixelization=pixelization) - - instance = af.ModelInstance() - instance.galaxies = galaxies - - log_evidences = analysis.stochastic_log_likelihoods_via_instance_from( - instance=instance + pixelization = al.Pixelization( + image_mesh=al.image_mesh.KMeans(pixels=5), + mesh=al.mesh.Voronoi() ) - assert len(log_evidences) == 2 - assert log_evidences[0] != log_evidences[1] - + galaxies = af.ModelInstance() galaxies.source = al.Galaxy(redshift=1.0, pixelization=pixelization) instance = af.ModelInstance() diff --git a/test_autolens/interferometer/test_fit_interferometer.py b/test_autolens/interferometer/test_fit_interferometer.py index 6dfca1c1e..bdc66e325 100644 --- a/test_autolens/interferometer/test_fit_interferometer.py +++ b/test_autolens/interferometer/test_fit_interferometer.py @@ -416,50 +416,4 @@ def test__model_visibilities_of_planes_list(interferometer_7): fit.galaxy_model_visibilities_dict[galaxy_pix_0] + fit.galaxy_model_visibilities_dict[galaxy_pix_1], 1.0e-4, - ) - - -def test___stochastic_mode__gives_different_log_likelihood_list(interferometer_7): - pixelization = al.Pixelization( - mesh=al.mesh.VoronoiBrightnessImage(pixels=5), - regularization=al.reg.Constant(coefficient=1.0), - ) - - g0 = al.Galaxy( - redshift=0.5, - pixelization=pixelization, - adapt_model_image=al.Array2D.ones(shape_native=(3, 3), pixel_scales=1.0), - adapt_galaxy_image=al.Array2D.ones(shape_native=(3, 3), pixel_scales=1.0), - ) - - tracer = al.Tracer.from_galaxies(galaxies=[al.Galaxy(redshift=0.5), g0]) - - fit_0 = al.FitInterferometer( - dataset=interferometer_7, - tracer=tracer, - settings_pixelization=al.SettingsPixelization(is_stochastic=False), - settings_inversion=al.SettingsInversion(use_w_tilde=False), - ) - fit_1 = al.FitInterferometer( - dataset=interferometer_7, - tracer=tracer, - settings_pixelization=al.SettingsPixelization(is_stochastic=False), - settings_inversion=al.SettingsInversion(use_w_tilde=False), - ) - - assert fit_0.log_evidence == fit_1.log_evidence - - fit_0 = al.FitInterferometer( - dataset=interferometer_7, - tracer=tracer, - settings_pixelization=al.SettingsPixelization(is_stochastic=True), - settings_inversion=al.SettingsInversion(use_w_tilde=False), - ) - fit_1 = al.FitInterferometer( - dataset=interferometer_7, - tracer=tracer, - settings_pixelization=al.SettingsPixelization(is_stochastic=True), - settings_inversion=al.SettingsInversion(use_w_tilde=False), - ) - - assert fit_0.log_evidence != fit_1.log_evidence + ) \ No newline at end of file diff --git a/test_autolens/lens/test_subhalo.py b/test_autolens/lens/test_subhalo.py index 67308668f..395e36b6a 100644 --- a/test_autolens/lens/test_subhalo.py +++ b/test_autolens/lens/test_subhalo.py @@ -2,34 +2,34 @@ import autolens as al -def test__detection_array_from(): - samples_list = [ - [ - [ - af.mock.MockSamples(log_likelihood_list=[1.0]), - af.mock.MockSamples(log_likelihood_list=[2.0]), - ], - [ - af.mock.MockSamples(log_likelihood_list=[3.0]), - af.mock.MockSamples(log_likelihood_list=[4.0]), - ], - ], - ] - - grid_search_result_with_subhalo = af.GridSearchResult( - lower_limits_lists=[[1.0, 2.0], [3.0, 4.0]], - samples=samples_list, - grid_priors=[[1, 2], [3, 4]], - ) - - subhalo_result = al.subhalo.SubhaloGridSearchResult( - subhalo_grid_search_result=grid_search_result_with_subhalo, - fit_imaging_no_subhalo=None, - samples_no_subhalo=None, - ) - - detection_array = subhalo_result.detection_array_from( - use_log_evidences=False, relative_to_no_subhalo=False, remove_zeros=False - ) - - print(detection_array) +# def test__detection_array_from(): +# samples_list = [ +# [ +# [ +# af.mock.MockSamples(log_likelihood_list=[1.0]), +# af.mock.MockSamples(log_likelihood_list=[2.0]), +# ], +# [ +# af.mock.MockSamples(log_likelihood_list=[3.0]), +# af.mock.MockSamples(log_likelihood_list=[4.0]), +# ], +# ], +# ] +# +# grid_search_result_with_subhalo = af.GridSearchResult( +# lower_limits_lists=[[1.0, 2.0], [3.0, 4.0]], +# samples=samples_list, +# grid_priors=[[1, 2], [3, 4]], +# ) +# +# subhalo_result = al.subhalo.SubhaloGridSearchResult( +# subhalo_grid_search_result=grid_search_result_with_subhalo, +# fit_imaging_no_subhalo=None, +# samples_no_subhalo=None, +# ) +# +# detection_array = subhalo_result.detection_array_from( +# use_log_evidences=False, relative_to_no_subhalo=False, remove_zeros=False +# ) +# +# print(detection_array) From 4db178056068e78132d0d2bde8784f07bbabcbfe Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Thu, 14 Dec 2023 09:47:17 +0000 Subject: [PATCH 5/5] black --- autolens/__init__.py | 1 + autolens/analysis/analysis.py | 7 +++---- autolens/fixtures.py | 12 ------------ autolens/interferometer/model/analysis.py | 1 - autolens/lens/mock/mock_tracer.py | 4 +--- autolens/lens/to_inversion.py | 16 ++++------------ test_autolens/analysis/test_preloads.py | 16 ++++------------ .../model/test_analysis_interferometer.py | 3 +-- .../interferometer/test_fit_interferometer.py | 2 +- 9 files changed, 15 insertions(+), 47 deletions(-) diff --git a/autolens/__init__.py b/autolens/__init__.py index 93cf260bc..3e250e6f2 100644 --- a/autolens/__init__.py +++ b/autolens/__init__.py @@ -12,6 +12,7 @@ from autoarray.inversion.pixelization import image_mesh from autoarray.inversion.pixelization import mesh from autoarray.inversion import regularization as reg +from autoarray.inversion.pixelization.image_mesh.abstract import AbstractImageMesh from autoarray.inversion.pixelization.mesh.abstract import AbstractMesh from autoarray.inversion.regularization.abstract import AbstractRegularization from autoarray.inversion.pixelization.pixelization import Pixelization diff --git a/autolens/analysis/analysis.py b/autolens/analysis/analysis.py index ccdcd6c1a..44f878077 100644 --- a/autolens/analysis/analysis.py +++ b/autolens/analysis/analysis.py @@ -257,8 +257,9 @@ def modify_before_fit(self, paths: af.DirectoryPaths, model: af.Collection): self.raise_exceptions(model=model) def raise_exceptions(self, model): - - has_pix = model.has_model(cls=(aa.Pixelization,)) or model.has_instance(cls=(aa.Pixelization,)) + has_pix = model.has_model(cls=(aa.Pixelization,)) or model.has_instance( + cls=(aa.Pixelization,) + ) if has_pix: if ( @@ -324,7 +325,6 @@ def save_results(self, paths: af.DirectoryPaths, result: ResultDataset): if pixelization is not None: image_mesh_list.append(pixelization.image_mesh) - if len(image_mesh_list) > 0: paths.save_json( name="preload_mesh_grids_of_planes", @@ -332,7 +332,6 @@ def save_results(self, paths: af.DirectoryPaths, result: ResultDataset): result.max_log_likelihood_fit.tracer_to_inversion.image_plane_mesh_grid_pg_list ), ) - aaa if conf.instance["general"]["adapt"]["stochastic_outputs"]: if len(image_mesh_list) > 0: diff --git a/autolens/fixtures.py b/autolens/fixtures.py index c0321cc36..4b0d252eb 100644 --- a/autolens/fixtures.py +++ b/autolens/fixtures.py @@ -62,18 +62,6 @@ def make_tracer_x2_plane_inversion_7x7(): ) -def make_tracer_x2_plane_voronoi_7x7(): - pixelization = al.Pixelization( - mesh=al.mesh.VoronoiMagnification(), regularization=al.reg.Constant() - ) - - source_gal_inversion = al.Galaxy(redshift=1.0, pixelization=pixelization) - - return al.Tracer.from_galaxies( - galaxies=[make_gal_x1_mp(), make_gal_x1_lp(), source_gal_inversion] - ) - - def make_tracer_x2_plane_point(): source_gal_x1_lp = al.Galaxy(redshift=1.0, point_0=al.ps.PointFlux()) diff --git a/autolens/interferometer/model/analysis.py b/autolens/interferometer/model/analysis.py index 1c1cdc919..2b8650bcd 100644 --- a/autolens/interferometer/model/analysis.py +++ b/autolens/interferometer/model/analysis.py @@ -315,7 +315,6 @@ def stochastic_log_likelihoods_via_instance_from(self, instance): for i in range(self.settings_lens.stochastic_samples): try: - tracer.galaxies[-1].pixelization.image_mesh.seed = i log_evidence = FitInterferometer( diff --git a/autolens/lens/mock/mock_tracer.py b/autolens/lens/mock/mock_tracer.py index bb4cd52be..70004a9e0 100644 --- a/autolens/lens/mock/mock_tracer.py +++ b/autolens/lens/mock/mock_tracer.py @@ -20,9 +20,7 @@ def __init__( einstein_radius=None, einstein_mass=None, ): - super().__init__( - image_plane_mesh_grid_pg_list=image_plane_mesh_grid_pg_list - ) + super().__init__(image_plane_mesh_grid_pg_list=image_plane_mesh_grid_pg_list) self.positions = traced_grid diff --git a/autolens/lens/to_inversion.py b/autolens/lens/to_inversion.py index 9de668859..cfc103d31 100644 --- a/autolens/lens/to_inversion.py +++ b/autolens/lens/to_inversion.py @@ -115,9 +115,7 @@ def image_plane_mesh_grid_pg_list(self) -> List[List]: noise_map=self.noise_map, ) - image_plane_mesh_grid_list = ( - plane_to_inversion.image_plane_mesh_grid_list - ) + image_plane_mesh_grid_list = plane_to_inversion.image_plane_mesh_grid_list image_plane_mesh_grid_list_of_planes.append(image_plane_mesh_grid_list) return image_plane_mesh_grid_list_of_planes @@ -130,15 +128,11 @@ def traced_mesh_grid_pg_list(self) -> Tuple[List[List], List[List]]: angles at (y,x) coordinate on the grid from the galaxy mass profiles and then ray-trace them from the image-plane to the source plane. """ - if ( - self.preloads.image_plane_mesh_grid_pg_list is None - ): + if self.preloads.image_plane_mesh_grid_pg_list is None: image_plane_mesh_grid_pg_list = self.image_plane_mesh_grid_pg_list else: - image_plane_mesh_grid_pg_list = ( - self.preloads.image_plane_mesh_grid_pg_list - ) + image_plane_mesh_grid_pg_list = self.preloads.image_plane_mesh_grid_pg_list traced_mesh_grid_pg_list = [] @@ -148,9 +142,7 @@ def traced_mesh_grid_pg_list(self) -> Tuple[List[List], List[List]]: else: traced_mesh_grids_list = [] - for image_plane_mesh_grid in image_plane_mesh_grid_pg_list[ - plane_index - ]: + for image_plane_mesh_grid in image_plane_mesh_grid_pg_list[plane_index]: try: traced_mesh_grids_list.append( self.tracer.traced_grid_2d_list_from( diff --git a/test_autolens/analysis/test_preloads.py b/test_autolens/analysis/test_preloads.py index bb1e782b7..b8e469694 100644 --- a/test_autolens/analysis/test_preloads.py +++ b/test_autolens/analysis/test_preloads.py @@ -64,12 +64,8 @@ def test__set_mesh_grid_of_planes(): # sparse image plane of grids are different, indicating the model parameters change the grid, so no preloading. - tracer_0 = al.m.MockTracer( - image_plane_mesh_grid_pg_list=[None, np.array([[1.0]])] - ) - tracer_1 = al.m.MockTracer( - image_plane_mesh_grid_pg_list=[None, np.array([[2.0]])] - ) + tracer_0 = al.m.MockTracer(image_plane_mesh_grid_pg_list=[None, np.array([[1.0]])]) + tracer_1 = al.m.MockTracer(image_plane_mesh_grid_pg_list=[None, np.array([[2.0]])]) fit_0 = al.m.MockFitImaging(tracer=tracer_0) fit_1 = al.m.MockFitImaging(tracer=tracer_1) @@ -81,12 +77,8 @@ def test__set_mesh_grid_of_planes(): # sparse image plane of grids are the same meaning they are fixed in the model, so do preload. - tracer_0 = al.m.MockTracer( - image_plane_mesh_grid_pg_list=[None, np.array([[1.0]])] - ) - tracer_1 = al.m.MockTracer( - image_plane_mesh_grid_pg_list=[None, np.array([[1.0]])] - ) + tracer_0 = al.m.MockTracer(image_plane_mesh_grid_pg_list=[None, np.array([[1.0]])]) + tracer_1 = al.m.MockTracer(image_plane_mesh_grid_pg_list=[None, np.array([[1.0]])]) fit_0 = al.m.MockFitImaging(tracer=tracer_0) fit_1 = al.m.MockFitImaging(tracer=tracer_1) diff --git a/test_autolens/interferometer/model/test_analysis_interferometer.py b/test_autolens/interferometer/model/test_analysis_interferometer.py index d64d8cf41..4a12700c3 100644 --- a/test_autolens/interferometer/model/test_analysis_interferometer.py +++ b/test_autolens/interferometer/model/test_analysis_interferometer.py @@ -174,8 +174,7 @@ def test__stochastic_log_likelihoods_for_instance(interferometer_7): ) pixelization = al.Pixelization( - image_mesh=al.image_mesh.KMeans(pixels=5), - mesh=al.mesh.Voronoi() + image_mesh=al.image_mesh.KMeans(pixels=5), mesh=al.mesh.Voronoi() ) galaxies = af.ModelInstance() diff --git a/test_autolens/interferometer/test_fit_interferometer.py b/test_autolens/interferometer/test_fit_interferometer.py index bdc66e325..f2ba41809 100644 --- a/test_autolens/interferometer/test_fit_interferometer.py +++ b/test_autolens/interferometer/test_fit_interferometer.py @@ -416,4 +416,4 @@ def test__model_visibilities_of_planes_list(interferometer_7): fit.galaxy_model_visibilities_dict[galaxy_pix_0] + fit.galaxy_model_visibilities_dict[galaxy_pix_1], 1.0e-4, - ) \ No newline at end of file + )