def test_addition(self):
        phase_1 = DummyPhaseImaging("one")
        phase_2 = DummyPhaseImaging("two")
        phase_3 = DummyPhaseImaging("three")

        pipeline1 = al.PipelineImaging("", phase_1, phase_2)
        pipeline2 = al.PipelineImaging("", phase_3)

        assert (phase_1, phase_2, phase_3) == (pipeline1 + pipeline2).phases
    def test__hyper_mode_on__must_receive_mask(self):
        phase_1 = DummyPhaseImaging("one")
        phase_2 = DummyPhaseImaging("two")

        pipeline = al.PipelineImaging("", phase_1, phase_2, hyper_mode=False)

        pipeline.run(MockImagingData())

        pipeline = al.PipelineImaging("", phase_1, phase_2, hyper_mode=True)

        with pytest.raises(exc.PhaseException):
            pipeline.run(MockImagingData())

        pipeline.run(data=MockImagingData, mask=1.0)
Beispiel #3
0
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):

    phase1 = al.PhaseImaging(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(redshift=0.5,
                                light=al.light_profiles.EllipticalSersic,
                                light_1=None)),
        optimizer_class=optimizer_class,
    )

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

    phase2 = al.PhaseImaging(
        phase_name="phase_2",
        phase_folders=phase_folders,
        galaxies=dict(lens=al.GalaxyModel(
            redshift=0.5,
            light=al.light_profiles.EllipticalSersic,
            light_1=phase1.result.constant.galaxies.lens.light_1,
        )),
        optimizer_class=optimizer_class,
    )

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

    return al.PipelineImaging(name, phase1, phase2)
Beispiel #4
0
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):
    class SourcePix(al.PhaseImaging):
        def customize_priors(self, results):

            self.galaxies.lens.mass.centre.centre_0 = 0.0
            self.galaxies.lens.mass.centre.centre_1 = 0.0
            self.galaxies.lens.mass.einstein_radius_in_units = 1.6
            self.galaxies.source.pixelization.shape_0 = 20.0
            self.galaxies.source.pixelization.shape_1 = 20.0

    phase1 = SourcePix(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(redshift=0.5,
                                mass=al.mass_profiles.EllipticalIsothermal),
            source=al.GalaxyModel(
                redshift=1.0,
                pixelization=al.pixelizations.Rectangular,
                regularization=al.regularization.Constant,
            ),
        ),
        optimizer_class=optimizer_class,
    )

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

    return al.PipelineImaging(name, phase1)
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):
    class MMPhase(al.PhaseImaging):
        pass

    phase1 = MMPhase(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(lens=al.GalaxyModel(
            redshift=0.5, light=al.light_profiles.EllipticalSersic)),
        optimizer_class=optimizer_class,
    )

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

    class MMPhase2(al.PhaseImaging):
        def customize_priors(self, results):
            self.galaxies = results.from_phase("phase_1").variable.galaxies

    phase2 = MMPhase2(
        phase_name="phase_2",
        phase_folders=phase_folders,
        galaxies=dict(lens=al.GalaxyModel(
            redshift=0.5, light=al.light_profiles.EllipticalSersic)),
        optimizer_class=optimizer_class,
    )

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

    return al.PipelineImaging(name, phase1, phase2)
Beispiel #6
0
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):
    class MMPhase(al.PhaseImaging):
        def customize_priors(self, results):

            self.galaxies.lens.light_0.axis_ratio = 0.2
            self.galaxies.lens.light_0.phi = 90.0
            self.galaxies.lens.light_0.centre_0 = 1.0
            self.galaxies.lens.light_0.centre_1 = 2.0
            self.galaxies.lens.light_1.axis_ratio = 0.2
            self.galaxies.lens.light_1.phi = 90.0
            self.galaxies.lens.light_1.centre_0 = 1.0
            self.galaxies.lens.light_1.centre_1 = 2.0

    phase1 = MMPhase(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(lens=al.GalaxyModel(
            redshift=0.5,
            light_0=al.light_profiles.EllipticalSersic,
            light_1=al.light_profiles.EllipticalSersic,
        )),
        optimizer_class=optimizer_class,
    )

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

    return al.PipelineImaging(name, phase1)
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):
    class LensPlanex2GalPhase(al.PhaseImaging):
        def customize_priors(self, results):

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

    def mask_function(image):
        return al.Mask.circular(
            shape=image.shape, pixel_scale=image.pixel_scale, radius_arcsec=5.0
        )

    phase1 = LensPlanex2GalPhase(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(
            lens_0=al.GalaxyModel(
                redshift=0.5, light=al.light_profiles.EllipticalSersic
            ),
            lens_1=al.GalaxyModel(
                redshift=0.5, light=al.light_profiles.EllipticalSersic
            ),
        ),
        mask_function=mask_function,
        optimizer_class=optimizer_class,
    )

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

    return al.PipelineImaging(name, phase1)
Beispiel #8
0
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):
    class QuickPhase(al.PhaseImaging):
        def customize_priors(self, results):

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

    phase1 = QuickPhase(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(lens=al.GalaxyModel(
            redshift=0.5, light=al.light_profiles.EllipticalSersic)),
        optimizer_class=optimizer_class,
    )

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

    class GridPhase(al.PhaseImaging):
        def customize_priors(self, results):

            self.galaxies.lens.light.centre_0 = 0.0
            self.galaxies.lens.light.centre_1 = 0.0
            self.galaxies.lens.light.axis_ratio = results.from_phase(
                "phase_1").constant.lens.light.axis_ratio
            self.galaxies.lens.light.phi = results.from_phase(
                "phase_1").constant.lens.light.phi
            self.galaxies.lens.light.intensity = results.from_phase(
                "phase_1").constant.lens.light.intensity

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

    phase2 = GridPhase(
        phase_name="phase_2",
        phase_folders=phase_folders,
        galaxies=dict(lens=al.GalaxyModel(
            redshift=0.5, light=al.light_profiles.EllipticalSersic)),
        optimizer_class=af.GridSearch,
    )

    phase2.optimizer.const_efficiency_mode = True

    return al.PipelineImaging(name, phase1, phase2)
    def test_pass_mask(self):
        mask = MockMask()
        phase_1 = DummyPhaseImaging("one")
        phase_2 = DummyPhaseImaging("two")
        pipeline = al.PipelineImaging("", phase_1, phase_2)
        pipeline.run(data=MockImagingData(), mask=mask)

        assert phase_1.mask is mask
        assert phase_2.mask is mask
Beispiel #10
0
    def test_pass_positions(self):
        positions = [[[1.0, 1.0], [2.0, 2.0]]]
        phase_1 = DummyPhaseImaging("one")
        phase_2 = DummyPhaseImaging("two")
        pipeline = al.PipelineImaging("", phase_1, phase_2)
        pipeline.run(data=MockImagingData(), positions=positions)

        assert phase_1.positions == positions
        assert phase_2.positions == positions
Beispiel #11
0
    def test_run_pipeline(self):
        phase_1 = DummyPhaseImaging("one")
        phase_2 = DummyPhaseImaging("two")

        pipeline = al.PipelineImaging("", phase_1, phase_2)

        pipeline.run(MockImagingData())

        assert len(phase_2.results) == 2
Beispiel #12
0
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):
    class SourcePix(al.PhaseImaging):
        def customize_priors(self, results):

            self.galaxies.lens.mass.centre.centre_0 = 0.0
            self.galaxies.lens.mass.centre.centre_1 = 0.0
            self.galaxies.lens.mass.einstein_radius = 1.6

    phase1 = SourcePix(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(redshift=0.5,
                                mass=al.mass_profiles.EllipticalIsothermal),
            source=al.GalaxyModel(
                redshift=1.0,
                pixelization=al.pixelizations.VoronoiMagnification,
                regularization=al.regularization.Constant,
            ),
        ),
        optimizer_class=optimizer_class,
    )

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

    phase1 = phase1.extend_with_inversion_phase()

    class SourcePix(al.PhaseImaging):
        def customize_priors(self, results):

            self.galaxies.source = results.last.inversion.constant.galaxies.source

    phase2 = SourcePix(
        phase_name="phase_2",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5, mass=phase1.result.variable.galaxies.lens.mass),
            source=al.GalaxyModel(
                redshift=1.0,
                pixelization=al.pixelizations.VoronoiMagnification,
                regularization=al.regularization.Constant,
            ),
        ),
        optimizer_class=optimizer_class,
    )

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

    phase2 = phase2.extend_with_inversion_phase()

    return al.PipelineImaging(name, phase1, phase2)
Beispiel #13
0
    def test_files(self, mock_files):
        pipeline = al.PipelineImaging(
            "pipeline_name",
            DummyPhaseImaging(phase_name="phase_name", phase_path="phase_path"),
        )
        pipeline.run(MockImagingData(), data_name="data_name")

        assert (
            mock_files[1].text
            == "pipeline=pipeline_name\nphase=phase_name\ndata=data_name"
        )

        assert "phase_name///optimizer.pickle" in mock_files[2].filename
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):

    phase1 = al.PhaseImaging(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(lens=al.GalaxyModel(
            redshift=0.5, light=al.light_profiles.EllipticalSersic)),
        optimizer_class=optimizer_class,
    )

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

    phase1 = phase1.extend_with_multiple_hyper_phases(
        hyper_galaxy=True,
        include_background_sky=True,
        include_background_noise=True)

    class HyperLensPlanePhase(al.PhaseImaging):
        def customize_priors(self, results):

            self.galaxies = results.from_phase("phase_1").variable.galaxies

            self.galaxies.lens.hyper_galaxy = (
                results.last.hyper_combined.constant.galaxies.lens.hyper_galaxy
            )

            self.hyper_image_sky = results.last.hyper_combined.constant.hyper_image_sky

            self.hyper_background_noise = (
                results.last.hyper_combined.constant.hyper_background_noise)

    phase2 = HyperLensPlanePhase(
        phase_name="phase_2",
        phase_folders=phase_folders,
        galaxies=dict(lens=al.GalaxyModel(
            redshift=0.5,
            light=phase1.result.variable.galaxies.lens.light,
            hyper_galaxy=al.HyperGalaxy,
        )),
        optimizer_class=optimizer_class,
    )

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

    return al.PipelineImaging(name, phase1, phase2)
Beispiel #15
0
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):

    phase1 = al.PhaseImaging(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(lens=al.GalaxyModel(
            redshift=0.5, sersic=al.light_profiles.EllipticalSersic)),
        psf_shape=(3, 3),
        optimizer_class=optimizer_class,
    )

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

    return al.PipelineImaging(name, phase1)
Beispiel #16
0
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):
    class MMPhase(al.PhaseImaging):
        def customize_priors(self, results):

            self.galaxies.lens.sersic.centre_0 = 0.0
            self.galaxies.lens.sersic.centre_1 = 0.0
            self.galaxies.lens.sersic.axis_ratio = af.UniformPrior(
                lower_limit=-0.5, upper_limit=0.1)
            self.galaxies.lens.sersic.phi = 90.0
            self.galaxies.lens.sersic.intensity = af.UniformPrior(
                lower_limit=-0.5, upper_limit=0.1)
            self.galaxies.lens.sersic.effective_radius = 1.3
            self.galaxies.lens.sersic.sersic_index = 3.0

    phase1 = MMPhase(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(lens=al.GalaxyModel(
            redshift=0.5, sersic=al.light_profiles.EllipticalSersic)),
        optimizer_class=optimizer_class,
    )

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

    class MMPhase(al.PhaseImaging):
        def customize_priors(self, results):

            self.galaxies.lens.sersic.intensity = results.from_phase(
                "phase_1").variable.lens.sersic.intensity
            self.galaxies.lens = results.from_phase("phase_1").variable.lens

    phase2 = MMPhase(
        phase_name="phase_2",
        phase_folders=phase_folders,
        galaxies=dict(lens=al.GalaxyModel(
            redshift=0.5, sersic=al.light_profiles.EllipticalSersic)),
        optimizer_class=optimizer_class,
    )

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

    return al.PipelineImaging(name, phase1, phase2)
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):
    class MMPhase(al.PhaseImaging):
        pass

    phase1 = MMPhase(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(
            lens_0=al.GalaxyModel(redshift=0.5,
                                  light=al.light_profiles.EllipticalSersic),
            lens_1=al.GalaxyModel(redshift=0.5,
                                  light=al.light_profiles.EllipticalSersic),
        ),
        optimizer_class=optimizer_class,
    )

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

    class MMPhase2(al.PhaseImaging):
        def customize_priors(self, results):

            self.galaxies.lens_0 = results.from_phase(
                "phase_1").variable.lens_0
            self.galaxies.lens_1 = results.from_phase(
                "phase_1").variable.lens_1

    phase2 = MMPhase2(
        phase_name="phase_2",
        phase_folders=phase_folders,
        galaxies=dict(
            lens_0=al.GalaxyModel(redshift=0.5,
                                  light=al.light_profiles.EllipticalSersic),
            lens_1=al.GalaxyModel(redshift=0.5,
                                  light=al.light_profiles.EllipticalSersic),
        ),
        optimizer_class=optimizer_class,
    )

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

    return al.PipelineImaging(name, phase1, phase2)
Beispiel #18
0
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):

    phase1 = al.PhaseImaging(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(redshift=0.5,
                                mass=al.mass_profiles.EllipticalIsothermal),
            source=al.GalaxyModel(redshift=1.0,
                                  light=al.light_profiles.EllipticalSersic),
        ),
        optimizer_class=optimizer_class,
    )

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

    return al.PipelineImaging(name, phase1)
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):

    phase1 = al.PhaseImaging(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(lens=al.GalaxyModel(
            redshift=0.5,
            light=al.light_profiles.EllipticalSersic(
                effective_radius=af.UniformPrior(lower_limit=0.0,
                                                 upper_limit=4.0)),
        )),
        optimizer_class=optimizer_class,
    )

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

    return al.PipelineImaging(name, phase1)
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):
    class GridPhase(af.as_grid_search(al.PhaseImaging, parallel=True)):
        @property
        def grid_priors(self):
            return [
                self.variable.galaxies.subhalo.mass.centre_0,
                self.variable.galaxies.subhalo.mass.centre_1,
            ]

        def customize_priors(self, results):

            ### Lens Subhalo, Adjust priors to physical masses (10^6 - 10^10) and concentrations (6-24)

            self.galaxies.subhalo.mass.kappa_s = af.UniformPrior(
                lower_limit=0.0005, upper_limit=0.2)
            self.galaxies.subhalo.mass.centre_0 = af.UniformPrior(
                lower_limit=-2.0, upper_limit=2.0)
            self.galaxies.subhalo.mass.centre_1 = af.UniformPrior(
                lower_limit=-2.0, upper_limit=2.0)

    phase1 = GridPhase(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(redshift=0.5,
                                mass=al.mass_profiles.EllipticalIsothermal),
            subhalo=al.GalaxyModel(
                redshift=0.5,
                mass=al.mass_profiles.SphericalTruncatedNFWChallenge),
            source=al.GalaxyModel(redshift=1.0,
                                  light=al.light_profiles.EllipticalSersic),
        ),
        optimizer_class=optimizer_class,
        number_of_steps=2,
    )

    phase1.optimizer.const_efficiency_mode = True

    return al.PipelineImaging(name, phase1)
Beispiel #21
0
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):
    class MMPhase(al.PhaseImaging):
        pass

    phase1 = MMPhase(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(lens=al.GalaxyModel(
            redshift=0.5,
            light_0=al.light_profiles.EllipticalSersic,
            light_1=al.light_profiles.EllipticalSersic,
            mass=al.mass_profiles.EllipticalIsothermal,
            align_centres=True,
        )),
        optimizer_class=optimizer_class,
    )

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

    return al.PipelineImaging(name, phase1)
Beispiel #22
0
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):
    class MMPhase(al.PhaseImaging):
        def customize_priors(self, results):
            self.galaxies.lens.light.intensity = self.galaxies.lens.mass.einstein_radius

    phase1 = MMPhase(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5,
                light=al.light_profiles.EllipticalSersic,
                mass=al.mass_profiles.SphericalIsothermal,
            )
        ),
        optimizer_class=optimizer_class,
    )

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

    return al.PipelineImaging(name, phase1)
def make_pipeline(
    name,
    phase_folders,
    pipeline_align_light_dark_centre=True,
    optimizer_class=af.MultiNest,
):

    phase1 = al.PhaseImaging(
        phase_name="phase_1__lens_sersic",
        phase_folders=phase_folders,
        galaxies=dict(lens=al.GalaxyModel(
            redshift=0.5, light=al.light_profiles.EllipticalSersic)),
        optimizer_class=optimizer_class,
    )

    # You'll see these lines throughout all of the example pipelines. They are used to make MultiNest sample the \
    # non-linear parameter space faster (if you haven't already, checkout the tutorial '' in howtolens/chapter_2).

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

    ### PHASE 2 ###

    # In phase 2, we will fit the lens galaxy's mass and source galaxy's light, where we:

    # 1) Use a lens-subtracted image generated by subtracting model lens galaxy image from phase 1.
    # 2) Initialize the priors on the centre of the lens galaxy's mass-profile by linking them to those inferred for \
    #    its light profile in phase 1.
    # 3) Have the option to use an annular mask removing the central light, if the inner_mask_radii parametr is input.

    class LensSubtractedPhase(al.PhaseImaging):
        def customize_priors(self, results):

            ## Lens Light Sersic -> Sersic ##

            self.galaxies.lens.light = results.from_phase(
                "phase_1__lens_sersic").constant.galaxies.lens.light

            ## Lens Mass, Move centre priors to centre of lens light ###

            self.galaxies.lens.mass.centre = (
                results.from_phase("phase_1__lens_sersic").variable_absolute(
                    a=0.1).galaxies.lens.light.centre)

    phase2 = LensSubtractedPhase(
        phase_name="phase_2__lens_sie__source_sersic",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5,
                light=al.light_profiles.EllipticalSersic,
                mass=al.mass_profiles.EllipticalIsothermal,
                shear=al.mass_profiles.ExternalShear,
            ),
            source=al.GalaxyModel(redshift=1.0,
                                  light=al.light_profiles.EllipticalSersic),
        ),
        optimizer_class=optimizer_class,
    )

    phase2.optimizer.const_efficiency_mode = False
    phase2.optimizer.n_live_points = 50
    phase2.optimizer.sampling_efficiency = 0.3

    ### PHASE 3 ###

    # In phase 3, we will fit simultaneously the lens and source galaxies, where we:

    # 1) Initialize the lens's light, mass, shear and source's light using the results of phases 1 and 2.
    # 2) Use a circular mask, to fully capture the lens and source light.

    class LensSourcePhase(al.PhaseImaging):
        def customize_priors(self, results):

            ## Lens Light, Sersic -> Sersic ###

            self.galaxies.lens.light = results.from_phase(
                "phase_1__lens_sersic").variable.galaxies.lens.light

            ## Lens Mass, SIE -> SIE, Shear -> Shear ###

            self.galaxies.lens.mass = results.from_phase(
                "phase_2__lens_sie__source_sersic").variable.galaxies.lens.mass

            self.galaxies.lens.shear = results.from_phase(
                "phase_2__lens_sie__source_sersic"
            ).variable.galaxies.lens.shear

            ### Source Light, Sersic -> Sersic ###

            self.galaxies.source = results.from_phase(
                "phase_2__lens_sie__source_sersic").variable.galaxies.source

    phase3 = LensSourcePhase(
        phase_name="phase_3__lens_sersic_sie__source_sersic",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5,
                light=al.light_profiles.EllipticalSersic,
                mass=al.mass_profiles.EllipticalIsothermal,
                shear=al.mass_profiles.ExternalShear,
            ),
            source=al.GalaxyModel(redshift=1.0,
                                  light=al.light_profiles.EllipticalSersic),
        ),
        optimizer_class=optimizer_class,
    )

    phase3.optimizer.const_efficiency_mode = True
    phase3.optimizer.n_live_points = 75
    phase3.optimizer.sampling_efficiency = 0.3

    ### PHASE 1 ###

    # In phase 1, we will fit the lens galaxy's light and mass and one source galaxy, where we:

    # 1) Pass priors on the lens galaxy's light using the EllipticalSersic of the previous pipeline.
    # 2) Pass priors on the lens galaxy's SphericalNFW mass profile's centre using the EllipticalIsothermal fit of the
    #    previous pipeline, if the NFW centre is a free parameter.
    # 3) Pass priors on the lens galaxy's shear using the ExternalShear fit of the previous pipeline.
    # 4) Pass priors on the source galaxy's light using the EllipticalSersic of the previous pipeline.

    class LensSourcePhase(al.PhaseImaging):
        def customize_priors(self, results):

            ### Lens Light, Sersic -> Sersic ###

            self.galaxies.lens.light_mass.centre = results.from_phase(
                "phase_3__lens_sersic_sie__source_sersic"
            ).variable.galaxies.lens.light.centre

            self.galaxies.lens.light_mass.axis_ratio = results.from_phase(
                "phase_3__lens_sersic_sie__source_sersic"
            ).variable.galaxies.lens.light.axis_ratio

            self.galaxies.lens.light_mass.phi = results.from_phase(
                "phase_3__lens_sersic_sie__source_sersic"
            ).variable.galaxies.lens.light.phi

            self.galaxies.lens.light_mass.intensity = results.from_phase(
                "phase_3__lens_sersic_sie__source_sersic"
            ).variable.galaxies.lens.light.intensity

            self.galaxies.lens.light_mass.effective_radius = results.from_phase(
                "phase_3__lens_sersic_sie__source_sersic"
            ).variable.galaxies.lens.light.effective_radius

            self.galaxies.lens.light_mass.sersic_index = results.from_phase(
                "phase_3__lens_sersic_sie__source_sersic"
            ).variable.galaxies.lens.light.sersic_index

            ### Lens Mass, SIE ->  NFW ###

            if pipeline_align_light_dark_centre:

                self.galaxies.lens.dark.centre = self.galaxies.light_mass.centre

            elif not pipeline_align_light_dark_centre:

                self.galaxies.lens.dark.centre = (results.from_phase(
                    "phase_3__lens_sersic_sie__source_sersic"
                ).variable_absolute(a=0.05).galaxies.lens.mass.centre)

            ### Lens Shear, Shear -> Shear ###

            self.galaxies.lens.shear = results.from_phase(
                "phase_3__lens_sersic_sie__source_sersic"
            ).variable.galaxies.lens.shear

            ### Source Light, Sersic -> Sersic ###

            self.galaxies.source = results.from_phase(
                "phase_3__lens_sersic_sie__source_sersic"
            ).variable.galaxies.source

    phase4 = LensSourcePhase(
        phase_name="phase_4",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5,
                light_mass=al.light_and_mass_profiles.EllipticalSersic,
                dark=al.mass_profiles.SphericalNFW,
                shear=al.mass_profiles.ExternalShear,
            ),
            source=al.GalaxyModel(redshift=1.0,
                                  light=al.light_profiles.EllipticalSersic),
        ),
        optimizer_class=optimizer_class,
    )

    phase4.optimizer.const_efficiency_mode = True
    phase4.optimizer.n_live_points = 75
    phase4.optimizer.sampling_efficiency = 0.2

    return al.PipelineImaging(name, phase1, phase2, phase3, phase4)
Beispiel #24
0
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):

    phase1 = al.PhaseImaging(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5, mass=al.mass_profiles.EllipticalIsothermal
            ),
            source=al.GalaxyModel(
                redshift=1.0, light=al.light_profiles.EllipticalSersic
            ),
        ),
        optimizer_class=optimizer_class,
    )

    phase2 = al.PhaseImaging(
        phase_name="phase_2_weighted_regularization",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5,
                mass=phase1.constant.galaxies.lens.mass,
                shear=phase1.constant.galaxies.lens.shear,
            ),
            source=al.GalaxyModel(
                redshift=1.0,
                pixelization=al.pixelizations.VoronoiBrightnessImage,
                regularization=al.regularization.AdaptiveBrightness,
            ),
        ),
        optimizer_class=optimizer_class,
    )

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

    phase3 = al.PhaseImaging(
        phase_name="phase_3",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5,
                mass=phase1.variable.galaxies.lens.mass,
                shear=phase1.variable.galaxies.lens.shear,
            ),
            source=al.GalaxyModel(
                redshift=1.0,
                pixelization=phase2.constant.galaxies.source.pixelization,
                regularization=phase2.constant.galaxies.source.regularization,
            ),
        ),
        optimizer_class=optimizer_class,
    )

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

    phase4 = al.PhaseImaging(
        phase_name="phase_4_weighted_regularization",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5,
                mass=phase3.constant.galaxies.lens.mass,
                shear=phase3.constant.galaxies.lens.shear,
            ),
            source=al.GalaxyModel(
                redshift=1.0,
                pixelization=phase2.variable.galaxies.source.pixelization,
                regularization=phase2.variable.galaxies.source.pixelization,
            ),
        ),
        optimizer_class=optimizer_class,
    )

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

    return al.PipelineImaging(name, phase1, phase2, phase3, phase4)
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):
    class MMPhase(al.PhaseImaging):

        pass

    phase1 = MMPhase(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(lens=al.GalaxyModel(
            redshift=0.5, light=al.light_profiles.EllipticalSersic)),
        optimizer_class=optimizer_class,
    )

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

    class MMPhase2(al.PhaseImaging):
        def customize_priors(self, results):

            centre_value = results.from_phase(
                "phase_1").constant.galaxies.lens.light.centre
            self.galaxies.lens.light.centre.centre_0 = af.GaussianPrior(
                mean=centre_value[0], sigma=0.5)
            self.galaxies.lens.light.centre.centre_1 = af.GaussianPrior(
                mean=centre_value[1], sigma=0.5)

            intensity_value = results.from_phase(
                "phase_1").constant.galaxies.lens.light.intensity
            self.galaxies.lens.light.intensity = af.GaussianPrior(
                mean=intensity_value, sigma=1.0)

            effective_radius_value = results.from_phase(
                "phase_1").constant.galaxies.lens.light.effective_radius
            self.galaxies.lens.light.effective_radius = af.GaussianPrior(
                mean=effective_radius_value, sigma=2.0)

            sersic_index_value = results.from_phase(
                "phase_1").constant.galaxies.lens.light.sersic_index
            self.galaxies.lens.light.sersic_index = af.GaussianPrior(
                mean=sersic_index_value, sigma=2.0)

            axis_ratio_value = results.from_phase(
                "phase_1").constant.galaxies.lens.light.axis_ratio
            self.galaxies.lens.light.axis_ratio = af.GaussianPrior(
                mean=axis_ratio_value, sigma=0.3)

            phi_value = results.from_phase(
                "phase_1").constant.galaxies.lens.light.phi
            self.galaxies.lens.light.phi = af.GaussianPrior(mean=phi_value,
                                                            sigma=30.0)

    phase2 = MMPhase2(
        phase_name="phase_2",
        phase_folders=phase_folders,
        galaxies=dict(lens=al.GalaxyModel(
            redshift=0.5, light=al.light_profiles.EllipticalSersic)),
        optimizer_class=optimizer_class,
    )

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

    return al.PipelineImaging(name, phase1, phase2)
Beispiel #26
0
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):
    class QuickPhase(al.PhaseImaging):
        def customize_priors(self, results):

            self.galaxies.lens.mass.centre_0 = af.UniformPrior(
                lower_limit=-0.01, upper_limit=0.01)
            self.galaxies.lens.mass.centre_1 = af.UniformPrior(
                lower_limit=-0.01, upper_limit=0.01)
            self.galaxies.lens.mass.axis_ratio = af.UniformPrior(
                lower_limit=0.65, upper_limit=0.75)
            self.galaxies.lens.mass.phi = af.UniformPrior(lower_limit=40.0,
                                                          upper_limit=50.0)
            self.galaxies.lens.mass.einstein_radius = af.UniformPrior(
                lower_limit=1.55, upper_limit=1.65)

            self.galaxies.source.light.centre_0 = af.UniformPrior(
                lower_limit=-0.01, upper_limit=0.01)
            self.galaxies.source.light.centre_1 = af.UniformPrior(
                lower_limit=-0.01, upper_limit=0.01)
            self.galaxies.source.light.axis_ratio = af.UniformPrior(
                lower_limit=0.75, upper_limit=0.85)
            self.galaxies.source.light.phi = af.UniformPrior(lower_limit=50.0,
                                                             upper_limit=70.0)
            self.galaxies.source.light.intensity = af.UniformPrior(
                lower_limit=0.35, upper_limit=0.45)
            self.galaxies.source.light.effective_radius = af.UniformPrior(
                lower_limit=0.45, upper_limit=0.55)
            self.galaxies.source.light.sersic_index = af.UniformPrior(
                lower_limit=0.9, upper_limit=1.1)

    phase1 = QuickPhase(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(redshift=0.5,
                                mass=al.mass_profiles.EllipticalIsothermal),
            source=al.GalaxyModel(redshift=1.0,
                                  light=al.light_profiles.EllipticalSersic),
        ),
        optimizer_class=optimizer_class,
    )

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

    class GridPhase(af.as_grid_search(al.PhaseImaging)):
        @property
        def grid_priors(self):
            return [
                self.variable.galaxies.subhalo.mass.centre_0,
                self.variable.galaxies.subhalo.mass.centre_1,
            ]

        def customize_priors(self, results):

            ### Lens Mass, PL -> PL, Shear -> Shear ###

            # self.galaxies.lens = results.from_phase('phase_1').\
            #     constant.galaxies.lens

            ### Lens Subhalo, Adjust priors to physical masses (10^6 - 10^10) and concentrations (6-24)

            self.galaxies.subhalo.mass.mass_at_200 = af.LogUniformPrior(
                lower_limit=10.0e6, upper_limit=10.0e9)

            self.galaxies.subhalo.mass.centre_0 = af.UniformPrior(
                lower_limit=-2.0, upper_limit=2.0)
            self.galaxies.subhalo.mass.centre_1 = af.UniformPrior(
                lower_limit=-2.0, upper_limit=2.0)

            ### Source Light, Sersic -> Sersic ###

            self.galaxies.source.light.centre = (
                results.from_phase("phase_1").variable_absolute(
                    a=0.05).galaxies.source.light.centre)

            self.galaxies.source.light.intensity = (
                results.from_phase("phase_1").variable_relative(
                    r=0.5).galaxies.source.light.intensity)

            self.galaxies.source.light.effective_radius = (
                results.from_phase("phase_1").variable_relative(
                    r=0.5).galaxies.source.light.effective_radius)

            self.galaxies.source.light.sersic_index = (
                results.from_phase("phase_1").variable_relative(
                    r=0.5).galaxies.source.light.sersic_index)

            self.galaxies.source.light.axis_ratio = (
                results.from_phase("phase_1").variable_absolute(
                    a=0.1).galaxies.source.light.axis_ratio)

            self.galaxies.source.light.phi = (
                results.from_phase("phase_1").variable_absolute(
                    a=20.0).galaxies.source.light.phi)

    phase2 = GridPhase(
        phase_name="phase_2",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(redshift=0.5,
                                mass=al.mass_profiles.EllipticalIsothermal),
            subhalo=al.GalaxyModel(
                redshift=0.5,
                mass=al.mass_profiles.SphericalTruncatedNFWChallenge),
            source=al.GalaxyModel(redshift=1.0,
                                  light=al.light_profiles.EllipticalSersic),
        ),
        optimizer_class=optimizer_class,
        number_of_steps=2,
    )

    phase2.optimizer.const_efficiency_mode = True

    return al.PipelineImaging(name, phase1, phase2)
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):
    class Phase1(al.PhaseImaging):
        def customize_priors(self, results):
            self.galaxies.source.light.sersic_index = af.UniformPrior(3.9, 4.1)

    phase1 = Phase1(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5,
                mass=al.mass_profiles.EllipticalIsothermal,
                shear=al.mass_profiles.ExternalShear,
            ),
            source=al.GalaxyModel(redshift=1.0,
                                  light=al.light_profiles.EllipticalSersic),
        ),
        optimizer_class=optimizer_class,
    )

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

    phase1 = phase1.extend_with_multiple_hyper_phases(
        hyper_galaxy=True,
        include_background_sky=True,
        include_background_noise=True)

    class InversionPhase(al.PhaseImaging):
        def customize_priors(self, results):
            ## Lens Mass, SIE -> SIE, Shear -> Shear ###

            self.galaxies.lens.hyper_galaxy = (
                results.last.hyper_combined.constant.galaxies.lens.hyper_galaxy
            )

            self.galaxies.source.hyper_galaxy = (
                results.last.hyper_combined.constant.galaxies.source.
                hyper_galaxy)

    phase2 = InversionPhase(
        phase_name="phase_2_weighted_regularization",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5,
                mass=phase1.result.constant.galaxies.lens.mass,
                shear=phase1.result.constant.galaxies.lens.shear,
            ),
            source=al.GalaxyModel(
                redshift=1.0,
                pixelization=al.pixelizations.VoronoiBrightnessImage,
                regularization=al.regularization.AdaptiveBrightness,
            ),
        ),
        optimizer_class=optimizer_class,
    )

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

    phase2 = phase2.extend_with_multiple_hyper_phases(
        hyper_galaxy=True,
        include_background_sky=True,
        include_background_noise=True,
        inversion=True,
    )

    class InversionPhase(al.PhaseImaging):
        def customize_priors(self, results):
            ## Lens Mass, SIE -> SIE, Shear -> Shear ###

            self.galaxies.lens.hyper_galaxy = (
                results.last.hyper_combined.constant.galaxies.lens.hyper_galaxy
            )

            self.galaxies.source.hyper_galaxy = (
                results.last.hyper_combined.constant.galaxies.source.
                hyper_galaxy)

    phase3 = InversionPhase(
        phase_name="phase_3",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5,
                mass=phase1.result.variable.galaxies.lens.mass,
                shear=phase1.result.variable.galaxies.lens.shear,
            ),
            source=al.GalaxyModel(
                redshift=1.0,
                pixelization=phase2.result.constant.galaxies.source.
                pixelization,
                regularization=phase2.result.constant.galaxies.source.
                regularization,
            ),
        ),
        optimizer_class=optimizer_class,
    )

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

    phase3 = phase3.extend_with_multiple_hyper_phases(
        hyper_galaxy=True,
        include_background_sky=True,
        include_background_noise=True,
        inversion=True,
    )

    return al.PipelineImaging(name, phase1, phase2, phase3)
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):
    phase1 = al.PhaseImaging(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(redshift=0.5,
                                mass=al.mass_profiles.EllipticalIsothermal),
            source=al.GalaxyModel(redshift=1.0,
                                  light=al.light_profiles.EllipticalSersic),
        ),
        optimizer_class=optimizer_class,
    )

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

    phase1 = phase1.extend_with_multiple_hyper_phases(hyper_galaxy=True)

    class InversionPhase(al.PhaseImaging):
        def customize_priors(self, results):
            # Lens Mass, SIE -> SIE, Shear -> Shear #

            self.galaxies.lens = results.last.constant.galaxies.lens

            self.galaxies.lens.hyper_galaxy = (
                results.last.hyper_combined.constant.galaxies.lens.hyper_galaxy
            )

            self.galaxies.source.hyper_galaxy = (
                results.last.hyper_combined.constant.galaxies.source.
                hyper_galaxy)

    phase2 = InversionPhase(
        phase_name="phase_2",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(redshift=0.5,
                                mass=al.mass_profiles.EllipticalIsothermal),
            source=al.GalaxyModel(
                redshift=1.0,
                pixelization=al.pixelizations.VoronoiBrightnessImage,
                regularization=al.regularization.AdaptiveBrightness,
            ),
        ),
        inversion_pixel_limit=716,
        optimizer_class=optimizer_class,
    )

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

    phase2 = phase2.extend_with_multiple_hyper_phases(hyper_galaxy=False,
                                                      inversion=True)

    class InversionPhase(al.PhaseImaging):
        def customize_priors(self, results):
            # Lens Mass, SIE -> SIE, Shear -> Shear #

            self.galaxies.lens = results.from_phase(
                "phase_1").variable.galaxies.lens

            self.galaxies.source = results.from_phase(
                "phase_2").variable.galaxies.source

            self.galaxies.lens.hyper_galaxy = (
                results.last.hyper_combined.constant.galaxies.lens.hyper_galaxy
            )
            self.galaxies.source.hyper_galaxy = (
                results.last.hyper_combined.constant.galaxies.source.
                hyper_galaxy)

    phase3 = InversionPhase(
        phase_name="phase_3",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(redshift=0.5,
                                mass=al.mass_profiles.EllipticalIsothermal),
            source=al.GalaxyModel(
                redshift=1.0,
                pixelization=al.pixelizations.VoronoiBrightnessImage,
                regularization=al.regularization.AdaptiveBrightness,
            ),
        ),
        inversion_pixel_limit=716,
        optimizer_class=optimizer_class,
    )

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

    phase3 = phase3.extend_with_multiple_hyper_phases(hyper_galaxy=False,
                                                      inversion=True)

    return al.PipelineImaging(name, phase1, phase2, phase3)
def make_pipeline(
    name,
    phase_folders,
    pipeline_pixelization=al.pixelizations.VoronoiBrightnessImage,
    pipeline_regularization=al.regularization.AdaptiveBrightness,
    optimizer_class=af.MultiNest,
):

    phase1 = al.PhaseImaging(
        phase_name="phase_1__lens_sersic",
        phase_folders=phase_folders,
        galaxies=dict(lens=al.GalaxyModel(
            redshift=0.5, light=al.light_profiles.EllipticalSersic)),
        optimizer_class=optimizer_class,
    )

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

    phase1 = phase1.extend_with_multiple_hyper_phases(hyper_galaxy=True)

    class LensSubtractedPhase(al.PhaseImaging):
        def customize_priors(self, results):

            ## Lens Light Sersic -> Sersic ##

            self.galaxies.lens.light = results.from_phase(
                "phase_1__lens_sersic").constant.galaxies.lens.light

            ## Lens Mass, Move centre priors to centre of lens light ###

            self.galaxies.lens.mass.centre = (
                results.from_phase("phase_1__lens_sersic").variable_absolute(
                    a=0.1).galaxies.lens.light.centre)

            ## Set all hyper_galaxies-galaxies if feature is turned on ##

            self.galaxies.lens.hyper_galaxy = (
                results.last.hyper_combined.constant.galaxies.lens.hyper_galaxy
            )

    phase2 = LensSubtractedPhase(
        phase_name="phase_2__lens_sie__source_sersic",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5,
                light=al.light_profiles.EllipticalSersic,
                mass=al.mass_profiles.EllipticalIsothermal,
                shear=al.mass_profiles.ExternalShear,
            ),
            source=al.GalaxyModel(redshift=1.0,
                                  light=al.light_profiles.EllipticalSersic),
        ),
        optimizer_class=optimizer_class,
    )

    phase2.optimizer.const_efficiency_mode = False
    phase2.optimizer.n_live_points = 50
    phase2.optimizer.sampling_efficiency = 0.3

    phase2 = phase2.extend_with_multiple_hyper_phases(
        hyper_galaxy=True,
        include_background_sky=True,
        include_background_noise=True)

    class LensSourcePhase(al.PhaseImaging):
        def customize_priors(self, results):

            ## Lens Light, Sersic -> Sersic ###

            self.galaxies.lens.light = results.from_phase(
                "phase_1__lens_sersic").variable.galaxies.lens.light

            ## Lens Mass, SIE -> SIE, Shear -> Shear ###

            self.galaxies.lens.mass = results.from_phase(
                "phase_2__lens_sie__source_sersic").variable.galaxies.lens.mass

            self.galaxies.lens.shear = results.from_phase(
                "phase_2__lens_sie__source_sersic"
            ).variable.galaxies.lens.shear

            ### Source Light, Sersic -> Sersic ###

            self.galaxies.source = results.from_phase(
                "phase_2__lens_sie__source_sersic").variable.galaxies.source

            ## Set all hyper_galaxies-galaxies if feature is turned on ##

            self.galaxies.lens.hyper_galaxy = (
                results.last.hyper_combined.constant.galaxies.lens.hyper_galaxy
            )

    phase3 = LensSourcePhase(
        phase_name="phase_3__lens_sersic_sie__source_sersic",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5,
                light=al.light_profiles.EllipticalSersic,
                mass=al.mass_profiles.EllipticalIsothermal,
                shear=al.mass_profiles.ExternalShear,
            ),
            source=al.GalaxyModel(redshift=1.0,
                                  light=al.light_profiles.EllipticalSersic),
        ),
        optimizer_class=optimizer_class,
    )

    phase3.optimizer.const_efficiency_mode = True
    phase3.optimizer.n_live_points = 75
    phase3.optimizer.sampling_efficiency = 0.3

    phase3 = phase3.extend_with_multiple_hyper_phases(hyper_galaxy=True)

    class InversionPhase(al.PhaseImaging):
        def customize_priors(self, results):

            ## Lens Light & Mass, Sersic -> Sersic, SIE -> SIE, Shear -> Shear ###

            self.galaxies.lens.light = results.from_phase(
                "phase_3__lens_sersic_sie__source_sersic"
            ).constant.galaxies.lens.light

            self.galaxies.lens.mass = results.from_phase(
                "phase_3__lens_sersic_sie__source_sersic"
            ).constant.galaxies.lens.mass

            self.galaxies.lens.shear = results.from_phase(
                "phase_3__lens_sersic_sie__source_sersic"
            ).constant.galaxies.lens.shear

            ## Set all hyper_galaxies-galaxies if feature is turned on ##

            self.galaxies.lens.hyper_galaxy = (
                results.last.hyper_combined.constant.galaxies.lens.hyper_galaxy
            )

    phase4 = InversionPhase(
        phase_name="phase_4__initialize_magnification_inversion",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5,
                light=al.light_profiles.EllipticalSersic,
                mass=al.mass_profiles.EllipticalIsothermal,
                shear=al.mass_profiles.ExternalShear,
            ),
            source=al.GalaxyModel(
                redshift=1.0,
                pixelization=al.pixelizations.VoronoiMagnification,
                regularization=al.regularization.Constant,
            ),
        ),
        optimizer_class=optimizer_class,
    )

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

    phase4 = phase4.extend_with_multiple_hyper_phases(hyper_galaxy=True,
                                                      inversion=False)

    class InversionPhase(al.PhaseImaging):
        def customize_priors(self, results):

            ## Lens Light & Mass, Sersic -> Sersic, SIE -> SIE, Shear -> Shear ###

            self.galaxies.lens = results.from_phase(
                "phase_3__lens_sersic_sie__source_sersic"
            ).variable.galaxies.lens

            ### Source Inversion, Inv -> Inv ###

            self.galaxies.source.pixelization = results.from_phase(
                "phase_4__initialize_magnification_inversion"
            ).constant.galaxies.source.pixelization

            self.galaxies.source.regularization = results.from_phase(
                "phase_4__initialize_magnification_inversion"
            ).constant.galaxies.source.regularization

            ## Set all hyper_galaxies-galaxies if feature is turned on ##

            self.galaxies.lens.hyper_galaxy = (
                results.last.hyper_combined.constant.galaxies.lens.hyper_galaxy
            )

    phase5 = InversionPhase(
        phase_name="phase_5__lens_sersic_sie__source_magnification_inversion",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5,
                light=al.light_profiles.EllipticalSersic,
                mass=al.mass_profiles.EllipticalIsothermal,
                shear=al.mass_profiles.ExternalShear,
            ),
            source=al.GalaxyModel(
                redshift=1.0,
                pixelization=pipeline_pixelization,
                regularization=pipeline_regularization,
            ),
        ),
        optimizer_class=optimizer_class,
    )

    phase5.optimizer.const_efficiency_mode = True
    phase5.optimizer.n_live_points = 75
    phase5.optimizer.sampling_efficiency = 0.2

    phase5 = phase5.extend_with_multiple_hyper_phases(
        hyper_galaxy=True,
        include_background_sky=True,
        include_background_noise=True,
        inversion=False,
    )

    class InversionPhase(al.PhaseImaging):
        def customize_priors(self, results):

            ## Lens Light & Mass, Sersic -> Sersic, SIE -> SIE, Shear -> Shear ###

            self.galaxies.lens.light = results.from_phase(
                "phase_5__lens_sersic_sie__source_magnification_inversion"
            ).constant.galaxies.lens.light

            self.galaxies.lens.mass = results.from_phase(
                "phase_5__lens_sersic_sie__source_magnification_inversion"
            ).constant.galaxies.lens.mass

            self.galaxies.lens.shear = results.from_phase(
                "phase_5__lens_sersic_sie__source_magnification_inversion"
            ).constant.galaxies.lens.shear

            ## Set all hyper_galaxies-galaxies if feature is turned on ##

            self.galaxies.lens.hyper_galaxy = (
                results.last.hyper_combined.constant.galaxies.lens.hyper_galaxy
            )

    phase6 = InversionPhase(
        phase_name="phase_6_initialize_inversion",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5,
                light=al.light_profiles.EllipticalSersic,
                mass=al.mass_profiles.EllipticalIsothermal,
                shear=al.mass_profiles.ExternalShear,
            ),
            source=al.GalaxyModel(
                redshift=1.0,
                pixelization=pipeline_pixelization,
                regularization=pipeline_regularization,
            ),
        ),
        optimizer_class=optimizer_class,
    )

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

    phase6 = phase6.extend_with_multiple_hyper_phases(
        hyper_galaxy=True,
        include_background_sky=True,
        include_background_noise=True,
        inversion=True,
    )

    class InversionPhase(al.PhaseImaging):
        def customize_priors(self, results):

            ## Lens Light & Mass, Sersic -> Sersic, SIE -> SIE, Shear -> Shear ###

            self.galaxies.lens = results.from_phase(
                "phase_5__lens_sersic_sie__source_magnification_inversion"
            ).variable.galaxies.lens

            ### Source Inversion, Inv -> Inv ###

            self.galaxies.source.pixelization = results.from_phase(
                "phase_6_initialize_inversion"
            ).hyper_combined.constant.galaxies.source.pixelization

            self.galaxies.source.regularization = results.from_phase(
                "phase_6_initialize_inversion"
            ).hyper_combined.constant.galaxies.source.regularization

            ## Set all hyper_galaxies-galaxies if feature is turned on ##

            self.galaxies.lens.hyper_galaxy = (
                results.last.hyper_combined.constant.galaxies.lens.hyper_galaxy
            )

            self.galaxies.source.hyper_galaxy = (
                results.last.hyper_combined.constant.galaxies.source.
                hyper_galaxy)

    phase7 = InversionPhase(
        phase_name="phase_7__lens_sersic_sie__source_inversion",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5,
                light=al.light_profiles.EllipticalSersic,
                mass=al.mass_profiles.EllipticalIsothermal,
                shear=al.mass_profiles.ExternalShear,
            ),
            source=al.GalaxyModel(
                redshift=1.0,
                pixelization=pipeline_pixelization,
                regularization=pipeline_regularization,
            ),
        ),
        optimizer_class=optimizer_class,
    )

    phase7.optimizer.const_efficiency_mode = True
    phase7.optimizer.n_live_points = 75
    phase7.optimizer.sampling_efficiency = 0.2

    phase7 = phase7.extend_with_multiple_hyper_phases(
        hyper_galaxy=True,
        include_background_sky=True,
        include_background_noise=True,
        inversion=True,
    )

    return al.PipelineImaging(name,
                              phase1,
                              phase2,
                              phase3,
                              phase4,
                              phase5,
                              phase6,
                              phase7,
                              hyper_mode=False)
def make_pipeline(name, phase_folders, optimizer_class=af.MultiNest):

    phase1 = al.PhaseImaging(
        phase_name="phase_1",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5,
                light=al.light_profiles.SphericalDevVaucouleurs,
                mass=al.mass_profiles.EllipticalIsothermal,
            ),
            source=al.GalaxyModel(
                redshift=1.0, light=al.light_profiles.EllipticalSersic
            ),
        ),
        optimizer_class=optimizer_class,
    )

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

    phase1 = phase1.extend_with_multiple_hyper_phases(hyper_galaxy=True)

    class HyperLensSourcePlanePhase(al.PhaseImaging):
        def customize_priors(self, results):

            self.galaxies.lens.hyper_galaxy = (
                results.last.hyper_combined.constant.galaxies.lens.hyper_galaxy
            )

            self.galaxies.source.hyper_galaxy = (
                results.last.hyper_combined.constant.galaxies.source.hyper_galaxy
            )

    phase2 = HyperLensSourcePlanePhase(
        phase_name="phase_2",
        phase_folders=phase_folders,
        galaxies=dict(
            lens=al.GalaxyModel(
                redshift=0.5,
                light=phase1.result.variable.galaxies.lens.light,
                mass=phase1.result.variable.galaxies.lens.mass,
                hyper_galaxy=al.HyperGalaxy,
            ),
            source=al.GalaxyModel(
                redshift=1.0,
                light=phase1.result.variable.galaxies.source.light,
                hyper_galaxy=al.HyperGalaxy,
            ),
        ),
        optimizer_class=optimizer_class,
    )

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

    phase2 = phase2.extend_with_multiple_hyper_phases(hyper_galaxy=True)

    return al.PipelineImaging(name, phase1, phase2)