Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/adapt via fit #245

Merged
merged 22 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
3 changes: 1 addition & 2 deletions autolens/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from autoarray.inversion.pixelization.mesh.abstract import AbstractMesh
from autoarray.inversion.regularization.abstract import AbstractRegularization
from autoarray.inversion.pixelization.pixelization import Pixelization
from autoarray.inversion.pixelization.settings import SettingsPixelization
from autoarray.inversion.inversion.settings import SettingsInversion
from autoarray.inversion.inversion.factory import inversion_from as Inversion
from autoarray.inversion.inversion.factory import (
Expand Down Expand Up @@ -48,6 +47,7 @@
from autoarray.structures.visibilities import VisibilitiesNoiseMap

from autogalaxy import cosmology as cosmo
from autogalaxy.analysis.adapt_images import AdaptImages
from autogalaxy.gui.clicker import Clicker
from autogalaxy.gui.scribbler import Scribbler
from autogalaxy.galaxy.galaxy import Galaxy
Expand Down Expand Up @@ -83,7 +83,6 @@
from . import plot
from . import aggregator as agg
from .lens import subhalo
from .analysis.settings import SettingsLens
from .lens.ray_tracing import Tracer
from .lens.to_inversion import TracerToInversion
from .analysis.positions import PositionsLHResample
Expand Down
21 changes: 5 additions & 16 deletions autolens/aggregator/fit_imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def _fit_imaging_from(
fit: af.Fit,
galaxies: List[ag.Galaxy],
settings_dataset: aa.SettingsImaging = None,
settings_pixelization: aa.SettingsPixelization = None,
settings_inversion: aa.SettingsInversion = None,
use_preloaded_grid: bool = True,
) -> List[FitImaging]:
Expand All @@ -30,7 +29,6 @@ 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/mask.fits`).
- The settings of pixelization used by the fit (`dataset/settings_pixelization.json`).
- The settings of inversions used by the fit (`dataset/settings_inversion.json`).

Each individual attribute can be loaded from the database via the `fit.value()` method.
Expand All @@ -53,8 +51,6 @@ def _fit_imaging_from(
A list of galaxies corresponding to a sample of a non-linear search and model-fit.
settings_dataset
Optionally overwrite the `SettingsImaging` of the `Imaging` object that is created from the fit.
settings_pixelization
Optionally overwrite the `SettingsPixelization` of the `Pixelization` object that is created from the fit.
settings_inversion
Optionally overwrite the `SettingsInversion` of the `Inversion` object that is created from the fit.
use_preloaded_grid
Expand All @@ -67,9 +63,8 @@ def _fit_imaging_from(

tracer_list = _tracer_from(fit=fit, galaxies=galaxies)

settings_pixelization = settings_pixelization or fit.value(
name="settings_pixelization"
)
adapt_images_list = agg_util.adapt_images_from(fit=fit)

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

mesh_grids_of_planes_list = agg_util.mesh_grids_of_planes_list_from(
Expand All @@ -78,8 +73,8 @@ def _fit_imaging_from(

fit_dataset_list = []

for dataset, tracer, mesh_grids_of_planes in zip(
dataset_list, tracer_list, mesh_grids_of_planes_list
for dataset, tracer, adapt_images, mesh_grids_of_planes in zip(
dataset_list, tracer_list, adapt_images_list, mesh_grids_of_planes_list
):
preloads = agg_util.preloads_from(
preloads_cls=Preloads,
Expand All @@ -92,7 +87,7 @@ def _fit_imaging_from(
FitImaging(
dataset=dataset,
tracer=tracer,
settings_pixelization=settings_pixelization,
adapt_images=adapt_images,
settings_inversion=settings_inversion,
preloads=preloads,
)
Expand All @@ -106,7 +101,6 @@ def __init__(
self,
aggregator: af.Aggregator,
settings_dataset: Optional[aa.SettingsImaging] = None,
settings_pixelization: Optional[aa.SettingsPixelization] = None,
settings_inversion: Optional[aa.SettingsInversion] = None,
use_preloaded_grid: bool = True,
):
Expand All @@ -118,7 +112,6 @@ 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/mask.fits`).
- The settings of pixelization used by the fit (`dataset/settings_pixelization.json`).
- The settings of inversions used by the fit (`dataset/settings_inversion.json`).

The `aggregator` contains the path to each of these files, and they can be loaded individually. This class
Expand All @@ -143,8 +136,6 @@ def __init__(
A `PyAutoFit` aggregator object which can load the results of model-fits.
settings_dataset
Optionally overwrite the `SettingsImaging` of the `Imaging` object that is created from the fit.
settings_pixelization
Optionally overwrite the `SettingsPixelization` of the `Pixelization` object that is created from the fit.
settings_inversion
Optionally overwrite the `SettingsInversion` of the `Inversion` object that is created from the fit.
use_preloaded_grid
Expand All @@ -155,7 +146,6 @@ def __init__(
super().__init__(aggregator=aggregator)

self.settings_dataset = settings_dataset
self.settings_pixelization = settings_pixelization
self.settings_inversion = settings_inversion
self.use_preloaded_grid = use_preloaded_grid

Expand All @@ -176,7 +166,6 @@ def object_via_gen_from(self, fit, galaxies) -> List[FitImaging]:
fit=fit,
galaxies=galaxies,
settings_dataset=self.settings_dataset,
settings_pixelization=self.settings_pixelization,
settings_inversion=self.settings_inversion,
use_preloaded_grid=self.use_preloaded_grid,
)
21 changes: 5 additions & 16 deletions autolens/aggregator/fit_interferometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def _fit_interferometer_from(
galaxies: List[ag.Galaxy],
real_space_mask: Optional[aa.Mask2D] = None,
settings_dataset: aa.SettingsInterferometer = None,
settings_pixelization: aa.SettingsPixelization = None,
settings_inversion: aa.SettingsInversion = None,
use_preloaded_grid: bool = True,
) -> List[FitInterferometer]:
Expand All @@ -30,7 +29,6 @@ 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 pixelization used by the fit (`dataset/settings_pixelization.json`).
- The settings of inversions used by the fit (`dataset/settings_inversion.json`).

Each individual attribute can be loaded from the database via the `fit.value()` method.
Expand All @@ -54,8 +52,6 @@ def _fit_interferometer_from(
A list of galaxies corresponding to a sample of a non-linear search and model-fit.
settings_dataset
Optionally overwrite the `SettingsInterferometer` of the `Interferometer` object that is created from the fit.
settings_pixelization
Optionally overwrite the `SettingsPixelization` of the `Pixelization` object that is created from the fit.
settings_inversion
Optionally overwrite the `SettingsInversion` of the `Inversion` object that is created from the fit.
use_preloaded_grid
Expand All @@ -70,9 +66,8 @@ def _fit_interferometer_from(
)
tracer_list = _tracer_from(fit=fit, galaxies=galaxies)

settings_pixelization = settings_pixelization or fit.value(
name="settings_pixelization"
)
adapt_images_list = agg_util.adapt_images_from(fit=fit)

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

mesh_grids_of_planes_list = agg_util.mesh_grids_of_planes_list_from(
Expand All @@ -81,8 +76,8 @@ def _fit_interferometer_from(

fit_dataset_list = []

for dataset, tracer, mesh_grids_of_planes in zip(
dataset_list, tracer_list, mesh_grids_of_planes_list
for dataset, tracer, adapt_images, mesh_grids_of_planes in zip(
dataset_list, tracer_list, adapt_images_list, mesh_grids_of_planes_list
):
preloads = agg_util.preloads_from(
preloads_cls=Preloads,
Expand All @@ -95,7 +90,7 @@ def _fit_interferometer_from(
FitInterferometer(
dataset=dataset,
tracer=tracer,
settings_pixelization=settings_pixelization,
adapt_images=adapt_images,
settings_inversion=settings_inversion,
preloads=preloads,
)
Expand All @@ -109,7 +104,6 @@ def __init__(
self,
aggregator: af.Aggregator,
settings_dataset: Optional[aa.SettingsInterferometer] = None,
settings_pixelization: Optional[aa.SettingsPixelization] = None,
settings_inversion: Optional[aa.SettingsInversion] = None,
use_preloaded_grid: bool = True,
real_space_mask: Optional[aa.Mask2D] = None,
Expand All @@ -122,7 +116,6 @@ 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 pixelization used by the fit (`dataset/settings_pixelization.json`).
- The settings of inversions used by the fit (`dataset/settings_inversion.json`).

The `aggregator` contains the path to each of these files, and they can be loaded individually. This class
Expand All @@ -143,8 +136,6 @@ def __init__(
A `PyAutoFit` aggregator object which can load the results of model-fits.
settings_dataset
Optionally overwrite the `SettingsInterferometer` of the `Interferometer` object that is created from the fit.
settings_pixelization
Optionally overwrite the `SettingsPixelization` of the `Pixelization` object that is created from the fit.
settings_inversion
Optionally overwrite the `SettingsInversion` of the `Inversion` object that is created from the fit.
use_preloaded_grid
Expand All @@ -155,7 +146,6 @@ def __init__(
super().__init__(aggregator=aggregator)

self.settings_dataset = settings_dataset
self.settings_pixelization = settings_pixelization
self.settings_inversion = settings_inversion
self.use_preloaded_grid = use_preloaded_grid
self.real_space_mask = real_space_mask
Expand All @@ -177,7 +167,6 @@ def object_via_gen_from(self, fit, galaxies) -> FitInterferometer:
fit=fit,
galaxies=galaxies,
settings_dataset=self.settings_dataset,
settings_pixelization=self.settings_pixelization,
settings_inversion=self.settings_inversion,
use_preloaded_grid=self.use_preloaded_grid,
)
2 changes: 0 additions & 2 deletions autolens/aggregator/subhalo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def __init__(
self,
aggregator_grid_search: af.GridSearchAggregator,
settings_dataset: Optional[aa.SettingsImaging] = None,
settings_pixelization: Optional[aa.SettingsPixelization] = None,
settings_inversion: Optional[aa.SettingsInversion] = None,
use_preloaded_grid: bool = True,
):
Expand All @@ -22,7 +21,6 @@ def __init__(

self.aggregator_grid_search = aggregator_grid_search
self.settings_dataset = settings_dataset
self.settings_pixelization = settings_pixelization
self.settings_inversion = settings_inversion
self.use_preloaded_grid = use_preloaded_grid

Expand Down
4 changes: 1 addition & 3 deletions autolens/aggregator/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ def _tracer_from(fit: af.Fit, galaxies: List[ag.Galaxy]) -> List[Tracer]:
A list of galaxies corresponding to a sample of a non-linear search and model-fit.
"""

galaxies = agg_util.galaxies_with_adapt_images_from(fit=fit, galaxies=galaxies)

if len(fit.children) > 0:
logger.info(
"""
Using database for a fit with multiple summed Analysis objects.

Tracer objects do not fully support this yet (e.g. adapt images may not be set up correctly)
Tracer objects do not fully support this yet (e.g. model parameters which vary over analyses may be incorrect)
so proceed with caution!
"""
)
Expand Down
Loading
Loading