Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import os
import pytest
from autofit import conf
from autofit.core import model_mapper as mm
from autofit.core import non_linear
from autolens.model.galaxy import galaxy as g, galaxy_model as gp
from autolens.pipeline import phase as ph
from autolens.pipeline import phase_property
directory = os.path.dirname(os.path.realpath(__file__))
conf.instance = conf.Config("{}/../../workspace/config".format(directory),
"{}/../../workspace/output/".format(directory))
class NLO(non_linear.NonLinearOptimizer):
def fit(self, analysis):
class Fitness(object):
def __init__(self, instance_from_physical_vector, constant):
self.result = None
self.instance_from_physical_vector = instance_from_physical_vector
self.constant = constant
def __call__(self, vector):
instance = self.instance_from_physical_vector(vector)
for key, value in self.constant.__dict__.items():
setattr(instance, key, value)
def do_something():
af.conf.instance = af.conf.Config(
config_path="{}/../../test_files/config/radial_min".format(directory)
)
def reset_config():
"""
Use configuration from the default path. You may want to change this to set a specific path.
"""
af.conf.instance = af.conf.default
def do_something():
af.conf.instance = af.conf.Config(
"{}/../../test_files/config/galaxy_model".format(
os.path.dirname(os.path.realpath(__file__))
)
def do_something():
af.conf.instance = af.conf.Config(
"{}/../test_files/config/phase_imaging_7x7".format(directory)
)
def set_config_path():
conf.instance = conf.Config(
path.join(directory, "files/plotter"), path.join(directory, "output")
)
def clean_images():
try:
os.remove("{}/source_lens_phase/source_image_0.fits".format(directory))
os.remove("{}/source_lens_phase/lens_image_0.fits".format(directory))
os.remove("{}/source_lens_phase/model_image_0.fits".format(directory))
except FileNotFoundError:
pass
af.conf.instance.data_path = directory
def do_something():
af.conf.instance = af.conf.Config(
"{}/../test_files/config/phase_imaging_7x7".format(directory)
)
def do_something():
af.conf.instance = af.conf.Config(
config_path="{}/../../test_files/config/radial_min".format(directory)
)
mass_profile=al.mass_profiles.SphericalIsothermal,
)
redshift_prior = af.GaussianPrior(1, 1)
einstein_radius_prior = af.GaussianPrior(4, 1)
intensity_prior = af.GaussianPrior(7, 1)
arguments = {
galaxy_model.redshift.redshift: redshift_prior,
galaxy_model.mass_profile.mask_centre.centre_0: af.GaussianPrior(2, 1),
galaxy_model.mass_profile.mask_centre.centre_1: af.GaussianPrior(3, 1),
galaxy_model.mass_profile.einstein_radius.value: einstein_radius_prior,
galaxy_model.light_profile.axis_ratio: af.GaussianPrior(5, 1),
galaxy_model.light_profile.phi: af.GaussianPrior(6, 1),
galaxy_model.light_profile.intensity.value: intensity_prior,
galaxy_model.light_profile.effective_radius.value: af.GaussianPrior(8, 1),
galaxy_model.light_profile.sersic_index: af.GaussianPrior(9, 1),
}
gaussian_galaxy_model_model = galaxy_model.gaussian_prior_model_for_arguments(
arguments
)
assert gaussian_galaxy_model_model.redshift.redshift == redshift_prior
assert (
gaussian_galaxy_model_model.mass_profile.einstein_radius.value
== einstein_radius_prior
)
assert (
gaussian_galaxy_model_model.light_profile.intensity.value == intensity_prior
)