コード例 #1
0
ファイル: test_xray.py プロジェクト: schlepuetz/XrayDB
def test_mirror_reflectivity():
    rh1 = np.array([
        0.97199571, 0.97748356, 0.95360848, 0.92357963, 0.93588329, 0.94249572,
        0.94771043, 0.95137756, 0.95416567, 0.95693941, 0.95906606, 0.9606963,
        0.96193867, 0.96298571, 0.9637671, 0.96434822, 0.96458685, 0.96443861,
        0.963873, 0.96273628, 0.9607325, 0.95705164, 0.94578432, 0.69383757,
        0.65937538, 0.57222587, 0.40829232, 0.26919575, 0.18904094, 0.14024917
    ])
    r1 = mirror_reflectivity('Rh', 0.0025, np.arange(1000, 31000, 1000))
    assert_allclose(rh1, r1, rtol=0.005)

    assert_allclose(mirror_reflectivity('Pt', 0.001, 80000), 0.74, rtol=0.005)
コード例 #2
0
def reflectdata(formula, rho, angle, rough, polar, e1, e2, de, fname):
    """mirror reflectivity data as file"""
    en_array = energy_array(e1, e2, de)
    angle = float(angle)
    rho = float(rho)
    rough = float(rough)
    reflectivity = xraydb.mirror_reflectivity(formula,
                                              0.001 * angle,
                                              en_array,
                                              rho,
                                              roughness=rough,
                                              polarization=polar)

    _del, _bet, _ = xraydb.xray_delta_beta(formula, rho, en_array)
    ang_crit = 1000 * (np.pi / 2 - np.arcsin(1 - _del - 1j * _bet)).real

    header = (' X-ray reflectivity data from xrayweb  %s ' % time.ctime(),
              ' Material.formula   : %s ' % formula,
              ' Material.density   : %.4f gr/cm^3 ' % rho,
              ' Material.angle     : %.4f mrad ' % angle,
              ' Material.roughness : %.4f Ang ' % rough,
              ' Material.polarization: %s ' % polar, ' Column.1: energy (eV)',
              ' Column.2: reflectivity', ' Column.3: critical_angle (mrad)')

    arr_names = ('energy       ', 'reflectivity ', 'crit_angle    ')
    txt = make_asciifile(header, arr_names, (en_array, reflectivity, ang_crit))
    return Response(txt, mimetype='text/plain')
コード例 #3
0
ファイル: webapp.py プロジェクト: anicolellis/xrayweb
def reflectdata(formula, rho, angle, rough, polar, e1, e2, estep):
    """mirror reflectivity data as file"""
    en_array = np.arange(float(e1), float(e2), float(estep))
    angle = float(angle)
    rho = float(rho)
    rough = float(rough)
    reflectivity = xraydb.mirror_reflectivity(formula,
                                              angle,
                                              en_array,
                                              rho,
                                              roughness=rough,
                                              polarization=polar)

    header = (' X-ray reflectivity data from xrayweb  %s ' % time.ctime(),
              ' Material.formula   : %s ' % formula,
              ' Material.density   : %.3f gr/cm^3 ' % rho,
              ' Material.angle     : %.6f rad ' % angle,
              ' Material.roughness : %.3f Ang ' % rough,
              ' Material.polarization: %s ' % polar, ' Column.1: energy (eV)',
              ' Column.2: reflectivity')

    arr_names = ('energy       ', 'reflectivity ')
    txt = make_asciifile(header, arr_names, (en_array, reflectivity))

    fname = 'xrayweb_reflect_%s_%s.txt' % (formula,
                                           time.strftime('%Y%h%d_%H%M%S'))
    return Response(
        txt,
        mimetype='text/plain',
        headers={"Content-Disposition": "attachment;filename=%s" % fname})
コード例 #4
0
ファイル: webapp.py プロジェクト: newville/xrayweb
def reflectdata(formula, rho, angle, rough, polar, e1, e2, estep):
    """mirror reflectivity data as file"""
    en_array = np.arange(float(e1), float(e2)+float(estep), float(estep))
    angle = float(angle)
    rho   = float(rho)
    rough = float(rough)
    reflectivity = xraydb.mirror_reflectivity(formula, 0.001*angle, en_array, rho,
                                              roughness=rough, polarization=polar)

    _del, _bet, _ = xraydb.xray_delta_beta(formula, rho, en_array)
    ang_crit = 1000*(np.pi/2 - np.arcsin(1 - _del - 1j*_bet)).real
    
    header = (' X-ray reflectivity data from xrayweb  %s ' % time.ctime(),
              ' Material.formula   : %s ' % formula,
              ' Material.density   : %.4f gr/cm^3 ' % rho,
              ' Material.angle     : %.4f mrad ' % angle,
              ' Material.roughness : %.4f Ang ' % rough,
              ' Material.polarization: %s ' % polar,
              ' Column.1: energy (eV)',
              ' Column.2: reflectivity',
              ' Column.3: crit_angle (mrad)')

    arr_names = ('energy       ', 'reflectivity ', 'crit_angle    ')

    txt = make_asciifile(header, arr_names, (en_array, reflectivity, ang_crit))

    fname = 'xrayweb_reflect_%s_%s.txt' % (formula,
                                          time.strftime('%Y%h%d_%H%M%S'))
    return Response(txt, mimetype='text/plain',
                    headers={"Content-Disposition":
                             "attachment;filename=%s" % fname})
コード例 #5
0
import numpy as np
from xraydb import mirror_reflectivity
import matplotlib.pyplot as plt

energy = np.linspace(1000, 51000, 501)

r_si = mirror_reflectivity('Si', 0.002, energy)
r_ni = mirror_reflectivity('Ni', 0.002, energy)
r_rh = mirror_reflectivity('Rh', 0.002, energy)
r_pt = mirror_reflectivity('Pt', 0.002, energy)

plt.plot(energy, r_si, label='Si')
plt.plot(energy, r_ni, label='Ni')
plt.plot(energy, r_rh, label='Rh')
plt.plot(energy, r_pt, label='Pt')

plt.title('X-ray reflectivity at $\\theta=2 \mathrm{mrad}$')
plt.xlabel('Energy (eV)')
plt.ylabel('Reflectivity')
plt.legend()
plt.show()
コード例 #6
0
def reflectivity(material=None):
    message = []
    ref_plot = angc_plot = {}
    has_data = False
    de = '50'
    if request.method == 'POST':
        formula1 = request.form.get('formula1', 'None')
        density1 = request.form.get('density1', '')
        angle1 = request.form.get('angle1', '0')
        material1 = request.form.get('mats1', 'silicon')

        e1 = request.form.get('e1', '1000')
        e2 = request.form.get('e2', '50000')
        de = request.form.get('de', '50')
        mode = request.form.get('mode', 'Linear')
        roughness = request.form.get('roughness')
        polarization = request.form.get('polarization')

        if not xraydb.validate_formula(formula1):
            message.append("cannot interpret chemical formula")

        try:
            density = max(0, float(density1))
        except:
            message.append('Density must be a positive number.')

        if len(message) == 0:
            has_data = True
            en_array = energy_array(e1, e2, de)
            use_log = mode.lower() == 'log'

            ref_array = xraydb.mirror_reflectivity(formula1,
                                                   0.001 * float(angle1),
                                                   en_array,
                                                   density,
                                                   roughness=float(roughness),
                                                   polarization=polarization)
            title = "%s, %s mrad" % (formula1, angle1)
            ref_plot = make_plot(en_array,
                                 ref_array,
                                 title,
                                 formula1,
                                 yformat='.3f',
                                 ytitle='Reflectivity',
                                 ylog_scale=use_log)

            title = "%s Reflectivity, %s mrad" % (formula1, angle1)
            ref_plot = make_plot(en_array,
                                 ref_array,
                                 title,
                                 formula1,
                                 yformat='.3f',
                                 ytitle='Reflectivity',
                                 ylog_scale=use_log)

            _del, _bet, _ = xraydb.xray_delta_beta(formula1, density, en_array)
            ang_crit = 1000 * np.arccos(1 - _del - 1j * _bet).real

            title = "%s, Critical Angle" % (formula1)
            angc_plot = make_plot(en_array,
                                  ang_crit,
                                  title,
                                  formula1,
                                  ytitle='Critical Angle (mrad)',
                                  ylog_scale=use_log)

    else:
        request.form = {
            'mats1': 'silicon',
            'formula1': materials_['silicon'].formula,
            'density1': materials_['silicon'].density,
            'angle1': 2.5,
            'mats2': 'None',
            'formula2': '',
            'density2': '',
            'angle2': 2.5,
            'e1': 1000,
            'e2': 50000,
            'de': de,
            'polarization': 's',
            'roughness': '0',
            'mode': 'Linear'
        }

    return render_template('reflectivity.html',
                           message=message,
                           errors=len(message),
                           ref_plot=ref_plot,
                           angc_plot=angc_plot,
                           has_data=has_data,
                           matlist=mirror_mat,
                           de=int(de),
                           materials_dict=materials_dict)
コード例 #7
0
ファイル: webapp.py プロジェクト: anicolellis/xrayweb
def reflectivity(material=None):
    message = ['']
    ref_plot = output = {}
    energies = reflectivities = []
    num = errors = 0
    df = ef = ef2 = sf = af = rf = 0
    isLog = True

    if request.method == 'POST':
        #obtain form input and verify
        formula = request.form.get('formula')
        density = request.form.get('density')
        angle = request.form.get('angle')
        roughness = request.form.get('roughness')
        polarization = request.form.get('polarization')
        energy1 = request.form.get('energy1')
        energy2 = request.form.get('energy2')
        step = request.form.get('step')
        mode = request.form.get('mode')

        output = validate_input(formula,
                                density,
                                step,
                                energy1,
                                energy2,
                                mode,
                                material,
                                angle,
                                roughness,
                                page='reflectivity')
        message = output['message']
    else:
        request.form = {
            'formula': materials_dict['silicon'].formula,
            'density': materials_dict['silicon'].density,
            'energy1': '1000',
            'energy2': '50000',
            'step': '100',
            'angle': '0.001',
            'roughness': '0'
        }

    #if verification passes, calculate output and pass to render_template
    if message[0] == 'Input is valid':
        df = output['df']
        ef = output['ef']
        ef2 = output['ef2']
        sf = output['sf']
        isLog = output['isLog']
        af = output['af']
        rf = output['rf']

        while ef2 < (
                ef + (sf * 2)
        ):  #this ensures that there are always at least 3 energy values for a meaningful plot
            ef2 += sf
        ef2 += sf  #this includes energy2 in the plot, normally np.arrage excludes the upper bound
        en_array = np.arange(ef, ef2, sf)
        num = en_array.size
        ref_array = xraydb.mirror_reflectivity(formula, af, en_array, df, rf,
                                               polarization)

        ref_plot = make_plot(en_array,
                             ref_array,
                             material,
                             formula,
                             ytitle='Reflectivity',
                             ylog_scale=isLog)

        energies = [nformat(x) for x in en_array]
        reflectivities = [nformat(x) for x in ref_array]

        message = []
    else:
        errors = len(message)

    return render_template('reflectivity.html',
                           message=message,
                           errors=errors,
                           ref_plot=ref_plot,
                           energies=energies,
                           reflectivities=reflectivities,
                           num=num,
                           matlist=mirror_list,
                           materials_dict=materials_dict_j)