Beispiel #1
0
def pipeline():

    sersic = lp.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(light_profile=sersic)

    tools.reset_paths(test_name=test_name, output_path=output_path)
    tools.simulate_integration_image(test_name=test_name,
                                     pixel_scale=0.1,
                                     lens_galaxies=[lens_galaxy],
                                     source_galaxies=[],
                                     target_signal_to_noise=30.0)

    ccd_data = ccd.load_ccd_data_from_fits(
        image_path=path + '/data/' + test_name + '/image.fits',
        psf_path=path + '/data/' + test_name + '/psf.fits',
        noise_map_path=path + '/data/' + test_name + '/noise_map.fits',
        pixel_scale=0.1)

    pipeline = make_pipeline(test_name=test_name)
    pipeline.run(data=ccd_data)
Beispiel #2
0
def pipeline():

    lens_mass = mp.SphericalIsothermal(centre=(0.0, 0.0), einstein_radius=1.6)
    lens_subhalo = mp.SphericalIsothermal(centre=(1.0, 1.0),
                                          einstein_radius=0.0)
    source_light = lp.SphericalSersic(centre=(0.0, 0.0),
                                      intensity=1.0,
                                      effective_radius=0.5,
                                      sersic_index=1.0)

    lens_galaxy = galaxy.Galaxy(mass=lens_mass, subhalo=lens_subhalo)
    source_galaxy = galaxy.Galaxy(light=source_light)

    tools.reset_paths(test_name=test_name, output_path=output_path)
    tools.simulate_integration_image(test_name=test_name,
                                     pixel_scale=0.1,
                                     lens_galaxies=[lens_galaxy],
                                     source_galaxies=[source_galaxy],
                                     target_signal_to_noise=30.0)

    ccd_data = ccd.load_ccd_data_from_fits(
        image_path=path + '/data/' + test_name + '/image.fits',
        psf_path=path + '/data/' + test_name + '/psf.fits',
        noise_map_path=path + '/data/' + test_name + '/noise_map.fits',
        pixel_scale=0.1)

    pipeline = make_pipeline(test_name=test_name)
    result = pipeline.run(data=ccd_data)

    print(dir(result))
def pipeline():

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

    lens_light = lp.SphericalDevVaucouleurs(centre=(0.0, 0.0),
                                            intensity=0.1,
                                            effective_radius=0.5)
    lens_mass = mp.EllipticalIsothermal(centre=(0.0, 0.0),
                                        axis_ratio=0.8,
                                        phi=80.0,
                                        einstein_radius=1.6)
    source_light = lp.EllipticalSersic(centre=(0.0, 0.0),
                                       axis_ratio=0.6,
                                       phi=90.0,
                                       intensity=1.0,
                                       effective_radius=0.5,
                                       sersic_index=1.0)

    lens_galaxy = galaxy.Galaxy(dev=lens_light, sie=lens_mass)
    source_galaxy = galaxy.Galaxy(sersic=source_light)

    tools.simulate_integration_image(test_name=test_name,
                                     pixel_scale=0.1,
                                     lens_galaxies=[lens_galaxy],
                                     source_galaxies=[source_galaxy],
                                     target_signal_to_noise=30.0)

    ccd_data = ccd.load_ccd_data_from_fits(
        image_path=path + '/data/' + test_name + '/image.fits',
        psf_path=path + '/data/' + test_name + '/psf.fits',
        noise_map_path=path + '/data/' + test_name + '/noise_map.fits',
        pixel_scale=0.1)

    pipeline = make_pipeline(test_name=test_name)
    pipeline.run(data=ccd_data)
Beispiel #4
0
def load_profiling_ccd_data(image_type, lens_name, psf_shape):

    pixel_scale = pixel_scale_from_image_type(image_type=image_type)

    return ccd.load_ccd_data_from_fits(
        image_path=path + '/data/' + lens_name + '/' + image_type +
        '/image.fits',
        psf_path=path + '/data/' + lens_name + '/' + image_type + '/psf.fits',
        noise_map_path=path + '/data/' + lens_name + '/' + image_type +
        '/noise_map.fits',
        pixel_scale=pixel_scale,
        resized_psf_shape=psf_shape)
Beispiel #5
0
    def test_constants_work(self):
        name = "const_float"
        test_name = '/const_float'

        tools.reset_paths(test_name, output_path)

        sersic = lp.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(light_profile=sersic)

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

        ccd_data = ccd.load_ccd_data_from_fits(image_path=path + '/data/' + test_name + '/image.fits',
                                               psf_path=path + '/data/' + test_name + '/psf.fits',
                                               noise_map_path=path + '/data/' + test_name + '/noise_map.fits',
                                               pixel_scale=0.1)

        class MMPhase(ph.LensPlanePhase):

            def pass_priors(self, previous_results):
                self.lens_galaxies.lens.sersic.axis_ratio = 0.2
                self.lens_galaxies.lens.sersic.phi = 90.0
                self.lens_galaxies.lens.sersic.intensity = 1.0
                self.lens_galaxies.lens.sersic.effective_radius = 1.3
                self.lens_galaxies.lens.sersic.sersic_index = 3.0

        phase = MMPhase(lens_galaxies=dict(lens=gm.GalaxyModel(sersic=lp.EllipticalSersic)),
                        optimizer_class=nl.MultiNest, phase_name="{}/phase1".format(name))

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

        phase.make_analysis(data=ccd_data)

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

        assert isinstance(sersic, mm.PriorModel)

        assert isinstance(sersic.axis_ratio, prior.Constant)
        assert isinstance(sersic.phi, prior.Constant)
        assert isinstance(sersic.intensity, prior.Constant)
        assert isinstance(sersic.effective_radius, prior.Constant)
        assert isinstance(sersic.sersic_index, prior.Constant)
Beispiel #6
0
def test_pipeline():

    bulge_0 = lp.EllipticalSersic(centre=(-1.0, -1.0),
                                  axis_ratio=0.9,
                                  phi=90.0,
                                  intensity=1.0,
                                  effective_radius=1.0,
                                  sersic_index=4.0)
    disk_0 = lp.EllipticalSersic(centre=(-1.0, -1.0),
                                 axis_ratio=0.6,
                                 phi=90.0,
                                 intensity=20.0,
                                 effective_radius=2.5,
                                 sersic_index=1.0)
    bulge_1 = lp.EllipticalSersic(centre=(1.0, 1.0),
                                  axis_ratio=0.9,
                                  phi=90.0,
                                  intensity=1.0,
                                  effective_radius=1.0,
                                  sersic_index=4.0)
    disk_1 = lp.EllipticalSersic(centre=(1.0, 1.0),
                                 axis_ratio=0.6,
                                 phi=90.0,
                                 intensity=20.0,
                                 effective_radius=2.5,
                                 sersic_index=1.0)

    lens_galaxy_0 = galaxy.Galaxy(bulge=bulge_0, disk=disk_0)
    lens_galaxy_1 = galaxy.Galaxy(bulge=bulge_1, disk=disk_1)

    tools.reset_paths(test_name=test_name, output_path=output_path)
    tools.simulate_integration_image(
        test_name=test_name,
        pixel_scale=0.1,
        lens_galaxies=[lens_galaxy_0, lens_galaxy_1],
        source_galaxies=[],
        target_signal_to_noise=30.0)

    ccd_data = ccd.load_ccd_data_from_fits(
        image_path=path + '/data/' + test_name + '/image.fits',
        psf_path=path + '/data/' + test_name + '/psf.fits',
        noise_map_path=path + '/data/' + test_name + '/noise_map.fits',
        pixel_scale=0.1)

    pipeline = make_pipeline(test_name=test_name)
    pipeline.run(data=ccd_data)
Beispiel #7
0
    def test_pairing_works(self):
        test_name = 'pair_floats'

        tools.reset_paths(test_name, output_path)

        sersic = lp.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(light_profile=sersic)

        tools.simulate_integration_image(test_name=test_name, pixel_scale=0.5, lens_galaxies=[lens_galaxy],
                                         source_galaxies=[], target_signal_to_noise=10.0)

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

        ccd_data = ccd.load_ccd_data_from_fits(image_path=path + '/data/' + test_name + '/image.fits',
                                               psf_path=path + '/data/' + test_name + '/psf.fits',
                                               noise_map_path=path + '/data/' + test_name + '/noise_map.fits',
                                               pixel_scale=0.1)

        class MMPhase(ph.LensPlanePhase):

            def pass_priors(self, previous_results):
                self.lens_galaxies.lens.sersic.intensity = self.lens_galaxies.lens.sersic.axis_ratio

        phase = MMPhase(lens_galaxies=dict(lens=gm.GalaxyModel(sersic=lp.EllipticalSersic)),
                        optimizer_class=nl.MultiNest, phase_name="{}/phase1".format(test_name))

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

        assert phase.lens_galaxies[0].sersic.intensity == phase.lens_galaxies[0].sersic.axis_ratio
        assert initial_total_priors - 1 == phase.variable.prior_count
        assert len(phase.variable.flat_prior_model_tuples) == 1

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

        assert len(lines) == 2
        assert "lens_axis_ratio                                             UniformPrior, lower_limit = 0.2, " \
               "upper_limit = 1.0" in lines
        assert "lens_intensity                                              UniformPrior, lower_limit = 0.2, " \
               "upper_limit = 1.0" in lines
Beispiel #8
0
def pipeline():

    lens_mass = mp.EllipticalIsothermal(centre=(0.01, 0.01),
                                        axis_ratio=0.8,
                                        phi=80.0,
                                        einstein_radius=1.6)

    source_bulge_0 = lp.EllipticalSersic(centre=(0.01, 0.01),
                                         axis_ratio=0.9,
                                         phi=90.0,
                                         intensity=1.0,
                                         effective_radius=1.0,
                                         sersic_index=4.0)

    source_bulge_1 = lp.EllipticalSersic(centre=(0.1, 0.1),
                                         axis_ratio=0.9,
                                         phi=90.0,
                                         intensity=1.0,
                                         effective_radius=1.0,
                                         sersic_index=4.0)

    lens_galaxy = galaxy.Galaxy(sie=lens_mass)
    source_galaxy = galaxy.Galaxy(bulge_0=source_bulge_0,
                                  bulge_1=source_bulge_1)

    tools.reset_paths(test_name=test_name, output_path=output_path)
    tools.simulate_integration_image(test_name=test_name,
                                     pixel_scale=0.1,
                                     lens_galaxies=[lens_galaxy],
                                     source_galaxies=[source_galaxy],
                                     target_signal_to_noise=30.0)

    ccd_data = ccd.load_ccd_data_from_fits(
        image_path=path + '/data/' + test_name + '/image.fits',
        psf_path=path + '/data/' + test_name + '/psf.fits',
        noise_map_path=path + '/data/' + test_name + '/noise_map.fits',
        pixel_scale=0.1)

    pipeline = make_pipeline(test_name=test_name)
    pipeline.run(data=ccd_data)
Beispiel #9
0
# expand on them for your own personal scientific needs

# Get the relative path to the config files and output folder in our workspace.
path = '{}/../'.format(os.path.dirname(os.path.realpath(__file__)))

# Use this path to explicitly set the config path and output path.
conf.instance = conf.Config(config_path=path+'config', output_path=path+'output')

# It is convenient to specify the lens name as a string, so that if the pipeline is applied to multiple images we \
# don't have to change all of the path entries in the load_ccd_data_from_fits function below.

lens_name = 'no_lens_light_and_x2_source' # An example simulated image with lens light emission and a source galaxy.
pixel_scale = 0.1

ccd_data = ccd.load_ccd_data_from_fits(image_path=path + '/data/example/' + lens_name + '/image.fits',
                                       psf_path=path+'/data/example/'+lens_name+'/psf.fits',
                                       noise_map_path=path+'/data/example/'+lens_name+'/noise_map.fits',
                                       pixel_scale=pixel_scale)

ccd_plotters.plot_ccd_subplot(ccd_data=ccd_data)

# Running a pipeline is easy, we simply import it from the pipelines folder and pass the lens data to its run function.
# Below, we'll' use a 3 phase example pipeline to fit the data with a parametric lens light, mass and source light
# profile. Checkout _workspace/pipelines/examples/lens_light_and_x1_source_parametric.py_' for a full description of
# the pipeline.

from workspace.pipelines.examples import no_lens_light_and_source_inversion

pipeline = no_lens_light_and_source_inversion.make_pipeline(pipeline_path='example/' + lens_name + '/')

pipeline.run(data=ccd_data)
Beispiel #10
0
# spans its dynamic range.
array_plotters.plot_array(array=image,
                          title='SLACS1430+4105 Image',
                          norm='linear',
                          norm_min=0.0,
                          norm_max=0.3)

# We can also load the full set of ccd data (image, noise-map, PSF) and use the ccd_plotters to make the figures above.
from autolens.data import ccd
from autolens.data.plotters import ccd_plotters

psf_path = path + '/data/example/' + lens_name + '/psf.fits'
noise_map_path = path + '/data/example/' + lens_name + '/noise_map.fits'

ccd_data = ccd.load_ccd_data_from_fits(image_path=image_path,
                                       psf_path=psf_path,
                                       noise_map_path=noise_map_path,
                                       pixel_scale=0.03)

# These plotters can be customized using the exact same functions as above.
ccd_plotters.plot_noise_map(ccd_data=ccd_data,
                            title='SLACS1430+4105 Noise-Map',
                            norm='log')

# Of course, as we've seen in many other examples, a sub-plot of the ccd data can be plotted. This can also take the
# customization inputs above, but it should be noted that the options are applied to all images, and thus will most
# likely degrade a number of the sub-plot images.
ccd_plotters.plot_ccd_subplot(ccd_data=ccd_data,
                              norm='symmetric_log',
                              linthresh=0.05,
                              linscale=0.02)
Beispiel #11
0
from autolens.lens.plotters import ray_tracing_plotters
from autolens.lens.plotters import lens_fit_plotters

# In this example, we'll fit the ccd imaging data we simulated in the previous exercise. We'll do this using model
# images generated via a tracer, and by comparing to the simulated image we'll get diagostics about the quality of the fit.

# If you are using Docker, the path you should use to output these images is (e.g. comment out this line)
# path = '/home/user/workspace/howtolens/chapter_1_introduction'

# If you arn't using docker, you need to change the path below to the chapter 2 directory and uncomment it
# path = '/path/to/user/workspace/howtolens/chapter_1_introduction'

path = '/home/jammy/PyCharm/Projects/AutoLens/workspace/howtolens/chapter_1_introduction'

ccd_data = ccd.load_ccd_data_from_fits(image_path=path + '/data/image.fits',
                                       noise_map_path=path+'/data/noise_map.fits',
                                       psf_path=path + '/data/psf.fits', pixel_scale=0.1)

# The variable ccd_data is a CCDData object, which is a 'package' of all components of the CCD data of the lens, in particular:

# 1) The image.
#
# 2) The Point Spread Function (PSF).
#
# 3) Its noise-map.
print('Image:')
print(ccd_data.image)
print('Noise-Map:')
print(ccd_data.noise_map)
print('PSF:')
print(ccd_data.psf)
Beispiel #12
0
# datas from an unsuitable format.

# First, lets setup the path to our current working directory. I recommend you use the 'AutoLens/workspace' directory
# and that you place your datas in the 'AutoLens/workspace/datas' directory.

# (for this tutorial, we'll use the 'AutoLens/workspace/howtolens/preparing_data' directory. The folder 'datas' contains
# the example datas-sets we'll use in this tutorial).
path = 'path/to/AutoLens/workspace/howtolens/chapter_2_lens_modeling/'  # <----- You must include this slash on the end
path = '/home/jammy/PyCharm/Projects/AutoLens/workspace/howtolens/loading_and_preparing_data/'
simulate_data.simulate_all_images()  # This will populate the 'data' folder.

# First, lets load a datas-set using the 'load_imaging_from_fits' function of the regular module (import as 'im'). This
# datas-set represents a good datas-reduction - it conforms to all the formatting standards I describe in this tutorial!
ccd_data = ccd.load_ccd_data_from_fits(
    image_path=path + 'data/image/image.fits',
    noise_map_path=path + 'data/image/noise_map.fits',
    psf_path=path + 'data/image/psf.fits',
    pixel_scale=0.1)
ccd_plotters.plot_ccd_subplot(ccd_data=ccd_data)

# If your datas comes in one .fits file spread across multiple hdus, you can specify the hdus of each regular instead.
ccd_data = ccd.load_ccd_data_from_fits(
    image_path=path + 'data/image/multiple_hdus.fits',
    image_hdu=0,
    noise_map_path=path + 'data/image/multiple_hdus.fits',
    noise_map_hdu=1,
    psf_path=path + 'data/image/multiple_hdus.fits',
    psf_hdu=2,
    pixel_scale=0.1)
ccd_plotters.plot_ccd_subplot(ccd_data=ccd_data)
def test__simulate_lensed_source_and_fit__include_psf_blurring__chi_squared_is_0__noise_normalization_correct(
):

    psf = ccd.PSF.simulate_as_gaussian(shape=(3, 3),
                                       pixel_scale=0.2,
                                       sigma=0.75)

    grid_stack = grids.GridStack.grid_stack_for_simulation(shape=(11, 11),
                                                           pixel_scale=0.2,
                                                           psf_shape=psf.shape,
                                                           sub_grid_size=1)

    lens_galaxy = g.Galaxy(light=lp.EllipticalSersic(centre=(0.1, 0.1),
                                                     intensity=0.1),
                           mass=mp.EllipticalIsothermal(centre=(0.1, 0.1),
                                                        einstein_radius=1.8))
    source_galaxy = g.Galaxy(
        light=lp.EllipticalExponential(centre=(0.1, 0.1), intensity=0.5))
    tracer = ray_tracing.TracerImageSourcePlanes(
        lens_galaxies=[lens_galaxy],
        source_galaxies=[source_galaxy],
        image_plane_grid_stack=grid_stack)

    ccd_simulated = ccd.CCDData.simulate(
        array=tracer.image_plane_image_for_simulation,
        pixel_scale=0.2,
        exposure_time=300.0,
        psf=psf,
        background_sky_level=None,
        add_noise=False)
    ccd_simulated.noise_map = np.ones(ccd_simulated.image.shape)

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

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

    if os.path.exists(path) == False:
        os.makedirs(path)

    array_util.numpy_array_to_fits(array=ccd_simulated.image,
                                   file_path=path + '/image.fits')
    array_util.numpy_array_to_fits(array=ccd_simulated.noise_map,
                                   file_path=path + '/noise_map.fits')
    array_util.numpy_array_to_fits(array=psf, file_path=path + '/psf.fits')

    ccd_data = ccd.load_ccd_data_from_fits(image_path=path + '/image.fits',
                                           noise_map_path=path +
                                           '/noise_map.fits',
                                           psf_path=path + '/psf.fits',
                                           pixel_scale=0.2)

    mask = msk.Mask.circular(shape=ccd_data.image.shape,
                             pixel_scale=0.2,
                             radius_arcsec=0.8)

    lens_data = ld.LensData(ccd_data=ccd_data, mask=mask, sub_grid_size=1)

    tracer = ray_tracing.TracerImageSourcePlanes(
        lens_galaxies=[lens_galaxy],
        source_galaxies=[source_galaxy],
        image_plane_grid_stack=lens_data.grid_stack)

    fitter = lens_fit.LensProfileFit(lens_data=lens_data, tracer=tracer)

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