-
Notifications
You must be signed in to change notification settings - Fork 28
/
test_galaxy_model_model_mapper.py
71 lines (56 loc) · 2.78 KB
/
test_galaxy_model_model_mapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import autolens as al
import os
import autofit as af
import autofit as af
class TestCase:
def test_integration(self):
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,
light_profile=al.light_profiles.EllipticalExponential,
mass_profile=al.mass_profiles.EllipticalExponential,
align_centres=True,
config=config,
limit_config=limit_config,
)
mapper.source_galaxy = source_galaxy_prior
mapper.lens_galaxy = lens_galaxy_prior
# Create a model instance. All the instances of the profile classes are created here. Normally we would do this
# using the output of a non linear search but in this case we are using the median values from the priors.
instance = mapper.instance_from_prior_medians()
# Recover model_galaxy instances. We can pass the model instance to model_galaxy priors to recover a fully
# constructed model_galaxy
source_galaxy = instance.source_galaxy
lens_galaxy = instance.lens_galaxy
# Let's just check that worked
assert len(source_galaxy.light_profiles) == 2
assert len(source_galaxy.mass_profiles) == 0
print(lens_galaxy.light_profiles)
assert len(lens_galaxy.light_profiles) == 1
assert len(lens_galaxy.mass_profiles) == 1
assert source_galaxy.redshift == 1.5
assert lens_galaxy.redshift == 1.5