Skip to content

Commit f2ad520

Browse files
authored
Merge pull request #322 from Jammy2211/feature/single_image_positions
Feature/single image positions
2 parents 19a1125 + 3555dd6 commit f2ad520

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

autolens/analysis/result.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import os
23
import numpy as np
34
from typing import Optional, Union
@@ -15,6 +16,8 @@
1516
from autolens.lens.tracer import Tracer
1617
from autolens.point.solver import PointSolver
1718

19+
logger = logging.getLogger(__name__)
20+
1821

1922
class Result(AgResultDataset):
2023
@property
@@ -101,8 +104,63 @@ def image_plane_multiple_image_positions(self) -> aa.Grid2DIrregular:
101104
source_plane_coordinate=self.source_plane_centre.in_list[0],
102105
)
103106

107+
if multiple_images.shape[0] == 1:
108+
return self.image_plane_multiple_image_positions_for_single_image_from()
109+
104110
return aa.Grid2DIrregular(values=multiple_images)
105111

112+
def image_plane_multiple_image_positions_for_single_image_from(self, increments : int = 20) -> aa.Grid2DIrregular:
113+
"""
114+
If the standard point solver only locates one multiple image, finds one or more additional images, which are
115+
not technically multiple image in the point source regime, but are close enough to it they can be used
116+
in a position threshold likelihood.
117+
118+
This is performed by incrementally moving the source-plane centre's coordinates towards the centre of the
119+
source-plane at (0.0", 0.0"). This ensures that the centre will eventually go inside the caustic, where
120+
multiple images are formed.
121+
122+
To move the source-plane centre, the original source-plane centre is multiplied by a factor that decreases
123+
from 1.0 to 0.0 in increments of 1/increments. For example, if the source-plane centre is (1.0", -0.5") and
124+
the `factor` is 0.5, the input source-plane centre is (0.5", -0.25").
125+
126+
The multiple images are always computed for the same mass model, thus they will always be valid multiple images
127+
for the model being fitted, but as the factor decrease the multiple images may move furhter from their observed
128+
positions.
129+
130+
Parameters
131+
----------
132+
increments
133+
The number of increments the source-plane centre is moved to compute multiple images.
134+
"""
135+
136+
logger.info("""
137+
Could not find multiple images for maximum likelihood lens model.
138+
139+
Incrementally moving source centre inwards towards centre of source-plane until caustic crossing occurs
140+
and multiple images are formed.
141+
""")
142+
143+
grid = self.analysis.dataset.mask.derive_grid.all_false
144+
145+
centre = self.source_plane_centre.in_list[0]
146+
147+
solver = PointSolver.for_grid(
148+
grid=grid,
149+
pixel_scale_precision=0.001,
150+
)
151+
152+
for i in range(1, increments):
153+
154+
factor = 1.0 - (1.0 * (i/increments))
155+
156+
multiple_images = solver.solve(
157+
tracer=self.max_log_likelihood_tracer,
158+
source_plane_coordinate=(centre[0] * factor, centre[1] * factor),
159+
)
160+
161+
if multiple_images.shape[0] > 1:
162+
return aa.Grid2DIrregular(values=multiple_images)
163+
106164
def positions_threshold_from(
107165
self,
108166
factor=1.0,

test_autolens/analysis/test_result.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def test__image_plane_multiple_image_positions(analysis_imaging_7x7):
227227

228228
multiple_images = result.image_plane_multiple_image_positions
229229

230-
assert pytest.approx((0.968719, 0.366210), 1.0e-4) in multiple_images.in_list
230+
assert pytest.approx((0.968719, 0.366210), 1.0e-2) in multiple_images.in_list
231231

232232

233233
def test__positions_threshold_from(analysis_imaging_7x7):
@@ -247,9 +247,9 @@ def test__positions_threshold_from(analysis_imaging_7x7):
247247

248248
result = res.Result(samples_summary=samples_summary, analysis=analysis_imaging_7x7)
249249

250-
assert result.positions_threshold_from() == pytest.approx(1.1001488121, 1.0e-4)
250+
assert result.positions_threshold_from() == pytest.approx(0.930414842576, 1.0e-4)
251251
assert result.positions_threshold_from(factor=5.0) == pytest.approx(
252-
5.5007440609, 1.0e-4
252+
4.652074212, 1.0e-4
253253
)
254254
assert result.positions_threshold_from(minimum_threshold=10.0) == pytest.approx(
255255
10.0, 1.0e-4

test_autolens/point/fit/positions/image/test_abstract.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def test__multi_plane_position_solving():
7777
)
7878

7979
assert fit_0.model_data[0, 0] == pytest.approx(
80-
scaling_factor * fit_1.model_data[0, 0], 1.0e-1
80+
scaling_factor * fit_1.model_data[1, 0], 1.0e-1
8181
)
82-
assert fit_0.model_data[0, 1] == pytest.approx(
82+
assert fit_0.model_data[1, 1] == pytest.approx(
8383
scaling_factor * fit_1.model_data[0, 1], 1.0e-1
8484
)

0 commit comments

Comments
 (0)