Ejemplo n.º 1
0
def tst_panel():
    '''Test pickling the panel object.'''
    obj1 = Panel()
    obj1.set_local_frame((1, 0, 0), (0, 1, 0), (0, 0, 1))
    obj2 = pickle_then_unpickle(obj1)
    assert (obj1 == obj2)
    print "OK"
Ejemplo n.º 2
0
def test_offset_px_mm_strategy():
    # for future reference this is the array the same shape
    # as the image in pixels with offsets in pixels

    dx = flex.double(flex.grid(10, 10), 1)
    dy = flex.double(flex.grid(10, 10), 1)

    strategy = OffsetParallaxCorrectedPxMmStrategy(1, 1, dx, dy)

    p = Panel()
    p.set_image_size((10, 10))
    p.set_mu(1)
    p.set_thickness(1)
    p.set_px_mm_strategy(strategy)

    d = p.to_dict()

    # Panel.from_dict sets the strategy to ParallaxCorrectedPxMmStrategy rather than
    # OffsetParallaxCorrectedPxMmStrategy as the offsets aren't currently serialized
    pnew = Panel.from_dict(d)
    assert pnew != p

    pnew = pickle.loads(pickle.dumps(pnew))
    assert pnew != p
Ejemplo n.º 3
0
    def __init__(self, obj, beam):
        from dxtbx.model import Detector, Panel
        from cctbx.eltbx import attenuation_coefficient
        from dxtbx.model import ParallaxCorrectedPxMmStrategy
        from scitbx import matrix

        # Get the handles
        nx_file = obj.handle.file
        nx_detector = obj.handle
        nx_module = obj.modules[0].handle

        # Get the detector name and type
        detector_type = str(nx_detector['type'][()])
        detector_name = str(nx_detector.name)

        # Get the trusted range of pixel values
        trusted_range = (-1, float(nx_detector['saturation_value'][()]))

        # Get the detector thickness
        thickness = nx_detector['sensor_thickness']
        thickness_value = float(thickness[()])
        thickness_units = thickness.attrs['units']
        thickness_value = float(
            convert_units(thickness_value, thickness_units, "mm"))

        # Get the detector material
        material = str(nx_detector['sensor_material'][()])

        # Get the fast pixel size and vector
        fast_pixel_direction = nx_module['fast_pixel_direction']
        fast_pixel_direction_value = float(fast_pixel_direction[()])
        fast_pixel_direction_units = fast_pixel_direction.attrs['units']
        fast_pixel_direction_vector = fast_pixel_direction.attrs['vector']
        fast_pixel_direction_value = convert_units(fast_pixel_direction_value,
                                                   fast_pixel_direction_units,
                                                   "mm")
        fast_axis = matrix.col(fast_pixel_direction_vector).normalize()

        # Get the slow pixel size and vector
        slow_pixel_direction = nx_module['slow_pixel_direction']
        slow_pixel_direction_value = float(slow_pixel_direction[()])
        slow_pixel_direction_units = slow_pixel_direction.attrs['units']
        slow_pixel_direction_vector = slow_pixel_direction.attrs['vector']
        slow_pixel_direction_value = convert_units(slow_pixel_direction_value,
                                                   slow_pixel_direction_units,
                                                   "mm")
        slow_axis = matrix.col(slow_pixel_direction_vector).normalize()

        # Get the origin vector
        module_offset = nx_module['module_offset']
        origin = construct_vector(nx_file, module_offset.name)

        # Ensure that fast and slow axis are orthogonal
        normal = fast_axis.cross(slow_axis)
        slow_axis = -fast_axis.cross(normal)

        # Compute the attenuation coefficient.
        # This will fail for undefined composite materials
        # mu_at_angstrom returns cm^-1, but need mu in mm^-1
        if material == 'Si':
            pass
        elif material == 'Silicon':
            material = 'Si'
        elif material == 'Sillicon':
            material = 'Si'
        elif material == 'CdTe':
            pass
        elif material == 'GaAs':
            pass
        else:
            raise RuntimeError('Unknown material: %s' % material)
        table = attenuation_coefficient.get_table(material)
        wavelength = beam.get_wavelength()
        mu = table.mu_at_angstrom(wavelength) / 10.0

        # Construct the detector model
        pixel_size = (fast_pixel_direction_value, slow_pixel_direction_value)
        image_size = tuple(map(int, nx_module['data_size']))

        self.model = Detector()
        self.model.add_panel(
            Panel(detector_type, detector_name, tuple(fast_axis),
                  tuple(slow_axis), tuple(origin), pixel_size, image_size,
                  trusted_range, thickness_value, material, mu))

        # Set the parallax correction
        for panel in self.model:
            panel.set_px_mm_strategy(
                ParallaxCorrectedPxMmStrategy(mu, thickness_value))
            panel.set_type('SENSOR_PAD')
Ejemplo n.º 4
0
    -150.0059,
)

dl1 = dl[0], dl[3], dl[6]
dl2 = dl[1], dl[4], dl[7]
dl0 = dl[2], dl[5], dl[8]

dp1 = dp[0], dp[3], dp[6]
dp2 = dp[1], dp[4], dp[7]
dp0 = dp[2], dp[5], dp[8]

d1 = (-0.00182517255306, 0.999997320637, -0.00142389018396)
d2 = (0.999998194757, 0.0018259228625, 0.000525821456245)
d0 = (-48.3367467929, -1.3827137802, -149.981643976)

p = Panel()
p.set_parent_frame(dp1, dp2, dp0)
p.set_local_frame(dl1, dl2, dl0)
p.set_frame(d1, d2, d0)

# print repr([10000000000*pp for pp in p.get_parent_d_matrix()])
# for pp in p.get_parent_d_matrix():
#  print '{0:.16f}'.format(pp)

#
# p.set_local_frame(dl1, dl2, dl0)

# d_matrix1 = p.get_d_matrix()

# p = Panel()
# p.set_frame(dl1, dl2, dl0)