Esempio n. 1
0
def darwindata(xtal, hkl, energy, polar, fname):
    hkl = hkl.replace('_', ' ')
    hkl_tuple = tuple([int(a) for a in hkl.split()])
    out = xraydb.darwin_width(float(energy),
                              xtal,
                              hkl_tuple,
                              polarization=polar)

    header = (
        ' X-ray Monochromator Darwin Width from xrayweb  %s ' % time.ctime(),
        ' Monochromator.xtal        : %s ' % xtal,
        ' Monochromator.hkl         : %s ' % hkl,
        ' Monochromator.polarization: \'%s\' ' % polar,
        ' Monochromator.theta       : %.5f (deg) ' % (out.theta * 180 / np.pi),
        ' Monochromator.theta_width : %.5f (microrad) ' %
        (out.theta_width * 1e6), ' Monochromator.energy_width: %.5f (eV) ' %
        out.energy_width, ' Monochromator.theta_fwhm  : %.5f (microrad) ' %
        (out.theta_fwhm * 1e6), ' Monochromator.energy_fwhm : %.5f (eV) ' %
        out.energy_fwhm, ' Xray.Energy               : %s (eV)' % energy,
        ' Column.1: dtheta (microrad)', ' Column.2: denergy (eV)',
        ' Column.3: zeta (delta_lambda / lambda)', ' Column.4: intensity')
    arr_names = ('dtheta       ', 'denergy      ', 'zeta         ',
                 'intensity    ')

    txt = make_asciifile(
        header, arr_names,
        (out.dtheta * 1e6, out.denergy, out.zeta, out.intensity))

    return Response(txt, mimetype='text/plain')
Esempio n. 2
0
def analyzers(elem=None):
    elem = line = theta1 = theta2 = None
    energy = 10000
    analyzer_results = None

    if len(request.form) != 0:
        elem = request.form.get('elem', '')
        line = request.form.get('line', 'Ka1')
        energy = float(request.form.get('energy', '10000'))
        theta_min = float(request.form.get('theta1', '60'))
        theta_max = float(request.form.get('theta2', '90'))

    if request.method == 'POST':
        analyzer_results = []
        for xtal in ('Si', 'Ge'):
            a = lattice_constants[xtal]
            for hkl in hkl_list:
                hkl_tuple = tuple([int(ref) for ref in hkl.split()])
                hkl_link = '_'.join([ref for ref in hkl.split()])
                thbragg = th_diffracted(float(energy), hkl_tuple, a)
                if thbragg < theta_max and thbragg > theta_min:
                    dw = xraydb.darwin_width(energy,
                                             crystal=xtal,
                                             hkl=hkl_tuple,
                                             polarization='u')
                    analyzer_results.append(
                        (xtal, hkl, hkl_link, "%8.4f" % thbragg,
                         "%8.4f" % (dw.theta_width * 1e6),
                         "%8.4f" % dw.energy_width))

    else:
        request.form = {
            'theta1': '60',
            'theta2': '90',
            'energy': '10000',
            'elem': '',
            'line': 'Ka1'
        }

    return render_template('analyzers.html',
                           analyzer_results=analyzer_results,
                           emission_energies=emission_energies_json,
                           analyzer_lines=analyzer_lines,
                           materials_dict=materials_dict)
Esempio n. 3
0
import numpy as np
from xraydb import darwin_width
import matplotlib.pyplot as plt

dw_si111 = darwin_width(10000, 'Si', (1, 1, 1))
dw_si333 = darwin_width(30000, 'Si', (3, 3, 3))

fmt_string = "Darwin Width for {:s} at {:.0f} keV: {:5.2f} microrad, {:5.2f} eV"
print(
    fmt_string.format('Si(111)', 10, dw_si111.theta_width * 1e6,
                      dw_si111.energy_width))

print(
    fmt_string.format('Si(333)', 30, dw_si333.theta_width * 1e6,
                      dw_si333.energy_width))

dtheta = dw_si111.dtheta * 1e6
denergy = dw_si111.denergy[::-1]

#  slightly advanced matplotlib hackery:
fig, ax = plt.subplots(constrained_layout=True)

ax.plot(dtheta, dw_si111.intensity, label='$I$, Si(111)', linewidth=2)
ax.plot(dtheta, dw_si111.intensity**2, label='$I^2$, Si(111)', linewidth=2)
ax.plot(dw_si333.dtheta * 1e6,
        dw_si333.intensity**2,
        label='$I^2$ Si(333) 30 keV',
        linewidth=2)

ax.set_title('X-ray diffraction intensity at 10keV')
ax.set_xlabel('Angle - $\\theta_B$ ($ \mu \mathrm{rad}$)')
Esempio n. 4
0
 def dw_fwhm(energy, crystal, hkl):
     """as-calculated darwin width in energy (eV)"""
     return darwin_width(energy, crystal=crystal, hkl=hkl).energy_fwhm
Esempio n. 5
0
 def dw_dide(energy, crystal, hkl):
     """estimate darwin width in energy from min/max derivative"""
     dat = darwin_width(energy, crystal=crystal, hkl=hkl)
     dide = np.gradient(dat.intensity) / np.gradient(dat.denergy)
     return (dat.denergy[np.where(dide == dide.min())] -
             dat.denergy[np.where(dide == dide.max())])[0]
Esempio n. 6
0
def darwinwidth(xtal=None, hkl=None, energy=None, polar='s'):
    xtal_list = ('Si', 'Ge', 'C')

    dtheta_plot = denergy_plot = None
    theta_deg = theta_fwhm = energy_fwhm = theta_width = energy_width = ''

    if request.method == 'POST':
        xtal = request.form.get('xtal', 'Si')
        hkl = request.form.get('hkl', '1 1 1')
        polar = request.form.get('polarization', 's')
        energy = request.form.get('energy', '10000')
        do_calc = True
    elif xtal in xtal_list and hkl is not None:
        hkl = hkl.replace('_', ' ')
        request.form = {
            'xtal': xtal,
            'hkl': hkl,
            'polarization': polar,
            'energy': energy
        }
        do_calc = True
    else:
        do_calc = False
        request.form = {
            'xtal': 'Si',
            'hkl': '1 1 1',
            'polarization': 's',
            'energy': '10000'
        }

    if do_calc:
        hkl_tuple = tuple([int(a) for a in hkl.split()])
        energy = float(energy)
        out = xraydb.darwin_width(energy,
                                  xtal,
                                  hkl_tuple,
                                  polarization=polar,
                                  m=1)
        if np.isnan(out.theta):
            theta_deg = "not allowed"
            theta_width = "-"
            energy_width = "-"
            theta_fwhm = "-"
            energy_fwhm = "-"

        else:
            title = "%s(%s), '%s' polar, E=%.1f eV" % (xtal, hkl, polar,
                                                       energy)
            dtheta_plot = make_plot(out.dtheta * 1.e6,
                                    out.intensity,
                                    title,
                                    xtal,
                                    y1label='1 bounce',
                                    yformat='.2f',
                                    y2=out.intensity**2,
                                    y2label='2 bounces',
                                    ytitle='reflectivity',
                                    xtitle='Angle(microrad)')

            denergy_plot = make_plot(out.denergy,
                                     out.intensity,
                                     title,
                                     xtal,
                                     y1label='1 bounce',
                                     yformat='.2f',
                                     y2=out.intensity**2,
                                     y2label='2 bounces',
                                     ytitle='reflectivity',
                                     xtitle='Energy (eV)')

            theta_deg = "%.5f" % (out.theta * 180 / np.pi)
            theta_width = "%.5f" % (out.theta_width * 1.e6)
            energy_width = "%.5f" % out.energy_width
            theta_fwhm = "%.5f" % (out.theta_fwhm * 1.e6)
            energy_fwhm = "%.5f" % out.energy_fwhm

    return render_template('darwinwidth.html',
                           dtheta_plot=dtheta_plot,
                           denergy_plot=denergy_plot,
                           theta_deg=theta_deg,
                           theta_fwhm=theta_fwhm,
                           energy_fwhm=energy_fwhm,
                           theta_width=theta_width,
                           energy_width=energy_width,
                           xtal_list=xtal_list,
                           hkl_list=hkl_list,
                           materials_dict=materials_dict)