Exemplo n.º 1
0
def test_work():
    '''Test all features of the module using a detector composed of four
    overlapping square sensors, with lots of rays.'''

    import random, time

    nrays = 10000

    d1 = matrix.col((1, 0, 0))
    d2 = matrix.col((0, 1, 0))
    lim = (0,50)
    panel0 = sensor(matrix.col((-45, -45, 100)), d1, d2, lim, lim)
    panel1 = sensor(matrix.col((-5, -45, 99)), d1, d2, lim, lim)
    panel2 = sensor(matrix.col((-45, -5, 98)), d1, d2, lim, lim)
    panel3 = sensor(matrix.col((-5, -5, 97)), d1, d2, lim, lim)

    d = detector([panel0, panel1, panel2, panel3])

    rays = [matrix.col((random.random() - 0.5,
                        random.random() - 0.5,
                        random.random() - 0.5)) for j in range(nrays)]

    rpi = { }

    for ver in ('matrix', 'vector'):
        t0 = time.time()
        rp = predictor_factory(ver)(rays, d.sensors())

        rpi[ver] = rp.intersections()

    for j, intersection_matrix in enumerate(rpi['matrix']):
        intersection_vector = rpi['vector'][j]
        assert(intersection_matrix[0] == intersection_vector[0])

    print 'OK'
Exemplo n.º 2
0
def test_all():
    '''Test all features of the module using a detector composed of four
    overlapping square sensors.'''

    d1 = matrix.col((1, 0, 0))
    d2 = matrix.col((0, 1, 0))
    lim = (0,50)
    panel0 = sensor(matrix.col((-45, -45, 100)), d1, d2, lim, lim)
    panel1 = sensor(matrix.col((-5, -45, 99)), d1, d2, lim, lim)
    panel2 = sensor(matrix.col((-45, -5, 98)), d1, d2, lim, lim)
    panel3 = sensor(matrix.col((-5, -5, 97)), d1, d2, lim, lim)

    d = detector([panel0, panel1, panel2, panel3])
    rays = [matrix.col((0, 0, 1))]

    for ver in ('matrix', 'vector'):
        rp = predictor_factory(ver)
        rp = rp(rays, d.sensors())

        # only one ray to consider
        rpi = rp.intersections()

        # the closest intersection should be on panel3
        assert rpi[0][0] == 3

    print 'OK'
Exemplo n.º 3
0
    def __init__(self, origin, dir1, dir2, pixel_size_fast, pixel_size_slow,
                 npx_fast, npx_slow):
        self._px_size_fast = pixel_size_fast
        self._px_size_slow = pixel_size_slow
        self._npx_fast = int(npx_fast)
        self._npx_slow = int(npx_slow)

        lim1 = (0, self._npx_fast * self._px_size_fast)
        lim2 = (0, self._npx_slow * self._px_size_slow)
        # set up a single sensor
        s = sensor(origin, dir1, dir2, lim1, lim2)

        # set up the abstract detector
        detector.__init__(self, [s])
    def __init__(self, origin, dir1, dir2, pixel_size_fast, pixel_size_slow,
                 npx_fast, npx_slow):
        self._px_size_fast = pixel_size_fast
        self._px_size_slow = pixel_size_slow
        self._npx_fast = int(npx_fast)
        self._npx_slow = int(npx_slow)

        lim1 = (0, self._npx_fast * self._px_size_fast)
        lim2 = (0, self._npx_slow * self._px_size_slow)
        # set up a single sensor
        s = sensor(origin, dir1, dir2, lim1, lim2)

        # set up the abstract detector
        detector.__init__(self, [s])
Exemplo n.º 5
0
def scattering_prediction(reflections,
                          UB_mat,
                          rotation_vector,
                          wavelength,
                          resolution,
                          assert_non_integer_index=False):
    '''Test the reflection_prediction class.'''

    ra = rotation_angles(resolution, UB_mat, wavelength, rotation_vector)
    beam_vector = matrix.col([0, 0, 1 / wavelength])

    detector_size = 100
    detector_distance = 100

    s = sensor(
        matrix.col(
            (-0.5 * detector_size, -0.5 * detector_size, detector_distance)),
        matrix.col((1, 0, 0)), matrix.col((0, 1, 0)), (0, detector_size),
        (0, detector_size))
    rp = reflection_prediction(rotation_vector, beam_vector, UB_mat, s)

    for hkl in reflections:
        if ra(hkl):
            omegas = ra.get_intersection_angles()
            if assert_non_integer_index:
                assert ra.H[0] != int(ra.H[0]) or \
                       ra.H[1] != int(ra.H[1]) or \
                       ra.H[2] != int(ra.H[2])

            for omegaidx in [0, 1]:

                rot_mat = rotation_vector.axis_and_angle_as_r3_rotation_matrix(
                    omegas[omegaidx])

                assert (math.fabs(rot_mat.determinant() - 1.0) < 0.0001)

                H1 = (rot_mat * UB_mat) * hkl
                H1 = H1 + beam_vector
                len_H1 = math.sqrt((H1[0] * H1[0]) + (H1[1] * H1[1]) +
                                   (H1[2] * H1[2]))

                if math.fabs(len_H1 - 1.0 / wavelength) > 0.0001:
                    raise RuntimeError, 'length error for %d %d %d' % hkl

                if rp(hkl, omegas[omegaidx]):
                    x, y = rp.get_prediction()
                    assert (0 < x < detector_size)
                    assert (0 < y < detector_size)
Exemplo n.º 6
0
def scattering_prediction(reflections, UB_mat, rotation_vector,
                          wavelength, resolution,
                          assert_non_integer_index = False):
    '''Test the reflection_prediction class.'''

    ra = rotation_angles(resolution, UB_mat, wavelength, rotation_vector)
    beam_vector = matrix.col([0, 0, 1 / wavelength])

    detector_size = 100
    detector_distance = 100

    s =  sensor(matrix.col((- 0.5 * detector_size,
                            - 0.5 * detector_size,
                            detector_distance)),
                matrix.col((1, 0, 0)),
                matrix.col((0, 1, 0)),
                (0, detector_size), (0, detector_size))
    rp = reflection_prediction(rotation_vector, beam_vector, UB_mat, s)

    for hkl in reflections:
        if ra(hkl):
            omegas = ra.get_intersection_angles()
            if assert_non_integer_index:
                assert ra.H[0] != int(ra.H[0]) or \
                       ra.H[1] != int(ra.H[1]) or \
                       ra.H[2] != int(ra.H[2])

            for omegaidx in [0,1]:

                rot_mat = rotation_vector.axis_and_angle_as_r3_rotation_matrix(
                    omegas[omegaidx])

                assert(math.fabs(rot_mat.determinant() - 1.0) < 0.0001)

                H1 = (rot_mat * UB_mat)*hkl
                H1 =  H1 + beam_vector
                len_H1 = math.sqrt((H1[0] * H1[0]) +
                                   (H1[1] * H1[1]) +
                                   (H1[2] * H1[2]))

                if math.fabs(len_H1 - 1.0 / wavelength) > 0.0001:
                    raise RuntimeError, 'length error for %d %d %d' % hkl

                if rp(hkl, omegas[omegaidx]):
                    x, y = rp.get_prediction()
                    assert(0 < x < detector_size)
                    assert(0 < y < detector_size)
Exemplo n.º 7
0
def work_detector_model():
    # trivial test of instantiation

    i = matrix.col((1, 0, 0))
    j = matrix.col((0, 1, 0))
    k = matrix.col((0, 0, 1))

    d1 = i
    d2 = -j
    lim = (0,50)

    panel0 = sensor(matrix.col((-126, 144, -193)), d1, d2, lim, lim)

    panel0.set_origin(k)
    panel0.set_frame(k, i, j)

    assert(k.dot(matrix.col(panel0.origin)) > 0.999)

    print 'OK'
    return
Exemplo n.º 8
0
from rstbx.bpcx import sensor
from dxtbx.model.experiment import Panel

npx_fast = 1475
npx_slow = 1679
pix_size_f = pix_size_s = 0.172
fast = matrix.col((1.0, 0.0, 0.0))
norm = matrix.col((0.0, 0.0, 1.0))
slow = norm.cross(fast).normalize()
centre = matrix.col((0.0, 0.0, 200.0))
origin = centre - (
    0.5 * npx_fast * pix_size_f * fast + 0.5 * npx_slow * pix_size_s * slow
)
# direct use of the sensor constructor
lim = (0, 50)
my_panel = sensor(origin, fast, slow, lim, lim)

# equivalent using the dials Panel
dials_panel = Panel(
    "PAD", fast, slow, origin, (lim[1] / 200, lim[1] / 200), (200, 200), (0, 2e20)
)

# get the bits needed to make a RayPredictor
s0 = mybeam.get_s0()
spindle = mygonio.get_rotation_axis()
ray_predictor = RayPredictor(s0, spindle, UB, sweep_range)

# also make a reflection_prediction object
from rstbx.diffraction import reflection_prediction

rp = reflection_prediction(mygonio.get_rotation_axis(), mybeam.get_s0(), UB, my_panel)
Exemplo n.º 9
0
# make an identical sensor and a Panel for testing.
from rstbx.bpcx import sensor
from dxtbx.model.experiment import Panel
npx_fast = 1475
npx_slow = 1679
pix_size_f = pix_size_s = 0.172
fast = matrix.col((1., 0., 0.))
norm = matrix.col((0., 0., 1.))
slow = norm.cross(fast).normalize()
centre = matrix.col((0., 0., 200.))
origin = centre - (0.5 * npx_fast * pix_size_f * fast +
                   0.5 * npx_slow * pix_size_s * slow)
# direct use of the sensor constructor
lim = (0,50)
my_panel = sensor(origin, fast, slow, lim, lim)

# equivalent using the dials Panel
dials_panel = Panel("PAD", fast, slow, origin,
            (lim[1]/200, lim[1]/200), (200, 200), (0, 2e20))

# get the bits needed to make a RayPredictor
s0 = mybeam.get_s0()
spindle = mygonio.get_rotation_axis()
ray_predictor = RayPredictor(s0, spindle, UB, sweep_range)

# also make a reflection_prediction object
from rstbx.diffraction import reflection_prediction
rp = reflection_prediction(mygonio.get_rotation_axis(), mybeam.get_s0(),
                           UB, my_panel)