def __init__(self, material): """ Parameters ---------- material_str : str A string representation of the material which includes an element symbol (e.g. Si), an element name (e.g. Silicon), or the name of a compound (e.g. cdte, mylar). """ if is_an_element(material): atomic_number = get_atomic_number(material) datafile_path = os.path.join( _data_directory, "elements", "z" + str(atomic_number).zfill(2) + ".csv") symbol = roentgen.elements[atomic_number - 1]["symbol"] name = roentgen.elements[atomic_number - 1]["name"] elif is_in_known_compounds(material): compound_index = get_compound_index(material) symbol = roentgen.compounds[compound_index]["symbol"] name = roentgen.compounds[compound_index]["name"] datafile_path = os.path.join(_data_directory, "compounds_mixtures", symbol.replace(" ", "_") + ".csv") else: return NameError("Element or compound not found.") data = np.loadtxt(datafile_path, delimiter=",") # find the material in our list self.symbol = symbol self.name = name self.energy = u.Quantity(data[:, 0] * 1000, "keV") self.data = u.Quantity(data[:, 1], "cm^2/g") data_energy_kev = np.log10(self.energy.value) data_attenuation_coeff = np.log10(self.data.value) self._f = interpolate.interp1d(data_energy_kev, data_attenuation_coeff, bounds_error=False, fill_value=0.0) self.func = lambda x: u.Quantity( 10**self._f(np.log10(x.to("keV").value)), "cm^2/g")
def test_is_an_element_caseinsensitive_name(): """Test that searching for an element name is not case sensitive""" for el in roentgen.elements['name']: assert is_an_element(el.upper()) assert is_an_element(el.lower()) assert is_an_element(el.capitalize())
def test_is_an_element_name(): """Test that function is okay with all known elements names""" for el in roentgen.elements['name']: assert (is_an_element(el))
def test_is_an_element_symbol(): """Test that function is okay with all known elements symbols""" for el in roentgen.elements['symbol']: assert (is_an_element(el))