autolens.analysis.model_util.mass_field_from#

mass_field_from(lens, shear=True, mass_sheet=False, potential=False, redshift=None)[source]#

Build the af.Model(al.MassField, ...) describing the tidal field of everything outside the modelled system, with its geometry tied to a lens galaxy model.

The external field is composed of the components no galaxy owns — an ExternalShear, a MassSheet, an ExternalPotential — and is placed in a model’s fields collection rather than bolted onto a galaxy:

lens = af.Model(al.Galaxy, redshift=0.5, mass=af.Model(al.mp.Isothermal))

model = af.Collection(
    galaxies=af.Collection(lens=lens, source=source),
    fields=af.Collection(field=al.model_util.mass_field_from(lens=lens)),
)

For a single field, fields=al.model_util.mass_field_from(lens=lens) is also supported. This shortens prior paths (fields.shear.gamma_1 instead of fields.field.shear.gamma_1), so the two forms have different result identifiers by design. The collection form above remains the primary example and retains its existing identifier.

The MassSheet and ExternalPotential have a meaningful centre (unlike an ExternalShear, whose deflection field is constant), and that centre is physically the centre of the system the field is expanded about. It is therefore shared with the lens galaxy’s mass centre — the same prior object, not a copy — so the two move together in the non-linear search and cost no extra dimensions.

In a multi-deflector system, lens is the primary deflector: the galaxy whose centre the external expansion is about. Pass that galaxy’s model, not a secondary one.

The galaxy-attached form (af.Model(al.Galaxy, ..., shear=af.Model(al.mp.ExternalShear))) remains fully supported and is not deprecated; this is a second way to write the same physics, one which keeps the external field out of the galaxy.

Parameters:
  • lens (Model) – The af.Model of the (primary) lens galaxy. Its mass.centre is shared with the field’s centred components and, unless redshift is given, its redshift is the field’s redshift.

  • shear (bool) – If True (default), the field includes an ExternalShear.

  • mass_sheet (bool) – If True, the field includes a MassSheet, centred on the lens mass.

  • potential (bool) – If True, the field includes an ExternalPotential, centred on the lens mass.

  • redshift (Optional[float]) – The redshift of the field. Defaults to the lens galaxy model’s redshift.

Returns:

  • The af.Model of the MassField, to be placed in the model’s fields collection

  • or supplied directly as fields for a single field.