示例#1
0
def source__from_result(result: af.Result,
                        setup_hyper: al.SetupHyper,
                        source_is_model: bool = False) -> af.Model:
    """
    Setup the source model using the previous pipeline and search results.

    The source light model is not specified by the  MASS PIPELINE and the previous SOURCE PIPELINE is used to
    determine whether the source model is parametric or an inversion.

    The source can be returned as an `instance` or `model`, depending on the optional input. The default SLaM
    pipelines 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.

    Parameters
    ----------
    result : af.Result
        The result of the previous source pipeline.
    setup_hyper
        The setup of the hyper analysis if used (e.g. hyper-galaxy noise scaling).
    source_is_model : bool
        If `True` the source is returned as a *model* where the parameters are fitted for using priors of the
        search result it is loaded from. If `False`, it is an instance of that search's result.
    """

    hyper_galaxy = setup_hyper.hyper_galaxy_source_from_result(result=result)

    if result.instance.galaxies.source.pixelization is None:

        if source_is_model:

            return af.Model(
                al.Galaxy,
                redshift=result.instance.galaxies.source.redshift,
                bulge=result.model.galaxies.source.bulge,
                disk=result.model.galaxies.source.disk,
                envelope=result.model.galaxies.source.envelope,
                hyper_galaxy=hyper_galaxy,
            )

        else:

            return af.Model(
                al.Galaxy,
                redshift=result.instance.galaxies.source.redshift,
                bulge=result.instance.galaxies.source.bulge,
                disk=result.instance.galaxies.source.disk,
                envelope=result.instance.galaxies.source.envelope,
                hyper_galaxy=hyper_galaxy,
            )

    if hasattr(result, "hyper"):

        if source_is_model:

            return af.Model(
                al.Galaxy,
                redshift=result.instance.galaxies.source.redshift,
                pixelization=result.hyper.instance.galaxies.source.
                pixelization,
                regularization=result.hyper.model.galaxies.source.
                regularization,
                hyper_galaxy=hyper_galaxy,
            )

        else:

            return af.Model(
                al.Galaxy,
                redshift=result.instance.galaxies.source.redshift,
                pixelization=result.hyper.instance.galaxies.source.
                pixelization,
                regularization=result.hyper.instance.galaxies.source.
                regularization,
                hyper_galaxy=hyper_galaxy,
            )

    else:

        if source_is_model:

            return af.Model(
                al.Galaxy,
                redshift=result.instance.galaxies.source.redshift,
                pixelization=result.instance.galaxies.source.pixelization,
                regularization=result.model.galaxies.source.regularization,
                hyper_galaxy=hyper_galaxy,
            )

        else:

            return af.Model(
                al.Galaxy,
                redshift=result.instance.galaxies.source.redshift,
                pixelization=result.instance.galaxies.source.pixelization,
                regularization=result.instance.galaxies.source.regularization,
                hyper_galaxy=hyper_galaxy,
            )
示例#2
0
def with_lens_light(
    settings_autofit: slam_util.SettingsAutoFit,
    analysis: Union[al.AnalysisImaging, al.AnalysisInterferometer],
    setup_hyper: al.SetupHyper,
    source_results: af.ResultsCollection,
    light_results: af.ResultsCollection,
    lens_bulge: af.Model(al.lp.LightProfile) = af.Model(al.lp.EllSersic),
    lens_disk: af.Model(al.lp.LightProfile) = None,
    lens_envelope: af.Model(al.lp.LightProfile) = None,
    dark: af.Model(al.mp.MassProfile) = af.Model(al.mp.EllNFWMCRLudlow),
    smbh: af.Model(al.mp.MassProfile) = None,
    einstein_mass_range: Optional[Tuple[float, float]] = (0.01, 5.0),
    end_with_hyper_extension: bool = False,
) -> af.ResultsCollection:
    """
    The SLaM MASS LIGHT DARK PIPELINE for fitting imaging data with a lens light component.

    Parameters
    ----------
    analysis
        The analysis class which includes the `log_likelihood_function` and can be customized for the SLaM model-fit.
    setup_hyper
        The setup of the hyper analysis if used (e.g. hyper-galaxy noise scaling).
    source_results
        The results of the SLaM SOURCE PARAMETRIC PIPELINE or SOURCE INVERSION PIPELINE which ran before this pipeline.
    light_results
        The results of the SLaM LIGHT PARAMETRIC PIPELINE which ran before this pipeline.
    mass
        The `MassProfile` used to fit the lens galaxy mass in this pipeline.
    smbh
        The `MassProfile` used to fit the a super massive black hole in the lens galaxy.
    lens_bulge
        The `LightMassProfile` `Model` used to represent the light and stellar mass distribution of the lens galaxy's
        bulge (set to None to omit a bulge).
    lens_disk
        The `LightMassProfile` `Model` used to represent the light and stellar mass distribution of the lens galaxy's
        disk (set to None to omit a disk).
    lens_envelope
        The `LightMassProfile` `Model` used to represent the light and stellar mass distribution of the lens galaxy's
        envelope (set to None to omit an envelope).
    dark
        The `MassProfile` `Model` used to represent the dark matter distribution of the lens galaxy's (set to None to
        omit dark matter).
    einstein_mass_range
        The values a the estimate of the Einstein Mass in the LIGHT PIPELINE is multiplied by to set the lower and
        upper limits of the profile's mass-to-light ratio.
    end_with_hyper_extension
        If `True` a hyper extension is performed at the end of the pipeline. If this feature is used, you must be
        certain you have manually passed the new hyper images geneted in this search to the next pipelines.
    """

    """
    __Model + Search + Analysis + Model-Fit (Search 1)__

    In search 1 of the MASS LIGHT DARK PIPELINE we fit a lens model where:

     - The lens galaxy light and stellar mass is modeled using light and mass profiles [Priors on light model parameters
     initialized from LIGHT PIPELINE].
     - The lens galaxy dark mass is modeled using a dark mass distribution [No prior initialization].
     - The source galaxy's light is parametric or an inversion depending on the previous pipeline [Model and priors 
     initialized from SOURCE PIPELINE].

    This search aims to accurately estimate the lens mass model, using the improved mass model priors and source model 
    of the SOURCE PIPELINE and LIGHT PIPELINE.

    The `mass_to_light_ratio` prior of each light and stellar profile is set using the Einstein Mass estimate of the
    SOURCE PIPELINE, specifically using values which are 1% and 500% this estimate.

    The dark matter mass profile has the lens and source redshifts added to it, which are used to determine its mass
    from the mass-to-concentration relation of Ludlow et al.    
    """
    lens_bulge = slam_util.pass_light_and_mass_profile_priors(
        model=lens_bulge,
        result_light_component=light_results.last.model.galaxies.lens.bulge,
        result=light_results.last,
        einstein_mass_range=einstein_mass_range,
    )
    lens_disk = slam_util.pass_light_and_mass_profile_priors(
        model=lens_disk,
        result_light_component=light_results.last.model.galaxies.lens.disk,
        result=light_results.last,
        einstein_mass_range=einstein_mass_range,
    )
    lens_envelope = slam_util.pass_light_and_mass_profile_priors(
        model=lens_envelope,
        result_light_component=light_results.last.model.galaxies.lens.envelope,
        result=light_results.last,
        einstein_mass_range=einstein_mass_range,
    )

    dark.mass_at_200 = af.LogUniformPrior(lower_limit=1e10, upper_limit=1e15)
    dark.redshift_object = light_results.last.instance.galaxies.lens.redshift
    dark.redshift_source = light_results.last.instance.galaxies.source.redshift

    if smbh is not None:
        smbh.centre = lens_bulge.centre

    source = slam_util.source__from_result_model_if_parametric(
        result=source_results.last, setup_hyper=setup_hyper
    )

    model = af.Collection(
        galaxies=af.Collection(
            lens=af.Model(
                al.Galaxy,
                redshift=light_results.last.instance.galaxies.lens.redshift,
                bulge=lens_bulge,
                disk=lens_disk,
                envelope=lens_envelope,
                dark=dark,
                shear=source_results.last.model.galaxies.lens.shear,
                smbh=smbh,
                hyper_galaxy=setup_hyper.hyper_galaxy_lens_from_result(
                    result=light_results.last
                ),
            ),
            source=source,
        ),
        hyper_image_sky=setup_hyper.hyper_image_sky_from_result(
            result=light_results.last, as_model=True
        ),
        hyper_background_noise=setup_hyper.hyper_background_noise_from_result(
            result=light_results.last
        ),
    )

    search = af.DynestyStatic(
        path_prefix=settings_autofit.path_prefix,
        name="mass_light_dark[1]_light[parametric]_mass[light_dark]_source",
        unique_tag=settings_autofit.unique_tag,
        number_of_cores=settings_autofit.number_of_cores,
        session=settings_autofit.session,
        nlive=100,
    )

    result_1 = search.fit(model=model, analysis=analysis, info=settings_autofit.info)

    """
    __Hyper Extension__

    The above search may be extended with a hyper-search, if the SetupHyper has one or more of the following inputs:

     - The source is using an `Inversion`.
     - One or more `HyperGalaxy`'s are included.
     - The background sky is included via `hyper_image_sky` input.
     - The background noise is included via the `hyper_background_noise`.
    """

    if end_with_hyper_extension:

        result_1 = extensions.hyper_fit(
            setup_hyper=setup_hyper,
            result=result_1,
            analysis=analysis,
            include_hyper_image_sky=True,
        )

    return af.ResultsCollection([result_1])
def with_lens_light(
    path_prefix: str,
    analysis: Union[al.AnalysisImaging, al.AnalysisInterferometer],
    setup_hyper: al.SetupHyper,
    source_results: af.ResultsCollection,
    lens_bulge: af.Model(al.lp.LightProfile) = af.Model(al.lp.EllSersic),
    lens_disk: af.Model(al.lp.LightProfile) = None,
    lens_envelope: af.Model(al.lp.LightProfile) = None,
    end_with_hyper_extension: bool = False,
    unique_tag: Optional[str] = None,
    session: Optional[bool] = None,
) -> af.ResultsCollection:
    """
    The SlaM LIGHT PARAMETRIC PIPELINE for fitting imaging data with a lens light component.

    Parameters
    ----------
    path_prefix
        The prefix of folders between the output path and the search folders.
    analysis
        The analysis class which includes the `log_likelihood_function` and can be customized for the SLaM model-fit.
    setup_hyper
        The setup of the hyper analysis if used (e.g. hyper-galaxy noise scaling).
    source_results
        The results of the SLaM SOURCE PARAMETRIC PIPELINE or SOURCE INVERSION PIPELINE which ran before this pipeline.
    lens_bulge
        The `LightProfile` `Model` used to represent the light distribution of the lens galaxy's bulge (set to
        None to omit a bulge).
    lens_disk
        The `LightProfile` `Model` used to represent the light distribution of the lens galaxy's disk (set to
        None to omit a disk).
    lens_envelope
        The `LightProfile` `Model` used to represent the light distribution of the lens galaxy's envelope (set to
        None to omit an envelope).
    end_with_hyper_extension
        If `True` a hyper extension is performed at the end of the pipeline. If this feature is used, you must be
        certain you have manually passed the new hyper images geneted in this search to the next pipelines.
    unique_tag
        The unique tag for this model-fit, which will be given a unique entry in the sqlite database and also acts as
        the folder after the path prefix and before the search name. This is typically the name of the dataset.
    """
    """
    __Model + Search + Analysis + Model-Fit (Search 1)__

    In search 1 of the LIGHT PARAMETRIC PIPELINE we fit a lens model where:

     - The lens galaxy light is modeled using parametric bulge + disk + envelope [no prior initialization].
     - The lens galaxy mass is modeled using SOURCE PIPELINE's mass distribution [Parameters fixed from MASS PIPELINE].
     - The source galaxy's light is modeled using SOURCE PIPELINE's model [Parameters fixed from SOURCE PIPELINE].

    This search aims to produce an accurate model of the lens galaxy's light, which may not have been possible in the
    SOURCE PIPELINE as the mass and source models were not properly initialized.
    """
    """
    If hyper-galaxy noise scaling for the lens is on, it may have scaled the noise to high values in the SOURCE
    PIPELINE (which fitted a simpler lens light model than this pipeline). The new lens light model fitted in this
    pipeline may fit the data better, requiring a reducing level of noise scaling. For this reason, the noise scaling
    normalization is included as a free parameter.
    """
    hyper_galaxy = setup_hyper.hyper_galaxy_lens_from_result(
        result=source_results.last, noise_factor_is_model=True)

    source = slam_util.source__from_result(result=source_results.last,
                                           setup_hyper=setup_hyper,
                                           source_is_model=False)

    model = af.Collection(
        galaxies=af.Collection(
            lens=af.Model(
                al.Galaxy,
                redshift=source_results.last.instance.galaxies.lens.redshift,
                bulge=lens_bulge,
                disk=lens_disk,
                envelope=lens_envelope,
                mass=source_results.last.instance.galaxies.lens.mass,
                shear=source_results.last.instance.galaxies.lens.shear,
                hyper_galaxy=hyper_galaxy,
            ),
            source=source,
        ),
        hyper_image_sky=setup_hyper.hyper_image_sky_from_result(
            result=source_results.last, as_model=True),
        hyper_background_noise=setup_hyper.hyper_background_noise_from_result(
            result=source_results.last),
    )

    search = af.DynestyStatic(
        path_prefix=path_prefix,
        name="light[1]_light[parametric]",
        unique_tag=unique_tag,
        session=session,
        nlive=75,
    )

    result_1 = search.fit(model=model, analysis=analysis.no_positions)
    """
    __Hyper Extension__

    The above search is extended with a hyper-search if the SetupHyper has one or more of the following inputs:

     - The source is using an `Inversion`.
     - One or more `HyperGalaxy`'s are included.
     - The background sky is included via `hyper_image_sky` input.
     - The background noise is included via the `hyper_background_noise`.
    """

    if end_with_hyper_extension:

        result_1 = extensions.hyper_fit(
            setup_hyper=setup_hyper,
            result=result_1,
            analysis=analysis,
            include_hyper_image_sky=True,
        )

    return af.ResultsCollection([result_1])
示例#4
0
def no_lens_light(
    settings_autofit: af.SettingsSearch,
    analysis: Union[al.AnalysisImaging, al.AnalysisInterferometer],
    setup_hyper: al.SetupHyper,
    source_results: af.ResultsCollection,
    mass: af.Model = af.Model(al.mp.EllIsothermal),
    smbh: Optional[af.Model] = None,
    mass_centre: Optional[Tuple[float, float]] = None,
    end_with_hyper_extension: bool = False,
) -> af.ResultsCollection:
    """
    The SLaM MASS TOTAL PIPELINE for fitting imaging data without a lens light component.

    Parameters
    ----------
    analysis
        The analysis class which includes the `log_likelihood_function` and can be customized for the SLaM model-fit.
    setup_hyper
        The setup of the hyper analysis if used (e.g. hyper-galaxy noise scaling).
    source_results
        The results of the SLaM SOURCE PARAMETRIC PIPELINE or SOURCE INVERSION PIPELINE which ran before this pipeline.
    mass
        The `MassProfile` used to fit the lens galaxy mass in this pipeline.
    smbh
        The `MassProfile` used to fit the a super massive black hole in the lens galaxy.
    mass_centre
       If input, a fixed (y,x) centre of the mass profile is used which is not treated as a free parameter by the
       non-linear search.
    end_with_hyper_extension
        If `True` a hyper extension is performed at the end of the pipeline. If this feature is used, you must be
        certain you have manually passed the new hyper images geneted in this search to the next pipelines.
    """
    """
    __Model + Search + Analysis + Model-Fit (Search 1)__

    In search 1 of the MASS TOTAL PIPELINE we fit a lens model where:

     - The lens galaxy mass is modeled using a total mass distribution [Priors initialized from SOURCE PIPELINE].
     - The source galaxy's light is parametric or an inversion depending on the previous pipeline [Model and priors 
     initialized from SOURCE PIPELINE].

    This search aims to accurately estimate the lens mass model, using the improved mass model priors and source model 
    of the SOURCE PIPELINE
    """
    mass = slam_util.mass__from(mass=mass,
                                result=source_results.last,
                                unfix_mass_centre=True)

    if mass_centre is not None:
        mass.centre = mass_centre

    if smbh is not None:
        smbh.centre = mass.centre

    source = slam_util.source__from_result_model_if_parametric(
        result=source_results.last, setup_hyper=setup_hyper)

    model = af.Collection(
        galaxies=af.Collection(
            lens=af.Model(
                al.Galaxy,
                redshift=source_results.last.instance.galaxies.lens.redshift,
                mass=mass,
                smbh=smbh,
                shear=source_results.last.model.galaxies.lens.shear,
            ),
            source=source,
        ),
        hyper_image_sky=setup_hyper.hyper_image_sky_from(
            result=source_results.last, as_model=True),
        hyper_background_noise=setup_hyper.hyper_background_noise_from(
            result=source_results.last),
    )

    search = af.DynestyStatic(
        name="mass_total[1]_mass[total]_source",
        **settings_autofit.search_dict,
        nlive=100,
    )

    result_1 = search.fit(model=model,
                          analysis=analysis,
                          **settings_autofit.fit_dict)
    """
    __Hyper Extension__

    The above search may be extended with a hyper-search, if the SetupHyper has one or more of the following inputs:

     - The source is using an `Inversion`.
     - One or more `HyperGalaxy`'s are included.
     - The background sky is included via `hyper_image_sky` input.
     - The background noise is included via the `hyper_background_noise`.
    """

    if end_with_hyper_extension:

        result_1 = extensions.hyper_fit(
            setup_hyper=setup_hyper,
            result=result_1,
            analysis=analysis,
            include_hyper_image_sky=True,
        )

    return af.ResultsCollection([result_1])
示例#5
0
def detection_single_plane(
    path_prefix: str,
    analysis: Union[al.AnalysisImaging, al.AnalysisInterferometer],
    setup_hyper: al.SetupHyper,
    mass_results: af.ResultsCollection,
    subhalo_mass: af.Model(al.mp.MassProfile) = af.Model(
        al.mp.SphNFWMCRLudlow),
    grid_dimension_arcsec: float = 3.0,
    number_of_steps: Union[Tuple[int], int] = 5,
    number_of_cores: int = 1,
    unique_tag: Optional[str] = None,
    session: Optional[bool] = None,
) -> af.ResultsCollection:
    """
    The SLaM SUBHALO PIPELINE for fitting imaging data with or without a lens light component, where it is assumed
    that the subhalo is at the same redshift as the lens galaxy.

    Parameters
    ----------
    path_prefix
        The prefix of folders between the output path and the search folders.
    analysis
        The analysis class which includes the `log_likelihood_function` and can be customized for the SLaM model-fit.
    setup_hyper
        The setup of the hyper analysis if used (e.g. hyper-galaxy noise scaling).
    mass_results
        The results of the SLaM MASS PIPELINE which ran before this pipeline.
    subhalo_mass
        The `MassProfile` used to fit the subhalo in this pipeline.
    grid_dimension_arcsec
        the arc-second dimensions of the grid in the y and x directions. An input value of 3.0" means the grid in
        all four directions extends to 3.0" giving it dimensions 6.0" x 6.0".
    number_of_steps
        The 2D dimensions of the grid (e.g. number_of_steps x number_of_steps) that the subhalo search is performed for.
    number_of_cores
        The number of cores used to perform the non-linear search grid search. If 1, each model-fit on the grid is
        performed in serial, if > 1 fits are distributed in parallel using the Python multiprocessing module.
    unique_tag
        The unique tag for this model-fit, which will be given a unique entry in the sqlite database and also acts as
        the folder after the path prefix and before the search name. This is typically the name of the dataset.
    """
    """
    __Model + Search + Analysis + Model-Fit (Search 1)__

    In search 1 of the SUBHALO PIPELINE we fit a lens model where:

     - The lens galaxy mass is modeled using MASS PIPELINE's mass distribution [Priors initialized from MASS PIPELINE].
     - The source galaxy's light is parametric or an inversion depending on the previous MASS PIPELINE [Model and 
     priors initialized from MASS PIPELINE].

    This search aims to accurately estimate the lens mass model, using the improved mass model priors and source model 
    of the MASS PIPELINE. This model will be used to perform Bayesian model comparison with models that include a 
    subhalo, to determine if a subhalo is detected.
    """

    source = slam_util.source__from_result_model_if_parametric(
        result=mass_results.last, setup_hyper=setup_hyper)

    model = af.Collection(
        galaxies=af.Collection(lens=mass_results.last.model.galaxies.lens,
                               source=source),
        hyper_image_sky=setup_hyper.hyper_image_sky_from_result(
            result=mass_results.last, as_model=True),
        hyper_background_noise=setup_hyper.hyper_background_noise_from_result(
            result=mass_results.last),
    )

    search = af.DynestyStatic(
        path_prefix=path_prefix,
        name="subhalo[1]_mass[total_refine]",
        unique_tag=unique_tag,
        session=session,
        nlive=100,
    )

    result_1 = search.fit(model=model, analysis=analysis)
    """
    __Model + Search + Analysis + Model-Fit (Search 2)__

    In search 2 of the SUBHALO PIPELINE we perform a [number_of_steps x number_of_steps] grid search of non-linear
    searches where:

     - The lens galaxy mass is modeled using MASS PIPELINE's mass distribution [Priors initialized from MASS PIPELINE].
     - The source galaxy's light is parametric or an inversion depending on the previous MASS PIPELINE [Model and 
     priors initialized from MASS PIPELINE].
     - The subhalo redshift is fixed to that of the lens galaxy.
     - Each grid search varies the subhalo (y,x) coordinates and mass as free parameters.
     - The priors on these (y,x) coordinates are UniformPriors, with limits corresponding to the grid-cells.

    This search aims to detect a dark matter subhalo.
    """

    subhalo = af.Model(al.Galaxy,
                       redshift=result_1.instance.galaxies.lens.redshift,
                       mass=subhalo_mass)

    subhalo.mass.mass_at_200 = af.LogUniformPrior(lower_limit=1.0e6,
                                                  upper_limit=1.0e11)
    subhalo.mass.centre_0 = af.UniformPrior(lower_limit=-grid_dimension_arcsec,
                                            upper_limit=grid_dimension_arcsec)
    subhalo.mass.centre_1 = af.UniformPrior(lower_limit=-grid_dimension_arcsec,
                                            upper_limit=grid_dimension_arcsec)

    subhalo.mass.redshift_object = result_1.instance.galaxies.lens.redshift
    subhalo.mass.redshift_source = result_1.instance.galaxies.source.redshift

    source = slam_util.source__from_result_model_if_parametric(
        result=mass_results.last, setup_hyper=setup_hyper)

    model = af.Collection(
        galaxies=af.Collection(lens=mass_results.last.model.galaxies.lens,
                               subhalo=subhalo,
                               source=source),
        hyper_image_sky=setup_hyper.hyper_image_sky_from_result(
            result=mass_results.last, as_model=True),
        hyper_background_noise=setup_hyper.hyper_background_noise_from_result(
            result=mass_results.last),
    )

    search = af.DynestyStatic(
        path_prefix=path_prefix,
        name="subhalo[2]_mass[total]_source_subhalo[search_lens_plane]",
        unique_tag=unique_tag,
        session=session,
        nlive=50,
        walks=5,
        facc=0.2,
    )

    subhalo_grid_search = af.SearchGridSearch(search=search,
                                              number_of_steps=number_of_steps,
                                              number_of_cores=number_of_cores)

    grid_search_result = subhalo_grid_search.fit(
        model=model,
        analysis=analysis,
        grid_priors=[
            model.galaxies.subhalo.mass.centre_0,
            model.galaxies.subhalo.mass.centre_1,
        ],
    )
    """
    __Model + Search + Analysis + Model-Fit (Search 3)__

    In search 3 of the SUBHALO PIPELINE we refit the lens and source models above but now including a subhalo, where 
    the subhalo model is initalized from the highest evidence model of the subhalo grid search.

     - The lens galaxy mass is modeled using MASS PIPELINE's mass distribution [Priors initialized from MASS PIPELINE].
     - The source galaxy's light is parametric or an inversion depending on the previous MASS PIPELINE [Model and 
     priors initialized from MASS PIPELINE].
     - The subhalo redshift is fixed to that of the lens galaxy.
     - Each grid search varies the subhalo (y,x) coordinates and mass as free parameters.
     - The priors on these (y,x) coordinates are UniformPriors, with limits corresponding to the grid-cells.

    This search aims to refine the parameter estimates and errors of a dark matter subhalo detected in the grid search
    above.
    """

    subhalo = af.Model(al.Galaxy,
                       redshift=result_1.instance.galaxies.lens.redshift,
                       mass=subhalo_mass)

    subhalo.mass.mass_at_200 = (
        grid_search_result.model.galaxies.subhalo.mass.mass_at_200)
    subhalo.mass.centre = grid_search_result.model.galaxies.subhalo.mass.centre

    subhalo.mass.redshift_object = grid_search_result.instance.galaxies.lens.redshift
    subhalo.mass.redshift_source = grid_search_result.instance.galaxies.source.redshift

    model = af.Collection(
        galaxies=af.Collection(
            lens=grid_search_result.model.galaxies.lens,
            subhalo=subhalo,
            source=grid_search_result.model.galaxies.source,
        ),
        hyper_image_sky=grid_search_result.instance.hyper_image_sky,
        hyper_background_noise=grid_search_result.instance.
        hyper_background_noise,
    )

    search = af.DynestyStatic(
        name="subhalo[3]_subhalo[single_plane_refine]",
        unique_tag=unique_tag,
        session=session,
        path_prefix=path_prefix,
        nlive=100,
    )

    result_3 = search.fit(model=model, analysis=analysis)

    return af.ResultsCollection([result_1, grid_search_result, result_3])
示例#6
0
def no_lens_light(
    settings_autofit: slam_util.SettingsAutoFit,
    analysis: Union[al.AnalysisImaging, al.AnalysisInterferometer],
    setup_hyper: al.SetupHyper,
    source_parametric_results: af.ResultsCollection,
    pixelization: af.Model(al.pix.Pixelization) = af.Model(
        al.pix.VoronoiBrightnessImage),
    regularization: af.Model(al.reg.Regularization) = af.Model(
        al.reg.Constant),
) -> af.ResultsCollection:
    """
    The S:aM SOURCE INVERSION PIPELINE for fitting imaging data without a lens light component.

    Parameters
    ----------
    analysis
        The analysis class which includes the `log_likelihood_function` and can be customized for the SLaM model-fit.
    setup_hyper
        The setup of the hyper analysis if used (e.g. hyper-galaxy noise scaling).
    source_parametric_results
        The results of the SLaM SOURCE PARAMETRIC PIPELINE which ran before this pipeline.
    pixelization
        The pixelization used by the `Inversion` which fits the source light.
    regularization
        The regularization used by the `Inversion` which fits the source light.
    """
    """
    __Model + Search + Analysis + Model-Fit (Search 1)__

    In search 1 of the SOURCE INVERSION PIPELINE we fit a lens model where:

     - The lens galaxy mass is modeled using a total mass distribution [parameters fixed to result of SOURCE PARAMETRIC 
     PIPELINE].
     - The source galaxy's light is a `VoronoiMagnification` pixelization and `Constant` regularization scheme.

    This search aims to quickly estimate values for the pixelization resolution and regularization coefficient.
    """
    model = af.Collection(
        galaxies=af.Collection(
            lens=af.Model(
                al.Galaxy,
                redshift=source_parametric_results.last.instance.galaxies.lens.
                redshift,
                mass=source_parametric_results.last.instance.galaxies.lens.
                mass,
                shear=source_parametric_results.last.instance.galaxies.lens.
                shear,
            ),
            source=af.Model(
                al.Galaxy,
                redshift=source_parametric_results.last.instance.galaxies.
                source.redshift,
                pixelization=al.pix.VoronoiMagnification,
                regularization=al.reg.Constant,
                hyper_galaxy=setup_hyper.hyper_galaxy_source_from_result(
                    result=source_parametric_results.last),
            ),
        ),
        hyper_image_sky=setup_hyper.hyper_image_sky_from_result(
            result=source_parametric_results.last, as_model=False),
        hyper_background_noise=setup_hyper.hyper_background_noise_from_result(
            result=source_parametric_results.last),
    )

    search = af.DynestyStatic(
        path_prefix=settings_autofit.path_prefix,
        name=
        "source_inversion[1]_mass[fixed]_source[inversion_magnification_initialization]",
        unique_tag=settings_autofit.unique_tag,
        number_of_cores=settings_autofit.number_of_cores,
        session=settings_autofit.session,
        nlive=30,
    )

    result_1 = search.fit(model=model,
                          analysis=analysis.no_positions,
                          info=settings_autofit.info)
    """
    __Model + Search + Analysis + Model-Fit (Search 2)__

    In search 2 of the SOURCE INVERSION PIPELINE we fit a lens model where:

     - The lens galaxy mass is modeled using a total mass distribution [parameters initialized from the results of the 
     SOURCE PARAMETRIC PIPELINE].
     - The source galaxy's light is a `VoronoiMagnification` pixelization and `Constant` regularization scheme 
     [parameters are fixed to the result of search 1].

    This search aims to improve the lens mass model using the search 1 `Inversion`.
    """
    model = af.Collection(
        galaxies=af.Collection(
            lens=af.Model(
                al.Galaxy,
                redshift=result_1.instance.galaxies.lens.redshift,
                mass=source_parametric_results.last.model.galaxies.lens.mass,
                shear=source_parametric_results.last.model.galaxies.lens.shear,
            ),
            source=af.Model(
                al.Galaxy,
                redshift=result_1.instance.galaxies.source.redshift,
                pixelization=result_1.instance.galaxies.source.pixelization,
                regularization=result_1.instance.galaxies.source.
                regularization,
                hyper_galaxy=result_1.instance.galaxies.source.hyper_galaxy,
            ),
        ),
        hyper_image_sky=result_1.instance.hyper_image_sky,
        hyper_background_noise=result_1.instance.hyper_background_noise,
    )

    search = af.DynestyStatic(
        path_prefix=settings_autofit.path_prefix,
        name="source_inversion[2]_mass[total]_source[fixed]",
        unique_tag=settings_autofit.unique_tag,
        number_of_cores=settings_autofit.number_of_cores,
        session=settings_autofit.session,
        nlive=50,
    )

    result_2 = search.fit(model=model,
                          analysis=analysis,
                          info=settings_autofit.info)
    """
    __Model + Search + Analysis + Model-Fit (Search 3)__

    In search 3 of the SOURCE INVERSION PIPELINE we fit a lens model where:

     - The lens galaxy mass is modeled using a total mass distribution [parameters fixed to result of search 2].
     - The source galaxy's light is the input pixelization and regularization.

    This search aims to estimate values for the pixelization and regularization scheme.
    """

    model = af.Collection(
        galaxies=af.Collection(
            lens=af.Model(
                al.Galaxy,
                redshift=result_2.instance.galaxies.lens.redshift,
                mass=result_2.instance.galaxies.lens.mass,
                shear=result_2.instance.galaxies.lens.shear,
            ),
            source=af.Model(
                al.Galaxy,
                redshift=result_2.instance.galaxies.source.redshift,
                pixelization=pixelization,
                regularization=regularization,
                hyper_galaxy=result_2.instance.galaxies.source.hyper_galaxy,
            ),
        ),
        hyper_image_sky=result_2.instance.hyper_image_sky,
        hyper_background_noise=result_2.instance.hyper_background_noise,
    )

    search = af.DynestyStatic(
        path_prefix=settings_autofit.path_prefix,
        name="source_inversion[3]_mass[fixed]_source[inversion_initialization]",
        unique_tag=settings_autofit.unique_tag,
        number_of_cores=settings_autofit.number_of_cores,
        session=settings_autofit.session,
        nlive=30,
        dlogz=10.0,
        sample="rstagger",
    )

    analysis.set_hyper_dataset(result=result_2)

    result_3 = search.fit(model=model,
                          analysis=analysis.no_positions,
                          info=settings_autofit.info)
    result_3.use_as_hyper_dataset = True
    """
    __Model + Search + Analysis + Model-Fit (Search 4)__

    In search 4 of the SOURCE INVERSION PIPELINE we fit a lens model where:

     - The lens galaxy mass is modeled using a total mass distribution [parameters initialized from the results of the 
     search 2].
     - The source galaxy's light is the input pixelization and regularization scheme [parameters fixed to the result 
     of search 3].

    This search aims to improve the lens mass model using the input `Inversion`.
    """
    mass = slam_util.mass__from_result(
        mass=result_2.model.galaxies.lens.mass,
        result=source_parametric_results.last,
        unfix_mass_centre=True,
    )

    model = af.Collection(
        galaxies=af.Collection(
            lens=af.Model(
                al.Galaxy,
                redshift=result_3.instance.galaxies.lens.redshift,
                mass=mass,
                shear=result_2.model.galaxies.lens.shear,
            ),
            source=af.Model(
                al.Galaxy,
                redshift=result_3.instance.galaxies.source.redshift,
                pixelization=result_3.instance.galaxies.source.pixelization,
                regularization=result_3.instance.galaxies.source.
                regularization,
                hyper_galaxy=result_3.instance.galaxies.source.hyper_galaxy,
            ),
        ),
        hyper_image_sky=result_3.instance.hyper_image_sky,
        hyper_background_noise=result_3.instance.hyper_background_noise,
    )

    analysis.preloads = al.Preloads.setup(result=result_3,
                                          model=model,
                                          pixelization=True)

    search = af.DynestyStatic(
        path_prefix=settings_autofit.path_prefix,
        name="source_inversion[4]_mass[total]_source[fixed]",
        unique_tag=settings_autofit.unique_tag,
        number_of_cores=settings_autofit.number_of_cores,
        session=settings_autofit.session,
        nlive=50,
    )

    result_4 = search.fit(model=model,
                          analysis=analysis,
                          info=settings_autofit.info)
    """
    __Hyper Extension__

    The above search is extended with a hyper-search if the SetupHyper has one or more of the following inputs:

     - The source is using an `Inversion`.
     - One or more `HyperGalaxy`'s are included.
     - The background sky is included via `hyper_image_sky` input.
     - The background noise is included via the `hyper_background_noise`.
    """
    result_4 = extensions.hyper_fit(
        setup_hyper=setup_hyper,
        result=result_4,
        analysis=analysis,
        include_hyper_image_sky=True,
    )

    return af.ResultsCollection([result_1, result_2, result_3, result_4])