From a756db1028d4c5a3eaa4a7d8e96c3543e019c657 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Tue, 17 Jun 2025 16:44:29 +0100 Subject: [PATCH] Revert "Feature/jax point source" --- autolens/__init__.py | 2 +- autolens/analysis/positions.py | 7 +- autolens/analysis/result.py | 10 +- autolens/imaging/fit_imaging.py | 14 +- autolens/imaging/model/analysis.py | 2 - autolens/imaging/plot/fit_imaging_plotters.py | 6 +- autolens/lens/to_inversion.py | 3 +- autolens/lens/tracer.py | 11 +- autolens/point/fit/fluxes.py | 7 +- autolens/point/fit/positions/image/pair.py | 3 - .../point/fit/positions/image/pair_all.py | 29 ++- .../point/fit/positions/image/pair_repeat.py | 7 +- .../point/fit/positions/source/separations.py | 13 +- autolens/point/fit/times_delays.py | 7 +- autolens/point/max_separation.py | 4 +- autolens/point/model/analysis.py | 2 - autolens/point/solver/point_solver.py | 30 ++- autolens/point/solver/shape_solver.py | 30 ++- docs/installation/conda.rst | 1 + docs/installation/overview.rst | 4 +- docs/installation/pip.rst | 1 + docs/installation/source.rst | 1 + files/citations.bib | 11 ++ files/citations.md | 1 + files/citations.tex | 3 + paper/paper.bib | 12 +- paper/paper.md | 4 +- test_autolens/aggregator/conftest.py | 1 + .../aggregator/test_aggregator_fit_imaging.py | 2 +- test_autolens/config/grids.yaml | 65 +++++++ test_autolens/config/notation.yaml | 1 + test_autolens/conftest.py | 14 +- .../imaging/model/test_result_imaging.py | 4 +- test_autolens/imaging/test_fit_imaging.py | 175 +++++++++--------- .../imaging/test_simulate_and_fit_imaging.py | 42 ++--- .../model/test_analysis_interferometer.py | 6 +- .../interferometer/test_fit_interferometer.py | 125 +++++++------ .../test_simulate_and_fit_interferometer.py | 42 +++-- test_autolens/lens/test_operate.py | 72 +++++-- test_autolens/lens/test_to_inversion.py | 29 +-- test_autolens/lens/test_tracer.py | 18 +- test_autolens/lens/test_tracer_util.py | 14 +- test_autolens/plot/test_get_visuals.py | 12 +- .../fit/positions/image/test_abstract.py | 11 +- .../fit/positions/image/test_pair_all.py | 12 +- test_autolens/point/fit/test_abstract.py | 2 +- 46 files changed, 515 insertions(+), 357 deletions(-) create mode 100644 test_autolens/config/grids.yaml diff --git a/autolens/__init__.py b/autolens/__init__.py index a61557b67..b4ed6c6e6 100644 --- a/autolens/__init__.py +++ b/autolens/__init__.py @@ -10,6 +10,7 @@ from autoarray.mask.mask_1d import Mask1D from autoarray.mask.mask_2d import Mask2D from autoarray.mask.derive.zoom_2d import Zoom2D +from autoarray.operators.convolver import Convolver from autoarray.operators.over_sampling.over_sampler import OverSampler # noqa from autoarray.inversion.inversion.dataset_interface import DatasetInterface from autoarray.inversion.inversion.mapper_valued import MapperValued @@ -26,7 +27,6 @@ from autoarray.inversion.pixelization.mappers.mapper_grids import MapperGrids from autoarray.inversion.pixelization.mappers.factory import mapper_from as Mapper from autoarray.inversion.pixelization.border_relocator import BorderRelocator -from autoarray.inversion.convolver import Convolver from autoarray.operators.transformer import TransformerDFT from autoarray.operators.transformer import TransformerNUFFT from autoarray.structures.arrays.uniform_1d import Array1D diff --git a/autolens/analysis/positions.py b/autolens/analysis/positions.py index f21abce0c..283298f17 100644 --- a/autolens/analysis/positions.py +++ b/autolens/analysis/positions.py @@ -71,7 +71,6 @@ def __init__( The plane redshift of the lensed source multiple images, which is only required if position threshold for a double source plane lens system is being used where the specific plane is required. """ - self.positions = positions self.threshold = threshold self.plane_redshift = plane_redshift @@ -166,12 +165,10 @@ def log_likelihood_penalty_base_from( residual_map=residual_map, noise_map=dataset.noise_map ) - chi_squared = aa.util.fit.chi_squared_from( - chi_squared_map=chi_squared_map.array - ) + chi_squared = aa.util.fit.chi_squared_from(chi_squared_map=chi_squared_map) noise_normalization = aa.util.fit.noise_normalization_from( - noise_map=dataset.noise_map.array + noise_map=dataset.noise_map ) else: diff --git a/autolens/analysis/result.py b/autolens/analysis/result.py index a1c15b975..9f971f6dd 100644 --- a/autolens/analysis/result.py +++ b/autolens/analysis/result.py @@ -233,7 +233,7 @@ def positions_threshold_from( data=positions, noise_map=None, tracer=tracer, plane_redshift=plane_redshift ) - threshold = factor * np.nanmax(positions_fits.max_separation_of_plane_positions) + threshold = factor * np.max(positions_fits.max_separation_of_plane_positions) if minimum_threshold is not None: if threshold < minimum_threshold: @@ -285,7 +285,7 @@ def positions_likelihood_from( Returns ------- - The `PositionsLH` object used to apply a likelihood penalty or resample the positions. + The `PositionsLH` object used to apply a likelihood penalty using the positions. """ if os.environ.get("PYAUTOFIT_TEST_MODE") == "1": @@ -308,12 +308,6 @@ def positions_likelihood_from( positions = positions[distances > mass_centre_radial_distance_min] - mask = np.isfinite(positions.array).all(axis=1) - - positions = aa.Grid2DIrregular( - positions[mask] - ) - threshold = self.positions_threshold_from( factor=factor, minimum_threshold=minimum_threshold, diff --git a/autolens/imaging/fit_imaging.py b/autolens/imaging/fit_imaging.py index 08d81c48d..775367fac 100644 --- a/autolens/imaging/fit_imaging.py +++ b/autolens/imaging/fit_imaging.py @@ -82,17 +82,9 @@ def blurred_image(self) -> aa.Array2D: """ Returns the image of all light profiles in the fit's tracer convolved with the imaging dataset's PSF. """ - - if len(self.tracer.cls_list_from(cls=ag.LightProfile)) == len( - self.tracer.cls_list_from(cls=ag.lp_operated.LightProfileOperated) - ): - return self.tracer.image_2d_from( - grid=self.grids.lp, - ) - return self.tracer.blurred_image_2d_from( grid=self.grids.lp, - psf=self.dataset.psf, + convolver=self.dataset.convolver, blurring_grid=self.grids.blurring, ) @@ -101,6 +93,7 @@ def profile_subtracted_image(self) -> aa.Array2D: """ Returns the dataset's image with all blurred light profile images in the fit's tracer subtracted. """ + return self.data - self.blurred_image @property @@ -110,7 +103,6 @@ def tracer_to_inversion(self) -> TracerToInversion: data=self.profile_subtracted_image, noise_map=self.noise_map, grids=self.grids, - psf=self.dataset.psf, convolver=self.dataset.convolver, w_tilde=self.w_tilde, ) @@ -171,7 +163,7 @@ def galaxy_model_image_dict(self) -> Dict[ag.Galaxy, np.ndarray]: galaxy_blurred_image_2d_dict = self.tracer.galaxy_blurred_image_2d_dict_from( grid=self.grids.lp, - psf=self.dataset.psf, + convolver=self.dataset.convolver, blurring_grid=self.grids.blurring, ) diff --git a/autolens/imaging/model/analysis.py b/autolens/imaging/model/analysis.py index a63f30fb6..1c2c727ad 100644 --- a/autolens/imaging/model/analysis.py +++ b/autolens/imaging/model/analysis.py @@ -117,8 +117,6 @@ def log_likelihood_function(self, instance: af.ModelInstance) -> float: np.linalg.LinAlgError, OverflowError, ) as e: - print(e) - fggdfg raise exc.FitException from e def fit_from( diff --git a/autolens/imaging/plot/fit_imaging_plotters.py b/autolens/imaging/plot/fit_imaging_plotters.py index d5ec4b66a..ac958cacf 100644 --- a/autolens/imaging/plot/fit_imaging_plotters.py +++ b/autolens/imaging/plot/fit_imaging_plotters.py @@ -216,7 +216,7 @@ def figures_2d_of_planes( for plane_index in plane_indexes: if use_source_vmax: - self.mat_plot_2d.cmap.kwargs["vmax"] = np.max(self.fit.model_images_of_planes_list[plane_index].array) + self.mat_plot_2d.cmap.kwargs["vmax"] = np.max(self.fit.model_images_of_planes_list[plane_index]) if subtracted_image: @@ -765,7 +765,7 @@ def figures_2d( if data: if use_source_vmax: - self.mat_plot_2d.cmap.kwargs["vmax"] = np.max([model_image.array for model_image in self.fit.model_images_of_planes_list[1:]]) + self.mat_plot_2d.cmap.kwargs["vmax"] = np.max(self.fit.model_images_of_planes_list[1:]) self.mat_plot_2d.plot_array( array=self.fit.data, @@ -799,7 +799,7 @@ def figures_2d( if model_image: if use_source_vmax: - self.mat_plot_2d.cmap.kwargs["vmax"] = np.max([model_image.array for model_image in self.fit.model_images_of_planes_list[1:]]) + self.mat_plot_2d.cmap.kwargs["vmax"] = np.max(self.fit.model_images_of_planes_list[1:]) self.mat_plot_2d.plot_array( array=self.fit.model_data, diff --git a/autolens/lens/to_inversion.py b/autolens/lens/to_inversion.py index c26cc3860..2e020775b 100644 --- a/autolens/lens/to_inversion.py +++ b/autolens/lens/to_inversion.py @@ -180,8 +180,7 @@ def lp_linear_func_list_galaxy_dict( data=self.dataset.data, noise_map=self.dataset.noise_map, grids=grids, - psf=self.psf, - convolver=self.dataset.convolver, + convolver=self.convolver, transformer=self.transformer, w_tilde=self.dataset.w_tilde, ) diff --git a/autolens/lens/tracer.py b/autolens/lens/tracer.py index 0c245017d..1dee85bf1 100644 --- a/autolens/lens/tracer.py +++ b/autolens/lens/tracer.py @@ -1,5 +1,6 @@ from abc import ABC import numpy as np +from functools import wraps from scipy.interpolate import griddata from typing import Dict, List, Optional, Type, Union @@ -548,9 +549,9 @@ def image_2d_via_input_plane_image_from( )[plane_index] image = griddata( - points=plane_grid.array, - values=plane_image.array, - xi=traced_grid.over_sampled.array, + points=plane_grid, + values=plane_image, + xi=traced_grid.over_sampled, fill_value=0.0, method="linear", ) @@ -1190,5 +1191,5 @@ def set_snr_of_snr_light_profiles( ) @aa.profile_func - def convolve_via_psf(self, image, blurring_image, psf): - return psf.convolve_image(image=image, blurring_image=blurring_image) + def convolve_via_convolver(self, image, blurring_image, convolver): + return convolver.convolve_image(image=image, blurring_image=blurring_image) diff --git a/autolens/point/fit/fluxes.py b/autolens/point/fit/fluxes.py index a34c4e56c..788368c1a 100644 --- a/autolens/point/fit/fluxes.py +++ b/autolens/point/fit/fluxes.py @@ -1,4 +1,3 @@ -import jax.numpy as jnp from typing import Optional import autoarray as aa @@ -102,10 +101,10 @@ def model_data(self): are used. """ return aa.ArrayIrregular( - values=jnp.array([ + values=[ magnification * self.profile.flux for magnification in self.magnifications_at_positions - ]) + ] ) @property @@ -129,5 +128,5 @@ def chi_squared(self) -> float: RMS noise-map values squared. """ return ag.util.fit.chi_squared_from( - chi_squared_map=self.chi_squared_map.array, + chi_squared_map=self.chi_squared_map, ) diff --git a/autolens/point/fit/positions/image/pair.py b/autolens/point/fit/positions/image/pair.py index ab2cf99b4..e7af82c2b 100644 --- a/autolens/point/fit/positions/image/pair.py +++ b/autolens/point/fit/positions/image/pair.py @@ -1,7 +1,4 @@ -import jax.numpy as jnp import numpy as np -from ott.geometry import pointcloud -from ott.solvers.linear import sinkhorn from scipy.optimize import linear_sum_assignment import autoarray as aa diff --git a/autolens/point/fit/positions/image/pair_all.py b/autolens/point/fit/positions/image/pair_all.py index 6429b333c..00bd4a454 100644 --- a/autolens/point/fit/positions/image/pair_all.py +++ b/autolens/point/fit/positions/image/pair_all.py @@ -1,4 +1,3 @@ -import jax.numpy as jnp import numpy as np import autoarray as aa @@ -86,7 +85,7 @@ def log_p( The log probability of the model coordinate explaining the observed coordinate. """ chi2 = self.square_distance(data_position, model_position) / sigma**2 - return -jnp.log(jnp.sqrt(2 * jnp.pi * sigma**2)) - 0.5 * chi2 + return -np.log(np.sqrt(2 * np.pi * sigma**2)) - 0.5 * chi2 def all_permutations_log_likelihoods(self) -> np.ndarray: """ @@ -102,23 +101,21 @@ def all_permutations_log_likelihoods(self) -> np.ndarray: This is every way in which the coordinates generated by the model can explain the observed coordinates. """ - - model_data = self.model_data.array - - return jnp.array( + return np.array( [ - jnp.log( - jnp.sum( - jnp.array([ - jnp.exp( + np.log( + np.sum( + [ + np.exp( self.log_p( data_position, model_position, sigma, ) ) - for model_position in model_data - ]) + for model_position in self.model_data + if not np.isnan(model_position).any() + ] ) ) for data_position, sigma in zip(self.data, self.noise_map) @@ -143,12 +140,12 @@ def chi_squared(self) -> float: This is every way in which the coordinates generated by the model can explain the observed coordinates. """ - n_non_nan_model_positions = jnp.count_nonzero( - ~jnp.isnan( - self.model_data.array, + n_non_nan_model_positions = np.count_nonzero( + ~np.isnan( + self.model_data, ).any(axis=1) ) n_permutations = n_non_nan_model_positions ** len(self.data) return -2.0 * ( - -jnp.log(n_permutations) + jnp.sum(self.all_permutations_log_likelihoods()) + -np.log(n_permutations) + np.sum(self.all_permutations_log_likelihoods()) ) diff --git a/autolens/point/fit/positions/image/pair_repeat.py b/autolens/point/fit/positions/image/pair_repeat.py index f3bc1dac1..9d6da6b99 100644 --- a/autolens/point/fit/positions/image/pair_repeat.py +++ b/autolens/point/fit/positions/image/pair_repeat.py @@ -1,4 +1,5 @@ -import jax.numpy as jnp +import numpy as np + import autoarray as aa from autolens.point.fit.positions.image.abstract import AbstractFitPositionsImagePair @@ -62,6 +63,6 @@ def residual_map(self) -> aa.ArrayIrregular: self.square_distance(model_position, position) for model_position in self.model_data ] - residual_map.append(jnp.sqrt(jnp.min(jnp.array(distances)))) + residual_map.append(np.sqrt(min(distances))) - return aa.ArrayIrregular(values=jnp.array(residual_map)) + return aa.ArrayIrregular(values=residual_map) diff --git a/autolens/point/fit/positions/source/separations.py b/autolens/point/fit/positions/source/separations.py index 3a4529d7a..95ec8c952 100644 --- a/autolens/point/fit/positions/source/separations.py +++ b/autolens/point/fit/positions/source/separations.py @@ -1,4 +1,4 @@ -import jax.numpy as jnp +from autoarray.numpy_wrapper import numpy as npw import numpy as np from typing import Optional @@ -118,7 +118,7 @@ def chi_squared_map(self) -> float: """ return self.residual_map**2.0 / ( - self.magnifications_at_positions.array**-2.0 * self.noise_map.array**2.0 + self.magnifications_at_positions**-2.0 * self.noise_map**2.0 ) @property @@ -126,14 +126,11 @@ def noise_normalization(self) -> float: """ Returns the normalization of the noise-map, which is the sum of the noise-map values squared. """ - return jnp.sum( - jnp.log( + return npw.sum( + npw.log( 2 * np.pi - * ( - self.magnifications_at_positions.array**-2.0 - * self.noise_map.array**2.0 - ) + * (self.magnifications_at_positions**-2.0 * self.noise_map**2.0) ) ) diff --git a/autolens/point/fit/times_delays.py b/autolens/point/fit/times_delays.py index df576510d..814a94764 100644 --- a/autolens/point/fit/times_delays.py +++ b/autolens/point/fit/times_delays.py @@ -1,4 +1,3 @@ -import jax.numpy as jnp import numpy as np from typing import Optional @@ -90,8 +89,8 @@ def residual_map(self) -> aa.ArrayIrregular: from the dataset time delays and model time delays before the subtraction. """ - data = self.data - jnp.min(self.data) - model_data = self.model_data - jnp.min(self.model_data) + data = self.data - np.min(self.data) + model_data = self.model_data - np.min(self.model_data) residual_map = aa.util.fit.residual_map_from(data=data, model_data=model_data) return aa.ArrayIrregular(values=residual_map) @@ -103,5 +102,5 @@ def chi_squared(self) -> float: which is the residual values divided by the RMS noise-map squared. """ return ag.util.fit.chi_squared_from( - chi_squared_map=self.chi_squared_map.array, + chi_squared_map=self.chi_squared_map, ) diff --git a/autolens/point/max_separation.py b/autolens/point/max_separation.py index f17e65de3..d7c9d50c8 100644 --- a/autolens/point/max_separation.py +++ b/autolens/point/max_separation.py @@ -42,7 +42,7 @@ def __init__( except TypeError: plane_index = -1 - self.plane_positions = aa.Grid2DIrregular(values=tracer.traced_grid_2d_list_from(grid=data)[plane_index]) + self.plane_positions = tracer.traced_grid_2d_list_from(grid=data)[plane_index] @property def furthest_separations_of_plane_positions(self) -> aa.ArrayIrregular: @@ -50,7 +50,7 @@ def furthest_separations_of_plane_positions(self) -> aa.ArrayIrregular: Returns the furthest distance of every source-plane (y,x) coordinate to the other source-plane (y,x) coordinates. - For example, for the following plane positions: + For example, for the following source-plane positions: plane_positions = [[(0.0, 0.0), (0.0, 1.0), (0.0, 3.0)] diff --git a/autolens/point/model/analysis.py b/autolens/point/model/analysis.py index 820074b07..aa4e56cca 100644 --- a/autolens/point/model/analysis.py +++ b/autolens/point/model/analysis.py @@ -125,8 +125,6 @@ def log_likelihood_function(self, instance): fit = self.fit_from(instance=instance) return fit.log_likelihood except (AttributeError, ValueError, TypeError, NumbaException) as e: - print(e) - dfdsfd raise exc.FitException from e def fit_from( diff --git a/autolens/point/solver/point_solver.py b/autolens/point/solver/point_solver.py index 4caee637c..f98d5a129 100644 --- a/autolens/point/solver/point_solver.py +++ b/autolens/point/solver/point_solver.py @@ -1,11 +1,13 @@ -import jax.numpy as jnp import logging from typing import Tuple, Optional +from autoarray.numpy_wrapper import np + import autoarray as aa +from autoarray.numpy_wrapper import use_jax from autoarray.structures.triangles.shape import Point -from autofit.jax_wrapper import register_pytree_node_class +from autofit.jax_wrapper import jit, register_pytree_node_class from autogalaxy import OperateDeflections from .shape_solver import AbstractSolver @@ -15,7 +17,7 @@ @register_pytree_node_class class PointSolver(AbstractSolver): - + @jit def solve( self, tracer: OperateDeflections, @@ -55,11 +57,23 @@ def solve( filtered_means = self._filter_low_magnification( tracer=tracer, points=kept_triangles.means ) + if use_jax: + return aa.Grid2DIrregular([pair for pair in filtered_means]) - solution = aa.Grid2DIrregular([pair for pair in filtered_means]).array + filtered_means = [ + pair for pair in filtered_means if not np.any(np.isnan(pair)).all() + ] - is_nan = jnp.isnan(solution).any(axis=1) - sentinel = jnp.full_like(solution[0], fill_value=jnp.inf) - solution = jnp.where(is_nan[:, None], sentinel, solution) + difference = len(kept_triangles.means) - len(filtered_means) + if difference > 0: + logger.debug( + f"Filtered one multiple-image with magnification below threshold." + ) + elif difference > 1: + logger.warning( + f"Filtered {difference} multiple-images with magnification below threshold." + ) - return aa.Grid2DIrregular(solution) \ No newline at end of file + return aa.Grid2DIrregular( + [pair for pair in filtered_means if not np.isnan(pair).all()] + ) diff --git a/autolens/point/solver/shape_solver.py b/autolens/point/solver/shape_solver.py index 48a88ca99..e3fb06e44 100644 --- a/autolens/point/solver/shape_solver.py +++ b/autolens/point/solver/shape_solver.py @@ -1,4 +1,3 @@ -import jax.numpy as jnp import logging import math @@ -7,11 +6,23 @@ import autoarray as aa from autoarray.structures.triangles.shape import Shape -from autofit.jax_wrapper import register_pytree_node_class +from autofit.jax_wrapper import jit, use_jax, numpy as np, register_pytree_node_class + +try: + if use_jax: + from autoarray.structures.triangles.coordinate_array.jax_coordinate_array import ( + CoordinateArrayTriangles, + ) + else: + from autoarray.structures.triangles.coordinate_array.coordinate_array import ( + CoordinateArrayTriangles, + ) + +except ImportError: + from autoarray.structures.triangles.coordinate_array.coordinate_array import ( + CoordinateArrayTriangles, + ) -from autoarray.structures.triangles.coordinate_array.jax_coordinate_array import ( - CoordinateArrayTriangles, -) from autoarray.structures.triangles.abstract import AbstractTriangles from autogalaxy import OperateDeflections @@ -204,6 +215,7 @@ def _plane_grid( # noinspection PyTypeChecker return grid.grid_2d_via_deflection_grid_from(deflection_grid=deflections) + @jit def solve_triangles( self, tracer: OperateDeflections, @@ -263,13 +275,13 @@ def _filter_low_magnification( ------- The points with an absolute magnification above the threshold. """ - points = jnp.array(points) + points = np.array(points) magnifications = tracer.magnification_2d_via_hessian_from( - grid=aa.Grid2DIrregular(points).array, + grid=aa.Grid2DIrregular(points), buffer=self.scale, ) - mask = jnp.abs(magnifications.array) > self.magnification_threshold - return jnp.where(mask[:, None], points, jnp.nan) + mask = np.abs(magnifications.array) > self.magnification_threshold + return np.where(mask[:, None], points, np.nan) def _plane_triangles( self, diff --git a/docs/installation/conda.rst b/docs/installation/conda.rst index 7cca957f3..141ed42f1 100644 --- a/docs/installation/conda.rst +++ b/docs/installation/conda.rst @@ -105,6 +105,7 @@ For interferometer analysis there are two optional dependencies that must be ins .. code-block:: bash pip install pynufft + pip install pylops==2.3.1 **PyAutoLens** will run without these libraries and it is recommended that you only install them if you intend to do interferometer analysis. diff --git a/docs/installation/overview.rst b/docs/installation/overview.rst index c5917fc7c..1915ca12b 100644 --- a/docs/installation/overview.rst +++ b/docs/installation/overview.rst @@ -66,4 +66,6 @@ Dependencies And the following optional dependencies: -**pynufft**: https://github.com/jyhmiinlin/pynufft \ No newline at end of file +**pynufft**: https://github.com/jyhmiinlin/pynufft + +**PyLops**: https://github.com/PyLops/pylops \ No newline at end of file diff --git a/docs/installation/pip.rst b/docs/installation/pip.rst index 356d329c4..53d453c3b 100644 --- a/docs/installation/pip.rst +++ b/docs/installation/pip.rst @@ -86,6 +86,7 @@ For interferometer analysis there are two optional dependencies that must be ins .. code-block:: bash pip install pynufft + pip install pylops==2.3.1 **PyAutoLens** will run without these libraries and it is recommended that you only install them if you intend to do interferometer analysis. diff --git a/docs/installation/source.rst b/docs/installation/source.rst index cf0c85d7c..5af7b5692 100644 --- a/docs/installation/source.rst +++ b/docs/installation/source.rst @@ -59,6 +59,7 @@ For unit tests to pass you will also need the following optional requirements: .. code-block:: bash pip install pynufft + pip install pylops==2.3.1 If you are using a ``conda`` environment, add the source repository as follows: diff --git a/files/citations.bib b/files/citations.bib index 162021d3a..195c498d7 100644 --- a/files/citations.bib +++ b/files/citations.bib @@ -33,6 +33,17 @@ @article{astropy2 Bdsk-Url-1 = {https://doi.org/10.3847/1538-3881/aabc4f} } +@article{PyLops, +abstract = {Linear operators and optimisation are at the core of many algorithms used in signal and image processing, remote sensing, and inverse problems. For small to medium-scale problems, existing software packages (e.g., MATLAB, Python numpy and scipy) allow for explicitly building dense (or sparse) matrices and performing algebraic operations (e.g., computation of matrix-vector products and manipulation of matrices) with syntax that closely represents their corresponding analytical forms. However, many real application, large-scale operators do not lend themselves to explicit matrix representations, usually forcing practitioners to forego of the convenient linear-algebra syntax available for their explicit-matrix counterparts. PyLops is an open-source Python library providing a flexible and scalable framework for the creation and combination of so-called linear operators, class-based entities that represent matrices and inherit their associated syntax convenience, but do not rely on the creation of explicit matrices. We show that PyLops operators can dramatically reduce the memory load and CPU computations compared to explicit-matrix calculations, while still allowing users to seamlessly use their existing knowledge of compact matrix-based syntax that scales to any problem size because no explicit matrices are required.}, +archivePrefix = {arXiv}, +arxivId = {1907.12349}, +author = {Ravasi, Matteo and Vasconcelos, Ivan}, +eprint = {1907.12349}, +file = {:home/jammy/Documents/Papers/Software/PyLops.pdf:pdf}, +title = {{PyLops -- A Linear-Operator Python Library for large scale optimization}}, +url = {http://arxiv.org/abs/1907.12349}, +year = {2019} +} @article{colossus, abstract = {This paper introduces Colossus, a public, open-source python package for calculations related to cosmology, the large-scale structure (LSS) of matter in the universe, and the properties of dark matter halos. The code is designed to be fast and easy to use, with a coherent, well-documented user interface. The cosmology module implements Friedman-Lemaitre-Robertson-Walker cosmologies including curvature, relativistic species, and different dark energy equations of state, and provides fast computations of the linear matter power spectrum, variance, and correlation function. The LSS module is concerned with the properties of peaks in Gaussian random fields and halos in a statistical sense, including their peak height, peak curvature, halo bias, and mass function. The halo module deals with spherical overdensity radii and masses, density profiles, concentration, and the splashback radius. To facilitate the rapid exploration of these quantities, Colossus implements more than 40 different fitting functions from the literature. I discuss the core routines in detail, with particular emphasis on their accuracy. Colossus is available at bitbucket.org/bdiemer/colossus.}, diff --git a/files/citations.md b/files/citations.md index cf914917c..36589cbb5 100644 --- a/files/citations.md +++ b/files/citations.md @@ -19,6 +19,7 @@ This work uses the following software packages: - `PyAutoFit` https://github.com/rhayes777/PyAutoFit [@pyautofit] - `PyAutoGalaxy` https://github.com/Jammy2211/PyAutoGalaxy [@Nightingale2018] [@pyautogalaxy] - `PyAutoLens` https://github.com/Jammy2211/PyAutoLens [@Nightingale2015] [@Nightingale2018] [@pyautolens] +- `PyLops` https://github.com/equinor/pylops [@pylops] - `PyNUFFT` https://github.com/jyhmiinlin/pynufft [@pynufft] - `PySwarms` https://github.com/ljvmiranda921/pyswarms [@pyswarms] - `Python` https://www.python.org/ [@python] diff --git a/files/citations.tex b/files/citations.tex index fd9b4bb1e..f500eb271 100644 --- a/files/citations.tex +++ b/files/citations.tex @@ -54,6 +54,9 @@ \section*{Software Citations} \href{https://github.com/Jammy2211/PyAutoLens}{\textt{PyAutoLens}} \citep{Nightingale2015, Nightingale2018, pyautolens} +\item +\href{https://github.com/equinor/pylops}{\textt{PyLops}} +\citep{pylops} \item \href{https://github.com/jyhmiinlin/pynufft}{\textt{PyNUFFT}} diff --git a/paper/paper.bib b/paper/paper.bib index eba78d1bf..fe46fc04f 100644 --- a/paper/paper.bib +++ b/paper/paper.bib @@ -30,7 +30,17 @@ @article{astropy2 Volume = {156}, Year = 2018, Bdsk-Url-1 = {https://doi.org/10.3847/1538-3881/aabc4f}} - +@article{PyLops, +abstract = {Linear operators and optimisation are at the core of many algorithms used in signal and image processing, remote sensing, and inverse problems. For small to medium-scale problems, existing software packages (e.g., MATLAB, Python numpy and scipy) allow for explicitly building dense (or sparse) matrices and performing algebraic operations (e.g., computation of matrix-vector products and manipulation of matrices) with syntax that closely represents their corresponding analytical forms. However, many real application, large-scale operators do not lend themselves to explicit matrix representations, usually forcing practitioners to forego of the convenient linear-algebra syntax available for their explicit-matrix counterparts. PyLops is an open-source Python library providing a flexible and scalable framework for the creation and combination of so-called linear operators, class-based entities that represent matrices and inherit their associated syntax convenience, but do not rely on the creation of explicit matrices. We show that PyLops operators can dramatically reduce the memory load and CPU computations compared to explicit-matrix calculations, while still allowing users to seamlessly use their existing knowledge of compact matrix-based syntax that scales to any problem size because no explicit matrices are required.}, +archivePrefix = {arXiv}, +arxivId = {1907.12349}, +author = {Ravasi, Matteo and Vasconcelos, Ivan}, +eprint = {1907.12349}, +file = {:home/jammy/Documents/Papers/Software/PyLops.pdf:pdf}, +title = {{PyLops -- A Linear-Operator Python Library for large scale optimization}}, +url = {http://arxiv.org/abs/1907.12349}, +year = {2019} +} @article{colossus, abstract = {This paper introduces Colossus, a public, open-source python package for calculations related to cosmology, the large-scale structure (LSS) of matter in the universe, and the properties of dark matter halos. The code is designed to be fast and easy to use, with a coherent, well-documented user interface. The cosmology module implements Friedman-Lemaitre-Robertson-Walker cosmologies including curvature, relativistic species, and different dark energy equations of state, and provides fast computations of the linear matter power spectrum, variance, and correlation function. The LSS module is concerned with the properties of peaks in Gaussian random fields and halos in a statistical sense, including their peak height, peak curvature, halo bias, and mass function. The halo module deals with spherical overdensity radii and masses, density profiles, concentration, and the splashback radius. To facilitate the rapid exploration of these quantities, Colossus implements more than 40 different fitting functions from the literature. I discuss the core routines in detail, with particular emphasis on their accuracy. Colossus is available at bitbucket.org/bdiemer/colossus.}, archivePrefix = {arXiv}, diff --git a/paper/paper.md b/paper/paper.md index fe72c079f..77ea3412a 100644 --- a/paper/paper.md +++ b/paper/paper.md @@ -160,7 +160,8 @@ effects like the telescope optics and background sky subtraction in the model-fi performed directly on the observed visibilities in their native Fourier space, circumventing issues associated with the incomplete sampling of the uv-plane that give rise to artefacts that can bias the inferred mass model and source reconstruction in real-space. To make feasible the analysis of millions of visibilities, `PyAutoLens` -uses `PyNUFFT` [@pynufft] to fit the visibilities via a non-uniform fast Fourier transform. Creating +uses `PyNUFFT` [@pynufft] to fit the visibilities via a non-uniform fast Fourier transform and `PyLops` [@PyLops] to +express the memory-intensive linear algebra calculations as efficient linear operators [@Powell2020]. Creating realistic simulations of imaging and interferometer strong lensing datasets is possible, as performed by [@Alexander2019] [@Hermans2019] who used `PyAutoLens` to train neural networks to detect strong lenses. @@ -197,6 +198,7 @@ taken without a local `PyAutoLens` installation. - `numba` [@numba] - `NumPy` [@numpy] - `PyAutoFit` [@pyautofit] +- `PyLops` [@PyLops] - `PyMultiNest` [@pymultinest] [@multinest] - `PyNUFFT` [@pynufft] - `pyprojroot` (https://github.com/chendaniely/pyprojroot) diff --git a/test_autolens/aggregator/conftest.py b/test_autolens/aggregator/conftest.py index 2009c2ef8..8e9419fb3 100644 --- a/test_autolens/aggregator/conftest.py +++ b/test_autolens/aggregator/conftest.py @@ -44,6 +44,7 @@ def aggregator_from(database_file, analysis, model, samples): samples=samples, result=al.m.MockResult(model=model, samples=samples) ) search.paths = af.DirectoryPaths(path_prefix=database_file) + search.fit(model=model, analysis=analysis) analysis.visualize_before_fit(paths=search.paths, model=model) diff --git a/test_autolens/aggregator/test_aggregator_fit_imaging.py b/test_autolens/aggregator/test_aggregator_fit_imaging.py index 4687ea903..d2bd588f5 100644 --- a/test_autolens/aggregator/test_aggregator_fit_imaging.py +++ b/test_autolens/aggregator/test_aggregator_fit_imaging.py @@ -5,7 +5,7 @@ database_file = "db_fit_imaging" -def test__fit_imaging_randomly_drawn_via_pdf_gen_from__analysis_single( +def test__fit_imaging_randomly_drawn_via_pdf_gen_from( analysis_imaging_7x7, samples, model ): agg = aggregator_from( diff --git a/test_autolens/config/grids.yaml b/test_autolens/config/grids.yaml new file mode 100644 index 000000000..06d81535e --- /dev/null +++ b/test_autolens/config/grids.yaml @@ -0,0 +1,65 @@ +interpolate: + convergence_2d_from: + Isothermal: false + IsothermalInitialize: false + IsothermalSph: true + deflections_yx_2d_from: + Isothermal: false + IsothermalInitialize: false + IsothermalSph: true + image_2d_from: + Sersic: false + SersicInitialize: false + SersicSph: true + potential_2d_from: + Isothermal: false + IsothermalInitialize: false + IsothermalSph: true +# Certain light and mass profile calculations become ill defined at (0.0, 0.0) or close to this value. This can lead +# to numerical issues in the calculation of the profile, for example a np.nan may arise, crashing the code. + +# To avoid this, we set a minimum value for the radial coordinate of the profile. If the radial coordinate is below +# this value, it is rounded up to this value. This ensures that the profile cannot receive a radial coordinate of 0.0. + +# For example, if an input grid coordinate has a radial coordinate of 1e-12, for most profiles this will be rounded up +# to radial_minimum=1e-08. This is a small enough value that it should not impact the results of the profile calculation. + +radial_minimum: + radial_minimum: + DevVaucouleurs: 1.0e-08 + DevVaucouleursSph: 1.0e-08 + EllMassProfile: 1.0e-08 + EllProfile: 1.0e-08 + Exponential: 1.0e-08 + ExponentialSph: 1.0e-08 + ExternalShear: 1.0e-08 + Gaussian: 1.0e-08 + GaussianGradient: 1.0e-08 + GaussianSph: 1.0e-08 + Isothermal: 1.0e-08 + IsothermalCore: 1.0e-08 + IsothermalCoreSph: 1.0e-08 + IsothermalInitialize: 1.0e-08 + IsothermalSph: 1.0e-08 + MassSheet: 1.0e-08 + MockGridRadialMinimum: 2.5 + NFW: 1.0e-08 + NFWSph: 1.0e-08 + NFWTruncatedSph: 1.0e-08 + PointMass: 0.0 + PowerLaw: 1.0e-08 + PowerLawBroken: 1.0e-08 + PowerLawBrokenSph: 1.0e-08 + PowerLawCore: 1.0e-08 + PowerLawCoreSph: 1.0e-08 + PowerLawSph: 1.0e-08 + Sersic: 1.0e-08 + SersicCore: 1.0e-08 + SersicCoreSph: 1.0e-08 + SersicGradient: 1.0e-08 + SersicGradientSph: 1.0e-08 + SersicSph: 1.0e-08 + SphNFWTruncatedMCR: 1.0e-08 + gNFW: 1.0e-08 + gNFWSph: 1.0e-08 + diff --git a/test_autolens/config/notation.yaml b/test_autolens/config/notation.yaml index 92a53b924..2d19ca16d 100644 --- a/test_autolens/config/notation.yaml +++ b/test_autolens/config/notation.yaml @@ -62,6 +62,7 @@ label: weight_power: W_{\rm p} superscript: ExternalShear: ext + InputDeflections: defl Pixelization: pix Point: point Redshift: '' diff --git a/test_autolens/conftest.py b/test_autolens/conftest.py index 961f3fd09..cf02d168f 100644 --- a/test_autolens/conftest.py +++ b/test_autolens/conftest.py @@ -56,6 +56,14 @@ def remove_logs(): # Lens Datasets # +@pytest.fixture(autouse=True) +def set_config_path(request): + conf.instance.push( + new_path=path.join(directory, "config"), + output_path=path.join(directory, "output"), + ) + + @pytest.fixture(name="mask_2d_7x7") def make_mask_2d_7x7(): return fixtures.make_mask_2d_7x7() @@ -111,9 +119,9 @@ def make_psf_3x3(): return fixtures.make_psf_3x3() -@pytest.fixture(name="psf_3x3") -def make_psf_3x3(): - return fixtures.make_psf_3x3() +@pytest.fixture(name="convolver_7x7") +def make_convolver_7x7(): + return fixtures.make_convolver_7x7() @pytest.fixture(name="imaging_7x7") diff --git a/test_autolens/imaging/model/test_result_imaging.py b/test_autolens/imaging/model/test_result_imaging.py index 0cad3ae94..9263e2e8b 100644 --- a/test_autolens/imaging/model/test_result_imaging.py +++ b/test_autolens/imaging/model/test_result_imaging.py @@ -9,7 +9,7 @@ def test___linear_light_profiles_in_result(analysis_imaging_7x7): galaxies = af.ModelInstance() - galaxies.galaxy = al.Galaxy(redshift=0.5, bulge=al.lp_linear.Sersic(centre=(0.05, 0.05))) + galaxies.galaxy = al.Galaxy(redshift=0.5, bulge=al.lp_linear.Sersic()) instance = af.ModelInstance() instance.galaxies = galaxies @@ -24,4 +24,4 @@ def test___linear_light_profiles_in_result(analysis_imaging_7x7): ) assert result.max_log_likelihood_tracer.galaxies[ 0 - ].bulge.intensity == pytest.approx(0.1868684644, 1.0e-4) + ].bulge.intensity == pytest.approx(0.002310735, 1.0e-4) diff --git a/test_autolens/imaging/test_fit_imaging.py b/test_autolens/imaging/test_fit_imaging.py index 52132eeac..d2ada81de 100644 --- a/test_autolens/imaging/test_fit_imaging.py +++ b/test_autolens/imaging/test_fit_imaging.py @@ -35,39 +35,39 @@ def test__fit_figure_of_merit(masked_imaging_7x7, masked_imaging_covariance_7x7) g0 = al.Galaxy( redshift=0.5, - bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0), - disk=al.lp.Sersic(centre=(0.05, 0.05), intensity=2.0), - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + bulge=al.lp.Sersic(intensity=1.0), + disk=al.lp.Sersic(intensity=2.0), + mass_profile=al.mp.IsothermalSph(einstein_radius=1.0), ) - g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0)) + g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(intensity=1.0)) tracer = al.Tracer(galaxies=[g0, g1]) fit = al.FitImaging(dataset=masked_imaging_7x7, tracer=tracer) assert fit.perform_inversion is False - assert fit.figure_of_merit == pytest.approx(-648.4814555620, 1.0e-4) + assert fit.figure_of_merit == pytest.approx(-2859741.44762, 1.0e-4) basis = al.lp_basis.Basis( profile_list=[ - al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0), - al.lp.Sersic(centre=(0.05, 0.05), intensity=2.0), + al.lp.Sersic(intensity=1.0), + al.lp.Sersic(intensity=2.0), ] ) g0 = al.Galaxy( - redshift=0.5, bulge=basis, mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0) + redshift=0.5, bulge=basis, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0) ) - g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0)) + g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(intensity=1.0)) tracer = al.Tracer(galaxies=[g0, g1]) fit = al.FitImaging(dataset=masked_imaging_7x7, tracer=tracer) assert fit.perform_inversion is False - assert fit.figure_of_merit == pytest.approx(-648.4814555620, 1.0e-4) + assert fit.figure_of_merit == pytest.approx(-2859741.44762, 1.0e-4) pixelization = al.Pixelization( mesh=al.mesh.Rectangular(shape=(3, 3)), @@ -83,7 +83,7 @@ def test__fit_figure_of_merit(masked_imaging_7x7, masked_imaging_covariance_7x7) assert fit.perform_inversion is True assert fit.figure_of_merit == pytest.approx(-22.90055, 1.0e-4) - galaxy_light = al.Galaxy(redshift=0.5, bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0)) + galaxy_light = al.Galaxy(redshift=0.5, bulge=al.lp.Sersic(intensity=1.0)) pixelization = al.Pixelization( mesh=al.mesh.Rectangular(shape=(3, 3)), @@ -97,13 +97,13 @@ def test__fit_figure_of_merit(masked_imaging_7x7, masked_imaging_covariance_7x7) fit = al.FitImaging(dataset=masked_imaging_7x7, tracer=tracer) assert fit.perform_inversion is True - assert fit.figure_of_merit == pytest.approx(-29.201919365, 1.0e-4) + assert fit.figure_of_merit == pytest.approx(-37667.0303, 1.0e-4) g0_linear = al.Galaxy( redshift=0.5, - bulge=al.lp_linear.Sersic(centre=(0.05, 0.05), sersic_index=1.0), - disk=al.lp_linear.Sersic(centre=(0.05, 0.05), sersic_index=4.0), - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + bulge=al.lp_linear.Sersic(sersic_index=1.0), + disk=al.lp_linear.Sersic(sersic_index=4.0), + mass_profile=al.mp.IsothermalSph(einstein_radius=1.0), ) tracer = al.Tracer(galaxies=[g0_linear, g1]) @@ -111,17 +111,17 @@ def test__fit_figure_of_merit(masked_imaging_7x7, masked_imaging_covariance_7x7) fit = al.FitImaging(dataset=masked_imaging_7x7, tracer=tracer) assert fit.perform_inversion is True - assert fit.figure_of_merit == pytest.approx(-16.9731347648, 1.0e-4) + assert fit.figure_of_merit == pytest.approx(-6741.83381, 1.0e-4) basis = al.lp_basis.Basis( profile_list=[ - al.lp_linear.Sersic(centre=(0.05, 0.05), sersic_index=1.0), - al.lp_linear.Sersic(centre=(0.05, 0.05), sersic_index=4.0), + al.lp_linear.Sersic(sersic_index=1.0), + al.lp_linear.Sersic(sersic_index=4.0), ] ) g0_linear = al.Galaxy( - redshift=0.5, bulge=basis, mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0) + redshift=0.5, bulge=basis, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0) ) tracer = al.Tracer(galaxies=[g0_linear, g1]) @@ -129,12 +129,12 @@ def test__fit_figure_of_merit(masked_imaging_7x7, masked_imaging_covariance_7x7) fit = al.FitImaging(dataset=masked_imaging_7x7, tracer=tracer) assert fit.perform_inversion is True - assert fit.figure_of_merit == pytest.approx(-16.97313476, 1.0e-4) + assert fit.figure_of_merit == pytest.approx(-6741.83381, 1.0e-4) basis = al.lp_basis.Basis( profile_list=[ - al.lp_linear.Sersic(centre=(0.05, 0.05), sersic_index=1.0), - al.lp_linear.Sersic(centre=(0.05, 0.05), sersic_index=4.0), + al.lp_linear.Sersic(sersic_index=1.0), + al.lp_linear.Sersic(sersic_index=4.0), ], regularization=al.reg.Constant(coefficient=1.0), ) @@ -148,7 +148,7 @@ def test__fit_figure_of_merit(masked_imaging_7x7, masked_imaging_covariance_7x7) fit = al.FitImaging(dataset=masked_imaging_7x7, tracer=tracer) assert fit.perform_inversion is True - assert fit.figure_of_merit == pytest.approx(-51.0835080747, 1.0e-4) + assert fit.figure_of_merit == pytest.approx(-208205.2074336, 1.0e-4) tracer = al.Tracer(galaxies=[g0_linear, galaxy_pix]) @@ -159,27 +159,27 @@ def test__fit_figure_of_merit(masked_imaging_7x7, masked_imaging_covariance_7x7) g0_operated = al.Galaxy( redshift=0.5, - bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0), - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + bulge=al.lp.Sersic(intensity=1.0), + mass_profile=al.mp.IsothermalSph(einstein_radius=1.0), ) - g1_operated = al.Galaxy(redshift=1.0, bulge=al.lp_operated.Sersic(centre=(0.05, 0.05), intensity=1.0)) + g1_operated = al.Galaxy(redshift=1.0, bulge=al.lp_operated.Sersic(intensity=1.0)) tracer = al.Tracer(galaxies=[g0_operated, g1_operated]) fit = al.FitImaging(dataset=masked_imaging_7x7, tracer=tracer) assert fit.perform_inversion is False - assert fit.figure_of_merit == pytest.approx(-745.25961066, 1.0e-4) + assert fit.figure_of_merit == pytest.approx(-2657889.4489, 1.0e-4) g0_linear_operated = al.Galaxy( redshift=0.5, - bulge=al.lp_linear_operated.Sersic(centre=(0.05, 0.05), sersic_index=1.0), - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + bulge=al.lp_linear_operated.Sersic(sersic_index=1.0), + mass_profile=al.mp.IsothermalSph(einstein_radius=1.0), ) g1_linear_operated = al.Galaxy( - redshift=1.0, bulge=al.lp_linear_operated.Sersic(centre=(0.05, 0.05), sersic_index=4.0) + redshift=1.0, bulge=al.lp_linear_operated.Sersic(sersic_index=4.0) ) tracer = al.Tracer(galaxies=[g0_linear_operated, g1_linear_operated]) @@ -187,23 +187,23 @@ def test__fit_figure_of_merit(masked_imaging_7x7, masked_imaging_covariance_7x7) fit = al.FitImaging(dataset=masked_imaging_7x7, tracer=tracer) assert fit.perform_inversion is True - assert fit.figure_of_merit == pytest.approx(-14.933306470, 1.0e-4) + assert fit.figure_of_merit == pytest.approx(-14.9881985, 1.0e-4) g0 = al.Galaxy( redshift=0.5, - bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0), - disk=al.lp.Sersic(centre=(0.05, 0.05), intensity=2.0), - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + bulge=al.lp.Sersic(intensity=1.0), + disk=al.lp.Sersic(intensity=2.0), + mass_profile=al.mp.IsothermalSph(einstein_radius=1.0), ) - g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0)) + g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(intensity=1.0)) tracer = al.Tracer(galaxies=[g0, g1]) fit = al.FitImaging(dataset=masked_imaging_covariance_7x7, tracer=tracer) assert fit.perform_inversion is False - assert fit.figure_of_merit == pytest.approx(-775.003133428, 1.0e-4) + assert fit.figure_of_merit == pytest.approx(-3688191.0841, 1.0e-4) def test__fit_figure_of_merit__sub_2(image_7x7, psf_3x3, noise_map_7x7, mask_2d_7x7, masked_imaging_covariance_7x7): @@ -377,19 +377,19 @@ def test__fit_figure_of_merit__sub_2(image_7x7, psf_3x3, noise_map_7x7, mask_2d_ g0 = al.Galaxy( redshift=0.5, - bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0), - disk=al.lp.Sersic(centre=(0.05, 0.05), intensity=2.0), - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + bulge=al.lp.Sersic(intensity=1.0), + disk=al.lp.Sersic(intensity=2.0), + mass_profile=al.mp.IsothermalSph(einstein_radius=1.0), ) - g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0)) + g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(intensity=1.0)) tracer = al.Tracer(galaxies=[g0, g1]) fit = al.FitImaging(dataset=masked_imaging_covariance_7x7, tracer=tracer) assert fit.perform_inversion is False - assert fit.figure_of_merit == pytest.approx(-775.0031334280, 1.0e-4) + assert fit.figure_of_merit == pytest.approx(-3688191.0841, 1.0e-4) def test__fit__sky___handles_special_behaviour(masked_imaging_7x7): @@ -399,12 +399,12 @@ def test__fit__sky___handles_special_behaviour(masked_imaging_7x7): g0 = al.Galaxy( redshift=0.5, - bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0), - disk=al.lp.Sersic(centre=(0.05, 0.05), intensity=2.0), - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + bulge=al.lp.Sersic(intensity=1.0), + disk=al.lp.Sersic(intensity=2.0), + mass_profile=al.mp.IsothermalSph(einstein_radius=1.0), ) - g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0)) + g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(intensity=1.0)) tracer = al.Tracer(galaxies=[g0, g1]) @@ -412,7 +412,7 @@ def test__fit__sky___handles_special_behaviour(masked_imaging_7x7): dataset=masked_imaging_7x7, tracer=tracer, dataset_model=al.DatasetModel(background_sky_level=5.0) ) - assert fit.figure_of_merit == pytest.approx(-18050.8847818, 1.0e-4) + assert fit.figure_of_merit == pytest.approx(-3196962.5844406, 1.0e-4) def test__fit__model_dataset__grid_offset__handles_special_behaviour(masked_imaging_7x7): @@ -421,13 +421,13 @@ def test__fit__model_dataset__grid_offset__handles_special_behaviour(masked_imag g0 = al.Galaxy( redshift=0.5, - bulge=al.lp.Sersic(centre=(-1.05, -2.05), intensity=1.0), - disk=al.lp.Sersic(centre=(-1.05, -2.05), intensity=2.0), - mass_profile=al.mp.IsothermalSph(centre=(-1.05, -2.05), einstein_radius=1.0), + bulge=al.lp.Sersic(centre=(-1.0, -2.0), intensity=1.0), + disk=al.lp.Sersic(centre=(-1.0, -2.0), intensity=2.0), + mass_profile=al.mp.IsothermalSph(centre=(-1.0, -2.0), einstein_radius=1.0), ) g1 = al.Galaxy(redshift=1.0, - bulge=al.lp.Sersic(centre=(-1.05, -2.05), intensity=1.0) + bulge=al.lp.Sersic(centre=(-1.0, -2.0), intensity=1.0) ) tracer = al.Tracer(galaxies=[g0, g1]) @@ -438,7 +438,7 @@ def test__fit__model_dataset__grid_offset__handles_special_behaviour(masked_imag dataset_model=al.DatasetModel(grid_offset=(1.0, 2.0)) ) - assert fit.figure_of_merit == pytest.approx(-648.48145556, 1.0e-4) + assert fit.figure_of_merit == pytest.approx(-2849711.5317237, 1.0e-4) g0_linear = al.Galaxy( redshift=0.5, @@ -468,10 +468,10 @@ def test__galaxy_model_image_dict(masked_imaging_7x7): g0 = al.Galaxy( redshift=0.5, - bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0), - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + bulge=al.lp.Sersic(intensity=1.0), + mass_profile=al.mp.IsothermalSph(einstein_radius=1.0), ) - g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0)) + g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(intensity=1.0)) g2 = al.Galaxy(redshift=1.0) tracer = al.Tracer(galaxies=[g0, g1, g2]) @@ -480,20 +480,20 @@ def test__galaxy_model_image_dict(masked_imaging_7x7): blurred_image_2d_list = tracer.blurred_image_2d_list_from( grid=masked_imaging_7x7.grids.lp, - psf=masked_imaging_7x7.psf, + convolver=masked_imaging_7x7.convolver, blurring_grid=masked_imaging_7x7.grids.blurring, ) assert fit.galaxy_model_image_dict[g0] == pytest.approx( - blurred_image_2d_list[0].array, 1.0e-4 + blurred_image_2d_list[0], 1.0e-4 ) assert fit.galaxy_model_image_dict[g1] == pytest.approx( - blurred_image_2d_list[1].array, 1.0e-4 + blurred_image_2d_list[1], 1.0e-4 ) assert (fit.galaxy_model_image_dict[g2] == np.zeros(9)).all() assert fit.model_data.native == pytest.approx( - fit.galaxy_model_image_dict[g0].native.array + fit.galaxy_model_image_dict[g1].native.array, + fit.galaxy_model_image_dict[g0].native + fit.galaxy_model_image_dict[g1].native, 1.0e-4, ) @@ -519,7 +519,7 @@ def test__galaxy_model_image_dict(masked_imaging_7x7): assert (fit.galaxy_model_image_dict[g2] == np.zeros(9)).all() assert fit.model_data == pytest.approx( - fit.galaxy_model_image_dict[g0_linear].array + fit.galaxy_model_image_dict[g1_linear].array, + fit.galaxy_model_image_dict[g0_linear] + fit.galaxy_model_image_dict[g1_linear], 1.0e-4, ) @@ -540,13 +540,13 @@ def test__galaxy_model_image_dict(masked_imaging_7x7): fit = al.FitImaging(dataset=masked_imaging_7x7, tracer=tracer) - assert (fit.galaxy_model_image_dict[g0_no_light].array == np.zeros(9)).all() - assert fit.galaxy_model_image_dict[galaxy_pix_0].array[4] == pytest.approx( + assert (fit.galaxy_model_image_dict[g0_no_light] == np.zeros(9)).all() + assert fit.galaxy_model_image_dict[galaxy_pix_0][4] == pytest.approx( 1.259965886, 1.0e-4 ) assert fit.model_data == pytest.approx( - fit.galaxy_model_image_dict[galaxy_pix_0].array, 1.0e-4 + fit.galaxy_model_image_dict[galaxy_pix_0], 1.0e-4 ) # Normal light + Linear Light PRofiles + Pixelization + Regularizaiton @@ -562,18 +562,18 @@ def test__galaxy_model_image_dict(masked_imaging_7x7): fit = al.FitImaging(dataset=masked_imaging_7x7, tracer=tracer, settings_inversion=al.SettingsInversion(use_w_tilde=False)) assert fit.galaxy_model_image_dict[g0] == pytest.approx( - blurred_image_2d_list[0].array, 1.0e-4 + blurred_image_2d_list[0], 1.0e-4 ) assert fit.galaxy_model_image_dict[g0_linear][4] == pytest.approx( - -9.31341026467, 1.0e-4 + -650.736682, 1.0e-4 ) assert fit.galaxy_model_image_dict[galaxy_pix_0][4] == pytest.approx( - 0.9501715, 1.0e-4 + 1.08219997, 1.0e-4 ) assert fit.galaxy_model_image_dict[galaxy_pix_1][4] == pytest.approx( - 0.9501714, 1.0e-4 + 1.0822004, 1.0e-4 ) assert (fit.galaxy_model_image_dict[g2] == np.zeros(9)).all() @@ -596,29 +596,29 @@ def test__subtracted_image_of_galaxies_dict(masked_imaging_7x7): g0_image = g0.blurred_image_2d_from( grid=masked_imaging_7x7.grids.lp, blurring_grid=masked_imaging_7x7.grids.blurring, - psf=masked_imaging_7x7.psf + convolver=masked_imaging_7x7.convolver ) g1_image = g1.blurred_image_2d_from( grid=masked_imaging_7x7.grids.lp, blurring_grid=masked_imaging_7x7.grids.blurring, - psf=masked_imaging_7x7.psf + convolver=masked_imaging_7x7.convolver ) g2_image = g2.blurred_image_2d_from( grid=masked_imaging_7x7.grids.lp, blurring_grid=masked_imaging_7x7.grids.blurring, - psf=masked_imaging_7x7.psf + convolver=masked_imaging_7x7.convolver ) assert fit.subtracted_images_of_galaxies_dict[g0] == pytest.approx( - masked_imaging_7x7.data.array - g1_image.array - g2_image.array, 1.0e-4 + masked_imaging_7x7.data - g1_image - g2_image, 1.0e-4 ) assert fit.subtracted_images_of_galaxies_dict[g1] == pytest.approx( - masked_imaging_7x7.data.array - g0_image.array - g2_image.array, 1.0e-4 + masked_imaging_7x7.data - g0_image - g2_image, 1.0e-4 ) assert fit.subtracted_images_of_galaxies_dict[g2] == pytest.approx( - masked_imaging_7x7.data.array - g0_image.array - g1_image.array, 1.0e-4 + masked_imaging_7x7.data - g0_image - g1_image, 1.0e-4 ) # 3 Planes @@ -637,18 +637,18 @@ def test__subtracted_image_of_galaxies_dict(masked_imaging_7x7): blurred_image_2d_list = tracer.blurred_image_2d_list_from( grid=masked_imaging_7x7.grids.lp, - psf=masked_imaging_7x7.psf, + convolver=masked_imaging_7x7.convolver, blurring_grid=masked_imaging_7x7.grids.blurring, ) assert fit.subtracted_images_of_galaxies_dict[g0] == pytest.approx( - masked_imaging_7x7.data.array - blurred_image_2d_list[1].array - blurred_image_2d_list[2].array, 1.0e-4 + masked_imaging_7x7.data - blurred_image_2d_list[1] - blurred_image_2d_list[2], 1.0e-4 ) assert fit.subtracted_images_of_galaxies_dict[g1] == pytest.approx( - masked_imaging_7x7.data.array - blurred_image_2d_list[0].array - blurred_image_2d_list[2].array, 1.0e-4 + masked_imaging_7x7.data - blurred_image_2d_list[0] - blurred_image_2d_list[2], 1.0e-4 ) assert fit.subtracted_images_of_galaxies_dict[g2] == pytest.approx( - masked_imaging_7x7.data.array - blurred_image_2d_list[0].array - blurred_image_2d_list[1].array, 1.0e-4 + masked_imaging_7x7.data - blurred_image_2d_list[0] - blurred_image_2d_list[1], 1.0e-4 ) @@ -677,14 +677,14 @@ def test__model_images_of_planes_list(masked_imaging_7x7_sub_2): fit = al.FitImaging(dataset=masked_imaging_7x7_sub_2, tracer=tracer, settings_inversion=al.SettingsInversion(use_w_tilde=False)) assert fit.model_images_of_planes_list[0] == pytest.approx( - fit.galaxy_model_image_dict[g0].array, 1.0e-4 + fit.galaxy_model_image_dict[g0], 1.0e-4 ) assert fit.model_images_of_planes_list[1] == pytest.approx( - fit.galaxy_model_image_dict[g1_linear].array, 1.0e-4 + fit.galaxy_model_image_dict[g1_linear], 1.0e-4 ) assert fit.model_images_of_planes_list[2] == pytest.approx( - fit.galaxy_model_image_dict[galaxy_pix_0].array - + fit.galaxy_model_image_dict[galaxy_pix_1].array, + fit.galaxy_model_image_dict[galaxy_pix_0] + + fit.galaxy_model_image_dict[galaxy_pix_1], 1.0e-4, ) @@ -741,7 +741,7 @@ def test___unmasked_blurred_images(masked_imaging_7x7): blurred_images_of_planes = tracer.blurred_image_2d_list_from( grid=masked_imaging_7x7.grids.lp, - psf=masked_imaging_7x7.psf, + convolver=masked_imaging_7x7.convolver, blurring_grid=masked_imaging_7x7.grids.blurring, ) @@ -767,16 +767,15 @@ def test___unmasked_blurred_images(masked_imaging_7x7): def test__tracer_linear_light_profiles_to_light_profiles(masked_imaging_7x7): - g0 = al.Galaxy(redshift=0.5, bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0)) + g0 = al.Galaxy(redshift=0.5, bulge=al.lp.Sersic(intensity=1.0)) g0_linear = al.Galaxy( redshift=0.5, - bulge=al.lp_linear.Sersic(centre=(0.05, 0.05), sersic_index=1.0), - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + bulge=al.lp_linear.Sersic(sersic_index=1.0), + mass_profile=al.mp.IsothermalSph(einstein_radius=1.0), ) - g1_linear = al.Galaxy(redshift=1.0, bulge=al.lp_linear.Sersic(centre=(0.05, 0.05), sersic_index=4.0)) - + g1_linear = al.Galaxy(redshift=1.0, bulge=al.lp_linear.Sersic(sersic_index=4.0)) tracer = al.Tracer(galaxies=[g0, g0_linear, g1_linear]) @@ -787,8 +786,8 @@ def test__tracer_linear_light_profiles_to_light_profiles(masked_imaging_7x7): tracer = fit.tracer_linear_light_profiles_to_light_profiles assert tracer.galaxies[0].bulge.intensity == pytest.approx(1.0, 1.0e-4) - assert tracer.galaxies[1].bulge.intensity == pytest.approx(-5.830442986, 1.0e-4) - assert tracer.galaxies[2].bulge.intensity == pytest.approx(0.135755913, 1.0e-4) + assert tracer.galaxies[1].bulge.intensity == pytest.approx(-371.061130, 1.0e-4) + assert tracer.galaxies[2].bulge.intensity == pytest.approx(0.08393533428, 1.0e-4) diff --git a/test_autolens/imaging/test_simulate_and_fit_imaging.py b/test_autolens/imaging/test_simulate_and_fit_imaging.py index efa22052f..f1dc8c990 100644 --- a/test_autolens/imaging/test_simulate_and_fit_imaging.py +++ b/test_autolens/imaging/test_simulate_and_fit_imaging.py @@ -111,7 +111,7 @@ def test__simulate_imaging_data_and_fit__known_likelihood(): dataset = simulator.via_tracer_from(tracer=tracer, grid=grid) mask = al.Mask2D.circular( - shape_native=dataset.data.shape_native, pixel_scales=0.2, radius=2.005 + shape_native=dataset.data.shape_native, pixel_scales=0.2, radius=2.0 ) masked_dataset = dataset.apply_mask(mask=mask) @@ -149,7 +149,7 @@ def test__simulate_imaging_data_and_fit__linear_light_profiles_agree_with_standa ) mask = al.Mask2D.circular( - shape_native=dataset.data.shape_native, pixel_scales=0.2, radius=0.805 + shape_native=dataset.data.shape_native, pixel_scales=0.2, radius=0.8 ) masked_dataset = dataset.apply_mask(mask=mask) @@ -199,15 +199,15 @@ def test__simulate_imaging_data_and_fit__linear_light_profiles_agree_with_standa lens_galaxy_image = lens_galaxy.blurred_image_2d_from( grid=masked_dataset.grids.lp, - psf=masked_dataset.psf, + convolver=masked_dataset.convolver, blurring_grid=masked_dataset.grids.blurring, ) assert fit_linear.galaxy_model_image_dict[lens_galaxy_linear] == pytest.approx( - lens_galaxy_image.array, 1.0e-4 + lens_galaxy_image, 1.0e-4 ) assert fit_linear.model_images_of_planes_list[0] == pytest.approx( - lens_galaxy_image.array, 1.0e-4 + lens_galaxy_image, 1.0e-4 ) traced_grid_2d_list = tracer.traced_grid_2d_list_from(grid=masked_dataset.grids.lp) @@ -217,16 +217,16 @@ def test__simulate_imaging_data_and_fit__linear_light_profiles_agree_with_standa source_galaxy_image = source_galaxy.blurred_image_2d_from( grid=traced_grid_2d_list[1], - psf=masked_dataset.psf, + convolver=masked_dataset.convolver, blurring_grid=traced_blurring_grid_2d_list[1], ) assert fit_linear.galaxy_model_image_dict[source_galaxy_linear] == pytest.approx( - source_galaxy_image.array, 1.0e-4 + source_galaxy_image, 1.0e-4 ) assert fit_linear.model_images_of_planes_list[1] == pytest.approx( - source_galaxy_image.array, 1.0e-4 + source_galaxy_image, 1.0e-4 ) @@ -258,7 +258,7 @@ def test__simulate_imaging_data_and_fit__linear_light_profiles_and_pixelization( ) mask = al.Mask2D.circular( - shape_native=dataset.data.shape_native, pixel_scales=0.2, radius=0.805 + shape_native=dataset.data.shape_native, pixel_scales=0.2, radius=0.8 ) masked_dataset = dataset.apply_mask(mask=mask) @@ -316,15 +316,15 @@ def test__simulate_imaging_data_and_fit__linear_light_profiles_and_pixelization( lens_galaxy_image = lens_galaxy.blurred_image_2d_from( grid=masked_dataset.grids.lp, - psf=masked_dataset.psf, + convolver=masked_dataset.convolver, blurring_grid=masked_dataset.grids.blurring, ) assert fit_linear.galaxy_model_image_dict[lens_galaxy_linear] == pytest.approx( - lens_galaxy_image.array, 1.0e-2 + lens_galaxy_image, 1.0e-2 ) assert fit_linear.model_images_of_planes_list[0] == pytest.approx( - lens_galaxy_image.array, 1.0e-2 + lens_galaxy_image, 1.0e-2 ) assert fit_linear.galaxy_model_image_dict[source_galaxy_pix][0] == pytest.approx( @@ -360,7 +360,7 @@ def test__simulate_imaging_data_and_fit__linear_light_profiles_and_pixelization( 0.0, ] ), - abs=1.0e-1, + 1.0e-4, ) assert fit_linear.figure_of_merit == pytest.approx(-84.11166, 1.0e-4) @@ -382,7 +382,7 @@ def test__simulate_imaging_data_and_fit__linear_light_profiles_and_pixelization( settings_inversion=al.SettingsInversion(use_w_tilde=False), ) - assert fit_linear.figure_of_merit == pytest.approx(-73.27676850869975, abs=1.0e-4) + assert fit_linear.figure_of_merit == pytest.approx(-73.27676850869975, 1.0e-4) def test__simulate_imaging_data_and_fit__linear_light_profiles_and_pixelization__sub_2(): @@ -413,7 +413,7 @@ def test__simulate_imaging_data_and_fit__linear_light_profiles_and_pixelization_ ) mask = al.Mask2D.circular( - shape_native=dataset.data.shape_native, pixel_scales=0.2, radius=0.805 + shape_native=dataset.data.shape_native, pixel_scales=0.2, radius=0.8 ) dataset = al.Imaging( @@ -464,15 +464,15 @@ def test__simulate_imaging_data_and_fit__linear_light_profiles_and_pixelization_ lens_galaxy_image = lens_galaxy.blurred_image_2d_from( grid=masked_dataset.grids.lp, - psf=masked_dataset.psf, + convolver=masked_dataset.convolver, blurring_grid=masked_dataset.grids.blurring, ) assert fit_linear.galaxy_model_image_dict[lens_galaxy_linear] == pytest.approx( - lens_galaxy_image.array, 1.0e-2 + lens_galaxy_image, 1.0e-2 ) assert fit_linear.model_images_of_planes_list[0] == pytest.approx( - lens_galaxy_image.array, 1.0e-2 + lens_galaxy_image, 1.0e-2 ) assert fit_linear.galaxy_model_image_dict[source_galaxy_pix][0] == pytest.approx( @@ -512,9 +512,9 @@ def test__simulate_imaging_data_and_fit__linear_light_profiles_and_pixelization_ 0.0, ] ), - abs=1.0e-1, + 1.0e-4, ) - assert fit_linear.figure_of_merit == pytest.approx(-84.66302233089499, abs=1.0e-4) + assert fit_linear.figure_of_merit == pytest.approx(-84.66302233089499, 1.0e-4) def test__simulate_imaging_data_and_fit__complex_fit_compare_mapping_matrix_w_tilde(): @@ -676,7 +676,7 @@ def test__fit_figure_of_merit__mge_mass_model(masked_imaging_7x7, masked_imaging ) mask = al.Mask2D.circular( - shape_native=dataset.data.shape_native, pixel_scales=0.2, radius=0.805 + shape_native=dataset.data.shape_native, pixel_scales=0.2, radius=0.8 ) masked_dataset = dataset.apply_mask(mask=mask) diff --git a/test_autolens/interferometer/model/test_analysis_interferometer.py b/test_autolens/interferometer/model/test_analysis_interferometer.py index 5ceea7199..017d3d28b 100644 --- a/test_autolens/interferometer/model/test_analysis_interferometer.py +++ b/test_autolens/interferometer/model/test_analysis_interferometer.py @@ -42,8 +42,8 @@ def test__figure_of_merit__matches_correct_fit_given_galaxy_profiles(interferome def test__positions__likelihood_overwrite__changes_likelihood( interferometer_7, mask_2d_7x7 ): - lens = al.Galaxy(redshift=0.5, mass=al.mp.IsothermalSph(centre=(0.05, 0.05))) - source = al.Galaxy(redshift=1.0, light=al.lp.SersicSph(centre=(0.05, 0.05))) + lens = al.Galaxy(redshift=0.5, mass=al.mp.IsothermalSph()) + source = al.Galaxy(redshift=1.0, light=al.lp.SersicSph()) model = af.Collection(galaxies=af.Collection(lens=lens, source=source)) @@ -57,7 +57,7 @@ def test__positions__likelihood_overwrite__changes_likelihood( fit = al.FitInterferometer(dataset=interferometer_7, tracer=tracer) assert fit.log_likelihood == analysis_log_likelihood - assert analysis_log_likelihood == pytest.approx(-62.463179940, 1.0e-4) + assert analysis_log_likelihood == pytest.approx(-127914.36273, 1.0e-4) positions_likelihood = al.PositionsLH( positions=al.Grid2DIrregular([(1.0, 100.0), (200.0, 2.0)]), threshold=0.01 diff --git a/test_autolens/interferometer/test_fit_interferometer.py b/test_autolens/interferometer/test_fit_interferometer.py index cbb12c93c..52045349d 100644 --- a/test_autolens/interferometer/test_fit_interferometer.py +++ b/test_autolens/interferometer/test_fit_interferometer.py @@ -19,9 +19,9 @@ def test__fit_figure_of_merit(interferometer_7): g0 = al.Galaxy( redshift=0.5, - bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0), - disk=al.lp.Sersic(centre=(0.05, 0.05), intensity=2.0), - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + bulge=al.lp.Sersic(intensity=1.0), + disk=al.lp.Sersic(intensity=2.0), + mass_profile=al.mp.IsothermalSph(einstein_radius=1.0), ) g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(intensity=1.0)) @@ -31,29 +31,27 @@ def test__fit_figure_of_merit(interferometer_7): fit = al.FitInterferometer(dataset=interferometer_7, tracer=tracer) assert fit.perform_inversion is False - assert fit.figure_of_merit == pytest.approx(-12758.714175708, 1.0e-4) + assert fit.figure_of_merit == pytest.approx(-59413306.47762, 1.0e-4) basis = al.lp_basis.Basis( profile_list=[ - al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0), - al.lp.Sersic(centre=(0.05, 0.05), intensity=2.0), + al.lp.Sersic(intensity=1.0), + al.lp.Sersic(intensity=2.0), ] ) g0 = al.Galaxy( - redshift=0.5, - bulge=basis, - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + redshift=0.5, bulge=basis, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0) ) - g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0)) + g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(intensity=1.0)) tracer = al.Tracer(galaxies=[g0, g1]) fit = al.FitInterferometer(dataset=interferometer_7, tracer=tracer) assert fit.perform_inversion is False - assert fit.figure_of_merit == pytest.approx(-12779.937568696, 1.0e-4) + assert fit.figure_of_merit == pytest.approx(-59413306.47762, 1.0e-4) pixelization = al.Pixelization( mesh=al.mesh.Rectangular(shape=(3, 3)), @@ -73,9 +71,7 @@ def test__fit_figure_of_merit(interferometer_7): assert fit.perform_inversion is True assert fit.figure_of_merit == pytest.approx(-66.90612, 1.0e-4) - galaxy_light = al.Galaxy( - redshift=0.5, bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0) - ) + galaxy_light = al.Galaxy(redshift=0.5, bulge=al.lp.Sersic(intensity=1.0)) pixelization = al.Pixelization( mesh=al.mesh.Rectangular(shape=(3, 3)), @@ -93,13 +89,13 @@ def test__fit_figure_of_merit(interferometer_7): ) assert fit.perform_inversion is True - assert fit.figure_of_merit == pytest.approx(-250.22594512, 1.0e-4) + assert fit.figure_of_merit == pytest.approx(-1570173.14216, 1.0e-4) g0_linear = al.Galaxy( redshift=0.5, - bulge=al.lp_linear.Sersic(centre=(0.05, 0.05), sersic_index=1.0), - disk=al.lp_linear.Sersic(centre=(0.05, 0.05), sersic_index=4.0), - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + bulge=al.lp_linear.Sersic(sersic_index=1.0), + disk=al.lp_linear.Sersic(sersic_index=4.0), + mass_profile=al.mp.IsothermalSph(einstein_radius=1.0), ) tracer = al.Tracer(galaxies=[g0_linear, g1]) @@ -107,19 +103,17 @@ def test__fit_figure_of_merit(interferometer_7): fit = al.FitInterferometer(dataset=interferometer_7, tracer=tracer) assert fit.perform_inversion is True - assert fit.figure_of_merit == pytest.approx(-197.670468767, 1.0e-4) + assert fit.figure_of_merit == pytest.approx(-669283.091396, 1.0e-4) basis = al.lp_basis.Basis( profile_list=[ - al.lp_linear.Sersic(centre=(0.05, 0.05), sersic_index=1.0), - al.lp_linear.Sersic(centre=(0.05, 0.05), sersic_index=4.0), + al.lp_linear.Sersic(sersic_index=1.0), + al.lp_linear.Sersic(sersic_index=4.0), ] ) g0_linear = al.Galaxy( - redshift=0.5, - bulge=basis, - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + redshift=0.5, bulge=basis, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0) ) tracer = al.Tracer(galaxies=[g0_linear, g1]) @@ -127,7 +121,7 @@ def test__fit_figure_of_merit(interferometer_7): fit = al.FitInterferometer(dataset=interferometer_7, tracer=tracer) assert fit.perform_inversion is True - assert fit.figure_of_merit == pytest.approx(-197.6704687, 1.0e-4) + assert fit.figure_of_merit == pytest.approx(-669283.091396, 1.0e-4) tracer = al.Tracer(galaxies=[g0_linear, galaxy_pix]) @@ -137,15 +131,40 @@ def test__fit_figure_of_merit(interferometer_7): assert fit.figure_of_merit == pytest.approx(-34.393456, 1.0e-4) +def test___fit_figure_of_merit__different_settings( + interferometer_7, interferometer_7_lop +): + pixelization = al.Pixelization( + mesh=al.mesh.Rectangular(shape=(3, 3)), + regularization=al.reg.Constant(coefficient=0.01), + ) + + g0 = al.Galaxy(redshift=0.5, pixelization=pixelization) + + tracer = al.Tracer(galaxies=[al.Galaxy(redshift=0.5), g0]) + + fit = al.FitInterferometer( + dataset=interferometer_7_lop, + tracer=tracer, + settings_inversion=al.SettingsInversion( + use_w_tilde=False, use_linear_operators=True + ), + ) + + assert (fit.noise_map.slim == np.full(fill_value=2.0 + 2.0j, shape=(7,))).all() + assert fit.log_evidence == pytest.approx(-71.5177, 1e-4) + assert fit.figure_of_merit == pytest.approx(-71.5177, 1.0e-4) + + def test___galaxy_model_image_dict(interferometer_7, interferometer_7_grid): # Normal Light Profiles Only g0 = al.Galaxy( redshift=0.5, - bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0), - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + bulge=al.lp.Sersic(intensity=1.0), + mass_profile=al.mp.IsothermalSph(einstein_radius=1.0), ) - g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0)) + g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(intensity=1.0)) g2 = al.Galaxy(redshift=1.0) tracer = al.Tracer(galaxies=[g0, g1, g2]) @@ -163,15 +182,15 @@ def test___galaxy_model_image_dict(interferometer_7, interferometer_7_grid): g0_image = g0.image_2d_from(grid=traced_grid_2d_list_from[0]) g1_image = g1.image_2d_from(grid=traced_grid_2d_list_from[1]) - assert fit.galaxy_model_image_dict[g0] == pytest.approx(g0_image.array, 1.0e-4) - assert fit.galaxy_model_image_dict[g1] == pytest.approx(g1_image.array, 1.0e-4) + assert fit.galaxy_model_image_dict[g0] == pytest.approx(g0_image, 1.0e-4) + assert fit.galaxy_model_image_dict[g1] == pytest.approx(g1_image, 1.0e-4) # Linear Light Profiles Only g0_linear = al.Galaxy( redshift=0.5, - bulge=al.lp_linear.Sersic(centre=(0.05, 0.05)), - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + bulge=al.lp_linear.Sersic(), + mass_profile=al.mp.IsothermalSph(einstein_radius=1.0), ) g1_linear = al.Galaxy(redshift=1.0, bulge=al.lp_linear.Sersic()) @@ -187,7 +206,7 @@ def test___galaxy_model_image_dict(interferometer_7, interferometer_7_grid): 1.00018622848, 1.0e-2 ) assert fit.galaxy_model_image_dict[g1_linear][3] == pytest.approx( - -0.017435532289, 1.0e-2 + -3.89387356e-04, 1.0e-2 ) pixelization = al.Pixelization( @@ -196,8 +215,7 @@ def test___galaxy_model_image_dict(interferometer_7, interferometer_7_grid): ) g0_no_light = al.Galaxy( - redshift=0.5, - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + redshift=0.5, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0) ) galaxy_pix_0 = al.Galaxy(redshift=1.0, pixelization=pixelization) @@ -212,7 +230,7 @@ def test___galaxy_model_image_dict(interferometer_7, interferometer_7_grid): assert (fit.galaxy_model_image_dict[g0_no_light].native == np.zeros((7, 7))).all() assert fit.galaxy_model_image_dict[galaxy_pix_0][0] == pytest.approx( - -0.1039673270, 1.0e-4 + -0.169439019, 1.0e-4 ) # Normal light + Linear Light PRofiles + Pixelization + Regularizaiton @@ -226,17 +244,17 @@ def test___galaxy_model_image_dict(interferometer_7, interferometer_7_grid): settings_inversion=al.SettingsInversion(use_w_tilde=False), ) - assert fit.galaxy_model_image_dict[g0] == pytest.approx(g0_image.array, 1.0e-4) + assert fit.galaxy_model_image_dict[g0] == pytest.approx(g0_image, 1.0e-4) assert fit.galaxy_model_image_dict[g0_linear][4] == pytest.approx( - -22.8444395, 1.0e-4 + -1946.44265722, 1.0e-4 ) assert fit.galaxy_model_image_dict[galaxy_pix_0][4] == pytest.approx( - -0.052005033, 1.0e-3 + 0.0473537322, 1.0e-3 ) assert fit.galaxy_model_image_dict[galaxy_pix_1][4] == pytest.approx( - -0.0520050308, 1.0e-3 + 0.0473505541, 1.0e-3 ) assert (fit.galaxy_model_image_dict[g2] == np.zeros(9)).all() @@ -246,10 +264,10 @@ def test__galaxy_model_visibilities_dict(interferometer_7, interferometer_7_grid g0 = al.Galaxy( redshift=0.5, - bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0), - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + bulge=al.lp.Sersic(intensity=1.0), + mass_profile=al.mp.IsothermalSph(einstein_radius=1.0), ) - g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(centre=(0.05, 0.05), intensity=1.0)) + g1 = al.Galaxy(redshift=1.0, bulge=al.lp.Sersic(intensity=1.0)) g2 = al.Galaxy(redshift=1.0) tracer = al.Tracer(galaxies=[g0, g1, g2]) @@ -288,20 +306,20 @@ def test__galaxy_model_visibilities_dict(interferometer_7, interferometer_7_grid g0_linear = al.Galaxy( redshift=0.5, - bulge=al.lp_linear.Sersic(centre=(0.05, 0.05)), - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + bulge=al.lp_linear.Sersic(), + mass_profile=al.mp.IsothermalSph(einstein_radius=1.0), ) - g1_linear = al.Galaxy(redshift=1.0, bulge=al.lp_linear.Sersic(centre=(0.05, 0.05))) + g1_linear = al.Galaxy(redshift=1.0, bulge=al.lp_linear.Sersic()) tracer = al.Tracer(galaxies=[g0_linear, g1_linear, g2]) fit = al.FitInterferometer(dataset=interferometer_7, tracer=tracer) assert fit.galaxy_model_visibilities_dict[g0_linear][0] == pytest.approx( - 1.0138228768598911 + 0.006599377953512708j, 1.0e-2 + 1.0002975772292932 - 7.12783377916253e-21j, 1.0e-2 ) assert fit.galaxy_model_visibilities_dict[g1_linear][0] == pytest.approx( - -0.012892097547972572 - 0.0019719184145301906j, 1.0e-2 + -0.0002828972025576841 + 3.035459109423297e-06j, 1.0e-2 ) assert (fit.galaxy_model_visibilities_dict[g2] == np.zeros((7,))).all() @@ -319,8 +337,7 @@ def test__galaxy_model_visibilities_dict(interferometer_7, interferometer_7_grid ) g0_no_light = al.Galaxy( - redshift=0.5, - mass_profile=al.mp.IsothermalSph(centre=(0.05, 0.05), einstein_radius=1.0), + redshift=0.5, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0) ) galaxy_pix_0 = al.Galaxy(redshift=1.0, pixelization=pixelization) @@ -330,7 +347,7 @@ def test__galaxy_model_visibilities_dict(interferometer_7, interferometer_7_grid assert (fit.galaxy_model_visibilities_dict[g0_no_light] == np.zeros((7,))).all() assert fit.galaxy_model_visibilities_dict[galaxy_pix_0][0] == pytest.approx( - 0.37828909168666935 + 0.40127834296223164j, 1.0e-4 + 0.2813594007737543 + 0.18428485685088292j, 1.0e-4 ) assert fit.model_data == pytest.approx( @@ -350,14 +367,14 @@ def test__galaxy_model_visibilities_dict(interferometer_7, interferometer_7_grid ) assert fit.galaxy_model_visibilities_dict[g0_linear][0] == pytest.approx( - -23.049182329227243 - 0.1500363319686841j, 1.0e-4 + -1946.6593508251335 + 1.3871336483456645e-17j, 1.0e-4 ) assert fit.galaxy_model_visibilities_dict[galaxy_pix_0][0] == pytest.approx( - -0.054816474483476214 + 0.14599319644288866j, 1.0e-4 + 0.04732569077375984 + 0.14872801091458496j, 1.0e-4 ) assert fit.galaxy_model_visibilities_dict[galaxy_pix_1][0] == pytest.approx( - -0.054816474483476214 + 0.14599319644288866j, 1.0e-4 + 0.047320971438523735 + 0.14872801091458515j, 1.0e-4 ) assert (fit.galaxy_model_visibilities_dict[g2] == np.zeros((7,))).all() diff --git a/test_autolens/interferometer/test_simulate_and_fit_interferometer.py b/test_autolens/interferometer/test_simulate_and_fit_interferometer.py index 71c7fc8fc..e88f3a7ef 100644 --- a/test_autolens/interferometer/test_simulate_and_fit_interferometer.py +++ b/test_autolens/interferometer/test_simulate_and_fit_interferometer.py @@ -221,7 +221,7 @@ def test__simulate_interferometer_data_and_fit__linear_light_profiles_agree_with lens_galaxy_image = lens_galaxy.image_2d_from(grid=dataset.grids.lp) assert fit_linear.galaxy_model_image_dict[lens_galaxy_linear] == pytest.approx( - lens_galaxy_image.array, 1.0e-4 + lens_galaxy_image, 1.0e-4 ) traced_grid_2d_list = tracer.traced_grid_2d_list_from(grid=dataset.grids.lp) @@ -229,7 +229,7 @@ def test__simulate_interferometer_data_and_fit__linear_light_profiles_agree_with source_galaxy_image = source_galaxy.image_2d_from(grid=traced_grid_2d_list[1]) assert fit_linear.galaxy_model_image_dict[source_galaxy_linear] == pytest.approx( - source_galaxy_image.array, 1.0e-4 + source_galaxy_image, 1.0e-4 ) lens_galaxy_visibilities = lens_galaxy.visibilities_from( @@ -262,8 +262,8 @@ def test__simulate_interferometer_data_and_fit__linear_light_profiles_and_pixeli source_galaxy = al.Galaxy( redshift=1.0, - bulge=al.lp.Sersic(centre=(0.1, 0.1), intensity=0.1, sersic_index=1.0), - disk=al.lp.Sersic(centre=(0.1, 0.1), intensity=0.2, sersic_index=4.0), + bulge=al.lp.Sersic(intensity=0.1, sersic_index=1.0), + disk=al.lp.Sersic(intensity=0.2, sersic_index=4.0), ) tracer = al.Tracer(galaxies=[lens_galaxy, source_galaxy]) @@ -307,18 +307,32 @@ def test__simulate_interferometer_data_and_fit__linear_light_profiles_and_pixeli assert fit_linear.inversion.reconstruction == pytest.approx( np.array( [ - 101.72951207, - 0.50020335, - 0.50421638, - 0.50249167, - 0.44875688, - 0.44968722, - 0.45050618, - 0.40024606, - 0.39917044, - 0.40168314, + 1.00338472e02, + 9.55074606e-02, + 9.24767167e-02, + 9.45392540e-02, + 1.41969109e-01, + 1.41828976e-01, + 1.41521130e-01, + 1.84257307e-01, + 1.85507562e-01, + 1.83726575e-01, ] ), 1.0e-2, ) assert fit_linear.figure_of_merit == pytest.approx(-29.20551989, 1.0e-4) + + lens_galaxy_image = lens_galaxy.image_2d_from(grid=dataset.grids.lp) + + assert fit_linear.galaxy_model_image_dict[lens_galaxy_linear] == pytest.approx( + lens_galaxy_image, 1.0e-2 + ) + + traced_grid_2d_list = tracer.traced_grid_2d_list_from(grid=dataset.grids.lp) + + source_galaxy_image = source_galaxy.image_2d_from(grid=traced_grid_2d_list[1]) + + # assert fit_linear.galaxy_model_image_dict[source_galaxy_pix] == pytest.approx( + # source_galaxy_image, 1.0e-1 + # ) diff --git a/test_autolens/lens/test_operate.py b/test_autolens/lens/test_operate.py index d5f7e09fb..32268bbc2 100644 --- a/test_autolens/lens/test_operate.py +++ b/test_autolens/lens/test_operate.py @@ -35,7 +35,7 @@ def test__operate_image__blurred_images_2d_via_psf_from__for_tracer_gives_list_o ) assert blurred_image.native == pytest.approx( - blurred_image_0.native.array + blurred_image_1.native.array, 1.0e-4 + blurred_image_0.native + blurred_image_1.native, 1.0e-4 ) blurred_image_list = tracer.blurred_image_2d_list_from( @@ -49,6 +49,56 @@ def test__operate_image__blurred_images_2d_via_psf_from__for_tracer_gives_list_o assert (blurred_image_list[1].native == blurred_image_1.native).all() +def test__operate_image__blurred_images_2d_via_convolver_from__for_tracer_gives_list_of_planes( + grid_2d_7x7, blurring_grid_2d_7x7, convolver_7x7 +): + g0 = al.Galaxy( + redshift=0.5, + light_profile=al.lp.Sersic(intensity=1.0), + mass_profile=al.mp.IsothermalSph(einstein_radius=1.0), + ) + g1 = al.Galaxy(redshift=1.0, light_profile=al.lp.Sersic(intensity=2.0)) + + blurred_image_0 = g0.blurred_image_2d_from( + grid=grid_2d_7x7, + convolver=convolver_7x7, + blurring_grid=blurring_grid_2d_7x7, + ) + + source_grid_2d_7x7 = g0.traced_grid_2d_from(grid=grid_2d_7x7) + source_blurring_grid_2d_7x7 = g0.traced_grid_2d_from(grid=blurring_grid_2d_7x7) + + blurred_image_1 = g1.blurred_image_2d_from( + grid=source_grid_2d_7x7, + convolver=convolver_7x7, + blurring_grid=source_blurring_grid_2d_7x7, + ) + + tracer = al.Tracer(galaxies=[g0, g1], cosmology=al.cosmo.Planck15()) + + blurred_image = tracer.blurred_image_2d_from( + grid=grid_2d_7x7, + convolver=convolver_7x7, + blurring_grid=blurring_grid_2d_7x7, + ) + + assert blurred_image.native == pytest.approx( + blurred_image_0.native + blurred_image_1.native, 1.0e-4 + ) + + blurred_image_list = tracer.blurred_image_2d_list_from( + grid=grid_2d_7x7, + convolver=convolver_7x7, + blurring_grid=blurring_grid_2d_7x7, + ) + + assert (blurred_image_list[0].slim == blurred_image_0.slim).all() + assert (blurred_image_list[1].slim == blurred_image_1.slim).all() + + assert (blurred_image_list[0].native == blurred_image_0.native).all() + assert (blurred_image_list[1].native == blurred_image_1.native).all() + + def test__operate_image__visibilities_of_planes_from_grid_and_transformer( grid_2d_7x7, transformer_7x7_7 ): @@ -74,7 +124,7 @@ def test__operate_image__visibilities_of_planes_from_grid_and_transformer( def test__operate_image__galaxy_blurred_image_2d_dict_from( - grid_2d_7x7, blurring_grid_2d_7x7, psf_3x3 + grid_2d_7x7, blurring_grid_2d_7x7, convolver_7x7 ): g0 = al.Galaxy(redshift=0.5, light_profile=al.lp.Sersic(intensity=1.0)) g1 = al.Galaxy( @@ -89,19 +139,19 @@ def test__operate_image__galaxy_blurred_image_2d_dict_from( g0_blurred_image = g0.blurred_image_2d_from( grid=grid_2d_7x7, - psf=psf_3x3, + convolver=convolver_7x7, blurring_grid=blurring_grid_2d_7x7, ) g1_blurred_image = g1.blurred_image_2d_from( grid=grid_2d_7x7, - psf=psf_3x3, + convolver=convolver_7x7, blurring_grid=blurring_grid_2d_7x7, ) g2_blurred_image = g2.blurred_image_2d_from( grid=grid_2d_7x7, - psf=psf_3x3, + convolver=convolver_7x7, blurring_grid=blurring_grid_2d_7x7, ) @@ -110,7 +160,7 @@ def test__operate_image__galaxy_blurred_image_2d_dict_from( g3_blurred_image = g3.blurred_image_2d_from( grid=source_grid_2d_7x7, - psf=psf_3x3, + convolver=convolver_7x7, blurring_grid=source_blurring_grid_2d_7x7, ) @@ -118,14 +168,14 @@ def test__operate_image__galaxy_blurred_image_2d_dict_from( blurred_image_dict = tracer.galaxy_blurred_image_2d_dict_from( grid=grid_2d_7x7, - psf=psf_3x3, + convolver=convolver_7x7, blurring_grid=blurring_grid_2d_7x7, ) - assert blurred_image_dict[g0].slim == pytest.approx(g0_blurred_image.slim.array, 1.0e-4) - assert blurred_image_dict[g1].slim == pytest.approx(g1_blurred_image.slim.array, 1.0e-4) - assert blurred_image_dict[g2].slim == pytest.approx(g2_blurred_image.slim.array, 1.0e-4) - assert blurred_image_dict[g3].slim == pytest.approx(g3_blurred_image.slim.array, 1.0e-4) + assert (blurred_image_dict[g0].slim == g0_blurred_image.slim).all() + assert (blurred_image_dict[g1].slim == g1_blurred_image.slim).all() + assert (blurred_image_dict[g2].slim == g2_blurred_image.slim).all() + assert (blurred_image_dict[g3].slim == g3_blurred_image.slim).all() def test__operate_image__galaxy_visibilities_dict_from_grid_and_transformer( diff --git a/test_autolens/lens/test_to_inversion.py b/test_autolens/lens/test_to_inversion.py index 9e617fc29..d8a008583 100644 --- a/test_autolens/lens/test_to_inversion.py +++ b/test_autolens/lens/test_to_inversion.py @@ -62,12 +62,8 @@ def test__lp_linear_func_galaxy_dict_from(masked_imaging_7x7): assert lp_linear_func_list[0].grid == pytest.approx( masked_imaging_7x7.grids.lp, 1.0e-4 ) - assert lp_linear_func_list[1].grid == pytest.approx( - traced_grid_list[1].array, 1.0e-4 - ) - assert lp_linear_func_list[2].grid == pytest.approx( - traced_grid_list[2].array, 1.0e-4 - ) + assert lp_linear_func_list[1].grid == pytest.approx(traced_grid_list[1], 1.0e-4) + assert lp_linear_func_list[2].grid == pytest.approx(traced_grid_list[2], 1.0e-4) lp_linear_3 = al.lp_linear.LightProfileLinear() lp_linear_4 = al.lp_linear.LightProfileLinear() @@ -364,12 +360,8 @@ def test__traced_mesh_grid_pg_list(masked_imaging_7x7): traced_mesh_grids_list_of_planes = tracer_to_inversion.traced_mesh_grid_pg_list - traced_grid_pix_0 = tracer.traced_grid_2d_list_from( - grid=al.Grid2DIrregular(values=[[1.0, 0.0]]) - )[2] - traced_grid_pix_1 = tracer.traced_grid_2d_list_from( - grid=al.Grid2DIrregular(values=[[2.0, 0.0]]) - )[4] + 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_mesh_grids_list_of_planes[0] == None assert traced_mesh_grids_list_of_planes[1] == None @@ -471,13 +463,10 @@ def test__inversion_imaging_from(grid_2d_7x7, masked_imaging_7x7): data=masked_imaging_7x7.data, noise_map=masked_imaging_7x7.noise_map, grids=grids, - psf=masked_imaging_7x7.psf, convolver=masked_imaging_7x7.convolver, ) - g_linear = al.Galaxy( - redshift=0.5, light_linear=al.lp_linear.Sersic(centre=(0.05, 0.05)) - ) + g_linear = al.Galaxy(redshift=0.5, light_linear=al.lp_linear.Sersic()) tracer = al.Tracer(galaxies=[al.Galaxy(redshift=0.5), g_linear]) @@ -489,7 +478,7 @@ def test__inversion_imaging_from(grid_2d_7x7, masked_imaging_7x7): inversion = tracer_to_inversion.inversion - assert inversion.reconstruction[0] == pytest.approx(0.186868464426, 1.0e-2) + assert inversion.reconstruction[0] == pytest.approx(0.002310, 1.0e-2) pixelization = al.Pixelization( mesh=al.mesh.Rectangular(shape=(3, 3)), @@ -530,9 +519,7 @@ def test__inversion_interferometer_from(grid_2d_7x7, interferometer_7): transformer=interferometer_7.transformer, ) - g_linear = al.Galaxy( - redshift=0.5, light_linear=al.lp_linear.Sersic(centre=(0.05, 0.05)) - ) + g_linear = al.Galaxy(redshift=0.5, light_linear=al.lp_linear.Sersic()) tracer = al.Tracer(galaxies=[al.Galaxy(redshift=0.5), g_linear]) @@ -544,7 +531,7 @@ def test__inversion_interferometer_from(grid_2d_7x7, interferometer_7): inversion = tracer_to_inversion.inversion - assert inversion.reconstruction[0] == pytest.approx(0.0412484695, 1.0e-5) + assert inversion.reconstruction[0] == pytest.approx(0.000513447, 1.0e-5) pixelization = al.Pixelization( mesh=al.mesh.Rectangular(shape=(7, 7)), diff --git a/test_autolens/lens/test_tracer.py b/test_autolens/lens/test_tracer.py index f97a54e96..e526b505e 100644 --- a/test_autolens/lens/test_tracer.py +++ b/test_autolens/lens/test_tracer.py @@ -174,7 +174,7 @@ def test__grid_2d_at_redshift_from(grid_2d_7x7): grid_at_redshift = tracer.grid_2d_at_redshift_from(grid=grid_simple, redshift=0.5) - assert grid_2d_list_from[1] == pytest.approx(grid_at_redshift.array, 1.0e-4) + assert grid_2d_list_from[1] == pytest.approx(grid_at_redshift, 1.0e-4) assert grid_at_redshift[0] == pytest.approx((0.6273814, 1.2547628), 1.0e-4) galaxies_plus_extra = [g0, g1, g2, g3, g4, g5, al.Galaxy(redshift=1.75)] @@ -185,7 +185,7 @@ def test__grid_2d_at_redshift_from(grid_2d_7x7): grid_at_redshift = tracer.grid_2d_at_redshift_from(grid=grid_simple, redshift=1.75) - assert grid_2d_list_from[2] == pytest.approx(grid_at_redshift.array, 1.0e-4) + assert grid_2d_list_from[2] == pytest.approx(grid_at_redshift, 1.0e-4) assert grid_at_redshift[0] == pytest.approx((0.27331481161, 0.5466296232), 1.0e-4) galaxies_plus_extra = [g0, g1, g2, g3, g4, g5, al.Galaxy(redshift=2.0)] @@ -196,7 +196,7 @@ def test__grid_2d_at_redshift_from(grid_2d_7x7): grid_at_redshift = tracer.grid_2d_at_redshift_from(grid=grid_simple, redshift=2.0) - assert grid_2d_list_from[2] == pytest.approx(grid_at_redshift.array, 1.0e-4) + assert grid_2d_list_from[2] == pytest.approx(grid_at_redshift, 1.0e-4) assert grid_at_redshift[0] == pytest.approx((0.222772465, 0.445544931), 1.0e-4) @@ -294,7 +294,7 @@ def test__image_2d_from__sum_of_individual_images(mask_2d_7x7): image_tracer = tracer.image_2d_from(grid=grid_2d_7x7) assert image.shape_native == (7, 7) - assert image == pytest.approx(image_tracer.array, 1.0e-4) + assert image == pytest.approx(image_tracer, 1.0e-4) def test__image_2d_via_input_plane_image_from__with_foreground_planes(grid_2d_7x7): @@ -323,7 +323,7 @@ def test__image_2d_via_input_plane_image_from__with_foreground_planes(grid_2d_7x ) assert image_via_light_profile[0] == pytest.approx( - image_via_input_plane_image[0].array, 1.0e-2 + image_via_input_plane_image[0], 1.0e-2 ) @@ -398,7 +398,7 @@ def test__image_2d_via_input_plane_image_from__with_foreground_planes__multi_pla ) assert image_via_light_profile[0] == pytest.approx( - image_via_input_plane_image[0].array, 1.0e-2 + image_via_input_plane_image[0], 1.0e-2 ) plane_image = g1.image_2d_from(grid=plane_grid) @@ -411,7 +411,7 @@ def test__image_2d_via_input_plane_image_from__with_foreground_planes__multi_pla ) assert image_via_light_profile[0] == pytest.approx( - image_via_input_plane_image[0].array, 1.0e-2 + image_via_input_plane_image[0], 1.0e-2 ) @@ -436,7 +436,7 @@ def test__padded_image_2d_from(grid_2d_7x7): assert padded_tracer_image.shape_native == (9, 9) assert padded_tracer_image == pytest.approx( - padded_g0_image.array + padded_g1_image.array + padded_g2_image.array, 1.0e-4 + padded_g0_image + padded_g1_image + padded_g2_image, 1.0e-4 ) @@ -847,7 +847,7 @@ def test__regression__centre_of_profile_in_right_place(): g0 = al.Galaxy( redshift=0.5, - mass=al.mp.Isothermal(centre=(1.9999, 0.9999), einstein_radius=1.0), + mass=al.mp.Isothermal(centre=(2.0, 1.0), einstein_radius=1.0), ) tracer = al.Tracer(galaxies=[g0, al.Galaxy(redshift=1.0)]) diff --git a/test_autolens/lens/test_tracer_util.py b/test_autolens/lens/test_tracer_util.py index 023f7cf98..9f7aba695 100644 --- a/test_autolens/lens/test_tracer_util.py +++ b/test_autolens/lens/test_tracer_util.py @@ -47,14 +47,14 @@ def test__traced_grid_2d_list_from(grid_2d_7x7_simple): assert traced_grid_list[2][0] == pytest.approx( np.array( [ - (1.0 - beta_02 * val - beta_12 * defl11.array[0, 0]), - (1.0 - beta_02 * val - beta_12 * defl11.array[0, 1]), + (1.0 - beta_02 * val - beta_12 * defl11[0, 0]), + (1.0 - beta_02 * val - beta_12 * defl11[0, 1]), ] ), 1e-4, ) assert traced_grid_list[2][1] == pytest.approx( - np.array([(1.0 - beta_02 * 1.0 - beta_12 * defl12.array[0, 0]), 0.0]), 1e-4 + np.array([(1.0 - beta_02 * 1.0 - beta_12 * defl12[0, 0]), 0.0]), 1e-4 ) assert traced_grid_list[3][1] == pytest.approx(np.array([1.0, 0.0]), 1e-4) @@ -120,25 +120,25 @@ def test__grid_2d_at_redshift_from(grid_2d_7x7): galaxies=galaxies, grid=grid_2d_7x7, redshift=0.75 ) - assert grid_at_redshift == pytest.approx(traced_grid_list[1].array, 1.0e-4) + assert grid_at_redshift == pytest.approx(traced_grid_list[1], 1.0e-4) grid_at_redshift = al.util.tracer.grid_2d_at_redshift_from( galaxies=galaxies, grid=grid_2d_7x7, redshift=1.0 ) - assert grid_at_redshift == pytest.approx(traced_grid_list[2].array, 1.0e-4) + assert grid_at_redshift == pytest.approx(traced_grid_list[2], 1.0e-4) grid_at_redshift = al.util.tracer.grid_2d_at_redshift_from( galaxies=galaxies, grid=grid_2d_7x7, redshift=1.5 ) - assert grid_at_redshift == pytest.approx(traced_grid_list[3].array, 1.0e-4) + assert grid_at_redshift == pytest.approx(traced_grid_list[3], 1.0e-4) grid_at_redshift = al.util.tracer.grid_2d_at_redshift_from( galaxies=galaxies, grid=grid_2d_7x7, redshift=2.0 ) - assert grid_at_redshift == pytest.approx(traced_grid_list[4].array, 1.0e-4) + assert grid_at_redshift == pytest.approx(traced_grid_list[4], 1.0e-4) def test__grid_2d_at_redshift_from__redshift_between_planes(grid_2d_7x7): diff --git a/test_autolens/plot/test_get_visuals.py b/test_autolens/plot/test_get_visuals.py index 6ebcbbc2b..82f453e44 100644 --- a/test_autolens/plot/test_get_visuals.py +++ b/test_autolens/plot/test_get_visuals.py @@ -45,10 +45,7 @@ def test__2d__via_tracer(tracer_x2_plane_7x7, grid_2d_7x7): visuals_2d_via.tangential_critical_curves[0] == tracer_x2_plane_7x7.tangential_critical_curve_list_from(grid=grid_2d_7x7)[0] ).all() - assert ( - visuals_2d_via.radial_critical_curves[0] - == tracer_x2_plane_7x7.radial_critical_curve_list_from(grid=grid_2d_7x7)[0] - ).all() + assert visuals_2d_via.radial_critical_curves == None assert visuals_2d_via.vectors == 2 include_2d = aplt.Include2D( @@ -137,12 +134,7 @@ def test__via_fit_imaging_from(fit_imaging_x2_plane_7x7, grid_2d_7x7): grid=grid_2d_7x7 )[0] ).all() - assert ( - visuals_2d_via.radial_critical_curves[0] - == fit_imaging_x2_plane_7x7.tracer.radial_critical_curve_list_from( - grid=grid_2d_7x7 - )[0] - ).all() + assert visuals_2d_via.radial_critical_curves == None assert visuals_2d_via.vectors == 2 include_2d = aplt.Include2D( diff --git a/test_autolens/point/fit/positions/image/test_abstract.py b/test_autolens/point/fit/positions/image/test_abstract.py index 4ad50e2ac..89cd0c3df 100644 --- a/test_autolens/point/fit/positions/image/test_abstract.py +++ b/test_autolens/point/fit/positions/image/test_abstract.py @@ -76,12 +76,9 @@ def test__multi_plane_position_solving(): redshift_0=0.5, redshift_1=1.0, redshift_final=2.0 ) - print(fit_0.model_data) - print(fit_1.model_data.array) - - assert fit_0.model_data[0, :] == pytest.approx( - scaling_factor * fit_1.model_data.array[0, :], 1.0e-1 + assert fit_0.model_data[0, 0] == pytest.approx( + scaling_factor * fit_1.model_data[1, 0], 1.0e-1 ) - assert fit_0.model_data[0, :] == pytest.approx( - scaling_factor * fit_1.model_data.array[0, :], 1.0e-1 + assert fit_0.model_data[1, 1] == pytest.approx( + scaling_factor * fit_1.model_data[0, 1], 1.0e-1 ) diff --git a/test_autolens/point/fit/positions/image/test_pair_all.py b/test_autolens/point/fit/positions/image/test_pair_all.py index cefad8282..c95af0d02 100644 --- a/test_autolens/point/fit/positions/image/test_pair_all.py +++ b/test_autolens/point/fit/positions/image/test_pair_all.py @@ -27,7 +27,7 @@ def noise_map(): @pytest.fixture def fit(data, noise_map): - model_positions = al.Grid2DIrregular( + model_positions = np.array( [ (-1.0749, -1.1), (1.19117, 1.175), @@ -54,16 +54,16 @@ def test_andrew_implementation(fit): assert fit.chi_squared == -2.0 * -4.40375330990644 -# @pytest.mark.skipif(not JAX_INSTALLED, reason="JAX is not installed") -# def test_jax(fit): -# assert jax.jit(fit.log_likelihood)() == -4.40375330990644 +@pytest.mark.skipif(not JAX_INSTALLED, reason="JAX is not installed") +def test_jax(fit): + assert jax.jit(fit.log_likelihood)() == -4.40375330990644 def test_nan_model_positions( data, noise_map, ): - model_positions = al.Grid2DIrregular( + model_positions = np.array( [ (-1.0749, -1.1), (1.19117, 1.175), @@ -92,7 +92,7 @@ def test_duplicate_model_position( data, noise_map, ): - model_positions = al.Grid2DIrregular( + model_positions = np.array( [ (-1.0749, -1.1), (1.19117, 1.175), diff --git a/test_autolens/point/fit/test_abstract.py b/test_autolens/point/fit/test_abstract.py index 888d2f983..d8dc63ec7 100644 --- a/test_autolens/point/fit/test_abstract.py +++ b/test_autolens/point/fit/test_abstract.py @@ -52,5 +52,5 @@ def test__magnifications_at_positions__multi_plane_calculation(gal_x1_mp): assert fit_1.magnifications_at_positions[0] == magnification_1 assert fit_0.magnifications_at_positions[0] != pytest.approx( - fit_1.magnifications_at_positions.array[0], 1.0e-1 + fit_1.magnifications_at_positions[0], 1.0e-1 )