def updated_positions_threshold_from_positions(self, positions, results) -> [float]: """ If automatic position updating is on, update the phase's threshold using this phase's updated positions. First, we ray-trace forward the positions of the source-plane centres (see above) via the mass model to determine how far apart they are separated. This gives us their source-plane sepration, which is multiplied by self.auto_positions_factor to set the threshold. The threshold is rounded up to the auto positions minimum threshold if that setting is included.""" if results.last is not None: try: if len(results.last.max_log_likelihood_tracer.planes) <= 1: if self.settings.settings_lens.positions_threshold is not None: return self.settings.settings_lens.positions_threshold if (self.settings.settings_lens. auto_positions_minimum_threshold is not None): return (self.settings.settings_lens. auto_positions_minimum_threshold) return None except AttributeError: pass if (self.settings.settings_lens.auto_positions_factor and results.last is not None): if positions is None: return None positions_fits = fit_point_source.FitPositionsSourceMaxSeparation( positions=positions, noise_map=None, tracer=results.last.max_log_likelihood_tracer, ) positions_threshold = ( self.settings.settings_lens.auto_positions_factor * np.max( positions_fits.max_separation_of_source_plane_positions)) else: positions_threshold = self.settings.settings_lens.positions_threshold if (self.settings.settings_lens.auto_positions_minimum_threshold is not None and positions_threshold is not None): if (positions_threshold < self.settings.settings_lens. auto_positions_minimum_threshold) or (positions_threshold is None): positions_threshold = (self.settings.settings_lens. auto_positions_minimum_threshold) return positions_threshold
def check_positions_trace_within_threshold_via_tracer( self, positions, tracer): if not tracer.has_mass_profile or len(tracer.planes) == 1: return if positions is not None and self.positions_threshold is not None: positions_fit = fit_point_source.FitPositionsSourceMaxSeparation( positions=positions, noise_map=None, tracer=tracer) if not positions_fit.max_separation_within_threshold( self.positions_threshold): raise exc.RayTracingException
def positions_threshold_from(self, factor=1.0, minimum_threshold=None) -> float: """ Compute a new position threshold from these results corresponding to the image-plane multiple image positions of the maximum log likelihood `Tracer` ray-traced to the source-plane. First, we ray-trace forward the multiple-image's to the source-plane via the mass model to determine how far apart they are separated. We take the maximum source-plane separation of these points and multiple this by the auto_positions_factor to determine a new positions threshold. This value may also be rounded up to the input `auto_positions_minimum_threshold`. This is used for non-linear search chaining, specifically updating the position threshold of a new model-fit using the maximum likelihood model of a previous search. Parameters ---------- factor : float The value the computed threshold is multipled by to make the position threshold larger or smaller than the maximum log likelihood model's threshold. minimum_threshold : float The output threshold is rounded up to this value if it is below it, to avoid extremely small threshold values. Returns ------- float The maximum source plane separation of this results maximum likelihood `Tracer` multiple images multipled by `factor` and rounded up to the `threshold`. """ positions = self.image_plane_multiple_image_positions positions_fits = fit_point_source.FitPositionsSourceMaxSeparation( positions=positions, noise_map=None, tracer=self.max_log_likelihood_tracer) positions_threshold = factor * np.max( positions_fits.max_separation_of_source_plane_positions) if minimum_threshold is not None: if positions_threshold < minimum_threshold: return minimum_threshold return positions_threshold