Пример #1
0
def causAmp(uvec, rF2, lc, ax, ay):
    """ Returns an approximation to the amplitude at the caustic, using the formula from Cooke 1982. """
    ux, uy = uvec
    psi20, psi02, psi11 = lensh(ux, uy)
    phi20 = ax**2 / rF2 + lc * psi20
    phi02 = ay**2 / rF2 + lc * psi02
    phi11 = lc * psi11
    phi30, phi21, phi12, phi03 = lc * np.asarray(lensgh(ux, uy))
    B = phi20**3 * phi03 - 3 * phi20**2 * phi11 * phi12 + 3 * phi20 * phi11**2 * phi21 - phi11**3 * phi30
    amp = ax * ay / (2 * pi * rF2) * 2.**(5. / 6.) * pi**(1. / 2.) * gfunc(
        1. / 3.) * np.abs(phi20)**0.5 / (3.**(1. / 6.) * np.abs(B)**(1. / 3.))
    #  G = 2./(pi*np.abs(phi20))*(ax*ay*gfunc(1./3.)*np.cos(pi/6.)/(rF2*(9*np.abs(phi03))**(1./3.)))**2.
    # G = (ax*ay/(2*pi*rF2))**2/3 * (gfunc(0.5)*gfunc(1./3.)/(np.abs(phi20)**0.5*np.abs(phi03)**(1./3.)))**2
    return amp**2
Пример #2
0
def L(nser, reff):
    return reff**2 * 2 * np.pi * nser / b(nser)**(2 * nser) * gfunc(2 * nser)
Пример #3
0
def rho(r, r2, alpha):
    h = r2 / (2. / alpha)**(1 / alpha)
    mtot = 4. * np.pi * h**3 * np.exp(2. / alpha) / alpha * gfunc(3. / alpha)
    return np.exp(-2. / alpha * ((r / r2)**alpha - 1.)) / mtot
Пример #4
0
def M2d(R, gamma):
    return 2 * np.pi**1.5 / (3. - gamma) * gfunc(
        (gamma - 1.) / 2.) / gfunc(gamma / 2.) * R**(3 - gamma)
def L(n, Re):
    return Re**2 * 2 * np.pi * n / b(n)**(2 * n) * gfunc(2 * n)
Пример #6
0
def L(n,Re):
    return Re**2*2*np.pi*n/b(n)**(2*n)*gfunc(2*n)
Пример #7
0
def Sigma(R, gamma):
    return R**(1 - gamma) * np.pi**0.5 * gfunc(
        (gamma - 1.) / 2.) / gfunc(gamma / 2.)
Пример #8
0
def main():
    theta_E = 1.25
    # check if all the output files are created #
    str = []
    nl = 0
    for line in open('sig_files/list', 'r'):
        str.append(line)
        nl += 1
    print nl
    for j in range(nl):
        string_ = str[j]
        str[j] = string_[41:-5]
    print len(str)
    num = map(int, str)
    num = sort(num)
    print num
    # finding the missing file index #
    nmiss = 0
    missings = []
    for i in range(nl):
        if i != num[i]:
            print i
            missings.append(i)
            num = insert(num, i, i)
            nmiss += 1
    f = open('missing_idx', 'w')
    for i in range(nmiss):
        f.write('%s\n' % (missings[i]))
    f.close()
    print nmiss
    print nmiss + nl
    #	return
    ngam = 121
    nbout = 13
    nbin = 13
    nrani = 121
    re = 1.85
    gamma_arr = linspace(1.01, 2.99, ngam)
    rani_arr = logspace(log10(0.5 * re), log10(5. * re), nrani)
    bin_arr = linspace(-0.6, 0.6, nbin)
    bout_arr = linspace(-0.6, 0.6, nbout)
    np = 32
    nsamp = 13 * 13
    data_grid = zeros((ngam, nrani, nbin, nbout), 'float64')
    asec_to_rad = 4.84e-6
    # i is the index of vdisp file #
    for i in range(77323):
        nline = 0
        if i % 1000 == 0:
            print '...reading %d th file...' % i
        vdisp_file = 'sig_files/log_grid_spl_idx_fft_vdisp_out_fine_full_%d.txt' % (
            i)
        for line in open(vdisp_file, 'r'):
            nline += 1
        #		if i%100 ==0:
        #			print '...number of lines : %d...'%nline
        vdisp_data = zeros((nline, 3), 'float64')
        count = 0
        for line in open(vdisp_file, 'r'):
            if (line.find('#') == -1):
                vdisp_data[count] = line.split()
                count += 1
        gal_idx = vdisp_data[:, 0]
        vdisp_norm = vdisp_data[:, 1]
        vdisp_raw = vdisp_data[:, 2]
        idxs = i * np
        idxf = (i + 1) * np - 1
        if idxf > ngam * nrani * nbin * nbout:
            idxf = ngam * nrani * nbin * nbout - 1
        # nfiles is the index of param file #
        nfiles = idxs / nsamp
        nfilef = idxf / nsamp
        iis = nfiles / ngam
        jjs = nfiles % ngam
        iif = nfilef / ngam
        jjf = nfilef % ngam
        idx_offset = idxs - nfiles * nsamp
        file = 'param/grid_gam%03drani%03d.dat' % (iis, jjs)
        data2 = zeros((nsamp, 8), 'float64')
        data = zeros((nsamp, 8), 'float64')
        count = 0
        for line in open(file, 'r'):
            if (line.find('#') == -1):
                data[count] = line.split()
                count += 1
        file2 = 'param/grid_gam%03drani%03d.dat' % (iif, jjf)
        data2 = zeros((nsamp, 8), 'float64')
        count = 0
        for line in open(file2, 'r'):
            if (line.find('#') == -1):
                data2[count] = line.split()
                count += 1
        if jjs != jjf:
            data = concatenate((data, data2), axis=0)
        Dd = data[:, 0] * 1000000.
        gamma = data[:, 1]
        kext = data[:, 2]
        theta_E = data[:, 3]
        mE = data[:, 4]
        mass = mE * (1. - kext)
        if iis == 0 and jjs == 0:
            print mE
        from scipy.special import gamma as gfunc
        rho = -mass * theta_E**(gamma - 3) * gfunc(
            gamma / 2.) * pi**(-1.5) / gfunc(0.5 * (gamma - 3))
        norm = 4. * pi * rho / (3. - gamma)

        #	        data = zeros((nsamp,8),'float64')
        #	        count = 0
        #	        for line in open(file,'r'):
        #      	        	if(line.find('#')==-1):
        #                      	data[count] = line.split()
        #                     	count += 1
        gal_idx = gal_idx.astype(int)
        gamma_idx = gal_idx / (nbout * nbin * nrani)
        rani_idx = (gal_idx / (nbout * nbin)) % nrani
        bin_idx = (gal_idx / nbout) % nbin
        bout_idx = gal_idx % nbout
        # data grid is guaranteed to be positive #
        # check what's happening with interpolation #
        for m in range(nline):
            #data_grid[gamma_idx[m],rani_idx[m],bin_idx[m],bout_idx[m]] = (vdisp_raw[m])**2./norm[idx_offset+m]/(asec_to_rad*Dd[idx_offset+m])
            data_grid[gamma_idx[m], rani_idx[m], bin_idx[m],
                      bout_idx[m]] = (vdisp_norm[m])**2. / norm[
                          idx_offset + m] * (Dd[idx_offset + m])
    print 'data grid created'
    import ndinterp
    from scipy import interpolate
    axes = {}
    axes[0] = interpolate.splrep(gamma_arr, arange(ngam), k=3, s=0)
    axes[1] = interpolate.splrep(rani_arr, arange(nrani), k=3, s=0)
    axes[2] = interpolate.splrep(bin_arr, arange(nbin), k=3, s=0)
    axes[3] = interpolate.splrep(bout_arr, arange(nbout), k=3, s=0)
    model = ndinterp.ndInterp(axes, data_grid)

    filesigv = 'filesigv_adriparam'
    import cPickle
    f = open(filesigv, 'wb')
    cPickle.dump(model, f, 2)
    f.close()
    print '1 grid interpolated and saved'

    model2 = interpolate.RegularGridInterpolator(
        (gamma_arr, rani_arr, bin_arr, bout_arr), data_grid, method='nearest')

    filesigv = 'filesigv_adriparam_reg_grid_norm_1115'
    import cPickle
    f = open(filesigv, 'wb')
    cPickle.dump(model2, f, 2)
    f.close()
    print '2 grid interpolated and saved'
    return
    numpy.random.seed(10)

    c = 8.39e-10
    Grav = 6.67408e-11 * (3.086e22)**-3. * 1.989e30 / (1.157e-5)**2.

    zl = 0.6304
    zs = 1.394

    reff = 0.58
    ######## number of beta_in and beta_out : each has 13 sample points in [-0.6,0.6] ########
    nbin = 13
    nbout = 13
    ######## number of samples in each parameter file ########
    nsamp = nbin * nbout
    ######## for grid creation, pick a single value ########
    Ddmax = 2100
    Ddmin = 700
    Dd_samp = numpy.random.random(nsamp) * (Ddmax - Ddmin) + Ddmin

    DdsDsmax = 0.70
    DdsDsmin = 0.30
    DdsDs_samp = numpy.random.random(nsamp) * (DdsDsmax - DdsDsmin) + DdsDsmin

    SigCrit_samp = c**2. / (4. * pi * Grav * Dd_samp * DdsDs_samp)
    #	SigCrit = c**2./(4.*pi*Grav*Dd*DdsDs)

    thE_samp = [0.826 for i in range(nsamp)]
    #	thE = 0.826

    mE_samp = SigCrit_samp * pi * thE_samp * thE_samp * Dd_samp * Dd_samp * asec_to_rad * asec_to_rad
    #	mE = SigCrit * pi * thE * thE * Dd * Dd * asec_to_rad * asec_to_rad
    # number of desired gamma / rani for the grid #
    ngam = 121
    nrani = 121
    count = 0
    kextfile = 'kextcounts_for_Inh_16-0623.dat'
    for line in open(kextfile, 'r'):
        count += 1
    kext = numpy.zeros(count)
    kext_samp = numpy.zeros(nsamp)
    m = 0
    for line in open(kextfile, 'r'):
        kext[m] = line
        m += 1

    gam_samp = numpy.linspace(1.01, 2.99, ngam)
    rani_samp = numpy.logspace(log10(0.5 * reff), log10(5 * reff), nrani)
    bi_samp = numpy.linspace(-0.6, 0.6, nbin)
    bo_samp = numpy.linspace(-0.6, 0.6, nbout)
    # give a random seed to numpy random so that one can reproduce the same results #
    for i2 in range(nsamp):
        idx = numpy.random.randint(low=0, high=m)
        kext_samp[i2] = kext[idx]
        mass_samp = (1 - kext_samp) * mE_samp
    for i1 in range(ngam):
        gam = gam_samp[i1]
        for j1 in range(nrani):
            rani = rani_samp[j1]
            paramfile = 'param/grid_gam%03drani%03d.dat' % (i1, j1)

            f = open(paramfile, 'w')
            f.write(
                "# Dd, gamma, kext, theta_E, m_E, rani, beta_in, beta_out\n")

            #	model_Inh = numpy.load('filesigv_Inh_100CF')
            for i3 in range(nbin):
                bin = bi_samp[i3]
                for j3 in range(nbout):
                    bout = bo_samp[j3]
                    idxp = i3 * nbout + j3
                    #	sig_ref = numpy.sqrt(2.)*sm.getSigmaFromGrid2(mass_samp,thE_samp, gam_samp, rani_samp, model_Inh, Dd_samp)
                    f.write("%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\n" %
                            (Dd_samp[idxp], gam, kext_samp[idxp],
                             thE_samp[idxp], mE_samp[idxp], rani, bin, bout))
            f.close()
Пример #9
0
def sersic_sb(rvals, lp_pars):
    # Sersic surface brightness profile, normalized to unit luminosity
    reff, nser = lp_pars
    L = reff**2 * 2 * np.pi * nser / sersic_bfunc(nser)**(2 * nser) * gfunc(
        2 * nser)
    return np.exp(-sersic_bfunc(nser) * (rvals / reff)**(1. / nser)) / L
Пример #10
0
def physField(uvec, rF2, lc, ax, ay):
    """ Returns an approximation of the field at the caustic, using the formula from Cooke 1982. """
    ux, uy = uvec
    alp = rF2*lc
    phi20, phi02 = ax**2/rF2 + lc*gauss20(ux, uy), ay**2/rF2 + lc*gauss02(ux, uy)
    phi11 = lc*gauss11(ux, uy)
    phi30 = lc*gauss30(ux, uy)
    phi21 = lc*gauss21(ux, uy)
    phi12 = lc*gauss12(ux, uy)
    phi03 = lc*gauss03(ux, uy)
    B = phi20**3*phi03 - 3*phi20**2*phi11*phi12 + 3*phi20*phi11**2*phi21 - phi11**3*phi30
    U = ax*ay/(2*pi*rF2) * exp(1j*(phi(uvec, rF2, lc, ax, ay) + 0.25*pi*np.sign(phi20))) * 2.**(5./6.) * pi**(1./3.) * gfunc(1./3.) * np.abs(phi20)**0.5/(3.**(1./6.) * np.abs(B)**(1./3.))
    return U
Пример #11
0
def M2d(R, nser, Re):
    return 2.*np.pi*Re**2*nser/b(nser)**(2.*nser)*gammainc(2*nser, b(nser)*(R/Re)**(1./nser))/L(nser, Re)*gfunc(2.*nser)
Пример #12
0
def L(nser, Re):
    return Re**2*2*np.pi*nser/b(nser)**(2*nser)*gfunc(2*nser)