예제 #1
0
    def setup_class(cls):

        # Create arguments to IonizationStates that are all consistent
        # with each other.

        cls.ionic_fractions = {"H": [0.9, 0.1], "He": [0.99, 0.01, 0.0]}
        cls.abundances = {"H": 1, "He": 0.08}
        cls.n = 5.3 * u.m ** -3
        cls.number_densities = {
            element: cls.ionic_fractions[element] * cls.n * cls.abundances[element]
            for element in cls.ionic_fractions.keys()
        }

        # The keys that begin with 'ndens' have enough information to
        # yield the number_densities attribute, whereas the keys that
        # begin with "no_ndens" do not.

        cls.dict_of_kwargs = {
            "ndens1": {
                "inputs": cls.ionic_fractions,
                "abundances": cls.abundances,
                "n": cls.n,
            },
            "ndens2": {"inputs": cls.number_densities},
            "no_ndens3": {"inputs": cls.ionic_fractions},
            "no_ndens4": {"inputs": cls.ionic_fractions, "abundances": cls.abundances},
            "no_ndens5": {"inputs": cls.ionic_fractions, "n": cls.n},
        }

        cls.instances = {
            key: IonizationStates(**cls.dict_of_kwargs[key])
            for key in cls.dict_of_kwargs.keys()
        }
예제 #2
0
 def test_instantiation(self, test_name):
     try:
         self.instances[test_name] = IonizationStates(**tests[test_name])
     except Exception:
         pytest.fail(
             f"Cannot create IonizationStates instance for test='{test_name}'"
         )
예제 #3
0
def test_abundances_consistency():
    """Test that ``abundances`` and ``log_abundances`` are consistent."""

    inputs = {"H": [1, 0], "He": [1, 0, 0]}
    abundances = {"H": 1.0, "He": 0.1}
    elements = abundances.keys()

    log_abundances = {element: np.log10(abundances[element]) for element in elements}

    instance_nolog = IonizationStates(inputs, abundances=abundances)
    instance_log = IonizationStates(inputs, log_abundances=log_abundances)

    for element in elements:
        assert np.allclose(
            instance_log.abundances[element], instance_nolog.abundances[element]
        ), "abundances not consistent."

    for element in elements:
        assert np.allclose(
            instance_log.log_abundances[element], instance_nolog.log_abundances[element]
        ), "log_abundances not consistent."
예제 #4
0
    def setup_class(cls):

        cls.initial_ionfracs = {'H': np.array([0.87, 0.13]), 'He': np.array([0.24, 0.37, 0.39])}
        cls.abundances = {'H': 1.0, 'He': 0.0835}
        cls.n = 10 * u.m ** -3

        cls.expected_densities = {
            'H': np.array([8.7, 1.3]) * u.m ** -3,
            'He': np.array([0.2004, 0.30895, 0.32565]) * u.m ** -3,
        }

        cls.expected_electron_density = 2.26025 * u.m ** -3
        cls.states = IonizationStates(cls.initial_ionfracs, abundances=cls.abundances, n=cls.n)
예제 #5
0
 def setup_class(cls):
     cls.elements = ["H", "He", "Li", "Fe"]
     cls.instance = IonizationStates(cls.elements)
     cls.new_n = 5.153 * u.cm**-3
예제 #6
0
 def setup_class(cls):
     cls.states = IonizationStates({
         "H": [0.9, 0.1],
         "He": [0.5, 0.4999, 1e-4]
     })
예제 #7
0
 def test_simple_equality(self, test_name):
     """Test that __eq__ is not extremely broken."""
     a = IonizationStates(**tests[test_name])
     b = IonizationStates(**tests[test_name])
     assert a == a, f"IonizationStates instance does not equal itself."
     assert a == b, f"IonizationStates instance does not equal identical instance."
예제 #8
0
def test_number_density_assignment():
    instance = IonizationStates(["H", "He"])
    number_densities = [2, 3, 5] * u.m**-3
    instance["He"] = number_densities
예제 #9
0
 def setup_class(cls):
     cls.elements = ['H', 'He', 'Li', 'Fe']
     cls.instance = IonizationStates(cls.elements)
     cls.new_n = 5.153 * u.cm ** -3
예제 #10
0
 def setup_class(cls):
     cls.states = IonizationStates({'H': [0.9, 0.1], 'He': [0.5, 0.4999, 1e-4]})