Exemplo n.º 1
0
def test_ion_list(particle, min_charge, max_charge, expected_charge_numbers):
    """Test that inputs to ionic_levels are interpreted correctly."""
    particle = Particle(particle)
    ions = ionic_levels(particle, min_charge, max_charge)
    np.testing.assert_equal(ions.charge_number, expected_charge_numbers)
    assert ions[0].element == particle.element
    if particle.is_category("isotope"):
        assert ions[0].isotope == particle.isotope
Exemplo n.º 2
0
def test_weighted_mean_ion(base_particle, ionic_fractions, physical_property):
    """
    Test that `IonizationState.average_ion` gives a |CustomParticle|
    instance with the expected mass or charge when calculating the
    weighted mean.
    """
    ionization_state = IonizationState(base_particle, ionic_fractions)
    ions = ionic_levels(base_particle)
    physical_quantity = getattr(ions, physical_property)
    expected_mean_quantity = np.average(physical_quantity, weights=ionic_fractions)
    mean_ion = ionization_state.average_ion()
    actual_mean_quantity = getattr(mean_ion, physical_property)
    assert_quantity_allclose(actual_mean_quantity, expected_mean_quantity)
Exemplo n.º 3
0
def test_weighted_rms_ion(base_particle, ionic_fractions, physical_property):
    """
    Test that `IonizationState.average_ion` gives a |CustomParticle|
    instances with the expected mass or charge when calculating the
    weighted root mean square.
    """
    ionization_state = IonizationState(base_particle, ionic_fractions)
    ions = ionic_levels(base_particle)
    physical_quantity = getattr(ions, physical_property)
    expected_rms_quantity = np.sqrt(
        np.average(physical_quantity**2, weights=ionic_fractions))
    kwargs = {f"use_rms_{physical_property}": True}
    rms_ion = ionization_state.average_ion(**kwargs)
    actual_rms_quantity = getattr(rms_ion, physical_property)
    assert_quantity_allclose(actual_rms_quantity, expected_rms_quantity)
Exemplo n.º 4
0
def test_invalid_inputs_to_ion_list(element, min_charge, max_charge):
    with pytest.raises(ChargeError):
        ionic_levels(element, min_charge, max_charge)
Exemplo n.º 5
0
def test_ion_list_example():
    ions = ionic_levels("He-4")
    np.testing.assert_equal(ions.charge_number, [0, 1, 2])
    assert ions.symbols == ["He-4 0+", "He-4 1+", "He-4 2+"]
Exemplo n.º 6
0
 def to_list(self) -> ParticleList:
     """
     Return a `~plasmapy.particles.particle_collections.ParticleList`
     of the ionic levels.
     """
     return ionic_levels(self.base_particle)