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(
"{}/../../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 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
Parameters
-----------
image : datas.imaging.datas.Image
The datas-datas, which includes the observed datas, noise_map-map, PSF, signal-to-noise_map-map, etc.
plot_origin : True
If true, the origin of the datas's coordinate system is plotted as a 'x'.
image_plane_pix_grid : ndarray or datas.array.grid_stacks.PixGrid
If an adaptive pixelization whose pixels are formed by tracing pixels from the datas, this plots those pixels \
over the immage.
ignore_config : bool
If *False*, the config file general.ini is used to determine whether the subpot is plotted. If *True*, the \
config file is ignored.
"""
plot_image_as_subplot = conf.instance.general.get('output', 'plot_imaging_as_subplot', bool)
if plot_image_as_subplot or ignore_config:
rows, columns, figsize_tool = plotter_util.get_subplot_rows_columns_figsize(number_subplots=4)
if figsize is None:
figsize = figsize_tool
plt.figure(figsize=figsize)
plt.subplot(rows, columns, 1)
plot_image(image=image, plot_origin=plot_origin, mask=mask, should_plot_border=should_plot_border,
positions=positions, as_subplot=True,
units=units, kpc_per_arcsec=kpc_per_arcsec, figsize=figsize, aspect=aspect,
cmap=cmap, norm=norm, norm_min=norm_min, norm_max=norm_max, linthresh=linthresh, linscale=linscale,
cb_ticksize=cb_ticksize, cb_fraction=cb_fraction, cb_pad=cb_pad,
import autofit as af
import matplotlib
backend = af.conf.instance.visualize.get("figures", "backend", str)
matplotlib.use(backend)
from matplotlib import pyplot as plt
import autoarray as aa
from autolens.data.plotters import data_plotters
def plot_uv_plane_subplot(
uv_plane_data,
plot_origin=True,
units="arcsec",
kpc_per_arcsec=None,
figsize=None,
aspect="square",
cmap="jet",
norm="linear",
# guide us to the lens models with the highest liikelihood.
# We'll use the path to howtolens multiple times, so make sure you set it upt correctly!
path = '{}/../'.format(os.path.dirname(os.path.realpath(__file__)))
# You're going to see a line like this in every tutorial this chapter. I recommend that for now you just ignore it.
# A non-linear search can take a long time to run (minutes, hours, or days), and this isn't ideal if you want to
# go through the tutorials without having to constant stop for long periods!
# This line over-rides the configuration of the non-linear search such that it computes the solution really fast. To
# do this, I've 'cheated' - I've computed the solution myself and then input it into the config. Nevertheless, it means
# things will run fast for you, meaning you won't suffer long delays doin the tutorials.
#
# This will all become clear at the end of the chapter, so for now just bare in mind that we are taking a short-cut
# to get our non-linear search to run fast!
conf.instance = conf.Config(config_path=path+'configs/1_non_linear_search', output_path=path+"output")
# This function simulates the regular we'll fit_normal in this tutorial.
def simulate():
from autolens.data.array import grids
from autolens.model.galaxy import galaxy as g
from autolens.lensing import ray_tracing
psf = im.PSF.simulate_as_gaussian(shape=(11, 11), sigma=0.1, pixel_scale=0.1)
image_plane_grids = grids.DataGrids.grids_for_simulation(shape=(130, 130), pixel_scale=0.1, psf_shape=(11, 11))
lens_galaxy = g.Galaxy(mass=mp.SphericalIsothermal(centre=(0.0, 0.0), einstein_radius=1.6))
source_galaxy = g.Galaxy(light=lp.SphericalExponential(centre=(0.0, 0.0), intensity=0.2, effective_radius=0.2))
tracer = ray_tracing.TracerImageSourcePlanes(lens_galaxies=[lens_galaxy], source_galaxies=[source_galaxy],
image_plane_grids=[image_plane_grids])
def pixelization_tag_from_pixelization(pixelization):
if pixelization is None:
return ""
else:
return "__pix_" + af.conf.instance.label.get(
"tag", pixelization().__class__.__name__, str
)