Jammy2211 / PyAutoLens

PyAutoLens: Open Source Strong Gravitational Lensing
https://pyautolens.readthedocs.io/
MIT License
163 stars 32 forks source link

Slam pipeline chaining using mass_total tracer; PowerLaw not working with chaining_util #271

Closed AstroAaron closed 5 months ago

AstroAaron commented 6 months ago

Hello again, using the code from my previous run (#270) I get the following error when the slam pipeline executes source_pix:

Traceback (most recent call last):
  File "/projects/ag-riechers/users/aaron/ALMACE/PyAutoLensNN/source_pixelized_2LensesNewOptVelocityReconstruction.py", line 232, in <module>
    source_pix_results = slam.source_pix2LensesOptBest.run(
  File "/projects/ag-riechers/users/aaron/ALMACE/PyAutoLensNN/slam/source_pix2LensesOptBest.py", line 79, in run
    mass_0 = al.util.chaining.mass_from(
  File "/projects/ag-riechers/users/aaron/ALMACE/PyAutoLensNN/PyAutoGalaxy/autogalaxy/analysis/chaining_util.py", line 43, in mass_from
    mass.take_attributes(source=mass_result)
AttributeError: 'PowerLaw' object has no attribute 'take_attributes'

I have two lenses masses modelled each as a PowerLaw. The chaining_util part of the script looks like this:

mass_0 = al.util.chaining.mass_from(
        mass=source_lp_results.last.model.galaxies.lens_0.mass,
        mass_result=source_lp_results.last.model.galaxies.lens_0.mass,
        unfix_mass_centre=True,
    )

And works for the normal full run without the fixed tracer as input.

Jammy2211 commented 6 months ago

The problem (for this bug and the previous) is that these things:

    mass_0=tracer.planes[0].galaxies[0].mass,
    mass_1=tracer.planes[0].galaxies[1].mass,
    shear=tracer.planes[0].galaxies[0].shear,

Are not af.Model objects but just instances of the PowerLaw and ExternalShear class.

SLaM are modeling pipelines so expect that everything will be PyAutoFit objects.

I think you want to do something like:

mass_0_model = af.Model(al.mp.PowerLaw)
mass_0_model.centre = mass_0.centre
... repeat for all parameters (ell comps, einstein_radius, slope) and for mass_1 and shear
AstroAaron commented 5 months ago

Thank you for the fix. It started the source_pix pipeline without issue.

The problem (for this bug and the previous) is that these things:

Regarding the previous problem: not using positions=positions in positions_likelihood=source_lp_results.last.positions_likelihood_from() did return the same error as in 270, even with your suggestion above.