Skip to content

Commit 89a638a

Browse files
committed
Merge branch 'main' into feature/jax_wrapper
2 parents 2607e67 + dbf6569 commit 89a638a

19 files changed

Lines changed: 256 additions & 140 deletions

File tree

autolens/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@
113113
from . import util
114114

115115
from autoconf import conf
116+
from autoconf.fitsable import ndarray_via_hdu_from
117+
from autoconf.fitsable import ndarray_via_fits_from
118+
from autoconf.fitsable import header_obj_from
119+
from autoconf.fitsable import output_to_fits
120+
from autoconf.fitsable import hdu_list_for_output_from
116121

117122
conf.instance.register(__file__)
118123

autolens/aggregator/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@
2121
from autogalaxy.aggregator.ellipse.fit_ellipse import FitEllipseAgg
2222

2323
from autolens.aggregator.subhalo import SubhaloAgg
24+
25+
from autolens.aggregator.subplot import SubplotDataset as subplot_dataset
26+
from autolens.aggregator.subplot import SubplotTracer as subplot_tracer
27+
from autolens.aggregator.subplot import SubplotFit as subplot_fit
28+
from autolens.aggregator.subplot import SubplotFitLog10 as subplot_fit_log10
29+
from autolens.aggregator.subplot import FITSTracer as fits_tracer
30+
from autolens.aggregator.subplot import FITSFit as fits_fit

autolens/aggregator/fit_imaging.py

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ def _fit_imaging_from(
1818
settings_inversion: aa.SettingsInversion = None,
1919
) -> List[FitImaging]:
2020
"""
21-
Returns a list of `FitImaging` object from a `PyAutoFit` sqlite database `Fit` object.
21+
Returns a list of `FitImaging` object from a `PyAutoFit` loaded directory `Fit` or sqlite database `Fit` object.
2222
23-
The results of a model-fit can be stored in a sqlite database, including the following attributes of the fit:
23+
The results of a model-fit can be loaded from hard-disk or stored in a sqlite database, including the following
24+
attributes of the fit:
2425
2526
- The imaging data, noise-map, PSF and settings as .fits files (e.g. `dataset/data.fits`).
26-
- The mask used to mask the `Imaging` data structure in the fit (`dataset/mask.fits`).
27+
- The mask used to mask the `Imaging` data structure in the fit (`dataset.fits[hdu=0]`).
2728
- The settings of inversions used by the fit (`dataset/settings_inversion.json`).
2829
2930
Each individual attribute can be loaded from the database via the `fit.value()` method.
@@ -41,7 +42,8 @@ def _fit_imaging_from(
4142
Parameters
4243
----------
4344
fit
44-
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry in a sqlite database.
45+
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry which has been loaded from
46+
an output directory or from an sqlite database..
4547
instance
4648
A manual instance that overwrites the max log likelihood instance in fit (e.g. for drawing the instance
4749
randomly from the PDF).
@@ -67,7 +69,6 @@ def _fit_imaging_from(
6769
dataset_model_list,
6870
adapt_images_list,
6971
):
70-
7172
fit_dataset_list.append(
7273
FitImaging(
7374
dataset=dataset,
@@ -88,41 +89,42 @@ def __init__(
8889
settings_inversion: Optional[aa.SettingsInversion] = None,
8990
):
9091
"""
91-
Interfaces with an `PyAutoFit` aggregator object to create instances of `FitImaging` objects from the results
92-
of a model-fit.
93-
94-
The results of a model-fit can be stored in a sqlite database, including the following attributes of the fit:
95-
96-
- The imaging data, noise-map, PSF and settings as .fits files (e.g. `dataset/data.fits`).
97-
- The mask used to mask the `Imaging` data structure in the fit (`dataset/mask.fits`).
98-
- The settings of inversions used by the fit (`dataset/settings_inversion.json`).
99-
100-
The `aggregator` contains the path to each of these files, and they can be loaded individually. This class
101-
can load them all at once and create an `FitImaging` object via the `_fit_imaging_from` method.
102-
103-
This class's methods returns generators which create the instances of the `FitImaging` objects. This ensures
104-
that large sets of results can be efficiently loaded from the hard-disk and do not require storing all
105-
`FitImaging` instances in the memory at once.
106-
107-
For example, if the `aggregator` contains 3 model-fits, this class can be used to create a generator which
108-
creates instances of the corresponding 3 `FitImaging` objects.
109-
110-
If multiple `FitImaging` objects were fitted simultaneously via analysis summing, the `fit.child_values()` method
111-
is instead used to load lists of the data, noise-map, PSF and mask and combine them into a list of
112-
`FitImaging` objects.
113-
114-
This can be done manually, but this object provides a more concise API.
115-
116-
Parameters
117-
----------
118-
aggregator
119-
A `PyAutoFit` aggregator object which can load the results of model-fits.
120-
settings_inversion
121-
Optionally overwrite the `SettingsInversion` of the `Inversion` object that is created from the fit.
122-
use_preloaded_grid
123-
Certain pixelization's construct their mesh in the source-plane from a stochastic KMeans algorithm. This
124-
grid may be output to hard-disk after the model-fit and loaded via the database to ensure the same grid is
125-
used as the fit.
92+
Interfaces with an `PyAutoFit` aggregator object to create instances of `FitImaging` objects from the results
93+
of a model-fit.
94+
95+
The results of a model-fit can be loaded from hard-disk or stored in a sqlite database, including the following
96+
attributes of the fit:
97+
98+
- The imaging data, noise-map, PSF and settings as .fits files (e.g. `dataset/data.fits`).
99+
- The mask used to mask the `Imaging` data structure in the fit (`dataset.fits[hdu=0]`).
100+
- The settings of inversions used by the fit (`dataset/settings_inversion.json`).
101+
102+
The `aggregator` contains the path to each of these files, and they can be loaded individually. This class
103+
can load them all at once and create an `FitImaging` object via the `_fit_imaging_from` method.
104+
105+
This class's methods returns generators which create the instances of the `FitImaging` objects. This ensures
106+
that large sets of results can be efficiently loaded from the hard-disk and do not require storing all
107+
`FitImaging` instances in the memory at once.
108+
109+
For example, if the `aggregator` contains 3 model-fits, this class can be used to create a generator which
110+
creates instances of the corresponding 3 `FitImaging` objects.
111+
112+
If multiple `FitImaging` objects were fitted simultaneously via analysis summing, the `fit.child_values()` method
113+
is instead used to load lists of the data, noise-map, PSF and mask and combine them into a list of
114+
`FitImaging` objects.
115+
116+
This can be done manually, but this object provides a more concise API.
117+
118+
Parameters
119+
----------
120+
aggregator
121+
A `PyAutoFit` aggregator object which can load the results of model-fits.
122+
settings_inversion
123+
Optionally overwrite the `SettingsInversion` of the `Inversion` object that is created from the fit.
124+
use_preloaded_grid
125+
Certain pixelization's construct their mesh in the source-plane from a stochastic KMeans algorithm. This
126+
grid may be output to hard-disk after the model-fit and loaded via the database to ensure the same grid is
127+
used as the fit.
126128
"""
127129
super().__init__(aggregator=aggregator)
128130

@@ -139,7 +141,8 @@ def object_via_gen_from(
139141
Parameters
140142
----------
141143
fit
142-
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry in a sqlite database.
144+
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry which has been loaded from
145+
an output directory or from an sqlite database..
143146
instance
144147
A manual instance that overwrites the max log likelihood instance in fit (e.g. for drawing the instance
145148
randomly from the PDF).

autolens/aggregator/fit_interferometer.py

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
def _fit_interferometer_from(
1616
fit: af.Fit,
1717
instance: Optional[af.ModelInstance] = None,
18-
real_space_mask: Optional[aa.Mask2D] = None,
1918
settings_inversion: aa.SettingsInversion = None,
2019
) -> List[FitInterferometer]:
2120
"""
22-
Returns a list of `FitInterferometer` objects from a `PyAutoFit` sqlite database `Fit` object.
21+
Returns a list of `FitInterferometer` objects from a `PyAutoFit` loaded directory `Fit` or sqlite database `Fit` object.
2322
24-
The results of a model-fit can be stored in a sqlite database, including the following attributes of the fit:
23+
The results of a model-fit can be loaded from hard-disk or stored in a sqlite database, including the following
24+
attributes of the fit:
2525
2626
- The interferometer data, noise-map, uv-wavelengths and settings as .fits files (e.g. `dataset/data.fits`).
2727
- The real space mask defining the grid of the interferometer for the FFT (`dataset/real_space_mask.fits`).
@@ -43,7 +43,8 @@ def _fit_interferometer_from(
4343
Parameters
4444
----------
4545
fit
46-
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry in a sqlite database.
46+
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry which has been loaded from
47+
an output directory or from an sqlite database..
4748
instance
4849
A manual instance that overwrites the max log likelihood instance in fit (e.g. for drawing the instance
4950
randomly from the PDF).
@@ -52,7 +53,6 @@ def _fit_interferometer_from(
5253
"""
5354
dataset_list = _interferometer_from(
5455
fit=fit,
55-
real_space_mask=real_space_mask,
5656
)
5757
tracer_list = _tracer_from(fit=fit, instance=instance)
5858
dataset_model_list = _dataset_model_from(fit=fit, instance=instance)
@@ -69,7 +69,6 @@ def _fit_interferometer_from(
6969
dataset_model_list,
7070
adapt_images_list,
7171
):
72-
7372
fit_dataset_list.append(
7473
FitInterferometer(
7574
dataset=dataset,
@@ -88,45 +87,44 @@ def __init__(
8887
self,
8988
aggregator: af.Aggregator,
9089
settings_inversion: Optional[aa.SettingsInversion] = None,
91-
real_space_mask: Optional[aa.Mask2D] = None,
9290
):
9391
"""
94-
Interfaces with an `PyAutoFit` aggregator object to create instances of `FitInterferometer` objects from the
95-
results of a model-fit.
92+
Interfaces with an `PyAutoFit` aggregator object to create instances of `FitInterferometer` objects from the
93+
results of a model-fit.
9694
97-
The results of a model-fit can be stored in a sqlite database, including the following attributes of the fit:
95+
The results of a model-fit can be loaded from hard-disk or stored in a sqlite database, including the following
96+
attributes of the fit:
9897
99-
- The interferometer data, noise-map, uv-wavelengths and settings as .fits files (e.g. `dataset/data.fits`).
100-
- The real space mask defining the grid of the interferometer for the FFT (`dataset/real_space_mask.fits`).
101-
- The settings of inversions used by the fit (`dataset/settings_inversion.json`).
98+
- The interferometer data, noise-map, uv-wavelengths and settings as .fits files (e.g. `dataset/data.fits`).
99+
- The real space mask defining the grid of the interferometer for the FFT (`dataset/real_space_mask.fits`).
100+
- The settings of inversions used by the fit (`dataset/settings_inversion.json`).
102101
103-
The `aggregator` contains the path to each of these files, and they can be loaded individually. This class
104-
can load them all at once and create an `FitInterferometer` object via the `_fit_interferometer_from` method.
102+
The `aggregator` contains the path to each of these files, and they can be loaded individually. This class
103+
can load them all at once and create an `FitInterferometer` object via the `_fit_interferometer_from` method.
105104
106-
This class's methods returns generators which create the instances of the `FitInterferometer` objects. This ensures
107-
that large sets of results can be efficiently loaded from the hard-disk and do not require storing all
108-
`FitInterferometer` instances in the memory at once.
105+
This class's methods returns generators which create the instances of the `FitInterferometer` objects. This ensures
106+
that large sets of results can be efficiently loaded from the hard-disk and do not require storing all
107+
`FitInterferometer` instances in the memory at once.
109108
110-
For example, if the `aggregator` contains 3 model-fits, this class can be used to create a generator which
111-
creates instances of the corresponding 3 `FitInterferometer` objects.
109+
For example, if the `aggregator` contains 3 model-fits, this class can be used to create a generator which
110+
creates instances of the corresponding 3 `FitInterferometer` objects.
112111
113-
This can be done manually, but this object provides a more concise API.
112+
This can be done manually, but this object provides a more concise API.
114113
115-
Parameters
116-
----------
117-
aggregator
118-
A `PyAutoFit` aggregator object which can load the results of model-fits.
119-
settings_inversion
120-
Optionally overwrite the `SettingsInversion` of the `Inversion` object that is created from the fit.
121-
use_preloaded_grid
122-
Certain pixelization's construct their mesh in the source-plane from a stochastic KMeans algorithm. This
123-
grid may be output to hard-disk after the model-fit and loaded via the database to ensure the same grid is
124-
used as the fit.
114+
Parameters
115+
----------
116+
aggregator
117+
A `PyAutoFit` aggregator object which can load the results of model-fits.
118+
settings_inversion
119+
Optionally overwrite the `SettingsInversion` of the `Inversion` object that is created from the fit.
120+
use_preloaded_grid
121+
Certain pixelization's construct their mesh in the source-plane from a stochastic KMeans algorithm. This
122+
grid may be output to hard-disk after the model-fit and loaded via the database to ensure the same grid is
123+
used as the fit.
125124
"""
126125
super().__init__(aggregator=aggregator)
127126

128127
self.settings_inversion = settings_inversion
129-
self.real_space_mask = real_space_mask
130128

131129
def object_via_gen_from(
132130
self, fit, instance: Optional[af.ModelInstance] = None
@@ -139,7 +137,8 @@ def object_via_gen_from(
139137
Parameters
140138
----------
141139
fit
142-
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry in a sqlite database.
140+
A `PyAutoFit` `Fit` object which contains the results of a model-fit as an entry which has been loaded from
141+
an output directory or from an sqlite database..
143142
instance
144143
A manual instance that overwrites the max log likelihood instance in fit (e.g. for drawing the instance
145144
randomly from the PDF).

autolens/aggregator/subplot.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
from enum import Enum
2+
3+
4+
class FITSTracer(Enum):
5+
"""
6+
The HDUs that can be extracted from the fit.fits file.
7+
"""
8+
9+
convergence = "CONVERGENCE"
10+
potential = "POTENTIAL"
11+
deflections_y = "DEFLECTIONS_Y"
12+
deflections_x = "DEFLECTIONS_X"
13+
14+
15+
class FITSFit(Enum):
16+
"""
17+
The HDUs that can be extracted from the fit.fits file.
18+
"""
19+
20+
model_image = "MODEL_IMAGE"
21+
residual_map = "RESIDUAL_MAP"
22+
normalized_residual_map = "NORMALIZED_RESIDUAL_MAP"
23+
chi_squared_map = "CHI_SQUARED_MAP"
24+
25+
26+
class SubplotDataset(Enum):
27+
"""
28+
The subplots that can be extracted from the subplot_fit image.
29+
30+
The values correspond to the position of the subplot in the 4x3 grid.
31+
"""
32+
33+
data = (0, 0)
34+
data_log_10 = (1, 0)
35+
noise_map = (2, 0)
36+
psf = (0, 1)
37+
psf_log_10 = (1, 1)
38+
signal_to_noise_map = (2, 1)
39+
over_sample_size_lp = (0, 2)
40+
over_sample_size_pixelization = (1, 2)
41+
42+
43+
class SubplotTracer(Enum):
44+
"""
45+
The subplots that can be extracted from the subplot_tracer image.
46+
47+
The values correspond to the position of the subplot in the 3x3 grid.
48+
"""
49+
50+
image = (0, 0)
51+
source_image = (1, 0)
52+
source_plane_image = (2, 0)
53+
lens_light_image = (1, 0)
54+
convergence = (1, 1)
55+
potential = (1, 2)
56+
magnification = (0, 2)
57+
deflections_y = (1, 2)
58+
deflections_x = (2, 2)
59+
60+
61+
class SubplotFit(Enum):
62+
"""
63+
The subplots that can be extracted from the subplot_fit image.
64+
65+
The values correspond to the position of the subplot in the 4x3 grid.
66+
"""
67+
68+
data = (0, 0)
69+
data_source_scale = (1, 0)
70+
signal_to_noise_map = (2, 0)
71+
model_image = (3, 0)
72+
lens_light_model = (1, 0)
73+
lens_light_subtracted_image = (1, 1)
74+
source_model_image = (1, 2)
75+
source_plane_image_zoom = (1, 3)
76+
normalized_residual_map = (2, 0)
77+
normalized_residual_map_one_sigma = (2, 1)
78+
chi_squared_map = (2, 2)
79+
source_plane_image = (2, 3)
80+
81+
82+
class SubplotFitLog10(Enum):
83+
"""
84+
The subplots that can be extracted from the subplot_fit image.
85+
86+
The values correspond to the position of the subplot in the 4x3 grid.
87+
"""
88+
89+
data = (0, 0)
90+
data_source_scale = (1, 0)
91+
signal_to_noise_map = (2, 0)
92+
model_image = (3, 0)
93+
lens_light_model = (1, 0)
94+
lens_light_subtracted_image = (1, 1)
95+
source_model_image = (1, 2)
96+
source_plane_image_zoom = (1, 3)
97+
normalized_residual_map = (2, 0)
98+
normalized_residual_map_one_sigma = (2, 1)
99+
chi_squared_map = (2, 2)
100+
source_plane_image = (2, 3)

0 commit comments

Comments
 (0)