How to use the autolens.exc function in autolens

To help you get started, we’ve selected a few autolens examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Jammy2211 / PyAutoLens / test / autofit / test_model_mapper.py View on Github external
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)
github Jammy2211 / PyAutoLens / test / autofit / test_model_mapper.py View on Github external
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]))
github Jammy2211 / PyAutoLens / test / model / galaxy / test_galaxy_data.py View on Github external
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)
github Jammy2211 / PyAutoLens / test / pipeline / test_phase.py View on Github external
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
github Jammy2211 / PyAutoLens / test / profiling / pixelization / rectangular / grid_to_pix / jitted.py View on Github external
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
github Jammy2211 / PyAutoLens / test / lens / test_plane.py View on Github external
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
github Jammy2211 / PyAutoLens / autolens / lens / stack / plane_stack.py View on Github external
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')
github Jammy2211 / PyAutoLens / autolens / lens / stack / lens_fit_stack.py View on Github external
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')
github Jammy2211 / PyAutoLens / autolens / plotters / line_yx_plotters.py View on Github external
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="--")
github Jammy2211 / PyAutoLens / autolens / data / uv_plane.py View on Github external
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,
        )