Beispiel #1
0
    def test_constants_work(self):
        name = "const_float"
        test_name = "/const_float"

        integration_util.reset_paths(test_name, output_path)

        sersic = al.EllipticalSersic(
            centre=(0.0, 0.0),
            axis_ratio=0.8,
            phi=90.0,
            intensity=1.0,
            effective_radius=1.3,
            sersic_index=3.0,
        )

        lens_galaxy = galaxy.Galaxy(redshift=0.5, light_profile=sersic)

        simulate_integration_image(test_name=test_name,
                                   pixel_scale=0.5,
                                   galaxies=[lens_galaxy])
        path = "{}/".format(os.path.dirname(os.path.realpath(
            __file__)))  # Setup path so we can output the simulated image.

        imaging_data = al.load_imaging_data_from_fits(
            image_path=path + "/test_files/data/" + test_name + "/image.fits",
            psf_path=path + "/test_files/data/" + test_name + "/psf.fits",
            noise_map_path=path + "/test_files/data/" + test_name +
            "/noise_map.fits",
            pixel_scale=0.1,
        )

        class MMPhase(al.PhaseImaging):
            def customize_priors(self, results):
                self.galaxies.lens.sersic.axis_ratio = 0.2
                self.galaxies.lens.sersic.phi = 90.0
                self.galaxies.lens.sersic.intensity = 1.0
                self.galaxies.lens.sersic.effective_radius = 1.3
                self.galaxies.lens.sersic.sersic_index = 3.0

        phase = MMPhase(
            galaxies=dict(lens=al.GalaxyModel(
                redshift=0.5, sersic=al.light_profiles.EllipticalSersic)),
            optimizer_class=af.MultiNest,
            phase_name="{}/phase1".format(name),
        )

        phase.optimizer.n_live_points = 20
        phase.optimizer.sampling_efficiency = 0.8

        phase.make_analysis(data=imaging_data)

        sersic = phase.variable.galaxies[0].sersic

        assert isinstance(sersic, af.PriorModel)

        assert isinstance(sersic.axis_ratio, float)
        assert isinstance(sersic.phi, float)
        assert isinstance(sersic.intensity, float)
        assert isinstance(sersic.effective_radius, float)
        assert isinstance(sersic.sersic_index, float)
Beispiel #2
0
def galaxy_fit_phase():

    pixel_scale = 0.1
    image_shape = (150, 150)

    integration_util.reset_paths(test_name=test_name, output_path=output_path)

    grid = al.Grid.from_shape_pixel_scale_and_sub_size(shape=image_shape,
                                                       pixel_scale=pixel_scale,
                                                       sub_size=4)

    galaxy = al.Galaxy(
        redshift=0.5,
        mass=al.mass_profiles.SphericalIsothermal(centre=(0.0, 0.0),
                                                  einstein_radius=1.0),
    )

    deflections = galaxy.deflections_from_grid(galaxies=[galaxy],
                                               grid=grid,
                                               return_in_2d=True,
                                               bypass_decorator=False)

    noise_map = al.ScaledSquarePixelArray(array=np.ones(deflections[:,
                                                                    0].shape),
                                          pixel_scale=pixel_scale)

    data_y = al.GalaxyData(image=deflections[:, 0],
                           noise_map=noise_map,
                           pixel_scale=pixel_scale)
    data_x = al.GalaxyData(image=deflections[:, 1],
                           noise_map=noise_map,
                           pixel_scale=pixel_scale)

    phase1 = al.PhaseGalaxy(
        phase_name=test_name + "/",
        galaxies=dict(gal=al.GalaxyModel(
            redshift=0.5, light=al.mass_profiles.SphericalIsothermal)),
        use_deflections=True,
        sub_size=4,
        optimizer_class=af.MultiNest,
    )

    phase1.run(galaxy_data=[data_y, data_x])
Beispiel #3
0
def galaxy_fit_phase():

    pixel_scale = 0.1
    image_shape = (150, 150)

    integration_util.reset_paths(test_name=test_name, output_path=output_path)

    grid = al.Grid.from_shape_pixel_scale_and_sub_size(shape=image_shape,
                                                       pixel_scale=pixel_scale,
                                                       sub_size=4)

    galaxy = al.Galaxy(
        redshift=0.5,
        light=al.light_profiles.SphericalExponential(centre=(0.0, 0.0),
                                                     intensity=1.0,
                                                     effective_radius=0.5),
    )

    image = galaxy.profile_image_from_grid(galaxies=[galaxy],
                                           grid=grid,
                                           return_in_2d=True,
                                           bypass_decorator=False)

    noise_map = al.ScaledSquarePixelArray(array=np.ones(image.shape),
                                          pixel_scale=pixel_scale)

    data = al.GalaxyData(image=image,
                         noise_map=noise_map,
                         pixel_scale=pixel_scale)

    phase1 = al.PhaseGalaxy(
        phase_name=test_name + "/",
        galaxies=dict(gal=al.GalaxyModel(
            redshift=0.5, light=al.light_profiles.SphericalExponential)),
        use_image=True,
        sub_size=4,
        optimizer_class=af.MultiNest,
    )

    phase1.run(galaxy_data=[data])
Beispiel #4
0
def run(
    module,
    test_name=None,
    optimizer_class=af.MultiNest,
    config_folder="config",
    positions=None,
):
    test_name = test_name or module.test_name
    test_path = "{}/../".format(os.path.dirname(os.path.realpath(__file__)))
    output_path = test_path + "output/"
    config_path = test_path + config_folder
    af.conf.instance = af.conf.Config(config_path=config_path, output_path=output_path)
    integration_util.reset_paths(test_name=test_name, output_path=output_path)

    imaging_data = simulation_util.load_test_imaging_data(
        data_type=module.data_type, data_resolution=module.data_resolution
    )

    module.make_pipeline(
        name=test_name,
        phase_folders=[module.test_type, test_name],
        optimizer_class=optimizer_class,
    ).run(data=imaging_data, positions=positions)
Beispiel #5
0
    def test_pairing_works(self):

        test_name = "pair_floats"

        integration_util.reset_paths(test_name, output_path)

        sersic = al.EllipticalSersic(
            centre=(0.0, 0.0),
            axis_ratio=0.8,
            phi=90.0,
            intensity=1.0,
            effective_radius=1.3,
            sersic_index=3.0,
        )

        lens_galaxy = galaxy.Galaxy(redshift=0.5, light_profile=sersic)

        simulate_integration_image(test_name=test_name,
                                   pixel_scale=0.5,
                                   galaxies=[lens_galaxy])

        path = "{}/".format(os.path.dirname(os.path.realpath(
            __file__)))  # Setup path so we can output the simulated image.

        imaging_data = al.load_imaging_data_from_fits(
            image_path=path + "/test_files/data/" + test_name + "/image.fits",
            psf_path=path + "/test_files/data/" + test_name + "/psf.fits",
            noise_map_path=path + "/test_files/data/" + test_name +
            "/noise_map.fits",
            pixel_scale=0.1,
        )

        class MMPhase(al.PhaseImaging):
            def customize_priors(self, results):
                self.galaxies.lens.sersic.intensity = (
                    self.galaxies.lens.sersic.axis_ratio)

        phase = MMPhase(
            galaxies=dict(lens=al.GalaxyModel(
                redshift=0.5, sersic=al.light_profiles.EllipticalSersic)),
            optimizer_class=af.MultiNest,
            phase_name="{}/phase1".format(test_name),
        )

        initial_total_priors = phase.variable.prior_count
        phase.make_analysis(data=imaging_data)

        assert phase.galaxies[0].sersic.intensity == al.Galaxies[
            0].sersic.axis_ratio
        assert initial_total_priors - 1 == phase.variable.prior_count

        lines = list(
            filter(
                lambda line: "axis_ratio" in line or "intensity" in line,
                str(phase.variable).split("\n"),
            ))

        assert len(lines) == 2
        assert (
            "galaxies_lens_sersic_axis_ratio                                                  UniformPrior, lower_limit = 0.2, upper_limit = 1.0"
            in lines)
        assert (
            "galaxies_lens_sersic_intensity                                                   UniformPrior, lower_limit = 0.2, upper_limit = 1.0"
            in lines)