def test_bad(self): with self.assertRaises(ValueError): xraylib.GetCompoundDataNISTByName("jwjfpfj") with self.assertRaises(TypeError): xraylib.GetCompoundDataNISTByName(0) with self.assertRaises(ValueError): xraylib.GetCompoundDataNISTByName(None) with self.assertRaises(ValueError): xraylib.GetCompoundDataNISTByIndex(-1) with self.assertRaises(ValueError): xraylib.GetCompoundDataNISTByIndex(180) with self.assertRaises(TypeError): xraylib.GetCompoundDataNISTByIndex(None) with self.assertRaises(TypeError): xraylib.GetCompoundDataNISTByIndex("jpwjfpfwj")
def find_nist_name(compound_name): ''' Get physical properties of one of the compounds registered in nist database ''' import xraylib return xraylib.GetCompoundDataNISTByName(compound_name)
def GetDensity(material): if material == 'H2C': cpH2C = xrl.GetCompoundDataNISTByName('Polyethylene') density = cpH2C['density'] else: Z = xrl.SymbolToAtomicNumber(material) density = xrl.ElementDensity(Z) return density
def test_good(self): list = xraylib.GetCompoundDataNISTList() self.assertEqual(len(list), 180) for i, v in enumerate(list): cdn = xraylib.GetCompoundDataNISTByIndex(i) self.assertEqual(cdn['name'], v) cdn = xraylib.GetCompoundDataNISTByName(v) self.assertEqual(cdn['name'], v) cdn = xraylib.GetCompoundDataNISTByIndex(5) self.assertEqual(cdn['nElements'], 4) self.assertEqual(cdn['density'], 0.001205) self.assertEqual(cdn['Elements'], [6, 7, 8, 18]) self.assertAlmostEqual(cdn['massFractions'], [0.000124, 0.755267, 0.231781, 0.012827]) self.assertEqual(cdn['name'], 'Air, Dry (near sea level)') cdn = xraylib.GetCompoundDataNISTByName('Air, Dry (near sea level)') self.assertEqual(cdn['nElements'], 4) self.assertEqual(cdn['density'], 0.001205) self.assertEqual(cdn['Elements'], [6, 7, 8, 18]) self.assertAlmostEqual(cdn['massFractions'], [0.000124, 0.755267, 0.231781, 0.012827]) self.assertEqual(cdn['name'], 'Air, Dry (near sea level)')
def __init__(self, nistname, name=None): """ Args: nistname(str): NIST name name(Optional[str]): compound name """ data = xraylib.GetCompoundDataNISTByName(nistname) if name is None: name = data["name"] super(CompoundFromNist, self).__init__( data["Elements"], data["massFractions"], types.fraction.mass, data["density"], name=name, )
def phantom_assign_concentration(ph_or, data_type=np.float32): """Builds the phantom used in: - N. Viganò and V. A. Solé, “Physically corrected forward operators for induced emission tomography: a simulation study,” Meas. Sci. Technol., no. Advanced X-Ray Tomography, pp. 1–26, Nov. 2017. :param ph_or: DESCRIPTION :type ph_or: TYPE :param data_type: DESCRIPTION, defaults to np.float32 :type data_type: TYPE, optional :return: DESCRIPTION :rtype: TYPE """ # ph_air = ph_or < 0.1 ph_FeO = 0.5 < ph_or ph_CaO = np.logical_and(0.25 < ph_or, ph_or < 0.5) ph_CaC = np.logical_and(0.1 < ph_or, ph_or < 0.25) conv_mm_to_cm = 1e-1 conv_um_to_mm = 1e-3 voxel_size_um = 0.5 voxel_size_cm = voxel_size_um * conv_um_to_mm * conv_mm_to_cm # cm to micron print("Sample size: [%g %g] um" % (ph_or.shape[0] * voxel_size_um, ph_or.shape[1] * voxel_size_um)) import xraylib xraylib.XRayInit() cp_fo = xraylib.GetCompoundDataNISTByName("Ferric Oxide") cp_co = xraylib.GetCompoundDataNISTByName("Calcium Oxide") cp_cc = xraylib.GetCompoundDataNISTByName("Calcium Carbonate") ca_an = xraylib.SymbolToAtomicNumber("Ca") ca_kal = xraylib.LineEnergy(ca_an, xraylib.KA_LINE) in_energy_keV = 20 out_energy_keV = ca_kal ph_lin_att_in = ( ph_FeO * xraylib.CS_Total_CP("Ferric Oxide", in_energy_keV) * cp_fo["density"] + ph_CaC * xraylib.CS_Total_CP("Calcium Carbonate", in_energy_keV) * cp_cc["density"] + ph_CaO * xraylib.CS_Total_CP("Calcium Oxide", in_energy_keV) * cp_co["density"]) ph_lin_att_out = ( ph_FeO * xraylib.CS_Total_CP("Ferric Oxide", out_energy_keV) * cp_fo["density"] + ph_CaC * xraylib.CS_Total_CP("Calcium Carbonate", out_energy_keV) * cp_cc["density"] + ph_CaO * xraylib.CS_Total_CP("Calcium Oxide", out_energy_keV) * cp_co["density"]) vol_att_in = ph_lin_att_in * voxel_size_cm vol_att_out = ph_lin_att_out * voxel_size_cm ca_cs = xraylib.CS_FluorLine_Kissel( ca_an, xraylib.KA_LINE, in_energy_keV) # fluo production for cm2/g ph_CaC_mass_fract = cp_cc["massFractions"][np.where( np.array(cp_cc["Elements"]) == ca_an)[0][0]] ph_CaO_mass_fract = cp_co["massFractions"][np.where( np.array(cp_co["Elements"]) == ca_an)[0][0]] ph = ph_CaC * ph_CaC_mass_fract * cp_cc[ "density"] + ph_CaO * ph_CaO_mass_fract * cp_co["density"] ph = ph * ca_cs * voxel_size_cm return (ph, vol_att_in, vol_att_out)
FH = xraylib.Crystal_F_H_StructureFactor(cryst, energy, 3, 3, 1, debye_temp_factor, rel_angle) print(" FH(3,3,1) structure factor: ({}, {})".format(FH.real, FH.imag)) F0 = xraylib.Crystal_F_H_StructureFactor(cryst, energy, 0, 0, 0, debye_temp_factor, rel_angle) print(" F0=FH(0,0,0) structure factor: ({}, {})".format(F0.real, F0.imag)) crystals = xraylib.Crystal_GetCrystalsList() print("List of available crystals:") for i in range(len(crystals)): print(" Crystal {}: {}".format(i, crystals[i])) print("") cdn = xraylib.GetCompoundDataNISTByName("Uranium Monocarbide") print("Uranium Monocarbide") print(" Name: {}".format(cdn['name'])) print(" Density: {}".format(cdn['density'])) for i in range(cdn['nElements']): print(" Element {}: {} %%".format(cdn['Elements'][i], cdn['massFractions'][i] * 100.0)) cdn = xraylib.GetCompoundDataNISTByIndex(xraylib.NIST_COMPOUND_BRAIN_ICRP) print("NIST_COMPOUND_BRAIN_ICRP") print(" Name: {}".format(cdn['name'])) print(" Density: {}".format(cdn['density'])) for i in range(cdn['nElements']): print(" Element {}: {} %%".format(cdn['Elements'][i], cdn['massFractions'][i] * 100.0))
0.95, name="pe") compounddb["pan"] = compoundfromformula.CompoundFromFormula("C3H3N", 1.184, name="pan") compounddb["pva"] = compoundfromformula.CompoundFromFormula("C3H3N", 1.19, name="pva") compounddb["pp"] = compoundfromformula.CompoundFromFormula("C3H6", 0.86, name="pp") compounddb["specx pp"] = compoundfromformula.CompoundFromFormula( "C3H6", 1.1289633445, name="pp") data = xraylib.GetCompoundDataNISTByName("Kapton Polyimide Film") compounddb["kapton"] = compound.Compound( data["Elements"], data["massFractions"], types.fraction.mass, data["density"], name="kapton", ) compounddb["specx kapton"] = compound.Compound( data["Elements"], data["massFractions"], types.fraction.mass, 1.35297609903, name="kapton", )
def find_name(compound_name): return xraylib.GetCompoundDataNISTByName(compound_name)