|
1 | | -import numpy as np |
2 | | -import pytest |
3 | | - |
4 | | -import autolens as al |
5 | | - |
6 | | - |
7 | | -def test__one_set_of_time_delays__residuals_likelihood_correct(): |
8 | | - # Mock tracer returns fixed time delays (like magnifications in original) |
9 | | - tracer = al.m.MockTracerPoint( |
10 | | - profile=al.ps.Point(), |
11 | | - time_delays=al.ArrayIrregular([2.0, 2.0]), # Mock time delays for two positions |
12 | | - ) |
13 | | - |
14 | | - data = al.ArrayIrregular([1.0, 2.0]) # observed time delays |
15 | | - noise_map = al.ArrayIrregular([3.0, 1.0]) |
16 | | - positions = al.Grid2DIrregular([(0.0, 0.0), (3.0, 4.0)]) |
17 | | - |
18 | | - fit = al.FitTimeDelays( |
19 | | - name="point_0", |
20 | | - data=data, |
21 | | - noise_map=noise_map, |
22 | | - positions=positions, |
23 | | - tracer=tracer, |
24 | | - ) |
25 | | - |
26 | | - assert fit.data.in_list == [1.0, 2.0] |
27 | | - assert fit.noise_map.in_list == [3.0, 1.0] |
28 | | - assert fit.model_time_delays.in_list == [2.0, 2.0] |
29 | | - assert fit.residual_map.in_list == [0.0, 1.0] |
30 | | - assert fit.normalized_residual_map.in_list == [0.0, 1.0] |
31 | | - assert fit.chi_squared_map.in_list == [0.0, 1.0] |
32 | | - assert fit.chi_squared == pytest.approx(1.0, 1.0e-4) |
33 | | - assert fit.noise_normalization == pytest.approx(5.87297, 1.0e-4) |
34 | | - assert fit.log_likelihood == pytest.approx(-3.43648935, 1.0e-4) |
35 | | - |
36 | | - |
37 | | -def test__use_real_tracer(gal_x1_mp): |
38 | | - |
39 | | - point_source = al.ps.Point(centre=(0.1, 0.1)) |
40 | | - galaxy_point_source = al.Galaxy(redshift=1.0, point_0=point_source) |
41 | | - tracer = al.Tracer(galaxies=[gal_x1_mp, galaxy_point_source]) |
42 | | - |
43 | | - data = al.ArrayIrregular([1.0, 2.0]) # observed time delays |
44 | | - noise_map = al.ArrayIrregular([3.0, 1.0]) |
45 | | - positions = al.Grid2DIrregular([(0.0, 0.0), (3.0, 4.0)]) |
46 | | - |
47 | | - fit = al.FitTimeDelays( |
48 | | - name="point_0", |
49 | | - data=data, |
50 | | - noise_map=noise_map, |
51 | | - positions=positions, |
52 | | - tracer=tracer, |
53 | | - ) |
54 | | - |
55 | | - # Replace 2.5 with expected model time delay from your tracer |
56 | | - assert fit.model_time_delays.in_list[1] == pytest.approx(-573.994580905, 1.0e-4) |
57 | | - assert fit.log_likelihood == pytest.approx(-22600.81488747, 1.0e-4) |
| 1 | +import numpy as np |
| 2 | +import pytest |
| 3 | + |
| 4 | +import autolens as al |
| 5 | + |
| 6 | + |
| 7 | +def test__fit_time_delays__all_residual_quantities_computed_correctly_with_mock_tracer(): |
| 8 | + tracer = al.m.MockTracerPoint( |
| 9 | + profile=al.ps.Point(), |
| 10 | + time_delays=al.ArrayIrregular([2.0, 2.0]), |
| 11 | + ) |
| 12 | + |
| 13 | + data = al.ArrayIrregular([1.0, 2.0]) |
| 14 | + noise_map = al.ArrayIrregular([3.0, 1.0]) |
| 15 | + positions = al.Grid2DIrregular([(0.0, 0.0), (3.0, 4.0)]) |
| 16 | + |
| 17 | + fit = al.FitTimeDelays( |
| 18 | + name="point_0", |
| 19 | + data=data, |
| 20 | + noise_map=noise_map, |
| 21 | + positions=positions, |
| 22 | + tracer=tracer, |
| 23 | + ) |
| 24 | + |
| 25 | + assert fit.data.in_list == [1.0, 2.0] |
| 26 | + assert fit.noise_map.in_list == [3.0, 1.0] |
| 27 | + assert fit.model_time_delays.in_list == [2.0, 2.0] |
| 28 | + assert fit.residual_map.in_list == [0.0, 1.0] |
| 29 | + assert fit.normalized_residual_map.in_list == [0.0, 1.0] |
| 30 | + assert fit.chi_squared_map.in_list == [0.0, 1.0] |
| 31 | + assert fit.chi_squared == pytest.approx(1.0, 1.0e-4) |
| 32 | + assert fit.noise_normalization == pytest.approx(5.87297, 1.0e-4) |
| 33 | + assert fit.log_likelihood == pytest.approx(-3.43648935, 1.0e-4) |
| 34 | + |
| 35 | + |
| 36 | +def test__fit_time_delays__model_time_delays_correct_with_real_isothermal_tracer( |
| 37 | + gal_x1_mp, |
| 38 | +): |
| 39 | + point_source = al.ps.Point(centre=(0.1, 0.1)) |
| 40 | + galaxy_point_source = al.Galaxy(redshift=1.0, point_0=point_source) |
| 41 | + tracer = al.Tracer(galaxies=[gal_x1_mp, galaxy_point_source]) |
| 42 | + |
| 43 | + data = al.ArrayIrregular([1.0, 2.0]) |
| 44 | + noise_map = al.ArrayIrregular([3.0, 1.0]) |
| 45 | + positions = al.Grid2DIrregular([(0.0, 0.0), (3.0, 4.0)]) |
| 46 | + |
| 47 | + fit = al.FitTimeDelays( |
| 48 | + name="point_0", |
| 49 | + data=data, |
| 50 | + noise_map=noise_map, |
| 51 | + positions=positions, |
| 52 | + tracer=tracer, |
| 53 | + ) |
| 54 | + |
| 55 | + assert fit.model_time_delays.in_list[1] == pytest.approx(-573.994580905, 1.0e-4) |
| 56 | + assert fit.log_likelihood == pytest.approx(-22600.81488747, 1.0e-4) |
0 commit comments