def with_lens_light( settings_autofit: af.SettingsSearch, analysis: Union[al.AnalysisImaging, al.AnalysisInterferometer], setup_hyper: al.SetupHyper, source_results: af.ResultsCollection, light_results: af.ResultsCollection, lens_bulge: Optional[af.Model] = af.Model(al.lp.EllSersic), lens_disk: Optional[af.Model] = None, lens_envelope: Optional[af.Model] = None, dark: af.Model = af.Model(al.mp.EllNFWMCRLudlow), smbh: Optional[af.Model] = 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=light_results.last), ), source=source, ), hyper_image_sky=setup_hyper.hyper_image_sky_from( result=light_results.last, as_model=True), hyper_background_noise=setup_hyper.hyper_background_noise_from( result=light_results.last), ) search = af.DynestyStatic( name="mass_light_dark[1]_light[parametric]_mass[light_dark]_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])
def with_lens_light( settings_autofit: af.SettingsSearch, analysis: Union[al.AnalysisImaging, al.AnalysisInterferometer], setup_hyper: al.SetupHyper, source_results: af.ResultsCollection, light_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 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. 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=light_results.last.instance.galaxies.lens.redshift, bulge=light_results.last.instance.galaxies.lens.bulge, disk=light_results.last.instance.galaxies.lens.disk, envelope=light_results.last.instance.galaxies.lens.envelope, mass=mass, shear=source_results.last.model.galaxies.lens.shear, smbh=smbh, hyper_galaxy=setup_hyper.hyper_galaxy_lens_from( result=light_results.last), ), 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]_light[parametric]_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])
def with_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 SLaM SOURCE INVERSION 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_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 light is modeled using a parametric bulge + disk + envelope [parameters fixed to result of SOURCE PARAMETER PIPELINE]. - 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, bulge=source_parametric_results.last.instance.galaxies.lens. bulge, disk=source_parametric_results.last.instance.galaxies.lens. disk, envelope=source_parametric_results.last.instance.galaxies.lens. envelope, mass=source_parametric_results.last.instance.galaxies.lens. mass, shear=source_parametric_results.last.instance.galaxies.lens. shear, hyper_galaxy=setup_hyper.hyper_galaxy_lens_from( result=source_parametric_results.last), ), 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]_light[fixed]_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 light is modeled using a parametric bulge + disk + envelope [parameters fixed to result of SOURCE PARAMETER PIPELINE]. - 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, bulge=result_1.instance.galaxies.lens.bulge, disk=result_1.instance.galaxies.lens.disk, envelope=result_1.instance.galaxies.lens.envelope, mass=source_parametric_results.last.model.galaxies.lens.mass, shear=source_parametric_results.last.model.galaxies.lens.shear, hyper_galaxy=result_1.instance.galaxies.lens.hyper_galaxy, ), 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]_light[fixed]_mass[total]_source[inversion_magnification]", **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 light is modeled using a parametric bulge + disk + envelope [parameters fixed to result of SOURCE PARAMETER PIPELINE]. - 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, bulge=result_2.instance.galaxies.lens.bulge, disk=result_2.instance.galaxies.lens.disk, envelope=result_2.instance.galaxies.lens.envelope, mass=result_2.instance.galaxies.lens.mass, shear=result_2.instance.galaxies.lens.shear, hyper_galaxy=result_2.instance.galaxies.lens.hyper_galaxy, ), 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]_light[fixed]_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 light is modeled using a parametric bulge + disk + envelope [parameters fixed to result of SOURCE PARAMETER PIPELINE]. - 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, bulge=result_3.instance.galaxies.lens.bulge, disk=result_3.instance.galaxies.lens.disk, envelope=result_3.instance.galaxies.lens.envelope, mass=mass, shear=result_2.model.galaxies.lens.shear, hyper_galaxy=result_3.instance.galaxies.lens.hyper_galaxy, ), 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]_light[fixed]_mass[total]_source[inversion]", **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])
def detection( settings_autofit: af.SettingsSearch, analysis: Union[al.AnalysisImaging, al.AnalysisInterferometer], setup_hyper: al.SetupHyper, mass_results: af.ResultsCollection, subhalo_mass: af.Model = af.Model(al.mp.SphNFWMCRLudlow), free_redshift: bool = False, grid_dimension_arcsec: float = 3.0, number_of_steps: Union[Tuple[int], int] = 5, ) -> 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 ---------- 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". free_redshift If `True` the redshift of the subhalo is a free parameter in the second and third searches. 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. """ """ __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) lens = mass_results.last.model.galaxies.lens lens.hyper_galaxy = setup_hyper.hyper_galaxy_lens_from( result=mass_results.last) model = af.Collection( galaxies=af.Collection(lens=lens, source=source), hyper_image_sky=setup_hyper.hyper_image_sky_from( result=mass_results.last, as_model=True), hyper_background_noise=setup_hyper.hyper_background_noise_from( result=mass_results.last), ) search_no_subhalo = af.DynestyStatic(name="subhalo[1]_mass[total_refine]", **settings_autofit.search_dict, nlive=100) result_1 = search_no_subhalo.fit(model=model, analysis=analysis, **settings_autofit.fit_dict) """ __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, 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) if not free_redshift: subhalo.redshift = result_1.instance.galaxies.lens.redshift subhalo.mass.redshift_object = result_1.instance.galaxies.lens.redshift search_tag = "search_lens_plane" refine_tag = "single_plane_refine" else: subhalo.redshift = af.UniformPrior( lower_limit=0.0, upper_limit=result_1.instance.galaxies.source.redshift) subhalo.mass.redshift_object = subhalo.redshift search_tag = "search_multi_plane" refine_tag = "multi_plane_refine" 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=lens, subhalo=subhalo, source=source), hyper_image_sky=setup_hyper.hyper_image_sky_from( result=mass_results.last, as_model=True), hyper_background_noise=setup_hyper.hyper_background_noise_from( result=mass_results.last), ) search = af.DynestyStatic( name=f"subhalo[2]_mass[total]_source_subhalo[{search_tag}]", **settings_autofit.search_dict_x1_core, nlive=50, walks=5, facc=0.2, ) number_of_cores = 2 subhalo_grid_search = af.SearchGridSearch(search=search, number_of_steps=number_of_steps, number_of_cores=number_of_cores) subhalo_result = subhalo_grid_search.fit( model=model, analysis=analysis, grid_priors=[ model.galaxies.subhalo.mass.centre_1, model.galaxies.subhalo.mass.centre_0, ], info=settings_autofit.info, parent=search_no_subhalo, ) """ __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 = af.LogUniformPrior(lower_limit=1.0e6, upper_limit=1.0e11) subhalo.mass.centre = subhalo_result.model_absolute( a=1.0).galaxies.subhalo.mass.centre subhalo.redshift = subhalo_result.model.galaxies.subhalo.redshift subhalo.mass.redshift_object = subhalo.redshift # subhalo.mass.redshift_object = subhalo_result.instance.galaxies.lens.redshift # subhalo.mass.redshift_source = subhalo_result.instance.galaxies.source.redshift model = af.Collection( galaxies=af.Collection( lens=subhalo_result.model.galaxies.lens, subhalo=subhalo, source=subhalo_result.model.galaxies.source, ), hyper_image_sky=setup_hyper.hyper_image_sky_from( result=mass_results.last, as_model=True), hyper_background_noise=setup_hyper.hyper_background_noise_from( result=mass_results.last), ) search = af.DynestyStatic( name=f"subhalo[3]_subhalo[{refine_tag}]", **settings_autofit.search_dict, nlive=100, ) result_3 = search.fit(model=model, analysis=analysis, **settings_autofit.fit_dict) return af.ResultsCollection([result_1, subhalo_result, result_3])
def with_lens_light( settings_autofit: af.SettingsSearch, analysis: Union[al.AnalysisImaging, al.AnalysisInterferometer], setup_hyper: al.SetupHyper, source_results: af.ResultsCollection, lens_bulge: Optional[af.Model] = af.Model(al.lp.EllSersic), lens_disk: Optional[af.Model] = None, lens_envelope: Optional[af.Model] = None, end_with_hyper_extension: bool = False, ) -> af.ResultsCollection: """ The SlaM LIGHT PARAMETRIC PIPELINE for fitting imaging data with a lens light component. Parameters ---------- settings_autofit A collection of settings that control the behaviour of PyAutoFit thoughout the pipeline (e.g. paths, database, parallelization, etc.). 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. """ """ __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=source_results.last, noise_factor_is_model=True) source = slam_util.source__from(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=source_results.last, as_model=True), hyper_background_noise=setup_hyper.hyper_background_noise_from( result=source_results.last), ) search = af.DynestyStatic(name="light[1]_light[parametric]", **settings_autofit.search_dict, nlive=150) result_1 = 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`. """ 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])