Beispiel #1
0
def generate_Glafic_input_shear(gamma, kappa, x, y, theta, infile="temp.input", outfile="temp.input", **kwargs):
    tmpfile = "tmp.tmp"
    with open(infile) as f2:
        with open(tmpfile, "w") as f3:
            for line in f2:
                f3.write(line)
    lt.replaceAll(
        tmpfile,
        "#lens pert pert_z pert_X pert_Y pert_gamma pert_theta 0.0 pert_kappa",
        "lens pert "
        + str(gparam.z_s)
        + " "
        + str(x)
        + " "
        + str(y)
        + " "
        + str(gamma)
        + " "
        + str(theta)
        + " 0.0 "
        + str(kappa),
    )
    lt.replaceAll(tmpfile, "startup 1 1 1", "startup 2 1 1")  # for 'main' only
    lt.replaceAll(tmpfile, "startup " + str(2) + " 1 0", "startup " + str(3) + " 1 0")
    with open(tmpfile) as f4:
        with open(outfile, "w") as f5:
            for line in f4:
                f5.write(line)
    del f2, f3, f4, f5
    return outfile
Beispiel #2
0
def generate_point_src_input(
    ID_macroimg, pntsrc_count, infile="data_point.dat", x, y, f, err_xy, err_f, dt, err_dt, parity
):
    outfile = "%s_point.dat" % (dataname)
    tmpfile = "tmp.tmp"
    with open(infile) as f2:
        with open(tmpfile, "w") as f3:
            for line in f2:
                f3.write(line)
    lt.replaceAll(
        tmpfile,
        "#ps_ID no_macroimg z_s",
        str(ID_macroimg) + str(pntsrc_count) + str(gparam.z_s) + "\n#ps_ID no_macroimg z_s",
    )
    lt.replaceAll(
        tmpfile,
        "#x_macroimg y_macroimg  f_macroimg  err_xy  err_f  dt_macroimg err_dt parity_macroimg",
        str(x)
        + " "
        + str(y)
        + " "
        + str(f)
        + " "
        + str(err_xy)
        + " "
        + str(err_f)
        + " "
        + str(dt)
        + " "
        + str(err_dt)
        + " "
        + str(parity)
        + "\n#x_macroimg y_macroimg  f_macroimg  err_xy  err_f  dt_macroimg err_dt parity_macroimg",
    )
    f3.close()
    del f2, f3
    return outfile
Beispiel #3
0
def generate_Glafic_input_src(srctype, f, x, y, infile="temp.input", outfile="temp.input", **kwargs):
    tmpfile = "tmp.tmp"
    with open(infile) as f2:
        with open(tmpfile, "w") as f3:
            for line in f2:
                f3.write(line)
    if srctype == "point":
        lt.replaceAll(
            tmpfile,
            "#point PS_z PS_X PS_Y",
            "point " + str(gparam.z_s) + " " + str(x) + " " + str(y) + "\n#point PS_z PS_X PS_Y",
        )
    elif srctype == "gauss":
        r0 = 0.01
        e = 0
        theta = 0
        for key, value in kwargs.iteritems():
            if key == "r0":
                r0 = value
            if key == "e":
                e = value
            if key == "theta":
                theta = value
        lt.replaceAll(
            tmpfile,
            "#extend gauss G_z G_ftot G_X G_Y G_e G_theta G_sigma 0.0",
            "extend gauss "
            + str(gparam.z_s)
            + " "
            + str(f)
            + " "
            + str(x)
            + " "
            + str(y)
            + " "
            + str(e)
            + " "
            + str(theta)
            + " "
            + str(r0)
            + " 0.0"
            + "\n#extend gauss G_z G_ftot G_X G_Y G_e G_theta G_sigma 0.0",
        )
        lt.replaceAll(tmpfile, "calcein Z_S", "calcein " + str(gparam.z_s))
    with open(tmpfile) as f4:
        with open(outfile, "w") as f5:
            for line in f4:
                f5.write(line)
    del f2, f3, f4, f5
    return outfile
Beispiel #4
0
def generate_Glafic_input_gen(prefix, infile="Glafic.input", outfile="temp.input"):
    """ This function needs to be called before adding any lensing component 
    (source, lens, shear) to the input"""
    with open("Glafic.input", "r") as f2:
        with open(outfile, "w") as f3:
            for line in f2:
                f3.write(line)
    lt.replaceAll(outfile, "z_l", str(gparam.z_l))
    lt.replaceAll(outfile, "PREFIX", prefix)
    lt.replaceAll(outfile, "XMIN", str(gparam.xmin))
    lt.replaceAll(outfile, "YMIN", str(gparam.ymin))
    lt.replaceAll(outfile, "XMAX", str(gparam.xmax))
    lt.replaceAll(outfile, "YMAX", str(gparam.ymax))
    lt.replaceAll(outfile, "pix_ext   RES", "pix_ext   " + str(gparam.pix_ext))
    lt.replaceAll(outfile, "pix_poi   RES", "pix_poi   " + str(gparam.pix_poi))
    lt.replaceAll(outfile, "MAXLEV", str(gparam.maxlev))
    f3.close()
    del f2, f3
    return outfile
Beispiel #5
0
def generate_Glafic_input_lens(profile, lgM, x, y, e, theta, infile="temp.input", outfile="temp.input", **kwargs):
    """ When calling this function for a halo that contains subhalos, 
    make sure the subhalo mass is reduced from the original halo mass """
    tmpfile = "tmp.tmp"
    M = 10 ** lgM
    sigma = lt.logMtosigma(lgM, gparam.z_l)
    C = lt.Bullock01(lgM, gparam.z_l)
    with open(infile) as f2:
        with open(tmpfile, "w") as f3:
            for line in f2:
                f3.write(line)
    if profile == "sie":
        core = 1e-5
        for key, value in kwargs.iteritems():
            if key == "core":
                core = value
        lt.replaceAll(
            tmpfile,
            "#lens sie S_sigma S_X S_Y S_e S_theta S_core 0.0",
            "lens sie "
            + str(sigma)
            + " "
            + str(x)
            + " "
            + str(y)
            + " "
            + str(e)
            + " "
            + str(theta)
            + " "
            + str(core)
            + " 0.0"
            + "\n#lens sie S_sigma S_X S_Y S_e S_theta S_core 0.0",
        )
    elif profile == "jaffe":
        core = 1e-5
        trunc = 1.0
        for key, value in kwargs.iteritems():
            if key == "core":
                core = value
            if key == "trunc":
                trunc = value
        lt.replaceAll(
            tmpfile,
            "#lens jaffe J_sigma J_X J_Y J_e J_theta J_trun J_core",
            "lens jaffe "
            + str(sigma)
            + " "
            + str(x)
            + " "
            + str(y)
            + " "
            + str(e)
            + " "
            + str(theta)
            + " "
            + str(trunc)
            + " "
            + str(core)
            + "\n#lens jaffe J_sigma J_X J_Y J_e J_theta J_trun J_core",
        )
    elif profile == "gnfw":
        alpha = 0.05
        for key, value in kwargs.iteritems():
            if key == "alpha":
                alpha = value
        lt.replaceAll(
            tmpfile,
            "#lens gnfw NFW_MASS NFW_X NFW_Y NFW_e NFW_theta NFW_c NFW_alpha",
            "lens gnfw "
            + str(M)
            + " "
            + str(x)
            + " "
            + str(y)
            + " "
            + str(e)
            + " "
            + str(theta)
            + " "
            + str(C)
            + " "
            + str(alpha)
            + "\n#lens gnfw NFW_MASS NFW_X NFW_Y NFW_e NFW_theta NFW_c NFW_alpha",
        )
    elif profile == "tnfw":
        lt.replaceAll(
            tmpfile,
            "#lens tnfw NFW_MASS NFW_X NFW_Y NFW_e NFW_theta NFW_c 0.0",
            "lens tnfw "
            + str(M)
            + " "
            + str(x)
            + " "
            + str(y)
            + " "
            + str(e)
            + " "
            + str(theta)
            + " "
            + str(C)
            + " 0.037"
            + "\n#lens tnfw NFW_MASS NFW_X NFW_Y NFW_e NFW_theta NFW_c 0.037",
        )  # t=r_trunc/r_vir 0.037 for 300pc in 1e9, and 0.123 for 1kpc in 1e9
    elif profile == "ein":
        alpha = 0.05
        for key, value in kwargs.iteritems():
            if key == "alpha":
                alpha = value
        lt.replaceAll(
            tmpfile,
            "#lens ein E_MASS E_X E_Y E_e E_theta E_c E_alpha",
            "lens ein "
            + str(M)
            + " "
            + str(x)
            + " "
            + str(y)
            + " "
            + str(e)
            + " "
            + str(theta)
            + " "
            + str(C)
            + " "
            + str(alpha)
            + "\n#lens ein E_MASS E_X E_Y E_e E_theta E_c E_alpha",
        )
    f3.close()
    with open(tmpfile) as f4:
        with open(outfile, "w") as f5:
            for line in f4:
                f5.write(line)
    del f2, f3, f4, f5
    return outfile
Beispiel #6
0
def generate_Glafic_input_startup(lens_count, extsrc_count, pntsrc_count, infile="temp.input", outfile="temp.input"):
    """ This function needs to be called with the correct count of all sources and lenses"""
    tmpfile = "tmp.tmp"
    with open(infile) as f2:
        with open(tmpfile, "w") as f3:
            for line in f2:
                f3.write(line)
    lt.replaceAll(tmpfile, "startup L_No. S_No. P_No.", "startup %d %d %d" % (lens_count, extsrc_count, pntsrc_count))
    for l in range(lens_count):
        if l == lens_count - 1:
            lt.replaceAll(tmpfile, "#LENS_setopt", "0 0 0 0 0 0 0")
        else:
            lt.replaceAll(tmpfile, "#LENS_setopt", "0 0 0 0 0 0 0\n#LENS_setopt")
    for e in range(extsrc_count):
        if e == extsrc_count - 1:
            lt.replaceAll(tmpfile, "#ext_setopt", "0 0 0 0 0 0 0 0")
        else:
            lt.replaceAll(tmpfile, "#ext_setopt", "0 0 0 0 0 0 0 0\n#ext_setopt")
    for p in range(pntsrc_count):
        if p == pntsrc_count - 1:
            lt.replaceAll(tmpfile, "#pnt_setopt", "0 0 0")
        else:
            lt.replaceAll(tmpfile, "#pnt_setopt", "0 0 0\n#pnt_setopt")
    f3.close()
    with open(tmpfile) as f4:
        with open(outfile, "w") as f5:
            for line in f4:
                f5.write(line)
    del f2, f3, f4, f5
    return outfile