Skip to content

Commit a812400

Browse files
authored
Merge pull request #348 from Jammy2211/feature/source_plane_images
Feature/source plane images
2 parents 59452a7 + f19c7c7 commit a812400

4 files changed

Lines changed: 54 additions & 4 deletions

File tree

autolens/analysis/plotter_interface.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import ast
2+
import numpy as np
3+
4+
from autoconf import conf
15
from autoconf.fitsable import hdu_list_for_output_from
26

37
import autoarray as aa
8+
import autogalaxy as ag
49
import autogalaxy.plot as aplt
510

611
from autogalaxy.analysis.plotter_interface import plot_setting
@@ -86,11 +91,54 @@ def should_plot(name):
8691
"deflections_y",
8792
"deflections_x",
8893
],
89-
header_dict=grid.mask.header_dict,
94+
header_dict=grid_zoom.mask.header_dict,
9095
)
9196

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

99+
if should_plot("fits_source_plane_images"):
100+
101+
shape_native = conf.instance["visualize"]["plots"]["tracer"][
102+
"fits_source_plane_shape"
103+
]
104+
shape_native = ast.literal_eval(shape_native)
105+
106+
zoom = aa.Zoom2D(mask=grid.mask)
107+
mask = zoom.mask_2d_from(buffer=1)
108+
grid_source_plane = aa.Grid2D.from_extent(
109+
extent=mask.geometry.extent, shape_native=tuple(shape_native)
110+
)
111+
112+
print(grid_source_plane)
113+
114+
image_list = [grid_source_plane.mask.astype("float")]
115+
ext_name_list = ["mask"]
116+
117+
for i, plane in enumerate(tracer.planes[1:]):
118+
119+
if plane.has(cls=ag.LightProfile):
120+
121+
image = plane.image_2d_from(
122+
grid=grid_source_plane,
123+
).native
124+
125+
else:
126+
127+
image = np.zeros(grid_source_plane.shape_native)
128+
129+
image_list.append(image)
130+
ext_name_list.append(f"source_plane_image_{i+1}")
131+
132+
hdu_list = hdu_list_for_output_from(
133+
values_list=image_list,
134+
ext_name_list=ext_name_list,
135+
header_dict=grid_source_plane.mask.header_dict,
136+
)
137+
138+
hdu_list.writeto(
139+
self.image_path / "source_plane_images.fits", overwrite=True
140+
)
141+
94142
def image_with_positions(self, image: aa.Array2D, positions: aa.Grid2DIrregular):
95143
"""
96144
Visualizes the positions of a model-fit, where these positions are used to resample lens models where

autolens/config/visualize/plots.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ tracer: # Settings for plots of tracers (e.g.
3434
subplot_tracer: true # Plot subplot of all quantities in each tracer (e.g. images, convergence)?
3535
subplot_galaxies_images: false # Plot subplot of the image of each plane in the tracer?
3636
fits_tracer: false # Output tracer.fits file of tracer's convergence, potential, deflections_y and deflections_x?
37+
fits_source_plane_images: false # Output source_plane_images.fits file of the source-plane image (light profiles only) of each galaxy in the tracer?
38+
fits_source_plane_shape: (100, 100) # The shape of the source-plane image output in the fits_source_plane_images.fits file.
3739

3840
inversion: # Settings for plots of inversions (e.g. InversionPlotter).
3941
subplot_inversion: true # Plot subplot of all quantities in each inversion (e.g. reconstrucuted image, reconstruction)?

autolens/imaging/plot/fit_imaging_plotters.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,6 @@ def figures_2d_of_planes(
292292

293293
elif self.tracer.planes[plane_index].has(cls=aa.Pixelization):
294294

295-
pix = self.tracer.planes[plane_index].cls_list_from(cls=aa.Pixelization)[0]
296-
297295
inversion_plotter = self.inversion_plotter_of_plane(
298296
plane_index=plane_index
299297
)

test_autolens/config/visualize.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,6 @@ plots:
9999
tracer:
100100
subplot_tracer: true
101101
subplot_galaxies_images: true
102-
fits_tracer: true # Output tracer.fits file of tracer's convergence, potential, deflections_y and deflections_x?
102+
fits_tracer: true # Output tracer.fits file of tracer's convergence, potential, deflections_y and deflections_x?
103+
fits_source_plane_images: true # Output source_plane_images.fits file of the source-plane image (light profiles only) of each galaxy in the tracer?
104+
fits_source_plane_shape: (3, 3) # The shape of the source-plane image output in the fits_source_plane_images.fits file.

0 commit comments

Comments
 (0)