Example #1
0
    def lens_for_subhalo_pipeline_from_results(
            self, results: af.ResultsCollection) -> ag.GalaxyModel:
        """
        Pass the lens `PriorModel` as a `model` or `instance` from the `MassPipeline` to the `SubhaloPipeline`.

        Parameters
        ----------
        result : af.Result
            The result of the previous mass pipeline.

        Returns
        -------
        ag.GalaxyModel
            Contains the `PriorModel`'s of the lens's mass, the shear, etc.
        """

        if self.setup_subhalo.mass_is_model:

            return ag.GalaxyModel(
                redshift=self.redshift_lens,
                mass=results.last.model.galaxies.lens.mass,
                shear=results.last.model.galaxies.lens.shear,
                hyper_galaxy=self.setup_hyper.hyper_galaxy_lens_from_result(
                    result=results.last),
            )

        else:

            return ag.GalaxyModel(
                redshift=self.redshift_lens,
                mass=results.last.instance.galaxies.lens.mass,
                shear=results.last.instance.galaxies.lens.shear,
                hyper_galaxy=self.setup_hyper.hyper_galaxy_lens_from_result(
                    result=results.last),
            )
Example #2
0
    def lens_for_mass_pipeline_from_result(
            self, result: af.Result, mass: af.PriorModel,
            shear: af.PriorModel) -> ag.GalaxyModel:
        """
        Setup the lens model for a `Mass` pipeline using the previous `Light` pipeline and phase results.

        The lens light model is not specified by the `Mass` pipeline, so the `Light` pipelines are used to
        determine this. This function returns a `GalaxyModel` for the lens, where:

        1) The lens light model uses the light model of the Light pipeline.
        2) The lens light is returned as a model if *light_is_model* is *False, an instance if `True`.

        Parameters
        ----------
        result : af.Result
            The result of the previous source or light pipeline.
        mass : ag.MassProfile
            The mass model of the len galaxy.
        shear : ag.ExternalShear
            The `ExternalShear` of the lens galaxy.

        Returns
        -------
        ag.GalaxyModel
            Contains the `PriorModel`'s of the lens's light, mass, the shear, etc.
        """

        smbh = self.pipeline_mass.smbh_prior_model_from_result(result=result)

        if not self.pipeline_mass.light_is_model:

            return ag.GalaxyModel(
                redshift=self.redshift_lens,
                bulge=result.instance.galaxies.lens.bulge,
                disk=result.instance.galaxies.lens.disk,
                envelope=result.instance.galaxies.lens.envelope,
                mass=mass,
                shear=shear,
                smbh=smbh,
                hyper_galaxy=self.setup_hyper.hyper_galaxy_lens_from_result(
                    result=result),
            )

        else:

            return ag.GalaxyModel(
                redshift=self.redshift_lens,
                bulge=result.model.galaxies.lens.bulge,
                disk=result.model.galaxies.lens.disk,
                envelope=result.model.galaxies.lens.envelope,
                mass=mass,
                shear=shear,
                smbh=smbh,
                hyper_galaxy=self.setup_hyper.hyper_galaxy_lens_from_result(
                    result=result),
            )
Example #3
0
    def lens_from_light_pipeline_for_mass_pipeline(self, redshift_lens, mass,
                                                   shear):
        """Setup the lens model for a Mass pipeline using the previous pipeline and phase results.

        The lens light model is not specified by the Mass pipeline, so the Light pipelines are used to
        determine this. This function returns a _GalaxyModel_ for the lens, where:

        1) The lens light model uses the light model of the Light pipeline.
        2) The lens light is returned as a model if *fix_lens_light* is *False, an instance if *True*.

        Parameters
        ----------
        redshift_lens : float
            The redshift of the lens galaxy.
        mass : ag.MassProfile
            The mass model of the len galaxy.
        shear : ag.ExternalShear
            The external shear of the lens galaxy.
        """

        if self.mass.fix_lens_light:

            return ag.GalaxyModel(
                redshift=redshift_lens,
                bulge=af.last.instance.galaxies.lens.bulge,
                disk=af.last.instance.galaxies.lens.disk,
                mass=mass,
                shear=shear,
                hyper_galaxy=af.last.hyper_combined.instance.optional.galaxies.
                lens.hyper_galaxy,
            )

        else:

            return ag.GalaxyModel(
                redshift=redshift_lens,
                bulge=af.last.model.galaxies.lens.bulge,
                disk=af.last.model.galaxies.lens.disk,
                mass=mass,
                shear=shear,
                hyper_galaxy=af.last.hyper_combined.instance.optional.galaxies.
                lens.hyper_galaxy,
            )
Example #4
0
    def _source_parametric_from_result(
            self,
            result: af.Result,
            source_is_model: bool = True) -> ag.GalaxyModel:
        """
         Pass a parametric source `PriorModel` as a `model` or `instance` from a previous pipeline.

        Parameters
        ----------
        result : af.Result
            The result of the previous source pipeline.        
        source_is_model : bool
            If `True`, the source is passed as a `model` and fitted for by the pipeline. If `False` it is
            passed as an `instance` with fixed parameters.

        Returns
        -------
        ag.GalaxyModel
            Contains the `PriorModel`'s of the source's bulge, disk, etc.
        """
        hyper_galaxy = self.setup_hyper.hyper_galaxy_source_from_result(
            result=result)

        if source_is_model:

            return ag.GalaxyModel(
                redshift=self.redshift_source,
                bulge=result.model.galaxies.source.bulge,
                disk=result.model.galaxies.source.disk,
                envelope=result.model.galaxies.source.envelope,
                hyper_galaxy=hyper_galaxy,
            )

        else:

            return ag.GalaxyModel(
                redshift=self.redshift_source,
                bulge=result.instance.galaxies.source.bulge,
                disk=result.instance.galaxies.source.disk,
                envelope=result.instance.galaxies.source.envelope,
                hyper_galaxy=hyper_galaxy,
            )
Example #5
0
    def _source_inversion_from_result(
            self,
            result: af.Result,
            source_is_model: bool = False) -> ag.GalaxyModel:
        """
         Pass an inversion source `PriorModel` as a `model` or `instance` from a previous pipeline.

        Parameters
        ----------
        result : af.Result
            The result of the previous source pipeline.          
        source_is_model : bool
            If `True`, the source is passed as a `model` and fitted for by the pipeline. If `False` it is
            passed as an `instance` with fixed parameters.
            
        Returns
        -------
        ag.GalaxyModel
            Contains the `PriorModel`'s of the source's pixelization, regularization, etc.
        """
        hyper_galaxy = self.setup_hyper.hyper_galaxy_source_from_result(
            result=result)

        if not self.setup_hyper.hyper_fixed_after_source:

            if source_is_model:

                return ag.GalaxyModel(
                    redshift=self.redshift_source,
                    pixelization=result.hyper.instance.galaxies.source.
                    pixelization,
                    regularization=result.hyper.model.galaxies.source.
                    regularization,
                    hyper_galaxy=hyper_galaxy,
                )

            else:

                return ag.GalaxyModel(
                    redshift=self.redshift_source,
                    pixelization=result.hyper.instance.galaxies.source.
                    pixelization,
                    regularization=result.hyper.instance.galaxies.source.
                    regularization,
                    hyper_galaxy=hyper_galaxy,
                )

        else:

            if source_is_model:

                return ag.GalaxyModel(
                    redshift=self.redshift_source,
                    pixelization=result.instance.galaxies.source.pixelization,
                    regularization=result.model.galaxies.source.regularization,
                    hyper_galaxy=hyper_galaxy,
                )

            else:

                return ag.GalaxyModel(
                    redshift=self.redshift_source,
                    pixelization=result.instance.galaxies.source.pixelization,
                    regularization=result.instance.galaxies.source.
                    regularization,
                    hyper_galaxy=hyper_galaxy,
                )
Example #6
0
    def source_from_previous_pipeline_model_or_instance(
            self, source_as_model=False, index=0):
        """Setup the source model using the previous pipeline and phase results.

        The source light model is not specified by the pipeline light and mass pipelines (e.g. the previous pipelines
        are used to determine whether the source model is parametric or an inversion).

        The source can be returned as an instance or a model, depending on the optional input. The default SLaM p
        ipelines return parametric sources as a model (give they must be updated to properly compute a new mass model)
        and return inversions as an instance (as they have sufficient flexibility to typically not required updating).
        They use the *source_from_pevious_pipeline* method of the SLaM class to do this.

        The pipeline tool af.last is required to locate the previous source model, which requires an index based on the
        pipelines that have run. For example, if the source model you wish to load from is 3 phases back (perhaps
        because there were multiple phases in a Light pipeline preivously) this index should be 2.

        Parameters
        ----------
        source_as_model : bool
            If *True* the source is returned as a *model* where the parameters are fitted for using priors of the
            phase result it is loaded from. If *False*, it is an instance of that phase's result.
        index : integer
            The index (counting backwards from this phase) of the phase result used to setup the source.
        """

        if self.hyper.hyper_galaxies:

            hyper_galaxy = af.PriorModel(ag.HyperGalaxy)

            hyper_galaxy.noise_factor = (af.last.hyper_combined.model.galaxies.
                                         source.hyper_galaxy.noise_factor)
            hyper_galaxy.contribution_factor = (
                af.last.hyper_combined.instance.optional.galaxies.source.
                hyper_galaxy.contribution_factor)
            hyper_galaxy.noise_power = (
                af.last.hyper_combined.instance.optional.galaxies.source.
                hyper_galaxy.noise_power)

        else:

            hyper_galaxy = None

        if self.source.type_tag in "sersic":

            if source_as_model:

                return ag.GalaxyModel(
                    redshift=af.last[index].model.galaxies.source.redshift,
                    sersic=af.last[index].model.galaxies.source.sersic,
                    hyper_galaxy=hyper_galaxy,
                )

            else:

                return ag.GalaxyModel(
                    redshift=af.last[index].instance.galaxies.source.redshift,
                    sersic=af.last[index].instance.galaxies.source.sersic,
                    hyper_galaxy=hyper_galaxy,
                )

        else:

            if source_as_model:

                return ag.GalaxyModel(
                    redshift=af.last.instance.galaxies.source.redshift,
                    pixelization=af.last.hyper_combined.instance.galaxies.
                    source.pixelization,
                    regularization=af.last.hyper_combined.model.galaxies.
                    source.regularization,
                )

            else:

                return ag.GalaxyModel(
                    redshift=af.last.instance.galaxies.source.redshift,
                    pixelization=af.last[index].hyper_combined.instance.
                    galaxies.source.pixelization,
                    regularization=af.last[index].hyper_combined.instance.
                    galaxies.source.regularization,
                    hyper_galaxy=hyper_galaxy,
                )