Skip to content

Commit 499a90f

Browse files
author
NiekWielders
committed
added functions for a second main galaxy
1 parent 9baff2e commit 499a90f

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed

autogalaxy/analysis/chaining_util.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,87 @@ def mass_light_dark_basis_from(
515515

516516
return af.Model(Basis, profile_list=lmp_model_list)
517517

518+
def mass_light_dark_basis_two_from(
519+
name: str,
520+
lp_chain_tracer,
521+
linear_lp_to_standard: bool = False,
522+
use_gradient: bool = False,
523+
) -> af.Model:
524+
"""
525+
Returns a basis containing light and mass profiles from a basis (e.g. an MGE) in the LIGHT PIPELINE result, for the
526+
LIGHT DARK MASS PIPELINE.
527+
528+
For example, if the light pipeline fits a basis of Gaussians, this function will return a basis of Gaussians for the
529+
LIGHT DARK MASS PIPELINE where each Gaussian has been converted to a light and mass profile.
530+
531+
These profiles will have been converted from standard light profiles / linear light profiles to light and mass
532+
profiles, where their light profile parameters (e.g. their `centre`, `ell_comps`) are used to set up the parameters
533+
of the light and mass profile.
534+
535+
For the light profile, it will by default use a linear light and mass profile, which therefore continues to solve
536+
for the intensity of the linear light profile via linear algebra. This means that during the fit the `intensity`
537+
used to compute deflection angles is not the same as the `intensity` parameter solved for in the linear light
538+
profile. If the input `linear_lp_to_standard` is `True`, the function will instead use a standard light profile.
539+
540+
The light and mass profiles can also be switched to variants which have a radial gradient in their mass-to-light
541+
conversion, by setting the `include_mass_to_light_gradient` parameter to `True`.
542+
543+
Parameters
544+
----------
545+
light_result
546+
The result of the light pipeline, which determines the light and mass profiles used in the LIGHT DARK
547+
MASS PIPELINE.
548+
name
549+
The name of the light profile in the light pipeline's galaxy model that the model is being created for
550+
(e.g. `bulge`).
551+
552+
Returns
553+
-------
554+
The light and mass profile for a basis (e.g. an MGE) whose priors are initialized from a previous result.
555+
"""
556+
557+
try:
558+
lp_instance = getattr(
559+
lp_chain_tracer.galaxies[1],
560+
name,
561+
)
562+
except AttributeError:
563+
return None
564+
565+
profile_list = lp_instance.profile_list
566+
567+
lmp_model_list = []
568+
569+
for i, light_profile in enumerate(profile_list):
570+
if not linear_lp_to_standard:
571+
if not use_gradient:
572+
lmp_model = af.Model(lmp_linear.Gaussian)
573+
else:
574+
lmp_model = af.Model(lmp_linear.GaussianGradient)
575+
else:
576+
if not use_gradient:
577+
lmp_model = af.Model(lmp.Gaussian)
578+
else:
579+
lmp_model = af.Model(lmp.GaussianGradient)
580+
581+
lmp_model.centre = light_profile.centre
582+
lmp_model.ell_comps = light_profile.ell_comps
583+
584+
lmp_model.intensity = float(light_profile.intensity)
585+
lmp_model.sigma = light_profile.sigma
586+
587+
lmp_model_list += [lmp_model]
588+
589+
if not use_gradient:
590+
lmp_model.mass_to_light_ratio = lmp_model_list[0].mass_to_light_ratio
591+
else:
592+
lmp_model.mass_to_light_ratio_base = lmp_model_list[
593+
0
594+
].mass_to_light_ratio_base
595+
lmp_model.mass_to_light_gradient = lmp_model_list[0].mass_to_light_gradient
596+
597+
return af.Model(Basis, profile_list=lmp_model_list)
598+
518599

519600
def mass_light_dark_from(
520601
light_result: Result,
@@ -646,3 +727,56 @@ def link_ratios(link_mass_to_light_ratios: bool, light_result, bulge, disk):
646727
].mass_to_light_gradient
647728

648729
return bulge, disk
730+
731+
def link_ratios_two(link_mass_to_light_ratios: bool, light_result, bulge, disk):
732+
"""
733+
Links the mass to light ratios and gradients of the bulge and disk profiles in the MASS LIGHT DARK PIPELINE.
734+
735+
The following use cases are supported:
736+
737+
1) Link the mass to light ratios of the bulge and diskwhen they are both sersic light and mass profile.
738+
2) Link the mass to light ratios of the bulge and disk when for a basis (e.g. an MGE).
739+
3) Does approrpiate linking with the gradient of the mass-to-light ratio for the basis profiles.
740+
741+
Parameters
742+
----------
743+
link_mass_to_light_ratios
744+
Whether the mass-to-light ratios of the bulge and disk profiles are linked.
745+
light_result
746+
The result of the light pipeline, which determines the light and mass profiles used in the MASS LIGHT DARK
747+
PIPELINE.
748+
bulge
749+
The bulge model light profile.
750+
disk
751+
The disk model light profile.
752+
753+
Returns
754+
-------
755+
The bulge and disk profiles with the mass-to-light ratios linked.
756+
"""
757+
758+
if bulge is None or disk is None:
759+
return bulge, disk
760+
761+
if not link_mass_to_light_ratios:
762+
return bulge, disk
763+
764+
bulge_instance = getattr(light_result.instance.extra_galaxies[0], "bulge")
765+
766+
if not isinstance(bulge_instance, Basis):
767+
bulge.mass_to_light_ratio = disk.mass_to_light_ratio
768+
769+
return bulge, disk
770+
771+
for bulge_lp in bulge.profile_list:
772+
try:
773+
bulge_lp.mass_to_light_ratio = disk.profile_list[0].mass_to_light_ratio
774+
except AttributeError:
775+
bulge_lp.mass_to_light_ratio_base = disk.profile_list[
776+
0
777+
].mass_to_light_ratio_base
778+
bulge_lp.mass_to_light_gradient = disk.profile_list[
779+
0
780+
].mass_to_light_gradient
781+
782+
return bulge, disk

0 commit comments

Comments
 (0)