Exemplo n.º 1
0
def compare_nu(pop, dat, err):
    # pop \in {1,2} gives population
    # if dat == True: return data; else: model (possibly projected)
    # if err == True: return data error instead
    if (not dat) and err:
        print('wrong use of compare_nu, error only given for data, not model')
        exit(1)
    ret = []
    if dat:
        if gp.geom == 'disc':
            ret = gp.ipol.nudat1 if pop == 1 else gp.dat.nudat2
            if err:
                ret = gp.ipol.nuerr1 if pop == 1 else gp.ipol.nuerr2
        elif gp.geom == 'sphere':
            ret = gp.ipol.nudat1_2D if pop == 1 else gp.dat.nudat2_2D
            if err:
                ret = gp.ipol.nuerr1_2D if pop == 1 else gp.ipol.nuerr2_2D
    else:                               # [model]
        if gp.geom == 'disc':
            ret = gp.ipol.nudat1 if pop == 1 else gp.ipol.nudat2
            if err:
                ret = gp.ipol.nuerr1 if pop == 1 else gp.ipol.nuerr2
        elif gp.geom == 'sphere':
            ret = rho_INT_Rho(gp.xipol,gp.ipol.nudat1) if pop == 1 else\
               rho_Int_Rho(gp.ipol.nudat2)
            if err:
                # TODO: does that make sense? what do we want to compare to here?
                ret = rho_INT_Rho(gp.xipol,gp.ipol.nuerr1) if pop == 1 else\
                   rho_Int_Rho(gp.ipol.nuerr2)
    return ret
Exemplo n.º 2
0
def plot_analytic(r0, prof, pop=0):
    if gp.investigate == 'gaia':
        if prof=="rho":
            analytic = ga.rhogaiatot_3D(r0)
        elif prof=="nr":
            analytic = ga.nrgaiatot_3D(r0)
        elif prof=="beta":
            analytic = ga.betagaia(r0)
        elif prof=="betastar":
            b = ga.betagaia(r0)
            analytic = b/(2.-b)
        elif prof=="nu":
            analytic_3D = ga.nugaiatot_3D(r0)
            analytic = rho_INT_Rho(r0, analytic_3D)
        elif prof=="sig":
            analytic = 0.*r0 # TODO
    elif gp.investigate == 'walk':
        if prof=='rho':
            analytic = ga.rhowalk_3D(r0)[pop]
        elif prof=='nr':
            analytic = ga.rhowalk_3D(r0)[pop] # TODO
        elif prof=='beta':
            analytic = ga.walker_delta(pop, r0) # TODO
        elif prof=='betastar':                  # TODO
            b = ga.walker_delta(pop, r0)
            analytic = b/(2.-b)
        elif prof=='nu':                # TODO: mass ratio M_tracer/M_DM
            pdb.set_trace()
            analytic_3D = ga.rhowalk_3D(r0)[pop]
            analytic = rho_INT_Rho(r0, analytic_3D)
        elif prof=='sig':
            analytic = 0.*r0            # TODO
    gpl.plot(r0, analytic, 'b')
    return analytic
Exemplo n.º 3
0
def Rhowalk(rad):
    rhodm, rhostar1, rhostar2 = rhowalk(rad)     # 3* [msun/pc^3]

    surfdm    = rho_INT_Rho(rad, rhodm)    # [msun/pc^2]
    surfstar1 = rho_INT_Rho(rad, rhostar1) # [msun/pc^2]
    surfstar2 = rho_INT_Rho(rad, rhostar2) # [msun/pc^2]

    return surfdm, surfstar1, surfstar2               # 3* [msun/pc^2]
Exemplo n.º 4
0
def sig_kap_los(dens_r, nu_r, beta_r):
    r0 = gp.xipol[:]

    # TODO: fix spline warnings
    surfden = rho_INT_Rho(r0, nu_r)  # or INTIPOL
    # takes [pc], [munit/pc^3], gives back [munit/pc^2]
    # gpl.start()
    # pdb.set_trace()
    # gpl.plot(r0, surfden,'red')
    # gpl.plot(r0, Sigma_anf(r0))

    # Calculate density and M force:
    intbeta = ant_intbeta(r0, beta_r)  # [1]
    # TODO:pdb.set_trace() get splines correctly
    siglos2surf, kaplos4surf = ant_sigkaplos2surf(r0, beta_r, intbeta, dens_r, nu_r)
    # takes [pc], [1*pc], [munit], [munit/pc^3], gives back [(km/s)^2], [1]

    siglos2 = siglos2surf / surfden  # [(km/s)^2]
    siglos = np.sqrt(siglos2)  # [km/s]

    # gpl.start(); pdb.set_trace()
    # gpl.plot(r0,sig_los_anf(r0),lw=2)

    if gp.usekappa:
        kaplos4 = kaplos4surf / surfden
        # takes [munit/pc^2 (km/s)^2], gives back [(km/s)^2]

        kaplos = kaplos4 / (siglos2 ** 2)
        # - 3.0 # subtract 3.0 for Gaussian distribution in Fisher version.
    else:
        kaplos = 3.0 * np.ones(len(siglos))

    return siglos, kaplos  # [km/s], [1]
Exemplo n.º 5
0
def calc_chi2():
    numodel1 = rho_INT_Rho(gp.xipol,gp.nu1_x) if gp.geom=='sphere' else gp.nu1_x
    nudata1  = compare_nu(1,True,False)
    nuerr1   = compare_nu(1,True,True)

    gp.chi2t_nu1      = chi2red(numodel1, nudata1, nuerr1, gp.dof)
    gp.chi2t_nu       = gp.chi2t_nu1
    if gp.analytic:
        gp.chi2t_sig1     = chi2red(gp.sig1_x,rho_anf(gp.xipol),\
                                    gp.ipol.sigerr1,gp.dof)
        gp.chi2t_kap1     = chi2red(gp.kap1_x,gp.ipol.kapdat1,\
                                    gp.ipol.kaperr1,gp.dof)
    else:
        gp.chi2t_sig1     = chi2red(gp.sig1_x,gp.ipol.sigdat1,\
                                    gp.ipol.sigerr1,gp.dof)
        gp.chi2t_kap1     = chi2red(gp.kap1_x,gp.ipol.kapdat1,\
                                    gp.ipol.kaperr1,gp.dof)
    gp.chi2t_sig      = gp.chi2t_sig1
    gp.chi2t_kap      = gp.chi2t_kap1

    if not gp.deltaprior and gp.uselike:
        sig_Rz = phys.sigma_rz(gp.xipol, gp.xipol, gp.parst.delta1)
        prob_t = prob_t + np.sum((sig_Rz - sigRz_dat)**2./sigRz_dat_err**2.)

    gp.chi2t1         = gp.chi2t_nu1 + gp.chi2t_sig1 # + gp.chi2t_kap1 # TODO
    gp.chi2t          = gp.chi2t1
    if gp.pops == 2:
        numodel2 = rho_INT_Rho(gp.xipol,gp.nu2_x) if gp.geom=='sphere' \
          else gp.nu2_x
        nudata2  = compare_nu(2,True,False)
        nuerr2   = compare_nu(2,True,True)
        gp.chi2t_nu2  = chi2red(numodel2, nudata2, nuerr2, gp.dof)
        gp.chi2t_nu  += gp.chi2t_nu2
        gp.chi2t_sig2 = chi2red(gp.sig2_x, gp.ipol.sigdat2,\
                                gp.ipol.sigerr2,gp.dof)
        gp.chi2t_sig += gp.chi2t_sig2
        gp.chi2t_kap2 = chi2red(gp.kap2_x, gp.ipol.kapdat2,\
                                gp.ipol.kaperr2,gp.dof)
        gp.chi2t_kap += gp.chi2t_kap2
        gp.chi2t2     = gp.chi2t_nu2 + gp.chi2t_sig2 # + gp.chi2t_kap2 # TODO
        gp.chi2t     += gp.chi2t2

    gh.checknan(gp.chi2t)

    gp.fnewoverf = np.exp(gp.chi2/2.0-gp.chi2t/2.0)
    gh.checknan(gp.fnewoverf)
    return gp.fnewoverf
Exemplo n.º 6
0
def compare_nu(pop, dat, err):
    # if dat == True: return data; else: model (possibly projected)
    # if err == True: return data error instead
    if (not dat) and err:
        print('wrong use of compare_nu, error only given for data, not model')
        exit(1)
    ret = []
    if dat:
        if gp.geom == 'sphere':
            ret = gp.dat.Nudat[pop]  # [Msun/pc^2]
            if err:
                ret = gp.dat.Nuerr[pop] # [Msun/pc^2]
    else:                                  # [model]
        if gp.geom == 'sphere':
            print('TODO: calculating stupid thing?')
            ret = rho_INT_Rho(gp.xipol, gp.dat.nudat[pop]) # [Msun/pc^2]
    return ret                                             # [Msun/pc^2]
Exemplo n.º 7
0
def physical(r0, prof, pop, tmp_rho, tmp_nu, tmp_beta):
    if prof == "rho":
        tmp_prof = phys.rho(r0, tmp_rho)
    elif prof == 'nr':
        tmp_prof = tmp_rho[1:]
    elif prof == "nu":
        tmp_prof = rho_INT_Rho(r0, phys.rho(r0, tmp_nu))
    elif prof == "betastar":
        tmp_prof = phys.mapping_beta_star_poly(r0, tmp_beta)
    elif prof == "beta":
        tmp_prof = phys.beta(r0, tmp_beta)
    elif prof == "sig":
        tmp_sig, tmp_kap = phys.sig_kap_los(r0, pop, tmp_rho, tmp_nu, tmp_beta)
        tmp_prof = tmp_sig
    elif prof == "kap":
        tmp_sig, tmp_kap = phys.sig_kap_los(r0, pop, tmp_rho, tmp_nu, tmp_beta)
        tmp_prof = tmp_kap
    return tmp_prof
Exemplo n.º 8
0
print('input: ', basename)
M = np.loadtxt(basename+'prof'+prof+str(pop),skiprows=0,unpack=False)
print('len (M) = ',len(M))

radii = M[0]
profs = M[1:]                           # all saved profiles
#profs = M[-10:]
#profs = M[-10000::10] # only the last 1e5 profiles, thinned by 10

Mprofbins = np.transpose(profs)
newMprofbins = gh.sort_profiles_binwise(Mprofbins)

Mmin, M95lo, M68lo, Mmedi, M68hi, M95hi, Mmax = gh.get_median_1_2_sig(newMprofbins)

if prof == 'nu':
    Mmax=rho_INT_Rho(radii, Mmax)
    M95hi=rho_INT_Rho(radii, M95hi)
    M68hi=rho_INT_Rho(radii, M68hi)
    Mmedi=rho_INT_Rho(radii, Mmedi)
    M68lo=rho_INT_Rho(radii, M68lo)
    M95lo=rho_INT_Rho(radii, M95lo)
    Mmin=rho_INT_Rho(radii, Mmin)

# def extralast(rad, prof):
#     tck = splrep(rad[:-1],np.log(prof[:-1]),k=2,s=0.1)
#     prof = np.hstack([prof[:-1],np.exp(splev(rad[-1],tck))])
#     return prof

# M95hi = extralast(radii,M95hi)
# M68hi = extralast(radii,M68hi)
# Mmedi = extralast(radii,Mmedi)