Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4b0ec39
dataset fits now output to datasset.fits file
Jammy2211 Mar 20, 2025
bc8aa3f
hdu_for_output now used in analysis
Jammy2211 Mar 20, 2025
54aaf2d
use hdu_list output in autoconf fitsable
Jammy2211 Mar 21, 2025
5f06073
interferometer now uses fitsable
Jammy2211 Mar 21, 2025
33959cf
add adapt image output
Jammy2211 Mar 21, 2025
4a2b8d4
imaging agg updated
Jammy2211 Mar 21, 2025
4acdbdb
aggregator interferometer fixed
Jammy2211 Mar 21, 2025
2aa1881
now working on adapt images
Jammy2211 Mar 21, 2025
1803580
pixel scale header uses mask property
Jammy2211 Mar 21, 2025
999179c
moved some aggregaotr loading to agg_util
Jammy2211 Mar 21, 2025
0c15d60
fix agg adapt images
Jammy2211 Mar 21, 2025
57404aa
update quantity
Jammy2211 Mar 21, 2025
9ccf85a
update ellipse analysis
Jammy2211 Mar 21, 2025
702945f
fix header loading
Jammy2211 Mar 21, 2025
fde289f
fix aggregator via IndexError Exception
Jammy2211 Mar 21, 2025
7ee041d
docs
Jammy2211 Mar 21, 2025
46f480d
update imaging plotter interface
Jammy2211 Mar 21, 2025
447b592
fgalaxy imafges
Jammy2211 Mar 21, 2025
9ea8bf7
update intererometer plotter interface
Jammy2211 Mar 21, 2025
825544b
move save attributes stuff to plotter interface
Jammy2211 Mar 21, 2025
20cc2d0
quantitiy refactor
Jammy2211 Mar 21, 2025
157bdb6
ellispe
Jammy2211 Mar 21, 2025
f149cc9
fix imaging aggregator tests
Jammy2211 Mar 24, 2025
a49314f
fixinterferometer
Jammy2211 Mar 24, 2025
b7edac8
fix aggregator ellipse
Jammy2211 Mar 24, 2025
4726e75
fix adapt image test
Jammy2211 Mar 24, 2025
677d195
missing files
Jammy2211 Mar 24, 2025
4d9af45
aggregator uses enum
Jammy2211 Apr 2, 2025
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 autogalaxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@
from .gui.scribbler import Scribbler

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
75 changes: 57 additions & 18 deletions autogalaxy/aggregator/agg_util.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,68 @@
from __future__ import annotations
from typing import List, Optional

from autoconf.fitsable import ndarray_via_hdu_from

import autofit as af
import autoarray as aa

from autoarray.mask.mask_2d import Mask2DKeys

from autogalaxy.analysis.adapt_images.adapt_images import AdaptImages


def mask_header_from(fit):
"""
Returns the mask, header and pixel scales of the `PyAutoFit` `Fit` object.

These quantities are commonly loaded during the aggregator interface therefore this method is used to
avoid code duplication.

Parameters
----------
fit
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.


Returns
-------
The mask, header and pixel scales of the `PyAutoFit` `Fit` object.
"""

header = aa.Header(header_sci_obj=fit.value(name="dataset")[0].header)
pixel_scales = (
header.header_sci_obj[Mask2DKeys.PIXSCAY.value],
header.header_sci_obj[Mask2DKeys.PIXSCAY.value],
)
origin = (
header.header_sci_obj[Mask2DKeys.ORIGINY.value],
header.header_sci_obj[Mask2DKeys.ORIGINX.value],
)
mask = aa.Mask2D(
mask=ndarray_via_hdu_from(fit.value(name="dataset")[0]),
pixel_scales=pixel_scales,
origin=origin,
)

return mask, header


def adapt_images_from(
fit: af.Fit,
) -> List[AdaptImages]:
"""
Updates adaptive images when loading the galaxies from a `PyAutoFit` sqlite database `Fit` object.
Updates adaptive images when loading the galaxies from a `PyAutoFit` loaded directory `Fit` or sqlite
database `Fit` object.

This function ensures that if adaptive features (e.g. an `Hilbert` image-mesh) are used in a model-fit,
they work when using the database to load and inspect the results of the model-fit.

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 All @@ -30,31 +73,26 @@ def adapt_images_from(

fit_list = [fit] if not fit.children else fit.children

if fit.value(name="adapt_images.adapt_images") is None:
if fit.value(name="adapt_images") is None:
return [None] * len(fit_list)

adapt_images_list = []

for fit in fit_list:
try:
mask = aa.Mask2D.from_primary_hdu(
primary_hdu=fit.value(name="dataset.mask")[0]
)
except TypeError:
mask = aa.Mask2D.from_primary_hdu(
primary_hdu=fit.value(name="dataset.real_space_mask")[0]
)
mask, header = mask_header_from(fit=fit)

galaxy_name_image_dict = {}

adapt_image_name_list = fit.value(name="adapt_images.adapt_images")

for name in adapt_image_name_list:
adapt_image = aa.Array2D.from_primary_hdu(
primary_hdu=fit.value(name=f"adapt_images.{name}")[0]
for i, value in enumerate(fit.value(name="adapt_images")[1:]):
adapt_image = aa.Array2D.no_mask(
values=ndarray_via_hdu_from(value),
pixel_scales=mask.pixel_scales,
header=header,
origin=mask.origin,
)
adapt_image = adapt_image.apply_mask(mask=mask)
galaxy_name_image_dict[name] = adapt_image

galaxy_name_image_dict[value.header["EXTNAME"].lower()] = adapt_image

instance = fit.model.instance_from_prior_medians(ignore_prior_limits=True)

Expand Down Expand Up @@ -91,7 +129,8 @@ def mesh_grids_of_planes_list_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..
total_fits
The total number of `Analysis` objects summed to create the fit.
use_preloaded_grid
Expand Down
8 changes: 5 additions & 3 deletions autogalaxy/aggregator/dataset_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ def _dataset_model_from(
fit: af.Fit, instance: af.ModelInstance
) -> List[aa.DatasetModel]:
"""
Returns a `DatasetModel` object from a `PyAutoFit` sqlite database `Fit` object.
Returns a `DatasetModel` 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 model and its best fit parameters (e.g. `model.json`).

Expand All @@ -30,7 +31,8 @@ def _dataset_model_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 autogalaxy/aggregator/ellipse/ellipses.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

def _ellipses_from(fit: af.Fit, instance: af.ModelInstance) -> List[List[Ellipse]]:
"""
Returns a list of `Ellipse` objects from a `PyAutoFit` sqlite database `Fit` object.
Returns a list of `Ellipse` 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`).

Expand All @@ -31,7 +32,8 @@ def _ellipses_from(fit: af.Fit, instance: af.ModelInstance) -> List[List[Ellipse
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 @@ -63,7 +65,8 @@ class EllipsesAgg(af.AggBase):
Interfaces with an `PyAutoFit` aggregator object to create instances of `Ellipse` 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`).

Expand Down Expand Up @@ -100,7 +103,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
54 changes: 29 additions & 25 deletions autogalaxy/aggregator/ellipse/fit_ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ def _fit_ellipse_from(
instance: Optional[af.ModelInstance] = None,
) -> List[List[FitEllipse]]:
"""
Returns a list of `FitEllipse` objects from a `PyAutoFit` sqlite database `Fit` object.
Returns a list of `FitEllipse` 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 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]`).

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

Expand All @@ -38,7 +39,8 @@ def _fit_ellipse_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 @@ -78,34 +80,35 @@ def __init__(
aggregator: af.Aggregator,
):
"""
Interfaces with an `PyAutoFit` aggregator object to create instances of `FitEllipse` objects from the results
of a model-fit.
Interfaces with an `PyAutoFit` aggregator object to create instances of `FitEllipse` 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 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 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 `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 `FitEllipse` object via the `_fit_ellipse_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 `FitEllipse` object via the `_fit_ellipse_from` method.

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

If multiple `Ellipse` 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
`FitEllipse` objects.
If multiple `Ellipse` 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
`FitEllipse` 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.
Parameters
----------
aggregator
A `PyAutoFit` aggregator object which can load the results of model-fits.
"""
super().__init__(aggregator=aggregator)

Expand All @@ -120,7 +123,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 autogalaxy/aggregator/ellipse/multipoles.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ def _multipoles_from(
fit: af.Fit, instance: af.ModelInstance
) -> List[List[List[EllipseMultipole]]]:
"""
Returns a list of `EllipseMultipole` objects from a `PyAutoFit` sqlite database `Fit` object.
Returns a list of `EllipseMultipole` 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`).

Expand All @@ -33,7 +34,8 @@ def _multipoles_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 @@ -65,7 +67,8 @@ class MultipolesAgg(af.AggBase):
Interfaces with an `PyAutoFit` aggregator object to create instances of `EllipseMultipole` 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`).

Expand Down Expand Up @@ -102,7 +105,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 autogalaxy/aggregator/galaxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

def _galaxies_from(fit: af.Fit, instance: af.ModelInstance) -> List[Galaxy]:
"""
Returns a list of `Galaxy` objects from a `PyAutoFit` sqlite database `Fit` object.
Returns a list of `Galaxy` 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 @@ -32,7 +33,8 @@ def _galaxies_from(fit: af.Fit, instance: af.ModelInstance) -> List[Galaxy]:
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 @@ -73,7 +75,8 @@ class GalaxiesAgg(af.AggBase):
Interfaces with an `PyAutoFit` aggregator object to create instances of `Galaxy` 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 @@ -111,7 +114,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
Loading
Loading