Exemplo n.º 1
0
class TestIO_FIO(unittest.TestCase):
    dshape = (601, )
    dmax = 2272108.0
    dmin = 66133.0
    dmaxcorr = 216583893672.0
    dmincorr = 0.0
    motmax = 8.000001
    motmin = 0.0
    tpos = 300
    dtpos = 1278952.0
    motorname = 'Motor_TT'
    countername = 'MythenIntegral'
    h5file = '_test_fio.h5'
    P08_normalizer = xu.IntensityNormalizer(
        "MCA",
        time='CountingTime',
        mon='MonitorEnergyWindow',
        absfun=lambda d: d['AttenuationFactor'])

    @classmethod
    def setUpClass(cls):
        scanname = os.path.splitext(testfile)[0]
        mcatmp = os.path.join(datadir, scanname, scanname + "_mythen_%i.raw")
        cls.fiofile = xu.io.SPECTRAFile(fullfilename, mcatmp=mcatmp)
        cls.sdata = cls.fiofile.data
        cls.motor = cls.sdata[cls.motorname]
        cls.inte = cls.sdata[cls.countername]
        cls.fiofile.Save2HDF5(cls.h5file, scanname)
        [cls.h5tt, dummy, cls.h5int
         ], cls.h5data = xu.io.geth5_spectra_map(cls.h5file, [19],
                                                 cls.motorname, 'ZS',
                                                 cls.countername)

    @classmethod
    def tearDownClass(cls):
        try:
            os.remove(cls.h5file)
        except OSError:
            pass

    def test_datashape(self):
        self.assertEqual(self.dshape, self.sdata[self.motorname].shape)
        self.assertEqual(self.dshape, self.sdata[self.countername].shape)

    def test_datavalues(self):
        self.assertAlmostEqual(self.motmax, self.motor.max(), places=6)
        self.assertAlmostEqual(self.motmin, self.motor.min(), places=6)
        self.assertAlmostEqual(self.dmax, self.inte.max(), places=6)
        self.assertAlmostEqual(self.dmin, self.inte.min(), places=6)
        self.assertAlmostEqual(self.dtpos, self.inte[self.tpos], places=6)

    def test_hdf5file(self):
        self.assertTrue(numpy.all(self.inte == self.h5int))
        self.assertTrue(numpy.all(self.motor == self.h5tt))

    def test_normalizer(self):
        mcac = self.P08_normalizer(self.h5data)
        self.assertAlmostEqual(self.dmaxcorr, mcac.max(), places=6)
        self.assertAlmostEqual(self.dmincorr, mcac.min(), places=6)
Exemplo n.º 2
0
 def setUpClass(cls):
     imgreader = xu.io.Pilatus100K()
     cls.img = imgreader.readImage(testfile, path=datadir)
     cls.ccddata = numpy.asarray((cls.img, 2 * cls.img))
     cls.fakedata = numpy.array([(1.0, 10.0), (2.0, 21.0)],
                                dtype=[('time', float), ('moni', float)])
     cls.normalizer = xu.IntensityNormalizer(mon='moni',
                                             time='time',
                                             av_mon=1.0)
     cls.normdata = cls.normalizer(cls.fakedata, ccd=cls.ccddata)
# global setting for the experiment
sample = "test"  # sample name used also as file name for the data file
en = 8042.5  # x-ray energy in eV
# center channel of the linear detector used in the experiment
center_ch = 715.9
# channels per degree of the linear detector (mounted along z direction,
# which corresponds to twotheta)
chpdeg = 345.28
roi = [100, 1340]  # region of interest of the detector

# intensity normalizer function responsible for count time and absorber
# correction
normalizer_detcorr = xu.IntensityNormalizer(
    "MCA",
    mon="Monitor",
    time="Seconds",
    absfun=lambda d: d["detcorr"] / d["psd2"].astype(numpy.float))

# substrate material used for Bragg peak calculation to correct for
# experimental offsets
InP = xu.materials.InP

hxrd = xu.HXRD(InP.Q(1, 1, -2), InP.Q(1, 1, 1), en=en)

# configure linear detector
hxrd.Ang2Q.init_linear('z-', center_ch, 1500., chpdeg=chpdeg, roi=roi)

# read spec file and save to HDF5-file
# since reading is much faster from HDF5 once the data are transformed
h5file = os.path.join("data", sample + ".h5")
import re

import xrayutilities as xu
from matplotlib.pylab import *

# define root of the local data directory (needed because we assume the data
# path of detector frames from the specfile are not correct anymore)
datadir = '/local/data/path'
repl_n = len(datadir.split('/'))

# define intensity normalizer class to normalize for count time and
# monitor changes: to have comparable absolute intensities set the keyword
# argument av_mon to a fixed value, otherwise different scans can not be
# compared!
xid01_normalizer = xu.IntensityNormalizer('CCD',
                                          time='Seconds',
                                          mon='exp1',
                                          av_mon=10000.0)


def deadpixelkill(ccdraw, f=1.0):
    """
    fill empty "spacer" pixels of the maxipix 2x2 detector
    """
    ccd = ccdraw.astype(float32)
    ccd[255:258, :] = ccd[255, :] / 3 * f
    ccd[258:261, :] = ccd[260, :] / 3 * f
    ccd[:, 255:258] = ones(
        (ccd.shape[0], 3)) * (ccd[:, 255])[:, newaxis] / 3 * f
    ccd[:, 258:261] = ones(
        (ccd.shape[0], 3)) * (ccd[:, 260])[:, newaxis] / 3 * f
    return ccd
Exemplo n.º 5
0
import os

# global setting for the experiment
sample = "test"  # sample name used also as file name for the data file
energy = 8042.5  # x-ray energy in eV
center_ch = 715.9  # center channel of the linear detector
chpdeg = 345.28  # channels per degree of the linear detector
roi = [100, 1340]  # region of interest of the detector
nchannel = 1500  # number of channels of the detector

# intensity normalizer function responsible for count time and absorber
# correction
absfun = lambda d: d["detcorr"] / d["psd2"].astype(numpy.float)
normalizer_detcorr = xu.IntensityNormalizer(
    "MCA",
    mon="Monitor",
    time="Seconds",
    absfun=absfun)

# substrate material used for Bragg peak calculation to correct for
# experimental offsets
InP = xu.materials.InP

# initialize experimental class to specify the reference directions of your
# crystal
# 11-2: inplane reference
# 111: surface normal
hxrd = xu.HXRD(InP.Q(1, 1, -2), InP.Q(1, 1, 1), en=energy)

# configure linear detector
# detector direction + parameters need to be given
Exemplo n.º 6
0
    attnum = numpy.array(att, dtype=numpy.int)
    ret = numpy.ones(attnum.shape)
    # filter factors to be determined by reference measurements at the energy
    # you use
    fact = (1, numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan,
            numpy.nan)
    if ret.size > 1:
        ret[:] = numpy.nan
        ret[0 == attnum] = 1.0000
        ret[2 == attnum] = 3.6769
        return ret
    else:
        return fact[int(att)]


xid01_normalizer = xu.IntensityNormalizer(
    'CCD', time='Seconds', mon='Opt2', absfun=lambda d: filtfact(d['Filter']))
# define intensity normalizer class to normalize for count time and
# monitor changes: to have comparable absolute intensities set the keyword
# argument av_mon to a fixed value, otherwise different scans can not be
# compared! therefore add av_mon=1.eX


def hotpixelkill(ccd):
    """
    function to remove hot pixels from CCD frames
    ADD REMOVE VALUES IF NEEDED!
    """
    ccd[44, 159] = 0
    ccd[45, 159] = 0
    ccd[43, 160] = 0
    ccd[46, 160] = 0