Example #1
0
def last_accretion(fgallst):  # When do winds last time accreted?
    fig = plt.figure(1, figsize=(6, 6))
    flist = open(fgallst, "r")
    ls = ["-", "--"]
    clrs = ["blue", "red"]
    i = 0
    ps = []
    for line in flist:
        # gid = int(line.split()[0])
        # fgalname = "./p50n288zw/galacc_%d.stars" % (gid)
        fgalname = line.split()[0]
        print "Loading File: ", fgalname
        galacc = read_galacc_data(fgalname)
        asf, trec = [], []
        for igal in range(len(galacc)):
            if (galacc['a_last'][igal] < 0.):
                asf.append(galacc['a_form'][igal])
                tdiff = tcosmic(
                    galacc['a_form'][igal]) - tcosmic(-galacc['a_last'][igal])
                trec.append(tdiff / 1.e9)
        p, = plt.plot(asf, trec, ".", color=clrs[i], alpha=0.2, markersize=2)
        ps.append(p)
        i = 1
    flist.close()
    plt.xlabel(r"$a_{form}$")
    plt.ylabel(r"$t_{rec} [Gyr]$")
    # plt.yscale("log")
    # plt.axis([0.0, 1.0, 1.e10, 5.e12])
    plt.legend(ps, ["Fiducial", "sw"], loc=4, fontsize=12)
    plt.show()
Example #2
0
def plot_for_redshift(axi, zstr, zred):
    for modeli in range(len(models)):
        fname = "/home/shuiyao_umass_edu/scidata/gadget3io/"+models[modeli]+"/"+models[modeli]+"_"+zstr+".windage"
        tab = genfromtxt(fname, names=True)
        age = (tcosmic(1./(zred+1.)) - tcosmic(tab['atime'])) / 1.e9
        for i in range(4):
            frac = cumsum(tab[cols[i]])
            frac = frac / frac[-1]
            axs[axi].plot(age, frac, color=clrs[i], linestyle=lstyles[modeli])
Example #3
0
def calc_trec(ai, af, log=True):
    for i in range(len(af)):
        if (af[i] > 1.0): af[i] = 1.0
    tf = cosmology.tcosmic(array(af))
    ti = cosmology.tcosmic(array(ai))
    trec = tf - ti
    if (log == True): trec = log10(trec)
    for i in range(len(af)):
        if (af[i] == 1.0): trec[i] = 20.0
    return trec
Example #4
0
def set_colors_phew_particles(PhEWParticles, field, vmin, vmax, logscale=False, cmap=plt.get_cmap("jet")):
    clrsarr = []
    logvmin = log(vmin)
    if(logscale == False):
        color_grad = vmax - vmin
    else:
        color_grad = log(vmax) - log(vmin)
    for PhEWP in PhEWParticles:
        v = abs(PhEWP[field])
        if(field == "LastSFTime"):
            v = (tcosmic(0.5) - tcosmic(abs(v))) / 1.e9
        if(logscale == False):
            color_val = (v - vmin) / color_grad
        else:
            color_val = (log(v) - logvmin) / color_grad
        if(v < vmin): color_val = 0.0
        if(v > vmax): color_val = 1.0
        clrsarr.append(color_val)
    return clrsarr
Example #5
0
def write_mloss_info(foutname=fmlossinfo):
    PhEWParticles = phew.load_particles(filename_phews, fphewsname)  # phews
    fout = open(foutname, "w")
    fout.write(
        "#ID Mvir Rvir R75 R50 R25 Rlast t75 t50 t25 tlast Mach75 Mach50 Mach25 Machlast\n"
    )
    for PhEWP in PhEWParticles:
        flag = remove_spurious_particles(PhEWP.track)
        counter_spurious_particles[flag] += 1
        # if(flag): continue
        if (isnan(PhEWP.mvir) or PhEWP.mvir < 0): continue
        r25, r50, r75, rlast = -1., -1., -1., -1.
        mach25, mach50, mach75, machlast = -1., -1., -1., -1.
        t25, t50, t75, tlast = -1., -1., -1., -1.
        PhEWP.track['M_cloud'] /= MC_INIT
        dtime = (tcosmic(PhEWP.track['atime']) -
                 tcosmic(PhEWP.track['atime'][0])) / 1.e6
        for i in range(len(PhEWP.track['dr']))[1:]:
            if (r75 < 0.0 and PhEWP.track['M_cloud'][i] <= 0.75):
                r75, mach75, t75 = abs(
                    PhEWP.track['dr'][i]), PhEWP.track['Mach'][i], dtime[i]
            if (r50 < 0.0 and PhEWP.track['M_cloud'][i] <= 0.50):
                r50, mach50, t50 = abs(
                    PhEWP.track['dr'][i]), PhEWP.track['Mach'][i], dtime[i]
            if (r25 < 0.0 and PhEWP.track['M_cloud'][i] <= 0.25):
                r25, mach25, t25 = abs(
                    PhEWP.track['dr'][i]), PhEWP.track['Mach'][i], dtime[i]
        if (r25 > 0):
            rlast, machlast, tlast = abs(
                PhEWP.track['dr'][-1]), PhEWP.track['Mach'][-1], dtime[i]
        outstr = "%10d %6.3f %6.1f %6.1f %6.1f %6.1f %6.1f %6.1f %6.1f %6.1f %6.1f %6.3f %6.3f %6.3f %6.3f\n" % \
                 (PhEWP.key, PhEWP.mvir, PhEWP.rvir, \
                  r75, r50, r25, rlast, \
                  t75, t50, t25, tlast,
                  mach75, mach50, mach25, machlast)
        fout.write(outstr)
    fout.close()
Example #6
0
unit_m = 1.e10 / hparam

CUMULATIVE_DISTRIBUTION = False
models = ["l25n144-phew-m5-spl", "l25n288-phew-m5-spl"]
lgds = ["25/144,Split", "25/288,Split"]
# models = ["l25n144-phew-m5", "l25n144-phew-m5-spl"]
# lgds = ["PhEW,25/144", "PhEW,25/144,Split"]

lstyles = ["--", "-"]
REDSHIFT = 0.25
if(REDSHIFT == 0.0): zstr = "108"
if(REDSHIFT == 1.0): zstr = "078"
if(REDSHIFT == 2.0): zstr = "058"
if(REDSHIFT == 4.0): zstr = "033"
if(REDSHIFT == 0.25): zstr = "098"
ALIM = acosmic(tcosmic(1./(1.+REDSHIFT)) - 1.e9)

nbins = 20
aedges = linspace(0., 1., nbins+1)
acen = 0.5 * (aedges[1:] + aedges[:-1])
tcen = (tcosmic(acen) - tcosmic(REDSHIFT)) / 1.e9

acen = 1. / acen - 1. # z
da = 1. / nbins

ZSOLAR = log10(0.0122)

def find_windtime_bin(awind):
    bin_idx = awind / da
    return (int)(bin_idx)
Example #7
0
def discard_spurious_accretion(atime, alast):
    # ac is THIS accretion event to be evaluated
    if (alast <= 0): return 0
    if (tcosmic(atime) - tcosmic(alast) < DTTOL): return 1
    return 0
Example #8
0
BOXSIZE = 12000.
unit_Time = sqrt(8.0 * pi / 3.0) * ac.mpc / (100.e5 * HPARAM)
unit_Length = BOXSIZE * ac.kpc
unit_Velocity = unit_Length / unit_Time
unit_mass = 4.3e5 * (BOXSIZE / 25000.)**3
XTOL = 0.02
MTOL = 1.0
fbase = "/scratch/shuiyao/data/"
model = "l12n144-phew-movie"
gid = 1477

foutname = "progen_" + ("00000" + str(gid))[-5:]
fout = open(foutname, "w")

snapi = snapend
dtime = tcosmic(ascales[snapi]) - tcosmic(ascales[snapi - 1])
dtime = dtime * ac.yr / unit_Time
snapstr = ("000" + str(snapi))[-3:]
fgalname = fbase + model + "/gal_z" + snapstr + ".stat"
mgal, xgal, ygal, zgal, vxgal, vygal, vzgal = ioformat.rcol(
    fgalname, [4, 18, 19, 20, 15, 16, 17])
idx = gid - 1
xprev = xgal[idx] - vxgal[idx] * dtime
yprev = ygal[idx] - vygal[idx] * dtime
zprev = zgal[idx] - vzgal[idx] * dtime
mprev = mgal[idx]
fout.write("%5d %7.5f %7.5f %7.5f %6.3f\n" % (idx, xprev, yprev, zprev,\
            log10(mprev * unit_mass * 1.e10 / 0.7)))

mgalz0 = log10(mprev * unit_mass * 1.e10 / 0.7)
Example #9
0
models = ["l50n288-phew-m5", "l50n576-phew-m5"]
lgds = ["l50n288-phew-m5", "l50n576-phew-m5"]
ncpus = [256, 1024]
# models = ["l25n144-phew-m5-spl", "l25n288-phew-m5"]
# lgds = ["l25n144-phew-m5-spl", "l25n288-phew-m5"]
# ncpus = [128, 256]

lstyles = ["--", "-"]
REDSHIFT = 0.0
if (REDSHIFT == 0.0): zstr = "108"
if (REDSHIFT == 1.0): zstr = "078"
if (REDSHIFT == 2.0): zstr = "058"
if (REDSHIFT == 4.0): zstr = "033"
if (REDSHIFT == 0.25): zstr = "098"
ALIM = acosmic(tcosmic(1. / (1. + REDSHIFT)) - 1.e9)
# ALIM = 0

from pltastro import frame, draw
import config_mpl
frm = frame.multi(2, 1)
pars = frm.params
pars.figsize = (5, 7)
pars.left = 0.2
pars.top = 0.90
pars.bottom = 0.1
panels = frm.panels
panels.set_xlabels(r"$\sigma_{gal} [km/s]$")
panels.set_xlims(0.0, SIGMAX)
panels.set_ylabels("Mass")  # <--------------------------------
# panels.set_ylabels("Fraction")
Example #10
0
bins_sig = linspace(0.0, 150.0, nsigbins+1)
bins_sig_label = 0.5 * bins_sig[1:] + 0.5 * bins_sig[:-1]

def find_radial_bin(r):
    if(r > 1.0): return -1
    bin_idx = r / dr
    return (int)(bin_idx)

REDSHIFT = 0.25
if(REDSHIFT == 0.0): zstr = "108"
if(REDSHIFT == 0.25): zstr = "098"
if(REDSHIFT == 1.0): zstr = "078"
if(REDSHIFT == 2.0): zstr = "058"
if(REDSHIFT == 4.0): zstr = "033"

tcurrent = tcosmic(1./(REDSHIFT+1.0))

TMAXCUT = 5.0

model = 'l50n576-phew-m5'
# model = 'l50n288-phew-m5'

def calculate_gas_profile(model, zstr, mstr, PhEW=True):

    fname = DIRS['SCIDATA'] + model + "/snapshot_"+zstr+".gas."+mstr
    fauxname = DIRS['SCIDATA'] + model + "/snapshot_"+zstr+".gasaux."+mstr        
    gas = pd.read_csv(fname, sep='\s+', header=0)
    gasaux = pd.read_csv(fauxname, sep='\s+', header=0)
    # gas.rename(columns={'#Idx':'Idx'})
    # gasaux.rename(columns={'#f_w':'f_w'})
    gas = gas[gas['SfFlag'] == 0]
Example #11
0
    bin_idx = awind / da
    return (int)(bin_idx)

models = ["l25n144-phew-m5-spl", "l25n288-phew-m5-spl"]
lgds = ["25/144,Split", "25/288,Split"]
# models = ["l25n144-phew-m5", "l25n144-phew-m5-spl"]
# lgds = ["PhEW,25/144", "PhEW,25/144,Split"]

lstyles = ["--", "-"]
REDSHIFT = 0.25
if(REDSHIFT == 0.0): zstr = "108"
if(REDSHIFT == 1.0): zstr = "078"
if(REDSHIFT == 2.0): zstr = "058"
if(REDSHIFT == 4.0): zstr = "033"
if(REDSHIFT == 0.25): zstr = "098"
ALIM = acosmic(tcosmic(1./(1.+REDSHIFT)) - 1.e9)

from pltastro import frame, draw
import config_mpl
frm = frame.multi(3,1)
pars = frm.params
pars.figsize = (5, 9)
pars.left = 0.2
pars.top = 0.92
pars.bottom = 0.2
panels = frm.panels
panels.set_xlabels(r"$z$")
panels.set_ylabels("Fraction")
# panels.set_xlims(0.0, 1.0)
panels.set_xlims(REDSHIFT, 3.0)
if(CUMULATIVE_DISTRIBUTION):
Example #12
0
def draw_phew_particles(PhEWParticles, ax, fieldx, fieldy, fieldc, \
                        nskip=1, logxscale=False, logyscale=False, \
                        color_min=None, color_max=None, logcscale=False, alpha=0.2, \
                        showidx=False, allparts=False):
    if (color_min == None): color_min = min(fieldc)
    if (color_max == None): color_max = max(fieldc)
    set_colors_phew_particles(PhEWParticles,
                              fieldc,
                              color_min,
                              color_max,
                              logscale=logcscale)
    iskip = 0
    print("------ ", fieldy, "------")
    for i, PhEWP in enumerate(PhEWParticles):
        #     if(PhEWP.mvir > 13.0): print i

        if (iskip < nskip):
            iskip += 1
            continue

        if (allparts == False):
            flag = remove_spurious_particles(PhEWP.track)
            counter_spurious_particles[flag] += 1
            if (flag): continue

        if (fieldc == "Mvir"): color_val = PhEWP.mvir
        else: color_val = PhEWP.track[fieldc][0]
        if (color_min < color_val < color_max):
            if (fieldx == "time" or fieldx == "dt"):
                xarr = tcosmic(PhEWP.track['atime']) - tcosmic(
                    PhEWP.track['atime'][0])
                xarr /= 1.e6  # Myr
            else:
                xarr = PhEWP.track[fieldx]
            if (fieldy == 'r/rvir'):
                if (PhEWP.rvir <= 0): continue
                yarr = PhEWP.track['dr'] / PhEWP.rvir
            else:
                yarr = PhEWP.track[fieldy]
            ynorm = 1
            if (fieldy == 'M_cloud'): ynorm = MASS_CLOUD
            if (logxscale == True): xarr = log10(xarr)
            if (logyscale == True): yarr = log10(yarr)
            ax.plot(xarr,
                    yarr / ynorm,
                    ".-",
                    color=PhEWP.color,
                    alpha=alpha,
                    markersize=2)
            ax.plot(xarr[0],
                    yarr[0] / ynorm,
                    "^",
                    color=PhEWP.color,
                    markersize=6)
            ax.plot(xarr[-1],
                    yarr[-1] / ynorm,
                    "*",
                    color=PhEWP.color,
                    markersize=8)
            if (showidx):
                ax.text(xarr[0],
                        yarr[0],
                        str(i),
                        fontsize=6,
                        color=PhEWP.color)
        iskip = 0
Example #13
0
def write_wind_features(foutname=fwindsinfo):
    PhEWParticles = phew.load_particles(filename_phews, fphewsname)  # phews
    # filename_phews: sorted.phews under WINDS/z?/
    #   |- select.sh
    # fphewsname: phewsinfo.z?
    #   |- match_initwinds_rejoin.py
    #      |- [IN] initwinds.sorted
    #      |- [IN] rejoin.sorted
    #      |- [IN] phewsHalos
    #         |- $PHEW-PY/loadhdf5/find_host_haloes_for_phews.py
    #         |- [IN] .hdf5, .sogrp, .sovcirc
    fout = open(foutname, "w")
    fout.write("#ID Mvir Rvir Vinit V25 Rreturn\n")
    count, writecount = 0, 0
    for n, PhEWP in enumerate(PhEWParticles):
        flag = remove_spurious_particles(PhEWP.track)
        counter_spurious_particles[flag] += 1
        if (flag == 5): print(n)
        if (flag): continue
        PhEWP.mvir = 10.**PhEWP.mvir
        vc, v25, vinit = 0., 0., 0.
        x, y = [PhEWP.track['dr'][0]], [PhEWP.track['dv'][0]]
        dtime = (tcosmic(PhEWP.track['atime']) -
                 tcosmic(PhEWP.track['atime'][0])) / 1.e6
        ddr, ddt = [], []
        i25, r25 = 0, -1
        vel25 = -1
        ireturn = 0
        count += 1
        vc = sqrt(pc.G * PhEWP.mvir * ac.msolar / (PhEWP.rvir * ac.kpc)) / 1.e5
        for i in range(len(PhEWP.track['dr']))[1:]:
            x.append(abs(PhEWP.track['dr'][i]))
            y.append(PhEWP.track['dv'][i])
            ddt.append(dtime[i] - dtime[i - 1])
            ddr.append(x[i] - x[i - 1])
            if (i25 == 0 and abs(PhEWP.track['dr'][i]) > PhEWP.rvir * 0.25
                    and dtime[i] < 1000.):  # WARNING: dt < 400.
                i25 = i
            if (ireturn == 0
                    and ((ddr[i - 1] < 0. and PhEWP.track['dv'][i] < vc)
                         or ddt[i - 1] > 30.)):
                ireturn = i
                rreturn = x[i]
        if (ireturn == 0):
            ireturn = -1
            rreturn = -1
        if (len(ddr) == 0):
            continue
        if (PhEWP.rvir == -1 or isnan(PhEWP.mvir)):
            print("Warning: ", PhEWP.key, PhEWP.mvir, PhEWP.rvir)
            continue
        if (max(ddr) < 100. and min(ddr) > -100.):
            writecount += 1
            if (i25 > 0):
                v25 = y[i25]
            else:
                v25 = -1
            vinit = y[0]
            # fout.write("#ID, Mvir, Vc, Vinit, V25\n")
            outstr = str(PhEWP.key) + " " + str(log10(PhEWP.mvir)) + " " + str(
                PhEWP.rvir)
            outstr += " " + str(vinit) + " " + str(v25) + " " + str(rreturn)
            outstr += "\n"
            fout.write(outstr)
    print(counter_spurious_particles)
    print("Written, Count, All: ", writecount, count, len(PhEWParticles))
    fout.close()
Example #14
0
def draw_phew_particles(PhEWParticles, ax, fieldx, fieldy, fieldc, \
                        nskip=1, logxscale=False, logyscale=False, \
                        color_min=None, color_max=None, logcscale=False, alpha=0.2, \
                        showidx=False, post_recouple=False, phew=True):
    if (color_min == None): color_min = min(fieldc)
    if (color_max == None): color_max = max(fieldc)
    set_colors_phew_particles(PhEWParticles,
                              fieldc,
                              color_min,
                              color_max,
                              logscale=logcscale)
    iskip = 0
    count = 0
    keys = []
    print("------ ", fieldy, "------")
    for i, PhEWP in enumerate(PhEWParticles):
        #     if(PhEWP.mvir > 13.0): print i
        # if(PhEWP.track['flag'][-1] != 0):
        #     continue

        if (iskip < nskip):
            iskip += 1
            continue

        # We don't remove spurious particles here
        # flag = remove_spurious_particles(PhEWP.track)
        # counter_spurious_particles[flag] += 1
        # if(flag): continue

        if (fieldc == "Mvir"): color_val = PhEWP.mvir
        else: color_val = PhEWP.track[fieldc][0]
        if (color_min < color_val < color_max):
            # keys.append(PhEWP.key)
            track = PhEWP.track[PhEWP.track['atime'] < 0.833333]
            count += 1
            if (fieldx == "time" or fieldx == "dt"):
                xarr = tcosmic(track['atime']) - tcosmic(track['atime'][0])
                xarr /= 1.e6  # Myr
            else:
                xarr = track[fieldx]
            if (fieldy == 'r/rvir'):
                if (PhEWP.rvir <= 0): continue
                yarr = track['dr'] / PhEWP.rvir
            else:
                yarr = track[fieldy]
            if (fieldy == 'T'):
                for j in range(len(yarr)):
                    if (yarr[j] > 10.0): yarr[j] -= 10.0
            if (fieldx == 'rho'):
                xarr = log10(track['rho'])

            # Find if there's a recoupling point
            if (phew):
                wflag = track['flag']
                i_recouple = -1
                for j in range(len(wflag)):
                    if (wflag[j] == 0):
                        i_recouple = j - 1
                        break
            else:
                i_recouple = -1
            ynorm = 1
            if (fieldy == 'M_cloud'): ynorm = MASS_CLOUD
            if (logxscale == True): xarr = log10(xarr)
            if (logyscale == True): yarr = log10(yarr)
            if (post_recouple == False):
                ax.plot(xarr,
                        yarr / ynorm,
                        ".-",
                        color=PhEWP.color,
                        alpha=alpha,
                        markersize=2)
                ax.plot(xarr[0],
                        yarr[0] / ynorm,
                        "^",
                        color=PhEWP.color,
                        markersize=6)
                if (i_recouple != -1):  # recoupling point
                    ax.plot(xarr[-1],
                            yarr[-1] / ynorm,
                            "*",
                            color=PhEWP.color,
                            markersize=8)
                else:  # annihilated
                    ax.plot(xarr[-1],
                            yarr[-1] / ynorm,
                            "x",
                            color=PhEWP.color,
                            markersize=6)
            else:  # Only draw tracks after recouple
                if (i_recouple != -1):
                    # ax.plot([xarr[0],xarr[i_recouple]], [yarr[0]/ynorm,yarr[i_recouple]/ynorm], "--", color=PhEWP.color, alpha=alpha)
                    # ax.plot(xarr[0:i_recouple], yarr[0:i_recouple]/ynorm, ":", color=PhEWP.color, alpha=alpha)
                    ax.plot(xarr[i_recouple:],
                            yarr[i_recouple:] / ynorm,
                            ".-",
                            color=PhEWP.color,
                            alpha=alpha,
                            markersize=2)
                    ax.plot(xarr[-1],
                            yarr[-1] / ynorm,
                            "*",
                            color=PhEWP.color,
                            markersize=8)
                    keys.append(PhEWP.key)
            if (i_recouple != -1):
                ax.plot(xarr[i_recouple],
                        yarr[i_recouple] / ynorm,
                        "o",
                        color=PhEWP.color,
                        markersize=8)
            if (showidx):
                ax.text(xarr[-1],
                        yarr[-1],
                        wflag[-1],
                        fontsize=10,
                        color=PhEWP.color)
            iskip = 0
    print("Number of PhEWs: ", count)
    return keys
Example #15
0
def find_ascale_range_for_redshift(z, dtime=1.e9):
    amax = 1./(z+1.)
    amin = acosmic(tcosmic(amax) - dtime)
    return amin, amax