コード例 #1
0
def element(elem=None):
    edges = atomic = lines = {}
    if elem is not None:
        atomic = {
            'n': xraydb.atomic_number(elem),
            'mass': xraydb.atomic_mass(elem),
            'density': xraydb.atomic_density(elem)
        }
        _edges = xraydb.xray_edges(elem)
        _lines = xraydb.xray_lines(elem)
        lines = OrderedDict()
        for k in sorted(_lines.keys()):
            en, inten, init, final = _lines[k]  # XrayLine
            lines[k] = XrayLine(energy=f'{en:.1f}',
                                intensity=f'{inten:.5f}',
                                initial_level=init,
                                final_level=final)
        edges = OrderedDict()
        for k in sorted(_edges.keys()):
            en, fy, jump = _edges[k]  # XrayEdge
            edges[k] = XrayEdge(energy=f'{en:.1f}',
                                fyield=f'{fy:.5f}',
                                jump_ratio=f'{jump:.3f}')

    return render_template('elements.html',
                           edges=edges,
                           elem=elem,
                           atomic=atomic,
                           lines=lines,
                           materials_dict=materials_dict)
コード例 #2
0
def look_edges_db(element, edge='all'):
    '''
    uses xray_edges to return energies,fyield and jump ratio
    takes element, specific lines and group of lines
    '''
    try:
        edges = xray_edges(element)
    except:
        raise ValueError(
            'cant find element {}, please try Co, Xe or F'.format(element))
    string = str()
    string = 'edges for {}: \n'.format(element)
    string = string + 'edge \t | energy \t | fyield \t | jump ratio\n'
    if edge == 'all':
        for n in edges.keys():
            string = string + str(n) + '\t | ' + str(
                edges[n][0]) + ' eV' + '\t | ' + str(
                    edges[n][1]) + '\t | ' + str(edges[n][2]) + '\n'
    else:
        edge = edge.upper()
        try:
            for n in edges.keys():
                if n.startswith(edge):
                    string = string + str(n) + '\t | ' + str(
                        edges[n][0]) + ' eV' + '\t | ' + str(
                            edges[n][1]) + '\t | ' + str(edges[n][2]) + '\n'
        except:
            raise ValueError('cant find edge')
    return string
コード例 #3
0
ファイル: run_test.py プロジェクト: tschoonj/conda-recipes
def test_edge_energies():
    from xraydb.xray import _edge_energies

    assert xray_edge(30, 'K') == xray_edge('Zn', 'K')

    for edge in ('k', 'l3', 'l2'):
        for iz in range(1, 98):
            _edge = xray_edge(iz, edge)
            if _edge is not None:
                en = _edge.energy
                assert _edge_energies[edge][iz] < en + 0.5
                assert _edge_energies[edge][iz] > en - 0.5

    assert_allclose(xray_edge('Zn', 'K', energy_only=True), 9660, rtol=0.01)

    sr_edges = xray_edges('Sr')

    assert_allclose(sr_edges['K'].energy, 16105.0,  rtol=0.001)
    assert_allclose(sr_edges['L1'].energy, 2216.0, rtol=0.001)
    assert_allclose(sr_edges['L2'].energy, 2007.0, rtol=0.001)
    assert_allclose(sr_edges['L3'].energy, 1940.0, rtol=0.001)
    assert_allclose(sr_edges['M1'].energy, 358.7, rtol=0.001)
    assert_allclose(sr_edges['M2'].energy, 280.3, rtol=0.001)
    assert_allclose(sr_edges['M3'].energy, 270.0, rtol=0.001)
    assert_allclose(sr_edges['M4'].energy, 136.0, rtol=0.001)
    assert_allclose(sr_edges['M5'].energy, 134.2, rtol=0.001)
    assert_allclose(sr_edges['N1'].energy, 38.9, rtol=0.001)
    assert_allclose(sr_edges['N2'].energy, 21.6, rtol=0.001)
    assert_allclose(sr_edges['N3'].energy, 20.1, rtol=0.001)


    assert_allclose(sr_edges['K'].fyield, 0.664652, rtol=0.001)
    assert_allclose(sr_edges['L1'].fyield, 0.0051, rtol=0.001)
    assert_allclose(sr_edges['L2'].fyield, 0.024, rtol=0.001)
    assert_allclose(sr_edges['L3'].fyield, 0.026, rtol=0.001)
    assert_allclose(sr_edges['M1'].fyield, 5.95e-05, rtol=0.001)
    assert_allclose(sr_edges['M2'].fyield, 3.7e-05, rtol=0.001)
    assert_allclose(sr_edges['M3'].fyield, 0.000105, rtol=0.001)
    assert_allclose(sr_edges['M4'].fyield, 0.0027, rtol=0.001)
    assert_allclose(sr_edges['M5'].fyield, 0.0, rtol=0.001)
    assert_allclose(sr_edges['N1'].fyield, 1.2e-05, rtol=0.001)
    assert_allclose(sr_edges['N2'].fyield, 0.013, rtol=0.001)
    assert_allclose(sr_edges['N3'].fyield, 0.013, rtol=0.001)


    assert_allclose(sr_edges['K'].jump_ratio, 6.888, rtol=0.01)
    assert_allclose(sr_edges['L1'].jump_ratio, 1.1415, rtol=0.01)
    assert_allclose(sr_edges['L2'].jump_ratio, 1.4, rtol=0.01)
    assert_allclose(sr_edges['L3'].jump_ratio, 3.982, rtol=0.01)
    assert_allclose(sr_edges['M1'].jump_ratio, 1.04, rtol=0.01)
    assert_allclose(sr_edges['M2'].jump_ratio, 1.058, rtol=0.01)
    assert_allclose(sr_edges['M3'].jump_ratio, 1.12491, rtol=0.01)
    assert_allclose(sr_edges['M4'].jump_ratio, 1.139, rtol=0.01)
    assert_allclose(sr_edges['M5'].jump_ratio, 1.808, rtol=0.01)
    assert_allclose(sr_edges['N1'].jump_ratio, 1.0, rtol=0.01)
    assert_allclose(sr_edges['N2'].jump_ratio, 1.0, rtol=0.01)
    assert_allclose(sr_edges['N3'].jump_ratio, 1.0, rtol=0.01)
コード例 #4
0
ファイル: webapp.py プロジェクト: newville/xrayweb
def darwinwidth(elem=None):
    edges = atomic = lines = {}
    if elem is not None:
        edges= xraydb.xray_edges(elem)
        atomic= {'n': xraydb.atomic_number(elem),
                 'mass': xraydb.atomic_mass(elem),
                 'density': xraydb.atomic_density(elem)}
        lines= xraydb.xray_lines(elem)
    return render_template('darwinwidth.html', edges=edges, elem=elem,
                           atomic=atomic, lines=lines, materials_dict=materials_dict)
コード例 #5
0
ファイル: webapp.py プロジェクト: newville/xrayweb
def element(elem=None):
    edges = atomic = lines = {}
    if elem is not None:
        atomic= {'n': xraydb.atomic_number(elem),
                 'mass': xraydb.atomic_mass(elem),
                 'density': xraydb.atomic_density(elem)}
        _edges= xraydb.xray_edges(elem)
        _lines= xraydb.xray_lines(elem)
        lines = OrderedDict()
        for k in sorted(_lines.keys()):
            lines[k] = _lines[k]

        edges = OrderedDict()
        for k in sorted(_edges.keys()):
            edges[k] = _edges[k]
    return render_template('elements.html', edges=edges, elem=elem,
                           atomic=atomic, lines=lines, materials_dict=materials_dict)
コード例 #6
0
ファイル: xrf_model.py プロジェクト: yevgenyr/xraylarch
    def __init__(self,
                 symbol,
                 xray_energy=None,
                 energy_min=1.5,
                 overlap_energy=None):
        self.symbol = symbol
        self.xray_energy = xray_energy
        self.mu = 1.0
        self.edges = ['K']
        self.fyields = {}
        if xray_energy is not None:
            self.mu = mu_elam(symbol, 1000 * xray_energy, kind='photo')

            self.edges = []
            for ename, xedge in xray_edges(self.symbol).items():
                if ename.lower() in ('k', 'l1', 'l2', 'l3', 'm5'):
                    edge_kev = 0.001 * xedge.energy
                    if (edge_kev < xray_energy and edge_kev > energy_min):
                        self.edges.append(ename)
                        self.fyields[ename] = xedge.fyield

        # currently, we consider only one edge per element
        if 'K' in self.edges:
            self.edges = ['K']
        if 'L3' in self.edges:
            tmp = []
            for ename in self.edges:
                if ename.lower().startswith('l'):
                    tmp.append(ename)
            self.edges = tmp

        # apply CK corrections to fluorescent yields
        if 'L3' in self.edges:
            nlines = 1.0
            ck13 = ck_probability(symbol, 'L1', 'L3')
            ck12 = ck_probability(symbol, 'L1', 'L2')
            ck23 = ck_probability(symbol, 'L2', 'L3')
            fy3 = self.fyields['L3']
            fy2 = self.fyields.get('L2', 0)
            fy1 = self.fyields.get('L1', 0)
            if 'L2' in self.edges:
                nlines = 2.0
                fy3 = fy3 + fy2 * ck23
                fy2 = fy2 * (1 - ck23)
                if 'L1' in self.edges:
                    nlines = 3.0
                    fy3 = fy3 + fy1 * (ck13 + ck12 * ck23)
                    fy2 = fy2 + fy1 * ck12
                    fy1 = fy1 * (1 - ck12 - ck13 - ck12 * ck23)
                    self.fyields['L1'] = fy1
                self.fyields['L2'] = fy2
            self.fyields['L3'] = fy3 / nlines
            self.fyields['L2'] = fy2 / nlines
            self.fyields['L1'] = fy1 / nlines

        # look up X-ray lines, keep track of very close lines
        # so that they can be consolidate
        # slightly confusing (and working with XrayLine energies in ev)
        self.lines = {}
        self.all_lines = {}
        energy0 = None
        for ename in self.edges:
            for key, xline in xray_lines(symbol, ename).items():
                self.all_lines[key] = xline
                if xline.intensity > 0.002:
                    self.lines[key] = xline
                    if energy0 is None:
                        energy0 = xline.energy

        if overlap_energy is None:
            if xray_energy is None: xray_energy = 10.0
            if energy0 is not None: xray_energy = energy0
            # note: at this point xray_energy is in keV
            overlap_energy = 5.0 * (2 + np.sqrt(5 + xray_energy))

        # collect lines from the same initial level that are close in energy
        nlines = len(self.lines)
        combos = [[] for k in range(nlines)]
        comboe = [-1 for k in range(nlines)]
        combol = [None for k in range(nlines)]
        for key, xline in self.lines.items():
            assigned = False
            for i, en in enumerate(comboe):
                if (abs(0.001 * xline.energy - en) < overlap_energy
                        and xline.initial_level == combol[i]):
                    combos[i].append(key)
                    assigned = True
                    break
            if not assigned:
                for k in range(nlines):
                    if comboe[k] < 0:
                        break
                combol[k] = xline.initial_level
                comboe[k] = xline.energy
                combos[k].append(key)

        # consolidate overlapping X-ray lines
        for comps in combos:
            if len(comps) > 0:
                key = comps[0]
                l0 = self.lines.pop(key)
                ilevel = l0.initial_level
                iweight = l0.intensity
                flevel = [l0.final_level]
                en = [l0.energy]
                wt = [l0.intensity]
                for other in comps[1:]:
                    lx = self.lines.pop(other)
                    if lx.intensity > iweight:
                        iweight = lx.intensity
                        ilevel = lx.initial_level
                    flevel.append(lx.final_level)
                    en.append(lx.energy)
                    wt.append(lx.intensity)
                wt = np.array(wt)
                en = np.array(en)
                flevel = ', '.join(flevel)
                if len(comps) > 1:
                    newkey = key.replace('1', '').replace('2',
                                                          '').replace('3', '')
                    newkey = newkey.replace('4',
                                            '').replace('5',
                                                        '').replace(',', '')
                    if newkey not in self.lines:
                        key = newkey
                self.lines[key] = XrayLine(energy=(en * wt).sum() / wt.sum(),
                                           intensity=wt.sum(),
                                           initial_level=ilevel,
                                           final_level=flevel)