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_out_of_order_prior_limits(self):
with pytest.raises(exc.PriorException):
model_mapper.UniformPrior(1., 0)
with pytest.raises(exc.PriorException):
model_mapper.GaussianPrior(0, 1, 1, 0)
def test_out_of_limits(self, test_config, limit_config):
mm = model_mapper.ModelMapper(test_config, limit_config=limit_config)
mm.mock_class_gaussian = MockClassGaussian
assert mm.instance_from_physical_vector([1, 2]) is not None
with pytest.raises(exc.PriorLimitException):
mm.instance_from_physical_vector(([1, 3]))
with pytest.raises(exc.PriorLimitException):
mm.instance_from_physical_vector(([-1, 2]))
def test__no_use_method__raises_exception(self, image, mask):
galaxy_data = gd.GalaxyData(image=image, noise_map=2.0*np.ones((4, 4)), pixel_scale=3.0)
with pytest.raises(exc.GalaxyException):
gd.GalaxyFitData(galaxy_data=galaxy_data, mask=mask, sub_grid_size=2)
def test_make_analysis__positions_are_input__are_used_in_analysis(self, phase, ccd_data):
# If use positions is true and positions are input, make the positions part of the lens data.
phase.use_positions = True
analysis = phase.make_analysis(data=ccd_data, positions=[[[1.0, 1.0], [2.0, 2.0]]])
assert (analysis.lens_data.positions[0][0] == np.array([1.0, 1.0])).all()
assert (analysis.lens_data.positions[0][1] == np.array([2.0, 2.0])).all()
# If use positions is true but no positions are supplied, raise an error
with pytest.raises(exc.PhaseException):
phase.make_analysis(data=ccd_data, positions=None)
phase.make_analysis(data=ccd_data)
# If use positions is False, positions should always be None.
phase.use_positions = False
analysis = phase.make_analysis(data=ccd_data, positions=[[[1.0, 1.0], [2.0, 2.0]]])
assert analysis.lens_data.positions is None
def __init__(self, shape=(3, 3), regularization_coefficients=(1.0,)):
"""A rectangular inversion where pixels appear on a Cartesian, uniform and rectangular grid \
of shape (rows, columns).
Like an masked_image grid, the indexing of the rectangular grid begins in the top-left corner and goes right and down.
Parameters
-----------
shape : (int, int)
The dimensions of the rectangular grid of pixels (x_pixels, y_pixel)
regularization_coefficients : (float,)
The regularization_matrix coefficients used to smooth the pix reconstructed_image.
"""
if shape[0] <= 2 or shape[1] <= 2:
raise exc.PixelizationException('The rectangular inversion must be at least dimensions 3x3')
super(Rectangular, self).__init__(shape[0] * shape[1], regularization_coefficients)
self.shape = shape
def test__2_galaxies_in_plane__both_have_pixelization__raises_error(self, grid_stack):
galaxy_pix_0 = g.Galaxy(pixelization=MockPixelization(value=1), regularization=MockRegularization(value=0))
galaxy_pix_1 = g.Galaxy(pixelization=MockPixelization(value=2), regularization=MockRegularization(value=0))
plane = pl.Plane(galaxies=[galaxy_pix_0, galaxy_pix_1], grid_stack=grid_stack, border=MockBorders())
with pytest.raises(exc.PixelizationException):
plane.regularization
def regularization(self):
galaxies_with_regularization = list(filter(lambda galaxy: galaxy.has_regularization, self.galaxies))
if len(galaxies_with_regularization) == 0:
return None
if len(galaxies_with_regularization) == 1:
return galaxies_with_regularization[0].regularization
elif len(galaxies_with_regularization) > 1:
raise exc.PixelizationException('The number of galaxies with regularizations in one plane is above 1')
tracer : ray_tracing.AbstractTracerStack
The tracer, which describes the ray-tracing and strong lens configuration.
padded_tracer : ray_tracing.AbstractTracerStack or None
A tracer with an identical strong lens configuration to the tracer above, but using the lens image's \
padded grid_stack such that unmasked model-images can be computed.
"""
if tracer.has_light_profile and not tracer.has_pixelization:
if not tracer.has_hyper_galaxy:
return LensProfileFitStack(lens_data_stack=lens_data_stack, tracer=tracer,
padded_tracer=padded_tracer)
else:
raise exc.FittingException('The fit routine did not call a Fit class - check the '
'properties of the tracer')
def plot_vertical_lines(vertical_lines, vertical_line_labels, units, kpc_per_arcsec):
if vertical_lines is [] or vertical_lines is None:
return
for vertical_line, vertical_line_label in zip(vertical_lines, vertical_line_labels):
if units in "arcsec" or kpc_per_arcsec is None:
x_value_plot = vertical_line
elif units in "kpc":
x_value_plot = vertical_line
else:
raise exc.PlottingException(
"The units supplied to the plotter are not a valid string (must be pixels | "
"arcsec | kpc)"
)
plt.axvline(x=x_value_plot, label=vertical_line_label, linestyle="--")
The hdu the exposure_time_map is contained in the .fits file specified by *exposure_time_map_path*.
pixel_scales : float
The size of each pixel in arc seconds.
shape_1d : (int, int)
The shape of the image, required if a single value is used to calculate the exposure time map.
exposure_time : float
The exposure-time used to compute the expsure-time map if only a single value is used.
exposure_time_map_from_inverse_noise_map : bool
If True, the exposure-time map is computed from the background noise_map map \
(see *ExposureTimeMap.from_background_noise_map*)
inverse_noise_map : ndarray
The background noise-map, which the Poisson noise-map can be calculated using.
"""
if exposure_time is not None and exposure_time_map_path is not None:
raise exc.DataException(
"You have supplied both a exposure_time_map_path to an exposure time map and an exposure time. Only"
"one quantity should be supplied."
)
if exposure_time is not None and exposure_time_map_path is None:
return np.full(
fill_value=exposure_time, shape=shape_1d
)
elif exposure_time is None and exposure_time_map_path is not None:
return aa.array_util.numpy_array_1d_from_fits(
file_path=exposure_time_map_path,
hdu=exposure_time_map_hdu,
)