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( 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 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 `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, 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( result=source_parametric_results.last), ), 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]_light[fixed]_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 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 `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, 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( path_prefix=settings_autofit.path_prefix, name= "source_inversion[2]_light[fixed]_mass[total]_source[inversion_magnification]", 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 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( path_prefix=settings_autofit.path_prefix, name= "source_inversion[3]_light[fixed]_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 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_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, 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, ) 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]_light[fixed]_mass[total]_source[inversion]", 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])
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])
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, mass: af.Model(al.mp.MassProfile) = af.Model(al.mp.EllIsothermal), smbh: af.Model(al.mp.MassProfile) = 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_result( 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( result=light_results.last ), ), source=source, ) ) search = af.DynestyStatic( path_prefix=settings_autofit.path_prefix, name="mass_total[1]_light[parametric]_mass[total]_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])