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
8 changes: 4 additions & 4 deletions autogalaxy/aggregator/agg_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from autogalaxy.analysis.adapt_images.adapt_images import AdaptImages


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

Expand All @@ -30,7 +30,7 @@ def mask_header_from(fit):
The mask, header and pixel scales of the `PyAutoFit` `Fit` object.
"""

header = aa.Header(header_sci_obj=fit.value(name="dataset")[0].header)
header = aa.Header(header_sci_obj=fit.value(name=name)[0].header)
pixel_scales = (
header.header_sci_obj[Mask2DKeys.PIXSCAY.value],
header.header_sci_obj[Mask2DKeys.PIXSCAY.value],
Expand All @@ -40,7 +40,7 @@ def mask_header_from(fit):
header.header_sci_obj[Mask2DKeys.ORIGINX.value],
)
mask = aa.Mask2D(
mask=ndarray_via_hdu_from(fit.value(name="dataset")[0]),
mask=ndarray_via_hdu_from(fit.value(name=name)[0]),
pixel_scales=pixel_scales,
origin=origin,
)
Expand Down Expand Up @@ -79,7 +79,7 @@ def adapt_images_from(
adapt_images_list = []

for fit in fit_list:
mask, header = mask_header_from(fit=fit)
mask, header = mask_header_from(fit=fit, name="adapt_images")

galaxy_name_image_dict = {}

Expand Down
4 changes: 2 additions & 2 deletions autogalaxy/aggregator/subplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class FITSFit(Enum):
The HDUs that can be extracted from the fit.fits file.
"""

model_image = "MODEL_IMAGE"
model_data = "MODEL_DATA"
residual_map = "RESIDUAL_MAP"
normalized_residual_map = "NORMALIZED_RESIDUAL_MAP"
chi_squared_map = "CHI_SQUARED_MAP"
Expand Down Expand Up @@ -38,7 +38,7 @@ class SubplotFit(Enum):

data = (0, 0)
signal_to_noise_map = (1, 0)
model_image = (2, 0)
model_data = (2, 0)
normalized_residual_map = (0, 1)
normalized_residual_map_one_sigma = (1, 1)
chi_squared_map = (2, 1)
30 changes: 15 additions & 15 deletions autogalaxy/analysis/analysis/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,33 +192,33 @@ def profile_log_likelihood_function(

try:
info_dict["image_pixels"] = self.dataset.grids.lp.shape_slim
info_dict[
"sub_total_light_profiles"
] = self.dataset.grids.lp.over_sampler.sub_total
info_dict["sub_total_light_profiles"] = (
self.dataset.grids.lp.over_sampler.sub_total
)
except AttributeError:
pass

if fit.model_obj.has(cls=aa.Pixelization):
info_dict["use_w_tilde"] = fit.inversion.settings.use_w_tilde
try:
info_dict[
"sub_total_pixelization"
] = self.dataset.grids.pixelization.over_sampler.sub_total
info_dict["sub_total_pixelization"] = (
self.dataset.grids.pixelization.over_sampler.sub_total
)
except AttributeError:
pass
info_dict[
"use_positive_only_solver"
] = fit.inversion.settings.use_positive_only_solver
info_dict[
"force_edge_pixels_to_zeros"
] = fit.inversion.settings.force_edge_pixels_to_zeros
info_dict["use_positive_only_solver"] = (
fit.inversion.settings.use_positive_only_solver
)
info_dict["force_edge_pixels_to_zeros"] = (
fit.inversion.settings.force_edge_pixels_to_zeros
)
info_dict["use_w_tilde_numpy"] = fit.inversion.settings.use_w_tilde_numpy
info_dict["source_pixels"] = len(fit.inversion.reconstruction)

if hasattr(fit.inversion, "w_tilde"):
info_dict[
"w_tilde_curvature_preload_size"
] = fit.inversion.w_tilde.curvature_preload.shape[0]
info_dict["w_tilde_curvature_preload_size"] = (
fit.inversion.w_tilde.curvature_preload.shape[0]
)

self.output_profiling_info(
paths=paths, run_time_dict=run_time_dict, info_dict=info_dict
Expand Down
40 changes: 15 additions & 25 deletions autogalaxy/analysis/chaining_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,39 +215,29 @@ def extra_galaxies_from(

for extra_galaxy_index in range(len(result.instance.extra_galaxies)):
if hasattr(result.instance.extra_galaxies[extra_galaxy_index], "mass"):
extra_galaxies[
extra_galaxy_index
].mass.centre = result.instance.extra_galaxies[
extra_galaxy_index
].mass.centre
extra_galaxies[
extra_galaxy_index
].mass.einstein_radius = result.model.extra_galaxies[
extra_galaxy_index
].mass.einstein_radius
extra_galaxies[extra_galaxy_index].mass.centre = (
result.instance.extra_galaxies[extra_galaxy_index].mass.centre
)
extra_galaxies[extra_galaxy_index].mass.einstein_radius = (
result.model.extra_galaxies[extra_galaxy_index].mass.einstein_radius
)
if free_centre:
extra_galaxies[
extra_galaxy_index
].mass.centre = result.model.extra_galaxies[
extra_galaxy_index
].mass.centre
extra_galaxies[extra_galaxy_index].mass.centre = (
result.model.extra_galaxies[extra_galaxy_index].mass.centre
)

elif light_as_model:
extra_galaxies = result.instance.extra_galaxies.as_model((LightProfile,))

for extra_galaxy_index in range(len(result.instance.extra_galaxies)):
if extra_galaxies[extra_galaxy_index].bulge is not None:
extra_galaxies[
extra_galaxy_index
].bulge.centre = result.instance.extra_galaxies[
extra_galaxy_index
].bulge.centre
extra_galaxies[extra_galaxy_index].bulge.centre = (
result.instance.extra_galaxies[extra_galaxy_index].bulge.centre
)
if free_centre:
extra_galaxies[
extra_galaxy_index
].bulge.centre = result.model.extra_galaxies[
extra_galaxy_index
].bulge.centre
extra_galaxies[extra_galaxy_index].bulge.centre = (
result.model.extra_galaxies[extra_galaxy_index].bulge.centre
)

else:
extra_galaxies = result.instance.extra_galaxies.as_model(())
Expand Down
46 changes: 37 additions & 9 deletions autogalaxy/analysis/plotter_interface.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import csv
import os
from pathlib import Path
from typing import List, Union
Expand All @@ -11,7 +12,6 @@
from autogalaxy.analysis.adapt_images.adapt_images import AdaptImages
from autogalaxy.galaxy.galaxy import Galaxy
from autogalaxy.galaxy.galaxies import Galaxies
from autogalaxy.galaxy.plot.galaxy_plotters import GalaxyPlotter
from autogalaxy.galaxy.plot.galaxies_plotters import GalaxiesPlotter
from autogalaxy.galaxy.plot.adapt_plotters import AdaptPlotter

Expand Down Expand Up @@ -180,9 +180,13 @@ def should_plot(name):
pass

if should_plot("fits_galaxy_images"):

image_list = [
galaxy.image_2d_from(grid=grid).native_for_fits for galaxy in galaxies
]

hdu_list = hdu_list_for_output_from(
values_list=[grid.mask.astype("float")]
+ [galaxy.image_2d_from(grid=grid) for galaxy in galaxies],
values_list=[image_list[0].mask.astype("float")] + image_list,
ext_name_list=["mask"] + [f"galaxy_{i}" for i in range(len(galaxies))],
header_dict=grid.mask.header_dict,
)
Expand Down Expand Up @@ -221,8 +225,32 @@ def should_plot(name):
if should_plot("subplot_inversion"):
mapper_list = inversion.cls_list_from(cls=aa.AbstractMapper)

for mapper_index in range(len(mapper_list)):
inversion_plotter.subplot_of_mapper(mapper_index=mapper_index)
for i in range(len(mapper_list)):
suffix = "" if len(mapper_list) == 1 else f"_{i}"

inversion_plotter.subplot_of_mapper(
mapper_index=i, auto_filename=f"subplot_inversion{suffix}"
)

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

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]
reconstruction = inversion.reconstruction_dict[mapper]
noise_map = inversion.reconstruction_noise_map_dict[mapper]

with open(
self.image_path / f"inversion_reconstruction_{i}.csv",
mode="w",
newline="",
) as file:
writer = csv.writer(file)
writer.writerow(["y", "x", "reconstruction", "noise_map"]) # header

for i in range(len(x)):
writer.writerow([y[i], x[i], reconstruction[i], noise_map[i]])

def adapt_images(
self,
Expand Down Expand Up @@ -260,16 +288,16 @@ def should_plot(name):
)

if should_plot("fits_adapt_images"):
values_list = [
adapt_images.galaxy_name_image_dict[name].native
image_list = [
adapt_images.galaxy_name_image_dict[name].native_for_fits
for name in adapt_images.galaxy_name_image_dict.keys()
]

hdu_list = hdu_list_for_output_from(
values_list=[
adapt_images.mask.astype("float"),
image_list[0].mask.astype("float"),
]
+ values_list,
+ image_list,
ext_name_list=["mask"]
+ list(adapt_images.galaxy_name_image_dict.keys()),
header_dict=adapt_images.mask.header_dict,
Expand Down
3 changes: 2 additions & 1 deletion autogalaxy/config/visualize/plots.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# These can be disabled to save on hard-disk space but will lead to certain database functionality being disabled.

subplot_format: [png] # Output format of all subplots, can be png, pdf or both (e.g. [png, pdf])
fits_are_zoomed: true # If true, output .fits files are zoomed in on the center of the unmasked region image, saving hard-disk space.

dataset: # Settings for plots of all datasets (e.g. ImagingPlotter, InterferometerPlotter).
subplot_dataset: true # Plot subplot containing all dataset quantities (e.g. the data, noise-map, etc.)?
Expand All @@ -36,7 +37,7 @@ galaxies: # Settings for plots of galaxies (e.g
inversion: # Settings for plots of inversions (e.g. InversionPlotter).
subplot_inversion: true # Plot subplot of all quantities in each inversion (e.g. reconstrucuted image, reconstruction)?
subplot_mappings: true # Plot subplot of the image-to-source pixels mappings of each pixelization?
fits_reconstruction: false # output reconstruction.fits containing the reconstructed pixelization and noise map on the adaptive mesh?
csv_reconstruction: false # output reconstruction.csv containing the source-plane mesh y, x, reconstruction and noise map values.

adapt: # Settings for plots of adapt images used by adaptive pixelizations.
subplot_adapt_images: true # Plot subplot showing each adapt image used for adaptive pixelization?
Expand Down
11 changes: 6 additions & 5 deletions autogalaxy/ellipse/model/plotter_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ def should_plot(name):
if should_plot("subplot_dataset"):
dataset_plotter.subplot_dataset()

image_list = [
dataset.data.native_for_fits,
dataset.noise_map.native_for_fits,
]

hdu_list = hdu_list_for_output_from(
values_list=[
dataset.mask.astype("float"),
dataset.data.native,
dataset.noise_map.native,
],
values_list=[image_list[0].mask.astype("float")] + image_list,
ext_name_list=[
"mask",
"data",
Expand Down
6 changes: 3 additions & 3 deletions autogalaxy/imaging/fit_imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ def subtracted_images_of_galaxies_dict(self) -> Dict[Galaxy, aa.Array2D]:

subtracted_image = self.data - sum(other_galaxies_model_images)

subtracted_images_of_galaxies_dict[
self.galaxies[galaxy_index]
] = subtracted_image
subtracted_images_of_galaxies_dict[self.galaxies[galaxy_index]] = (
subtracted_image
)

return subtracted_images_of_galaxies_dict

Expand Down
41 changes: 25 additions & 16 deletions autogalaxy/imaging/model/plotter_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@ def fits_to_fits(
"""

if should_plot("fits_fit"):

image_list = [
fit.model_data.native_for_fits,
fit.residual_map.native_for_fits,
fit.normalized_residual_map.native_for_fits,
fit.chi_squared_map.native_for_fits,
]

hdu_list = hdu_list_for_output_from(
values_list=[
fit.mask.astype("float"),
fit.model_data,
fit.residual_map,
fit.normalized_residual_map,
fit.chi_squared_map,
],
image_list[0].mask.astype("float"),
]
+ image_list,
ext_name_list=[
"mask",
"model_data",
Expand All @@ -58,9 +63,12 @@ def fits_to_fits(
if should_plot("fits_model_galaxy_images"):
number_plots = len(fit.galaxy_model_image_dict.keys()) + 1

image_list = [
image.native_for_fits for image in fit.galaxy_model_image_dict.values()
]

hdu_list = hdu_list_for_output_from(
values_list=[fit.mask.astype("float")]
+ [image.native for image in fit.galaxy_model_image_dict.values()],
values_list=[image_list[0].mask.astype("float")] + image_list,
ext_name_list=[
"mask",
]
Expand Down Expand Up @@ -104,15 +112,16 @@ def should_plot(name):
dataset_plotter.subplot_dataset()

if should_plot("fits_dataset"):
image_list = [
dataset.data.native_for_fits,
dataset.noise_map.native_for_fits,
dataset.psf.native_for_fits,
dataset.grids.lp.over_sample_size.native_for_fits,
dataset.grids.pixelization.over_sample_size.native_for_fits,
]

hdu_list = hdu_list_for_output_from(
values_list=[
dataset.mask.astype("float"),
dataset.data.native,
dataset.noise_map.native,
dataset.psf.native,
dataset.grids.lp.over_sample_size.native,
dataset.grids.pixelization.over_sample_size.native,
],
values_list=[image_list[0].mask.astype("float")] + image_list,
ext_name_list=[
"mask",
"data",
Expand Down
Loading
Loading