1010from autogalaxy .imaging .model import latent as _latent_module
1111from autogalaxy .imaging .model .latent import (
1212 LATENT_FUNCTIONS ,
13+ LatentGalaxy ,
1314 ab_mag_via_flux_from ,
1415 flux_mujy_via_ab_mag_from ,
1516 latent_keys_enabled ,
@@ -139,7 +140,7 @@ def test_latent_keys_enabled_drops_unknown_with_warning(caplog):
139140 assert any ("never_registered_latent" in rec .message for rec in caplog .records )
140141
141142
142- def test_analysis_imaging_compute_latent_variables_aligns_with_latent_keys (
143+ def test_latent_galaxy_variables_aligns_with_keys (
143144 masked_imaging_7x7 ,
144145):
145146 galaxy = ag .Galaxy (redshift = 0.5 , light = ag .lp .Sersic (intensity = 0.1 ))
@@ -150,35 +151,34 @@ def test_analysis_imaging_compute_latent_variables_aligns_with_latent_keys(
150151 )
151152
152153 parameters = np .array (model .physical_values_from_prior_medians )
153- values = analysis .compute_latent_variables (parameters = parameters , model = model )
154+ values = LatentGalaxy .variables (analysis , parameters = parameters , model = model )
155+ keys = LatentGalaxy .keys (analysis )
154156
155157 assert isinstance (values , tuple )
156- assert len (values ) == len (analysis . LATENT_KEYS )
158+ assert len (values ) == len (keys )
157159 # test_autogalaxy/config/latent.yaml enables both keys, raw flux first.
158- assert analysis . LATENT_KEYS == ["total_galaxy_0_flux" , "total_galaxy_0_flux_mujy" ]
160+ assert keys == ["total_galaxy_0_flux" , "total_galaxy_0_flux_mujy" ]
159161 assert all (np .isfinite (v ) for v in values )
160162
161163
162- def test_analysis_imaging_compute_latent_variables_raises_when_empty (monkeypatch ):
164+ def test_latent_galaxy_variables_raises_when_empty (monkeypatch ):
163165 # When no latents are enabled, autofit's `except NotImplementedError`
164- # at autofit/non_linear/analysis/analysis.py:304 short-circuits the
165- # latent pipeline. We match that contract by raising explicitly.
166- monkeypatch .setattr (
167- ag .AnalysisImaging ,
168- "LATENT_KEYS" ,
169- property (lambda self : []),
170- )
166+ # short-circuits the latent pipeline. LatentGalaxy.variables matches that
167+ # contract by raising explicitly.
168+ monkeypatch .setattr (_latent_module , "latent_keys_enabled" , lambda * a , ** k : [])
171169 analysis = ag .AnalysisImaging (dataset = MagicMock (), use_jax = False )
172170
173171 with pytest .raises (NotImplementedError ):
174- analysis . compute_latent_variables ( parameters = np .array ([]), model = MagicMock ())
172+ LatentGalaxy . variables ( analysis , parameters = np .array ([]), model = MagicMock ())
175173
176174
177- def test_analysis_imaging_latent_keys_property_reads_config ():
175+ def test_analysis_imaging_declares_latent_galaxy_and_keys_read_config ():
178176 # The autouse fixture in test_autogalaxy/conftest.py pushes the test
179177 # config dir whose latent.yaml enables both keys.
180178 dataset = MagicMock ()
181179 analysis = ag .AnalysisImaging (dataset = dataset , use_jax = False )
182180
183- assert analysis .LATENT_KEYS == ["total_galaxy_0_flux" , "total_galaxy_0_flux_mujy" ]
184- assert set (analysis .LATENT_KEYS ).issubset (LATENT_FUNCTIONS .keys ())
181+ assert ag .AnalysisImaging .Latent is LatentGalaxy
182+ keys = ag .AnalysisImaging .Latent .keys (analysis )
183+ assert keys == ["total_galaxy_0_flux" , "total_galaxy_0_flux_mujy" ]
184+ assert set (keys ).issubset (LATENT_FUNCTIONS .keys ())
0 commit comments