Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_defaults_background_noise(self):
# noinspection PyTypeChecker
phase = phase_extensions.InversionBackgroundNoisePhase(MockPhase())
constant = af.ModelInstance()
constant.hyper_background_noise = hd.HyperBackgroundNoise()
mapper = phase.make_variable(constant)
assert isinstance(mapper.hyper_background_noise, af.PriorModel)
assert mapper.hyper_background_noise.cls == hd.HyperBackgroundNoise
phase = MMPhase(
galaxies=dict(
lens=al.GalaxyModel(redshift=0.5, sersic=al.lp.EllipticalSersic)
),
non_linear_class=af.MultiNest,
phase_name="{}/phase1".format(name),
)
phase.optimizer.n_live_points = 20
phase.optimizer.sampling_efficiency = 0.8
phase.make_analysis(dataset=imaging)
sersic = phase.model.galaxies[0].sersic
assert isinstance(sersic, af.PriorModel)
assert isinstance(sersic.axis_ratio, float)
assert isinstance(sersic.phi, float)
assert isinstance(sersic.intensity, float)
assert isinstance(sersic.effective_radius, float)
assert isinstance(sersic.sersic_index, float)
def test__align_centre_to_lens_light_centre(self):
light = af.PriorModel(al.mp.SphericalIsothermal)
source = al.slam.SourceSetup(lens_light_centre=(1.0, 2.0))
light = source.align_centre_to_lens_light_centre(light=light)
assert light.centre == (1.0, 2.0)
def test_set_prior_model(self):
mapper = af.ModelMapper()
galaxy_model = al.GalaxyModel(
redshift=al.Redshift,
light_profile=al.light_profiles.EllipticalSersic,
mass_profile=al.mass_profiles.EllipticalSersic,
)
mapper.galaxy = galaxy_model
assert 16 == len(mapper.prior_tuples_ordered_by_id)
galaxy_model.light_profile = af.PriorModel(al.light_profiles.LightProfile)
assert 9 == len(mapper.prior_tuples_ordered_by_id)
def test_get_prior_model(self):
galaxy_model = al.GalaxyModel(
redshift=al.Redshift,
light_profile=al.light_profiles.EllipticalSersic,
mass_profile=al.mass_profiles.EllipticalSersic,
)
assert isinstance(galaxy_model.light_profile, af.PriorModel)
assert isinstance(galaxy_model.mass_profile, af.PriorModel)
def test__align_centre_to_lens_mass_centre(self):
mass = af.PriorModel(al.mp.SphericalIsothermal)
source = al.slam.SourceSetup(lens_mass_centre=(1.0, 2.0))
mass = source.align_centre_to_lens_mass_centre(mass=mass)
assert mass.centre == (1.0, 2.0)
The pipeline tool af.last is required to locate the previous source model, which requires an index based on the
pipelines that have run. For example, if the source model you wish to load from is 3 phases back (perhaps
because there were multiple phases in a Light pipeline preivously) this index should be 2.
Parameters
----------
source_as_model : bool
If *True* the source is returned as a *model* where the parameters are fitted for using priors of the
phase result it is loaded from. If *False*, it is an instance of that phase's result.
index : integer
The index (counting backwards from this phase) of the phase result used to setup the source.
"""
if self.hyper.hyper_galaxies:
hyper_galaxy = af.PriorModel(ag.HyperGalaxy)
hyper_galaxy.noise_factor = (
af.last.hyper_combined.model.galaxies.source.hyper_galaxy.noise_factor
)
hyper_galaxy.contribution_factor = (
af.last.hyper_combined.instance.optional.galaxies.source.hyper_galaxy.contribution_factor
)
hyper_galaxy.noise_power = (
af.last.hyper_combined.instance.optional.galaxies.source.hyper_galaxy.noise_power
)
else:
hyper_galaxy = None
if self.source.type_tag in "sersic":
The model would be set up with these fixed centres! We want to treat the centres as free parameters in this phase,
requiring us to unpack the prior passing and setup the models using a PriorModel.
"""
left_light = af.PriorModel(al.lp.EllipticalSersic)
left_light.elliptical_comps = (
phase1.result.model.galaxies.left_lens.light.elliptical_comps
)
left_light.intensity = phase1.result.model.galaxies.left_lens.light.intensity
left_light.effective_radius = (
phase1.result.model.galaxies.left_lens.light.effective_radius
)
left_light.sersic_index = phase1.result.model.galaxies.left_lens.light.sersic_index
left_mass = af.PriorModel(al.mp.EllipticalIsothermal)
left_mass.elliptical_comps = (
phase3.result.model.galaxies.left_lens.mass.elliptical_comps
)
left_mass.einstein_radius = (
phase3.result.model.galaxies.left_lens.mass.einstein_radius
)
left_lens = al.GalaxyModel(redshift=0.5, light=left_light, mass=left_mass)
right_light = af.PriorModel(al.lp.EllipticalSersic)
right_light.elliptical_comps = (
phase2.result.model.galaxies.right_lens.light.elliptical_comps
)
right_light.intensity = phase2.result.model.galaxies.right_lens.light.intensity
right_light.effective_radius = (
phase2.result.model.galaxies.right_lens.light.effective_radius
def is_mass_profile_class(cls):
"""
Parameters
----------
cls
Some object
Returns
-------
bool: is_mass_profile_class
True if cls is a class that inherits from mass profile
"""
return inspect.isclass(cls) and issubclass(cls, mass_profiles.MassProfile)
class GalaxyModel(af.PriorModel):
"""
@DynamicAttrs
"""
def __init__(
self,
redshift,
align_centres=False,
align_axis_ratios=False,
align_orientations=False,
pixelization=None,
regularization=None,
hyper_galaxy=None,
**kwargs
):
"""Class to produce Galaxy instances from sets of profile classes and other model-fitting attributes (e.g. \