From c7c04417061215fa1381bc8774d6e37c66a9fdb8 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Thu, 21 Dec 2023 21:33:00 +0000 Subject: [PATCH] final test fixdd --- autolens/analysis/visualizer.py | 5 +-- autolens/fixtures.py | 5 ++- autolens/interferometer/model/analysis.py | 10 ++---- autolens/interferometer/model/result.py | 4 +-- autolens/lens/to_inversion.py | 20 +++++------- autolens/point/model/analysis.py | 4 +-- autolens/quantity/model/analysis.py | 4 +-- .../aggregator/test_aggregator_fit_imaging.py | 3 +- .../test_aggregator_fit_interferometer.py | 2 +- test_autolens/analysis/test_analysis.py | 8 ++--- test_autolens/conftest.py | 1 + .../model/test_analysis_interferometer.py | 32 ------------------- test_autolens/lens/test_to_inversion.py | 8 ++--- 13 files changed, 26 insertions(+), 80 deletions(-) diff --git a/autolens/analysis/visualizer.py b/autolens/analysis/visualizer.py index 0d6b14ae6..18e72d521 100644 --- a/autolens/analysis/visualizer.py +++ b/autolens/analysis/visualizer.py @@ -167,10 +167,7 @@ def should_plot(name): if should_plot("image_with_positions"): image_plotter.figure_2d() - def visualize_adapt_images( - self, - adapt_images : ag.AdaptImages - ): + def visualize_adapt_images(self, adapt_images: ag.AdaptImages): """ Visualizes the adapt-images and adapt image inferred by a model-fit. diff --git a/autolens/fixtures.py b/autolens/fixtures.py index 0ec38054e..1920292a6 100644 --- a/autolens/fixtures.py +++ b/autolens/fixtures.py @@ -148,14 +148,13 @@ def make_analysis_imaging_7x7(): return al.AnalysisImaging( dataset=make_masked_imaging_7x7(), settings_inversion=aa.SettingsInversion(use_w_tilde=False), - adapt_images=make_adapt_images_7x7() + adapt_images=make_adapt_images_7x7(), ) def make_analysis_interferometer_7(): return al.AnalysisInterferometer( - dataset=make_interferometer_7(), - adapt_images=make_adapt_images_7x7() + dataset=make_interferometer_7(), adapt_images=make_adapt_images_7x7() ) diff --git a/autolens/interferometer/model/analysis.py b/autolens/interferometer/model/analysis.py index b8bb919ec..f86c46fe5 100644 --- a/autolens/interferometer/model/analysis.py +++ b/autolens/interferometer/model/analysis.py @@ -166,9 +166,7 @@ def log_likelihood_function(self, instance): raise e try: - return self.fit_from( - instance=instance - ).figure_of_merit + return self.fit_from(instance=instance).figure_of_merit except ( PixelizationException, exc.PixelizationException, @@ -212,7 +210,7 @@ def fit_from( FitInterferometer The fit of the plane to the interferometer dataset, which includes the log likelihood. """ - + tracer = self.tracer_via_instance_from( instance=instance, run_time_dict=run_time_dict ) @@ -257,9 +255,7 @@ def visualize_before_fit(self, paths: af.DirectoryPaths, model: af.Collection): ) if self.adapt_images is not None: - visualizer.visualize_adapt_images( - adapt_images=self.adapt_images - ) + visualizer.visualize_adapt_images(adapt_images=self.adapt_images) def visualize(self, paths: af.DirectoryPaths, instance, during_analysis): """ diff --git a/autolens/interferometer/model/result.py b/autolens/interferometer/model/result.py index 566093703..3edb5dd3a 100644 --- a/autolens/interferometer/model/result.py +++ b/autolens/interferometer/model/result.py @@ -47,9 +47,7 @@ def max_log_likelihood_fit(self) -> FitInterferometer: An instance of a `FitInterferometer` corresponding to the maximum log likelihood model inferred by the non-linear search. """ - return self.analysis.fit_from( - instance=self.instance - ) + return self.analysis.fit_from(instance=self.instance) @property def max_log_likelihood_tracer(self) -> Tracer: diff --git a/autolens/lens/to_inversion.py b/autolens/lens/to_inversion.py index 01a799176..8d4716a52 100644 --- a/autolens/lens/to_inversion.py +++ b/autolens/lens/to_inversion.py @@ -75,7 +75,7 @@ def lp_linear_func_list_galaxy_dict( blurring_grid=traced_blurring_grids_of_planes_list[plane_index], noise_map=self.noise_map, settings_inversion=self.settings_inversion, - adapt_images=self.adapt_images + adapt_images=self.adapt_images, ) lp_linear_galaxy_dict_of_plane = ( @@ -94,19 +94,17 @@ def cls_pg_list_from(self, cls: Type) -> List: @cached_property def adapt_galaxy_image_pg_list(self) -> List: - adapt_galaxy_image_pg_list = [] for plane in self.planes: - if plane.has(cls=aa.Pixelization): - plane_image_list = [] - galaxies_with_pixelization_list = plane.galaxies_with_cls_list_from(cls=aa.Pixelization) + galaxies_with_pixelization_list = plane.galaxies_with_cls_list_from( + cls=aa.Pixelization + ) for galaxy in galaxies_with_pixelization_list: - try: image = self.adapt_images.galaxy_image_dict[galaxy] except (AttributeError, KeyError): @@ -117,7 +115,6 @@ def adapt_galaxy_image_pg_list(self) -> List: adapt_galaxy_image_pg_list.append(plane_image_list) else: - adapt_galaxy_image_pg_list.append([]) return adapt_galaxy_image_pg_list @@ -226,10 +223,9 @@ def mapper_galaxy_dict(self) -> Dict[aa.AbstractMapper, ag.Galaxy]: pixelization_list = self.cls_pg_list_from(cls=aa.Pixelization) try: - - adapt_galaxy_image = self.adapt_galaxy_image_pg_list[plane_index][ - mapper_index - ] + adapt_galaxy_image = self.adapt_galaxy_image_pg_list[ + plane_index + ][mapper_index] except AttributeError: adapt_galaxy_image = None @@ -244,7 +240,7 @@ def mapper_galaxy_dict(self) -> Dict[aa.AbstractMapper, ag.Galaxy]: image_plane_mesh_grid=image_plane_mesh_grid_list[plane_index][ mapper_index ], - adapt_galaxy_image=adapt_galaxy_image + adapt_galaxy_image=adapt_galaxy_image, ) galaxy = galaxies_with_pixelization_list[mapper_index] diff --git a/autolens/point/model/analysis.py b/autolens/point/model/analysis.py index 7e53da49b..49d89362d 100644 --- a/autolens/point/model/analysis.py +++ b/autolens/point/model/analysis.py @@ -81,9 +81,7 @@ def log_likelihood_function(self, instance): except (AttributeError, ValueError, TypeError, NumbaException) as e: raise exc.FitException from e - def fit_from( - self, instance, run_time_dict: Optional[Dict] = None - ) -> FitPointDict: + def fit_from(self, instance, run_time_dict: Optional[Dict] = None) -> FitPointDict: tracer = self.tracer_via_instance_from( instance=instance, run_time_dict=run_time_dict ) diff --git a/autolens/quantity/model/analysis.py b/autolens/quantity/model/analysis.py index bcf11396f..276f1013e 100644 --- a/autolens/quantity/model/analysis.py +++ b/autolens/quantity/model/analysis.py @@ -51,9 +51,7 @@ def __init__( """ super().__init__(dataset=dataset, func_str=func_str, cosmology=cosmology) - AnalysisLensing.__init__( - self=self, cosmology=cosmology - ) + AnalysisLensing.__init__(self=self, cosmology=cosmology) def fit_quantity_for_instance(self, instance: af.ModelInstance) -> FitQuantity: """ diff --git a/test_autolens/aggregator/test_aggregator_fit_imaging.py b/test_autolens/aggregator/test_aggregator_fit_imaging.py index fdfd330fa..ef1b255db 100644 --- a/test_autolens/aggregator/test_aggregator_fit_imaging.py +++ b/test_autolens/aggregator/test_aggregator_fit_imaging.py @@ -114,7 +114,6 @@ def test__fit_imaging__adapt_images( for fit_gen in fit_pdf_gen: for fit_list in fit_gen: - i += 1 assert ( @@ -127,4 +126,4 @@ def test__fit_imaging__adapt_images( assert i == 2 - clean(database_file=database_file) \ No newline at end of file + clean(database_file=database_file) diff --git a/test_autolens/aggregator/test_aggregator_fit_interferometer.py b/test_autolens/aggregator/test_aggregator_fit_interferometer.py index 171dd4b44..aaffa9862 100644 --- a/test_autolens/aggregator/test_aggregator_fit_interferometer.py +++ b/test_autolens/aggregator/test_aggregator_fit_interferometer.py @@ -132,4 +132,4 @@ def test__fit_interferometer__adapt_images( assert i == 2 - clean(database_file=database_file) \ No newline at end of file + clean(database_file=database_file) diff --git a/test_autolens/analysis/test_analysis.py b/test_autolens/analysis/test_analysis.py index 83a6a74d5..ebbdf96d4 100644 --- a/test_autolens/analysis/test_analysis.py +++ b/test_autolens/analysis/test_analysis.py @@ -78,7 +78,9 @@ def test__tracer_for_instance__subhalo_redshift_rescale_used(analysis_imaging_7x assert tracer.galaxies[1].mass.centre == pytest.approx((-0.19959, -0.39919), 1.0e-4) -def test__relocate_pix_border__determines_if_border_pixel_relocation_is_used(masked_imaging_7x7): +def test__relocate_pix_border__determines_if_border_pixel_relocation_is_used( + masked_imaging_7x7, +): pixelization = al.Pixelization( mesh=al.mesh.Rectangular(shape=(3, 3)), regularization=al.reg.Constant(coefficient=1.0), @@ -105,9 +107,7 @@ def test__relocate_pix_border__determines_if_border_pixel_relocation_is_used(mas analysis.dataset.grid_pixelization[4] = np.array([[500.0, 0.0]]) instance = model.instance_from_unit_vector([]) - fit = analysis.fit_from( - instance=instance - ) + fit = analysis.fit_from(instance=instance) assert fit.inversion.linear_obj_list[0].source_plane_data_grid[4][ 0 diff --git a/test_autolens/conftest.py b/test_autolens/conftest.py index d0674601e..e5c7f2450 100644 --- a/test_autolens/conftest.py +++ b/test_autolens/conftest.py @@ -385,6 +385,7 @@ def make_adapt_model_image_7x7(): def make_adapt_galaxy_name_image_dict_7x7(): return fixtures.make_adapt_galaxy_name_image_dict_7x7() + @pytest.fixture(name="adapt_images_7x7") def make_adapt_images_7x7(): return fixtures.make_adapt_images_7x7() diff --git a/test_autolens/interferometer/model/test_analysis_interferometer.py b/test_autolens/interferometer/model/test_analysis_interferometer.py index b6e8c3192..73deb53c5 100644 --- a/test_autolens/interferometer/model/test_analysis_interferometer.py +++ b/test_autolens/interferometer/model/test_analysis_interferometer.py @@ -115,38 +115,6 @@ def test__positions__likelihood_overwrite__changes_likelihood( assert analysis_log_likelihood == pytest.approx(-22048700567.590656, 1.0e-4) -def test__sets_up_adapt_galaxy_images(interferometer_7): - adapt_galaxy_name_image_dict = { - ("galaxies", "lens"): al.Array2D.ones(shape_native=(3, 3), pixel_scales=1.0), - ("galaxies", "source"): al.Array2D.full( - fill_value=2.0, shape_native=(3, 3), pixel_scales=1.0 - ), - } - - result = al.m.MockResult( - adapt_galaxy_name_image_dict=adapt_galaxy_name_image_dict, - adapt_model_image=al.Array2D.full( - fill_value=3.0, shape_native=(3, 3), pixel_scales=1.0 - ), - ) - - analysis = al.AnalysisInterferometer(dataset=interferometer_7, adapt_result=result) - - analysis.set_adapt_dataset(result=result) - - assert ( - analysis.adapt_galaxy_name_image_dict[("galaxies", "lens")].native - == np.ones((3, 3)) - ).all() - - assert ( - analysis.adapt_galaxy_name_image_dict[("galaxies", "source")].native - == 2.0 * np.ones((3, 3)) - ).all() - - assert (analysis.adapt_model_image.native == 3.0 * np.ones((3, 3))).all() - - def test__profile_log_likelihood_function(interferometer_7): pixelization = al.Pixelization( mesh=al.mesh.Rectangular(shape=(3, 3)), diff --git a/test_autolens/lens/test_to_inversion.py b/test_autolens/lens/test_to_inversion.py index 4c9f647e2..75cbc6c98 100644 --- a/test_autolens/lens/test_to_inversion.py +++ b/test_autolens/lens/test_to_inversion.py @@ -182,10 +182,7 @@ def test__adapt_galaxy_image_pg_list(sub_grid_2d_7x7): gal_pix = al.Galaxy(redshift=0.5, pixelization=pixelization) - adapt_images = al.AdaptImages( - model_image=1, - galaxy_image_dict={gal_pix : 1} - ) + adapt_images = al.AdaptImages(model_image=1, galaxy_image_dict={gal_pix: 1}) tracer = al.Tracer.from_galaxies(galaxies=[gal_pix, gal]) @@ -204,8 +201,7 @@ def test__adapt_galaxy_image_pg_list(sub_grid_2d_7x7): gal_pix2 = al.Galaxy(redshift=2.0, pixelization=pixelization) adapt_images = al.AdaptImages( - model_image=1, - galaxy_image_dict={gal_pix0 : 1, gal_pix1: 2, gal_pix2 : 3} + model_image=1, galaxy_image_dict={gal_pix0: 1, gal_pix1: 2, gal_pix2: 3} ) tracer = al.Tracer.from_galaxies(