Esempio n. 1
0
def read_stars_data(fname):
    stars = genfromtxt(fname, dtype='i8,i8,i8,i8,f8,f8,f8', names=True)
    # Idx, ID, GID, HID, Mass, Tmax, Age
    print stars.dtype
    stars['Mass'] = stars['Mass'] * unit_m * 1.e10 / 0.7
    for i in range(len(stars['Age'])):
        if (stars['Age'][i] > 0):
            stars['Age'][i] = acosmic(stars['Age'][i])
    return stars
Esempio n. 2
0
def read_gal_data(fname):
    gal = genfromtxt(fname, dtype='i8,i8,f8,f8,f8', names=True)
    # Idx, ID, Mass, Tmax, Age
    print gal.dtype
    gal['Mass'] = gal['Mass'] * unit_m * 1.e10 / 0.7
    for i in range(len(gal['Age'])):
        if (gal['Age'][i] > 0):
            gal['Age'][i] = acosmic(gal['Age'][i])
    return gal
Esempio n. 3
0
def read_stars_data(fname, flag_phew=False):
    stars = genfromtxt(fname, dtype='i8,i8,i8,i8,f8,f8,f8', names=True)
    # Idx, ID, GID, HID, Mass, Tmax, Age
    print stars.dtype
    stars['Mass'] = stars['Mass'] * unit_m * 1.e10 / 0.7 * 2.0e33
    # 'Age' used to be the real age. Now is the a_form
    if(flag_phew == False):
        for i in range(len(stars['Age'])):
            if(stars['Age'][i] > 0):
                stars['Age'][i] = acosmic(stars['Age'][i])
    return stars
Esempio n. 4
0
def read_stars_data(fname, stellar_age_in_ascale=True):
    stars = genfromtxt(fname, dtype='i8,i8,i8,i8,f8,f8,f8', names=True)
    # Idx, ID, GID, HID, Mass, Tmax, Age
    print(stars.dtype)
    stars['Mass'] = stars['Mass'] * unit_m * 1.e10 / 0.7 * 2.0e33
    # 'Age' used to be the real age. Now is the a_form
    if (stellar_age_in_ascale == False
        ):  # Force Convert the 'Age' field to ascale
        for i in range(len(stars['Age'])):
            if (stars['Age'][i] > 0):
                stars['Age'][i] = acosmic(stars['Age'][i])
    return stars
Esempio n. 5
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)
Esempio n. 6
0
def load_sfrinfo(stars, gals, sfrinfobase, outname, flag_format):
    # flag_format: The format of the SFRINFO file
    # Let's be concerned ONLY with STARS.
    # Idea: Loop over all sfrinfo.* files.
    # For each sfrinfo.* file, guided loop over particle ID.
    #   - a(sfrinfo) < a(fstars) is a sure thing.
    # Both files should be ranked with PID.
    #   - For a fast searching, should bin PID into bins
    # Each time sfrinfo.* finds a likely match for a PID, find
    #   - tmax(sfrinfo), tmax(fstars)
    # If tmax match, then YES!

    fformat, cols = format_of_sfrinfo_file(flag_format)
    print("flag_format = ", flag_format)
    print(fformat)
    print(cols)

    # stars = sort(stars, order='ID') # Order By StarP.ID(AccKey)
    acckey_to_sidx = dict()
    acckey_to_alast = dict()
    acckeys = stars['ID']
    smass = stars['Mass']
    for i in range(len(acckeys)):
        acckey_to_sidx[acckeys[i]] = i
        acckey_to_alast[acckeys[i]] = 0.0

    nparts = len(stars)
    aacc, alast, pmass, wmass, metals = [-1] * nparts, [-1] * nparts, [
        0.0
    ] * nparts, [0.0] * nparts, [-1.0] * nparts  # update: 20200110
    if (flag_format == "GIZMO-PhEW-Extra"):
        tavg, sigavg = [-1] * nparts, [0.0] * nparts
    # ---------------- LOOP: NCPU ----------------
    for fi in range(NCPU):
        fsfrinfo = sfrinfobase + "sfrinfo." + str(fi)
        print("Reading: ", fsfrinfo)
        if (not os.path.exists(fsfrinfo)): break
        # acc = genfromtxt(fsfrinfo, dtype=fformat, usecols=cols) # update: 20200110
        acc = pd.read_csv(fsfrinfo,
                          usecols=[
                              'atime', 'AccKey', 'LastSFTime', 'Tmax',
                              'WindMass', 'Mass', 'Z', 't1', 't3'
                          ])
        acc.rename(columns={
            "LastSFTime": "alast",
            "Tmax": "tmax",
            "WindMass": "wmass",
            "Mass": "mass"
        },
                   inplace=True)
        acc = acc[acc['alast'] == 0]  # excluding 'spurious accretions'
        acckeys = acc['AccKey']
        for iacc in range(len(acc)):
            last_sf_time = acc['alast'].iloc[iacc]  # LastSFTime
            thiskey = acckeys.iloc[iacc]
            if (thiskey in acckey_to_sidx):  # Match
                # Now find the most recent major accretion event
                if (abs(acc['alast'].iloc[iacc]) >= acckey_to_alast[thiskey]):
                    acckey_to_alast[thiskey] = abs(acc['alast'].iloc[iacc])
                else:
                    continue
                sidx = acckey_to_sidx[acckeys.iloc[iacc]]
                aacc[sidx] = acc['atime'].iloc[iacc]  # Accretion Time
                alast[sidx] = last_sf_time
                pmass[sidx] = acc['mass'].iloc[
                    iacc]  # Particle Mass At Accretion
                metals[sidx] = acc['Z'].iloc[iacc]  # Metallicity
                if (flag_format == "GIZMO-PhEWOff"):
                    wmass[sidx] = acc['mass'].iloc[
                        iacc] if last_sf_time < 0 else 0.0
                if (flag_format == "GIZMO-PhEW-Extra"):
                    wmass[sidx] = acc['wmass'].iloc[iacc]  # add: 20200110
                    tavg[sidx] = acc['t1'].iloc[iacc] / acc['wmass'].iloc[
                        iacc]  # add: 20200724
                    if (tavg[sidx] > 1.34e10):
                        tavg[sidx] = 1.0
                    elif (tavg[sidx] < 1.e6):
                        tavg[sidx] = 0.0
                    else:
                        tavg[sidx] = acosmic(tavg[sidx])
                    sigavg[sidx] = acc['t3'].iloc[iacc] / acc['wmass'].iloc[
                        iacc]  # add: 20200724
    fout = open(outname, "w")
    if (flag_format == "GIZMO-PhEW-Extra"):
        fout.write(
            "#a_form a_acc a_last Mass StarMass WindMass WindAge WindSig Tmax Z GID HID\n"
        )  # update: 20200724
    else:
        fout.write(
            "#a_form a_acc a_last Mass StarMass WindMass Tmax Z GID HID\n"
        )  # update: 20200110
    for istars in range(len(stars)):
        gid, hid = stars['GID'][istars], stars['HID'][istars]
        # update: 20200110
        if (flag_format == "GIZMO-PhEW-Extra"):
            line = "%7.5f %7.5f % 7.5f %7.5e %7.5e %7.5e %7.5f %5.1f % 5.3f %7.5e %5d %5d\n" % \
            (stars['Age'][istars], aacc[istars], alast[istars], \
             pmass[istars], smass[istars], wmass[istars], tavg[istars], sigavg[istars], \
             stars['Tmax'][istars], metals[istars], \
             gid, hid)
        else:
            line = "%7.5f %7.5f % 7.5f %7.5e %7.5e %7.5e % 5.3f %7.5e %5d %5d\n" % \
            (stars['Age'][istars], aacc[istars], alast[istars], \
             pmass[istars], smass[istars], wmass[istars], \
             stars['Tmax'][istars], metals[istars], \
             gid, hid)
        fout.write(line)
    fout.close()
Esempio n. 7
0
def find_windtime_bin(twind):
    if(twind > 1.34e10): awind = 0.99
    elif(twind < 1.e6): awind = 0.0
    else: awind = acosmic(twind)
    bin_idx = awind / da
    return (int)(bin_idx)
Esempio n. 8
0
def find_ascale_range_for_redshift(z, dtime=1.e9):
    amax = 1./(z+1.)
    amin = acosmic(tcosmic(amax) - dtime)
    return amin, amax
Esempio n. 9
0
def load_sfrinfo(stars, gals, sfrinfobase, outname, flag_format):
    # flag_format: The format of the SFRINFO file
    # Let's be concerned ONLY with STARS.
    # Idea: Loop over all sfrinfo.* files.
    # For each sfrinfo.* file, guided loop over particle ID.
    #   - a(sfrinfo) < a(fstars) is a sure thing.
    # Both files should be ranked with PID.
    #   - For a fast searching, should bin PID into bins
    # Each time sfrinfo.* finds a likely match for a PID, find
    #   - tmax(sfrinfo), tmax(fstars)
    # If tmax match, then YES!

    fformat, cols = format_of_sfrinfo_file(flag_format)
    print("flag_format = ", flag_format)
    print(fformat)
    print(cols)

    stars = sort(stars, order='ID')
    smass = stars['Mass']

    nparts = len(stars)
    aacc, alast, tmaxdiff, pmass, wmass, metals = [-1] * nparts, [
        -1
    ] * nparts, [10.] * nparts, [0.0] * nparts, [0.0] * nparts, [
        -1.0
    ] * nparts  # update: 20200110
    if (flag_format == "GIZMO-PhEW-Extra"):
        tavg, sigavg = [-1] * nparts, [0.0] * nparts
    for fi in range(NCPU):
        fsfrinfo = sfrinfobase + "sfrinfo." + str(fi)
        print("Reading: ", fsfrinfo)
        if (not os.path.exists(fsfrinfo)): break
        acc = genfromtxt(fsfrinfo, dtype=fformat,
                         usecols=cols)  # update: 20200110
        acc = sort(acc, order='ID')
        istars, nextPID = 0, stars['ID'][0]
        for iacc in range(len(acc)):
            if (istars > nparts - 1): break
            if (acc['ID'][iacc] < nextPID): continue
            # Now acc.ID >= nextPID
            # while(stars['ID'][istars] == nextPID): # Start counting in the stars array
            while (acc['ID'][iacc] >=
                   nextPID):  # Start counting in the stars array
                if (acc['ID'][iacc] == nextPID
                    ):  # For each stars particle, see if a match is found
                    # Do the spurious accretion check
                    # if(discard_spurious_accretion(acc['atime'][iacc], acc['alast'][iacc])): continue
                    # if(tcosmic(acc['atime'][iacc]) - tcosmic(acc['alast'][iacc]) >= DTTOL):
                    # Original value: 0.008
                    if (acc['atime'][iacc] - acc['alast'][iacc] >= 0.03):

                        # THE NEAREST ACCRETION EVENT THAT IS EITHER PRISTINE OR WIND
                        # if(acc['alast'][iacc] <= 0.0 and acc['atime'][iacc] > aacc[istars] and acc['atime'][iacc] < stars['Age'][istars]):

                        if (match_check(acc['tmax'][iacc],
                                        stars['Tmax'][istars],
                                        tol=tmaxdiff[istars])):  # tmaxs match
                            if (acc['atime'][iacc] < stars['Age'][istars] +
                                    ATOL):  # SF after accretion
                                aacc[istars] = acc['atime'][iacc]
                                alast[istars] = acc['alast'][iacc]
                                pmass[istars] = acc['mass'][
                                    iacc]  # add: 20200110
                                metals[istars] = acc['Z'][iacc]
                                tmaxdiff[istars] = abs(acc['tmax'][iacc] -
                                                       stars['Tmax'][istars])
                                if (flag_format != "Gadget3"):
                                    wmass[istars] = acc['wmass'][
                                        iacc]  # add: 20200110
                                if (flag_format == "GIZMO-PhEW-Extra"):
                                    tavg[istars] = acc['t1'][iacc] / acc[
                                        'wmass'][iacc]  # add: 20200724
                                    if (tavg[istars] > 1.34e10):
                                        tavg[istars] = 1.0
                                    elif (tavg[istars] < 1.e6):
                                        tavg[istars] = 0.0
                                    else:
                                        tavg[istars] = acosmic(tavg[istars])
                                    sigavg[istars] = acc['t3'][iacc] / acc[
                                        'wmass'][iacc]  # add: 20200724
                                # End (acc['ID'][iacc] == nextPID)
                istars += 1
                if (istars > nparts - 1): break  # No particle to match!
                # while(acc['ID'][iacc] >= nextPID):
                nextPID = stars['ID'][istars]  # now updated.
    # Now we got aacc, alast, tmaxdiff.
    # Now Write:
    fout = open(outname, "w")
    if (flag_format == "GIZMO-PhEW-Extra"):
        fout.write(
            "#a_form a_acc a_last Mass StarMass WindMass WindAge WindSig Tmax Z GID HID\n"
        )  # update: 20200724
    else:
        fout.write(
            "#a_form a_acc a_last Mass WindMass StarMass Tmax Z GID HID\n"
        )  # update: 20200110
    for istars in range(len(stars)):
        gid, hid = stars['GID'][istars], stars['HID'][istars]
        # if(gid != 0): mstar = gals[gid-1].mstar
        # else: mstar = -inf
        # if(hid != 0):
        #     if(abs(hid) >= len(gals)):
        #         print istars, hid, len(gals)
        #         continue
        #     else:
        #         mvir = gals[abs(hid)-1].mvir
        # else: mvir = -inf
        # if(gid != hid): # non-central
        #     mvir *= -1
        # update: 20200110
        if (flag_format == "GIZMO-PhEW-Extra"):
            line = "%7.5f %7.5f % 7.5f %7.5e %7.5e %7.5e %7.5f %5.1f % 5.3f %7.5e %5d %5d\n" % \
            (stars['Age'][istars], aacc[istars], alast[istars], \
             pmass[istars], smass[istars], wmass[istars], tavg[istars], sigavg[istars], \
             stars['Tmax'][istars], metals[istars], \
             gid, hid)
        else:
            line = "%7.5f %7.5f % 7.5f %7.5e %7.5e %7.5e % 5.3f %7.5e %5d %5d\n" % \
            (stars['Age'][istars], aacc[istars], alast[istars], \
             pmass[istars], smass[istars], wmass[istars], \
             stars['Tmax'][istars], metals[istars], \
             gid, hid)
        fout.write(line)
    fout.close()