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
33 changes: 16 additions & 17 deletions autogalaxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,17 @@
from autoarray.dataset.imaging.dataset import Imaging # noqa
from autoarray.dataset.interferometer.dataset import Interferometer # noqa
from autoarray.dataset.dataset_model import DatasetModel
from autoarray.inversion.pixelization import mesh # noqa
from autoarray.inversion.mesh import mesh # noqa
from autoarray.inversion import regularization as reg # noqa
from autoarray.inversion.pixelization import image_mesh
from autoarray.inversion.pixelization.mappers.abstract import AbstractMapper # noqa
from autoarray.inversion.inversion.settings import SettingsInversion # noqa
from autoarray.inversion.mesh import image_mesh
from autoarray.inversion.mappers.abstract import Mapper # noqa
from autoarray.settings import Settings # noqa
from autoarray.inversion.inversion.factory import inversion_from as Inversion # noqa
from autoarray.inversion.pixelization.image_mesh.abstract import AbstractImageMesh
from autoarray.inversion.pixelization.mesh.abstract import AbstractMesh
from autoarray.inversion.mesh.image_mesh.abstract import AbstractImageMesh
from autoarray.inversion.mesh.mesh.abstract import AbstractMesh
from autoarray.inversion.regularization.abstract import AbstractRegularization
from autoarray.inversion.pixelization.pixelization import Pixelization # noqa
from autoarray.inversion.pixelization.mappers.abstract import AbstractMapper
from autoarray.inversion.pixelization.mappers.mapper_grids import MapperGrids # noqa
from autoarray.inversion.pixelization.mappers.factory import (
mapper_from as Mapper,
) # noqa
from autoarray.inversion.pixelization.border_relocator import BorderRelocator
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
Expand All @@ -43,18 +38,22 @@
from autoarray.structures.grids.uniform_2d import Grid2D # noqa
from autoarray.structures.grids.irregular_2d import Grid2DIrregular # noqa
from autoarray.operators.over_sampling.over_sampler import OverSampler # noqa
from autoarray.structures.mesh.rectangular_2d import Mesh2DRectangular # noqa
from autoarray.structures.mesh.rectangular_2d_uniform import (
Mesh2DRectangularUniform,
from autoarray.inversion.mesh.interpolator.rectangular import (
InterpolatorRectangular,
) # noqa
from autoarray.inversion.mesh.interpolator.delaunay import (
InterpolatorDelaunay,
) # noqa
from autoarray.structures.mesh.delaunay_2d import Mesh2DDelaunay # noqa
from autoarray.structures.vectors.uniform import VectorYX2D # noqa
from autoarray.structures.vectors.irregular import VectorYX2DIrregular # noqa
from autoarray.layout.region import Region1D # noqa
from autoarray.layout.region import Region2D # noqa
from autoarray.structures.arrays.kernel_2d import Kernel2D # noqa
from autoarray.structures.visibilities import Visibilities # noqa
from autoarray.structures.visibilities import VisibilitiesNoiseMap # noqa
from autoarray.inversion.mesh.mesh_geometry.rectangular import (
rectangular_edge_pixel_list_from,
)

from .analysis import model_util
from .analysis.adapt_images.adapt_images import AdaptImages
Expand Down
8 changes: 4 additions & 4 deletions autogalaxy/abstract_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


class AbstractFitInversion:
def __init__(self, model_obj, settings_inversion: aa.SettingsInversion, xp=np):
def __init__(self, model_obj, settings: aa.Settings, xp=np):
"""
An abstract fit object which fits to datasets (e.g. imaging, interferometer) inherit from.

Expand All @@ -28,11 +28,11 @@ def __init__(self, model_obj, settings_inversion: aa.SettingsInversion, xp=np):
The object which contains the model components (e.g. light profiles, galaxies, etc) which are used to
create the model-data that fits the data. In PyAutoGalaxy this is a list of galaxies and PyAutoLens
it is a `Tracer`.
settings_inversion
settings
Settings controlling how an inversion is fitted for example which linear algebra formalism is used.
"""
self.model_obj = model_obj
self.settings_inversion = settings_inversion
self.settings = settings or aa.Settings()
self.use_jax = xp is not np
Comment on lines 18 to 36
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AbstractFitInversion.__init__ accepts settings but the implementation allows None (settings or aa.Settings()). The type annotation should be Optional[aa.Settings] (and ideally the signature should default settings to None) to match actual usage from callers like FitImaging / FitInterferometer.

Copilot uses AI. Check for mistakes.

@property
Expand Down Expand Up @@ -75,7 +75,7 @@ def perform_inversion(self) -> bool:
def sparse_operator(self) -> Optional[aa.ImagingSparseOperator]:
"""
Only call the `sparse_operator` property of a dataset used to perform efficient linear algebra calculations if
the SettingsInversion()` object has `use_sparse_operator=True`, to avoid unnecessary computation.
the Settings()` object has `use_sparse_operator=True`, to avoid unnecessary computation.

Returns
-------
Expand Down
2 changes: 1 addition & 1 deletion autogalaxy/aggregator/ellipse/fit_ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _fit_ellipse_from(
is instead used to load lists of the data, noise-map, PSF and mask and combine them into a list of
`FitEllipse` objects.

The settings of an inversion can be overwritten by inputting a `settings_inversion` object, for example
The settings of an inversion can be overwritten by inputting a `settings` object, for example
if you want to use a grid with a different inversion solver.

Comment on lines +36 to 38
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring says inversion settings can be overwritten by passing a settings object, but _fit_ellipse_from does not accept a settings parameter. Either remove this sentence or add a settings parameter (if ellipse fitting actually supports it).

Suggested change
The settings of an inversion can be overwritten by inputting a `settings` object, for example
if you want to use a grid with a different inversion solver.

Copilot uses AI. Check for mistakes.
Parameters
Expand Down
30 changes: 15 additions & 15 deletions autogalaxy/aggregator/imaging/fit_imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
def _fit_imaging_from(
fit: af.Fit,
instance: Optional[af.ModelInstance] = None,
settings_inversion: aa.SettingsInversion = None,
settings: aa.Settings = None,
) -> List[FitImaging]:
"""
Returns a list of `FitImaging` objects from a `PyAutoFit` loaded directory `Fit` or sqlite database `Fit` object.
Expand All @@ -26,7 +26,7 @@ def _fit_imaging_from(

- The imaging data, noise-map, PSF and settings as .fits files (e.g. `dataset/data.fits`).
- The mask used to mask the `Imaging` data structure in the fit (`dataset.fits[hdu=0]`).
- The settings of inversions used by the fit (`dataset/settings_inversion.json`).
- The settings of inversions used by the fit (`dataset/settings.json`).

Each individual attribute can be loaded from the database via the `fit.value()` method.

Expand All @@ -37,7 +37,7 @@ def _fit_imaging_from(
is instead used to load lists of the data, noise-map, PSF and mask and combine them into a list of
`FitImaging` objects.

The settings of an inversion can be overwritten by inputting a `settings_inversion` object, for example
The settings of an inversion can be overwritten by inputting a `settings` object, for example
if you want to use a grid with a different inversion solver.

Parameters
Expand All @@ -48,8 +48,8 @@ def _fit_imaging_from(
instance
A manual instance that overwrites the max log likelihood instance in fit (e.g. for drawing the instance
randomly from the PDF).
settings_inversion
Optionally overwrite the `SettingsInversion` of the `Inversion` object that is created from the fit.
settings
Optionally overwrite the `Settings` of the `Inversion` object that is created from the fit.
"""

from autogalaxy.imaging.fit_imaging import FitImaging
Expand All @@ -62,7 +62,7 @@ def _fit_imaging_from(

adapt_images_list = agg_util.adapt_images_from(fit=fit)

settings_inversion = settings_inversion or fit.value(name="settings_inversion")
settings = settings or fit.value(name="settings")

Comment on lines +65 to 66
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This aggregator now only loads settings via fit.value(name="settings"). This will likely break loading older fit outputs that saved settings_inversion (pre-refactor). Consider falling back to fit.value(name="settings_inversion") when settings is missing, to preserve backwards compatibility when inspecting existing databases / output directories.

Suggested change
settings = settings or fit.value(name="settings")
if settings is None:
try:
settings = fit.value(name="settings")
except (KeyError, AttributeError):
settings = None
if settings is None:
try:
settings = fit.value(name="settings_inversion")
except (KeyError, AttributeError):
settings = None

Copilot uses AI. Check for mistakes.
fit_dataset_list = []

Expand All @@ -79,7 +79,7 @@ def _fit_imaging_from(
galaxies=galaxies,
dataset_model=dataset_model,
adapt_images=adapt_images,
settings_inversion=settings_inversion,
settings=settings,
)
)

Expand All @@ -90,7 +90,7 @@ class FitImagingAgg(af.AggBase):
def __init__(
self,
aggregator: af.Aggregator,
settings_inversion: Optional[aa.SettingsInversion] = None,
settings: Optional[aa.Settings] = None,
):
"""
Interfaces with an `PyAutoFit` aggregator object to create instances of `FitImaging` objects from the results
Expand All @@ -101,7 +101,7 @@ def __init__(

- The imaging data, noise-map, PSF and settings as .fits files (e.g. `dataset/data.fits`).
- The mask used to mask the `Imaging` data structure in the fit (`dataset.fits[hdu=0]`).
- The settings of inversions used by the fit (`dataset/settings_inversion.json`).
- The settings of inversions used by the fit (`dataset/settings.json`).

The `aggregator` contains the path to each of these files, and they can be loaded individually. This class
can load them all at once and create an `FitImaging` object via the `_fit_imaging_from` method.
Expand All @@ -123,19 +123,19 @@ def __init__(
----------
aggregator
A `PyAutoFit` aggregator object which can load the results of model-fits.
settings_inversion
Optionally overwrite the `SettingsInversion` of the `Inversion` object that is created from the fit.
settings
Optionally overwrite the `Settings` of the `Inversion` object that is created from the fit.

Parameters
----------
aggregator
A `PyAutoFit` aggregator object which can load the results of model-fits.
settings_inversion
Optionally overwrite the `SettingsInversion` of the `Inversion` object that is created from the fit.
settings
Optionally overwrite the `Settings` of the `Inversion` object that is created from the fit.
"""
super().__init__(aggregator=aggregator)

self.settings_inversion = settings_inversion
self.settings = settings

def object_via_gen_from(
self, fit, instance: Optional[af.ModelInstance] = None
Expand All @@ -157,5 +157,5 @@ def object_via_gen_from(
return _fit_imaging_from(
fit=fit,
instance=instance,
settings_inversion=self.settings_inversion,
settings=self.settings,
)
30 changes: 15 additions & 15 deletions autogalaxy/aggregator/interferometer/fit_interferometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
def _fit_interferometer_from(
fit: af.Fit,
instance: Optional[af.ModelInstance] = None,
settings_inversion: aa.SettingsInversion = None,
settings: aa.Settings = None,
) -> List[FitInterferometer]:
"""
Returns a list of `FitInterferometer` objects from a `PyAutoFit` loaded directory `Fit` or sqlite database `Fit` object.
Expand All @@ -26,7 +26,7 @@ def _fit_interferometer_from(

- The interferometer data, noise-map, uv-wavelengths and settings as .fits files (e.g. `dataset/data.fits`).
- The real space mask defining the grid of the interferometer for the FFT (`dataset/real_space_mask.fits`).
- The settings of inversions used by the fit (`dataset/settings_inversion.json`).
- The settings of inversions used by the fit (`dataset/settings.json`).

Each individual attribute can be loaded from the database via the `fit.value()` method.

Expand All @@ -38,7 +38,7 @@ def _fit_interferometer_from(
method is instead used to load lists of the data, noise-map, PSF and mask and combine them into a list of
`FitInterferometer` objects.

The settings of an inversion can be overwritten by inputting a `settings_inversion` object, for
The settings of an inversion can be overwritten by inputting a `settings` object, for
example if you want to use a grid with a different inversion solver.

Parameters
Expand All @@ -49,8 +49,8 @@ def _fit_interferometer_from(
instance
A manual instance that overwrites the max log likelihood instance in fit (e.g. for drawing the instance
randomly from the PDF).
settings_inversion
Optionally overwrite the `SettingsInversion` of the `Inversion` object that is created from the fit.
settings
Optionally overwrite the `Settings` of the `Inversion` object that is created from the fit.
"""
from autogalaxy.interferometer.fit_interferometer import FitInterferometer

Expand All @@ -64,7 +64,7 @@ def _fit_interferometer_from(

adapt_images_list = agg_util.adapt_images_from(fit=fit)

settings_inversion = settings_inversion or fit.value(name="settings_inversion")
settings = settings or fit.value(name="settings")

Comment on lines +67 to 68
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This aggregator now only loads settings via fit.value(name="settings"). This will likely break loading older fit outputs that saved settings_inversion (pre-refactor). Consider falling back to fit.value(name="settings_inversion") when settings is missing, to preserve backwards compatibility when inspecting existing databases / output directories.

Suggested change
settings = settings or fit.value(name="settings")
if settings is None:
try:
settings = fit.value(name="settings")
except (KeyError, AttributeError):
settings = None
if settings is None:
try:
settings = fit.value(name="settings_inversion")
except (KeyError, AttributeError):
settings = None

Copilot uses AI. Check for mistakes.
fit_dataset_list = []

Expand All @@ -81,7 +81,7 @@ def _fit_interferometer_from(
galaxies=galaxies,
dataset_model=dataset_model,
adapt_images=adapt_images,
settings_inversion=settings_inversion,
settings=settings,
)
)

Expand All @@ -92,7 +92,7 @@ class FitInterferometerAgg(af.AggBase):
def __init__(
self,
aggregator: af.Aggregator,
settings_inversion: Optional[aa.SettingsInversion] = None,
settings: Optional[aa.Settings] = None,
):
"""
Interfaces with an `PyAutoFit` aggregator object to create instances of `FitInterferometer` objects from the
Expand All @@ -103,7 +103,7 @@ def __init__(

- The interferometer data, noise-map, uv-wavelengths and settings as .fits files (e.g. `dataset/data.fits`).
- The real space mask defining the grid of the interferometer for the FFT (`dataset/real_space_mask.fits`).
- The settings of inversions used by the fit (`dataset/settings_inversion.json`).
- The settings of inversions used by the fit (`dataset/settings.json`).

The `aggregator` contains the path to each of these files, and they can be loaded individually. This class
can load them all at once and create an `FitInterferometer` object via the `_fit_interferometer_from` method.
Expand All @@ -125,19 +125,19 @@ def __init__(
----------
aggregator
A `PyAutoFit` aggregator object which can load the results of model-fits.
settings_inversion
Optionally overwrite the `SettingsInversion` of the `Inversion` object that is created from the fit.
settings
Optionally overwrite the `Settings` of the `Inversion` object that is created from the fit.

Parameters
----------
aggregator
A `PyAutoFit` aggregator object which can load the results of model-fits.
settings_inversion
Optionally overwrite the `SettingsInversion` of the `Inversion` object that is created from the fit.
settings
Optionally overwrite the `Settings` of the `Inversion` object that is created from the fit.
"""
super().__init__(aggregator=aggregator)

self.settings_inversion = settings_inversion
self.settings = settings

def object_via_gen_from(
self, fit, instance: Optional[af.ModelInstance] = None
Expand All @@ -159,5 +159,5 @@ def object_via_gen_from(
return _fit_interferometer_from(
fit=fit,
instance=instance,
settings_inversion=self.settings_inversion,
settings=self.settings,
)
10 changes: 5 additions & 5 deletions autogalaxy/analysis/analysis/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(
dataset: Union[aa.Imaging, aa.Interferometer],
adapt_images: Optional[AdaptImages] = None,
cosmology: LensingCosmology = None,
settings_inversion: aa.SettingsInversion = None,
settings: aa.Settings = None,
preloads: aa.Preloads = None,
title_prefix: str = None,
use_jax: bool = True,
Expand All @@ -45,7 +45,7 @@ def __init__(
used by certain classes for adapting the analysis to the properties of the dataset.
cosmology
The Cosmology assumed for this analysis.
settings_inversion
settings
Settings controlling how an inversion is fitted during the model-fit, for example which linear algebra
formalism is used.
title_prefix
Expand All @@ -62,7 +62,7 @@ def __init__(
self.dataset = dataset
self.adapt_images = adapt_images

self.settings_inversion = settings_inversion or aa.SettingsInversion()
self.settings = settings or aa.Settings()

self.title_prefix = title_prefix

Expand Down Expand Up @@ -138,8 +138,8 @@ def save_attributes(self, paths: af.DirectoryPaths):
visualization, and the pickled objects used by the aggregator output by this function.
"""
paths.save_json(
name="settings_inversion",
object_dict=to_dict(self.settings_inversion),
name="settings",
object_dict=to_dict(self.settings),
)
paths.save_json(
name="cosmology",
Expand Down
8 changes: 4 additions & 4 deletions autogalaxy/analysis/plotter_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def should_plot(name):
)

if should_plot("subplot_inversion"):
mapper_list = inversion.cls_list_from(cls=aa.AbstractMapper)
mapper_list = inversion.cls_list_from(cls=aa.Mapper)

for i in range(len(mapper_list)):
suffix = "" if len(mapper_list) == 1 else f"_{i}"
Expand All @@ -224,11 +224,11 @@ def should_plot(name):
)

if should_plot("csv_reconstruction"):
mapper_list = inversion.cls_list_from(cls=aa.AbstractMapper)
mapper_list = inversion.cls_list_from(cls=aa.Mapper)

for i, mapper in enumerate(mapper_list):
y = mapper.mapper_grids.source_plane_mesh_grid[:, 0]
x = mapper.mapper_grids.source_plane_mesh_grid[:, 1]
y = mapper.source_plane_mesh_grid[:, 0]
x = mapper.source_plane_mesh_grid[:, 1]
reconstruction = inversion.reconstruction_dict[mapper]
noise_map = inversion.reconstruction_noise_map_dict[mapper]

Expand Down
2 changes: 1 addition & 1 deletion autogalaxy/config/priors/mass/dark/cnfw_mcr_scatter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ cNFWMCRScatterLudlowSph:
limits:
lower: 0.0
upper: inf
scatter:
scatter_sigma:
type: Gaussian
mean: 0.0
sigma: 3.0
Expand Down
2 changes: 1 addition & 1 deletion autogalaxy/config/priors/mass/dark/nfw_mcr_scatter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ NFWMCRScatterLudlowSph:
limits:
lower: 0.0
upper: inf
scatter:
scatter_sigma:
type: Gaussian
mean: 0.0
sigma: 3.0
Expand Down
2 changes: 1 addition & 1 deletion autogalaxy/config/priors/mass/dark/nfw_truncated_mcr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ NFWTruncatedMCRScatterLudlowSph:
limits:
lower: 0.0
upper: inf
scatter:
scatter_sigma:
type: Gaussian
mean: 0.0
sigma: 3.0
Expand Down
Loading
Loading