コード例 #1
0
def make_pipeline(test_name):

    phase1 = ph.LensSourcePlanePhase(lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)),
                                     source_galaxies=dict(source_0=gm.GalaxyModel(sersic=lp.EllipticalSersic)),
                                     optimizer_class=nl.MultiNest, phase_name="{}/phase1".format(test_name))

    phase1.optimizer.const_efficiency_mode = True
    phase1.optimizer.n_live_points = 60
    phase1.optimizer.sampling_efficiency = 0.7

    class AddSourceGalaxyPhase(ph.LensSourcePlanePhase):

        def pass_priors(self, previous_results):

            self.lens_galaxies_lens = previous_results[0].variable.lens
            self.source_galaxies_source_0 = previous_results[0].variable.source_0

    phase2 = AddSourceGalaxyPhase(lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)),
                                  source_galaxies=dict(source_0=gm.GalaxyModel(sersic=lp.EllipticalSersic),
                                                       source_1=gm.GalaxyModel(sersic=lp.EllipticalSersic)),
                                  optimizer_class=nl.MultiNest, phase_name="{}/phase2".format(test_name))

    phase2.optimizer.const_efficiency_mode = True
    phase2.optimizer.n_live_points = 60
    phase2.optimizer.sampling_efficiency = 0.7

    return pl.PipelineImaging(test_name, phase1, phase2)
コード例 #2
0
def make_pipeline(test_name):
    class SensitivePhase(ph.SensitivityPhase):
        def pass_priors(self, previous_results):

            self.lens_galaxies.lens.mass.centre_0 = 0.0
            self.lens_galaxies.lens.mass.centre_1 = 0.0
            self.lens_galaxies.lens.mass.einstein_radius = 1.6

            self.source_galaxies.source.light.centre_0 = 0.0
            self.source_galaxies.source.light.centre_1 = 0.0
            self.source_galaxies.source.light.intensity = 1.0
            self.source_galaxies.source.light.effective_radius = 0.5
            self.source_galaxies.source.light.sersic_index = 1.0

            self.sensitive_galaxies.subhalo.mass.centre_0 = prior.UniformPrior(
                lower_limit=-2.0, upper_limit=2.0)
            self.sensitive_galaxies.subhalo.mass.centre_1 = prior.UniformPrior(
                lower_limit=-2.0, upper_limit=2.0)
            self.sensitive_galaxies.subhalo.mass.kappa_s = 0.1
            self.sensitive_galaxies.subhalo.mass.scale_radius = 5.0

    phase1 = SensitivePhase(
        lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.SphericalIsothermal)),
        source_galaxies=dict(source=gm.GalaxyModel(light=lp.SphericalSersic)),
        sensitive_galaxies=dict(subhalo=gm.GalaxyModel(mass=mp.SphericalNFW)),
        optimizer_class=nl.GridSearch,
        phase_name="{}/phase1".format(test_name))

    return pl.PipelineImaging(test_name, phase1)
コード例 #3
0
ファイル: lens_x2_galaxy.py プロジェクト: AshKelly/PyAutoLens
def make_pipeline(test_name):
    class LensPlanex2GalPhase(ph.LensPlanePhase):
        def pass_priors(self, previous_results):

            self.lens_galaxies.lens_0.light.centre_0 = -1.0
            self.lens_galaxies.lens_0.light.centre_1 = -1.0
            self.lens_galaxies.lens_1.light.centre_0 = 1.0
            self.lens_galaxies.lens_1.light.centre_1 = 1.0

    def mask_function(image):
        return msk.Mask.circular(shape=image.shape,
                                 pixel_scale=image.pixel_scale,
                                 radius_arcsec=5.)

    phase1 = LensPlanex2GalPhase(lens_galaxies=dict(
        lens_0=gm.GalaxyModel(light=lp.EllipticalSersic),
        lens_1=gm.GalaxyModel(light=lp.EllipticalSersic)),
                                 mask_function=mask_function,
                                 optimizer_class=nl.MultiNest,
                                 phase_name="{}/phase1".format(test_name))

    phase1.optimizer.const_efficiency_mode = True
    phase1.optimizer.n_live_points = 40
    phase1.optimizer.sampling_efficiency = 0.8

    return pl.PipelineImaging(test_name, phase1)
コード例 #4
0
def make_pipeline(test_name):
    class MMPhase(ph.LensPlanePhase):
        pass

    phase1 = MMPhase(
        lens_galaxies=dict(lens=gm.GalaxyModel(light=lp.EllipticalSersic)),
        optimizer_class=nl.MultiNest,
        phase_name="{}/phase1".format(test_name))

    phase1.optimizer.n_live_points = 20
    phase1.optimizer.sampling_efficiency = 0.8
    phase1.optimizer.importance_nested_sampling = False

    class MMPhase2(ph.LensPlanePhase):
        def pass_priors(self, previous_results):
            self.lens_galaxies = previous_results[0].variable.lens_galaxies

    phase2 = MMPhase2(
        lens_galaxies=dict(lens=gm.GalaxyModel(light=lp.EllipticalSersic)),
        optimizer_class=nl.MultiNest,
        phase_name="{}/phase2".format(test_name))

    phase2.optimizer.n_live_points = 20
    phase2.optimizer.sampling_efficiency = 0.8
    phase2.optimizer.importance_nested_sampling = False

    return pl.PipelineImaging(test_name, phase1, phase2)
コード例 #5
0
def make_pipeline(test_name):
    class MMPhase(ph.LensPlanePhase):
        def pass_priors(self, previous_results):

            self.lens_galaxies.lens.light.centre_0 = 1.0
            self.lens_galaxies.lens.light.centre_1 = 2.0

    phase1 = MMPhase(
        lens_galaxies=dict(lens=gm.GalaxyModel(light=lp.EllipticalSersic)),
        optimizer_class=nl.MultiNest,
        phase_name="{}/phase1".format(test_name))

    phase1.optimizer.const_efficiency_mode = True
    phase1.optimizer.n_live_points = 20
    phase1.optimizer.sampling_efficiency = 0.8

    class MMPhase2(ph.LensPlanePhase):
        def pass_priors(self, previous_results):

            self.lens_galaxies.lens.light.centre_0 = previous_results[
                0].variable.lens.light.centre_0
            self.lens_galaxies.lens.light.centre_1 = previous_results[
                0].variable.lens.light.centre_1

    phase2 = MMPhase2(
        lens_galaxies=dict(lens=gm.GalaxyModel(light=lp.EllipticalSersic)),
        optimizer_class=nl.MultiNest,
        phase_name="{}/phase2".format(test_name))

    phase2.optimizer.const_efficiency_mode = True
    phase2.optimizer.n_live_points = 20
    phase2.optimizer.sampling_efficiency = 0.8

    return pl.PipelineImaging(test_name, phase1, phase2)
コード例 #6
0
def make_pipeline(test_name):
    class SensitivePhase(ph.SensitivityPhase):
        def pass_priors(self, previous_results):

            self.lens_galaxies.lens.mass.centre_0 = 0.0
            self.lens_galaxies.lens.mass.centre_1 = 0.0
            self.lens_galaxies.lens.mass.einstein_radius = 1.6

            self.source_galaxies.source.pixelization.shape_0 = 8.0
            self.source_galaxies.source.pixelization.shape_1 = 8.0
            self.source_galaxies.source.regularization.coefficients_0 = 1.0

            self.sensitive_galaxies.subhalo.mass.centre_0 = prior.GaussianPrior(
                mean=0.0, sigma=1.0)
            self.sensitive_galaxies.subhalo.mass.centre_1 = prior.GaussianPrior(
                mean=0.0, sigma=1.0)
            self.sensitive_galaxies.subhalo.mass.kappa_s = 0.1
            self.sensitive_galaxies.subhalo.mass.scale_radius = 5.0

    phase1 = SensitivePhase(
        lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.SphericalIsothermal)),
        source_galaxies=dict(source=gm.GalaxyModel(
            pixelization=pix.Rectangular, regularization=reg.Constant)),
        sensitive_galaxies=dict(subhalo=gm.GalaxyModel(mass=mp.SphericalNFW)),
        optimizer_class=nl.MultiNest,
        phase_name="{}/phase1".format(test_name))

    phase1.optimizer.const_efficiency_mode = True

    return pl.PipelineImaging(test_name, phase1)
コード例 #7
0
def make_pipeline(test_name):
    class SensitivePhase(ph.SensitivityPhase):
        def pass_priors(self, previous_results):

            self.lens_galaxies.lens.mass.centre_0 = 0.0
            self.lens_galaxies.lens.mass.centre_1 = 0.0
            self.lens_galaxies.lens.mass.einstein_radius = 1.6

            self.source_galaxies.source.light.centre_0 = 0.0
            self.source_galaxies.source.light.centre_1 = 0.0
            self.source_galaxies.source.light.intensity = 1.0
            self.source_galaxies.source.light.effective_radius = 0.5
            self.source_galaxies.source.light.sersic_index = 1.0

            self.sensitive_galaxies.subhalo.mass.centre_0 = prior.GaussianPrior(
                mean=0.0, sigma=1.0)
            self.sensitive_galaxies.subhalo.mass.centre_1 = prior.GaussianPrior(
                mean=0.0, sigma=1.0)
            self.sensitive_galaxies.subhalo.mass.kappa_s = 0.1
            self.sensitive_galaxies.subhalo.mass.scale_radius = 5.0

    phase1 = SensitivePhase(
        lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.SphericalIsothermal)),
        source_galaxies=dict(source=gm.GalaxyModel(light=lp.SphericalSersic)),
        sensitive_galaxies=dict(subhalo=gm.GalaxyModel(mass=mp.SphericalNFW)),
        optimizer_class=nl.MultiNest,
        phase_name="{}/phase1".format(test_name))

    phase1.optimizer.const_efficiency_mode = True

    return pl.PipelineImaging(test_name, phase1)
コード例 #8
0
ファイル: test_phase.py プロジェクト: AshKelly/PyAutoLens
    def test__phase_can_receive_list_of_galaxy_models(self):
        phase = ph.LensPlanePhase(lens_galaxies=[
            gm.GalaxyModel(sersic=lp.EllipticalSersic,
                           sis=mp.SphericalIsothermal,
                           variable_redshift=True),
            gm.GalaxyModel(sis=mp.SphericalIsothermal, variable_redshift=True)
        ],
                                  optimizer_class=non_linear.MultiNest,
                                  phase_name='test_phase')

        instance = phase.optimizer.variable.instance_from_physical_vector([
            0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.8, 0.1, 0.2, 0.3, 0.4, 0.9,
            0.5, 0.7, 0.8
        ])

        assert instance.lens_galaxies[0].sersic.centre[0] == 0.2
        assert instance.lens_galaxies[0].sis.centre[0] == 0.1
        assert instance.lens_galaxies[0].sis.centre[1] == 0.2
        assert instance.lens_galaxies[0].sis.einstein_radius == 0.3
        assert instance.lens_galaxies[0].redshift == 0.4
        assert instance.lens_galaxies[1].sis.centre[0] == 0.9
        assert instance.lens_galaxies[1].sis.centre[1] == 0.5
        assert instance.lens_galaxies[1].sis.einstein_radius == 0.7
        assert instance.lens_galaxies[1].redshift == 0.8

        class LensPlanePhase2(ph.LensPlanePhase):
            # noinspection PyUnusedLocal
            def pass_models(self, previous_results):
                self.lens_galaxies[0].sis.einstein_radius = prior.Constant(
                    10.0)

        phase = LensPlanePhase2(lens_galaxies=[
            gm.GalaxyModel(sersic=lp.EllipticalSersic,
                           sis=mp.SphericalIsothermal,
                           variable_redshift=True),
            gm.GalaxyModel(sis=mp.SphericalIsothermal, variable_redshift=True)
        ],
                                optimizer_class=non_linear.MultiNest,
                                phase_name='test_phase')

        # noinspection PyTypeChecker
        phase.pass_models(None)

        instance = phase.optimizer.variable.instance_from_physical_vector([
            0.01, 0.02, 0.23, 0.04, 0.05, 0.06, 0.87, 0.1, 0.2, 0.4, 0.5, 0.5,
            0.7, 0.8
        ])
        instance += phase.optimizer.constant

        assert instance.lens_galaxies[0].sersic.centre[0] == 0.01
        assert instance.lens_galaxies[0].sis.centre[0] == 0.1
        assert instance.lens_galaxies[0].sis.centre[1] == 0.2
        assert instance.lens_galaxies[0].sis.einstein_radius == 10.0
        assert instance.lens_galaxies[0].redshift == 0.4
        assert instance.lens_galaxies[1].sis.centre[0] == 0.5
        assert instance.lens_galaxies[1].sis.centre[1] == 0.5
        assert instance.lens_galaxies[1].sis.einstein_radius == 0.7
        assert instance.lens_galaxies[1].redshift == 0.8
コード例 #9
0
ファイル: test_phase.py プロジェクト: AshKelly/PyAutoLens
    def test_duplication(self):
        phase = ph.LensSourcePlanePhase(lens_galaxies=[gm.GalaxyModel()],
                                        source_galaxies=[gm.GalaxyModel()],
                                        phase_name='test_phase')

        ph.LensSourcePlanePhase(phase_name='test_phase')

        assert phase.lens_galaxies is not None
        assert phase.source_galaxies is not None
コード例 #10
0
ファイル: test_phase.py プロジェクト: AshKelly/PyAutoLens
    def test_fit(self, ccd_data):
        clean_images()

        phase = ph.LensSourcePlanePhase(
            optimizer_class=NLO,
            lens_galaxies=[gm.GalaxyModel(light=lp.EllipticalSersic)],
            source_galaxies=[gm.GalaxyModel(light=lp.EllipticalSersic)],
            phase_name='test_phase')
        result = phase.run(data=ccd_data)
        assert isinstance(result.constant.lens_galaxies[0], g.Galaxy)
        assert isinstance(result.constant.source_galaxies[0], g.Galaxy)
コード例 #11
0
 def test_multiple_galaxies(self, mapper):
     mapper.galaxy_1 = gp.GalaxyModel(
         variable_redshift=True,
         light_profile=light_profiles.EllipticalDevVaucouleurs,
         mass_profile=mass_profiles.EllipticalCoredIsothermal,
     )
     mapper.galaxy_2 = gp.GalaxyModel(
         variable_redshift=True,
         light_profile=light_profiles.EllipticalDevVaucouleurs,
         mass_profile=mass_profiles.EllipticalCoredIsothermal,
     )
     assert len(mapper.prior_model_tuples) == 2
コード例 #12
0
def make_pipeline(test_name):
    class QuickPhase(ph.LensPlanePhase):
        def pass_priors(self, previous_results):

            self.lens_galaxies.lens.light.centre_0 = prior.UniformPrior(
                lower_limit=-0.01, upper_limit=0.01)
            self.lens_galaxies.lens.light.centre_1 = prior.UniformPrior(
                lower_limit=-0.01, upper_limit=0.01)
            self.lens_galaxies.lens.light.axis_ratio = prior.UniformPrior(
                lower_limit=0.79, upper_limit=0.81)
            self.lens_galaxies.lens.light.phi = prior.UniformPrior(
                lower_limit=-1.0, upper_limit=1.0)
            self.lens_galaxies.lens.light.intensity = prior.UniformPrior(
                lower_limit=0.99, upper_limit=1.01)
            self.lens_galaxies.lens.light.effective_radius = prior.UniformPrior(
                lower_limit=1.25, upper_limit=1.35)
            self.lens_galaxies.lens.light.sersic_index = prior.UniformPrior(
                lower_limit=3.95, upper_limit=4.05)

    phase1 = QuickPhase(
        lens_galaxies=dict(lens=gm.GalaxyModel(light=lp.EllipticalSersic)),
        optimizer_class=nl.MultiNest,
        phase_name="{}/phase1".format(test_name))

    phase1.optimizer.const_efficiency_mode = True
    phase1.optimizer.n_live_points = 40
    phase1.optimizer.sampling_efficiency = 0.8

    class GridPhase(ph.LensPlanePhase):
        def pass_priors(self, previous_results):

            self.lens_galaxies.lens.light.centre_0 = 0.0
            self.lens_galaxies.lens.light.centre_1 = 0.0
            self.lens_galaxies.lens.light.axis_ratio = previous_results[
                0].constant.lens.light.axis_ratio
            self.lens_galaxies.lens.light.phi = previous_results[
                0].constant.lens.light.phi
            self.lens_galaxies.lens.light.intensity = previous_results[
                0].constant.lens.light.intensity

            self.lens_galaxies.lens.light.effective_radius = prior.UniformPrior(
                lower_limit=0.0, upper_limit=4.0)
            self.lens_galaxies.lens.light.sersic_index = prior.UniformPrior(
                lower_limit=1.0, upper_limit=8.0)

    phase2 = GridPhase(
        lens_galaxies=dict(lens=gm.GalaxyModel(light=lp.EllipticalSersic)),
        optimizer_class=nl.GridSearch,
        phase_name=test_type + '/phase2')

    phase2.optimizer.const_efficiency_mode = True

    return pl.PipelineImaging(test_name, phase1, phase2)
コード例 #13
0
    def test_integration(self):
        directory = os.path.dirname(os.path.realpath(__file__))

        config = conf.DefaultPriorConfig(
            "{}/../../{}".format(directory,
                              "test_files/configs/galaxy_model/priors/default"))

        print(config.path)

        limit_config = conf.LimitConfig(
            "{}/../../{}".format(directory,
                              "test_files/configs/galaxy_model/priors/limit"))


        # Create a mapper. This can be used to convert values output by a non linear optimiser into class instances.
        mapper = mm.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 = gm.GalaxyModel(variable_redshift=True,
                                             light_profile_one=light_profiles.EllipticalExponential,
                                             light_profile_2=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 = gm.GalaxyModel(variable_redshift=True, light_profile=light_profiles.EllipticalExponential,
                                           mass_profile=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

        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
コード例 #14
0
def make_pipeline(test_name):

    phase1 = ph.LensSourcePlanePhase(
        lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)),
        source_galaxies=dict(source=gm.GalaxyModel(light=lp.EllipticalSersic)),
        optimizer_class=nl.MultiNest,
        phase_name="{}/phase1".format(test_name))

    phase1.optimizer.const_efficiency_mode = True
    phase1.optimizer.n_live_points = 60
    phase1.optimizer.sampling_efficiency = 0.8

    return pl.PipelineImaging(test_name, phase1)
コード例 #15
0
    def test_make_galaxy_from_constant_profile(self, mass_and_light):
        prior = gp.GalaxyModel(profile=mass_and_light)

        galaxy = prior.instance_for_arguments({})

        assert galaxy.light_profiles[0] == mass_and_light
        assert galaxy.mass_profiles[0] == mass_and_light
コード例 #16
0
 def test_init_to_model_mapper(self, mapper):
     mapper.galaxy_1 = gp.GalaxyModel(
         variable_redshift=True,
         light_profile=light_profiles.EllipticalDevVaucouleurs,
         mass_profile=mass_profiles.EllipticalCoredIsothermal,
     )
     assert len(mapper.prior_tuples_ordered_by_id) == 13
コード例 #17
0
def make_galaxy_prior(mapper, ):
    galaxy_prior_1 = gp.GalaxyModel(
        variable_redshift=True,
        light_profile=light_profiles.EllipticalDevVaucouleurs,
        mass_profile=mass_profiles.EllipticalCoredIsothermal)
    mapper.galaxy_1 = galaxy_prior_1
    return galaxy_prior_1
コード例 #18
0
def make_pipeline(test_name):
    phase1 = ph.LensPlanePhase(lens_galaxies=[gm.GalaxyModel(sersic=lp.EllipticalSersic)],
                               optimizer_class=nl.MultiNest, phase_name="{}/phase1".format(test_name))

    phase1.optimizer.const_efficiency_mode = True
    phase1.optimizer.n_live_points = 40
    phase1.optimizer.sampling_efficiency = 0.8

    phase1h = ph.LensLightHyperOnlyPhase(optimizer_class=nl.MultiNest, phase_name="{}/phase1h".format(test_name))

    class LensHyperPhase(ph.LensPlaneHyperPhase):
        def pass_priors(self, previous_results):
            phase1_results = previous_results[-1]
            phase1h_results = previous_results[-1].hyper
            self.lens_galaxies = phase1_results.variable.lens_galaxies
            self.lens_galaxies[0].hyper_galaxy = phase1h_results.constant.lens_galaxies[0].hyper_galaxy

    phase2 = LensHyperPhase(lens_galaxies=[], optimizer_class=nl.MultiNest,
                            phase_name="{}/phase2".format(test_name))

    phase2.optimizer.const_efficiency_mode = True
    phase2.optimizer.n_live_points = 40
    phase2.optimizer.sampling_efficiency = 0.8

    return pl.PipelineImaging(test_name, phase1, phase1h, phase2)
コード例 #19
0
    def test_fixed_mass_property(self):
        galaxy_prior = gp.GalaxyModel(
            variable_redshift=True,
            mass_profile=mass_profiles.SphericalNFW(),
        )

        assert len(galaxy_prior.constant_mass_profiles) == 1
コード例 #20
0
    def test_make_galaxy_from_variable_profile(self):
        galaxy_prior = gp.GalaxyModel(
            profile=light_and_mass_profiles.EllipticalSersic)

        arguments = {
            galaxy_prior.profile.centre.centre_0: 1.0,
            galaxy_prior.profile.centre.centre_1: 0.2,
            galaxy_prior.profile.axis_ratio: 0.4,
            galaxy_prior.profile.phi: 0.5,
            galaxy_prior.profile.intensity: 0.6,
            galaxy_prior.profile.effective_radius: 0.7,
            galaxy_prior.profile.sersic_index: 0.8,
            galaxy_prior.profile.mass_to_light_ratio: 3.0
        }

        galaxy = galaxy_prior.instance_for_arguments(arguments)

        assert galaxy.light_profiles[0] == galaxy.mass_profiles[0]
        assert isinstance(galaxy.light_profiles[0],
                          light_and_mass_profiles.EllipticalSersic)

        assert galaxy.mass_profiles[0].centre == (1., 0.2)
        assert galaxy.mass_profiles[0].axis_ratio == 0.4
        assert galaxy.mass_profiles[0].phi == 0.5
        assert galaxy.mass_profiles[0].intensity == 0.6
        assert galaxy.mass_profiles[0].effective_radius == 0.7
        assert galaxy.mass_profiles[0].sersic_index == 0.8
        assert galaxy.mass_profiles[0].mass_to_light_ratio == 3.
コード例 #21
0
    def test_gaussian_prior_model_for_arguments(self):
        galaxy_prior = gp.GalaxyModel(
            variable_redshift=True,
            align_centres=True,
            light_profile=light_profiles.EllipticalSersic,
            mass_profile=mass_profiles.SphericalIsothermal)

        redshift_prior = mm.GaussianPrior(1, 1)
        einstein_radius_prior = mm.GaussianPrior(4, 1)
        intensity_prior = mm.GaussianPrior(7, 1)

        arguments = {
            galaxy_prior.redshift.redshift: redshift_prior,
            galaxy_prior.mass_profile.centre.centre_0: mm.GaussianPrior(2, 1),
            galaxy_prior.mass_profile.centre.centre_1: mm.GaussianPrior(3, 1),
            galaxy_prior.mass_profile.einstein_radius: einstein_radius_prior,
            galaxy_prior.light_profile.axis_ratio: mm.GaussianPrior(5, 1),
            galaxy_prior.light_profile.phi: mm.GaussianPrior(6, 1),
            galaxy_prior.light_profile.intensity: intensity_prior,
            galaxy_prior.light_profile.effective_radius:
            mm.GaussianPrior(8, 1),
            galaxy_prior.light_profile.sersic_index: mm.GaussianPrior(9, 1)
        }

        gaussian_galaxy_prior_model = galaxy_prior.gaussian_prior_model_for_arguments(
            arguments)

        assert gaussian_galaxy_prior_model.redshift.redshift == redshift_prior
        assert gaussian_galaxy_prior_model.mass_profile.einstein_radius == einstein_radius_prior
        assert gaussian_galaxy_prior_model.light_profile.intensity == intensity_prior
コード例 #22
0
ファイル: deflections.py プロジェクト: AshKelly/PyAutoLens
def phase():

    pixel_scale = 0.1
    image_shape = (150, 150)

    tools.reset_paths(test_name=test_name, output_path=output_path)

    grid_stack = grids.GridStack.from_shape_pixel_scale_and_sub_grid_size(shape=image_shape, pixel_scale=pixel_scale,
                                                                          sub_grid_size=4)

    galaxy = g.Galaxy(mass=mp.SphericalIsothermal(centre=(0.0, 0.0), einstein_radius=1.0))

    deflections = galaxy_util.deflections_of_galaxies_from_grid(galaxies=[galaxy], grid=grid_stack.sub)
    deflections_y = grid_stack.regular.scaled_array_from_array_1d(array_1d=deflections[:,0])
    deflections_x = grid_stack.regular.scaled_array_from_array_1d(array_1d=deflections[:,1])

    noise_map = scaled_array.ScaledSquarePixelArray(array=np.ones(deflections_y.shape), pixel_scale=pixel_scale)

    data_y = gd.GalaxyData(image=deflections_y, noise_map=noise_map, pixel_scale=pixel_scale)
    data_x = gd.GalaxyData(image=deflections_x, noise_map=noise_map, pixel_scale=pixel_scale)

    phase = ph.GalaxyFitPhase(galaxies=dict(gal=gm.GalaxyModel(light=mp.SphericalIsothermal)), use_deflections=True,
                              sub_grid_size=4,
                              optimizer_class=nl.MultiNest, phase_name=test_name+'/')

    phase.run(galaxy_data=[data_y, data_x])
コード例 #23
0
    def test_fixed_light_property(self):
        galaxy_prior = gp.GalaxyModel(
            variable_redshift=True,
            light_profile=light_profiles.EllipticalSersic(),
        )

        assert len(galaxy_prior.constant_light_profiles) == 1
コード例 #24
0
ファイル: intensities.py プロジェクト: AshKelly/PyAutoLens
def phase():

    pixel_scale = 0.1
    image_shape = (150, 150)

    tools.reset_paths(test_name=test_name, output_path=output_path)

    grid_stack = grids.GridStack.from_shape_pixel_scale_and_sub_grid_size(
        shape=image_shape, pixel_scale=pixel_scale, sub_grid_size=4)

    galaxy = g.Galaxy(mass=lp.SphericalExponential(
        centre=(0.0, 0.0), intensity=1.0, effective_radius=0.5))

    intensities = galaxy_util.intensities_of_galaxies_from_grid(
        galaxies=[galaxy], grid=grid_stack.sub)
    intensities = grid_stack.regular.scaled_array_from_array_1d(
        array_1d=intensities)

    noise_map = scaled_array.ScaledSquarePixelArray(array=np.ones(
        intensities.shape),
                                                    pixel_scale=pixel_scale)

    data = gd.GalaxyData(image=intensities,
                         noise_map=noise_map,
                         pixel_scale=pixel_scale)

    phase = ph.GalaxyFitPhase(
        galaxies=dict(gal=gm.GalaxyModel(light=lp.SphericalExponential)),
        use_intensities=True,
        sub_grid_size=4,
        optimizer_class=nl.MultiNest,
        phase_name=test_name + '/')

    phase.run(galaxy_data=[data])
コード例 #25
0
    def test_get_prior_model(self):
        galaxy_prior = gp.GalaxyModel(
            variable_redshift=True,
            light_profile=light_profiles.EllipticalSersic,
            mass_profile=mass_profiles.EllipticalSersic)

        assert isinstance(galaxy_prior.light_profile, mm.PriorModel)
        assert isinstance(galaxy_prior.mass_profile, mm.PriorModel)
コード例 #26
0
def make_pipeline(pipeline_name):

    # This is the same phase 1 as the complex source pipeline, which we saw gave a good fit to the overall
    # structure of the lensed source and provided an accurate lens mass model.

    phase1 = ph.LensSourcePlanePhase(
        lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)),
        source_galaxies=dict(source=gm.GalaxyModel(light=lp.EllipticalSersic)),
        optimizer_class=nl.MultiNest,
        phase_name=pipeline_name + '/phase_1_initialize')

    phase1.optimizer.sampling_efficiency = 0.3
    phase1.optimizer.const_efficiency_mode = True

    # Now, in phase 2, lets use the lens mass model to fit the source with an inversion.

    class InversionPhase(ph.LensSourcePlanePhase):
        def pass_priors(self, previous_results):

            # We can customize the inversion's priors like we do our light and mass profiles.

            self.lens_galaxies.lens = previous_results[0].variable.lens
            self.source_galaxies.source.pixelization.shape_0 = mm.UniformPrior(
                lower_limit=20.0, upper_limit=40.0)
            self.source_galaxies.source.pixelization.shape_1 = mm.UniformPrior(
                lower_limit=20.0, upper_limit=40.0)

            # The expected value of the regularization coefficient depends on the details of the data reduction and
            # source galaxy. A broad log-uniform prior is thus an appropriate way to sample the large range of
            # possible values.
            self.source_galaxies.source.regularization.coefficients_0 = mm.LogUniformPrior(
                lower_limit=1.0e-6, upper_limit=10000.0)

    phase2 = InversionPhase(
        lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)),
        source_galaxies=dict(source=gm.GalaxyModel(
            pixelization=pix.Rectangular, regularization=reg.Constant)),
        optimizer_class=nl.MultiNest,
        phase_name=pipeline_name + '/phase_2_inversion')

    phase2.optimizer.sampling_efficiency = 0.3
    phase2.optimizer.const_efficiency_mode = True

    return pipeline.PipelineImaging(pipeline_name, phase1, phase2)
コード例 #27
0
    def test_fixed_regularization(self):
        galaxy_prior = gp.GalaxyModel(variable_redshift=True,
                                      pixelization=pixelizations.Voronoi(),
                                      regularization=regularization.Constant())

        arguments = {galaxy_prior.redshift.redshift: 2.0}

        galaxy = galaxy_prior.instance_for_arguments(arguments)

        assert galaxy.regularization.coefficients == (1., )
コード例 #28
0
ファイル: positions.py プロジェクト: AshKelly/PyAutoLens
def make_pipeline(test_name):

    phase1 = ph.PhasePositions(lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.SphericalIsothermal)),
                               optimizer_class=nl.MultiNest, phase_name="{}/phase1".format(test_name))

    phase1.optimizer.const_efficiency_mode = True
    phase1.optimizer.n_live_points = 20
    phase1.optimizer.sampling_efficiency = 0.1

    return pl.PipelinePositions(test_name, phase1)
コード例 #29
0
ファイル: test_phase.py プロジェクト: AshKelly/PyAutoLens
    def test_fit_priors_with_results(self, phase):
        argument_tuples = []

        galaxy_model_one = gm.GalaxyModel()
        galaxy_model_two = gm.GalaxyModel()

        new_galaxy_model_one = gm.GalaxyModel()
        new_galaxy_model_two = gm.GalaxyModel()

        new_galaxy_models = {
            galaxy_model_one: new_galaxy_model_one,
            galaxy_model_two: new_galaxy_model_two
        }

        def fitting_function(best_fit_galaxy, initial_galaxy_model):
            argument_tuples.append((best_fit_galaxy, initial_galaxy_model))
            return new_galaxy_models[initial_galaxy_model]

        phase.lens_galaxies = dict(galaxy_one=galaxy_model_one,
                                   galaxy_two=galaxy_model_two)

        instance_one = mm.ModelInstance()
        galaxy_one = g.Galaxy()
        instance_one.galaxy_one = galaxy_one
        instance_one.galaxy_two = g.Galaxy()
        results_one = MockResults(constant=instance_one)

        instance_two = mm.ModelInstance()
        galaxy_two = g.Galaxy()
        instance_two.galaxy_two = galaxy_two
        results_two = MockResults(constant=instance_two)

        assert phase.lens_galaxies.galaxy_one == galaxy_model_one
        assert phase.lens_galaxies.galaxy_two == galaxy_model_two

        phase.fit_priors_with_results([results_one, results_two],
                                      fitting_function)

        assert phase.lens_galaxies.galaxy_one == new_galaxy_model_one
        assert phase.lens_galaxies.galaxy_two == new_galaxy_model_two
        assert argument_tuples == [(galaxy_one, galaxy_model_one),
                                   (galaxy_two, galaxy_model_two)]
コード例 #30
0
    def test_fixed_mass(self):
        galaxy_prior = gp.GalaxyModel(
            variable_redshift=True,
            nass_profile=mass_profiles.SphericalNFW(),
        )

        arguments = {galaxy_prior.redshift.redshift: 2.0}

        galaxy = galaxy_prior.instance_for_arguments(arguments)

        assert len(galaxy.mass_profiles) == 1