Пример #1
0
def calc_BTF(model, gals):
    """
    Calculates the baryonic Tully-Fisher relation for spiral galaxies in the given set of
    galaxies.

    The number of galaxies added to ``Model.properties["BTF_mass"]`` and
    ``Model.properties["BTF_vel"]`` arrays is given by
    :py:attr:`~sage_analysis.model.Model.sample_size`
    weighted by ``number_spirals_passed /``
    :py:attr:`~sage_analysis.model.Model.num_gals_all_files`. If this value is greater
    than ``number_spirals_passed``, then all spiral galaxies will be used.
    """

    # Make sure we're getting spiral galaxies. That is, don't include galaxies
    # that are too bulgy.
    spirals = np.where((gals["Type"][:] == 0) & (gals["StellarMass"][:] + gals["ColdGas"][:] > 0.0) & \
                       (gals["StellarMass"][:] > 0.0) & (gals["ColdGas"][:] > 0.0) & \
                       (gals["BulgeMass"][:] / gals["StellarMass"][:] > 0.1) & \
                       (gals["BulgeMass"][:] / gals["StellarMass"][:] < 0.5))[0]

    # Select a random subset of galaxies (if necessary).
    spirals = select_random_indices(spirals, model.num_gals_all_files, model.sample_size)

    baryon_mass = np.log10((gals["StellarMass"][:][spirals] + gals["ColdGas"][:][spirals]) * 1.0e10 / model.hubble_h)
    velocity = np.log10(gals["Vmax"][:][spirals])

    model.properties["BTF_mass"] = np.append(model.properties["BTF_mass"], baryon_mass)
    model.properties["BTF_vel"] = np.append(model.properties["BTF_vel"], velocity)
Пример #2
0
def calc_reservoirs(model, gals):
    """
    Calculates the mass in each reservoir as a function of halo virial mass.

    The number of galaxies added to ``Model.properties["reservoir_mvir"]`` and
    ``Model.properties["reservoir_<reservoir_name>"]`` arrays is given by
    :py:attr:`~sage_analysis.model.Model.sample_size` weighted by
    ``number_centrals_passed /`` :py:attr:`~sage_analysis.model.Model.num_gals_all_files`.
    If this value is greater than ``number_centrals_passed``, then all central galaxies
    will be used.
    """

    # To reduce scatter, only use galaxies in halos with mass > 1.0e10 Msun/h.
    centrals = np.where((gals["Type"][:] == 0) & (gals["Mvir"][:] > 1.0) & \
                        (gals["StellarMass"][:] > 0.0))[0]

    # Select a random subset of galaxies (if necessary).
    centrals = select_random_indices(centrals, model.num_gals_all_files, model.sample_size)

    reservoirs = ["Mvir", "StellarMass", "ColdGas", "HotGas",
                  "EjectedMass", "IntraClusterStars"]
    attribute_names = ["mvir", "stars", "cold", "hot", "ejected", "ICS"]

    for (reservoir, attribute_name) in zip(reservoirs, attribute_names):

        mass = np.log10(gals[reservoir][:][centrals] * 1.0e10 / model.hubble_h)

        # Extend the previous list of masses with these new values.
        dict_key = "reservoir_{0}".format(attribute_name)
        model.properties[dict_key] = np.append(model.properties[dict_key], mass)
Пример #3
0
def calc_bh_bulge(model, gals):
    """
    Calculates the black hole mass as a function of bulge mass.

    The number of galaxies added to ``Model.properties["BlackHoleMass"]`` and
    ``Model.properties["BulgeMass"]`` arrays is given by
    :py:attr:`~sage_analysis.model.Model.sample_size` weighted by
    ``number_galaxies_passed /`` :py:attr:`~sage_analysis.model.Model.num_gals_all_files`.
    If this value is greater than ``number_galaxies_passed``, then all galaxies
    will be used.

    Notes
    -----

    We only consider galaxies with bulge mass greater than 10^8 Msun/h and a black
    hole mass greater than 10^5 Msun/h.
    """

    # Only care about galaxies that have appreciable masses.
    my_gals = np.where((gals["BulgeMass"][:] > 0.01) & (gals["BlackHoleMass"][:] > 0.00001))[0]

    # Select a random subset of galaxies (if necessary).
    my_gals = select_random_indices(my_gals, model.num_gals_all_files, model.sample_size)

    bh = np.log10(gals["BlackHoleMass"][:][my_gals] * 1.0e10 / model.hubble_h)
    bulge = np.log10(gals["BulgeMass"][:][my_gals] * 1.0e10 / model.hubble_h)

    model.properties["bh_mass"] = np.append(model.properties["bh_mass"], bh)
    model.properties["bulge_mass"] = np.append(model.properties["bulge_mass"], bulge)
Пример #4
0
def calc_metallicity(model, gals):
    """
    Calculates the metallicity as a function of stellar mass.

    The number of galaxies added to ``Model.properties["metallicity_mass"]`` and
    ``Model.properties["metallicity"]`` arrays is given by
    :py:attr:`~sage_analysis.model.Model.sample_size` weighted by
    ``number_centrals_passed /`` :py:attr:`~sage_analysis.model.Model.num_gals_all_files`.
    If this value is greater than ``number_centrals_passed``, then all central galaxies
    will be used.
    """

    # Only care about central galaxies (Type 0) that have appreciable mass.
    centrals = np.where((gals["Type"][:] == 0) & \
                        (gals["ColdGas"][:] / (gals["StellarMass"][:] + gals["ColdGas"][:]) > 0.1) & \
                        (gals["StellarMass"][:] > 0.01))[0]

    # Select a random subset of galaxies (if necessary).
    centrals = select_random_indices(centrals, model.num_gals_all_files, model.sample_size)

    stellar_mass = np.log10(gals["StellarMass"][:][centrals] * 1.0e10 / model.hubble_h)
    Z = np.log10((gals["MetalsColdGas"][:][centrals] / gals["ColdGas"][:][centrals]) / 0.02) + 9.0

    model.properties["metallicity_mass"] = np.append(model.properties["metallicity_mass"], stellar_mass)
    model.properties["metallicity"] = np.append(model.properties["metallicity"], Z)
Пример #5
0
def calc_gas_fraction(model, gals):
    """
    Calculates the fraction of baryons that are in the cold gas reservoir as a function of
    stellar mass.

    The number of galaxies added to ``Model.properties["gas_frac_mass"]`` and
    ``Model.properties["gas_frac"]`` arrays is given by
    :py:attr:`~sage_analysis.model.Model.sample_size`
    weighted by ``number_spirals_passed /``
    :py:attr:`~sage_analysis.model.Model.num_gals_all_files`. If this value is greater
    than ``number_spirals_passed``, then all spiral galaxies will be used.
    """

    # Make sure we're getting spiral galaxies. That is, don't include galaxies
    # that are too bulgy.
    spirals = np.where((gals["Type"][:] == 0) & (gals["StellarMass"][:] + gals["ColdGas"][:] > 0.0) &
                       (gals["BulgeMass"][:] / gals["StellarMass"][:] > 0.1) & \
                       (gals["BulgeMass"][:] / gals["StellarMass"][:] < 0.5))[0]

    # Select a random subset of galaxies (if necessary).
    spirals = select_random_indices(spirals, model.num_gals_all_files, model.sample_size)

    stellar_mass = np.log10(gals["StellarMass"][:][spirals] * 1.0e10 / model.hubble_h)
    gas_fraction = gals["ColdGas"][:][spirals] / (gals["StellarMass"][:][spirals] + gals["ColdGas"][:][spirals])

    model.properties["gas_frac_mass"] = np.append(model.properties["gas_frac_mass"], stellar_mass)
    model.properties["gas_frac"] = np.append(model.properties["gas_frac"], gas_fraction)
Пример #6
0
def calc_sSFR(model, gals):
    """
    Calculates the specific star formation rate (star formation divided by the stellar
    mass of the galaxy) as a function of stellar mass.

    The number of galaxies added to ``Model.properties["sSFR_mass"]`` and
    ``Model.properties["sSFR_sSFR"]`` arrays is given by
    :py:attr:`~sage_analysis.model.Model.sample_size` weighted by ``number_gals_passed /``
    :py:attr:`~sage_analysis.model.Model.num_gals_all_files`. If
    this value is greater than ``number_gals_passed``, then all galaxies with non-zero
    stellar mass will be used.
    """

    non_zero_stellar = np.where(gals["StellarMass"][:] > 0.0)[0]

    # Select a random subset of galaxies (if necessary).
    random_inds = select_random_indices(non_zero_stellar, model.num_gals_all_files,
                                     model.sample_size)

    stellar_mass = np.log10(gals["StellarMass"][:][random_inds] * 1.0e10 / model.hubble_h)
    sSFR = (gals["SfrDisk"][:][random_inds] + gals["SfrBulge"][:][random_inds]) / \
               (gals["StellarMass"][:][random_inds] * 1.0e10 / model.hubble_h)


    model.properties["sSFR_mass"] = np.append(model.properties["sSFR_mass"], stellar_mass)
    model.properties["sSFR_sSFR"] = np.append(model.properties["sSFR_sSFR"], np.log10(sSFR))
Пример #7
0
def test_random_indices_less_than_number_available(
    local_inds: np.ndarray,
    global_num_inds_available: int,
    global_num_inds_requested: int,
    expected_inds: List[int],
):
    """
    Parameterize Combinations
    -------------------------
    """

    seed = 666
    inds = list(
        select_random_indices(local_inds, global_num_inds_available,
                              global_num_inds_requested, seed))
    assert inds == expected_inds
Пример #8
0
def calc_spatial(model, gals):
    """
    Calculates the spatial position of the galaxies.

    The number of galaxies added to ``Model.properties["<x/y/z>_pos"]`` arrays is given by
    :py:attr:`~sage_analysis.model.Model.sample_size` weighted by
    ``number_galaxies_passed /`` :py:attr:`~sage_analysis.model.Model.num_gals_all_files`.
    If this value is greater than ``number_galaxies_passed``, then all galaxies will be used.
    """

    non_zero = np.where((gals["Mvir"][:] > 0.0) & (gals["StellarMass"][:] > 0.1))[0]

    # Select a random subset of galaxies (if necessary).
    non_zero = select_random_indices(non_zero, model.num_gals_all_files, model.sample_size)

    attribute_names = ["x_pos", "y_pos", "z_pos"]
    data_names = ["Posx", "Posy", "Posz"]

    for (attribute_name, data_name) in zip(attribute_names, data_names):

        # Units are Mpc/h.
        pos = gals[data_name][:][non_zero]

        model.properties[attribute_name] = np.append(model.properties[attribute_name], pos)