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)
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
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
def thick_material(request): return Material(request.param, 500 * u.Mm)
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)
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)
def test_twomaterials_to_compound(material): # check that adding two materials returns a compound assert isinstance(material + Material('Si', 500 * u.micron), Compound)
def material(request): return Material(request.param, 500 * u.micron)
def thin_material(request): return Material(request.param, 1e-6 * u.pm)