Ejemplo n.º 1
0
 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")
Ejemplo n.º 2
0
 def nistcp_select(self):
     if self.nist_cb.currentIndex() > 0:
         self.el_cb.setCurrentIndex(0)
         self.cp_le.setText("")
         if self.name == "bet": self.chkbox_luxelht.setChecked(False)
         self.mat = xrl.GetCompoundDataNISTByIndex(
             self.nist_cb.currentIndex() - 1)
         self.apply_mat_thickness()
         self.mat_dens_le.setText(str(self.mat['density']))
         self.apply_mat_density()
     else:
         self.mat = {}
Ejemplo n.º 3
0
    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)')
Ejemplo n.º 4
0
    def xoppy_calc_xcrosssec(self):

        MAT_FLAG = self.MAT_FLAG
        MAT_LIST = self.MAT_LIST
        DESCRIPTOR = self.DESCRIPTOR
        density = self.DENSITY
        CALCULATE = self.CALCULATE
        GRID = self.GRID
        GRIDSTART = self.GRIDSTART
        GRIDEND = self.GRIDEND
        GRIDN = self.GRIDN
        UNIT = self.UNIT

        if MAT_FLAG == 0:  # element
            descriptor = DESCRIPTOR
            density = xraylib.ElementDensity(
                xraylib.SymbolToAtomicNumber(DESCRIPTOR))
        elif MAT_FLAG == 1:  # formula
            descriptor = DESCRIPTOR
        elif MAT_FLAG == 2:
            tmp = xraylib.GetCompoundDataNISTByIndex(MAT_LIST)
            descriptor = tmp["name"]
            density = tmp["density"]

        print("xoppy_calc_xcrosssec: using density = %g g/cm3" % density)
        if GRID == 0:
            energy = numpy.arange(0, 500)
            elefactor = numpy.log10(10000.0 / 30.0) / 300.0
            energy = 10.0 * 10**(energy * elefactor)
        elif GRID == 1:
            if GRIDN == 1:
                energy = numpy.array([GRIDSTART])
            else:
                energy = numpy.linspace(GRIDSTART, GRIDEND, GRIDN)
        elif GRID == 2:
            energy = numpy.array([GRIDSTART])

        if MAT_FLAG == 0:  # element
            out = cross_calc(descriptor,
                             energy,
                             calculate=CALCULATE,
                             density=density)
        elif MAT_FLAG == 1:  # compound parse
            out = cross_calc_mix(descriptor,
                                 energy,
                                 calculate=CALCULATE,
                                 density=density,
                                 parse_or_nist=0)
        elif MAT_FLAG == 2:  # NIST compound
            out = cross_calc_mix(descriptor,
                                 energy,
                                 calculate=CALCULATE,
                                 density=density,
                                 parse_or_nist=1)

        calculate_items = [
            'Total', 'PhotoElectric', 'Rayleigh', 'Compton',
            'Total minus Rayleigh'
        ]
        unit_items = ['barn/atom', 'cm^2', 'cm^2/g', 'cm^-1']
        if energy.size > 1:
            tmp_x = out[0, :].copy()
            tmp_y = out[UNIT + 1, :].copy()
            tmp = numpy.vstack((tmp_x, tmp_y))
            labels = [
                "Photon energy [eV]",
                "%s cross section [%s]" %
                (calculate_items[CALCULATE], unit_items[UNIT])
            ]
            to_return = {
                "application": "xoppy",
                "name": "xcrosssec",
                "data": tmp,
                "labels": labels
            }
        else:
            tmp = None
            txt = "xoppy_calc_xcrosssec: Calculated %s cross section: %g %s" % (
                calculate_items[CALCULATE], out[UNIT + 1, 0], unit_items[UNIT])
            print(txt)
            to_return = {
                "application": "xoppy",
                "name": "xcrosssec",
                "info": txt
            }

        if self.DUMP_TO_FILE:
            with open(self.FILE_NAME, "w") as file:
                try:
                    file.write("#F %s\n" % self.FILE_NAME)
                    file.write("\n#S 1 xoppy CrossSec results\n")
                    file.write("#N 5\n")
                    tmp = "#L  Photon energy [eV]"
                    for unit_item in unit_items:
                        tmp += "  %s [%s]" % (calculate_items[CALCULATE],
                                              unit_item)
                    tmp += "\n"
                    file.write(tmp)
                    for j in range(out.shape[1]):
                        # file.write("%19.12e  "%energy[j])
                        file.write(
                            ("%19.12e  " * out.shape[0] + "\n") %
                            tuple(out[i, j] for i in range(out.shape[0])))
                    file.close()
                    print("File written to disk: %s \n" % self.FILE_NAME)
                except:
                    raise Exception(
                        "CrossSec: The data could not be dumped onto the specified file!\n"
                    )

        return to_return
Ejemplo n.º 5
0
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))

nistCompounds = xraylib.GetCompoundDataNISTList()
print("List of available NIST compounds:")
for i in range(len(nistCompounds)):
    print("  Compound {}: {}".format(i, nistCompounds[i]))

print("")

# radioNuclideData tests
Ejemplo n.º 6
0
from flask import Blueprint, render_template, request

import xraylib

from xray_app.methods.forms import Xraylib_Request, Request_Error, Request_Units
from xray_app.methods.utils import validate_int, validate_float, validate_str, code_example, make_tup, calc_output, all_trans, all_trans_xrf

methods = Blueprint('methods', __name__)
#------------------------------------------------------------------------------------------------------------
# Generates dicts and tuples to populate wtforms choices
nist_dict = {
    xraylib.GetCompoundDataNISTByIndex(int(v))['name']: v
    for k, v in xraylib.__dict__.items() if k.startswith('NIST')
}
rad_dict = {
    xraylib.GetRadioNuclideDataByIndex(int(v))['name']: v
    for k, v in xraylib.__dict__.items() if k.startswith('RADIO')
}
shell_dict = {k: v for k, v in xraylib.__dict__.items() if k.endswith('SHELL')}

trans_dict = {k: v for k, v in xraylib.__dict__.items() if k.endswith('_LINE')}
cs_dict = {
    k: v
    for k, v in xraylib.__dict__.items()
    if k.startswith('CS_') and not k.endswith('CP')
}
dcs_dict = {
    k: v
    for k, v in xraylib.__dict__.items()
    if k.startswith('DCS_') and not k.endswith('CP')
    or k.startswith('DCSP_') and not k.endswith('CP')