コード例 #1
0
def CRerdistestinput(subdict):
    startno=subdict['startno']
    Nsnap=subdict['Nsnap']
    snapsep=subdict['snapsep']
    wanted=subdict['wanted']
    dirneed=subdict['dirneed']
    fmeat=subdict['fmeat']
    dirdict = collections.defaultdict(dict)
    keylist = np.array([])
    for ir, runtodo in enumerate(dirneed):
        keylist=np.append(keylist,keystore[ir])
        dirdict[keystore[ir]]=[runtodo]
    noplots=len(dirdict.keys())
    print 'noplots', noplots
    fig, ax = PS.setupfig(nrows=noplots, ncols=1,sharex=True,sharey=False)

    for i, key in enumerate(keylist):
        items=dirdict[key]
        for j, runtodo in enumerate(items):
            ssdict = collections.defaultdict(dict)
            ssdict = subdict
            ssdict['runtodo'] = runtodo
            print 'runtodo', runtodo
            plotdict = CR_r_energy_distribution(ssdict)
            xlab = plotdict[wanted]['xlab'];
            ylab = plotdict[wanted]['ylab'];
            ptitle = plotdict[wanted]['ptitle']
            filename = plotdict[wanted]['filename'];
            print 'filename', filename
            for k,inkey in enumerate(plotdict[wanted]['xnl']):
                xnl = plotdict[wanted]['xnl'][inkey];
                ynl = plotdict[wanted]['ynl'][inkey];
                labelneed = plotdict[wanted]['labelneed'];
                color = plotdict[wanted]['color'];
                lsn = plotdict[wanted]['lsn'][inkey];
                lw = plotdict[wanted]['lw'][inkey];
                marker = plotdict[wanted]['marker'][inkey];
                linelabel = plotdict[wanted]['linelab'][inkey];
                legendneed = 1
                if i==noplots-1 and j==0: 
                    label = linelabel
                else:
                    label = '_nolegend_' 
                if noplots==1:
                    ax.plot(xnl,ynl,label=label,lw=lw,ls=lsn,color=color,marker=marker)
                else:
                    ax[i].plot(xnl,ynl,label=label,lw=lw,ls=lsn,color=color,marker=marker)
        if i<noplots-1: xlab=''
        if noplots==1:
            ax.text(0.25, 0.1, ptitle, horizontalalignment='center',
            verticalalignment='center', transform=ax.transAxes,fontsize=22)            
        else:
            ax[i].text(0.25, 0.1, ptitle, horizontalalignment='center',
            verticalalignment='center', transform=ax[i].transAxes,fontsize=22)
        if noplots==1:
            PS.miscsetup(ax,logx=0,logy=1,xlab=xlab,ylab=ylab,legendneed=legendneed,labfs=22,legfs=12)
        else:
            PS.miscsetup(ax[i],logx=0,logy=1,xlab=xlab,ylab=ylab,legendneed=legendneed,labfs=22,legfs=12)        
    PS.finishsave(plt,filename)
    return None
コード例 #2
0
def kslawtestinput(subdict):
    startno = subdict['startno']
    Nsnap = subdict['Nsnap']
    snapsep = subdict['snapsep']
    wanted = subdict['wanted']
    dirneed = subdict['dirneed']
    fmeat = subdict['fmeat']
    dirdict = collections.defaultdict(dict)
    keylist = np.array([])
    noplots = 1
    fig, ax = PS.setupfig(nrows=noplots, ncols=1, sharex=True, sharey=False)
    for j, runtodo in enumerate(dirneed):
        ssdict = collections.defaultdict(dict)
        ssdict = subdict
        ssdict['runtodo'] = runtodo
        print 'runtodo', runtodo
        plotdict = kslaw(ssdict)
        xlab = plotdict[wanted]['xlab']
        ylab = plotdict[wanted]['ylab']
        ptitle = plotdict[wanted]['ptitle']
        filename = plotdict[wanted]['filename']
        xnl = plotdict[wanted]['xnl']
        ynl = plotdict[wanted]['ynl']
        labelneed = plotdict[wanted]['labelneed']
        color = plotdict[wanted]['color']
        lsn = plotdict[wanted]['lsn']
        lw = plotdict[wanted]['lw']
        marker = plotdict[wanted]['marker']
        legendneed = 1
        ax.plot(xnl,
                ynl,
                label=labelneed,
                lw=lw,
                ls=lsn,
                color=color,
                marker=marker,
                alpha=0.7)
    PS.miscsetup(ax,
                 logx=1,
                 logy=1,
                 xlab=xlab,
                 ylab=ylab,
                 legendneed=0,
                 labfs=22,
                 legfs=12)
    PS.finishsave(plt, filename)
    return None
コード例 #3
0
def doplot(plotdict, plotneed, markerl, colorl, labell, neederr=0):
    fig, ax = PS.setupfig()
    xnl = plotdict[plotneed]['xnl']
    ynl = plotdict[plotneed]['ynl']
    xlab = plotdict[plotneed]['xlab']
    ylab = plotdict[plotneed]['ylab']
    selectl = plotdict[plotneed]['selectl']
    filename = plotdict[plotneed]['filename']
    if neederr == 1 and (plotneed == 'mlmv' or plotneed == 'mlms'):
        yld = plotdict[plotneed]['yld']
        ylu = plotdict[plotneed]['ylu']
    for i in range(len(labell)):
        if neederr == 1 and (plotneed == 'mlmv' or plotneed == 'mlms'):
            ax.errorbar(xnl[selectl == i],
                        ynl[selectl == i],
                        yerr=[yld[selectl == i], ylu[selectl == i]],
                        color=colorl[i],
                        fmt=markerl[i],
                        markersize=7,
                        label=labell[i])
        else:

            ax.plot(xnl[selectl == i],
                    ynl[selectl == i],
                    marker=markerl[i],
                    ls='none',
                    color=colorl[i],
                    label=labell[i])
    PS.miscsetup(ax,
                 logx=1,
                 logy=1,
                 xlab=xlab,
                 ylab=ylab,
                 legendneed=1,
                 labfs=22,
                 legfs=12)
    PS.finishsave(plt, filename)
コード例 #4
0
def gasdenThistestinput(subdict):
    startno=subdict['startno']
    Nsnap=subdict['Nsnap']
    snapsep=subdict['snapsep']
    wanted=subdict['wanted']
    dirneed=np.array(subdict['dirneed'])
    fmeat=subdict['fmeat']
    title=subdict['title']
    dirdict = collections.defaultdict(dict)
    keylist = np.array([])
    for ir, subdirneed in enumerate(dirneed):
        keylist=np.append(keylist,keystore[ir])
        if dirneed.ndim>1:
            dirdict[keystore[ir]]=subdirneed
        else:
            dirdict[keystore[ir]]=[subdirneed]
    if dirneed.ndim>1:
        noplots=len(keylist)
    else:
        noplots=1
    print 'noplots', noplots
    fig, ax = PS.setupfig(nrows=noplots, ncols=1,sharex=True,sharey=False)
    linelablist=[]
    lxlist=[]
    for i, key in enumerate(keylist):
        items=dirdict[key]
        for j, runtodo in enumerate(items):
            ssdict = collections.defaultdict(dict)
            ssdict = subdict
            ssdict['runtodo'] = runtodo
            print 'runtodo', runtodo
            if dirneed.ndim>1: 
                ssdict['fmeat']=fmeat[-1]
                ssdict['title']=title[i]
            plotdict = gasdenThis_out(ssdict)
            xlab = plotdict[wanted]['xlab'];
            ylab = plotdict[wanted]['ylab'];
            ptitle = plotdict[wanted]['ptitle']
            filename = plotdict[wanted]['filename'];
            for k,inkey in enumerate(plotdict[wanted]['xnl']):
                xnl = plotdict[wanted]['xnl'][inkey];
                ynl = plotdict[wanted]['ynl'][inkey];
                labelneed = plotdict[wanted]['labelneed'];
                color = plotdict[wanted]['color'];
                lsn = plotdict[wanted]['lsn'][inkey];
                lw = plotdict[wanted]['lw'];
                marker = plotdict[wanted]['marker'];
                linelabel = plotdict[wanted]['linelab'][inkey];
                legendneed = 1
                if i==0 and j==0: 
                    label = linelabel
                else:
                    label = '_nolegend_' 
                print 'xnl', xnl
                print 'ynl', ynl
                if noplots==1:
                    ax.plot(xnl,ynl,label=label,lw=lw,ls=lsn,color=color,marker=marker)
                else:
                    ax[i].plot(xnl,ynl,label=label,lw=lw,ls=lsn,color=color,marker=marker)
                if k==0 and i==noplots-1:
                    lxlist.append(mlines.Line2D([], [], color=color, ls=lsn,label=labelneed))
                    linelablist = np.append(linelablist,labelneed)
        if i<noplots-1: xlab=''
        if i>1: legendneed=0
        if noplots==1:
            ax.set_title(ptitle, fontsize=22)
            legend1 = ax.legend(lxlist, linelablist, loc='lower left',fontsize=12,ncol=1)
            ax.add_artist(legend1)
        else:
            ax[i].set_title(ptitle, fontsize=22)
            if i==noplots-1:
                legend1 = ax[i].legend(lxlist, linelablist, loc='lower left',fontsize=12,ncol=1)
                ax[i].add_artist(legend1)
        if noplots==1:
            PS.miscsetup(ax,logx=0,logy=1,xlab=xlab,ylab=ylab,legendneed=legendneed,labfs=22,legfs=12)
        else:
            PS.miscsetup(ax[i],logx=0,logy=1,xlab=xlab,ylab=ylab,legendneed=legendneed,labfs=22,legfs=12)
        if not (i==0 or i==noplots-1):
            if noplots==1:
                ax.legend().set_visible(False)
            else:
                ax[i].legend().set_visible(False)
    #plt.legend(loc='upper right',fontsize=12)
    PS.finishsave(plt,filename)
    return None
コード例 #5
0
def vzcylouttestinput(subdict):
    startno = subdict['startno']
    Nsnap = subdict['Nsnap']
    snapsep = subdict['snapsep']
    wanted = subdict['wanted']
    dirneed = subdict['dirneed']
    fmeat = subdict['fmeat']
    dirdict = collections.defaultdict(dict)
    keylist = np.array([])
    for ir, runtodo in enumerate(dirneed):
        keylist = np.append(keylist, keystore[ir])
        dirdict[keystore[ir]] = [runtodo]
    #noplots=len(dirdict.keys())
    noplots = 1
    print 'noplots', noplots
    fig, ax = PS.setupfig(nrows=noplots, ncols=1, sharex=True, sharey=False)

    for i, key in enumerate(keylist):
        items = dirdict[key]
        for j, runtodo in enumerate(items):
            ssdict = collections.defaultdict(dict)
            ssdict = subdict
            ssdict['runtodo'] = runtodo
            print 'runtodo', runtodo
            plotdict = vzcylout_out(ssdict)
            xlab = plotdict[wanted]['xlab']
            ylab = plotdict[wanted]['ylab']
            ptitle = plotdict[wanted]['ptitle']
            filename = plotdict[wanted]['filename']
            xnl = plotdict[wanted]['xnl']
            ynl = plotdict[wanted]['ynl']
            labelneed = plotdict[wanted]['labelneed']
            color = plotdict[wanted]['color']
            lsn = plotdict[wanted]['lsn']
            lw = plotdict[wanted]['lw']
            marker = plotdict[wanted]['marker']
            linelabel = plotdict[wanted]['linelab']
            legendneed = 1
            if i == 0 and j == 0:
                label = linelabel
            else:
                label = '_nolegend_'
            print 'xnl', xnl
            print 'ynl', ynl
            if noplots == 1:
                ax.plot(xnl,
                        ynl,
                        label=labelneed,
                        lw=lw,
                        ls=lsn,
                        color=color,
                        marker=marker)
            else:
                ax[i].plot(xnl,
                           ynl,
                           label=labelneed,
                           lw=lw,
                           ls=lsn,
                           color=color,
                           marker=marker)
        if i < noplots - 1: xlab = ''
        if i > 1: legendneed = 0
        if noplots == 1:
            ax.set_title(ptitle, fontsize=16)
        else:
            ax[i].set_title(ptitle, fontsize=16)
        #ax.text(0.25, 0.95, ptitle, horizontalalignment='center',
        #verticalalignment='center', transform=ax.transAxes,fontsize=22)
        if noplots == 1:
            PS.miscsetup(ax,
                         logx=0,
                         logy=1,
                         xlab=xlab,
                         ylab=ylab,
                         legendneed=legendneed,
                         labfs=22,
                         legfs=12)
        else:
            PS.miscsetup(ax[i],
                         logx=0,
                         logy=1,
                         xlab=xlab,
                         ylab=ylab,
                         legendneed=legendneed,
                         labfs=22,
                         legfs=12)
    PS.finishsave(plt, filename)
    return None
コード例 #6
0
def CRerzdis_single_testinput(subdict):
    startno = subdict['startno']
    Nsnap = subdict['Nsnap']
    snapsep = subdict['snapsep']
    wanted = subdict['wanted']
    dirneed = np.array(subdict['dirneed'])
    fmeat = subdict['fmeat']
    title = subdict['title']
    dirdict = collections.defaultdict(dict)
    keylist = np.array([])
    for ir, subdirneed in enumerate(dirneed):
        keylist = np.append(keylist, keystore[ir])
        if dirneed.ndim > 1:
            dirdict[keystore[ir]] = subdirneed
        else:
            dirdict[keystore[ir]] = [subdirneed]
    noplots = 1
    print 'noplots', noplots
    fig, ax = PS.setupfig(nrows=noplots, ncols=1, sharex=True, sharey=False)
    linelablist = []
    lxlist = []
    for i, key in enumerate(keylist):  #i for different runs
        items = dirdict[key]
        for j, runtodo in enumerate(items):  #j for different CR models
            ssdict = collections.defaultdict(dict)
            ssdict = subdict
            ssdict['runtodo'] = runtodo
            print 'runtodo', runtodo
            plotdict = CR_rz_energy_distribution_single(ssdict)
            xlab = plotdict[wanted]['xlab']
            ylab = plotdict[wanted]['ylab']
            ptitle = plotdict[wanted]['ptitle']
            filename = plotdict[wanted]['filename']
            print 'filename', filename
            for k, inkey in enumerate(
                    plotdict[wanted]['xnl']):  #k for different energies
                xnl = plotdict[wanted]['xnl'][inkey]
                ynl = plotdict[wanted]['ynl'][inkey]
                labelneed = plotdict[wanted]['labelneed']
                #CR models
                color = plotdict[wanted]['color']
                lsn = plotdict[wanted]['lsn']
                lw = plotdict[wanted]['lw'][inkey]
                marker = plotdict[wanted]['marker']
                linelabel = plotdict[wanted]['linelab']
                #runlabel
                legendneed = 1
                if j == 1:
                    label = linelabel
                else:
                    label = '_nolegend_'
                print 'j,label', j, label
                if noplots == 1:
                    ax.plot(xnl,
                            ynl,
                            label=label,
                            lw=lw,
                            ls=lsn,
                            color=color,
                            marker=marker)
                else:
                    ax[i].plot(xnl,
                               ynl,
                               label=label,
                               lw=lw,
                               ls=lsn,
                               color=color,
                               marker=marker)
                if i == 0:
                    lxlist.append(
                        mlines.Line2D([], [],
                                      color=color,
                                      ls='solid',
                                      label=labelneed))
                    linelablist = np.append(linelablist, labelneed)
        if i < noplots - 1: xlab = ''
        legend1 = ax.legend(lxlist,
                            linelablist,
                            loc='lower left',
                            fontsize=12,
                            ncol=1)
        ax.add_artist(legend1)
        if noplots == 1:
            PS.miscsetup(ax,
                         logx=0,
                         logy=1,
                         xlab=xlab,
                         ylab=ylab,
                         legendneed=legendneed,
                         labfs=22,
                         legfs=12,
                         locneed='upper right')
        else:
            PS.miscsetup(ax[i],
                         logx=0,
                         logy=1,
                         xlab=xlab,
                         ylab=ylab,
                         legendneed=legendneed,
                         labfs=22,
                         legfs=12,
                         locneed='upper right')
    PS.finishsave(plt, filename)
    return None
コード例 #7
0
def sfrhotgasmass_testinput(subdict):
    nested_dict = lambda: collections.defaultdict(nested_dict)
    plotdict = nested_dict()
    startno = subdict['startno']
    Nsnap = subdict['Nsnap']
    snapsep = subdict['snapsep']
    wanted = subdict['wanted']
    dirneed = subdict['dirneed']
    fmeat = subdict['fmeat']
    withinr = subdict['withinr']
    withoutr = subdict['withoutr']
    maxlength = subdict['maxlength']
    minsfr = subdict['minsfr']
    maxsfr = subdict['maxsfr']
    title = ''
    titleneed = title
    ptitle = title
    needlog = 0
    dclabelneed = 1
    correctIa = 0
    useM1 = 0
    resoneed = 0
    rotface = 1
    loccen = 1
    newlabelneed = 1

    findradiusatnism = 1  #find the radius that has that ISM density (negative to turn off)
    #withinr=5. #withinr will change according to the above
    dr = 2.
    fig, ax = PS.setupfig(nrows=1, ncols=1, sharex=True, sharey=False)
    if wanted == 'sfrhotgasmass':
        ncount = 0
        ncrcount = 0
        nbcount = 0
        energylabel = 1
        usesolarcircle = 0
        usecentral = 0
        if usesolarcircle == 1:
            fmeat += '_usesolarcircle'
        elif usecentral == 1:
            fmeat += '_usecentral'
        sfrl = []
        gmhiml = []
        coloril = []
        runtodol = []
        for runtodo in dirneed:
            for i in range(startno, Nsnap, snapsep):
                info = SSF.outdirname(runtodo, i)
                rundir = info['rundir']
                runtitle = info['runtitle']
                slabel = info['slabel']
                snlabel = info['snlabel']
                dclabel = info['dclabel']
                resolabel = info['resolabel']
                the_snapdir = info['the_snapdir']
                the_prefix = info['the_prefix']
                the_suffix = info['the_suffix']
                Nsnapstring = info['Nsnapstring']
                havecr = info['havecr']
                Fcal = info['Fcal']
                iavesfr = info['iavesfr']
                timestep = info['timestep']
                maindir = info['maindir']
                haveB = info['haveB']
                cosmo = info['cosmo']
                newlabel = info['newlabel']
                color = info['color']
                usepep = info['usepep']
                snumadd = info['snumadd']
                halostr = info['halostr']
                h0 = info['h0']
                highres = info['highres']
                ptitle = title
                if runtitle == 'SMC':
                    ptitle = 'Dwarf'
                elif runtitle == 'SBC':
                    ptitle = 'Starburst'
                elif runtitle == 'MW':
                    ptitle = r'$L\star$ Galaxy'
                labelneed = dclabel
                if newlabelneed == 1:
                    labelneed = "\n".join(wrap(newlabel, 17))
                try:
                    usesnipshot = 1
                    if usesnipshot == 1:
                        print 'usesnipshot'
                        commonpath = '/home/tkc004/scratch/snipshot/philruns/'
                        fname = commonpath + rundir + '/output/withinr20GS/snipshot_' + Nsnapstring + '.hdf5'
                        data = RSS.readsnipshot(fname, ptypelist=[0, 4])
                        G = data[0]
                        S = data[1]
                        oheader = readsnapcr(the_snapdir,
                                             Nsnapstring,
                                             0,
                                             snapshot_name=the_prefix,
                                             extension=the_suffix,
                                             havecr=havecr,
                                             h0=h0,
                                             cosmological=cosmo,
                                             header_only=0,
                                             oheader_only=1)
                        S['header'] = oheader
                        #print 'oheader', oheader
                    else:
                        G = SSF.readsnapwcen(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix,\
                         havecr=havecr,h0=h0,cosmo=cosmo, usepep=usepep, maindir=maindir,snumadd=snumadd,rotface=rotface,\
                         loccen=loccen,runtodo=runtodo,rundir=rundir,halostr=halostr)
                        S = SSF.readsnapwcen(the_snapdir, Nsnapstring, 4, snapshot_name=the_prefix, extension=the_suffix,\
                         havecr=havecr,h0=h0,cosmo=cosmo, usepep=usepep, maindir=maindir,snumadd=snumadd,rotface=rotface,\
                         loccen=loccen,runtodo=runtodo,rundir=rundir,halostr=halostr)
                    Gmdata = SSF.calGmatT(G, withinr=withinr, nbin=2)
                    gmhim = np.sum(Gmdata['mgrhot'])
                    gmhiml = np.append(gmhiml, gmhim)
                    sfrdata = SSF.calsfr(S, cosmo=cosmo)
                    del G, S
                    sfr = sfrdata['sfr']
                    sfrl = np.append(sfrl, sfr)
                    colori = highres
                    coloril = np.append(coloril, colori)
                    runtodol = np.append(runtodol, runtodo)
                except (ZeroDivisionError, IndexError):
                    continue

        if wanted == 'sfrhotgasmass':
            neederrbar = 1
            if neederrbar == 1:
                for runtodo in dirneed:
                    Sds = sfrl[runtodol == runtodo]
                    sHs = gmhiml[runtodol == runtodo]
                    cls = coloril[runtodol == runtodo]
                    Sdmed = np.median(Sds)
                    sHmed = np.median(sHs)
                    clmed = np.median(cls)
                    Sdu = np.percentile(Sds, 84) - Sdmed
                    Sdd = Sdmed - np.percentile(Sds, 15.8)
                    sHu = np.percentile(sHs, 84) - sHmed
                    sHd = sHmed - np.percentile(sHs, 15.8)
                    if clmed == 0:
                        color = 'k'
                        marker = 's'
                    if clmed == 1:
                        color = 'r'
                        marker = '^'
                    if clmed == 3:
                        color = 'g'
                        marker = 'o'
                    ax.errorbar(Sdmed,
                                sHmed,
                                xerr=[[Sdd], [Sdu]],
                                yerr=[[sHd], [sHu]],
                                color=color,
                                fmt=marker,
                                markersize=7)
            else:
                ax.plot(sfrl[coloril == 1],
                        gmhiml[coloril == 1],
                        color='r',
                        ls='None',
                        marker='^')
                ax.plot(sfrl[coloril == 3],
                        gmhiml[coloril == 3],
                        color='g',
                        ls='None',
                        marker='s')
        xlab = r'${\rm SFR\;[M_\odot/yr]}$'
        if wanted == 'sfrhotgasmass':
            ylab = r'$M(T>10^5\;{\rm K})\;[{\rm M_\odot}]$'
        ax.set_title(ptitle, fontsize=16)
        PS.miscsetup(ax,
                     logx=0,
                     logy=0,
                     xlab=xlab,
                     ylab=ylab,
                     legendneed=0,
                     labfs=22,
                     legfs=12)
        import matplotlib.lines as mlines
        potr = mlines.Line2D([], [], color='r', ls='None', marker='^')
        potg = mlines.Line2D([], [], color='g', ls='None', marker='s')
        lxlist = [potr, potg]
        lablist = ['MHD+', 'CR+']
        legend1 = plt.legend(lxlist,
                             lablist,
                             loc='upper left',
                             fontsize=14,
                             ncol=1)
        plt.gca().add_artist(legend1)
        if wanted == 'sfrhotgasmass':
            filename = plotloc + 'CRplot/sfrhotgasmass/sfrhotgasmass_' + fmeat + '_sn' + str(
                startno) + '_' + str(Nsnap) + '.pdf'
        PS.finishsave(plt, filename)
コード例 #8
0
def sfrturtestinput(subdict):
    nested_dict = lambda: collections.defaultdict(nested_dict)
    plotdict = nested_dict()
    startno = subdict['startno']
    Nsnap = subdict['Nsnap']
    snapsep = subdict['snapsep']
    wanted = subdict['wanted']
    dirneed = subdict['dirneed']
    fmeat = subdict['fmeat']
    withinr = subdict['withinr']
    withoutr = subdict['withoutr']
    maxlength = subdict['maxlength']
    minsfr = subdict['minsfr']
    maxsfr = subdict['maxsfr']
    title = ''
    titleneed = title
    ptitle = title
    needlog = 0
    dclabelneed = 1
    correctIa = 0
    useM1 = 0
    resoneed = 0
    rotface = 1
    loccen = 1
    newlabelneed = 1

    findradiusatnism = 1  #find the radius that has that ISM density (negative to turn off)
    withinr = 5.  #withinr will change according to the above
    dr = 2.
    fig, ax = PS.setupfig(nrows=1, ncols=1, sharex=True, sharey=False)
    if wanted=='sfrtur' or wanted=='sfrtur_m' or wanted=='sigmatur_mweighted'\
    or wanted=='vth_mweighted' or wanted=='vcr_mweighted'\
    or wanted=='vA_mweighted' or wanted=='v_mweighted':
        ncount = 0
        ncrcount = 0
        nbcount = 0
        energylabel = 1
        usesolarcircle = 0
        usecentral = 0
        if usesolarcircle == 1:
            fmeat += '_usesolarcircle'
        elif usecentral == 1:
            fmeat += '_usecentral'
        turt = []
        thermt = []
        crt = []
        Begyt = []
        sfrl = []
        gml = []
        coloril = []
        for runtodo in dirneed:
            info = SSF.outdirname(runtodo, Nsnap)
            rundir = info['rundir']
            runtitle = info['runtitle']
            slabel = info['slabel']
            snlabel = info['snlabel']
            dclabel = info['dclabel']
            resolabel = info['resolabel']
            the_snapdir = info['the_snapdir']
            the_prefix = info['the_prefix']
            the_suffix = info['the_suffix']
            Nsnapstring = info['Nsnapstring']
            havecr = info['havecr']
            Fcal = info['Fcal']
            iavesfr = info['iavesfr']
            timestep = info['timestep']
            maindir = info['maindir']
            haveB = info['haveB']
            cosmo = info['cosmo']
            newlabel = info['newlabel']
            color = info['color']
            usepep = info['usepep']
            snumadd = info['snumadd']
            halostr = info['halostr']
            h0 = info['h0']
            highres = info['highres']
            ptitle = title
            if runtitle == 'SMC':
                ptitle = 'Dwarf'
            elif runtitle == 'SBC':
                ptitle = 'Starburst'
            elif runtitle == 'MW':
                ptitle = r'$L\star$ Galaxy'
            labelneed = dclabel
            if newlabelneed == 1:
                labelneed = "\n".join(wrap(newlabel, 17))
            for i in range(startno, Nsnap, snapsep):
                try:
                    info = SSF.outdirname(runtodo, i)
                    Nsnapstring = info['Nsnapstring']
                    egydata=CRTF.energyoutput(runtodo,i,usesolarcircle=usesolarcircle,usecentral=usecentral,\
                                              cylr=withinr,cylrin=withoutr,cylz=maxlength)
                    turl = egydata['turl']
                    therml = egydata['therml']
                    cregyl = egydata['cregyl']
                    Begyl = egydata['Begyl']
                    gm = np.sum(egydata['gminl'])  #in g
                    turt = np.append(turt, np.sum(turl))
                    thermt = np.append(thermt, np.sum(therml))
                    crt = np.append(crt, np.sum(cregyl))
                    Begyt = np.append(Begyt, np.sum(Begyl))
                    gml = np.append(gml, gm)
                    S = SSF.readsnapwcen(the_snapdir, Nsnapstring, 4, snapshot_name=the_prefix, extension=the_suffix,\
                     havecr=havecr,h0=h0,cosmo=cosmo, usepep=usepep, maindir=maindir,snumadd=snumadd,rotface=rotface,\
                     loccen=loccen,runtodo=runtodo,rundir=rundir,halostr=halostr)
                    sfrdata = SSF.calsfr(S, cosmo=cosmo)
                    sfr = sfrdata['sfr']
                    sfrl = np.append(sfrl, sfr)
                    colori = highres
                    coloril = np.append(coloril, colori)
                except (ZeroDivisionError, IndexError):
                    continue

        turt = np.array(turt)
        thermt = np.array(thermt)
        crt = np.array(crt)
        Begyt = np.array(Begyt)
        sigmaz = np.sqrt(turt / gml) / km_in_cm
        vth = np.sqrt(thermt * (GAMMA - 1) * (GAMMA) / gml) / km_in_cm
        vcr = np.sqrt(crt * (CRgamma - 1) * (CRgamma) / gml) / km_in_cm
        vA = np.sqrt(Begyt / gml * 2.0) / km_in_cm
        print 'sfrl', sfrl
        print 'turt', turt
        print 'sigmaz', sigmaz
        print 'vth', vth
        print 'vA', vA
        print 'coloril', coloril

        if wanted == 'sfrtur':
            ax.plot(sfrl[coloril == 0],
                    turt[coloril == 0],
                    color='k',
                    ls='None',
                    marker='s')
            ax.plot(sfrl[coloril == 1],
                    turt[coloril == 1],
                    color='r',
                    ls='None',
                    marker='s')
            ax.plot(sfrl[coloril == 3],
                    turt[coloril == 3],
                    color='g',
                    ls='None',
                    marker='s')
        if wanted == 'sfrtur_m':
            ax.plot(sfrl[coloril == 0],
                    turt[coloril == 0] / gml[coloril == 0],
                    color='k',
                    ls='None',
                    marker='s')
            ax.plot(sfrl[coloril == 1],
                    turt[coloril == 1] / gml[coloril == 1],
                    color='r',
                    ls='None',
                    marker='s')
            ax.plot(sfrl[coloril == 3],
                    turt[coloril == 3] / gml[coloril == 3],
                    color='g',
                    ls='None',
                    marker='s')
        if wanted == 'sigmatur_mweighted' or wanted == 'v_mweighted':
            ax.plot(sfrl[coloril == 0],
                    sigmaz[coloril == 0],
                    color='k',
                    ls='None',
                    marker='d')
            ax.plot(sfrl[coloril == 1],
                    sigmaz[coloril == 1],
                    color='r',
                    ls='None',
                    marker='d')
            ax.plot(sfrl[coloril == 3],
                    sigmaz[coloril == 3],
                    color='g',
                    ls='None',
                    marker='d')
            ax.set_ylim(ymin=1, ymax=30)
            ax.set_xlim(xmin=minsfr, xmax=maxsfr)
        if wanted == 'vth_mweighted' or wanted == 'v_mweighted':
            ax.plot(sfrl[coloril == 0],
                    vth[coloril == 0],
                    color='k',
                    ls='None',
                    marker='^')
            ax.plot(sfrl[coloril == 1],
                    vth[coloril == 1],
                    color='r',
                    ls='None',
                    marker='^')
            ax.plot(sfrl[coloril == 3],
                    vth[coloril == 3],
                    color='g',
                    ls='None',
                    marker='^')
            ax.set_ylim(ymin=1, ymax=30)
            ax.set_xlim(xmin=minsfr, xmax=maxsfr)
        if wanted == 'vcr_mweighted' or wanted == 'v_mweighted':
            ax.plot(sfrl[coloril == 0],
                    vcr[coloril == 0],
                    color='k',
                    ls='None',
                    marker='o')
            ax.plot(sfrl[coloril == 1],
                    vcr[coloril == 1],
                    color='r',
                    ls='None',
                    marker='o')
            ax.plot(sfrl[coloril == 3],
                    vcr[coloril == 3],
                    color='g',
                    ls='None',
                    marker='o')
            ax.set_ylim(ymin=1, ymax=30)
            ax.set_xlim(xmin=minsfr, xmax=maxsfr)
        if wanted == 'vA_mweighted' or wanted == 'v_mweighted':
            ax.plot(sfrl[coloril == 0],
                    vA[coloril == 0],
                    color='k',
                    ls='None',
                    marker='s')
            ax.plot(sfrl[coloril == 1],
                    vA[coloril == 1],
                    color='r',
                    ls='None',
                    marker='s')
            ax.plot(sfrl[coloril == 3],
                    vA[coloril == 3],
                    color='g',
                    ls='None',
                    marker='s')
            ax.set_ylim(ymin=1, ymax=30)
            ax.set_xlim(xmin=minsfr, xmax=maxsfr)
        xlab = r'${\rm SFR\;[M_\odot/yr]}$'
        if wanted == 'sfrtur':
            ylab = r'${\rm E_{tur}\;[erg]}$'
        if wanted == 'sfrtur_m':
            ylab = r'${\rm E_{tur}/m\;[erg/g]}$'
        if wanted == 'sigmatur_mweighted':
            ylab = r'${\rm  \langle\sigma_{tur}\rangle\;[km/s]}$'
        if wanted == 'vth_mweighted':
            ylab = r'${\rm  \langle c_{th}\rangle\;[km/s]}$'
        if wanted == 'vcr_mweighted':
            ylab = r'${\rm  \langle c_{cr}\rangle\;[km/s]}$'
        if wanted == 'vA_mweighted':
            ylab = r'${\rm  \langle v_{A}\rangle\;[km/s]}$'
        if wanted == 'v_mweighted':
            ylab = r'${\rm  \langle c\rangle\;[km/s]}$'
        ax.set_title(ptitle, fontsize=16)
        PS.miscsetup(ax,
                     logx=1,
                     logy=1,
                     xlab=xlab,
                     ylab=ylab,
                     legendneed=0,
                     labfs=22,
                     legfs=12)
        import matplotlib.lines as mlines
        potk = mlines.Line2D([], [], color='k', ls='None', marker='s')
        potr = mlines.Line2D([], [], color='r', ls='None', marker='s')
        potg = mlines.Line2D([], [], color='g', ls='None', marker='s')
        #potk = plt.plot([],[], ls='None',marker='s', color='k')
        #potr = plt.plot([],[], ls='None',marker='s', color='r')
        #potg = plt.plot([],[], ls='None',marker='s', color='g')
        lxlist = [potk, potr, potg]
        lablist = ['no CR', 'MHD no CR', r'MHD $\kappa$=3e29']
        legend1 = plt.legend(lxlist,
                             lablist,
                             loc='lower left',
                             fontsize=14,
                             ncol=1)
        plt.gca().add_artist(legend1)
        if wanted == 'v_mweighted':
            pottur = mlines.Line2D([], [], color='r', ls='None', marker='d')
            potth = mlines.Line2D([], [], color='r', ls='None', marker='^')
            potcr = mlines.Line2D([], [], color='r', ls='None', marker='o')
            potvA = mlines.Line2D([], [], color='r', ls='None', marker='s')
            lxvlist = [pottur, potth, potcr, potvA]
            labvlist = [
                r'${\rm \langle\sigma_{tur}\rangle}$',
                r'${\rm \langle c_{th}\rangle}$',
                r'${\rm \langle c_{cr}\rangle}$',
                r'${\rm \langle v_{A}\rangle}$'
            ]
            legend1v = plt.legend(lxvlist,
                                  labvlist,
                                  loc='lower right',
                                  fontsize=14,
                                  ncol=1)
            plt.gca().add_artist(legend1v)
        if wanted == 'sfrtur':
            filename = plotloc + 'CRplot/sfrtur/sfrtur_' + fmeat + '_sn' + str(
                startno) + '_' + str(Nsnap) + '.pdf'
        if wanted == 'sfrtur_m':
            filename = plotloc + 'CRplot/sfrtur/sfrtur_m_' + fmeat + '_sn' + str(
                startno) + '_' + str(Nsnap) + '.pdf'
        if wanted == 'sigmatur_mweighted':
            filename = plotloc + 'CRplot/sigmatur_mweighted/sigmatur_mweighted_' + fmeat + '_sn' + str(
                startno) + '_' + str(Nsnap) + '.pdf'
        if wanted == 'vth_mweighted':
            filename = plotloc + 'CRplot/vth_mweighted/vth_mweighted_' + fmeat + '_sn' + str(
                startno) + '_' + str(Nsnap) + '.pdf'
        if wanted == 'vcr_mweighted':
            filename = plotloc + 'CRplot/vcr_mweighted/vcr_mweighted_' + fmeat + '_sn' + str(
                startno) + '_' + str(Nsnap) + '.pdf'
        if wanted == 'vA_mweighted':
            filename = plotloc + 'CRplot/vA_mweighted/vA_mweighted_' + fmeat + '_sn' + str(
                startno) + '_' + str(Nsnap) + '.pdf'
        if wanted == 'v_mweighted':
            filename = plotloc + 'CRplot/v_mweighted/v_mweighted_' + fmeat + '_sn' + str(
                startno) + '_' + str(Nsnap) + '.pdf'
        PS.finishsave(plt, filename)
コード例 #9
0
def sfrmockturtestinput(subdict):
    nested_dict = lambda: collections.defaultdict(nested_dict)
    plotdict = nested_dict()
    startno = subdict['startno']
    Nsnap = subdict['Nsnap']
    snapsep = subdict['snapsep']
    wanted = subdict['wanted']
    dirneed = subdict['dirneed']
    fmeat = subdict['fmeat']
    withinr = subdict['withinr']
    withoutr = subdict['withoutr']
    maxlength = subdict['maxlength']
    minsfr = subdict['minsfr']
    maxsfr = subdict['maxsfr']
    maxlength = subdict['maxlength']
    usesnipshot = subdict['usesnipshot']
    title = ''
    titleneed = title
    ptitle = title
    needlog = 0
    dclabelneed = 1
    correctIa = 0
    useM1 = 0
    resoneed = 0
    rotface = 1
    loccen = 1
    newlabelneed = 1

    fig, ax = PS.setupfig(nrows=1, ncols=1, sharex=True, sharey=False)

    the_prefix = 'snapshot'
    the_suffix = '.hdf5'
    sigmaHIlosgridl = np.array([])
    SFRdengridl = np.array([])
    coloril = np.array([])
    runtodol = np.array([])
    for runtodo in dirneed:
        for i in range(startno, Nsnap, snapsep):
            info = SSF.outdirname(runtodo, i)
            rundir = info['rundir']
            runtitle = info['runtitle']
            slabel = info['slabel']
            snlabel = info['snlabel']
            dclabel = info['dclabel']
            resolabel = info['resolabel']
            the_snapdir = info['the_snapdir']
            Nsnapstring = info['Nsnapstring']
            havecr = info['havecr']
            haveB = info['haveB']
            Fcal = info['Fcal']
            iavesfr = info['iavesfr']
            timestep = info['timestep']
            color = info['color']
            h0 = info['h0']
            cosmo = info['cosmo']
            usepep = info['usepep']
            maindir = info['maindir']
            snumadd = info['snumadd']
            halostr = info['halostr']
            highres = info['highres']
            rotface = 1
            loccen = 1
            if usesnipshot == 1:
                commonpath = '/home/tkc004/scratch/snipshot/philruns/'
                fname = commonpath + rundir + '/output/withinr20GS/snipshot_' + Nsnapstring + '.hdf5'
                data = RSS.readsnipshot(fname, ptypelist=[0, 4])
                G = data[0]
                S = data[1]
                oheader = readsnapcr(the_snapdir,
                                     Nsnapstring,
                                     0,
                                     snapshot_name=the_prefix,
                                     extension=the_suffix,
                                     havecr=havecr,
                                     h0=h0,
                                     cosmological=cosmo,
                                     header_only=0,
                                     oheader_only=1)
                S['header'] = oheader
                #print 'oheader', oheader
            else:
                S = SSF.readsnapwcen(the_snapdir, Nsnapstring, 4, snapshot_name=the_prefix, extension=the_suffix,\
                 havecr=havecr,h0=h0,cosmo=cosmo, usepep=usepep, maindir=maindir,snumadd=snumadd,rotface=rotface,\
                 loccen=loccen,runtodo=runtodo,rundir=rundir,halostr=halostr)
                G = SSF.readsnapwcen(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix,\
                 havecr=havecr,h0=h0,cosmo=cosmo, usepep=usepep, maindir=maindir,snumadd=snumadd,rotface=rotface,\
                 loccen=loccen,runtodo=runtodo,rundir=rundir,halostr=halostr)
            Sdata = SSF.calsfr(S, tintval=0.01, cosmo=1, withinr=20)
            sfrl = Sdata['sfrl']
            Sxl = Sdata['Sxl']
            Syl = Sdata['Syl']
            Szl = Sdata['Szl']

            if wanted == 'SFRturrad':
                xlist = np.linspace(-10, 10, num=40)
                ylist = np.linspace(-10, 10, num=40)
                rlist = np.linspace(0, 15, num=10)
                data = calsigmaHIlos(G, xlist, ylist, maxlength)
                newdata = SSF.calSFRsurdenxynew(sfrl, Sxl, Syl, Szl, xlist,
                                                ylist, maxlength)
                sigmaHIlosgrid = data['sigmaHIlosgrid']
                HIm = data['HImgrid']
                Hpos = data['pos']
                sHIr = SSF.fromxytorad(sigmaHIlosgrid, Hpos, HIm, rlist)
                SFRdengrid = newdata['SFRdengrid']
                sarea = newdata['areagrid']
                spos = newdata['pos']
                SFRr = SSF.fromxytorad(SFRdengrid, spos, sarea, rlist)
                sigmaHIlosgridl = np.append(sigmaHIlosgridl, sHIr)
                SFRdengridl = np.append(SFRdengridl, SFRr)
            if wanted == 'SFRturtot':
                Sscaledata = SSF.findscalelength(S,
                                                 halfmassscale=0,
                                                 usecylr=1,
                                                 usecylz=0,
                                                 cutrout=10.,
                                                 cutzout=5.)
                rs = Sscaledata['rs']
                Sscalearea = 4.0 * np.pi * rs * rs  #in kpc2
                SFRtot = np.sum(sfrl)  #in Msun/yr
                SFRperarea = SFRtot / Sscalearea
                SFRdengridl = np.append(SFRdengridl, SFRperarea)
                vertical = 0
                horizontal = 1
                dr = 0.5  #kpc
                griddir = 'grid0_5kpc'
                usehalfz = 0
                data = SSF.calrhogfrompreexist(runtodo,i,withinr,maxlength,\
                                               usehalfz=usehalfz,griddir=griddir,\
                                               cutcold=0,vertical=vertical,\
                                               horizontal=horizontal,withoutr=withoutr,\
                                              dr=dr,outHI=1)
                pthl = data['pthl']
                rhol = data['rhol']
                pturHIl = data['pturHIl']
                rhoHIl = data['rhoHIl']
                volll = data['volll']
                print 'rhol', rhol
                massl = volll / rhol
                vturHI2l = pturHIl / rhoHIl * massl
                vth2l = pthl / rhol * GAMMA * massl
                massl[~np.isfinite(massl)] = 0.0
                vturHI2l[~np.isfinite(vturHI2l)] = 0.0
                vth2l[~np.isfinite(vth2l)] = 0.0
                vHIdis = np.sqrt(
                    np.sum(vturHI2l + vth2l) / np.sum(massl)) / km_in_cm
                print 'runtodo', runtodo
                print 'np.sqrt(np.sum(vturHI2l))', np.sqrt(np.sum(vturHI2l))
                print 'np.sqrt(np.sum(vth2l))', np.sqrt(np.sum(vth2l))
                sigmaHIlosgridl = np.append(sigmaHIlosgridl, vHIdis)
                runtodol = np.append(runtodol, runtodo)
                #print 'vHIdis', vHIdis
                #print 'runtodo', runtodo
                #print 'i', i
            colori = highres
            coloril = np.append(coloril, colori)
    #print 'coloril', coloril
    #print 'sigmaHIlosgridl', sigmaHIlosgridl
    #print 'SFRdengridl', SFRdengridl
    if wanted == 'SFRturrad':
        ax.plot(SFRdengridl, sigmaHIlosgridl, color='k', ls='None', marker='s')
    if wanted == 'SFRturtot':
        neederrbar = 1
        if neederrbar == 1:
            for runtodo in dirneed:
                Sds = SFRdengridl[runtodol == runtodo]
                sHs = sigmaHIlosgridl[runtodol == runtodo]
                cls = coloril[runtodol == runtodo]
                Sdmed = np.median(Sds)
                sHmed = np.median(sHs)
                clmed = np.median(cls)
                Sdu = np.percentile(Sds, 84) - Sdmed
                Sdd = Sdmed - np.percentile(Sds, 15.8)
                sHu = np.percentile(sHs, 84) - sHmed
                sHd = sHmed - np.percentile(sHs, 15.8)
                print 'Sdu,Sdmed,Sdd', Sdu, Sdmed, Sdd
                print 'sHu,sHmed,sHd', sHu, sHmed, sHd
                if clmed == 0:
                    color = 'k'
                    marker = 's'
                if clmed == 1:
                    color = 'r'
                    marker = '^'
                if clmed == 3:
                    color = 'g'
                    marker = 'o'

                ax.errorbar(Sdmed,
                            sHmed,
                            xerr=[[Sdd], [Sdu]],
                            yerr=[[sHd], [sHu]],
                            color=color,
                            fmt=marker,
                            markersize=7)
        else:
            ax.plot(SFRdengridl[coloril == 0],
                    sigmaHIlosgridl[coloril == 0],
                    color='k',
                    ls='None',
                    marker='s')
            ax.plot(SFRdengridl[coloril == 1],
                    sigmaHIlosgridl[coloril == 1],
                    color='r',
                    ls='None',
                    marker='^')
            ax.plot(SFRdengridl[coloril == 3],
                    sigmaHIlosgridl[coloril == 3],
                    color='g',
                    ls='None',
                    marker='o')
        plotobserved = 1
        if plotobserved == 1:
            ftxt = open(programdir + '/data/DibsigmaSFRA.txt', 'r')
            ftxt.readline()
            dars = ftxt.readlines()
            ftxt.close()
            obslogSFRA = []
            obssigma = []
            for line in dars:
                xsd = line.split()
                obslogSFRA = np.append(obslogSFRA, float(xsd[0]))
                obssigma = np.append(obssigma, float(xsd[1]))
            ax.plot(np.power(10, obslogSFRA),
                    obssigma,
                    markeredgecolor='k',
                    markerfacecolor="None",
                    ls='None',
                    marker='D')
            #ax.plot(np.power(10,-1.59832), 34.8944,markeredgecolor='k',markerfacecolor="k",ls='None',marker='D')
    ax.set_ylim(ymin=1, ymax=50)
    ax.set_xlim(xmin=1e-5, xmax=0.5)
    xlab = r'${\rm \Sigma_{SFR}\;[M_\odot/yr/kpc^2]}$'
    ylab = r'${\rm  \sigma_{HI}[km/s]}$'
    ax.set_title(ptitle, fontsize=16)
    PS.miscsetup(ax,
                 logx=1,
                 logy=0,
                 xlab=xlab,
                 ylab=ylab,
                 legendneed=0,
                 labfs=22,
                 legfs=12)
    import matplotlib.lines as mlines
    potk = mlines.Line2D([], [], color='k', ls='None', marker='s')
    potr = mlines.Line2D([], [], color='r', ls='None', marker='^')
    potg = mlines.Line2D([], [], color='g', ls='None', marker='o')
    poto = mlines.Line2D([], [],
                         markeredgecolor='k',
                         markerfacecolor="None",
                         ls='None',
                         marker='D')
    lxlist = [
        #potk,
        potr,
        potg,
        poto
    ]
    lablist = [
        #'no CR',
        #'MHD no CR',
        'MHD+',
        'CR+',
        #r'MHD $\kappa$=3e29',
        'Obs'
    ]
    legend1 = plt.legend(lxlist,
                         lablist,
                         loc='upper left',
                         fontsize=14,
                         ncol=1)
    plt.gca().add_artist(legend1)
    if wanted == 'SFRturrad':
        filename = plotloc + 'CRplot/sfrtur/Sigmasfr_sigmaHI_' + fmeat + '_sn' + str(
            startno) + '_' + str(Nsnap) + '.pdf'
    if wanted == 'SFRturtot':
        filename = plotloc + 'CRplot/sfrtur/Sigmasfr_sigmaHItot_' + fmeat + '_sn' + str(
            startno) + '_' + str(Nsnap) + '.pdf'
    PS.finishsave(plt, filename)
コード例 #10
0
def Tztrack_outtestinput(subdict):
    dirneed = subdict['dirneed']
    wanted = subdict['wanted']
    Tcut_t = subdict['Tcut_t']  #K
    highTcut_t = subdict['highTcut_t']
    hotwarmmode = subdict['hotwarmmode']
    trackstart = subdict['trackstart']
    if hotwarmmode == 1:
        modedict = collections.defaultdict(dict)
        modelist = ['hot', 'warm']
        modedict['warm']['Tcut_t'] = 1.0
        modedict['warm']['highTcut_t'] = 1.0e5
        modedict['hot']['Tcut_t'] = 1.0e5
        modedict['hot']['highTcut_t'] = 1.0e10
        modedict['warm']['lsn'] = 'dashed'
        modedict['hot']['lsn'] = 'dotted'
    else:
        modedict = collections.defaultdict(dict)
        modelist = ['normal']
        modedict['normal']['Tcut_t'] = Tcut_t
        modedict['normal']['highTcut_t'] = highTcut_t
    dirdict = collections.defaultdict(dict)
    keylist = np.array([])
    for ir, subdirneed in enumerate(dirneed):
        keylist = np.append(keylist, keystore[ir])
        dirdict[keystore[ir]] = subdirneed
    noplots = 1
    fig, ax = PS.setupfig(nrows=noplots, ncols=1, sharex=True, sharey=False)
    for i, key in enumerate(keylist):
        items = dirdict[key]
        ssdict = collections.defaultdict(dict)
        ssdict = subdict
        for j, runtodo in enumerate(items):
            ssdict['runtodo'] = runtodo
            print 'runtodo', runtodo
            for labelcount, modekey in enumerate(modelist):
                ssdict['Tcut_t'] = modedict[modekey]['Tcut_t']
                ssdict['highTcut_t'] = modedict[modekey]['highTcut_t']
                print 'modekey', modekey
                print 'ssdict[Tcut_t]', ssdict['Tcut_t']
                print 'ssdict[highTcut_t]', ssdict['highTcut_t']
                plotdict = Tztrack_out(ssdict)
                xlab = plotdict[wanted]['xlab']
                ylab = plotdict[wanted]['ylab']
                ptitle = plotdict[wanted]['ptitle']
                filename = plotdict[wanted]['filename']
                xpoints = plotdict[wanted]['xnl']
                ypoints = plotdict[wanted]['ynl']
                labelneed = plotdict[wanted]['labelneed']
                color = plotdict[wanted]['color']
                lsn = plotdict[wanted]['lsn']
                if hotwarmmode == 1:
                    lsn = modedict[modekey]['lsn']
                lw = plotdict[wanted]['lw']
                marker = plotdict[wanted]['marker']
                linelabel = plotdict[wanted]['linelab']
                legendneed = plotdict[wanted]['legendneed']
                print 'xpoints,ypoints', xpoints, ypoints
                if labelcount == 0:
                    ax.plot(xpoints,
                            ypoints,
                            label=labelneed,
                            lw=lw,
                            ls=lsn,
                            color=color)
                else:
                    ax.plot(xpoints,
                            ypoints,
                            lw=lw,
                            ls=lsn,
                            color=color,
                            marker=marker)
                ax.scatter(xpoints[1:-1], ypoints[1:-1], color=color)
                if labelcount == 0 and j == 0:
                    ax.scatter(xpoints[0],
                               ypoints[0],
                               color=color,
                               marker='s',
                               s=4 * rcParams['lines.markersize']**2,
                               label='Start')
                    ax.scatter(xpoints[-1],
                               ypoints[-1],
                               color=color,
                               marker='>',
                               s=4 * rcParams['lines.markersize']**2,
                               label='End')
                else:
                    ax.scatter(xpoints[0],
                               ypoints[0],
                               color=color,
                               marker='s',
                               s=4 * rcParams['lines.markersize']**2)
                    ax.scatter(xpoints[-1],
                               ypoints[-1],
                               color=color,
                               marker='>',
                               s=4 * rcParams['lines.markersize']**2)
        logx = 1
        if trackstart == 1:
            logx = 0
        PS.miscsetup(ax,
                     logx=logx,
                     logy=1,
                     xlab=xlab,
                     ylab=ylab,
                     legendneed=legendneed,
                     labfs=22,
                     legfs=20)
    if hotwarmmode == 1:
        plt.xlim([np.log10(5.0), 2.0])
    if trackstart == 1:
        plt.xlim([np.log10(0.5), 2.0])
    PS.finishsave(plt, filename)
    return None
コード例 #11
0
def sfrtestinput(subdict):
    nested_dict = lambda: collections.defaultdict(nested_dict)
    plotdict = nested_dict()
    startno = subdict['startno']
    Nsnap = subdict['Nsnap']
    snapsep = subdict['snapsep']
    wanted = subdict['wanted']
    dirneed = subdict['dirneed']
    fmeat = subdict['fmeat']
    withinr = subdict['withinr']
    withoutr = subdict['withoutr']
    maxlength = subdict['maxlength']
    minsfr = subdict['minsfr']
    maxsfr = subdict['maxsfr']
    title = ''
    titleneed = title
    ptitle = title
    needlog = 0
    dclabelneed = 1
    correctIa = 0
    useM1 = 0
    resoneed = 0
    rotface = 1
    loccen = 1
    newlabelneed = 1

    findradiusatnism = 1  #find the radius that has that ISM density (negative to turn off)
    withinr = 5.  #withinr will change according to the above
    dr = 2.
    fig, ax = PS.setupfig(nrows=1, ncols=1, sharex=True, sharey=False)
    if wanted == 'sfr':
        ncount = 0
        ncrcount = 0
        nbcount = 0
        energylabel = 1
        usesolarcircle = 0
        usecentral = 0
        if usesolarcircle == 1:
            fmeat += '_usesolarcircle'
        elif usecentral == 1:
            fmeat += '_usecentral'
        turt = []
        thermt = []
        crt = []
        Begyt = []
        sfrl = []
        gml = []
        coloril = []
        runtodol = []
        for runtodo in dirneed:
            info = SSF.outdirname(runtodo, Nsnap)
            rundir = info['rundir']
            runtitle = info['runtitle']
            slabel = info['slabel']
            snlabel = info['snlabel']
            dclabel = info['dclabel']
            resolabel = info['resolabel']
            the_snapdir = info['the_snapdir']
            the_prefix = info['the_prefix']
            the_suffix = info['the_suffix']
            Nsnapstring = info['Nsnapstring']
            havecr = info['havecr']
            Fcal = info['Fcal']
            iavesfr = info['iavesfr']
            timestep = info['timestep']
            maindir = info['maindir']
            haveB = info['haveB']
            cosmo = info['cosmo']
            newlabel = info['newlabel']
            color = info['color']
            usepep = info['usepep']
            snumadd = info['snumadd']
            halostr = info['halostr']
            h0 = info['h0']
            highres = info['highres']
            ptitle = title
            if runtitle == 'SMC':
                ptitle = 'Dwarf'
            elif runtitle == 'SBC':
                ptitle = 'Starburst'
            elif runtitle == 'MW':
                ptitle = r'$L\star$ Galaxy'
            labelneed = dclabel
            if newlabelneed == 1:
                labelneed = "\n".join(wrap(newlabel, 17))
            for i in range(startno, Nsnap, snapsep):
                try:
                    info = SSF.outdirname(runtodo, i)
                    Nsnapstring = info['Nsnapstring']
                    S = SSF.readsnapwcen(the_snapdir, Nsnapstring, 4, snapshot_name=the_prefix, extension=the_suffix,\
                     havecr=havecr,h0=h0,cosmo=cosmo, usepep=usepep, maindir=maindir,snumadd=snumadd,rotface=rotface,\
                     loccen=loccen,runtodo=runtodo,rundir=rundir,halostr=halostr)
                    sfrdata = SSF.calsfr(S, cosmo=cosmo)
                    sfr = sfrdata['sfr']
                    runtodol = np.append(runtodol, runtodo)
                    sfrl = np.append(sfrl, sfr)
                    colori = highres
                    coloril = np.append(coloril, colori)
                except (ZeroDivisionError, IndexError):
                    continue
        print 'runtodol', runtodol
        print 'sfrl', sfrl
コード例 #12
0
def Blitzmidplanepressure_testinput(subdict):
    nested_dict = lambda: collections.defaultdict(nested_dict)
    plotdict = nested_dict()
    startno=subdict['startno']
    Nsnap=subdict['Nsnap']
    snapsep=subdict['snapsep']
    wanted=subdict['wanted']
    dirneed=subdict['dirneed']
    fmeat=subdict['fmeat']
    withinr=subdict['withinr']
    withoutr=subdict['withoutr']
    maxlength=subdict['maxlength']
    minsfr=subdict['minsfr']
    maxsfr=subdict['maxsfr']
    maxlength=subdict['maxlength']
    usesnipshot=subdict['usesnipshot']
    title=''
    titleneed=title
    ptitle=title
    needlog=0
    dclabelneed=1
    correctIa=0
    useM1=0
    resoneed=0
    rotface=1
    loccen=1
    newlabelneed=1
      

    the_prefix = 'snapshot'
    the_suffix = '.hdf5'
    sigmaHIlosgridl=np.array([])
    SFRdengridl=np.array([])
    coloril=np.array([])
    runtodol=np.array([])
    for runtodo in dirneed:
        fig, ax = PS.setupfig(nrows=1, ncols=1,sharex=True,sharey=False)  
        i=Nsnap
        info=SSF.outdirname(runtodo, i)
        rundir=info['rundir']
        runtitle=info['runtitle']
        slabel=info['slabel']
        snlabel=info['snlabel']
        dclabel=info['dclabel']
        resolabel=info['resolabel']
        the_snapdir=info['the_snapdir']
        Nsnapstring=info['Nsnapstring']
        havecr=info['havecr']
        haveB=info['haveB']
        Fcal=info['Fcal']
        iavesfr=info['iavesfr']
        timestep=info['timestep']
        color=info['color']
        h0=info['h0']
        cosmo=info['cosmo']
        usepep=info['usepep']
        maindir=info['maindir']
        snumadd=info['snumadd']
        halostr=info['halostr']
        highres=info['highres']
        rotface = 1
        loccen = 1
        if usesnipshot==1:
            commonpath='/home/tkc004/scratch/snipshot/philruns/'
            fname=commonpath+rundir+'/output/withinr20GS/snipshot_'+Nsnapstring+'.hdf5'
            data = RSS.readsnipshot(fname,ptypelist = [0,4])
            G = data[0];
            S = data[1];
            oheader = readsnapcr(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix,\
                                 extension=the_suffix, havecr=havecr,h0=h0,cosmological=cosmo,\
                                 header_only=0,oheader_only=1)
            S['header']=oheader
            #print 'oheader', oheader
        else:
            S = SSF.readsnapwcen(the_snapdir, Nsnapstring, 4, snapshot_name=the_prefix, extension=the_suffix,\
             havecr=havecr,h0=h0,cosmo=cosmo, usepep=usepep, maindir=maindir,snumadd=snumadd,rotface=rotface,\
             loccen=loccen,runtodo=runtodo,rundir=rundir,halostr=halostr)
            G = SSF.readsnapwcen(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix,\
             havecr=havecr,h0=h0,cosmo=cosmo, usepep=usepep, maindir=maindir,snumadd=snumadd,rotface=rotface,\
             loccen=loccen,runtodo=runtodo,rundir=rundir,halostr=halostr)           
        rlist = np.linspace(0,10,num=10)
        gasdenlist = SSF.calsurden(G,rlist,maxlength)
        stardenlist = SSF.calsurden(S,rlist,maxlength)
        propconst = Msun_in_g/pc_in_cm/pc_in_cm
        gasdenlist = gasdenlist*propconst
        stardenlist = stardenlist*propconst
        Sscaledata = SSF.findscalelength(S, halfmassscale=0, usecylr=0, usecylz=1, cutrout =10., cutzout = 5.)
        hstar = Sscaledata['rs']
        hstar =hstar*kpc_in_cm
        Gscaledata = SSF.findscalelength(G, halfmassscale=0, usecylr=0, usecylz=1, cutrout =10., cutzout = 5.)
        hgas = Gscaledata['rs']
        hgas = hgas*kpc_in_cm
        vertical=0; horizontal=1;
        dr = 0.5 #kpc
        griddir = 'grid0_5kpc'
        usehalfz=0
        data = SSF.calrhogfrompreexist(runtodo,i,withinr,maxlength,\
                                       usehalfz=usehalfz,griddir=griddir,\
                                       cutcold=0,vertical=vertical,\
                                       horizontal=horizontal,withoutr=withoutr,\
                                      dr=dr,outHI=1)
        pthl = data['pthl']; rhol = data['rhol'];
        pturHIl = data['pturHIl']; rhoHIl = data['rhoHIl'];
        volll = data['volll']
        massl = volll/rhol
        vturHI2l = pturHIl/rhoHIl*massl
        vth2l = pthl/rhol*GAMMA*massl
        massl[~np.isfinite(massl)]=0.0
        vturHI2l[~np.isfinite(vturHI2l)]=0.0
        vth2l[~np.isfinite(vth2l)]=0.0
        vHIdis = np.sqrt(np.sum(vturHI2l+vth2l)/np.sum(massl))
        #finally Blitz & Rosolowsky 2004 formula:
        pext = np.sqrt(2.0*NewtonG_in_cgs*stardenlist/hstar)*gasdenlist*vHIdis
        #with gas gravity:
        pextg = np.sqrt(2.0*NewtonG_in_cgs)*gasdenlist*vHIdis*\
        (np.sqrt(stardenlist/hstar)+np.sqrt(np.pi/4.0*gasdenlist/hgas))
        ax.plot(rlist, pext)
        ax.plot(rlist, pextg,ls='dashed')
        xlab = r'$ r\;[{\rm kpc]}$'
        ylab = r'$  P_{\rm ext}[{\rm dyne/cm^2]}$'             
        ax.set_title(ptitle, fontsize=16)
        PS.miscsetup(ax,logx=0,logy=1,xlab=xlab,ylab=ylab,legendneed=0,labfs=22,legfs=12)
        filename=plotloc+'CRplot/Pext/Pext_Blitz_'+runtodo+'_sn'+str(Nsnap)+'.pdf'
        PS.finishsave(plt,filename)
コード例 #13
0
def main():
    #startno=450
    #Nsnap=500
    startno = 550
    Nsnap = 600
    snapsep = 50
    wanted = 'Tztrack'
    trackstart = 1
    dirdict = collections.defaultdict(dict)
    keylist = ['plot1']
    dirdict['plot1'] = ['m12imhdcvhr']
    #dirdict['plot1']=['m12icr_700hr']
    noplots = len(dirdict.keys())
    fig, ax = PS.setupfig(nrows=noplots, ncols=1, sharex=True, sharey=False)
    fmeat = ''
    for i, key in enumerate(keylist):
        items = dirdict[key]
        for j, runtodo in enumerate(items):
            print 'runtodo', runtodo
            plotdict = calTz(runtodo,
                             wanted,
                             startno,
                             Nsnap,
                             snapsep,
                             fmeat,
                             trackstart=trackstart)
            xlab = plotdict[wanted]['xlab']
            ylab = plotdict[wanted]['ylab']
            ptitle = plotdict[wanted]['ptitle']
            filename = plotdict[wanted]['filename']
            xpoints = plotdict[wanted]['xnl']
            ypoints = plotdict[wanted]['ynl']
            labelneed = plotdict[wanted]['labelneed']
            color = plotdict[wanted]['color']
            lsn = plotdict[wanted]['lsn']
            lw = plotdict[wanted]['lw']
            marker = plotdict[wanted]['marker']
            linelabel = plotdict[wanted]['linelab']
            legendneed = plotdict[wanted]['legendneed']
            print 'lw', lw
            print 'lsn', lsn
            print 'color', color
            print 'marker', marker
            if noplots == 1:
                ax.plot(xpoints,
                        ypoints,
                        label=labelneed,
                        lw=lw,
                        ls=lsn,
                        color=color,
                        marker=marker)
            else:
                ax[i].plot(xpoints,
                           ypoints,
                           label=labelneed,
                           lw=lw,
                           ls=lsn,
                           color=color,
                           marker=marker)
            ax.scatter(xpoints[1:-1], ypoints[1:-1], color=color)
            ax.scatter(xpoints[0],
                       ypoints[0],
                       color=color,
                       marker='s',
                       s=4 * rcParams['lines.markersize']**2)
            ax.scatter(xpoints[-1],
                       ypoints[-1],
                       color=color,
                       marker='>',
                       s=4 * rcParams['lines.markersize']**2)
        if i < noplots - 1: xlab = ''
        if noplots == 1:
            ax.text(0.25,
                    0.95,
                    ptitle,
                    horizontalalignment='center',
                    verticalalignment='center',
                    transform=ax.transAxes,
                    fontsize=22)
            PS.miscsetup(ax,
                         logx=1,
                         logy=1,
                         xlab=xlab,
                         ylab=ylab,
                         legendneed=legendneed,
                         labfs=22,
                         legfs=12)
        else:
            ax[i].text(0.25,
                       0.95,
                       ptitle,
                       horizontalalignment='center',
                       verticalalignment='center',
                       transform=ax[i].transAxes,
                       fontsize=22)
            PS.miscsetup(ax[i],
                         logx=1,
                         logy=1,
                         xlab=xlab,
                         ylab=ylab,
                         legendneed=legendneed,
                         labfs=22,
                         legfs=12)
    PS.finishsave(plt, filename)