Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_associate_images_(self, instance, result, lens_data_7x7):
results_collection = af.ResultsCollection()
results_collection.add("phase", result)
analysis = phase_imaging.PhaseImaging.Analysis(
lens_data=lens_data_7x7,
cosmology=None,
results=results_collection,
image_path="",
)
instance = analysis.associate_images(instance=instance)
hyper_lens_image_1d = lens_data_7x7.array_1d_from_array_2d(
array_2d=result.image_galaxy_2d_dict[("galaxies", "lens")]
)
hyper_source_image_1d = lens_data_7x7.array_1d_from_array_2d(
array_2d=result.image_galaxy_2d_dict[("galaxies", "source")]
)
def test__associate_images(self, instance, result, masked_imaging_7x7):
results_collection = af.ResultsCollection()
results_collection.add("phase", result)
results_collection[0].use_as_hyper_dataset = True
analysis = al.PhaseImaging.Analysis(
masked_imaging=masked_imaging_7x7,
cosmology=None,
results=results_collection,
image_path="",
)
instance = analysis.associate_hyper_images(instance=instance)
lens_hyper_image = result.image_galaxy_dict[("galaxies", "lens")]
source_hyper_image = result.image_galaxy_dict[("galaxies", "source")]
hyper_model_image = lens_hyper_image + source_hyper_image
self.max_log_likelihood_tracer = max_log_likelihood_tracer
self.pixelization = pixelization
self.use_as_hyper_dataset = use_as_hyper_dataset
self.positions = positions
self.updated_positions = (
updated_positions if updated_positions is not None else []
)
self.updated_positions_threshold = updated_positions_threshold
self.stochastic_log_evidences = stochastic_log_evidences
@property
def image_plane_multiple_image_positions_of_source_plane_centres(self):
return self.updated_positions
class MockResults(af.ResultsCollection):
def __init__(
self,
samples=None,
instance=None,
model=None,
analysis=None,
search=None,
mask=None,
model_image=None,
max_log_likelihood_tracer=None,
hyper_galaxy_image_path_dict=None,
hyper_model_image=None,
hyper_galaxy_visibilities_path_dict=None,
hyper_model_visibilities=None,
pixelization=None,
positions=None,
dataset
Data
results
Results from previous phases.
kwargs
Returns
-------
result
The result of the phase, with a hyper_galaxies result attached as an attribute with the hyper_name of this
phase.
"""
self.save_dataset(dataset=dataset)
results = (
copy.deepcopy(results) if results is not None else af.ResultsCollection()
)
result = self.phase.run(dataset, results=results, **kwargs)
results.add(self.phase.paths.phase_name, result)
hyper_result = self.run_hyper(
dataset=dataset, results=results, info=info, **kwargs
)
setattr(result, self.hyper_name, hyper_result)
return result
Returns
-------
result: AbstractPhase.Result
A result object comprising the best fit model and other hyper_galaxies.
"""
self.save_model_info()
self.save_metadata(dataset=dataset)
self.save_dataset(dataset=dataset)
self.save_mask(mask)
self.save_meta_dataset(meta_dataset=self.meta_dataset)
self.save_info(info=info)
self.model = self.model.populate(results)
results = results or af.ResultsCollection()
analysis = self.make_analysis(
dataset=dataset, mask=mask, results=results, positions=positions
)
phase_attributes = self.make_phase_attributes(analysis=analysis)
self.save_phase_attributes(phase_attributes=phase_attributes)
self.customize_priors(results)
self.assert_and_save_pickle()
result = self.run_analysis(analysis)
return self.make_result(result=result, analysis=analysis)
Finally, a phase in run with all of the variable results from all the individual hyper phases.
Parameters
----------
data
The data
results
Results from previous phases
kwargs
Returns
-------
result
The result of the regular phase, with hyper results attached by associated hyper names
"""
results = copy.deepcopy(results) if results is not None else af.ResultsCollection()
result = self.phase.run(data, results=results, **kwargs)
results.add(self.phase.phase_name, result)
for hyper_phase in self.hyper_phases:
hyper_result = hyper_phase.run_hyper(
data=data,
results=results,
**kwargs
)
setattr(result, hyper_phase.hyper_name, hyper_result)
setattr(
result,
self.hyper_name,
self.run_hyper(
data,
def run_hyper(self, dataset, info=None, results=None, **kwargs):
"""
Run the phase, overriding the search's model instance with one created to
only fit pixelization hyperparameters.
"""
self.results = results or af.ResultsCollection()
log_evidences = results.last.stochastic_log_evidences
phase = self.make_hyper_phase()
phase.settings.log_likelihood_cap = np.median(log_evidences)
phase.use_as_hyper_dataset = False
phase.model = self.make_model(results.last.instance)
return phase.run(dataset, mask=results.last.mask, results=results)