Example #1
0
def test_imf_is_zero_if_no_positive_mass(available_imfs):
    for imf in available_imfs:
        assert select_imf(imf).for_mass(0) == 0.0
        assert select_imf(imf).for_mass(-10) == 0.0

        for mass in [0.015, 0.02, 0.2, 0.75, 2, 8, 35, 90]:
            assert select_imf(imf).for_mass(mass) > 0.0
Example #2
0
def test_imf_supernovae_II_is_zero_for_lower_masses():
    imf = select_imf(np.random.choice(settings.valid_values["imf"]),
                     settings.default)

    assert functions.imf_supernovae_II(np.random.sample() * constants.M_SNII,
                                       imf) == 0
    assert functions.imf_supernovae_II(constants.M_SNII, imf) == 0
Example #3
0
def test_imf_supernovae_II_includes_binary_primaries():
    imf = select_imf(np.random.choice(settings.valid_values["imf"]),
                     settings.default)
    m = (constants.B_MIN + constants.B_MAX) / 2

    assert m > constants.M_SNII
    assert functions.imf_supernovae_II(m, imf) > functions.imf_zero(m, imf) / m
Example #4
0
def test_select_imf():
    strings = ["salpeter", "starburst", "chabrier", "ferrini", "kroupa2001", "kroupa2002", "miller_scalo", "maschberger"]
    classes = [Salpeter, Starburst, Chabrier, Ferrini, Kroupa2001, Kroupa2002, MillerScalo, Maschberger]

    for i in range(len(strings)):
        imf_instance = select_imf(strings[i])
        assert type(imf_instance) == classes[i]
Example #5
0
def test_imf_binaries_are_zero_for_non_valid_masses():
    imf = select_imf(np.random.choice(settings.valid_values["imf"]),
                     settings.default)

    assert functions.imf_binary_primary(-1, imf) == 0.0
    assert functions.imf_binary_primary(constants.M_MIN / 2, imf) == 0.0
    assert functions.imf_binary_secondary(-1, imf) == 0.0
    assert functions.imf_binary_secondary(constants.B_MAX * 2, imf) == 0.0
Example #6
0
def test_imf_supernovae_II_non_zero_for_SNII_masses():
    imf = select_imf(np.random.choice(settings.valid_values["imf"]),
                     settings.default)

    assert functions.imf_supernovae_II(constants.M_SNII + 0.01, imf) > 0
    assert functions.imf_supernovae_II(
        constants.M_SNII + np.random.sample() * 100, imf) > 0
    assert functions.imf_supernovae_II(constants.M_SNII + 100, imf) > 0
Example #7
0
def test_global_imf():
    imf = select_imf(np.random.choice(settings.valid_values["imf"]),
                     settings.default)

    assert functions.global_imf(constants.M_MIN - 0.001, imf) == 0
    assert functions.global_imf(100, imf) == functions.imf_zero(100, imf)
    for m in [1, 4, 8, 10, 40]:
        assert 0 < functions.global_imf(m, imf)
        assert functions.imf_zero(100, imf) < functions.global_imf(m, imf)
Example #8
0
def test_imf_binary_secondary_integrates_phi_secondary():
    m_in_binaries_range = 5.0
    m_inf = 2 * m_in_binaries_range
    imf = select_imf(np.random.choice(settings.valid_values["imf"]),
                     settings.default)

    expected = settings.default['binary_fraction'] * \
        functions.newton_cotes(m_inf, constants.B_MAX, functions.phi_secondary(m_in_binaries_range, imf))
    assert functions.imf_binary_secondary(m_in_binaries_range, imf) == expected
Example #9
0
def test_return_fractions():
    imf = select_imf(np.random.choice(settings.valid_values["imf"]),
                     settings.default)
    default_yields_file = settings.default['expelled_elements_filename']
    stellar_yields = elements.Expelled(default_yields_file)

    expected = functions.newton_cotes(
        1, 100, lambda m: (functions.global_imf(m, imf) / m) *
        (m - stellar_yields.for_mass(m)['remnants']))

    assert functions.return_fraction(1, 100, stellar_yields, imf) == expected
Example #10
0
def test_imf_zero():
    m_in_binaries_range = 5.0
    m_lower = constants.B_MIN - 0.5
    m_up = constants.B_MAX + 0.5
    imf = select_imf(np.random.choice(settings.valid_values["imf"]),
                     settings.default)

    assert functions.imf_zero(m_lower, imf) == imf.for_mass(m_lower)
    assert functions.imf_zero(m_up, imf) == imf.for_mass(m_up)

    imf_bin = imf.for_mass(m_in_binaries_range) * (1.0 -
                                                   constants.BIN_FRACTION)
    assert functions.imf_zero(m_in_binaries_range, imf) == imf_bin
Example #11
0
    def init_variables(self):
        self.initial_mass_function = select_imf(self.context["imf"],
                                                self.context)
        self.context["abundances"] = select_abundances(
            self.context["sol_ab"], float(self.context["z"]))
        self.context["expelled"] = elements.Expelled(
            expelled_elements_filename=self.
            context["expelled_elements_filename"])

        self.mass_intervals = []
        self.energies = []
        self.sn_Ia_rates = []

        self.z = self.context["z"]
        self.dtd = select_dtd(self.context["dtd_sn"])
        self.m_min = self.context["m_min"]
        self.m_max = self.context["m_max"]
        self.integration_step = self.context["integration_step"]
        self.total_time_steps = 0
        if "total_time_steps" in self.context:
            self.total_time_steps = self.context["total_time_steps"]

        self.bmaxm = constants.B_MAX / 2
Example #12
0
def test_description_presence(available_imfs):
    for imf in available_imfs:
        assert select_imf(imf).description() != IMF().description()
Example #13
0
def test_minimum_mass_value_for_kroupa_imfs():
    assert select_imf("kroupa2001").for_mass(0.014) == 0.0
    assert select_imf("kroupa2001").for_mass(0.015) > 0.0
    assert select_imf("kroupa2002").for_mass(0.014) == 0.0
    assert select_imf("kroupa2002").for_mass(0.015) > 0.0
Example #14
0
def test_for_mass_is_normalized(available_imfs):
    for imf_name in available_imfs:
        imf = select_imf(imf_name)
        mass = np.random.random() * 10
        imf_for_mass = imf.for_mass(mass)
        assert imf_for_mass == imf.m_phi(mass) * imf.normalization_factor
Example #15
0
def test_phi_m_phi_relation(available_imfs):
    for imf in available_imfs:
        selected_imf = select_imf(imf)
        for mass in [0.015, 0.02, 0.2, 0.75, 2, 8, 35, 90, np.random.random() * 10]:
            assert selected_imf.phi(mass) == selected_imf.m_phi(mass) / mass
Example #16
0
def test_valid_values_presence(available_imfs):
    for imf in available_imfs:
        assert select_imf(imf) is not None
Example #17
0
def test_stars_per_mass_unit(available_imfs):
    for imf in available_imfs:
        selected_imf = select_imf(imf)
        expected = selected_imf.normalization_factor * selected_imf.integrated_phi_in_mass_interval()
        assert selected_imf.stars_per_mass_unit == expected