|
| 1 | +import pytest |
| 2 | +import numpy as np |
| 3 | + |
| 4 | +import autofit as af |
| 5 | +import autogalaxy as ag |
| 6 | + |
| 7 | + |
| 8 | +def test__mge_point_model_from__returns_basis_model_with_correct_gaussians(): |
| 9 | + """ |
| 10 | + mge_point_model_from should return an af.Model wrapping a Basis whose |
| 11 | + profile_list contains the requested number of linear Gaussian components. |
| 12 | + """ |
| 13 | + model = ag.model_util.mge_point_model_from(pixel_scales=0.1, total_gaussians=5) |
| 14 | + |
| 15 | + instance = model.instance_from_prior_medians() |
| 16 | + |
| 17 | + assert isinstance(instance, ag.lp_basis.Basis) |
| 18 | + assert len(instance.profile_list) == 5 |
| 19 | + |
| 20 | + |
| 21 | +def test__mge_point_model_from__sigma_values_span_correct_range(): |
| 22 | + """ |
| 23 | + Sigma values should run from 10^-2 = 0.01 arcseconds up to 2 * pixel_scales, |
| 24 | + logarithmically spaced. |
| 25 | + """ |
| 26 | + pixel_scales = 0.1 |
| 27 | + total_gaussians = 10 |
| 28 | + |
| 29 | + model = ag.model_util.mge_point_model_from( |
| 30 | + pixel_scales=pixel_scales, total_gaussians=total_gaussians |
| 31 | + ) |
| 32 | + |
| 33 | + gaussian_list = list(model.profile_list) |
| 34 | + |
| 35 | + assert gaussian_list[0].sigma == pytest.approx(0.01, rel=1.0e-4) |
| 36 | + assert gaussian_list[-1].sigma == pytest.approx(pixel_scales * 2.0, rel=1.0e-4) |
| 37 | + |
| 38 | + |
| 39 | +def test__mge_point_model_from__shared_centre_and_ell_comps(): |
| 40 | + """ |
| 41 | + All Gaussians must share exactly the same centre prior objects and ell_comps |
| 42 | + prior objects so the model has only 4 free parameters total. |
| 43 | + """ |
| 44 | + model = ag.model_util.mge_point_model_from(pixel_scales=0.1, total_gaussians=5) |
| 45 | + |
| 46 | + gaussian_list = list(model.profile_list) |
| 47 | + |
| 48 | + # Centres are all the same prior objects |
| 49 | + for gaussian in gaussian_list[1:]: |
| 50 | + assert gaussian.centre.centre_0 is gaussian_list[0].centre.centre_0 |
| 51 | + assert gaussian.centre.centre_1 is gaussian_list[0].centre.centre_1 |
| 52 | + |
| 53 | + # Ell_comps are all the same prior objects |
| 54 | + for gaussian in gaussian_list[1:]: |
| 55 | + assert gaussian.ell_comps is gaussian_list[0].ell_comps |
| 56 | + |
| 57 | + # Only 4 free parameters: centre_0, centre_1, ell_comps_0, ell_comps_1 |
| 58 | + assert model.prior_count == 4 |
| 59 | + |
| 60 | + |
| 61 | +def test__mge_point_model_from__centre_prior_bounds(): |
| 62 | + """ |
| 63 | + When a custom centre is supplied the UniformPrior limits shift by ±0.1 |
| 64 | + arcseconds around that centre. |
| 65 | + """ |
| 66 | + centre = (0.3, -0.2) |
| 67 | + model = ag.model_util.mge_point_model_from( |
| 68 | + pixel_scales=0.1, total_gaussians=3, centre=centre |
| 69 | + ) |
| 70 | + |
| 71 | + gaussian_list = list(model.profile_list) |
| 72 | + centre_0_prior = gaussian_list[0].centre.centre_0 |
| 73 | + centre_1_prior = gaussian_list[0].centre.centre_1 |
| 74 | + |
| 75 | + assert isinstance(centre_0_prior, af.UniformPrior) |
| 76 | + assert centre_0_prior.lower_limit == pytest.approx(centre[0] - 0.1, rel=1.0e-6) |
| 77 | + assert centre_0_prior.upper_limit == pytest.approx(centre[0] + 0.1, rel=1.0e-6) |
| 78 | + |
| 79 | + assert isinstance(centre_1_prior, af.UniformPrior) |
| 80 | + assert centre_1_prior.lower_limit == pytest.approx(centre[1] - 0.1, rel=1.0e-6) |
| 81 | + assert centre_1_prior.upper_limit == pytest.approx(centre[1] + 0.1, rel=1.0e-6) |
0 commit comments