Example #1
0
def nismcretestinput(subdict):
    dirneed = subdict['dirneed']
    wanted = subdict['wanted']
    startno = subdict['startno']
    Nsnap = subdict['Nsnap']
    snapsep = subdict['snapsep']
    the_prefix = subdict['the_prefix']
    the_suffix = subdict['the_suffix']
    fmeat = subdict['fmeat']
    if wanted == 'nismgamma' or wanted == 'nismcre' or wanted == 'nismcrad' or wanted == 'nismcrg' or wanted == 'nismcrl' or wanted == 'rcrad':
        plt.figure(figsize=(5, 4))
        nogrid = 15
        Rvcut = 0
        atstarburst = 0
        trackneed = subdict['trackneed']
        newlabelneed = subdict['newlabelneed']
        legendneed = subdict['legendneed']
        for runtodo in dirneed:
            timel = []
            #enllist=[]
            #precount=0
            info = outdirname(runtodo, Nsnap)
            havecr = info['havecr']
            if havecr == 0:
                continue
            if atstarburst == 1:
                if runtodo == 'bwsbclr':
                    Nsnap = 523
                if runtodo == 'bwsbclrmhd':
                    Nsnap = 589
                if runtodo == 'bwsbclrdc0':
                    Nsnap = 590
                if runtodo == 'bwsbclrdc27':
                    Nsnap = 138
                if runtodo == 'bwsbclrdc28':
                    Nsnap = 520
                if runtodo == 'bwsbclrdc29':
                    Nsnap = 433
                if runtodo == 'bwsbclrstr':
                    Nsnap = 245
                if runtodo == 'bwsbclrdc28mhd':
                    Nsnap = 558
                if runtodo == 'bwsbclrdc28str':
                    Nsnap = 370
            for i in [Nsnap]:
                info = 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']
                Fcal = info['Fcal']
                iavesfr = info['iavesfr']
                timestep = info['timestep']
                cosmo = info['cosmo']
                color = info['color']
                haveB = info['haveB']
                Rvir = info['Rvir']
                newlabel = info['newlabel']
                if runtitle == 'SMC':
                    labelneed = dclabel
                if newlabelneed == 1:
                    labelneed = "\n".join(wrap(newlabel, 17))
                else:
                    labelneed = ''
                ptitle = title
                if runtitle == 'SMC':
                    ptitle = 'Dwarf'
                elif runtitle == 'SBC':
                    ptitle = 'Starburst'
                elif runtitle == 'MW':
                    ptitle = r'$L\star$ Galaxy'
                print 'the_snapdir', the_snapdir
                print 'Nsnapstring', Nsnapstring
                print 'havecr', havecr
                G = readsnapcr(the_snapdir,
                               Nsnapstring,
                               0,
                               snapshot_name=the_prefix,
                               extension=the_suffix,
                               havecr=havecr)
                header = readsnapcr(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix,\
                 extension=the_suffix, havecr=havecr, header_only=1)
                print 'time', header['time']
                timeneed = i * 0.98 * 1e6  #in yr
                Grho_t = G['rho']  #1e10Msun per kpc^3
                Gid_t = G['id']
                cregy_codeunit = G['cregy']
                cregy = cregy_codeunit * 1e10 * solar_mass_in_g * km_in_cm * km_in_cm  #original cosmic ray energy in 1e10Msun km^2/sec^2
                Neb = G['ne']
                cregyl = G[
                    'cregyl'] * 1e10 * solar_mass_in_g * km_in_cm * km_in_cm
                if wanted == 'nismcrad' or wanted == 'rcrad':
                    cregyad_t = G[
                        'cregya'] * 1e10 * solar_mass_in_g * km_in_cm * km_in_cm
                if wanted == 'nismcrg':
                    cregyg_t = G[
                        'cregyg'] * 1e10 * solar_mass_in_g * km_in_cm * km_in_cm
                Gp_t = G['p']
                Gx_t = Gp_t[:, 0]
                Gy_t = Gp_t[:, 1]
                Gz_t = Gp_t[:, 2]
                Gr_t = np.sqrt(Gx_t * Gx_t + Gy_t * Gy_t + Gz_t * Gz_t)
                if Rvcut == 1:
                    Grtcut = Gr_t < 1.0 * Rvir
                    Grho_t = Grho_t[Grtcut]
                    cregy_codeunit = cregy_codeunit[Grtcut]
                    cregy = cregy[Grtcut]
                    Neb = Neb[Grtcut]
                    cregyl = cregyl[Grtcut]
                    Gid_t = Gid_t[Grtcut]
                    Gr_t = Gr_t[Grtcut]
                    if wanted == 'nismcrad' or wanted == 'rcrad':
                        cregyad_t = cregyad_t[Grcut]
                    if wanted == 'nismcrg':
                        cregyg_t = cregyg_t[Grcut]
                if wanted == 'nismcrad' or wanted == 'nismcrg' or wanted == 'nismcrl' or wanted == 'rcrad':
                    snaptrack = i - snapsep
                    info = outdirname(runtodo, snaptrack)
                    Nsnapstring = info['Nsnapstring']
                    G = readsnapcr(the_snapdir,
                                   Nsnapstring,
                                   0,
                                   snapshot_name=the_prefix,
                                   extension=the_suffix,
                                   havecr=havecr)
                    timetrack = snaptrack * 0.98 * 1e6
                    if trackneed == 1:
                        Gp = G['p']
                        Gx = Gp[:, 0]
                        Gy = Gp[:, 1]
                        Gz = Gp[:, 2]
                        Gr = np.sqrt(Gx * Gx + Gy * Gy + Gz * Gz)
                        Grho = G['rho']
                        Gid = G['id']
                        Gid, unindex = np.unique(Gid, return_index=True)
                        Gid_t, unindex_t = np.unique(Gid_t, return_index=True)
                        idint0 = np.in1d(Gid, Gid_t)
                        # there are some duplicate IDs, from particle splitting? I drop those repetitions.
                        Gid = Gid[idint0]
                        Gidinds = Gid.argsort()
                        Gid_tinds = Gid_t.argsort()
                        Grho = Grho[unindex]
                        Grho = Grho[idint0]
                        Grho = Grho[Gidinds]
                        Grho_t = Grho_t[unindex_t]
                        Grho_t = Grho_t[Gid_tinds]
                        Gr = Gr[unindex]
                        Gr = Gr[idint0]
                        Gr = Gr[Gidinds]
                        Gr_t = Gr_t[unindex_t]
                        Gr_t = Gr_t[Gid_tinds]
                    if wanted == 'nismcrad' or wanted == 'rcrad':
                        cregyad = G[
                            'cregya'] * 1e10 * solar_mass_in_g * km_in_cm * km_in_cm
                        if trackneed == 1:
                            cregyad = cregyad[unindex]
                            cregyad = cregyad[idint0]
                            cregyad_t = cregyad_t[unindex_t]
                            dcrad = (cregyad_t[Gid_tinds] - cregyad[Gidinds]
                                     ) / (timeneed - timetrack) / yr_in_sec
                    if wanted == 'nismcrg':
                        cregyg = G[
                            'cregyg'] * 1e10 * solar_mass_in_g * km_in_cm * km_in_cm
                        cregyg = cregyg[idint0]
                        dcrg = (cregyg_t[Gid_tinds] - cregyg[Gidinds]) / (
                            timeneed - timetrack) / yr_in_sec
                    if wanted == 'nismcrl':
                        cregyl_p = G[
                            'cregyl'] * 1e10 * solar_mass_in_g * km_in_cm * km_in_cm
                        cregyl_p = cregyl_p[idint0]
                        dcrl = (cregyl[Gid_tinds] - cregyl_p[Gidinds]) / (
                            timeneed - timetrack) / yr_in_sec
                Gnism_in_cm_3 = 1.0 / proton_mass_in_g * Grho_t * 1e10 * Msun_in_g / kpc_in_cm / kpc_in_cm / kpc_in_cm
                if wanted == 'nismgamma':
                    Lout = outLgamma_nism(Grho, Neb, cregy_codeunit)
                    Lgamma = Lout['Lgamma']
                LogGnism = np.log10(Gnism_in_cm_3)
                LogGr = np.log10(Gr_t)
                if trackneed == 1:
                    LogGnxaxis = np.linspace(-6, 2.5, num=nogrid)
                else:
                    LogGnxaxis = np.linspace(-4, 4.0, num=nogrid)
                if wanted == 'rcrad':
                    LogGnxaxis = np.linspace(-1, 2.0, num=nogrid)
                dx = LogGnxaxis[1] - LogGnxaxis[0]
                Lgammal = []
                crel = []
                dcradl = []
                dcrgl = []
                dcrll = []
                for inism in range(nogrid - 1):
                    if wanted == 'rcrad':
                        cutg = (LogGr > LogGnxaxis[inism]) & (
                            LogGr < LogGnxaxis[inism + 1])
                    else:
                        cutg = (LogGnism > LogGnxaxis[inism]) & (
                            LogGnism < LogGnxaxis[inism + 1])
                    if wanted == 'nismgamma':
                        Lgammacut = Lgamma[cutg]
                        Lgammal = np.append(Lgammal, np.sum(Lgammacut))
                    if wanted == 'nismcre':
                        crecut = cregy[cutg]
                        crel = np.append(crel, np.sum(crecut))
                    if wanted == 'nismcrad' or wanted == 'rcrad':
                        dcradcut = dcrad[cutg]
                        dcradl = np.append(dcradl, np.sum(dcradcut))
                    if wanted == 'nismcrg':
                        dcrgcut = dcrg[cutg]
                        dcrgl = np.append(dcrgl, np.sum(dcrgcut))
                    if wanted == 'nismcrl':
                        dcrlcut = dcrl[cutg]
                        dcrll = np.append(dcrll, np.sum(dcrlcut))
                if haveB > 0:
                    ls = 'dashed'
                else:
                    ls = 'solid'
                if wanted == 'rcrad':
                    plt.plot((LogGnxaxis[1:] + LogGnxaxis[:-1]) / 2.,
                             dcradl / dx,
                             label=labelneed,
                             color=color,
                             lw=2,
                             ls=ls)
                if wanted == 'nismgamma':
                    plt.plot((LogGnxaxis[1:] + LogGnxaxis[:-1]) / 2.,
                             Lgammal / dx,
                             label=labelneed,
                             color=color,
                             lw=2,
                             ls=ls)
                if wanted == 'nismcre':
                    plt.plot((LogGnxaxis[1:] + LogGnxaxis[:-1]) / 2.,
                             crel / dx,
                             label=labelneed,
                             color=color,
                             lw=2,
                             ls=ls)
                if wanted == 'nismcrad':
                    plt.plot((LogGnxaxis[1:] + LogGnxaxis[:-1]) / 2.,
                             dcradl / dx,
                             label=labelneed,
                             color=color,
                             lw=2,
                             ls=ls)
                if wanted == 'nismcrg':
                    plt.plot((LogGnxaxis[1:] + LogGnxaxis[:-1]) / 2.,
                             dcrgl / dx,
                             label=labelneed,
                             color=color,
                             lw=2,
                             ls=ls)
                if wanted == 'nismcrl':
                    plt.plot((LogGnxaxis[1:] + LogGnxaxis[:-1]) / 2.,
                             dcrll / dx,
                             label=labelneed,
                             color=color,
                             lw=2,
                             ls=ls)
        if runtitle == 'SMC' and legendneed == 1:
            plt.legend(loc='best', fontsize=9, ncol=1)
        if trackneed == 0:
            plt.yscale('log')
        if wanted == 'rcrad':
            plt.ylabel(
                r'$\mathrm{d} \dot{E}_{\rm Ad}/\mathrm{d} \log r\;[{\rm erg/s}]$',
                fontsize=16)
            filename = plotloc + 'CRplot/rcrad/rcrad_' + fmeat + '.pdf'
        if wanted == 'nismgamma':
            plt.ylabel(
                r'$\mathrm{d} L_{\gamma}/\mathrm{d} \log (n)[{\rm erg/s}]$',
                fontsize=16)
            filename = plotloc + 'CRplot/nismgamma/nismgamma_' + fmeat + '.pdf'
        if wanted == 'nismcre':
            plt.ylim(ymin=1e48)
            plt.ylabel(
                r'$\mathrm{d} E_{\rm cr}/\mathrm{d} \log (n)[{\rm erg}]$',
                fontsize=16)
            filename = plotloc + 'CRplot/nismcre/nismcre_' + fmeat + '_sn' + str(
                Nsnap) + '.pdf'
        if wanted == 'nismcrad':
            plt.ylabel(
                r'$\mathrm{d} \dot{E}_{\rm Ad}/\mathrm{d} \log (n)[{\rm erg/s}]$',
                fontsize=16)
            filename = plotloc + 'CRplot/nismcrad/nismcrad_' + fmeat + '_sn' + str(
                Nsnap) + '.pdf'
        if wanted == 'nismcrg':
            plt.ylabel(
                r'$\mathrm{d} \dot{E}_{\rm SNe}/\mathrm{d} \log (n)[{\rm erg/s}]$',
                fontsize=16)
            filename = plotloc + 'CRplot/nismcrg/nismcrg_' + fmeat + '_sn' + str(
                Nsnap) + '.pdf'
        if wanted == 'nismcrl':
            plt.ylabel(
                r'$\mathrm{d} \dot{E}_{\rm Loss}/\mathrm{d} \log (n)[{\rm erg/s}]$',
                fontsize=16)
            filename = plotloc + 'CRplot/nismcrl/nismcrl_' + fmeat + '_sn' + str(
                Nsnap) + '.pdf'
        print 'filename', filename
        if wanted == 'rcrad':
            plt.xlabel(r'$\log (r\;[{\rm kpc}])$', fontsize=16)
        else:
            plt.xlabel(r'$\log (n[{\rm cm^{-3}}])$', fontsize=16)
        plt.title(ptitle, fontsize=16)
        plt.tick_params(axis='both',
                        which='both',
                        direction='in',
                        bottom=True,
                        top=True,
                        left=True,
                        right=True,
                        labelsize=16)
        plt.subplots_adjust(left=0.18, bottom=0.15, right=0.95, top=0.9)
        plt.savefig(filename)
        plt.clf()
    return None
Example #2
0
 if wanted == 'crecumz' or wanted == 'crecumr':
     crel = zlist * 0.
 if wanted == 'Begyz':
     Begyl = zlist * 0.
 if wanted == 'ethz':
     ethl = zlist * 0.
 if wanted == 'kez':
     kel = zlist * 0.
 Gm_in_sunl = zlist * 0.
 nooftimes = 0
 Esncr = 1.
 if (wanted == 'crecumz' or wanted == 'crecumr') and normalized == 1:
     Nsnapstring0 = '000'
     S0 = readsnapcr(the_snapdir,
                     Nsnapstring0,
                     4,
                     snapshot_name=the_prefix,
                     extension=the_suffix,
                     havecr=havecr)
     S0mass = np.sum(S0['m'] * 1e10)
     print 'Nsnapstring', Nsnapstring
     S = readsnapcr(the_snapdir,
                    Nsnapstring,
                    4,
                    snapshot_name=the_prefix,
                    extension=the_suffix,
                    havecr=havecr)
     Smass = np.sum(S['m'] * 1e10)
     Esncr = 0.1 * (Smass - S0mass) * 1e51 * 0.01 * (
         1. + massloss)  #total CR energy from SNII in erg
     print 'Esncr', Esncr
 for i in range(startno, Nsnap, snapsep):
Example #3
0
 timestep = info['timestep']
 maindir = info['maindir']
 haveB = info['haveB']
 print 'the_snapdir', the_snapdir
 print 'Nsnapstring', Nsnapstring
 print 'havecr', havecr
 cosmo = info['cosmo']
 if cosmo == 1:
     h0 = 1
 else:
     h0 = 0
 header = readsnapcr(the_snapdir,
                     Nsnapstring,
                     0,
                     snapshot_name=the_prefix,
                     extension=the_suffix,
                     havecr=havecr,
                     h0=h0,
                     cosmological=cosmo,
                     header_only=1)
 ascale = header['time']
 print 'this time', ascale
 thisred = 1. / ascale - 1.
 hubble = header['hubble']
 print 'hubble', hubble
 G = readsnapcr(the_snapdir,
                Nsnapstring,
                0,
                snapshot_name=the_prefix,
                extension=the_suffix,
                havecr=havecr,
Example #4
0
def cratmulttestinput(subdict):
    dirneed = subdict['dirneed']
    wanted = subdict['wanted']
    startno = subdict['startno']
    Nsnap = subdict['Nsnap']
    snapsep = subdict['snapsep']
    the_prefix = subdict['the_prefix']
    the_suffix = subdict['the_suffix']
    fmeat = subdict['fmeat']
    title = 'MW'
    ptitle = 'LSG'
    nolegend = 0

    print 'wanted', wanted
    print 'fmeat', fmeat
    print 'runtodo', dirneed
    print 'startno', startno
    print 'Nsnap', Nsnap
    print 'snapsep', snapsep

    if wanted == 'cratmult':
        plt.figure(figsize=(5, 4))
        normalizedsm = subdict['normalizedsm']
        M1labelneed = subdict['M1labelneed']
        M1runlabelneed = subdict['M1runlabelneed']
        resoneed = subdict['resoneed']
        diffusionsolverneed = subdict['diffusionsolverneed']
        newlabelneed = subdict['newlabelneed']
        strlabelneed = subdict['strlabelneed']
        legendneed = subdict['legendneed']
        runlabelneed = subdict['runlabelneed']
        withincr = subdict['withincr']
        checkcr = subdict['checkcr']
        twolegend = subdict['twolegend']
        print 'twolegend', twolegend
        rateneed = subdict['rateneed']
        #withincr=0
        snon = 1
        coolon = 1
        adon = 1
        numon = subdict['numon']
        stroff = 0
        avetime = 0  #number of time bins
        outputcrout = 0
        ratiocrout_sn = 0
        ratiocrout_sou = subdict['ratiocrout_sou']
        if ratiocrout_sou == 1:
            snon = coolon = adon = numon = 0
        if twolegend == 1:
            import matplotlib.lines as mlines
            lxlist = []
            lslist = []
            dclablist = []
            for icount in range(int(len(dirneed))):
                lineobj = mlines.Line2D([], [])
                lxlist.append(lineobj)
        plotn = 0
        for runtodo in dirneed:
            snaplist = np.array([])
            enclist = np.array([])
            englist = np.array([])
            enllist = np.array([])
            endlist = np.array([])
            enplist = np.array([])
            enalist = np.array([])
            avesfrl = np.array([])
            prel = 0
            preg = 0
            prec = 0
            pred = 0
            prep = 0
            prea = 0
            presm = 0
            presnap = []
            crecuml = []
            crecumg = []
            crecuma = []
            crecumd = []
            crecum = []
            crecump = []
            crecumlout = []
            crecumgout = []
            crecumaout = []
            crecumdout = []
            crecumout = []
            crecumpout = []
            crecumain = []
            totstrll = []
            timel = []
            info = outdirname(runtodo, Nsnap)
            havecr = info['havecr']
            if havecr == 0:
                continue
            for i in range(startno, Nsnap, snapsep):
                info = 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']
                Fcal = info['Fcal']
                iavesfr = info['iavesfr']
                timestep = info['timestep']
                cosmo = info['cosmo']
                exceptcool = info['exceptcool']
                havemetal = info['havemetal']
                the_prefix = info['the_prefix']
                the_suffix = info['the_suffix']
                stron = info['stron']
                newlabel = info['newlabel']
                strlabel = info['strlabel']
                haveB = info['haveB']
                color = info['color']
                usecalstr = info['usecalstr']
                ptitle = title
                labelneed = dclabel
                if newlabelneed == 1:
                    labelneed = "\n".join(wrap(newlabel, 17))
                    if strlabelneed == 1:
                        labelneed = "\n ".join(wrap(strlabel, 40))
                if runtitle == 'SMC':
                    ptitle = 'Dwarf'
                    rin = 6
                elif runtitle == 'SBC':
                    ptitle = 'Starburst'
                    rin = 10
                elif runtitle == 'MW':
                    ptitle = r'$L\star$ Galaxy'
                    rin = 10
                print 'the_snapdir', the_snapdir
                print 'Nsnapstring', Nsnapstring
                print 'havecr', havecr
                print 'exceptcool', exceptcool
                try:
                    if cosmo == 1:
                        G = readsnapcr(the_snapdir,
                                       Nsnapstring,
                                       0,
                                       snapshot_name=the_prefix,
                                       extension=the_suffix,
                                       havecr=havecr,
                                       cosmological=1,
                                       h0=1,
                                       exceptcool=exceptcool,
                                       havemetal=havemetal)
                        header = G['header']
                        timeneed = header[2]
                    else:
                        G = readsnapcr(the_snapdir,
                                       Nsnapstring,
                                       0,
                                       snapshot_name=the_prefix,
                                       extension=the_suffix,
                                       havecr=havecr,
                                       exceptcool=exceptcool,
                                       havemetal=havemetal)
                    Gpos = G['p']
                    Gx = Gpos[:, 0]
                    Gy = Gpos[:, 1]
                    Gz = Gpos[:, 2]
                    Gv = G['v']
                    Gvx = Gv[:, 0]
                    Gvy = Gv[:, 1]
                    Gvz = Gv[:, 2]
                    Grho = G['rho']
                    Gm = G['m'] * 1e10
                    Gu = G['u']
                    Gr = np.sqrt(np.square(Gx) + np.square(Gy) + np.square(Gz))
                    cutr = Gr < rin
                    codetocgs = 1e10 * Msun_in_g * km_in_cm * km_in_cm  #from code unit to erg
                    cregyl = G['cregyl'] * codetocgs
                    cregyg = G['cregyg'] * codetocgs
                    cregy = G['cregy'] * codetocgs
                    cregyd = G['cregyd'] * codetocgs
                    if withincr == 1 or outputcrout == 1 or ratiocrout_sou == 1:
                        cregylout = cregyl[~cutr]
                        cregygout = cregyg[~cutr]
                        cregyout = cregy[~cutr]
                        cregydout = cregyd[~cutr]
                    if withincr == 1:
                        cregyl = cregyl[cutr]
                        cregyg = cregyg[cutr]
                        cregy = cregy[cutr]
                        cregyd = cregyd[cutr]
                    if havecr > 4:
                        cregyp = G['cregyp'] * codetocgs
                        if withincr == 1 or outputcrout == 1 or ratiocrout_sou == 1:
                            cregypout = cregyp[~cutr]
                        if withincr == 1:
                            cregyp = cregyp[cutr]
                    if havecr > 5:
                        cregya = G['cregya'] * codetocgs
                        if withincr == 1 or outputcrout == 1 or ratiocrout_sou == 1:
                            cregyaout = cregya[~cutr]
                        if withincr == 1:
                            cregya = cregya[cutr]
                        if ratiocrout_sou == 1:
                            cregyain = cregya[cutr]
                            cregyain = cregyain[cregyain > 0.]  #take gain only
                    if rateneed == 1 and usecalstr == 1:
                        datastr = calstrloss(G)
                        totstrl = datastr['totstrl']
                except KeyError:
                    print 'KeyError'
                    continue
                if rateneed == 1 and usecalstr == 1:
                    totstrll = np.append(totstrll, totstrl)
                crecum = np.append(crecum, np.sum(cregy))
                crecuml = np.append(crecuml, np.sum(cregyl))
                crecumg = np.append(crecumg, np.sum(cregyg))
                crecumd = np.append(crecumd, np.sum(cregyd))
                if havecr > 4:
                    crecump = np.append(crecump, np.sum(cregyp))
                if havecr > 5:
                    crecuma = np.append(crecuma, np.sum(cregya))
                if withincr == 1 or outputcrout == 1 or ratiocrout_sou == 1:
                    crecumout = np.append(crecumout, np.sum(cregyout))
                    crecumlout = np.append(crecumlout, np.sum(cregylout))
                    crecumgout = np.append(crecumgout, np.sum(cregygout))
                    crecumdout = np.append(crecumdout, np.sum(cregydout))
                    if havecr > 4:
                        crecumpout = np.append(crecumpout, np.sum(cregypout))
                    if havecr > 5:
                        crecumaout = np.append(crecumaout, np.sum(cregyaout))
                if ratiocrout_sou == 1:
                    if havecr > 5:
                        crecumain = np.append(crecumain, np.sum(cregyain))
                print 'cregy', np.sum(cregy)
                print 'cregyp', np.sum(cregyp)
                if cosmo == 1:
                    readtimelist = readtime(firever=2)
                    snap2list = readtimelist['snaplist']
                    time2list = readtimelist['tiimelist']
                    a2list = readtimelist['alist']
                    timenow = np.interp(timeneed, a2list, time2list) * 1e3
                else:
                    timenow = i * 0.98
                    timel = np.append(timel, timenow)
                    prec = np.sum(cregy)
                    prel = np.sum(cregyl)
                    preg = np.sum(cregyg)
                if havecr > 5:
                    prea = np.sum(cregya)
                    pred = np.sum(cregyd)
                    prep = np.sum(cregyp)
            crecumnum = crecum - crecumg - crecuml - crecuma
            if stron == 1:
                crecumpold = crecump
                #crecump = crecumpold - (crecum - crecumg - crecuml - crecumd)
                crecumnum = crecumnum - crecumpold
            if withincr == 1 or outputcrout == 1 or ratiocrout_sou == 1:
                #crecumesc = -crecumout + crecumaout + crecumgout + crecumlout + crecumpout
                crecumesc = -np.array(crecumout) + np.array(
                    crecumaout) + np.array(crecumlout)
            if plotn == 0:
                snelabel = 'Supernovae'
                losslabel = 'Loss'
                crecumalabel = 'Adiabatic'
                strlabel = 'Streaming'
                numlabel = 'Numerical'
                if withincr == 1:
                    esclabel = 'Escape'
                elif outputcrout == 1:
                    esclabel = r'$\dot{E}_{\rm cr,esc}(r\,>$' + str(
                        int(rin)) + 'kpc$)$'
            else:
                snelabel = losslabel = crecumalabel = strlabel = esclabel = '_nolegend_'
            if np.mod(plotn, 4) == 0:
                ls = '-'
            elif np.mod(plotn, 4) == 1:
                ls = 'dashed'
            elif np.mod(plotn, 4) == 2:
                ls = 'dashdot'
            elif np.mod(plotn, 4) == 3:
                ls = 'dotted'
            if rateneed == 1:
                xcr = -(crecum[1:] - crecum[:-1]) / (
                    timel[1:] - timel[:-1]) / 1e6 / yr_in_sec
                xcrg = (crecumg[1:] - crecumg[:-1]) / (
                    timel[1:] - timel[:-1]) / 1e6 / yr_in_sec
                xcrl = (crecuml[1:] - crecuml[:-1]) / (
                    timel[1:] - timel[:-1]) / 1e6 / yr_in_sec
                xcra = (crecuma[1:] - crecuma[:-1]) / (
                    timel[1:] - timel[:-1]) / 1e6 / yr_in_sec
                if stron == 1:
                    if usecalstr == 0:
                        xcrp = (crecump[1:] - crecump[:-1]) / (
                            timel[1:] - timel[:-1]) / 1e6 / yr_in_sec
                    else:
                        xcrp = totstrll[:-1]
                if withincr == 1 or outputcrout == 1 or ratiocrout_sou == 1:
                    xcresc = (crecumesc[1:] - crecumesc[:-1]) / (
                        timel[1:] - timel[:-1]) / 1e6 / yr_in_sec
                if ratiocrout_sou == 1:
                    xcrain = (crecumain[1:] - crecumain[:-1]) / (
                        timel[1:] - timel[:-1]) / 1e6 / yr_in_sec
                xcrn = (crecumnum[1:] - crecumnum[:-1]) / (
                    timel[1:] - timel[:-1]) / 1e6 / yr_in_sec
                timel = (timel[1:] + timel[:-1]) / 2.
            else:
                xcrg = crecumg
                xcrl = crecuml
                xcra = crecuma
                xcr = crecum
                xcrn = crecumnum
                if stron == 1:
                    xcrp = crecump
                if withincr == 1 or outputcrout == 1 or ratiocrout_sou == 1:
                    xcresc = crecumesc
                if ratiocrout_sou == 1:
                    xcrain = crecumain
            if avetime > 1:
                notimebin = len(xcrg)
                noelement = notimebin / avetime
                newelementno = avetime * noelement
                xcrg = xcrg[0:newelementno]
                xcrl = xcrl[0:newelementno]
                xcra = xcra[0:newelementno]
                xcr = xcr[0:newelementno]
                xcrn = xcrn[0:newelementno]
                if stron == 1:
                    xcrp = xcrp[0:newelementno]
                if withincr == 1 or outputcrout == 1:
                    xcresc = xcresc[0:newelementno]
                if ratiocrout_sou == 1:
                    xcrain = xcrain[0:newelementno]
                    timel = timel[0:newelementno]
                    xcrg = np.average(xcrg.reshape((noelement, avetime)),
                                      axis=1)
                    xcrl = np.average(xcrl.reshape((noelement, avetime)),
                                      axis=1)
                    xcra = np.average(xcra.reshape((noelement, avetime)),
                                      axis=1)
                    xcr = np.average(xcr.reshape((noelement, avetime)), axis=1)
                    xcrn = np.average(xcrn.reshape((noelement, avetime)),
                                      axis=1)
                if stron == 1:
                    xcrp = np.average(xcrp.reshape((noelement, avetime)),
                                      axis=1)
                if withincr == 1 or outputcrout == 1:
                    xcresc = np.average(xcresc.reshape((noelement, avetime)),
                                        axis=1)
                if ratiocrout_sou == 1:
                    xcrain = np.average(xcrain.reshape((noelement, avetime)),
                                        axis=1)
                timel = np.average(timel.reshape((noelement, avetime)), axis=1)
            if runlabelneed == 1:
                if ratiocrout_sou == 0:
                    if snon == 1:
                        plt.plot(timel,
                                 xcrg,
                                 lw=2,
                                 ls=ls,
                                 label=labelneed,
                                 color=cmaps.inferno(0.1))
                    if coolon == 1:
                        plt.plot(timel,
                                 xcrl,
                                 lw=2,
                                 ls=ls,
                                 color=cmaps.inferno(0.4))
                    if adon == 1:
                        plt.plot(timel,
                                 xcra,
                                 lw=2,
                                 ls=ls,
                                 color=cmaps.inferno(0.7))
                    if checkcr == 1:
                        plt.plot(timel, xcr, lw=2, ls=ls, color='k')
                    if stron == 1 and stroff == 0:
                        plt.plot(timel,
                                 xcrp,
                                 lw=2,
                                 ls=ls,
                                 color=cmaps.inferno(0.9))
                    if numon == 1:
                        plt.plot(timel, xcrp, lw=2, ls=ls, color='g')
                    if (withincr == 1 or outputcrout == 1
                        ) and ratiocrout_sn == 0 and ratiocrout_sou == 0:
                        plt.plot(timel, xcresc, lw=2, ls=ls, color='m')
                if ratiocrout_sn == 1:
                    plt.plot(timel,
                             np.absolute(xcresc / xcrg),
                             lw=2,
                             ls=ls,
                             label=labelneed,
                             color='k')
                if ratiocrout_sou == 1:
                    ls = 'solid'
                    if haveB > 0:
                        ls = 'dashed'
                    plt.plot(timel,
                             np.absolute(xcresc / (xcrg + xcrain + xcrn)),
                             lw=2,
                             ls=ls,
                             label=labelneed,
                             color=color)
            else:
                if ratiocrout_sou == 0:
                    if snon == 1:
                        plt.plot(timel,
                                 xcrg,
                                 lw=2,
                                 ls=ls,
                                 label=snelabel,
                                 color=cmaps.inferno(0.1))
                    if coolon == 1:
                        plt.plot(timel,
                                 xcrl,
                                 lw=2,
                                 ls=ls,
                                 label=losslabel,
                                 color=cmaps.inferno(0.4))
                    if adon == 1:
                        plt.plot(timel,
                                 xcra,
                                 lw=2,
                                 ls=ls,
                                 label=crecumalabel,
                                 color=cmaps.inferno(0.7))
                    if checkcr == 1:
                        plt.plot(timel, xcr, lw=2, ls=ls, color='k')
                    if stron == 1 and stroff == 0:
                        plt.plot(timel,
                                 xcrp,
                                 lw=2,
                                 ls=ls,
                                 label=strlabel,
                                 color=cmaps.inferno(0.9))
                    if numon == 1:
                        plt.plot(timel,
                                 xcrn,
                                 lw=2,
                                 ls=ls,
                                 label=numlabel,
                                 color='g')
                    if (withincr == 1 or outputcrout == 1
                        ) and ratiocrout_sn == 0 and ratiocrout_sou == 0:
                        plt.plot(timel,
                                 xcresc,
                                 lw=2,
                                 ls=ls,
                                 label=esclabel,
                                 color='m')
                if ratiocrout_sn == 1:
                    plt.plot(timel,
                             np.absolute(xcresc / xcrg),
                             lw=2,
                             ls=ls,
                             color='k')
                if ratiocrout_sou == 1:
                    ls = 'solid'
                    if haveB > 0:
                        ls = 'dashed'
                    plt.plot(timel,
                             np.absolute(xcresc / (xcrg + xcrain + xcrn)),
                             lw=2,
                             ls=ls,
                             color=color)
                if twolegend == 1:
                    lxlist[plotn] = mlines.Line2D([], [],
                                                  color='r',
                                                  ls=ls,
                                                  label=dclabel)
                    lslist = np.append(lslist, ls)
                    dclablist = np.append(dclablist, labelneed)
            plotn += 1
    if legendneed == 1:
        if runlabelneed == 1:
            plt.legend(loc='best', ncol=2, fontsize=10)
        else:
            if twolegend == 1:
                legend1 = plt.legend(lxlist,
                                     dclablist,
                                     loc=2,
                                     fontsize=8,
                                     ncol=2)
                plt.gca().add_artist(legend1)
                plt.legend(loc=1, fontsize=8)
            else:
                plt.legend(loc='best', ncol=2, fontsize=10)
    if rateneed == 1:
        plt.ylabel(r'$ \dot{E}_{\rm cr} [ {\rm erg/s}]$', fontsize=18)
    else:
        plt.ylabel(r'${\rm CR\; energy\; [ erg}]$', fontsize=18)
    if ratiocrout_sn == 1 and rateneed == 1:
        plt.ylabel(r'$\dot{E}_{\rm esc}/\dot{E}_{\rm SN}$', fontsize=18)
    if ratiocrout_sn == 1 and rateneed == 0:
        plt.ylabel(r'$E_{\rm esc}/E_{\rm SN}$', fontsize=18)
    if ratiocrout_sou == 1 and rateneed == 1:
        plt.ylabel(r'$\dot{E}_{\rm esc}/\dot{E}_{\rm source}$', fontsize=18)
    if ratiocrout_sou == 1 and rateneed == 0:
        plt.ylabel(r'$E_{\rm esc}/E_{\rm source}$', fontsize=18)
    if rateneed == 1 and ratiocrout_sn == 0 and ratiocrout_sou == 0:
        if runtitle == 'SMC':
            #plt.ylim(ymax=2.3e39,ymin=-2.3e39)
            plt.ylim(ymax=2.3e39, ymin=-1.0e39)
        if runtitle == 'MW':
            #plt.ylim(ymax=2.5e41,ymin=-2.5e41)
            plt.ylim(ymax=2.7e41, ymin=-1.2e41)
        if runtitle == 'SBC':
            #plt.ylim(ymax=4.4e41,ymin=-4.4e41)
            plt.ylim(ymax=4.4e41, ymin=-3.0e41)
    if ratiocrout_sn == 1 or ratiocrout_sou == 1:
        if rateneed == 1:
            plt.ylim(ymin=0.0, ymax=1.5)
        else:
            plt.ylim(ymin=0.0, ymax=1.1)
    plt.xlabel(r'$t [{\rm Myr}]$', fontsize=18)
    plt.tick_params(axis='both',
                    which='both',
                    direction='in',
                    bottom=True,
                    top=True,
                    left=True,
                    right=True,
                    labelsize=16)
    plt.title(ptitle, fontsize=16)
    fnsuffix = ''
    if withincr == 1:
        fnsuffix = '_withinr'
    if outputcrout == 1:
        fnsuffix = '_outputcrout'
    if ratiocrout_sn == 1:
        fnsuffix = '_ratiocrout_sn'
    if ratiocrout_sou == 1:
        fnsuffix = '_ratiocrout_sou'
    if rateneed == 1:
        filename = plotloc + 'CRplot/cratmult/' + fmeat + '_rate' + fnsuffix + '.pdf'
    else:
        filename = plotloc + 'CRplot/cratmult/' + fmeat + '_time' + fnsuffix + '.pdf'
    print 'filename', filename
    plt.subplots_adjust(left=0.18, bottom=0.15, right=0.95, top=0.9)
    plt.savefig(filename)
    plt.clf()
    return None
Example #5
0
def crecumrtestinput(subdict):
        dirneed=subdict['dirneed']
        wanted=subdict['wanted']
        startno=subdict['startno']
        Nsnap=subdict['Nsnap']
        snapsep=subdict['snapsep']
        the_prefix=subdict['the_prefix']
        the_suffix=subdict['the_suffix']
        fmeat=subdict['fmeat']
        withinr=15.0
        nogrid=40
        maxlength=10.0
        print 'wanted', wanted
        print 'fmeat', fmeat
        print 'runtodo', dirneed


        if wanted=='gmz' or wanted=='crecumz' or wanted=='crecumr' or wanted=='Begyz' or wanted=='ethz' or wanted=='kez':
            plt.figure(figsize=(5,4))
            withinr=100.0
            minlength=0.5
            maxlength=100.
            nogrid=500
            normalized =1
            newlabelneed=subdict['newlabelneed']
            legendneed=subdict['legendneed']
            strlabelneed=subdict['strlabelneed']
            massloss=0.3
            rotface=0
            for runtodo in dirneed:
                info=outdirname(runtodo, Nsnap)
                havecr = info['havecr']
                haveB = info['haveB']
                Nsnapstring = info['Nsnapstring']
                the_prefix = info['the_prefix']
                the_suffix = info['the_suffix']
                the_snapdir = info['the_snapdir']
                cosmo = info['cosmo']
                if wanted=='crecumz':
                    if havecr==0:
                        continue
                if wanted=='Begyz':
                    if haveB==0:
                        continue
                zlist=np.linspace(minlength,maxlength,num=nogrid)
                if wanted=='crecumz' or wanted=='crecumr':
                    crel=zlist*0.
                if wanted=='Begyz':
                    Begyl=zlist*0.
                if wanted=='ethz':
                    ethl = zlist*0.
                if wanted=='kez':
                    kel = zlist*0.
                Gm_in_sunl=zlist*0.
                nooftimes=0
                Esncr=1.
                if (wanted=='crecumz' or wanted=='crecumr') and normalized == 1:
                    Nsnapstring0 = '000'
                    S0 = readsnapcr(the_snapdir, Nsnapstring0, 4, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr)
                    S0mass = np.sum(S0['m']*1e10)
                    print 'Nsnapstring', Nsnapstring
                    S = readsnapcr(the_snapdir, Nsnapstring, 4, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr)
                    Smass = np.sum(S['m']*1e10)
                    Esncr = 0.1*(Smass-S0mass)*1e51*0.01*(1.+massloss) #total CR energy from SNII in erg
                    print 'Esncr', Esncr
                for i in range(startno,Nsnap,snapsep):
                    info=outdirname(runtodo, i)
                    M1speed=info['M1speed']
                    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']
                    Fcal=info['Fcal']
                    avesfr=info['iavesfr']
                    timestep=info['timestep']
                    haveB=info['haveB']
                    havecr = info['havecr']
                    color=info['color']
                    newlabel=info['newlabel']
                    strlabel=info['strlabel']
                    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)) 
                    if strlabelneed==1:
                        labelneed="\n".join(wrap(strlabel,17)) 
                    print 'labelneed,newlabel', labelneed,newlabel
                    if cosmo==1:
                        loccen=0;
                    else:
                        loccen=1;
                    G = readsnapfromrun(runtodo,Nsnap,0,rotface=rotface,loccen=loccen)
                    Gp = G['p']
                    Gv = G['v']
                    Gu = G['u']
                    Gm = G['m']
                    Grho = G['rho']
                    if wanted=='crecumz' or wanted=='crecumr':
                        cregy = G['cregy']
                        print 'CR energy in erg', np.sum(cregy)*1e10*Msun_in_g*km_in_cm*km_in_cm
                    if wanted=='Begyz':
                        Bfield = G['B']
                        Bx = Bfield[:,0]
                        By = Bfield[:,1]
                        Bz = Bfield[:,2]
                        B2 = Bx*Bx+By*By+Bz*Bz
                        Begy = B2/8./np.pi*Gm/Grho*kpc_in_cm*kpc_in_cm*kpc_in_cm
                    if wanted=='kez':
                        Gvx = Gv[:,0]
                        Gvy = Gv[:,1]
                        Gvz = Gv[:,2]
                        ke = 0.5*Gm*(Gvx*Gvx+Gvy*Gvy+Gvz*Gvz)*1e10*Msun_in_g*km_in_cm*km_in_cm
                    Gz = Gp[:,2]
                    Gx = Gp[:,0]
                    Gy = Gp[:,1]
                    dz = maxlength/nogrid
                    if normalized==1:
                        cutxy = Gx*Gx+Gy*Gy < withinr
                        cutz = np.absolute(Gz)<dz*nogrid
                        cut= cutxy*cutz
                        Gmtot = np.sum(Gm[cut]*1e10)
                    for iz in range(nogrid):
                        if wanted=='crecumr':
                            cut = np.sqrt(Gx*Gx+Gy*Gy+Gz*Gz)<zlist[iz]
                        else:
                            cutxy = Gx*Gx+Gy*Gy < withinr
                            cutz = np.absolute(Gz)<zlist[iz]
                            cut = cutxy*cutz
                            Gmcut = Gm[cut]
                            Gm_in_sun = Gmcut*1e10
                        if wanted=='crecumz' or wanted=='crecumr':
                            cregycut = cregy[cut]*1e10*Msun_in_g*km_in_cm*km_in_cm
                            crel[iz] += np.sum(cregycut)
                        if wanted=='Begyz':
                            Begycut = Begy[cut]
                            Begyl[iz] += np.sum(Begycut)
                        if wanted=='ethz':
                            ethcut = Gu[cut]*km_in_cm*km_in_cm*Gm_in_sun*Msun_in_g
                            ethl[iz] += np.sum(ethcut)
                        if wanted=='kez':
                            kecut = ke[cut]
                            kel[iz] += np.sum(kecut)
                            Gm_in_sunl[iz] += np.sum(Gm_in_sun)
                    nooftimes+=1
                if wanted=='crecumz' or wanted=='crecumr':
                    crel=crel/nooftimes
                if wanted=='Begyz':
                    Begyl=Begyl/nooftimes
                if wanted=='ethz':
                    ethl=ethl/nooftimes
                if wanted=='kez':
                    kel=kel/nooftimes
                Gm_in_sunl=Gm_in_sunl/nooftimes
                if haveB==0:
                    lsn='solid'
                else:
                    lsn='dashed'
                if wanted == 'gmz':
                    if normalized==0:
                        plt.plot(zlist, Gm_in_sunl, label=labelneed, ls=lsn,lw=2,color=color)
                    else:
                        plt.plot(zlist, Gm_in_sunl/Gmtot/(1.+massloss), label=labelneed, ls=lsn,lw=2,color=color)
                if wanted == 'crecumz' or wanted=='crecumr':
                    plt.plot(zlist, crel/Esncr, label=labelneed, ls=lsn,lw=2,color=color)
                if wanted == 'Begyz':
                    plt.plot(zlist, Begyl, label=labelneed, ls=lsn,lw=2,color=color)
                    if wanted == 'ethz':
                                plt.plot(zlist, ethl, label=labelneed, ls=lsn,lw=2,color=color)
                if wanted == 'kez':
                    plt.plot(zlist, kel, label=labelneed, ls=lsn,lw=2,color=color)
        plt.yscale('log')
        plt.xscale('log')
        if wanted=='crecumr':
                    plt.xlabel(r'$r\; [{\rm kpc}]$',fontsize=18)
        else:
            plt.xlabel(r'$z\; [{\rm kpc}]$',fontsize=18)
        if wanted == 'gmz':
            if normalized==1:
                plt.ylabel(r'$M_{\rm gas}(<z)/M_0$',fontsize=18)
            else:
                plt.ylabel(r'$M_{\rm gas}(<z) [ M_\odot]$',fontsize=18)
            if runtitle=='SMC' and legendneed==1:
                #plt.legend(loc=2,fontsize=8,ncol=3,frameon=False)
                plt.legend(loc=4,fontsize=8,ncol=3)
        if wanted == 'crecumz' or wanted=='crecumr':
            if normalized==1:
                plt.ylabel(r'$E_{\rm cr}(<z)/E_{\rm cr,SN}(tot)$',fontsize=18)
            else:
                plt.ylabel(r'$E_{\rm cr}(<z)\;[{\rm erg}]$',fontsize=18)
            if wanted=='crecumr':
                if normalized==1:
                    plt.ylabel(r'$E_{\rm cr}(<r)/E_{\rm cr,SN}(tot)$',fontsize=18)
                else:   
                    plt.ylabel(r'$E_{\rm cr}(<r)\;[{\rm erg}]$',fontsize=18)
                if runtitle=='SMC' and legendneed==1:
                        #plt.legend(loc=2,fontsize=8,ncol=3,frameon=False)
                        plt.legend(loc=4,fontsize=8,ncol=3)
        if wanted == 'Begyz':
            plt.ylabel(r'$E_{\rm B}(<z)\;[{\rm erg}]$',fontsize=18)
            if wanted == 'ethz':
                    plt.ylabel(r'$E_{\rm th}(<z)\;[{\rm erg}]$',fontsize=18)
            if wanted == 'kez':
                    plt.ylabel(r'$E_{\rm KE}(<z)\;[{\rm erg}]$',fontsize=18)
        plt.tight_layout()
        if wanted == 'gmz':
            if normalized==0:
                filename = plotloc+'CRplot/gmz/gasmass_'+fmeat+'_sn'+str(startno)+'_'+str(Nsnap)+'.pdf'
            else:
                filename = plotloc+'CRplot/gmz/gasmass_'+fmeat+'_sn'+str(startno)+'_'+str(Nsnap)+'_normal.pdf'
        if wanted == 'crecumz':
            filename = plotloc+'CRplot/crecumz/crecumz_'+fmeat+'_sn'+str(startno)+'_'+str(Nsnap)+'.pdf'
        if wanted == 'crecumr':
                    filename = plotloc+'CRplot/crecumr/crecumr_'+fmeat+'_sn'+str(startno)+'_'+str(Nsnap)+'.pdf'
        if wanted == 'Begyz':
                    filename = plotloc+'CRplot/Begyz/Begyz_'+fmeat+'_sn'+str(startno)+'_'+str(Nsnap)+'.pdf'
        if wanted == 'ethz':
                    filename = plotloc+'CRplot/ethz/ethz_'+fmeat+'_sn'+str(startno)+'_'+str(Nsnap)+'.pdf'
        if wanted == 'kez':
                    filename = plotloc+'CRplot/kez/kez_'+fmeat+'_sn'+str(startno)+'_'+str(Nsnap)+'.pdf'
        print 'filename', filename
        plt.tick_params(axis='both', which='both',direction='in',bottom=True,top=True,left=True,right=True,labelsize=16)
        plt.subplots_adjust(left  = 0.18, bottom=0.15, right=0.95, top=0.9)
        plt.title(ptitle, fontsize=16)
        plt.savefig(filename)
        plt.clf()
        return None
Example #6
0
 if runtitle=='SMC':
     ptitle='Dwarf'
     rin = 6 
 elif runtitle=='SBC':
     ptitle='Starburst'
     rin = 10
 elif runtitle=='MW':
     ptitle=r'$L\star$ Galaxy'
     rin = 10
 print 'the_snapdir', the_snapdir
 print 'Nsnapstring', Nsnapstring
 print 'havecr', havecr
 print 'exceptcool', exceptcool
 try:
     if cosmo==1:
             G = readsnapcr(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr, cosmological=1,h0=1,exceptcool=exceptcool,havemetal=havemetal)
             header=G['header']
             timeneed=header[2]
     else:
             G = readsnapcr(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr,exceptcool=exceptcool, havemetal=havemetal)
     Gpos = G['p']
     Gx = Gpos[:,0]
     Gy = Gpos[:,1]
     Gz = Gpos[:,2]
     Gv = G['v']
     Gvx = Gv[:,0]
     Gvy = Gv[:,1]
     Gvz = Gv[:,2]
     Grho = G['rho']
     Gm = G['m']*1e10
     Gu = G['u']
def gammasfrsnaptestinpput(subdict):
        dirneed=subdict['dirneed']
        wanted=subdict['wanted']
        startno=subdict['startno']
        Nsnap=subdict['Nsnap']
        snapsep=subdict['snapsep']
        the_prefix=subdict['the_prefix']
        the_suffix=subdict['the_suffix']
        fmeat=subdict['fmeat']


        if wanted=='dirgammasfr' or wanted=='dirgamma' or wanted=='dirsfr' or wanted=='dirsm':
            plt.figure(figsize=(5,4))
            Rfrac=0.25
            #Rfrac=0.03
            xaxis_snapno=0
            normalizedsm=subdict['normalizedsm']
            M1labelneed=subdict['M1labelneed']
            M1runlabelneed=subdict['M1runlabelneed']
            resoneed=subdict['resoneed']
            diffusionsolverneed=subdict['diffusionsolverneed']
            newlabelneed=subdict['newlabelneed']
            strlabelneed=subdict['strlabelneed']
            showstarburst=subdict['showstarburst']
            legendneed=subdict['legendneed']
            correctIa=subdict['correctIa']
            refereelabelneed=subdict['refereelabelneed']
            for runtodo in dirneed:
                print 'runtodo', runtodo
                snaplist=[]
                enclist=[]
                englist=[]
                enllist=[]
                sml=[]
                diskml=[]
                bulgeml=[]
                nsml=[]
                timel=[]
                Lgcalist=[]
                pretime=0
                presnap=startno
                havecr=0
                if wanted=='dirgammasfr' or wanted=='dirgamma':     
                    info=outdirname(runtodo, Nsnap)
                    havecr=info['havecr']
                    if havecr==0:
                        continue
                for i in range(startno,Nsnap, snapsep):
                    info=outdirname(runtodo, i)
                    rundir=info['rundir']
                    maindir=info['maindir']
                    halostr=info['halostr']
                    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']
                    Fcal=info['Fcal']
                    iavesfr=info['iavesfr']
                    timestep=info['timestep']
                    cosmo=info['cosmo']
                    color=info['color']
                    withinRv=info['withinRv']
                    usepep=info['usepep']
                    beginno=info['beginno']
                    finalno=info['finalno']
                    firever=info['firever']     
                    initsnap=info['initsnap']   
                    haveB=info['haveB']
                    M1speed=info['M1speed']
                    Rvirguess=info['Rvir']
                    newlabel=info['newlabel']
                    strlabel=info['strlabel']
                    labelneed=dclabel
                    if newlabelneed==1:
                        labelneed="\n".join(wrap(newlabel,17))
                    if strlabelneed==1:
                        labelneed="\n".join(wrap(strlabel,40))
                    ptitle=title
                    if runtitle=='SMC':
                        ptitle='Dwarf'
                    elif runtitle=='SBC':
                        ptitle='Starburst'
                    elif runtitle=='MW':
                        ptitle=r'$L\star$ Galaxy'
                    if cosmo==0:
                        inittime=initsnap
                    else:
                        inittime=0
                    print 'set initial time'    
                    print 'the_snapdir', the_snapdir
                    print 'Nsnapstring', Nsnapstring
                    print 'havecr', havecr
                    print 'withinRv', withinRv
                    print 'cosmo', cosmo
                    try:
                        if cosmo==1:
                            G = readsnapcr(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr,h0=1,cosmological=1)
                            S = readsnapcr(the_snapdir, Nsnapstring, 4, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr,h0=1,cosmological=1)
                            if correctIa==1:
                                Disk = readsnapcr(the_snapdir, Nsnapstring, 2, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr,h0=1,cosmological=1)
                                Bulge = readsnapcr(the_snapdir, Nsnapstring, 3, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr,h0=1,cosmological=1)
                        else:
                            G = readsnapcr(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr)
                            S = readsnapcr(the_snapdir, Nsnapstring, 4, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr)
                            if correctIa==1:
                                Disk = readsnapcr(the_snapdir, Nsnapstring, 2, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr)
                                Bulge = readsnapcr(the_snapdir, Nsnapstring, 3, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr)
                        if havecr>4:
                            cregyl = G['cregyl']*1e10*solar_mass_in_g*km_in_cm*km_in_cm #in erg (originally in code unit: 1e10Msun*(km/s)^2)
                            cregyg = G['cregyg']*1e10*solar_mass_in_g*km_in_cm*km_in_cm
                        if havecr > 0:
                            cregy_codeunit = G['cregy']
                            cregy  = cregy_codeunit*1e10*solar_mass_in_g*km_in_cm*km_in_cm
                        Grho = G['rho']
                        Neb = G['ne']
                    except KeyError:
                        print 'Keyerror'
                        break
                    try:
                        header=S['header']
                        timeneed=header[2]
                        print 'timeneed', timeneed
                        Smi=S['m']
                        Sage=S['age']
                        if withinRv ==1 and cosmo==1:
                            Sp = S['p']
                            Sx = Sp[:,0]
                            Sy = Sp[:,1]
                            Sz = Sp[:,2]
                            header=readsnapcr(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr,h0=1,cosmological=1,header_only=1)
                            h0 = header['hubble']
                            atime = header['time']
                            if usepep==1:
                                halosA = SF.read_halo_history_pep(rundir, finalno, beginno=beginno,\
                                 singlesnap=0, firever=firever,halonostr=halostr, hubble=h0, comoving=1, maindir=maindir)
                                afactor=atime
                            else:
                                halosA = SF.read_halo_history(rundir, maindir=maindir, halonostr=halostr, hubble=h0, comoving=0)
                                afactor=1.0
                            redlist = halosA['redshift']
                            haloid = halosA['ID']
                            a_scale = 1.0/(1.0+redlist)
                            xcenl = halosA['x']*afactor
                            ycenl = halosA['y']*afactor
                            zcenl = halosA['z']*afactor
                            Rvirl = halosA['R']*afactor
                            xcen = np.interp(atime,a_scale,xcenl)
                            ycen = np.interp(atime,a_scale,ycenl)
                            zcen = np.interp(atime,a_scale,zcenl)
                            Rvir = np.interp(atime,a_scale,Rvirl)
                            Sxrel = Sx-xcen
                            Syrel = Sy-ycen
                            Szrel = Sz-zcen
                            Sr = np.sqrt(Sxrel*Sxrel+Syrel*Syrel+Szrel*Szrel)
                            cutrvs = Sr<Rvir*Rfrac
                            Smi = Smi[cutrvs]
                            Sage = Sage[cutrvs]
                        Sm = np.sum(Smi)*1e10 #in solar mass
                        tcut=Sage>pretime
                        Nsm = np.sum(Smi[tcut])*1e10
                        if correctIa==1:
                            diskm = np.sum(Disk['m'])*1e10
                            bulgem = np.sum(Bulge['m'])*1e10
                    except KeyError:
                        print 'key error'
                        Sm = 0.
                        Nsm = 0.
                        timeneed=0
                        if correctIa==1:
                            diskm = 0.
                            bulgem = 0.
                    if withinRv ==1:
                        Gp = G['p']
                        Gx = Gp[:,0]
                        Gy = Gp[:,1]
                        Gz = Gp[:,2]
                        header=readsnapcr(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr,h0=1,cosmological=1,header_only=1)
                        h0 = header['hubble']
                        atime = header['time']
                        if cosmo==1:
                            if usepep==1:
                                halosA = SF.read_halo_history_pep(rundir, finalno,\
                                beginno=beginno, singlesnap=0, firever=firever,halonostr=halostr,\
                                hubble=h0, comoving=1, maindir=maindir, snapsep=snapsep)
                                afactor=atime
                            else:
                                halosA = SF.read_halo_history(rundir, maindir=maindir, halonostr=halostr, hubble=h0, comoving=0)
                                afactor=1.0
                            redlist = halosA['redshift']
                            haloid = halosA['ID']
                            a_scale = 1.0/(1.0+redlist)
                            xcenl = halosA['x']*afactor
                            ycenl = halosA['y']*afactor
                            zcenl = halosA['z']*afactor
                            Rvirl = halosA['R']*afactor
                            xcen = np.interp(atime,a_scale,xcenl)
                            ycen = np.interp(atime,a_scale,ycenl)
                            zcen = np.interp(atime,a_scale,zcenl)
                            Rvir = np.interp(atime,a_scale,Rvirl)
                        else:
                            xcen=0
                            ycen=0
                            zcen=0
                            Rvir=Rvirguess
                        Gxrel = Gx-xcen
                        Gyrel = Gy-ycen
                        Gzrel = Gz-zcen
                        Gr = np.sqrt(Gxrel*Gxrel+Gyrel*Gyrel+Gzrel*Gzrel)
                        cutrv = Gr<Rvir*Rfrac
                        Grho = Grho[cutrv]
                        Neb = Neb[cutrv]
                        if havecr>0:
                            cregy = cregy[cutrv]
                            cregy_codeunit = cregy_codeunit[cutrv]
                            if havecr>4:
                                    cregyl = cregyl[cutrv]
                                    cregyg = cregyg[cutrv]
                    if cosmo==1:
                            readtimelist=readtime(firever=2)
                            snap2list=readtimelist['snaplist']
                            time2list=readtimelist['timelist']
                            a2list=readtimelist['alist']
                            tnow = np.interp(timeneed,a2list,time2list)*1e9
                            pret = np.interp(pretime,a2list,time2list)*1e9
                    if havecr>4:
                        cregygt=np.sum(cregyg)
                        cregylt=np.sum(cregyl)
                    if havecr>0:
                        cregyt =np.sum(cregy)
                        Lout = outLgamma_nism(Grho,Neb,cregy_codeunit)
                        Lgcal = np.sum(Lout['Lgamma'])
                        print 'Lgcal', Lgcal
                    snaplist.append(float(i))
                    if cosmo==1:
                        timel.append(tnow)
                    else:
                        timel.append(float(i)*0.98*1e6)
                    if havecr>0:
                        enclist.append(cregyt)
                    if havecr>4:
                        englist.append(cregygt)
                        enllist.append(cregylt)
                    if havecr>0:
                        Lgcalist.append(Lgcal)
                    sml.append(Sm)
                    if correctIa==1:
                        diskml.append(diskm)
                        bulgeml.append(bulgem)
                    nsml.append(Nsm)
                    pretime=timeneed
                    del G, S
                sml=np.array(sml)
                if correctIa==1:
                    diskml=np.array(diskml)
                    bulgeml=np.array(bulgeml)
                nsml=np.array(nsml)
                if havecr>0:
                    enclist=np.array(enclist)
                if havecr>4:
                    englist=np.array(englist)
                    enllist=np.array(enllist)
                snaplist=np.array(snaplist)
                if havecr>0:
                    Lgcalist=np.array(Lgcalist)
                timel=np.array(timel) #in yr
                #above is the coefficient for Salpeter only; for Kroupa, the coefficient is 50% larger:
                avesfrl=(nsml[1:])/(timel[1:]-timel[:-1]) #in Msun/yr
                print 'nsml',nsml
                print 'avesfrl', avesfrl
                Lsfr = Kroupa_Lsf*avesfrl*solar_mass_in_g/yr_in_sec*cspeed_in_cm_s*cspeed_in_cm_s #times 1.5? 6.2e-4 for Kroupa 3.8e-4 for Salpeter
                if correctIa==1:
                    IaeffSFR=5.3e-8/3.0e-4*(sml[1:]+diskml[1:]+bulgeml[1:])/0.03753/1e9
                    print 'IaeffSFR', IaeffSFR
                    LsfrnoIa = Kroupa_Lsf*(avesfrl+IaeffSFR)*solar_mass_in_g/yr_in_sec*cspeed_in_cm_s*cspeed_in_cm_s
                print 'Lsfr', Lsfr
                print 'timel', timel
                if havecr>4:
                    Lgamma = (enllist[1:]-enllist[:-1])/((timel[1:]-timel[:-1])*yr_in_sec)/(hadronicdecayrate+coulombdecayrate)*hadronicdecayrate*betapi/nopi_per_gamma
                    Lgamma_sfr = Lgamma/Lsfr
                if havecr>0:
                    Lgcal_sfr = Lgcalist[1:]/Lsfr
                if correctIa==1:
                    Lgamma_sfr_noIa = Lgamma/LsfrnoIa
                if haveB>0:
                    lsn='dashed'
                else:
                    lsn='solid'
                if M1labelneed>1 or M1runlabelneed==1:
                    if M1speed>499:
                        lsn='solid'
                    if M1speed>999:
                        lsn='dashed'
                    if M1speed>1999:
                        lsn='dashdot'
                    if M1speed>3999:
                        lsn='dotted'
                if M1labelneed==1:
                    if M1speed>499:
                            labelneed=r'$\tilde{c}=500$'
                    if M1speed>999:
                            labelneed=r'$\tilde{c}=1000$'
                    if M1speed>1999:
                            labelneed=r'$\tilde{c}=2000$'
                    if M1speed>3999:
                            labelneed=r'$\tilde{c}=4000$'

                if resoneed==1:
                    if resolabel=='llr':
                        labelneed='Lowest res'
                        lsn = 'solid'
                    if resolabel=='lr':
                        labelneed='Low res'
                        lsn = 'dashed'
                    if resolabel=='mr':
                        labelneed='Standard res'
                        lsn = 'dashdot'
                if diffusionsolverneed==1:
                    if runtodo=='bwmwlrdc27ds':
                        labelneed='Zeroth moment'
                        lsn = 'dashed'
                    else:
                        labelneed='Two moment'
                        lsn = 'solid'
                if refereelabelneed==1:
                    if runtodo=='bwsmclrdc28mhdref' or runtodo=='bwmwlrdc28mhdref':
                        labelneed='Modified'
                    else:
                        labelneed='Original'
                    
                if xaxis_snapno==1:
                    xaxisl = snaplist[1:]
                    xlab = 'snapshot number'
                else:
                    xaxisl = timel[1:]/1e6+inittime
                    xlab = 'Myr'
                if showstarburst==1 and runtitle=='SBC':
                    if runtodo=='bwsbclr':
                        pstartno=600
                    if runtodo=='bwsbclrdc0':
                        pstartno=590
                    if runtodo=='bwsbclrdc27':
                        pstartno=440
                    if runtodo=='bwsbclrdc28':
                        pstartno=505
                    if runtodo=='bwsbclrdc29':
                        pstartno=370
                print 'labelneed', labelneed
                if wanted=='dirgammasfr':
                    if havecr>4:
                        #plt.plot(xaxisl, np.absolute(Lgamma_sfr),  color=color,ls=lsn,lw=2, label=labelneed)
                        if (M1labelneed==1 and color=='r'):
                            plt.plot(xaxisl, np.absolute(Lgamma_sfr),  color=color,ls=lsn,lw=2)
                        elif (M1labelneed==2 and lsn=='solid'):
                            plt.plot(xaxisl, np.absolute(Lgamma_sfr),  color=color,ls=lsn,lw=2, label=labelneed)
                        else:
                            plt.plot(xaxisl, np.absolute(Lgamma_sfr),  color=color,ls=lsn,lw=2, label=labelneed)
                        #print 'M1speed', M1speed
                        print 'Lgamma_sfr', Lgamma_sfr
                    elif havecr>0:
                        plt.plot(xaxisl, np.absolute(Lgcal_sfr), color=color,ls=lsn,lw=2, label=labelneed)
                        print 'Lgcal_sfr', Lgcal_sfr
                    if correctIa==1 and havecr>0:
                        plt.plot(xaxisl, np.absolute(Lgamma_sfr_noIa),ls=lsn,lw=2, color=color)
                        print 'Lgamma_sfr_noIa', Lgamma_sfr_noIa
                if wanted=='dirgamma':
                    if havecr>4:
                        plt.plot(xaxisl, np.absolute(Lgamma),  color=color,ls=lsn,lw=2, label=labelneed)
                    elif havecr>0:
                        plt.plot(xaxisl, np.absolute(Lgcalist[1:]), color=color,ls=lsn,lw=2, label=labelneed)
                if wanted=='dirsfr':
                    if M1labelneed==1 and color=='r':
                        plt.plot(xaxisl, np.absolute(avesfrl), color=color,ls=lsn,lw=2)
                    elif M1speed<501 and (M1runlabelneed==1 or M1labelneed==1):
                        plt.plot(xaxisl, np.absolute(avesfrl), color=color,ls=lsn,lw=2, label=labelneed)
                    else:
                        plt.plot(xaxisl, np.absolute(avesfrl), color=color,ls=lsn,lw=2, label=labelneed)
                    if showstarburst==1 and runtitle=='SBC':
                        plt.axvline(x=pstartno, color=color,ls=lsn,lw=1)
                if wanted=='dirsm':
                    if M1labelneed==1 and color=='r':
                        if normalizedsm==1:
                            plt.plot(xaxisl, sml[:-1]-sml[0], color=color,ls=lsn,lw=2)
                        else:
                            plt.plot(xaxisl, sml[1:], color=color,ls=lsn,lw=2)
                    else:
                        if normalizedsm==1:
                                plt.plot(xaxisl, sml[:-1]-sml[0], color=color,ls=lsn,lw=2, label=labelneed)
                        else:
                                plt.plot(xaxisl, sml[1:], color=color,ls=lsn,lw=2, label=labelneed)
                    if showstarburst==1 and runtitle=='SBC':
                            plt.axvline(x=pstartno, color=color,ls='dashed',lw=1)
                if wanted=='dirgammasfr':
                    plt.axhline(y=0.0002,ls='--',color='k')
                    plt.yscale('log')
                    if runtitle=='SMC' and legendneed==1:
                        plt.legend(loc='best', fontsize=8)
                    elif legendneed==1 and M1runlabelneed==1:
                        plt.legend(loc='best', fontsize=8,ncol=2)
                    plt.xlabel(xlab, fontsize=16)
                    plt.ylabel(r'$L_{\gamma}/L_{\rm SF}$', fontsize=16)
                    figname=plotloc+'CRplot/dirgammasfr/gammasfrsnap_'+fmeat+'.pdf'
                if wanted=='dirgamma':
                    plt.yscale('log')
                    if runtitle=='SMC' or legendneed==1:
                            plt.legend(loc='best', fontsize=8,ncol=3)
                    if legendneed==1 and M1runlabelneed:
                            plt.legend(loc='best', fontsize=8,ncol=2)
                    plt.xlabel(xlab, fontsize=16)
                    plt.ylabel(r'$L_{\gamma} {\rm erg/s}$', fontsize=16)
                    figname=plotloc+'CRplot/dirgamma/gammasnap_'+fmeat+'.pdf'
                if wanted=='dirsfr':
                    plt.yscale('log')
                    if runtitle=='SMC' or legendneed==1:
                        plt.legend(loc='best', fontsize=8,ncol=3)
                    if M1labelneed==1 and legendneed==1:
                        plt.legend(loc='best', fontsize=8,ncol=2)
                    plt.xlabel(xlab, fontsize=16)
                    plt.ylabel(r'${\rm SFR (M_{\odot}/yr)} $', fontsize=16)
                    figname=plotloc+'CRplot/dirsfr/sfrsnap_'+fmeat+'.pdf'
                if wanted=='dirsm':
                    if runtitle=='SMC' and legendneed==1:
                        if strlabelneed==1 or M1labelneed==1:
                            plt.legend(loc='best', fontsize=10,ncol=2)
                        else:
                            plt.legend(loc='best', fontsize=8,ncol=3)
                    plt.xlabel('Myr', fontsize=16)
                    plt.ticklabel_format(style='sci',axis='y',scilimits=(0,0))
                    if normalizedsm==1:
                        plt.ylabel(r'${\rm M_{*,new} (M_{\odot})} $', fontsize=16)
                    else:
                        plt.ylabel(r'${\rm M_* (M_{\odot})} $', fontsize=16)
                    if normalizedsm==1:
                        figname=plotloc+'CRplot/dirsm/nsm_'+fmeat+'.pdf'
                    else:
                        figname=plotloc+'CRplot/dirsm/sm_'+fmeat+'.pdf'
            print 'Saving ', figname
            plt.title(ptitle,fontsize=16)
            plt.tick_params(axis='both', which='both',direction='in',bottom=True,top=True,left=True,right=True,labelsize=16)
            plt.subplots_adjust(left  = 0.18, bottom=0.15, right=0.95, top=0.9)
            #plt.tight_layout()
            plt.savefig(figname)
            plt.clf()
        return None
Example #8
0
     labelneed=dclabel
 if newlabelneed==1:
     labelneed="\n".join(wrap(newlabel,17))
 else:
     labelneed=''
 ptitle=title
 if runtitle=='SMC':
         ptitle='Dwarf'
 elif runtitle=='SBC':
         ptitle='Starburst'
 elif runtitle=='MW':
         ptitle=r'$L\star$ Galaxy'
 print 'the_snapdir', the_snapdir
 print 'Nsnapstring', Nsnapstring
 print 'havecr', havecr
 G = readsnapcr(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr)
 header = readsnapcr(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix,\
  extension=the_suffix, havecr=havecr, header_only=1)
 print 'time', header['time']
 timeneed=i*0.98*1e6 #in yr
 Grho_t = G['rho'] #1e10Msun per kpc^3
 Gid_t = G['id']
 cregy_codeunit = G['cregy']
 cregy = cregy_codeunit*1e10*solar_mass_in_g*km_in_cm*km_in_cm #original cosmic ray energy in 1e10Msun km^2/sec^2
 Neb = G['ne']
 cregyl = G['cregyl']*1e10*solar_mass_in_g*km_in_cm*km_in_cm
 if wanted == 'nismcrad' or wanted == 'rcrad':
     cregyad_t = G['cregya']*1e10*solar_mass_in_g*km_in_cm*km_in_cm
 if wanted == 'nismcrg':
     cregyg_t = G['cregyg']*1e10*solar_mass_in_g*km_in_cm*km_in_cm
 Gp_t = G['p']
Example #9
0
 if cosmo == 0:
     inittime = initsnap
 else:
     inittime = 0
 print 'set initial time'
 print 'the_snapdir', the_snapdir
 print 'Nsnapstring', Nsnapstring
 print 'havecr', havecr
 print 'withinRv', withinRv
 print 'cosmo', cosmo
 try:
     if cosmo == 1:
         G = readsnapcr(the_snapdir,
                        Nsnapstring,
                        0,
                        snapshot_name=the_prefix,
                        extension=the_suffix,
                        havecr=havecr,
                        h0=1,
                        cosmological=1)
         S = readsnapcr(the_snapdir,
                        Nsnapstring,
                        4,
                        snapshot_name=the_prefix,
                        extension=the_suffix,
                        havecr=havecr,
                        h0=1,
                        cosmological=1)
         if correctIa == 1:
             Disk = readsnapcr(the_snapdir,
                               Nsnapstring,
                               2,
Example #10
0
def avedentestinput(subdict):
    dirneed = subdict['dirneed']
    wanted = subdict['wanted']
    print 'wanted', wanted
    startno = subdict['startno']
    Nsnap = subdict['Nsnap']
    snapsep = subdict['snapsep']
    the_prefix = subdict['the_prefix']
    the_suffix = subdict['the_suffix']
    fmeat = subdict['fmeat']

    print 'wanted', wanted
    print 'fmeat', fmeat
    print 'runtodo', dirneed



    if wanted=='gmr' or wanted=='avedenr' or wanted=='avecrdenr'\
    or wanted=='avethdenr' or wanted=='aveedenr' or wanted=='FpFgr'\
    or wanted=='avekedenr':
        plt.figure(figsize=(5, 4))

        def funcab(x, a, b):
            return a + b * x

        def func(x, a, b, c):
            return a + b * x + c * x * x

        def d10func(r, a, b, c):
            return np.power(10., func(np.log10(r), a, b, c)) * (
                b + 2 * c * np.log(r) / np.log(10.)) / r

        nogrid = 20
        withinr = 2.0
        atstarburst = 1
        linelabelneed = 0
        if wanted == 'aveedenr':
            linelabelneed = 1
        labcount = 0
        newlabelneed = subdict['newlabelneed']
        legendneed = subdict['legendneed']
        for runtodo in dirneed:
            if atstarburst == 1:
                if runtodo == 'bwsbclr':
                    Nsnap = 284
                    #Nsnap=523
                if runtodo == 'bwsbclrmhd':
                    Nsnap = 600
                    #Nsnap=589
                if runtodo == 'bwsbclrdc0':
                    Nsnap = 286
                    #Nsnap=590
                if runtodo == 'bwsbclrdc27':
                    Nsnap = 369
                    #Nsnap=138
                if runtodo == 'bwsbclrdc28':
                    Nsnap = 504
                    #Nsnap=520
                if runtodo == 'bwsbclrdc29':
                    Nsnap = 430
                    #Nsnap=433
                if runtodo == 'bwsbclrstr':
                    Nsnap = 358
                    #Nsnap=245
                if runtodo == 'bwsbclrdc28mhd':
                    Nsnap = 433
                    #Nsnap=558
                if runtodo == 'bwsbclrdc28str':
                    Nsnap = 532
                    #Nsnap=370
            for i in [Nsnap]:
                info = outdirname(runtodo, i)
                rundir = info['rundir']
                maindir = info['maindir']
                halostr = info['halostr']
                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']
                Fcal = info['Fcal']
                iavesfr = info['iavesfr']
                timestep = info['timestep']
                cosmo = info['cosmo']
                color = info['color']
                withinRv = info['withinRv']
                usepep = info['usepep']
                beginno = info['beginno']
                finalno = info['finalno']
                firever = info['firever']
                initsnap = info['initsnap']
                haveB = info['haveB']
                M1speed = info['M1speed']
                Rvirguess = info['Rvir']
                newlabel = info['newlabel']
                snumadd = info['snumadd']
                ptitle = title
                labelneed = dclabel
                if newlabelneed == 1:
                    labelneed = "\n".join(wrap(newlabel, 17))
            if runtitle == 'SMC':
                ptitle = 'Dwarf'
            elif runtitle == 'SBC':
                ptitle = 'Starburst'
            elif runtitle == 'MW':
                ptitle = r'$L\star$ Galaxy'
            lsn = 'solid'
            if haveB > 0:
                lsn = 'dashed'
            if havecr == 0 and wanted == 'avecrdenr':
                continue
            if cosmo == 1:
                h0 = 1
                rotface = 1
                datasup = 0
            else:
                h0 = 0
                rotface = 0
                datasup = 1
            G = readsnapcr(the_snapdir,
                           Nsnapstring,
                           0,
                           snapshot_name=the_prefix,
                           extension=the_suffix,
                           havecr=havecr,
                           cosmological=cosmo,
                           h0=cosmo)
            Gp = G['p']
            Gv = G['v']
            Gu = G['u']
            Gm = G['m']
            Gvx = Gv[:, 0]
            Gvy = Gv[:, 1]
            Gvz = Gv[:, 2]
            GEint = Gu * km_in_cm * km_in_cm * Gm * 1e10 * Msun_in_g
            cregy = G['cregy']  #cosmic ray energy in 1e10Msun km^2/sec^2
            ke = 0.5 * (Gvx * Gvx + Gvy * Gvy + Gvz *
                        Gvz) * km_in_cm * km_in_cm * Gm * 1e10 * Msun_in_g
            #Gnism = (0.78+0.22*Neb*0.76)/1.67e-24*Grho*1e10*1.99e33/3.086e21/3.086e21/3.086e21 #gas number density in ISM
            Gz = Gp[:, 2]
            Gx = Gp[:, 0]
            Gy = Gp[:, 1]
            dr = withinr / nogrid
            from crtestfunction import findcenz
            datasup = 1
            xcen, ycen, zcen = findcennew(runtodo,
                                          Nsnap,
                                          withinr=2.5,
                                          datasup=datasup,
                                          Gx=Gx,
                                          Gy=Gy,
                                          Gz=Gz,
                                          Gm=Gm)
            Gz = Gz - zcen
            Gy = Gy - ycen
            Gx = Gx - xcen
            GEint = Gu * km_in_cm * km_in_cm * Gm * 1e10 * Msun_in_g
            cregy = G['cregy']  #cosmic ray energy in 1e10Msun km^2/sec^2
            ke = 0.5 * (Gvx * Gvx + Gvy * Gvy + Gvz *
                        Gvz) * km_in_cm * km_in_cm * Gm * 1e10 * Msun_in_g
            Gr = np.sqrt(Gx * Gx + Gy * Gy + Gz * Gz)
            dr = withinr / nogrid
            Gm_in_sunl = []
            GEl = []
            crel = []
            radl = []
            kel = []
            for irad in range(nogrid):
                cut = (Gr < dr * (irad + 1))
                crcut = cregy[
                    cut] * 1e10 * Msun_in_g * km_in_cm * km_in_cm  #erg
                crel = np.append(crel, np.sum(crcut))
                Gmcut = Gm[cut]
                Gm_in_sun = Gmcut * 1e10
                Gm_in_sunl = np.append(Gm_in_sunl, np.sum(Gm_in_sun))
                GEcut = GEint[cut]
                kecut = ke[cut]
                GEl = np.append(GEl, np.sum(GEcut))  #erg
                kel = np.append(kel, np.sum(kecut))
                radl = np.append(radl, dr * (irad + 1))
            if wanted == 'gmr':
                plt.plot(radl, Gm_in_sunl, label=runtodo)
            if wanted == 'avedenr':
                vol = np.power(radl * kpc_in_cm, 3.) * 4. / 3. * np.pi
                den = Gm_in_sunl * Msun_in_g / vol / protonmass_in_g
                plt.plot(radl, den, label=labelneed, lw=2, ls=lsn, color=color)
                print 'radl, den', radl, den
                x0 = [1.0, -0.1]
                xdata = np.log10(radl[1:])
                ydata = np.log10(den[1:])
                outfit = optimize.curve_fit(funcab, xdata, ydata, x0)
                afit = outfit[0][0]
                bfit = outfit[0][1]
                print 'afit, bfit', afit, bfit
            if wanted == 'avecrdenr' or wanted == 'aveedenr':
                if havecr > 0:
                    vol = np.power(radl * kpc_in_cm, 3.) * 4. / 3. * np.pi
                    crden = crel * erg_in_eV / vol
                    if linelabelneed == 1:
                        if labcount == 2:
                            plt.plot(radl,
                                     crden,
                                     label='CR',
                                     lw=2,
                                     ls=lsn,
                                     color=color)
                        else:
                            plt.plot(radl, crden, lw=2, ls=lsn, color=color)
                    else:
                        plt.plot(radl,
                                 crden,
                                 label=dclabel,
                                 lw=2,
                                 ls=lsn,
                                 color=color)
            if wanted == 'avethdenr' or wanted == 'aveedenr':
                vol = np.power(radl * kpc_in_cm, 3.) * 4. / 3. * np.pi
                thden = GEl * erg_in_eV / vol
                if linelabelneed == 1:
                    if labcount == 2:
                        plt.plot(radl,
                                 thden,
                                 label='Thermal',
                                 lw=1,
                                 ls=lsn,
                                 color=color)
                    else:
                        plt.plot(radl, thden, lw=1, ls=lsn, color=color)
                else:
                    plt.plot(radl,
                             thden,
                             label=dclabel,
                             lw=2,
                             ls=lsn,
                             color=color)
            if wanted == 'avekedenr':
                vol = np.power(radl * kpc_in_cm, 3.) * 4. / 3. * np.pi
                keden = kel * erg_in_eV / vol
                plt.plot(radl, keden, label=dclabel, lw=2, ls=lsn, color=color)
            if wanted == 'FpFgr':
                vol = np.power(radl * kpc_in_cm, 3.) * 4. / 3. * np.pi
                dv = vol[1:] - vol[:-1]
                drad = (radl[1:] - radl[:-1]) * kpc_in_cm
                dpth = (GAMMA - 1.0) * (GEl[1:] - GEl[:-1]) / dv / drad  #cgs
                Fg_m = Gm_in_sunl * Msun_in_g * NewtonG_in_cgs / (
                    radl * kpc_in_cm) / (radl * kpc_in_cm)
                dm = (Gm_in_sunl[1:] - Gm_in_sunl[:-1]) * Msun_in_g
                fg = Fg_m[:-1] * dm / dv  #force per unit volume
                plt.plot(radl[:-1],
                         dpth / fg,
                         label=dclabel,
                         lw=2,
                         ls='dashdot',
                         color=color)
                if havecr > 0:
                    dpcr = (CRgamma - 1.0) * (crel[1:] -
                                              crel[:-1]) / dv / drad  #cgs
                    plt.plot(radl[:-1],
                             dpcr / fg,
                             label=dclabel,
                             lw=2,
                             ls='solid',
                             color=color)
            labcount += 1
        plt.yscale('log')
        plt.xlabel(r'$ r\; [{\rm kpc}]$', fontsize=14)
        if wanted == 'gmr':
            plt.ylabel(r'enclosed $M_{\rm g} [M_{\odot}]$')
            filename = plotloc + 'CRplot/gmr/gasmass_' + fmeat + '_sn' + str(
                Nsnap) + '.pdf'
        if wanted == 'avedenr':
            plt.ylabel(r'$\bar{n}_{\rm ISM}(<r)\; [{\rm cm^{-3}}]$',
                       fontsize=14)
            filename = plotloc + 'CRplot/avedenr/avedenr_' + fmeat + '_sn' + str(
                Nsnap) + '.pdf'
            plt.legend(loc='best', fontsize=8, ncol=2)
        if wanted == 'avecrdenr':
            plt.ylabel(r'$\bar{e}_{\rm cr}\; [{\rm eV/cm^{3}}]$', fontsize=14)
            filename = plotloc + 'CRplot/avecrdenr/avecrdenr_' + fmeat + '_sn' + str(
                Nsnap) + '.pdf'
        if wanted == 'avethdenr':
            plt.ylabel(r'$\bar{e}_{\rm th}\; [{\rm eV/cm^{3}}]$', fontsize=14)
            filename = plotloc + 'CRplot/avethdenr/avethdenr_' + fmeat + '_sn' + str(
                Nsnap) + '.pdf'
        if wanted == 'aveedenr':
            plt.ylabel(r'$\bar{e}(<r)\; [{\rm eV/cm^{3}}]$', fontsize=14)
            filename = plotloc + 'CRplot/aveedenr/aveedenr_' + fmeat + '_sn' + str(
                Nsnap) + '.pdf'
            plt.legend(loc='best', fontsize=14)
        if wanted == 'avekedenr':
            plt.ylabel(r'$\bar{e}_{\rm KE}\; [{\rm eV/cm^{3}}]$', fontsize=14)
            filename = plotloc + 'CRplot/avekedenr/avekedenr_' + fmeat + '_sn' + str(
                Nsnap) + '.pdf'
        if wanted == 'FpFgr':
            plt.ylabel(r'$\nabla P/\rho g$', fontsize=14)
            filename = plotloc + 'CRplot/FpFgr/FpFgr_' + fmeat + '_sn' + str(
                Nsnap) + '.pdf'
        plt.tight_layout()
        print 'filename', filename
        plt.title(ptitle, fontsize=16)
        plt.tick_params(axis='both',
                        which='both',
                        direction='in',
                        bottom=True,
                        top=True,
                        left=True,
                        right=True,
                        labelsize=16)
        plt.subplots_adjust(left=0.18, bottom=0.15, right=0.95, top=0.9)
        plt.savefig(filename)
        plt.clf()
    return None