예제 #1
0
def simFunc(x, *args, **kwargs):
    # add a new parameter
    spacing_1, spacing_2, spacing_3, roughness, layer_occ_1, layer_occ_2, scale, q_offset, wse2_t, mos2_t = x
    layer_occ_1 = int(layer_occ_1)
    layer_occ_2 = int(layer_occ_2)
    layer_occ_2 = layer_occ_2 if layer_occ_1 != 0 else 0
    xrr_data, q_z, crystal_params = args[:]
    layer_dict = OrderedDict({
        "layer_1": {
            "wse2": 1
        },
        "layer_2": {
            "vacuum": spacing_2
        },
        "layer_3": {
            "mos2": layer_occ_1
        },
        "layer_4": {
            "vacuum": spacing_3
        },
        "layer_5": {
            "mos2": layer_occ_2
        }
    })
    # build film
    #pass new params
    film = build_crystal(layer_seq=layer_dict,
                         substrate=crystal_params[0],
                         mos2_layer=crystal_params[1],
                         wse2_layer=crystal_params[2],
                         vacuum=crystal_params[3],
                         stack_name="1_1_1",
                         substrate_spacing=spacing_1,
                         roughness=roughness,
                         mos2_thickness=mos2_t,
                         wse2_thickness=wse2_t)
    # simulate
    en = 10000
    resolution = np.rad2deg(2e-3)
    m = xu.simpack.SpecularReflectivityModel(film,
                                             sample_width=10,
                                             beam_width=0.3,
                                             energy=en,
                                             I0=scale)
    #                                              resolution_width=resolution, I0=1e4)
    q_z_shifted = np.copy(q_z) + q_offset
    #     print("q_z_shift:", q_z_shifted.shape)
    alpha = np.rad2deg(np.arcsin(xu.en2lam(en) * q_z_shifted /
                                 (4 * np.pi))).squeeze()
    #     print("alpha:", alpha.shape)
    xrr_sim = m.simulate(alpha)
    del film, layer_dict
    if 'fit_return' in list(kwargs.keys()):
        return xrr_sim, m.densityprofile(300, plot=False)
    return xrr_sim
예제 #2
0
    def test_area_calib_hkl(self):
        scannrs = (2, 4, 43, 44, 46, 47)
        sang, ang1, ang2 = [
            numpy.empty(0),
        ] * 3
        imghkl = numpy.empty((0, 3))
        r = self.roi
        detdata = numpy.empty((0, r[1] - r[0], r[3] - r[2]))

        for scannr, scanhkl, sl in zip(scannrs, self.hkls, self.slices):
            (om, tth,
             tt), angles = xu.io.gettty08_scan(datfile, scannr, 'om', 'tth',
                                               'tt')
            intensity = numpy.zeros(
                (len(angles[sl]), r[1] - r[0], r[3] - r[2]))
            # read images
            for i, nr in enumerate(angles[sl]['Number']):
                fname = ccdfile % (scannr, scannr, nr)
                intensity[i] = getimage(fname, self.hotpixelmap, roi=self.roi)

            if scanhkl == (0, 0, 0):
                sang = numpy.concatenate((sang, (0, ) * len(angles[sl])))
            else:
                sang = numpy.concatenate((sang, om[sl]))
            ang1 = numpy.concatenate((ang1, tth[sl]))
            ang2 = numpy.concatenate((ang2, tt[sl]))
            detdata = numpy.concatenate((detdata, intensity))
            imghkl = numpy.concatenate((imghkl, (scanhkl, ) * len(angles[sl])))

        # start calibration
        GaAs = xu.materials.GaAs
        qconv = xu.experiment.QConversion(['z+', 'y-', 'x+', 'z-'],
                                          ['z+', 'y-'], [1, 0, 0])
        hxrd = xu.HXRD(GaAs.Q(1, 1, 0),
                       GaAs.Q(0, 0, 1),
                       en=self.en,
                       qconv=qconv)

        param, eps = xu.analysis.sample_align.area_detector_calib_hkl(
            sang,
            ang1,
            ang2,
            detdata,
            imghkl,
            hxrd,
            GaAs, ['z+', 'y-'],
            'x+',
            start=(0, 0, 0, 0, 0, 0, xu.en2lam(self.en)),
            fix=(False, False, False, False, False, False, False),
            debug=False,
            plot=False)

        self.assertTrue(True)
예제 #3
0
    def test_area_calib_hkl(self):
        scannrs = (2, 4, 43, 44, 46, 47)
        sang, ang1, ang2 = [numpy.empty(0), ]*3
        imghkl = numpy.empty((0, 3))
        r = self.roi
        detdata = numpy.empty((0, r[1] - r[0], r[3] - r[2]))

        for scannr, scanhkl, sl in zip(scannrs, self.hkls, self.slices):
            (om, tth, tt), angles = xu.io.gettty08_scan(datfile, scannr,
                                                        'om', 'tth', 'tt')
            intensity = numpy.zeros((len(angles[sl]),
                                     r[1] - r[0], r[3] - r[2]))
            # read images
            for i, nr in enumerate(angles[sl]['Number']):
                fname = ccdfile % (scannr, scannr, nr)
                intensity[i] = getimage(fname, self.hotpixelmap, roi=self.roi)

            if scanhkl == (0, 0, 0):
                sang = numpy.concatenate((sang, (0,)*len(angles[sl])))
            else:
                sang = numpy.concatenate((sang, om[sl]))
            ang1 = numpy.concatenate((ang1, tth[sl]))
            ang2 = numpy.concatenate((ang2, tt[sl]))
            detdata = numpy.concatenate((detdata, intensity))
            imghkl = numpy.concatenate((imghkl, (scanhkl,)*len(angles[sl])))

        # start calibration
        GaAs = xu.materials.GaAs
        qconv = xu.experiment.QConversion(['z+', 'y-', 'x+', 'z-'],
                                          ['z+', 'y-'], [1, 0, 0])
        hxrd = xu.HXRD(GaAs.Q(1, 1, 0), GaAs.Q(0, 0, 1),
                       en=self.en, qconv=qconv)

        param, eps = xu.analysis.sample_align.area_detector_calib_hkl(
            sang, ang1, ang2, detdata, imghkl, hxrd, GaAs,
            ['z+', 'y-'], 'x+',
            start=(0, 0, 0, 0, 0, 0, xu.en2lam(self.en)),
            fix=(False, False, False, False, False, False, False),
            debug=False, plot=False)

        self.assertTrue(True)
예제 #4
0
    plt.show()

    # get the sample to detector distance
    # for that determine how much the the com has moved when the detector
    # has rotated by 1 degree. We may find this value with delta or nu. Here, we do
    # both and calculate the average. The leading coefficient of the function
    # x_com = f(delta) gives how much the x_com has moved when delta has changed by
    # one degree.

    x_com_shift = P.polyfit(delta, x_com, 1)[1]
    y_com_shift = P.polyfit(nu, y_com, 1)[1]

    pix0_x = P.polyfit(delta, x_com,
                       1)[0]  # pixel 0, reference of the direct beam
    pix0_y = P.polyfit(nu, y_com, 1)[0]

    sdd = (1 / 2) * (1 / np.tan(np.pi / 180)) * (x_com_shift +
                                                 y_com_shift) * 55e-6

    param, eps = xu.analysis.sample_align.area_detector_calib(
        angle1,
        angle2,
        ccdimages, ['z-', 'y-'],
        'x+',
        start=(55e-6, 55e-6, ssd, 45, 0, -0.7, 0),
        fix=(True, True, False, False, False, False, True),
        wl=xu.en2lam(en))

    # qx, qy, qz = hxrd.Ang2Q.area(eta, phi, nu, delta,
    # 							 delta=(0, 0, outerangle_offset, 0))
예제 #5
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2016 Dominik Kriegner <*****@*****.**>

from matplotlib.pylab import *
import xrayutilities as xu
import time

mpl.rcParams['font.size'] = 16.0

en = 'CuKa1'  # eV
lam = xu.en2lam(en)
resol = 2 * pi / 4998  # resolution in q; to suppress buffer oscillations
h, k, l = (0, 0, 4)
qz = linspace(4.0, 5.0, 3e3)

sub = xu.simpack.Layer(xu.materials.Si, inf)
#                                                   xfrom xto nsteps thickness
buf1 = xu.simpack.GradedLayerStack(xu.materials.SiGe,
                                   0.2,
                                   0.8,
                                   100,
                                   10000,
                                   relaxation=1.0)
buf2 = xu.simpack.Layer(xu.materials.SiGe(0.8), 4997.02, relaxation=1.0)
lay1 = xu.simpack.Layer(xu.materials.SiGe(0.6), 49.73, relaxation=0.0)
lay2 = xu.simpack.Layer(xu.materials.SiGe(1.0), 45.57, relaxation=0.0)
InPWZ = xu.materials.InPWZ

# approximate version of other hexagonal polytypes
ainp = InP.a
InP4H = xu.materials.Crystal(
    "InP(4H)",
    xu.materials.SGLattice(186,
                           ainp / sqrt(2),
                           2 * sqrt(4 / 3.) * ainp,
                           atoms=[In, In, P, P],
                           pos=[('2a', 0), ('2b', 1 / 4.), ('2a', 3 / 16.),
                                ('2b', 7 / 16.)]))

for energy in [8041]:  # eV

    lam = xu.en2lam(energy)  # e in eV -> lam in angstrom
    print('         %d eV = %8.4f A' % (energy, lam))
    print('------------------------------------------------------------------'
          '-----------------')
    print('material |         peak    |   omega  |  2theta  |    phi   |   '
          'tt-om  |     |F|   ')
    print('------------------------------------------------------------------'
          '-----------------')

    exp111 = xu.HXRD(InP.Q(1, 1, -2), InP.Q(1, 1, 1), en=energy)
    exphex = xu.HXRD(InPWZ.Q(1, -1, 0), InPWZ.Q(0, 0, 1), en=energy)

    # InP ZB reflections
    reflections = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [3, 3, 1], [2, 2, 4],
                   [1, 1, 5]]
    mat = InP
imagenrs = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
            20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]

images = []
ang1 = []
ang2 = []

# read images and angular positions from the data file
# this might differ for data taken at different beamlines since
# they way how motor positions are stored is not always consistent
for imgnr in imagenrs:
    filename = filetmp % imgnr
    edf = xu.io.EDFFile(filename)
    images.append(edf.data)
    ang1.append(float(edf.header['ESRF_ID01_PSIC_NANO_NU']))
    ang2.append(float(edf.header['ESRF_ID01_PSIC_NANO_DEL']))


# call the fit for the detector parameters
# detector arm rotations and primary beam direction need to be given.
# in total 9 parameters are fitted, however the severl of them can
# be fixed. These are the detector tilt azimuth, the detector tilt angle, the
# detector rotation around the primary beam and the outer angle offset
# The detector pixel size or the detector distance should be kept unfixed to
# be optimized by the fit.
param, eps = xu.analysis.sample_align.area_detector_calib(
    ang1, ang2, images, ['z+', 'y-'], 'x+',
    start=(None, None, 1.0, 45, 0, -0.7, 0),
    fix=(False, False, True, False, False, False, False),
    wl=xu.en2lam(en))
en = 10300.0  # eV
datadir = os.path.join("data", "wire_")  # data path for CCD files
# template for the CCD file names
filetmp = os.path.join(datadir, "wire_12_%05d.edf.gz")

# manually selected images
# select images which have the primary beam fully on the CCD
imagenrs = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
            20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]

images = []
ang1 = []
ang2 = []

# read images and angular positions from the data file
for imgnr in imagenrs:
    filename = filetmp % imgnr
    edf = xu.io.EDFFile(filename)
    images.append(edf.data)
    ang1.append(float(edf.header['ESRF_ID01_PSIC_NANO_NU']))
    ang2.append(float(edf.header['ESRF_ID01_PSIC_NANO_DEL']))
    # or for newer EDF files (recorded in year >~2013)
    # ang1.append(edf.motors['nu'])
    # ang2.append(edf.motors['del'])

# call the fit for the detector parameters
# detector arm rotations and primary beam direction need to be given
param, eps = xu.analysis.sample_align.area_detector_calib(
    ang1, ang2, images, ['z+', 'y-'], 'x+', start=(45, 0, -0.7, 0),
    fix=(False, False, False, False), wl=xu.en2lam(en))
# define materials
InP = xu.materials.InP
InPWZ = xu.materials.InPWZ

# approximate version of other hexagonal polytypes
ainp = InP.a
InP4H = xu.materials.Crystal(
    "InP(4H)",
    xu.materials.SGLattice(186, ainp / sqrt(2), 2 * sqrt(4/3.) * ainp,
                           atoms=[In, In, P, P],
                           pos=[('2a', 0), ('2b', 1/4.),
                                ('2a', 3/16.), ('2b', 7/16.)]))

for energy in [8041]:  # eV

    lam = xu.en2lam(energy)  # e in eV -> lam in Angstroem
    print('         %d eV = %8.4f A' % (energy, lam))
    print('------------------------------------------------------------------'
          '-----------------')
    print('material |         peak    |   omega  |  2theta  |    phi   |   '
          'tt-om  |     |F|   ')
    print('------------------------------------------------------------------'
          '-----------------')

    exp111 = xu.HXRD(InP.Q(1, 1, -2), InP.Q(1, 1, 1), en=energy)
    exphex = xu.HXRD(InPWZ.Q(1, -1, 0), InPWZ.Q(0, 0, 1), en=energy)

    # InP ZB reflections
    reflections = [[1, 1, 1], [2, 2, 2], [3, 3, 3],
                   [3, 3, 1], [2, 2, 4], [1, 1, 5]]
    mat = InP
InPWZ = xu.materials.InPWZ

# approximate version of other hexagonal polytypes
ainp = InP.a
InP4H = xu.materials.Crystal(
    "InP(4H)",
    xu.materials.SGLattice(186,
                           ainp / sqrt(2),
                           2 * sqrt(4 / 3.) * ainp,
                           atoms=[In, In, P, P],
                           pos=[('2a', 0), ('2b', 1 / 4.), ('2a', 3 / 16.),
                                ('2b', 7 / 16.)]))

for energy in [8041]:  # eV

    lam = xu.en2lam(energy)  # e in eV -> lam in Angstroem
    print('         %d eV = %8.4f A' % (energy, lam))
    print('------------------------------------------------------------------'
          '-----------------')
    print('material |         peak    |   omega  |  2theta  |    phi   |   '
          'tt-om  |     |F|   ')
    print('------------------------------------------------------------------'
          '-----------------')

    exp111 = xu.HXRD(InP.Q(1, 1, -2), InP.Q(1, 1, 1), en=energy)
    exphex = xu.HXRD(InPWZ.Q(1, -1, 0), InPWZ.Q(0, 0, 1), en=energy)

    # InP ZB reflections
    reflections = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [3, 3, 1], [2, 2, 4],
                   [1, 1, 5]]
    mat = InP
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2016 Dominik Kriegner <*****@*****.**>

import time

import xrayutilities as xu
from matplotlib.pylab import *

mpl.rcParams['font.size'] = 16.0


en = 'CuKa1'  # eV
lam = xu.en2lam(en)
resol = 2*pi/4998  # resolution in q; to suppress buffer oscillations
H, K, L = (0, 0, 4)
qz = linspace(4.0, 5.0, 3000)

sub = xu.simpack.Layer(xu.materials.Si, inf)
#                                                   xfrom xto nsteps thickness
buf1 = xu.simpack.GradedLayerStack(xu.materials.SiGe, 0.2, 0.8, 100, 10000,
                                   relaxation=1.0)
buf2 = xu.simpack.Layer(xu.materials.SiGe(0.8), 4997.02, relaxation=1.0)
lay1 = xu.simpack.Layer(xu.materials.SiGe(0.6), 49.73, relaxation=0.0)
lay2 = xu.simpack.Layer(xu.materials.SiGe(1.0), 45.57, relaxation=0.0)
# create superlattice stack
# lattice param. are adjusted to the relaxation parameter of the layers
# Note that to create a superlattice you can use summation and multiplication
pls = xu.simpack.PseudomorphicStack001('SL 5/5', sub+buf1+buf2+5*(lay1+lay2))