autolens.analysis.model_util.mge_model_from#
- mge_model_from(mask_radius, total_gaussians=30, gaussian_per_basis=1, centre_prior_is_uniform=True, centre=(0.0, 0.0), centre_fixed=None, centre_per_basis=False, centre_sigma=0.3, ell_comps_prior_is_uniform=False, ell_comps_uniform_width=0.2, ell_comps_sigma=0.3, use_spherical=False, sigma_min=0.0001, ell_comps_limit=1.0, order_bases=False)[source]#
Construct a Multi-Gaussian Expansion (MGE) for the lens or source galaxy light.
This model is designed as a “start here” configuration for lens modeling:
The lens and source light are represented by a Basis object composed of many Gaussian light profiles with fixed logarithmically spaced widths (sigma).
All Gaussians within each basis share common centres and ellipticity components, reducing degeneracy while retaining flexibility.
Users can combine with a lens mass model of their choice.
When
gaussian_per_basis > 1, each basis receives independent ellipticity components (ell_comps), allowing the model to represent twisting or varying isophotes across different radial scales. Centres are shared across bases by default (the common case: one luminosity centre, complex isophotal shape). Setcentre_per_basis=Trueto give each basis its own centre priors.Expected free-parameter counts (elliptical,
use_spherical=False):gaussian_per_basis=1: 2 centre + 2 ell_comps = 4gaussian_per_basis=K(shared centre) : 2 + 2Kgaussian_per_basis=K, centre_per_basis=True: 2K + 2K = 4K
Spherical (
use_spherical=True): no ell_comps, only centres.Shared centre: 2. Per-basis centre: 2K.
- Parameters:
mask_radius (
float) – The outer radius (in arcseconds) of the circular mask applied to the data. This determines the maximum Gaussian width (sigma) used in the MGE.total_gaussians (
int) – Total number of Gaussian light profiles used in each basis.gaussian_per_basis (
int) – Number of separate Gaussian bases. Each basis hastotal_gaussianscomponents sharing the same centre and ellipticity. Multiple bases allow independent ellipticity (and optionally centre) per radial scale group.centre_prior_is_uniform (
bool) – If True (default), centre priors areUniformPrior(±0.1)aroundcentre. If False,GaussianPriorwithcentre_sigma.centre (
Tuple[float,float]) – (y, x) centre in arcseconds used as the mean/midpoint for centre priors.centre_fixed (
Optional[Tuple[float,float]]) – If not None, fix all Gaussian centres to this (y, x) value instead of making them free parameters. Overridescentre_per_basis.centre_per_basis (
bool) – If True, each basis gets independently drawn centre priors. If False (default), all bases share the same centre. Ignored whencentre_fixedis set.centre_sigma (
float) – Sigma forGaussianPriorcentre priors (used whencentre_prior_is_uniform=False).ell_comps_prior_is_uniform (
bool) – If True, ell_comps priors areUniformPrior. If False (default),TruncatedGaussianPrior.ell_comps_uniform_width (
float) – Half-width for uniform ell_comps priors.ell_comps_sigma (
float) – Sigma for truncated-Gaussian ell_comps priors.use_spherical (
bool) – If True, useGaussianSph(no ell_comps). If False (default), useGaussianwith ellipticity.sigma_min (
float) – The smallest Gaussian width (sigma) in arcseconds, which sets the lower end of the log-spaced sigma values. Defaults to1e-4. Increase it (e.g. to a tenth of the pixel scale) to stop the basis wasting components on scales the data cannot resolve.ell_comps_limit (
float) –Half-width of the box the truncated-Gaussian ell_comps priors are truncated to, giving
lower_limit=-ell_comps_limitandupper_limit=+ell_comps_limit. Must satisfy0.0 < ell_comps_limit <= 1.0; the default1.0is the full physical range. Uniform ell_comps priors are unaffected – their width is set byell_comps_uniform_width.Callers tighten this box when the science case bounds the isophotal ellipticity: the Euclid strong-lens pipeline uses
0.5for the lens light and0.7for the source. Setting the box here rather than overwriting the priors on the returned model keeps the prior objects the ones this function built, which matters becauseorder_basesattaches an assertion that references them.order_bases (
bool) –If True, require the bases’ shared
ell_comps_1values to be strictly decreasing,basis_0 > basis_1 > ... > basis_{K-1}, viaK - 1assertions added to the returned model. Defaults to False (off until validated on production runs). A no-op whengaussian_per_basis == 1; aValueErrorwhenuse_spherical=True, which has noell_compsto order.The symmetry. With
gaussian_per_basis=K > 1every basis holds the sametotal_gaussianslinear Gaussians on the same fixedlog10_sigma_list, and differs from its siblings only in the ellipticity pair it carries. The bases are therefore exchangeable: permuting which basis holds whichell_compsleaves the likelihood exactly unchanged, so the posterior hasK!identical modes and an unseeded search lands in whichever one it reaches first. Repeat fits of the same data then report the same physical solution under swapped labels, which breaks any downstream comparison that readsbasis_0as a fixed component. Ordering the bases picks one labelling and deletes the otherK! - 1copies; it removes no physical solution.Why ``ell_comps_1`` and not the magnitude. The key must separate the modes the search actually finds. At the maximum-likelihood point either key admits exactly one permutation, so the choice is not about which key can order a single point – it is about the posterior spread. The two modes are separated in the key by
|key(e_A) - key(e_B)|, and when that separation is smaller than the marginal posterior width in the key the constraint surface passes through both modes: the retained region mixes the two labellings and the labels are still undetermined. On the Euclid phase-4 tiles the two bases commonly sit against opposite edges of the ell_comps box, e.g.(0.007, -0.500)and(-0.023, 0.497). For that pair the magnitude separation is0.0025while theell_comps_1separation is1.0, so thecos 2phicomponent separates the modes by far more than any plausible marginal width and the magnitude does not.Blind band. No continuous key is exact for every configuration – another tile has the two bases only
0.01apart inell_comps_1, a separation small compared with a typical marginal posterior width, so there too the constraint surface passes through both modes and ordering byell_comps_1does not resolve that tile. The diagnostic is a small|delta ell_comps_1|relative to the posterior width: read such a result as undetermined labelling rather than as an ordered answer.Consequences of an assertion being part of the model. It enters the PyAutoFit identifier, so turning
order_baseson gives an otherwise identical fit a newunique_idand a fresh output directory – with PyAutoFit at or after the identifier fix that ships alongside this option (PyAutoFit#1581 follow-up); on older PyAutoFit the ordered and unordered models share an identifier and an ordered fit would load a completed unordered result from the same directory. It also makes the model an invalid target fortake_attributes: PyAutoFit’sassert_no_assertionsrefuses to copy attributes into a model that already carries assertions, so build the ordered model after any such prior-passing step. Prior passing in the other direction drops the ordering altogether:Result.modelis built bygaussian_prior_model_for_arguments, which clears_assertions(PyAutoFit/autofit/mapper/prior_model/prior_model.py, line 601), so a model built from a result is unordered again – recompose theBasiswithorder_bases=Truewhen chaining fits rather than reusing the result’s model. Enforcement is backend-specific but has the same outcome – NumPy raisesaf.exc.FitExceptionfromcheck_assertionsand the search resamples; JAX cannot raise inside a trace and instead evaluates the assertions as a traced boolean and maps a violating model to the resample figure of merit (PyAutoFit #1583).
- Returns:
An
autofit.Modelwrapping aBasisof linear Gaussians.- Return type:
af.Model