Exemplo n.º 1
0
def main():
    zd = 0.5
    lens = lenses.PlummerLens(D(zd), { "mass": 1e14*MASS_SUN, "width": 5*ANGLE_ARCSEC })
    li = plotutil.LensInfo(lens, size=15*ANGLE_ARCSEC, zd=zd)

    iws = inversion.InversionWorkSpace(zd, 20*ANGLE_ARCSEC)
    
    num = 5
    print(f"Creating {num} sources")
    while num > 0:
        zs = np.random.uniform(zd, 6)
        beta = np.random.uniform(-1*ANGLE_ARCSEC, 1*ANGLE_ARCSEC, size=(2,))
        
        li.setSourceRedshift(zs)
        ip = li.getImagePlane()
        thetas = ip.traceBeta(beta)
        if len(thetas) > 1:
            num -= 1
            print(f"Found image, {num} to go")

            img = images.ImagesData(len(thetas))
            for i in range(len(thetas)):
                img.addPoint(i, thetas[i])

            iws.addImageDataToList(img, zs, "pointimages")

    print("Fitness info")
    print("------------")
    print(iws.calculateFitness(None))
    print("")


    imperfectLens = lenses.CompositeLens(D(zd), [
        { "lens": lens, "factor": 0.999, "x": 0, "y": 0, "angle": 0 } ])

    for l, info in [ (lens, "True lens"), (imperfectLens, "Imperfect lens") ]:
        s = f"Using: {info}"
        print(s)
        print("-" * len(s))
        print("Using lens itself:")
        print(iws.calculateFitness(l))
        print("")

        print("Using backprojected images:")
        bpImages = iws.backProject(l)
        print(iws.calculateFitness(bpImages))
        print("")
Exemplo n.º 2
0
V = lambda x, y: np.array([x, y], dtype=np.double)

cosm = cosmology.Cosmology(0.7, 0.3, 0, 0.7)
D = cosm.getAngularDiameterDistance

cosmology.setDefaultCosmology(cosm)
z1, z2 = 0.5, 1.5

sourceRedshifts = [ 1.25, 2.0 ]
allThetas = [ [ V(10,8)*ANGLE_ARCSEC ] , [ V(-12,2)*ANGLE_ARCSEC ] ]

for factor in [ 0.5, 1.0, 2.0 ]:
    print("Using factor", factor)
    lensesAndRedshifts = [
        (lenses.CompositeLens(D(z1), [
            { "lens": lenses.PlummerLens(D(z1), { "mass": 1e14*MASS_SUN, "width": 5*ANGLE_ARCSEC }),
              "x": 0, "y": 0, "angle": 0, "factor": factor }
            ]), z1),
        (lenses.CompositeLens(D(z2), [
            { "lens": lenses.PlummerLens(D(z2), { "mass": 5e13*MASS_SUN, "width": 3*ANGLE_ARCSEC }),
              "x": 1*ANGLE_ARCSEC, "y": -1*ANGLE_ARCSEC, "angle": 0, "factor": factor }
            ]), z2),
        ]

    lensPlane = multiplane.MultiLensPlane(lensesAndRedshifts, V(-30,-30)*ANGLE_ARCSEC, V(30, 30)*ANGLE_ARCSEC, 511, 511)

    for idx, zs, thetas in zip(range(len(sourceRedshifts)), sourceRedshifts, allThetas):
        print("Positions for source", idx)

        imgPlane = multiplane.MultiImagePlane(lensPlane, zs)
        betas = imgPlane.traceTheta(np.array(thetas))
        for bx, by in betas/ANGLE_ARCSEC:
Exemplo n.º 3
0
plotutil.setDefaultAngularUnit(ANGLE_ARCSEC)
feedback.setDefaultFeedback("none")

zd1, zd2 = 0.5, 1.0
lens1 = lenses.CompositeLens(D(zd1), [
    {
        "factor":
        0.7,
        "x":
        1.0 * ANGLE_ARCSEC,
        "y":
        -0.5 * ANGLE_ARCSEC,
        "angle":
        0,
        "lens":
        lenses.PlummerLens(D(zd1), {
            "mass": 1e14 * MASS_SUN,
            "width": 4 * ANGLE_ARCSEC
        })
    },
    {
        "factor": 1.0,
        "x": 0,
        "y": 0,
        "angle": 0,
        "lens": lenses.MassSheetLens(D(zd1), {"density": 1})
    },
])

lens2 = lenses.CompositeLens(D(zd2), [
    {
        "factor":
Exemplo n.º 4
0
                                                             MASS_SUN))

iws.setUniformGrid(64)
corrections, corrFitness, fitdesc = iws.invert(512,
                                               baseLens=baseLens,
                                               allowNegativeValues=True,
                                               massScale=corrMassScale)
corrections.save("corrections.lensdata")

correctedLens = lenses.CompositeLens(baseLens.getLensDistance(),
                                     [{
                                         "factor": 1,
                                         "x": 0,
                                         "y": 0,
                                         "angle": 0,
                                         "lens": baseLens
                                     }, {
                                         "factor": 1,
                                         "x": 0,
                                         "y": 0,
                                         "angle": 0,
                                         "lens": corrections
                                     }])
correctedLens.save("correctedlens.lensdata")

print(fitness1)
print(fitness2)
print(fitness3)
print(fitness4)
print(fitness5)
print(baseFitness)
print(corrFitness)
Exemplo n.º 5
0
for x in lensplanes:
    factor = np.random.uniform(0, 0.05)
    lens = lenses.MassSheetLens(x["Dd"], {"Ds": 1, "Dds": 1})
    x["params"].append({
        "lens": lens,
        "factor": factor,
        "x": 0,
        "y": 0,
        "angle": 0
    })
    density = lens.getLensParameters()["density"]
    print(f"{factor*density}, ", end='')

print("};")

lensesAndRedshifts = [(lenses.CompositeLens(x["Dd"], x["params"]), x["zd"])
                      for x in lensplanes]
# The grid dimensions are not used for this test
lensPlane = multiplane.MultiLensPlane(lensesAndRedshifts,
                                      V(-50, -50) * ANGLE_ARCSEC,
                                      V(50, 50) * ANGLE_ARCSEC, 64, 64)

numSources = np.random.randint(10, 20)
sourceRedshifts = np.random.uniform(min(lensRedShifts) + 0.1, 5.0, numSources)
# TODO: this doesn't seem to work if not sorted!
# sourceRedshifts = sorted(sourceRedshifts)

print(
    "const vector<pair<double,vector<pair<Vector2Dd, Vector2Dd>>>> thetaBetaMappings {"
)
for zs in sourceRedshifts:
Exemplo n.º 6
0
Z = cosm.getAngularDiameterDistance

# Use a default plot unit of one arcsec
plotutil.setDefaultAngularUnit(ANGLE_ARCSEC)

# A shorter name for the LensInfo class
LI = plotutil.LensInfo

# Create a SIS lens with a velocity dispersion of 250 km/s and
# set it at a specific position
z1 = 0.5
sis = lenses.SISLens(Z(z1), {"velocityDispersion": 250000})
movedSis = lenses.CompositeLens(Z(z1), [{
    "lens": sis,
    "factor": 1,
    "x": -0.25 * ANGLE_ARCSEC,
    "y": -0.5 * ANGLE_ARCSEC,
    "angle": 0
}])

# Create a SIE lens with specific velocity dispersion and ellipticity
# at different redshift
z2 = 1.0
sie = lenses.SIELens(Z(z2), {"velocityDispersion": 200000, "ellipticity": 0.7})
movedSie = lenses.CompositeLens(Z(z2), [{
    "lens": sie,
    "factor": 1,
    "x": 1 * ANGLE_ARCSEC,
    "y": 0.75 * ANGLE_ARCSEC,
    "angle": 60
}])
Exemplo n.º 7
0
# Omega_m = 0.3 and Omega_lambda = 0.7
cosm = cosmology.Cosmology(0.7, 0.3, 0, 0.7)

# For a lens at z = 0.5, calculate the angular diameter distance
z_d = 0.5
D_d = cosm.getAngularDiameterDistance(z_d)

# Let's show what this angular diameter distance is, in units of Mpc
print("D_d = {:.2f} Mpc".format(D_d / DIST_MPC))

# Create a SIS lens with a velocity dispersion of 250 km/s
sis = lenses.SISLens(D_d, {"velocityDispersion": 250000})

# Create a SIE lens with specific velocity dispersion and ellipticity
sie = lenses.SIELens(D_d, {"velocityDispersion": 200000, "ellipticity": 0.7})

# Combine these models using a CompositeLens
combLens = lenses.CompositeLens(D_d, [{
    "lens": sis,
    "factor": 1,
    "x": -1 * ANGLE_ARCSEC,
    "y": -2 * ANGLE_ARCSEC,
    "angle": 0
}, {
    "lens": sie,
    "factor": 1,
    "x": 2 * ANGLE_ARCSEC,
    "y": 1.5 * ANGLE_ARCSEC,
    "angle": 60
}])