def source__from( 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) 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, )
def no_lens_light( settings_autofit: af.SettingsSearch, analysis: Union[al.AnalysisImaging, al.AnalysisInterferometer], setup_hyper: al.SetupHyper, source_parametric_results: af.ResultsCollection, pixelization: af.Model(al.AbstractPixelization) = af.Model( al.pix.DelaunayBrightnessImage), regularization: af.Model(al.AbstractRegularization) = 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 `DelaunayMagnification` 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.DelaunayMagnification, regularization=al.reg.Constant, hyper_galaxy=setup_hyper.hyper_galaxy_source_from( result=source_parametric_results.last), ), ), hyper_image_sky=setup_hyper.hyper_image_sky_from( result=source_parametric_results.last, as_model=False), hyper_background_noise=setup_hyper.hyper_background_noise_from( result=source_parametric_results.last), ) search = af.DynestyStatic( name= "source_inversion[1]_mass[fixed]_source[inversion_magnification_initialization]", **settings_autofit.search_dict, nlive=30, ) result_1 = search.fit(model=model, analysis=analysis, **settings_autofit.fit_dict) """ __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 `DelaunayMagnification` 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( name="source_inversion[2]_mass[total]_source[fixed]", **settings_autofit.search_dict, nlive=50, ) result_2 = search.fit(model=model, analysis=analysis, **settings_autofit.fit_dict) """ __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( name="source_inversion[3]_mass[fixed]_source[inversion_initialization]", **settings_autofit.search_dict, nlive=30, dlogz=10.0, sample="rstagger", ) analysis.set_hyper_dataset(result=result_2) result_3 = search.fit(model=model, analysis=analysis, **settings_autofit.fit_dict) """ __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( 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, ) search = af.DynestyStatic( name="source_inversion[4]_mass[total]_source[fixed]", **settings_autofit.search_dict, nlive=50, ) result_4 = search.fit(model=model, analysis=analysis, **settings_autofit.fit_dict) """ __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])