Example #1
0
def test_compound_calculations(material):
    comp = Material('Ge', 500 * u.micron) + Material('cdte', 100 * u.micron)
    # test that it returns a quantity
    assert isinstance(comp.absorption(energy_array), u.Quantity)
    assert isinstance(comp.transmission(energy_array), u.Quantity)
    # test that it returns the same number of elements as energy array
    assert len(comp.absorption(energy_array)) == len(energy_array)
    assert len(comp.transmission(energy_array)) == len(energy_array)
Example #2
0
    def create_material(cls, name=None, fractional_masses=None, thickness=None, density=None):
        material = Material('h', thickness, density)
        material.name = name
        # probbably don't need this
        material.density = density

        def func(fractional_masses, e):
            return sum([MassAttenuationCoefficient(element).func(e) * frac_mass
                        for element, frac_mass in fractional_masses.items()])

        material_func = partial(func, fractional_masses)

        material.mass_attenuation_coefficient.func = material_func
        return material
Example #3
0
    def create_material(cls,
                        name=None,
                        fractional_masses=None,
                        thickness=None,
                        density=None):
        """
        Create a new material given the composition and fractional masses.

        Parameters
        ----------
        name : `str`
            Name of the meterial
        fractional_masses : `dict`
            The element and fractional masses of the material e.g. `{'H': 0.031, 'O': 0.969}`
        thickness : `astropy.units.Quantity`
            Thickness of the material
        density : `astropy.units.Quantity`
            Density of the material

        Returns
        -------
        `roentgen.absorption.material.Material`
            The material
        """
        material = Material('h', thickness, density)
        material.name = name
        # probably don't need this
        material.density = density

        # TODO remove in favour of upstream fix when completed
        #  see https://github.com/ehsteve/roentgen/issues/26
        def func(composition, e):
            return sum([
                MassAttenuationCoefficient(element).func(e) * frac_mass
                for element, frac_mass in composition.items()
            ])

        material_func = partial(func, fractional_masses)

        material.mass_attenuation_coefficient.func = material_func
        return material
Example #4
0
def thick_material(request):
    return Material(request.param, 500 * u.Mm)
Example #5
0
def test_compound_calculations(material):
    comp = Material('Ge', 500 * u.micron) + Material('cdte', 100 * u.micron)
    # test that it returns the same number of elements as energy array
    assert len(comp.absorption(energy_array)) == len(energy_array)
    assert len(comp.transmission(energy_array)) == len(energy_array)
Example #6
0
def test_threematerials_to_compound(material):
    # check that adding three materials returns a compound
    assert isinstance(
        material + Material('Ge', 500 * u.micron) +
        Material('cdte', 100 * u.micron), Compound)
Example #7
0
def test_twomaterials_to_compound(material):
    # check that adding two materials returns a compound
    assert isinstance(material + Material('Si', 500 * u.micron), Compound)
Example #8
0
def material(request):
    return Material(request.param, 500 * u.micron)
Example #9
0
def thin_material(request):
    return Material(request.param, 1e-6 * u.pm)