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_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_combine_variables(self, hyper_combined):
result = MockResult()
hyper_galaxy_result = MockResult()
inversion_result = MockResult()
hyper_galaxy_result.variable = af.ModelMapper()
inversion_result.variable = af.ModelMapper()
hyper_galaxy_result.variable.hyper_galaxy = g.HyperGalaxy
hyper_galaxy_result.variable.pixelization = px.Pixelization()
inversion_result.variable.pixelization = px.Pixelization
inversion_result.variable.hyper_galaxy = g.HyperGalaxy()
result.hyper_galaxy = hyper_galaxy_result
result.inversion = inversion_result
variable = hyper_combined.combine_variables(result)
assert isinstance(variable.hyper_galaxy, af.PriorModel)
assert isinstance(variable.pixelization, af.PriorModel)
assert variable.hyper_galaxy.cls == g.HyperGalaxy
assert variable.pixelization.cls == px.Pixelization
def test_fully_qualified_paramnames(self):
mapper = af.ModelMapper()
galaxy_model = al.GalaxyModel(
redshift=0.5, light_profile=al.lp.EllipticalLightProfile
)
light_profile = galaxy_model.light_profile
mapper.galaxy_model = galaxy_model
assert light_profile.name_for_prior(light_profile.axis_ratio) == "axis_ratio"
assert light_profile.name_for_prior(light_profile.centre.centre_0) == "centre_0"
assert (
galaxy_model.name_for_prior(light_profile.axis_ratio)
== "light_profile_axis_ratio"
)
assert mapper.param_names[0] == "galaxy_model_light_profile_centre_0"
directory = os.path.dirname(os.path.realpath(__file__))
config = af.conf.DefaultPriorConfig(
"{}/../../{}".format(
directory, "test_files/config/galaxy_model/priors/default"
)
)
limit_config = af.conf.LimitConfig(
"{}/../../{}".format(
directory, "test_files/config/galaxy_model/priors/limit"
)
)
# Create a mapper. This can be used to convert values output by a non linear optimiser into class instances.
mapper = af.ModelMapper(config=config, limit_config=limit_config)
# Create a model_galaxy prior for the source model_galaxy. Here we are describing only the light profile of
# the source model_galaxy which comprises an elliptical exponential and elliptical sersic light profile.
source_galaxy_prior = al.GalaxyModel(
redshift=al.Redshift,
light_profile_one=al.light_profiles.EllipticalExponential,
light_profile_2=al.light_profiles.EllipticalSersic,
config=config,
limit_config=limit_config,
)
# Create a model_galaxy prior for the source model_galaxy. Here we are describing both the light and mass
# profiles. We've also stipulated that the centres of any galaxies generated using the model_galaxy prior
# should match.
lens_galaxy_prior = al.GalaxyModel(
redshift=al.Redshift,
def __init__(self, most_likely_fit=None):
self.most_likely_fit = most_likely_fit
self.analysis = MockAnalysis()
self.path_galaxy_tuples = []
self.model = af.ModelMapper()
self.mask = None
self.positions = None
def make_result(lens_data_7x7, instance):
return phase_imaging.PhaseImaging.Result(
constant=instance,
figure_of_merit=1.0,
previous_variable=af.ModelMapper(),
gaussian_tuples=None,
analysis=phase_imaging.PhaseImaging.Analysis(
lens_data=lens_data_7x7, cosmology=cosmo.Planck15, image_path=""
),
optimizer=None,
)
Combine the variable objects from all previous results in this combined hyper phase.
Iterates through the hyper names of the included hyper phases, extracting a result
for each name and adding the variable of that result to a new variable.
Parameters
----------
result
The last result (with attribute results associated with phases in this phase)
Returns
-------
combined_variable
A variable object including all variables from results in this phase.
"""
variable = af.ModelMapper()
for name in self.phase_names:
variable += getattr(result, name).variable
return variable
Combine the model objects from all previous results in this hyper_combined hyper_galaxies phase.
Iterates through the hyper_galaxies names of the included hyper_galaxies phases, extracting a result
for each name and adding the model of that result to a new model.
Parameters
----------
result
The last result (with attribute results associated with phases in this phase)
Returns
-------
combined_model
A model object including all models from results in this phase.
"""
model = af.ModelMapper()
for name in self.phase_names:
model += getattr(result, name).model
return model