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
5 changes: 5 additions & 0 deletions autolens/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
from . import util

from autoconf import conf
from autoconf.fitsable import ndarray_via_hdu_from
from autoconf.fitsable import ndarray_via_fits_from
from autoconf.fitsable import header_obj_from
from autoconf.fitsable import output_to_fits
from autoconf.fitsable import hdu_list_for_output_from

conf.instance.register(__file__)

Expand Down
2 changes: 1 addition & 1 deletion autolens/aggregator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
from autolens.aggregator.subplot import SubplotFit as subplot_fit
from autolens.aggregator.subplot import SubplotFitLog10 as subplot_fit_log10
from autolens.aggregator.subplot import FITSTracer as fits_tracer
from autolens.aggregator.subplot import FITSFit as fits_fits
from autolens.aggregator.subplot import FITSFit as fits_fit
84 changes: 44 additions & 40 deletions autolens/aggregator/fit_imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ def _fit_imaging_from(
settings_inversion: aa.SettingsInversion = None,
) -> List[FitImaging]:
"""
Returns a list of `FitImaging` object from a `PyAutoFit` sqlite database `Fit` object.
Returns a list of `FitImaging` object from a `PyAutoFit` loaded directory `Fit` or sqlite database `Fit` object.

The results of a model-fit can be stored in a sqlite database, including the following attributes of the fit:
The results of a model-fit can be loaded from hard-disk or stored in a sqlite database, including the following
attributes of the fit:

- 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 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`).

Each individual attribute can be loaded from the database via the `fit.value()` method.
Expand All @@ -41,7 +42,8 @@ def _fit_imaging_from(
Parameters
----------
fit
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry in a sqlite database.
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry which has been loaded from
an output directory or from an sqlite database..
instance
A manual instance that overwrites the max log likelihood instance in fit (e.g. for drawing the instance
randomly from the PDF).
Expand Down Expand Up @@ -87,41 +89,42 @@ def __init__(
settings_inversion: Optional[aa.SettingsInversion] = None,
):
"""
Interfaces with an `PyAutoFit` aggregator object to create instances of `FitImaging` objects from the results
of a model-fit.

The results of a model-fit can be stored in a sqlite database, including the following attributes of the fit:

- 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 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
can load them all at once and create an `FitImaging` object via the `_fit_imaging_from` method.

This class's methods returns generators which create the instances of the `FitImaging` objects. This ensures
that large sets of results can be efficiently loaded from the hard-disk and do not require storing all
`FitImaging` instances in the memory at once.

For example, if the `aggregator` contains 3 model-fits, this class can be used to create a generator which
creates instances of the corresponding 3 `FitImaging` objects.

If multiple `FitImaging` objects were fitted simultaneously via analysis summing, the `fit.child_values()` method
is instead used to load lists of the data, noise-map, PSF and mask and combine them into a list of
`FitImaging` objects.

This can be done manually, but this object provides a more concise API.

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.
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.
Interfaces with an `PyAutoFit` aggregator object to create instances of `FitImaging` objects from the results
of a model-fit.

The results of a model-fit can be loaded from hard-disk or stored in a sqlite database, including the following
attributes of the fit:

- 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 `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.

This class's methods returns generators which create the instances of the `FitImaging` objects. This ensures
that large sets of results can be efficiently loaded from the hard-disk and do not require storing all
`FitImaging` instances in the memory at once.

For example, if the `aggregator` contains 3 model-fits, this class can be used to create a generator which
creates instances of the corresponding 3 `FitImaging` objects.

If multiple `FitImaging` objects were fitted simultaneously via analysis summing, the `fit.child_values()` method
is instead used to load lists of the data, noise-map, PSF and mask and combine them into a list of
`FitImaging` objects.

This can be done manually, but this object provides a more concise API.

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.
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.
"""
super().__init__(aggregator=aggregator)

Expand All @@ -138,7 +141,8 @@ def object_via_gen_from(
Parameters
----------
fit
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry in a sqlite database.
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry which has been loaded from
an output directory or from an sqlite database..
instance
A manual instance that overwrites the max log likelihood instance in fit (e.g. for drawing the instance
randomly from the PDF).
Expand Down
64 changes: 32 additions & 32 deletions autolens/aggregator/fit_interferometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
def _fit_interferometer_from(
fit: af.Fit,
instance: Optional[af.ModelInstance] = None,
real_space_mask: Optional[aa.Mask2D] = None,
settings_inversion: aa.SettingsInversion = None,
) -> List[FitInterferometer]:
"""
Returns a list of `FitInterferometer` objects from a `PyAutoFit` sqlite database `Fit` object.
Returns a list of `FitInterferometer` objects from a `PyAutoFit` loaded directory `Fit` or sqlite database `Fit` object.

The results of a model-fit can be stored in a sqlite database, including the following attributes of the fit:
The results of a model-fit can be loaded from hard-disk or stored in a sqlite database, including the following
attributes of the fit:

- 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`).
Expand All @@ -43,7 +43,8 @@ def _fit_interferometer_from(
Parameters
----------
fit
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry in a sqlite database.
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry which has been loaded from
an output directory or from an sqlite database..
instance
A manual instance that overwrites the max log likelihood instance in fit (e.g. for drawing the instance
randomly from the PDF).
Expand All @@ -52,7 +53,6 @@ def _fit_interferometer_from(
"""
dataset_list = _interferometer_from(
fit=fit,
real_space_mask=real_space_mask,
)
tracer_list = _tracer_from(fit=fit, instance=instance)
dataset_model_list = _dataset_model_from(fit=fit, instance=instance)
Expand Down Expand Up @@ -87,45 +87,44 @@ def __init__(
self,
aggregator: af.Aggregator,
settings_inversion: Optional[aa.SettingsInversion] = None,
real_space_mask: Optional[aa.Mask2D] = None,
):
"""
Interfaces with an `PyAutoFit` aggregator object to create instances of `FitInterferometer` objects from the
results of a model-fit.
Interfaces with an `PyAutoFit` aggregator object to create instances of `FitInterferometer` objects from the
results of a model-fit.

The results of a model-fit can be stored in a sqlite database, including the following attributes of the fit:
The results of a model-fit can be loaded from hard-disk or stored in a sqlite database, including the following
attributes of the fit:

- 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 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 `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.
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.

This class's methods returns generators which create the instances of the `FitInterferometer` objects. This ensures
that large sets of results can be efficiently loaded from the hard-disk and do not require storing all
`FitInterferometer` instances in the memory at once.
This class's methods returns generators which create the instances of the `FitInterferometer` objects. This ensures
that large sets of results can be efficiently loaded from the hard-disk and do not require storing all
`FitInterferometer` instances in the memory at once.

For example, if the `aggregator` contains 3 model-fits, this class can be used to create a generator which
creates instances of the corresponding 3 `FitInterferometer` objects.
For example, if the `aggregator` contains 3 model-fits, this class can be used to create a generator which
creates instances of the corresponding 3 `FitInterferometer` objects.

This can be done manually, but this object provides a more concise API.
This can be done manually, but this object provides a more concise API.

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.
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.
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.
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.
"""
super().__init__(aggregator=aggregator)

self.settings_inversion = settings_inversion
self.real_space_mask = real_space_mask

def object_via_gen_from(
self, fit, instance: Optional[af.ModelInstance] = None
Expand All @@ -138,7 +137,8 @@ def object_via_gen_from(
Parameters
----------
fit
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry in a sqlite database.
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry which has been loaded from
an output directory or from an sqlite database..
instance
A manual instance that overwrites the max log likelihood instance in fit (e.g. for drawing the instance
randomly from the PDF).
Expand Down
14 changes: 9 additions & 5 deletions autolens/aggregator/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ def _tracer_from(
fit: af.Fit, instance: Optional[af.ModelInstance] = None
) -> List[Tracer]:
"""
Returns a list of `Tracer` objects from a `PyAutoFit` sqlite database `Fit` object.
Returns a list of `Tracer` objects from a `PyAutoFit` loaded directory `Fit` or sqlite database `Fit` object.

The results of a model-fit can be stored in a sqlite database, including the following attributes of the fit:
The results of a model-fit can be loaded from hard-disk or stored in a sqlite database, including the following
attributes of the fit:

- The model and its best fit parameters (e.g. `model.json`).
- The adapt images associated with adaptive galaxy features (`adapt` folder).
Expand All @@ -31,7 +32,8 @@ def _tracer_from(
Parameters
----------
fit
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry in a sqlite database.
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry which has been loaded from
an output directory or from an sqlite database..
instance
A manual instance that overwrites the max log likelihood instance in fit (e.g. for drawing the instance
randomly from the PDF).
Expand Down Expand Up @@ -79,7 +81,8 @@ class TracerAgg(af.AggBase):
Interfaces with an `PyAutoFit` aggregator object to create instances of `Tracer` objects from the results
of a model-fit.

The results of a model-fit can be stored in a sqlite database, including the following attributes of the fit:
The results of a model-fit can be loaded from hard-disk or stored in a sqlite database, including the following
attributes of the fit:

- The model and its best fit parameters (e.g. `model.json`).
- The adapt images associated with adaptive galaxy features (`adapt` folder).
Expand Down Expand Up @@ -117,7 +120,8 @@ def object_via_gen_from(
Parameters
----------
fit
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry in a sqlite database.
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry which has been loaded from
an output directory or from an sqlite database..
galaxies
A list of galaxies corresponding to a sample of a non-linear search and model-fit.
"""
Expand Down
27 changes: 14 additions & 13 deletions autolens/analysis/plotter_interface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from os import path
from autoconf.fitsable import hdu_list_for_output_from

import autoarray as aa
import autogalaxy.plot as aplt
Expand Down Expand Up @@ -65,25 +65,26 @@ def should_plot(name):
tracer_plotter.subplot_galaxies_images()

if should_plot("fits_tracer"):
number_plots = 4

multi_plotter = aplt.MultiFigurePlotter(
plotter_list=[tracer_plotter] * number_plots
)

multi_plotter.output_to_fits(
func_name_list=["figures_2d"] * number_plots,
figure_name_list=[
hdu_list = hdu_list_for_output_from(
values_list=[
grid.mask.astype("float"),
tracer.convergence_2d_from(grid=grid).native,
tracer.potential_2d_from(grid=grid).native,
tracer.deflections_yx_2d_from(grid=grid).native[:, :, 0],
tracer.deflections_yx_2d_from(grid=grid).native[:, :, 1],
Comment on lines +73 to +74
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is it worth assigning

deflections = tracer.deflections_yx_2d_from(grid=grid)

?

],
ext_name_list=[
"mask",
"convergence",
"potential",
"deflections_y",
"deflections_x",
],
tag_list=["convergence", "potential", "deflections_y", "deflections_x"],
filename="tracer",
remove_fits_first=True,
header_dict=grid.mask.header_dict,
)

hdu_list.writeto(self.image_path / "tracer.fits", overwrite=True)

def image_with_positions(self, image: aa.Array2D, positions: aa.Grid2DIrregular):
"""
Visualizes the positions of a model-fit, where these positions are used to resample lens models where
Expand Down
Loading
Loading