Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions autogalaxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
from autoarray.inversion.regularization.abstract import AbstractRegularization
from autoarray.inversion.pixelization import Pixelization # noqa
from autoarray.inversion.mesh.border_relocator import BorderRelocator
from autoarray.preloads import Preloads
from autoarray.preloads import mapper_indices_from
from autoarray.mask.mask_1d import Mask1D # noqa
from autoarray.mask.mask_2d import Mask2D # noqa
from autoarray.mask.derive.zoom_2d import Zoom2D
Expand Down
68 changes: 7 additions & 61 deletions autogalaxy/aggregator/agg_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def adapt_images_from(


def mesh_grids_of_planes_list_from(
fit: af.Fit, total_fits: int, use_preloaded_grid: bool
fit: af.Fit, total_fits: int
) -> List[Optional[aa.Grid2D]]:
"""
Returns the image-plane pixelization grid(s) used by the fit.
Expand All @@ -196,69 +196,15 @@ def mesh_grids_of_planes_list_from(
an output directory or from an sqlite database..
total_fits
The total number of `Analysis` objects summed to create the fit.
use_preloaded_grid
Certain pixelization's construct their mesh in the source-plane from a stochastic KMeans algorithm. This grid
may be output to hard-disk after the model-fit and loaded via the database to ensure the same grid is used
as the fit.

Returns
-------
The list of image-plane mesh centres used when creating the overall fit.
"""

if use_preloaded_grid:
if not fit.children:
return [fit.value(name="preload_mesh_grids_of_planes")]
else:
try:
return fit.child_values(name="preload_mesh_grids_of_planes")
except AttributeError:
return [None] * total_fits
if not fit.children:
return [fit.value(name="preload_mesh_grids_of_planes")]
else:
return [None] * total_fits


def preloads_from(
preloads_cls,
use_preloaded_grid: bool,
mesh_grids_of_planes: List,
) -> aa.Preloads:
"""
Returns a `Preloads` object associated with a fit loaded via the database.

When loading results via the database, the preloads class may have certain attributes associated with it
in order to perform the fit. The main purpose is to use the same image-plane mesh centres for pixelization where
the mesh is computed in the image-plane (see `agg_util.mesh_grids_of_planes_list_from`).

Parameters
----------
preloads_cls
The `Preloads` object used to create the preloads (this varies across
projects like `autogalaxy` and `autolens`).
use_preloaded_grid
Certain pixelization's construct their mesh in the source-plane from a stochastic KMeans algorithm. This grid
may be output to hard-disk after the model-fit and loaded via the database to ensure the same grid is used
as the fit.
mesh_grids_of_planes
The list of image-plane mesh centres used when creating the overall fit which are associated with the
preloads.

Returns
-------
The preloads object associated with the fit loaded via the database.
"""
preloads = preloads_cls()

if use_preloaded_grid:
if mesh_grids_of_planes is not None:
preloads = preloads_cls(
image_plane_mesh_grid_pg_list=mesh_grids_of_planes,
)

if len(preloads.image_plane_mesh_grid_pg_list) == 2:
if type(preloads.image_plane_mesh_grid_pg_list[1]) != list:
preloads.image_plane_mesh_grid_pg_list[1] = [
preloads.image_plane_mesh_grid_pg_list[1]
]

return preloads
try:
return fit.child_values(name="preload_mesh_grids_of_planes")
except AttributeError:
return [None] * total_fits
2 changes: 0 additions & 2 deletions autogalaxy/analysis/analysis/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class Analysis(af.Analysis):
def __init__(
self,
cosmology: LensingCosmology = None,
preloads: aa.Preloads = None,
use_jax: bool = True,
**kwargs,
):
Expand All @@ -39,7 +38,6 @@ def __init__(
from autogalaxy.cosmology.model import Planck15

self.cosmology = cosmology or Planck15()
self.preloads = preloads

super().__init__(use_jax=use_jax, **kwargs)

Expand Down
2 changes: 0 additions & 2 deletions autogalaxy/analysis/analysis/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def __init__(
adapt_images: Optional[AdaptImages] = None,
cosmology: LensingCosmology = None,
settings: aa.Settings = None,
preloads: aa.Preloads = None,
title_prefix: str = None,
use_jax: bool = True,
**kwargs,
Expand Down Expand Up @@ -54,7 +53,6 @@ def __init__(
"""
super().__init__(
cosmology=cosmology,
preloads=preloads,
use_jax=use_jax,
**kwargs,
)
Expand Down
8 changes: 0 additions & 8 deletions autogalaxy/galaxy/to_inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def __init__(
dataset: Optional[Union[aa.Imaging, aa.Interferometer, aa.DatasetInterface]],
adapt_images: Optional[AdaptImages] = None,
settings: aa.Settings = None,
preloads: aa.Preloads = None,
xp=np,
):
"""
Expand Down Expand Up @@ -77,8 +76,6 @@ def __init__(

self.settings = settings or aa.Settings()

self.preloads = preloads

self.use_jax = xp is not np

@property
Expand Down Expand Up @@ -202,7 +199,6 @@ def __init__(
galaxies: List[Galaxy],
adapt_images: Optional[AdaptImages] = None,
settings: aa.Settings = None,
preloads: aa.Preloads = None,
xp=np,
):
"""
Expand Down Expand Up @@ -245,7 +241,6 @@ def __init__(
dataset=dataset,
adapt_images=adapt_images,
settings=settings,
preloads=preloads,
xp=xp,
)

Expand Down Expand Up @@ -477,7 +472,6 @@ def mapper_from(
source_plane_data_grid=source_plane_data_grid,
source_plane_mesh_grid=source_plane_mesh_grid,
adapt_data=adapt_galaxy_image,
preloads=self.preloads,
xp=self._xp,
)

Expand All @@ -486,7 +480,6 @@ def mapper_from(
image_plane_mesh_grid=image_plane_mesh_grid,
regularization=regularization,
settings=self.settings,
preloads=self.preloads,
xp=self._xp,
)

Expand Down Expand Up @@ -569,7 +562,6 @@ def inversion(self) -> aa.AbstractInversion:
dataset=self.dataset,
linear_obj_list=self.linear_obj_list,
settings=self.settings,
preloads=self.preloads,
xp=self._xp,
)

Expand Down
4 changes: 0 additions & 4 deletions autogalaxy/imaging/fit_imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def __init__(
dataset_model: Optional[aa.DatasetModel] = None,
adapt_images: Optional[AdaptImages] = None,
settings: aa.Settings = None,
preloads: aa.Preloads = None,
xp=np,
):
"""
Expand Down Expand Up @@ -84,8 +83,6 @@ def __init__(
self.adapt_images = adapt_images
self.settings = settings or aa.Settings()

self.preloads = preloads

@property
def blurred_image(self) -> aa.Array2D:
"""
Expand Down Expand Up @@ -132,7 +129,6 @@ def galaxies_to_inversion(self) -> GalaxiesToInversion:
galaxies=self.galaxies,
adapt_images=self.adapt_images,
settings=self.settings,
preloads=self.preloads,
xp=self._xp,
)

Expand Down
5 changes: 0 additions & 5 deletions autogalaxy/imaging/model/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def __init__(
adapt_images: Optional[AdaptImages] = None,
cosmology: LensingCosmology = None,
settings: aa.Settings = None,
preloads: aa.Preloads = None,
title_prefix: str = None,
use_jax: bool = True,
):
Expand Down Expand Up @@ -61,7 +60,6 @@ def __init__(
adapt_images=adapt_images,
cosmology=cosmology,
settings=settings,
preloads=preloads,
title_prefix=title_prefix,
use_jax=use_jax,
)
Expand Down Expand Up @@ -121,8 +119,6 @@ def fit_from(self, instance: af.ModelInstance) -> FitImaging:
instance
An instance of the model that is being fitted to the data by this analysis (whose parameters have been set
via a non-linear search).
preload_overwrite
If a `Preload` object is input this is used instead of the preloads stored as an attribute in the analysis.

Returns
-------
Expand All @@ -144,7 +140,6 @@ def fit_from(self, instance: af.ModelInstance) -> FitImaging:
dataset_model=dataset_model,
adapt_images=adapt_images,
settings=self.settings,
preloads=self.preloads,
xp=self._xp,
)

Expand Down
4 changes: 0 additions & 4 deletions autogalaxy/interferometer/fit_interferometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def __init__(
dataset_model: Optional[aa.DatasetModel] = None,
adapt_images: Optional[AdaptImages] = None,
settings: aa.Settings = None,
preloads: aa.Preloads = None,
xp=np,
):
"""
Expand Down Expand Up @@ -78,8 +77,6 @@ def __init__(
self.adapt_images = adapt_images
self.settings = settings or aa.Settings()

self.preloads = preloads

@property
def profile_visibilities(self) -> aa.Visibilities:
"""
Expand Down Expand Up @@ -112,7 +109,6 @@ def galaxies_to_inversion(self) -> GalaxiesToInversion:
galaxies=self.galaxies,
adapt_images=self.adapt_images,
settings=self.settings,
preloads=self.preloads,
xp=self._xp,
)

Expand Down
5 changes: 0 additions & 5 deletions autogalaxy/interferometer/model/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def __init__(
adapt_images: Optional[AdaptImages] = None,
cosmology: LensingCosmology = None,
settings: aa.Settings = None,
preloads: aa.Preloads = None,
title_prefix: str = None,
use_jax: bool = True,
):
Expand Down Expand Up @@ -68,7 +67,6 @@ def __init__(
adapt_images=adapt_images,
cosmology=cosmology,
settings=settings,
preloads=preloads,
title_prefix=title_prefix,
use_jax=use_jax,
)
Expand Down Expand Up @@ -127,8 +125,6 @@ def fit_from(self, instance: af.ModelInstance) -> FitInterferometer:
instance
An instance of the model that is being fitted to the data by this analysis (whose parameters have been set
via a non-linear search).
preload_overwrite
If a `Preload` object is input this is used instead of the preloads stored as an attribute in the analysis.

Returns
-------
Expand All @@ -146,7 +142,6 @@ def fit_from(self, instance: af.ModelInstance) -> FitInterferometer:
galaxies=galaxies,
adapt_images=adapt_images,
settings=self.settings,
preloads=self.preloads,
xp=self._xp,
)

Expand Down
2 changes: 1 addition & 1 deletion test_autogalaxy/galaxy/test_galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ def test__output_to_and_load_from_json():
light=ag.lp.Sersic(intensity=1.0),
mass=ag.mp.Isothermal(einstein_radius=1.0),
pixelization=ag.Pixelization(
mesh=ag.mesh.Delaunay(),
mesh=ag.mesh.Delaunay(pixels=9),
regularization=ag.reg.Constant(),
),
)
Expand Down
Loading