How to use the autolens.model.galaxy.galaxy_model.GalaxyModel function in autolens

To help you get started, we’ve selected a few autolens examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Jammy2211 / PyAutoLens / test / pipeline / test_phase_property.py View on Github external
def test_classes(self, list_phase):
        objects = [gp.GalaxyModel(), gp.GalaxyModel()]

        list_phase.prop = objects

        assert list_phase.variable.prop == objects
        assert len(list_phase.constant.prop) == 0

        assert list_phase.prop == objects
github Jammy2211 / PyAutoLens / test / pipeline / test_phase_property.py View on Github external
def test_named_attributes_in_variable(self, list_phase):
        galaxy_model = gp.GalaxyModel(variable_redshift=True)
        list_phase.prop = dict(one=galaxy_model)

        assert list_phase.variable.prior_count == 1
        assert list_phase.variable.one == galaxy_model

        instance = list_phase.variable.instance_from_prior_medians()

        assert instance.one is not None
        assert len(instance.prop) == 1
github Jammy2211 / PyAutoLens / test / autofit / test_model_mapper.py View on Github external
def test_set_tuple_constant(self):
        mm = model_mapper.ModelMapper()
        mm.galaxy = galaxy_model.GalaxyModel(sersic=light_profiles.EllipticalSersic)

        assert mm.prior_count == 7

        mm.galaxy.sersic.centre_0 = model_mapper.Constant(0)
        mm.galaxy.sersic.centre_1 = model_mapper.Constant(0)

        assert mm.prior_count == 5
github Jammy2211 / PyAutoLens / test / pipeline / test_phase_property.py View on Github external
def test_set_item(self, list_phase):
        galaxy_prior_0 = gp.GalaxyModel()
        objects = [galaxy_prior_0, g.Galaxy()]

        list_phase.prop = objects
        assert_ordered(list_phase.prop)

        galaxy_prior_1 = gp.GalaxyModel()
        list_phase.prop[1] = galaxy_prior_1

        assert_ordered(list_phase.prop)

        assert list_phase.constant.prop == []
        assert list_phase.variable.prop == [galaxy_prior_0, galaxy_prior_1]

        galaxy = g.Galaxy()

        list_phase.prop[0] = galaxy
github Jammy2211 / PyAutoLens / test / unit / pipeline / test_phase_extensions.py View on Github external
)
        assert (
            len(analysis.binned_hyper_galaxy_image_1d_path_dict[("g1",)])
            == analysis.lens_data.grid.binned.shape[0]
        )

        results_collection_7x7[0].galaxy_images = [
            2.0 * np.ones((7, 7)),
            2.0 * np.ones((7, 7)),
        ]
        results_collection_7x7[0].galaxy_images[0][3, 2] = -1.0
        results_collection_7x7[0].galaxy_images[1][3, 4] = -1.0

        phase_7x7 = phase_imaging.PhaseImaging(
            galaxies=dict(
                lens=gm.GalaxyModel(
                    redshift=0.5,
                    hyper_galaxy=g.HyperGalaxy,
                    pixelization=px.VoronoiBrightnessImage,
                    regularization=rg.Constant,
                )
            ),
            inversion_pixel_limit=1,
            optimizer_class=mock_pipeline.MockNLO,
            mask_function=mask_function_7x7,
            pixel_scale_binned_cluster_grid=ccd_data_7x7.pixel_scale * 2.0,
            phase_name="test_phase",
        )

        analysis = phase_7x7.make_analysis(
            data=ccd_data_7x7, results=results_collection_7x7
        )
github Jammy2211 / PyAutoLens / workspace / pipelines / examples / multi_plane.py View on Github external
return image - previous_results[0].unmasked_lens_plane_model_image

        def pass_priors(self, previous_results):

            self.galaxies.lens = previous_results[3].variable.lens

            self.galaxies.los_0.mass = previous_results[3].variable.los_0.mass
            self.galaxies.los_1.mass = previous_results[3].variable.los_1.mass
            self.galaxies.los_2.mass = previous_results[3].variable.los_2.mass

            self.galaxies.source = previous_results[3].variable.source

    phase5 = MultiPlanePhase(galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal),
                             los_0=gm.GalaxyModel(mass=mp.SphericalIsothermal, variable_redshift=True),
                             los_1=gm.GalaxyModel(mass=mp.SphericalIsothermal, variable_redshift=True),
                             los_2=gm.GalaxyModel(mass=mp.SphericalIsothermal, variable_redshift=True),
                             source=gm.GalaxyModel(pixelization=pix.AdaptiveMagnification,
                                                   regularization=reg.Constant)),
                             use_positions=True,
                             optimizer_class=nl.MultiNest, phase_name=pipeline_path + '/phase_5_multi_plane')

    # Customize MultiNest so it runs fast
    phase5.optimizer.n_live_points = 60
    phase5.optimizer.sampling_efficiency = 0.2
    phase5.optimizer.const_efficiency_mode = True

    return pipeline.PipelineImaging(pipeline_path, phase1, phase2, phase3, phase4, phase5)
github Jammy2211 / PyAutoLens / workspace / howtolens / chapter_4_inversions / tutorial_8_pipeline.py View on Github external
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)
github Jammy2211 / PyAutoLens / workspace / howtolens / chapter_3_pipelines / tutorial_3_complex_source.py View on Github external
def make_pipeline():
    pipeline_name = 'howtolens_c3_t3_complex_source'

    # To begin, we need to initialize the lens's mass model. We should be able to do this by using a simple source
    # model. It won't incorrect_fit the complicated structure of the source, but it'll give us a robust estimate of the
    # einstein radius and the other lens-mass parameters.

    # This should run fine without any prior-passes. In general, a thick, giant ring of source light is something we
    # can be confident MultiNest will incorrect_fit without much issue, especially when the lens model_galaxy's light isn't included
    # such that the parameter space is just 12 parameters.

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

    # Now lets add another source component, using the previous model as the initialization on the lens / source
    # parameters. We'll vary the parameters of the lens mass model and first source model_galaxy component during the incorrect_fit.

    class X2SourcePhase(ph.LensSourcePlanePhase):

        def pass_priors(self, previous_results):

            self.lens_galaxies.lens = previous_results[0].variable.lens
            self.source_galaxies.source.light_0 = previous_results[0].variable.source.light_0

    # You'll notice I've stop writing 'phase_1_results = previous_results[0]' and so on - we know how
    # the previous results are structured now so lets not clutter our code!

    phase2 = X2SourcePhase(lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)),
github Jammy2211 / PyAutoLens / workspace / howtolens / chapter_3_pipelines / tutorial_3_complex_source.py View on Github external
source_galaxies=dict(source=gm.GalaxyModel(light_0=lp.EllipticalExponential,
                                                                       light_1=lp.EllipticalSersic)),
                           optimizer_class=nl.MultiNest, phase_name=pipeline_name + '/phase_2_x2_source')

    # Now lets do the same again, but with 3 source model_galaxy components.

    class X3SourcePhase(ph.LensSourcePlanePhase):

        def pass_priors(self, previous_results):

            self.lens_galaxies.lens = previous_results[1].variable.lens
            self.source_galaxies.source.light_0 = previous_results[1].variable.source.light_0
            self.source_galaxies.source.light_1 = previous_results[1].variable.source.light_1

    phase3 = X3SourcePhase(lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)),
                           source_galaxies=dict(source=gm.GalaxyModel(light_0=lp.EllipticalExponential,
                                                                      light_1=lp.EllipticalSersic,
                                                                      light_2=lp.EllipticalSersic)),
                           optimizer_class=nl.MultiNest, phase_name=pipeline_name + '/phase_3_x3_source')

    # And one more for luck!

    class X4SourcePhase(ph.LensSourcePlanePhase):

        def pass_priors(self, previous_results):

            self.lens_galaxies.lens = previous_results[2].variable.lens
            self.source_galaxies.source.light_0 = previous_results[2].variable.source.light_0
            self.source_galaxies.source.light_1 = previous_results[2].variable.source.light_1
            self.source_galaxies.source.light_2 = previous_results[2].variable.source.light_2

    phase4 = X4SourcePhase(lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)),
github Jammy2211 / PyAutoLens / workspace / howtolens / chapter_3_pipelines / tutorial_3_pipeline_complex_source.py View on Github external
phase2.optimizer.const_efficiency_mode = True
    phase2.optimizer.n_live_points = 40
    phase2.optimizer.sampling_efficiency = 0.5

    # Now lets do the same again, but with 3 source galaxy components.

    class X3SourcePhase(ph.LensSourcePlanePhase):

        def pass_priors(self, previous_results):

            self.lens_galaxies.lens = previous_results[1].variable.lens
            self.source_galaxies.source.light_0 = previous_results[1].variable.source.light_0
            self.source_galaxies.source.light_1 = previous_results[1].variable.source.light_1

    phase3 = X3SourcePhase(lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)),
                           source_galaxies=dict(source=gm.GalaxyModel(light_0=lp.EllipticalExponential,
                                                                      light_1=lp.EllipticalSersic,
                                                                      light_2=lp.EllipticalSersic)),
                           optimizer_class=nl.MultiNest, phase_name=pipeline_path + '/phase_3_x3_source')

    phase3.optimizer.const_efficiency_mode = True
    phase3.optimizer.n_live_points = 50
    phase3.optimizer.sampling_efficiency = 0.5

    # And one more for luck!

    class X4SourcePhase(ph.LensSourcePlanePhase):

        def pass_priors(self, previous_results):

            self.lens_galaxies.lens = previous_results[2].variable.lens
            self.source_galaxies.source.light_0 = previous_results[2].variable.source.light_0