Пример #1
0
    def test__use_border__determines_if_border_pixel_relocation_is_used(
            self, imaging_7x7, mask_7x7):
        # noinspection PyTypeChecker

        lens_galaxy = al.Galaxy(
            redshift=0.5,
            mass=al.mp.SphericalIsothermal(einstein_radius=100.0))
        source_galaxy = al.Galaxy(
            redshift=1.0,
            pixelization=al.pix.Rectangular(shape=(3, 3)),
            regularization=al.reg.Constant(coefficient=1.0),
        )

        phase_imaging_7x7 = al.PhaseImaging(
            galaxies=[lens_galaxy, source_galaxy],
            settings=al.SettingsPhaseImaging(
                settings_masked_imaging=al.SettingsMaskedImaging(
                    grid_inversion_class=al.Grid2D),
                settings_pixelization=al.SettingsPixelization(use_border=True),
            ),
            search=mock.MockSearch("test_phase"),
        )

        analysis = phase_imaging_7x7.make_analysis(dataset=imaging_7x7,
                                                   mask=mask_7x7,
                                                   results=mock.MockResults())
        analysis.masked_dataset.grid_inversion[4] = np.array([[500.0, 0.0]])

        instance = phase_imaging_7x7.model.instance_from_unit_vector([])
        tracer = analysis.tracer_for_instance(instance=instance)
        fit = analysis.masked_imaging_fit_for_tracer(
            tracer=tracer, hyper_image_sky=None, hyper_background_noise=None)

        assert fit.inversion.mapper.source_grid_slim[4][0] == pytest.approx(
            97.19584, 1.0e-2)
        assert fit.inversion.mapper.source_grid_slim[4][1] == pytest.approx(
            -3.699999, 1.0e-2)

        phase_imaging_7x7 = al.PhaseImaging(
            galaxies=[lens_galaxy, source_galaxy],
            settings=al.SettingsPhaseImaging(
                settings_masked_imaging=al.SettingsMaskedImaging(
                    grid_inversion_class=al.Grid2D),
                settings_pixelization=al.SettingsPixelization(
                    use_border=False),
            ),
            search=mock.MockSearch("test_phase"),
        )

        analysis = phase_imaging_7x7.make_analysis(dataset=imaging_7x7,
                                                   mask=mask_7x7,
                                                   results=mock.MockResults())

        analysis.masked_dataset.grid_inversion[4] = np.array([300.0, 0.0])

        instance = phase_imaging_7x7.model.instance_from_unit_vector([])
        tracer = analysis.tracer_for_instance(instance=instance)
        fit = analysis.masked_imaging_fit_for_tracer(
            tracer=tracer, hyper_image_sky=None, hyper_background_noise=None)

        assert fit.inversion.mapper.source_grid_slim[4][0] == pytest.approx(
            200.0, 1.0e-4)
Пример #2
0
imaging_plotter = aplt.ImagingPlotter(imaging=imaging,
                                      visuals_2d=aplt.Visuals2D(mask=mask))
imaging_plotter.subplot_imaging()
"""
__Settings__

The `SettingsPhaseImaging` describe how the model is fitted to the data in the log likelihood function.

These settings are used and described throughout the `autolens_workspace/examples/model` example scripts, with a 
complete description of all settings given in `autolens_workspace/examples/model/customize/settings.py`.

The settings chosen here are applied to all phases in the pipeline.
"""

settings_masked_imaging = al.SettingsMaskedImaging(grid_class=al.Grid2D,
                                                   sub_size=2)

settings = al.SettingsPhaseImaging(
    settings_masked_imaging=settings_masked_imaging)
"""
__PIPELINE SETUP__

Transdimensional pipelines used the `SetupPipeline` object to customize the analysis performed by the pipeline,
for example if a shear was included in the mass model and the model used for the source galaxy.

SLaM pipelines break the analysis down into multiple pipelines which focus on modeling a specific aspect of the strong 
lens, first the Source, then the (lens) Light and finally the Mass. Each of these pipelines has it own setup object 
which is equivalent to the `SetupPipeline` object, customizing the analysis in that pipeline. Each pipeline therefore
has its own `SetupMass` and `SetupSourceParametric` object.

The `Setup` used in earlier pipelines determine the model used in later pipelines. For example, if the `Source` 
Пример #3
0
"""
Lets quickly confirm the annuli capture the source's light.
"""

# %%
aplt.Imaging.image(imaging=imaging, mask=mask)

# %%
"""
As usual, we setup our `Imaging` and `Mask2D` up as a `MaskedImaging` object and create a `Tracer` using the (masked) 
grid.
"""

# %%
masked_imaging = al.MaskedImaging(
    imaging=imaging, mask=mask, settings=al.SettingsMaskedImaging(sub_size=2)
)

tracer = al.Tracer.from_galaxies(galaxies=[lens_galaxy, al.Galaxy(redshift=1.0)])

source_plane_grid = tracer.traced_grids_of_planes_from_grid(grid=masked_imaging.grid)[1]

# %%
"""
Finally, we use the masked source-plane `Grid` to setup a new `Mapper` (using the same rectangular 25 x 25 
_Pixelization_ as before).
"""

# %%
mapper = rectangular.mapper_from_grid_and_sparse_grid(grid=source_plane_grid)
Пример #4
0
def test__simulate_imaging_data_and_fit__include_psf_blurring__chi_squared_is_0__noise_normalization_correct(
):

    grid = al.Grid2D.uniform(shape_native=(11, 11),
                             pixel_scales=0.2,
                             sub_size=1)

    psf = al.Kernel2D.from_gaussian(shape_native=(3, 3),
                                    pixel_scales=0.2,
                                    sigma=0.75,
                                    renormalize=True)

    lens_galaxy = al.Galaxy(
        redshift=0.5,
        light=al.lp.EllipticalSersic(centre=(0.1, 0.1), intensity=0.1),
        mass=al.mp.EllipticalIsothermal(centre=(0.1, 0.1),
                                        einstein_radius=1.8),
    )
    source_galaxy = al.Galaxy(
        redshift=1.0,
        light=al.lp.EllipticalExponential(centre=(0.1, 0.1), intensity=0.5),
    )
    tracer = al.Tracer.from_galaxies(galaxies=[lens_galaxy, source_galaxy])

    simulator = al.SimulatorImaging(exposure_time=300.0,
                                    psf=psf,
                                    add_poisson_noise=False)

    imaging = simulator.from_tracer_and_grid(tracer=tracer, grid=grid)
    imaging.noise_map = al.Array2D.ones(
        shape_native=imaging.image.shape_native, pixel_scales=0.2)

    file_path = path.join(
        "{}".format(path.dirname(path.realpath(__file__))),
        "data_temp",
        "simulate_and_fit",
    )

    try:
        shutil.rmtree(file_path)
    except FileNotFoundError:
        pass

    if path.exists(file_path) is False:
        os.makedirs(file_path)

    imaging.output_to_fits(
        image_path=path.join(file_path, "image.fits"),
        noise_map_path=path.join(file_path, "noise_map.fits"),
        psf_path=path.join(file_path, "psf.fits"),
    )

    simulator = al.Imaging.from_fits(
        image_path=path.join(file_path, "image.fits"),
        noise_map_path=path.join(file_path, "noise_map.fits"),
        psf_path=path.join(file_path, "psf.fits"),
        pixel_scales=0.2,
    )

    mask = al.Mask2D.circular(shape_native=simulator.image.shape_native,
                              pixel_scales=0.2,
                              radius=0.8)

    masked_imaging = al.MaskedImaging(
        imaging=simulator,
        mask=mask,
        settings=al.SettingsMaskedImaging(sub_size=1))

    tracer = al.Tracer.from_galaxies(galaxies=[lens_galaxy, source_galaxy])

    fit = al.FitImaging(masked_imaging=masked_imaging, tracer=tracer)

    assert fit.chi_squared == pytest.approx(0.0, 1e-4)

    file_path = path.join("{}".format(path.dirname(path.realpath(__file__))),
                          "data_temp")

    if path.exists(file_path) == True:
        shutil.rmtree(file_path)
Пример #5
0
for i in range(100):

    if not yay:

        try:
            imaging.psf = al.preprocess.array_with_new_shape(
                array=imaging.psf, new_shape=(21, 21)
            )
            yay = True
        except OSError:
            yay = False

if not yay:
    raise IOError("Nope")

settings_masked_imaging = al.SettingsMaskedImaging(grid_class=al.Grid)

settings_lens = al.SettingsLens(
    positions_threshold=0.7,
    auto_positions_factor=3.0,
    auto_positions_minimum_threshold=0.2,
)

settings = al.SettingsPhaseImaging(
    settings_masked_imaging=settings_masked_imaging, settings_lens=settings_lens
)


# %%
"""
__PIPELINE SETUP__