Skip to content

Commit 368f928

Browse files
Jammy2211Jammy2211
authored andcommitted
test: cover quick_update=True routing in the four model plotters (#680)
1 parent b87674a commit 368f928

5 files changed

Lines changed: 99 additions & 0 deletions

File tree

test_autolens/imaging/model/test_plotter_imaging.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ def test__fit_imaging(
4141

4242
assert image.shape == (5, 5)
4343

44+
def test__fit_imaging__quick_update__writes_normal_fit_subplot_only(
45+
fit_imaging_x2_plane_inversion_7x7, plot_path, plot_patch
46+
):
47+
if plot_path.exists():
48+
shutil.rmtree(plot_path)
49+
50+
plotter = PlotterImaging(image_path=plot_path)
51+
52+
plotter.fit_imaging(fit=fit_imaging_x2_plane_inversion_7x7, quick_update=True)
53+
54+
assert str(plot_path / "fit.png") in plot_patch.paths
55+
assert str(plot_path / "fit_quick.png") not in plot_patch.paths
56+
assert str(plot_path / "tracer.png") not in plot_patch.paths
57+
assert str(plot_path / "fit_log10.png") not in plot_patch.paths
58+
59+
4460
def test__fit_imaging_combined(
4561
fit_imaging_x2_plane_inversion_7x7, plot_path, plot_patch
4662
):

test_autolens/interferometer/model/test_plotter_interferometer.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ def make_plotter_plotter_setup():
1616
return directory / "files"
1717

1818

19+
def test__fit_interferometer__quick_update__writes_normal_fit_subplot_only(
20+
fit_interferometer_x2_plane_7x7,
21+
plot_path,
22+
plot_patch,
23+
):
24+
plotter = PlotterInterferometer(image_path=plot_path)
25+
26+
plotter.fit_interferometer(
27+
fit=fit_interferometer_x2_plane_7x7, quick_update=True
28+
)
29+
30+
assert str(plot_path / "fit.png") in plot_patch.paths
31+
assert str(plot_path / "fit_quick.png") not in plot_patch.paths
32+
assert str(plot_path / "fit_dirty_images.png") not in plot_patch.paths
33+
34+
1935
def test__fit_interferometer(
2036
fit_interferometer_x2_plane_7x7,
2137
plot_path,

test_autolens/point/model/test_plotter_point.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,17 @@ def test__fit_point(fit_point_dataset_x2_plane, plot_path, plot_patch):
2121
plotter.fit_point(fit=fit_point_dataset_x2_plane)
2222

2323
assert str(plot_path / "fit.png") in plot_patch.paths
24+
25+
26+
def test__fit_point__quick_update__writes_normal_fit_subplot(
27+
fit_point_dataset_x2_plane, plot_path, plot_patch
28+
):
29+
if plot_path.exists():
30+
shutil.rmtree(plot_path)
31+
32+
plotter = PlotterPoint(image_path=plot_path)
33+
34+
plotter.fit_point(fit=fit_point_dataset_x2_plane, quick_update=True)
35+
36+
assert str(plot_path / "fit.png") in plot_patch.paths
37+
assert str(plot_path / "fit_quick.png") not in plot_patch.paths

test_autolens/weak/model/__init__.py

Whitespace-only changes.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from pathlib import Path
2+
3+
import autoarray as aa
4+
import autolens as al
5+
6+
import pytest
7+
8+
from autolens.weak.model.plotter import PlotterWeak
9+
10+
directory = Path(__file__).resolve().parent
11+
12+
13+
def _isothermal_tracer(einstein_radius=1.6, ell_comps=(0.0, 0.05)):
14+
lens = al.Galaxy(
15+
redshift=0.5,
16+
mass=al.mp.Isothermal(
17+
centre=(0.0, 0.0),
18+
ell_comps=ell_comps,
19+
einstein_radius=einstein_radius,
20+
),
21+
)
22+
source = al.Galaxy(redshift=1.0)
23+
return al.Tracer(galaxies=[lens, source])
24+
25+
26+
@pytest.fixture(name="fit_weak")
27+
def make_fit_weak():
28+
grid = aa.Grid2DIrregular(
29+
values=[(0.7, 0.5), (1.0, 1.0), (-0.3, 0.6), (-1.1, -0.8)]
30+
)
31+
truth = _isothermal_tracer(einstein_radius=1.6)
32+
dataset = al.SimulatorShearYX(noise_sigma=0.0, seed=0).via_tracer_from(
33+
tracer=truth, grid=grid, name="test"
34+
)
35+
dataset.noise_map = aa.ArrayIrregular(values=[0.3, 0.3, 0.3, 0.3])
36+
model = _isothermal_tracer(einstein_radius=1.5)
37+
return al.FitWeak(dataset=dataset, tracer=model)
38+
39+
40+
@pytest.fixture(name="plot_path")
41+
def make_plot_path():
42+
return directory / "files"
43+
44+
45+
def test__fit_weak__quick_update__writes_normal_fit_subplot(
46+
fit_weak, plot_path, plot_patch
47+
):
48+
plotter = PlotterWeak(image_path=plot_path)
49+
50+
plotter.fit_weak(fit=fit_weak, quick_update=True)
51+
52+
assert str(plot_path / "subplot_fit_weak.png") in plot_patch.paths
53+
assert str(plot_path / "fit_quick.png") not in plot_patch.paths

0 commit comments

Comments
 (0)