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
3 changes: 1 addition & 2 deletions autolens/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@
from .lens.tracer import Tracer
from .lens.sensitivity import SubhaloSensitivityResult
from .lens.to_inversion import TracerToInversion
from .analysis.positions import PositionsLHResample
from .analysis.positions import PositionsLHPenalty
from .analysis.positions import PositionsLH
from .imaging.simulator import SimulatorImaging
from .imaging.fit_imaging import FitImaging
from .imaging.model.analysis import AnalysisImaging
Expand Down
28 changes: 13 additions & 15 deletions autolens/analysis/analysis/dataset.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
import logging
from typing import Optional, Union
from typing import List, Optional, Union

from autoconf import conf
from autoconf.dictable import to_dict, output_to_json
from autoconf.dictable import output_to_json

import autofit as af
import autoarray as aa
Expand All @@ -13,8 +13,7 @@

from autolens.analysis.analysis.lens import AnalysisLens
from autolens.analysis.result import ResultDataset
from autolens.analysis.positions import PositionsLHResample
from autolens.analysis.positions import PositionsLHPenalty
from autolens.analysis.positions import PositionsLH

from autolens import exc

Expand All @@ -27,9 +26,7 @@ class AnalysisDataset(AgAnalysisDataset, AnalysisLens):
def __init__(
self,
dataset,
positions_likelihood: Optional[
Union[PositionsLHResample, PositionsLHPenalty]
] = None,
positions_likelihood_list: Optional[List[PositionsLH]] = None,
adapt_image_maker: Optional[ag.AdaptImageMaker] = None,
cosmology: ag.cosmo.LensingCosmology = ag.cosmo.Planck15(),
settings_inversion: aa.SettingsInversion = None,
Expand All @@ -49,10 +46,11 @@ def __init__(
----------
dataset
The imaging, interferometer or other dataset that the model if fitted too.
positions_likelihood
An object which alters the likelihood function to include a term which accounts for whether
image-pixel coordinates in arc-seconds corresponding to the multiple images of the lensed source galaxy
trace close to one another in the source-plane.
positions_likelihood_list
Alters the likelihood function to include a term which accounts for whether image-pixel coordinates in
arc-seconds corresponding to the multiple images of each lensed source galaxy trace close to one another in
their source-plane. This is a list, as it may support multiple planes, where a positions likelihood object
is input for each plane (e.g. double source plane lensing).
adapt_images
Contains the adapt-images which are used to make a pixelization's mesh and regularization adapt to the
reconstructed galaxy's morphology.
Expand All @@ -62,7 +60,7 @@ def __init__(
Settings controlling how an inversion is fitted during the model-fit, for example which linear algebra
formalism is used.
raise_inversion_positions_likelihood_exception
If an inversion is used without the `positions_likelihood` it is likely a systematic solution will
If an inversion is used without the `positions_likelihood_list` it is likely a systematic solution will
be inferred, in which case an Exception is raised before the model-fit begins to inform the user
of this. This exception is not raised if this input is False, allowing the user to perform the model-fit
anyway.
Expand All @@ -78,7 +76,7 @@ def __init__(

AnalysisLens.__init__(
self=self,
positions_likelihood=positions_likelihood,
positions_likelihood_list=positions_likelihood_list,
cosmology=cosmology,
)

Expand Down Expand Up @@ -124,7 +122,7 @@ def raise_exceptions(self, model):

if has_pix:
if (
self.positions_likelihood is None
self.positions_likelihood_list is None
and self.raise_inversion_positions_likelihood_exception
and not conf.instance["general"]["test"][
"disable_positions_lh_inversion_check"
Expand All @@ -133,7 +131,7 @@ def raise_exceptions(self, model):
raise exc.AnalysisException(
"""
You have begun a model-fit which reconstructs the source using a pixelization.
However, you have not input a `positions_likelihood` object.
However, you have not input a `positions_likelihood_list` object.
It is likely your model-fit will infer an inaccurate solution.

Please read the following readthedocs page for a description of why this is, and how to set up
Expand Down
22 changes: 11 additions & 11 deletions autolens/analysis/analysis/lens.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import logging
import numpy as np
from typing import Dict, Optional, Union
from typing import Dict, List, Optional, Union

import autofit as af
import autoarray as aa
import autogalaxy as ag

from autolens.analysis.positions import PositionsLHResample
from autolens.analysis.positions import PositionsLHPenalty
from autolens.analysis.positions import PositionsLH
from autolens.lens.tracer import Tracer

from autolens.lens import tracer_util
Expand All @@ -22,9 +21,7 @@
class AnalysisLens:
def __init__(
self,
positions_likelihood: Optional[
Union[PositionsLHResample, PositionsLHPenalty]
] = None,
positions_likelihood_list: Optional[List[PositionsLH]] = None,
cosmology: ag.cosmo.LensingCosmology = ag.cosmo.Planck15(),
):
"""
Expand All @@ -43,7 +40,7 @@ def __init__(
The Cosmology assumed for this analysis.
"""
self.cosmology = cosmology
self.positions_likelihood = positions_likelihood
self.positions_likelihood_list = positions_likelihood_list

def tracer_via_instance_from(
self,
Expand Down Expand Up @@ -123,10 +120,13 @@ def log_likelihood_positions_overwrite_from(
The penalty value of the positions log likelihood, if the positions do not trace close in the source plane,
else a None is returned to indicate there is no penalty.
"""
if self.positions_likelihood is not None:
if self.positions_likelihood_list is not None:
try:
return self.positions_likelihood.log_likelihood_function_positions_overwrite(
instance=instance, analysis=self
)
log_likelihood = 0.0
for positions_likelihood in self.positions_likelihood_list:
log_likelihood += positions_likelihood.log_likelihood_function_positions_overwrite(
instance=instance, analysis=self
)
return log_likelihood
except (ValueError, np.linalg.LinAlgError) as e:
raise exc.FitException from e
6 changes: 3 additions & 3 deletions autolens/analysis/plotter_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def should_plot(name):

def image_with_positions(self, image: aa.Array2D, positions: aa.Grid2DIrregular):
"""
Visualizes the positions of a model-fit, where these positions are used to resample lens models where
Visualizes the positions of a model-fit, where these positions are used to penalize lens models where
the positions to do trace within an input threshold of one another in the source-plane.

Images are output to the `image` folder of the `image_path`. When used with a non-linear search the `image_path`
Expand All @@ -154,8 +154,8 @@ def image_with_positions(self, image: aa.Array2D, positions: aa.Grid2DIrregular)
----------
imaging
The imaging dataset whose image the positions are overlaid.
position
The 2D (y,x) arc-second positions used to resample inaccurate mass models.
positions
The 2D (y,x) arc-second positions used to penalize inaccurate mass models.
"""

def should_plot(name):
Expand Down
Loading
Loading