Esempio n. 1
0
 def calculate_J(self, gp):
     if len(self.profs)>0:
         for i in range(len(self.profs)):
             Sigprof = gip.rho_INT_Sig(gp.xepol, self.profs[i].get_prof('rho', 0), gp)
             Jprof = gip.Jpar(gp.xepol, Sigprof, gp)
             # add 3 extension bins
             tck = splrep(np.log(gp.xepol[:-gp.nexp]), np.log(Jprof), k=1, s=0.1)
             Jext = np.exp(splev(np.log(gp.xepol[-gp.nexp:]), tck))
             Jfull = np.hstack([Jprof, Jext])
             for k in range(gp.nepol):
                 Jfull[k] = max(0, Jfull[k])
             self.profs[i].set_prof('J', Jfull, 0, gp)
     else:
         gh.LOG(1, 'len(self.profs) == 0, did not calculate self.profs.J')
Esempio n. 2
0
def Sig_walk(rad, gp, mf1=1, mf2=1):
    rhodm, rhostar1, rhostar2 = rho_walk(rad, gp, mf1, mf2)  # 3* [msun/pc^3]
    Sig_star1 = gip.rho_INT_Sig(rad, rhostar1, gp)  # [msun/pc^2]
    Sig_star2 = gip.rho_INT_Sig(rad, rhostar2, gp)  # [msun/pc^2]
    return Sig_star1 + Sig_star2, Sig_star1, Sig_star2  # 3* [msun/pc^2]
Esempio n. 3
0
def Sig_gaia(rad, gp):
    rhodm, rhostar1 = rho_gaia(rad, gp)
    Sigdm = gip.rho_INT_Sig(rad, rhodm, gp)
    Sigstar = gip.rho_INT_Sig(rad, rhostar1, gp)
    return Sigdm, Sigstar
Esempio n. 4
0
def run(gp):
    Rscale = []; Dens0Rscale = []; Dens0pc = []; Totmass_Tracers = []
    rscale = []; dens0Rscale = []; dens0pc = []; totmass_tracers = []

    for pop in range(3):
        A = np.loadtxt(gp.files.get_scale_file(pop), unpack=False, skiprows=1)
        Rscale.append(A[0])
        Dens0Rscale.append(A[1])
        Dens0pc.append(A[2])
        Totmass_Tracers.append(A[3])

        B = np.loadtxt(gp.files.get_scale_file(pop)+'_3D', unpack=False, skiprows=1)
        rscale.append(B[0])
        dens0Rscale.append(B[1])
        dens0pc.append(B[2])
        totmass_tracers.append(B[3])

        print('#######  working on component ',pop)
        print('input: ',gp.files.get_com_file(pop)+'_3D')
        # start from data centered on COM already:
        if gfile.bufcount(gp.files.get_com_file(pop)+'_3D')<2: continue



        Rbin,Binmin,Binmax,Dens,Denserr = np.loadtxt(gp.files.Sigfiles[pop],\
                                                     skiprows=1,usecols=(0,1,2,3,4),\
                                                     unpack=True) # 3*[Rscale], [km/s]
        Rbin*=Rscale[pop]; Binmin*=Rscale[pop]; Binmax*=Rscale[pop]; Dens*=Dens0pc[pop]; Denserr*=Dens0pc[pop]



        rbin,binmin,binmax,dens,denserr = np.loadtxt(gp.files.Sigfiles[pop]+'_3D',\
                                                     skiprows=1,usecols=(0,1,2,3,4),\
                                                     unpack=True) # 3*[Rscale], [km/s]
        rbin*=rscale[pop]; binmin*=rscale[pop]; binmax*=rscale[pop]; dens*=dens0pc[pop]; denserr*=dens0pc[pop]


        ion()
        f=figure(figsize=(6,3))
        ax1 = f.add_subplot(121)                         # Sig
        ax2 = f.add_subplot(122, sharex=ax1)             # nu

        ax1.plot(Rbin, Dens,'b',lw=1)
        lbound = Dens-Denserr; lbound[lbound<1e-6] = 1e-6
        ubound = Dens+Denserr;
        ax1.fill_between(Rbin,lbound,ubound,alpha=0.5,color='r')
        ax1.set_yscale('log')
        ax1.set_xlim([0,np.max(Binmax)])
        ax1.set_ylim([np.min(lbound),np.max(ubound)])
        ax1.set_xlabel(r'$R [R_c]$')
        ax1.set_ylabel(r'$\nu_{2D}(R)/\nu_{2D}(0)$')

        try:
            ax1.plot(Rbin, gip.rho_INT_Sig(Rbin, dens, denserr, gp))
            ax1.plot(Rbin, gip.rho_INT_Sig(Rbin, Sig_INT_rho(Rbin,Dens,Denserr),denserr, gp))
        except Exception as detail:
            print('rho_INT_Sig giving NaN in plotting')
        draw()


        ax2.plot(rbin, dens,'b',lw=1)
        lbound = dens-denserr; lbound[lbound<1e-6] = 1e-6
        ubound = dens+denserr;
        ax2.fill_between(rbin,lbound,ubound,alpha=0.5,color='r')

        ax2.set_yscale('log')
        ax2.set_xlim([0,np.max(binmax)])
        ax2.set_ylim([np.min(lbound),np.max(ubound)])
        ax2.set_xlabel(r'$r [R_c]$')
        ax2.set_ylabel(r'$\nu(r)/\nu(0)$')
        ax2.yaxis.tick_right()
        ax2.yaxis.set_label_position("right")
        draw()

        # projSig = rho_INT_Sig(rbin, dens)
        # projSig = test(rbin, binmin, binmax, dens)
        # ax1.plot(rbin, projSig)

        ax2.plot(rbin, gip.Sig_INT_rho(Rbin,Dens,Denserr),color='green')
        draw()

        ioff(); show()
Esempio n. 5
0
 def set_analytic(self, x0, gp):
     r0 = x0 # [pc], spherical case
     self.analytic.x0 = r0
     anbeta = []; annu = [];  anSig = []
     if gp.investigate == 'gaia':
         anrho = ga.rho_gaia(r0, gp)[0]
         anM = gip.rho_SUM_Mr(r0, anrho)
         annr = ga.nr3Dtot_gaia(r0, gp)
         tmp_annu = ga.rho_gaia(r0, gp)[1]
         annu.append( tmp_annu )
         anSig.append( gip.rho_INT_Sig(r0, tmp_annu, gp) )
         for pop in np.arange(1, gp.pops+1):
             beta = ga.beta_gaia(r0, gp)[pop]
             anbeta.append(beta)
             nu = ga.rho_gaia(r0,gp)[pop]
             annu.append(nu)
             anSig.append(gip.rho_INT_Sig(r0, nu, gp))
     elif gp.investigate == 'walk':
         anrho = ga.rho_walk(r0, gp)[0]
         anM = gip.rho_SUM_Mr(r0, anrho)
         annr = ga.nr3Dtot_deriv_walk(r0, gp) # TODO too high in case of core
         tmp_annu = ga.rho_walk(r0, gp)[1]
         annu.append( tmp_annu )
         anSig.append( gip.rho_INT_Sig(r0, tmp_annu, gp) )
         for pop in np.arange(1, gp.pops+1):
             beta = ga.beta_walk(r0, gp)[pop]
             anbeta.append(beta)
             nu = ga.rho_walk(r0, gp)[pop]
             dum,dum,dum,nudat,nuerr = np.transpose(np.loadtxt(gp.files.nufiles[pop], unpack=False, skiprows=1))
             locrhalf = np.argmin(abs(gp.xipol-gp.Xscale[pop]))
             nuhalf = nudat[locrhalf]*gp.nu0pc[pop]
             annuhalf = nu[np.argmin(abs(r0-locrhalf))]
             annu.append(nu*nuhalf/annuhalf)
             dum,dum,dum,Sigdat,Sigerr = np.transpose(np.loadtxt(gp.files.Sigfiles[pop], unpack=False, skiprows=1))
             locrhalf = np.argmin(abs(gp.xipol-gp.Xscale[pop]))
             Sighalf = Sigdat[locrhalf]*gp.Sig0pc[pop]
             Sig = gip.rho_INT_Sig(r0, nu, gp)
             anSighalf = Sig[np.argmin(abs(r0-locrhalf))]
             anSig.append(Sig*Sighalf/anSighalf)
     elif gp.investigate == 'triax':
         anrho = ga.rho_triax(r0, gp) # one and only
         anM = gip.rho_SUM_Mr(r0, anrho)
         annr = ga.nr3Dtot_deriv_triax(r0, gp)
         tmp_annu = ga.rho_triax(r0, gp) # TODO, M/L=1 assumed here, wrong
         annu.append(tmp_annu)
         anSig.append( gip.rho_INT_Sig(r0, tmp_annu, gp))
         for pop in np.arange(1, gp.pops+1):
             beta = ga.beta_triax(r0)
             anbeta.append(beta)
             nu = ga.rho_triax(r0, gp) # TODO, assumes M/L=1
             annu.append(nu)
             anSig.append( gip.rho_INT_Sig(r0, nu, gp))
     self.analytic.set_prof('rho', anrho, 0, gp)
     self.analytic.set_prof('M', anM, 0, gp)
     self.analytic.set_prof('nr', annr, 0, gp)
     self.analytic.set_prof('nu', annu[0], 0, gp)
     self.analytic.set_prof('nrnu', -gh.derivipol(np.log(annu[0]), np.log(r0)), 0, gp)
     self.analytic.set_prof('Sig', anSig[0], 0, gp)
     for pop in np.arange(1, gp.pops+1):
         self.analytic.set_prof('beta', anbeta[pop-1], pop, gp)
         self.analytic.set_prof('betastar', anbeta[pop-1]/(2.-anbeta[pop-1]), pop, gp)
         self.analytic.set_prof('nu', annu[pop], pop, gp)
         nrnu = -gh.derivipol(np.log(annu[pop]), np.log(r0))
         self.analytic.set_prof('nrnu', nrnu, pop, gp)
         self.analytic.set_prof('Sig', anSig[pop] , pop, gp)#/ Signorm, pop, gp)
         self.analytic.set_prof('sig', -np.ones(len(r0)), pop, gp)
     return
Esempio n. 6
0
def run(gp):
    Rscale = []
    Dens0Rscale = []
    Dens0pc = []
    Totmass_Tracers = []
    rscale = []
    dens0Rscale = []
    dens0pc = []
    totmass_tracers = []

    for pop in range(3):
        A = np.loadtxt(gp.files.get_scale_file(pop), unpack=False, skiprows=1)
        Rscale.append(A[0])
        Dens0Rscale.append(A[1])
        Dens0pc.append(A[2])
        Totmass_Tracers.append(A[3])

        B = np.loadtxt(gp.files.get_scale_file(pop) + '_3D',
                       unpack=False,
                       skiprows=1)
        rscale.append(B[0])
        dens0Rscale.append(B[1])
        dens0pc.append(B[2])
        totmass_tracers.append(B[3])

        print('#######  working on component ', pop)
        print('input: ', gp.files.get_com_file(pop) + '_3D')
        # start from data centered on COM already:
        if gfile.bufcount(gp.files.get_com_file(pop) + '_3D') < 2: continue



        Rbin,Binmin,Binmax,Dens,Denserr = np.loadtxt(gp.files.Sigfiles[pop],\
                                                     skiprows=1,usecols=(0,1,2,3,4),\
                                                     unpack=True) # 3*[Rscale], [km/s]
        Rbin *= Rscale[pop]
        Binmin *= Rscale[pop]
        Binmax *= Rscale[pop]
        Dens *= Dens0pc[pop]
        Denserr *= Dens0pc[pop]



        rbin,binmin,binmax,dens,denserr = np.loadtxt(gp.files.Sigfiles[pop]+'_3D',\
                                                     skiprows=1,usecols=(0,1,2,3,4),\
                                                     unpack=True) # 3*[Rscale], [km/s]
        rbin *= rscale[pop]
        binmin *= rscale[pop]
        binmax *= rscale[pop]
        dens *= dens0pc[pop]
        denserr *= dens0pc[pop]

        ion()
        f = figure(figsize=(6, 3))
        ax1 = f.add_subplot(121)  # Sig
        ax2 = f.add_subplot(122, sharex=ax1)  # nu

        ax1.plot(Rbin, Dens, 'b', lw=1)
        lbound = Dens - Denserr
        lbound[lbound < 1e-6] = 1e-6
        ubound = Dens + Denserr
        ax1.fill_between(Rbin, lbound, ubound, alpha=0.5, color='r')
        ax1.set_yscale('log')
        ax1.set_xlim([0, np.max(Binmax)])
        ax1.set_ylim([np.min(lbound), np.max(ubound)])
        ax1.set_xlabel(r'$R [R_c]$')
        ax1.set_ylabel(r'$\nu_{2D}(R)/\nu_{2D}(0)$')

        try:
            ax1.plot(Rbin, gip.rho_INT_Sig(Rbin, dens, denserr, gp))
            ax1.plot(
                Rbin,
                gip.rho_INT_Sig(Rbin, Sig_INT_rho(Rbin, Dens, Denserr),
                                denserr, gp))
        except Exception as detail:
            print('rho_INT_Sig giving NaN in plotting')
        draw()

        ax2.plot(rbin, dens, 'b', lw=1)
        lbound = dens - denserr
        lbound[lbound < 1e-6] = 1e-6
        ubound = dens + denserr
        ax2.fill_between(rbin, lbound, ubound, alpha=0.5, color='r')

        ax2.set_yscale('log')
        ax2.set_xlim([0, np.max(binmax)])
        ax2.set_ylim([np.min(lbound), np.max(ubound)])
        ax2.set_xlabel(r'$r [R_c]$')
        ax2.set_ylabel(r'$\nu(r)/\nu(0)$')
        ax2.yaxis.tick_right()
        ax2.yaxis.set_label_position("right")
        draw()

        # projSig = rho_INT_Sig(rbin, dens)
        # projSig = test(rbin, binmin, binmax, dens)
        # ax1.plot(rbin, projSig)

        ax2.plot(rbin, gip.Sig_INT_rho(Rbin, Dens, Denserr), color='green')
        draw()

        ioff()
        show()
Esempio n. 7
0
def Sig_walk(rad, gp, mf1=1, mf2=1):
    rhodm, rhostar1, rhostar2 = rho_walk(rad, gp, mf1, mf2)     # 3* [msun/pc^3]
    Sig_star1 = gip.rho_INT_Sig(rad, rhostar1, gp) # [msun/pc^2]
    Sig_star2 = gip.rho_INT_Sig(rad, rhostar2, gp) # [msun/pc^2]
    return Sig_star1+Sig_star2, Sig_star1, Sig_star2               # 3* [msun/pc^2]
Esempio n. 8
0
def Sig_gaia(rad, gp):
    rhodm, rhostar1 = rho_gaia(rad, gp)
    Sigdm = gip.rho_INT_Sig(rad, rhodm, gp)
    Sigstar = gip.rho_INT_Sig(rad, rhostar1, gp)
    return Sigdm, Sigstar
Esempio n. 9
0
sigl2s = np.zeros(len(rfine)-gp.nexp)
for i in range(len(rfine)-gp.nexp): # get sig_los^2
    xnew = np.sqrt(rfine[i:]**2-rfine[i]**2)             # [pc]
    ynew = 2.*(1-betanu[i]*(rfine[i]**2)/(rfine[i:]**2))
    ynew *= nunu[i:] * sigr2nu[i:]
    gh.checkpositive(ynew, 'ynew in sigl2s') # is hit several times..
    # check sigr2nu: has too many entries of inf!

    # stop integration at xnew[-1] instead of at np.inf
    # to circumvent inf when nunu has increase at fudge radii
    sigl2s[i] = gh.quadinflog(xnew, ynew, 0, gp.rinfty*xnew[-1], False)
# for last 3 bins, we are up to a factor 2 off
gh.checkpositive(sigl2s, 'sigl2s')

# calculate surface density on the same rfine as the sigl2s
surfden = gip.rho_INT_Sig(rfine, nunu, gp)
siglos = np.sqrt(sigl2s/surfden[:-gp.nexp])

elapsed_time = time.time() - start_time
print("elapsed time: "+str(elapsed_time))

surfdenanf = ga.Sig_hern(rfine, 1, 1/MtoL)
rfine = rfine[:-gp.nexp]
siglanf = ga.sig_los_hern(rfine, 1, 1, G1)

plot(rfine, siglanf, 'b.-')
xscale('log')
plot(rfine, siglos, 'r.-')
pdb.set_trace()