Beispiel #1
0
def galaxy_ang_mom(gal_id, basePath, snapNum, reduced=True):
    """
    Parameters
    ----------
    gal_id : int
    basepath : string
    snapNum : int
    Lbox : array_like
    reduced : bool
    Returns
    -------
    eig_vals, eig_vecs
    """

    # load galaxy position (most bound particle)
    gal_positions = loadSubhalos(basePath, snapNum, fields=['SubhaloPos'
                                                            ]) / 1000.0
    gal_position = gal_positions[gal_id]

    # half mass radius
    gal_rhalfs = loadSubhalos(
        basePath, snapNum, fields=['SubhaloHalfmassRadType'])[:, 4] / 1000.0
    gal_rhalf = gal_rhalfs[gal_id]

    # load stellar particles
    ptcl_coords = loadSubhalo(
        basePath, snapNum, gal_id, 4, fields=['Coordinates']) / 1000.0
    ptcl_masses = loadSubhalo(basePath, snapNum, gal_id, 4,
                              fields=['Masses']) * 10.0**10
    ptcl_vels = loadSubhalo(basePath,
                            snapNum,
                            gal_id,
                            4,
                            fields=['Velocities'])
    sf_time = loadSubhalo(basePath,
                          snapNum,
                          gal_id,
                          4,
                          fields=['GFM_StellarFormationTime'])
    is_a_star = (sf_time >= 0.0)  # don't use wind particles

    # account for PBCs
    dx = ptcl_coords[:, 0] - gal_position[0]
    dy = ptcl_coords[:, 1] - gal_position[1]
    dz = ptcl_coords[:, 2] - gal_position[2]

    ptcl_coords = np.vstack((dx, dy, dz)).T

    r = np.sqrt(np.sum(ptcl_coords**2, axis=1)) / gal_rhalf
    mask = (r <= 10.0) & (is_a_star)

    L = specific_angular_momentum(ptcl_coords[mask], ptcl_vels[mask],
                                  ptcl_masses[mask])

    mag_L = np.sqrt(np.sum(L**2, axis=-1))

    return L, mag_L, L / mag_L
def main():

    if len(sys.argv) > 1:
        sim_name = sys.argv[1]
        snapNum = int(sys.argv[2])
        num_r_half = float(sys.argv[3])
    else:
        sim_name = 'Illustris-1'  # full physics high-res run
        snapNum = 135  # z=0
        num_r_half = 10.0

    # get simulation properties
    d = sim_prop_dict[sim_name]
    basePath = d['basePath']
    m_dm = d['m_dm']
    litte_h = d['litte_h']
    Lbox = d['Lbox']

    # make galaxy selection
    min_mstar = litte_h * 10.0**9.0
    mask, gal_ids = galaxy_selection(min_mstar, basePath, snapNum)

    # number of galaxies in selection
    Ngals = len(gal_ids)
    print("number of galaxies in selection: {0}".format(Ngals))

    # load galaxy table
    fields = [
        'SubhaloGrNr', 'SubhaloMassInRadType', 'SubhaloPos',
        'SubhaloHalfmassRadType'
    ]
    galaxy_table = loadSubhalos(basePath, snapNum, fields=fields)

    Lx = np.zeros(Ngals)
    Ly = np.zeros(Ngals)
    Lz = np.zeros(Ngals)
    f_disk = np.zeros(Ngals)

    for i in tqdm(range(Ngals)):
        gal_id = gal_ids[i]
        f, vec = galaxy_circularity(gal_id, galaxy_table, basePath, snapNum,
                                    Lbox, num_r_half, m_dm)
        f_disk[i] = f
        Lx[i] = vec[0]
        Ly[i] = vec[1]
        Lz[i] = vec[2]

    # save measurements
    fpath = './data/shape_catalogs/'
    fname = sim_name + '_' + str(
        snapNum) + '_galaxy_circularities_' + "{:.1f}".format(
            num_r_half) + '.dat'
    ascii.write([gal_ids, Lx, Ly, Lz, f_disk],
                fpath + fname,
                names=['gal_id', 'Lx', 'Ly', 'Lz', 'f_disk'],
                overwrite=True)
def halo_selection(min_num_ptcls, basePath, snapNum):
    """
    make a cut on number of dm particles
    """

    # make selection
    halo_table = loadSubhalos(basePath,
                              snapNum,
                              fields=['SubhaloGrNr', 'SubhaloLenType'])

    halo_ids = np.arange(0, len(halo_table['SubhaloGrNr']))

    # mass of stellar particles within 2*R_half
    mask = halo_table['SubhaloLenType'][:, 1] >= min_num_ptcls

    return mask, halo_ids[mask]
Beispiel #4
0
def galaxy_selection(min_mstar, basePath, snapNum):
    """
    make a cut on galaxy properties
    """

    # make selection
    galaxy_table = loadSubhalos(basePath, snapNum, fields=['SubhaloGrNr', 'SubhaloMassInRadType'])

    gal_ids = np.arange(0,len(galaxy_table['SubhaloGrNr']))

    # mass of stellar particles within 2*R_half
    mstar = galaxy_table['SubhaloMassInRadType'][:,4]
    mstar = mstar*10**10

    mask = (mstar >= min_mstar)

    return mask, gal_ids[mask]
Beispiel #5
0
import matplotlib.pyplot as plt
import illustris_python.groupcat as gc
import numpy as np

basePath = "/hpcfs/home/ciencias/fisica/docentes/je.forero/Illustris-1/"

subhalo_fields = ['SubhaloMass', 'SubhaloSFRinRad']
subhalos = gc.loadSubhalos(basePath, 135, fields=subhalo_fields)

halo_fields = ['GroupFirstSub', 'Group_M_Crit200', 'GroupNsubs']
halos = gc.loadHalos(basePath, 135, fields=halo_fields)

for k in subhalos.keys():
    print(k)

for k in halos.keys():
    print(k)

mass_msun = halos['Group_M_Crit200'] * 1e10 / 0.704
n_in_halo = halos['GroupNsubs']

fig = plt.figure(1, figsize=(11, 10))
plt.plot(mass_msun, n_in_halo, '.')

ax = plt.axes()
ax.set_xlim([1E9, 1E15])
ax.set_ylim([1, 1E5])

plt.xscale('log')
plt.yscale('log')
plt.xlabel('Total Mass [$M_\odot$]')
def main():

    if len(sys.argv) > 1:
        sim_name = sys.argv[1]
        snapNum = int(sys.argv[2])
    else:
        sim_name = 'Illustris-1'  # full physics high-res run
        snapNum = 135  # z=0

    # get simulation properties
    d = sim_prop_dict[sim_name]
    basePath = d['basePath']
    m_dm = d['m_dm']
    litte_h = d['litte_h']
    Lbox = d['Lbox']

    # make galaxy selection
    min_mstar = litte_h * 10.0**8.0
    min_ndark = 1000
    mask, gal_ids = galaxy_selection(min_mstar, min_ndark, basePath, snapNum)

    # number of galaxies in selection
    Ngals = len(gal_ids)
    print("number of galaxies in selection: {0}".format(Ngals))

    fields = [
        'SubhaloGrNr', 'SubhaloMassInRadType', 'SubhaloMassType', 'SubhaloPos',
        'SubhaloVel', 'SubhaloLenType', 'SubhaloStellarPhotometrics'
    ]

    galaxy_table = loadSubhalos(basePath, snapNum, fields=fields)

    # FoF host halo ID
    host_halo_ids = galaxy_table['SubhaloGrNr'][gal_ids]

    x = galaxy_table['SubhaloPos'][:, 0][gal_ids]
    y = galaxy_table['SubhaloPos'][:, 1][gal_ids]
    z = galaxy_table['SubhaloPos'][:, 2][gal_ids]

    vx = galaxy_table['SubhaloVel'][:, 0][gal_ids]
    vy = galaxy_table['SubhaloVel'][:, 1][gal_ids]
    vz = galaxy_table['SubhaloVel'][:, 2][gal_ids]

    ndark = galaxy_table['SubhaloLenType'][:, 1][gal_ids]
    nstar = galaxy_table['SubhaloLenType'][:, 4][gal_ids]

    gmag = galaxy_table['SubhaloStellarPhotometrics'][:, 4][gal_ids]
    rmag = galaxy_table['SubhaloStellarPhotometrics'][:, 5][gal_ids]
    imag = galaxy_table['SubhaloStellarPhotometrics'][:, 6][gal_ids]

    mstar_in_twice_halfrad = galaxy_table['SubhaloMassInRadType'][:,
                                                                  4][gal_ids]
    mstar_in_twice_halfrad = mstar_in_twice_halfrad * 10**10

    mstar_all = galaxy_table['SubhaloMassType'][:, 4][gal_ids]
    mstar_all = mstar_all * 10**10

    # central galaxy ID of group
    fields = [
        'GroupFirstSub', 'Group_M_Mean200', 'Group_R_Mean200', 'GroupMass'
    ]
    host_halo_table = loadHalos(basePath, snapNum, fields=fields)
    central_id = host_halo_table['GroupFirstSub'][host_halo_ids]

    # host halo properties
    host_halo_mass_200m = host_halo_table['Group_M_Mean200'][host_halo_ids]
    host_halo_radius_200m = host_halo_table['Group_R_Mean200'][host_halo_ids]
    host_halo_fof_mass = host_halo_table['GroupMass'][host_halo_ids]

    # save table
    fpath = './data/value_added_catalogs/'
    fname = sim_name + '_' + str(snapNum) + '_vagc.dat'
    ascii.write([
        gal_ids, host_halo_ids, central_id, x, y, z, vx, vy, vz, ndark, nstar,
        mstar_in_twice_halfrad, mstar_all, gmag, rmag, imag,
        host_halo_mass_200m, host_halo_radius_200m, host_halo_fof_mass
    ],
                fpath + fname,
                names=[
                    'gal_id', 'host_halo_id', 'central_id', 'x', 'y', 'z',
                    'vx', 'vy', 'vz', 'npart_dm', 'npart_stellar',
                    'stellar_mass_in_twice_halfrad', 'stellar_mass_all',
                    'gmag', 'rmag', 'imag', 'host_halo_mass_200m',
                    'host_halo_radius_200m', 'host_halo_fof_mass'
                ],
                overwrite=True)
def main():

    if len(sys.argv) > 1:
        sim_name = sys.argv[1]
        snapNum = int(sys.argv[2])
        shape_type = sys.argv[3]
    else:
        sim_name = 'Illustris-1'  # full physics high-res run
        snapNum = 135  # z=0
        shape_type = 'reduced'  # non-reduced, reduced, iterative

    # get simulation properties
    d = sim_prop_dict[sim_name]
    basePath = d['basePath']
    m_dm = d['m_dm']
    litte_h = d['litte_h']
    Lbox = d['Lbox']

    # make haloselection
    min_num_ptcls = 1000
    mask, halo_ids = halo_selection(min_num_ptcls, basePath, snapNum)

    # number of galaxies in selection
    Nhaloes = len(halo_ids)
    print("number of haloes in selection: {0}".format(Nhaloes))

    # load galaxy table
    fields = [
        'SubhaloGrNr',
        'SubhaloPos',
    ]
    halo_table = loadSubhalos(basePath, snapNum, fields=fields)

    # create array to store shape properties
    # eigen values
    a = np.zeros(Nhaloes)
    b = np.zeros(Nhaloes)
    c = np.zeros(Nhaloes)
    # eigen vectors
    av = np.zeros((Nhaloes, 3))
    bv = np.zeros((Nhaloes, 3))
    cv = np.zeros((Nhaloes, 3))

    # loop over the list of galaxy IDs
    for i in tqdm(range(Nhaloes)):
        halo_id = halo_ids[i]
        evals, evecs = halo_shape(halo_id,
                                  halo_table,
                                  basePath,
                                  snapNum,
                                  Lbox,
                                  shape_type=shape_type)
        a[i] = evals[2]
        b[i] = evals[1]
        c[i] = evals[0]
        av[i, :] = evecs[:, 2]
        bv[i, :] = evecs[:, 1]
        cv[i, :] = evecs[:, 0]

    # save measurements
    fpath = './data/shape_catalogs/'
    fname = sim_name + '_' + str(
        snapNum) + '_' + shape_type + '_halo_shapes.dat'
    ascii.write([
        halo_ids, a, b, c, av[:, 0], av[:, 1], av[:, 2], bv[:, 0], bv[:, 1],
        bv[:, 2], cv[:, 0], cv[:, 1], cv[:, 2]
    ],
                fpath + fname,
                names=[
                    'halo_id', 'a', 'b', 'c', 'av_x', 'av_y', 'av_z', 'bv_x',
                    'bv_y', 'bv_z', 'cv_x', 'cv_y', 'cv_z'
                ],
                overwrite=True)