|
| 1 | +import logging |
1 | 2 | import os
|
2 | 3 | import numpy as np
|
3 | 4 | from typing import Optional, Union
|
|
15 | 16 | from autolens.lens.tracer import Tracer
|
16 | 17 | from autolens.point.solver import PointSolver
|
17 | 18 |
|
| 19 | +logger = logging.getLogger(__name__) |
| 20 | + |
18 | 21 |
|
19 | 22 | class Result(AgResultDataset):
|
20 | 23 | @property
|
@@ -101,8 +104,63 @@ def image_plane_multiple_image_positions(self) -> aa.Grid2DIrregular:
|
101 | 104 | source_plane_coordinate=self.source_plane_centre.in_list[0],
|
102 | 105 | )
|
103 | 106 |
|
| 107 | + if multiple_images.shape[0] == 1: |
| 108 | + return self.image_plane_multiple_image_positions_for_single_image_from() |
| 109 | + |
104 | 110 | return aa.Grid2DIrregular(values=multiple_images)
|
105 | 111 |
|
| 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 | + |
106 | 164 | def positions_threshold_from(
|
107 | 165 | self,
|
108 | 166 | factor=1.0,
|
|
0 commit comments