示例#1
0
  def make_detector(stype, fast_axis, slow_axis, origin,
                    pixel_size, image_size, trusted_range = (0.0, 0.0),
                    px_mm=None, name="Panel", thickness=0.0, material='',
                    mu=0.0, gain=None, identifier=""):
    """Ensure all types are correct before creating c++ detector class."""

    if px_mm is None:
      px_mm = SimplePxMmStrategy()
    try:
      d = Detector()
      p = d.add_panel()
      p.set_type(str(stype))
      p.set_name(str(name))
      p.set_local_frame(
          tuple(map(float, fast_axis)),
          tuple(map(float, slow_axis)),
          tuple(map(float, origin)))
      p.set_pixel_size(tuple(map(float, pixel_size)))
      p.set_image_size(tuple(map(int, image_size)))
      p.set_trusted_range(tuple(map(float, trusted_range)))
      p.set_thickness(thickness)
      p.set_material(material)
      p.set_px_mm_strategy(px_mm)
      p.set_identifier(identifier)
      if gain is not None:
        p.set_gain(gain)
    except Exception, e:
      print e
      raise e
示例#2
0
    def make_detector(stype,
                      fast_axis,
                      slow_axis,
                      origin,
                      pixel_size,
                      image_size,
                      trusted_range=(0.0, 0.0),
                      px_mm=None,
                      name="Panel",
                      thickness=0.0,
                      material='',
                      mu=0.0,
                      gain=None,
                      identifier=""):
        """Ensure all types are correct before creating c++ detector class."""

        if px_mm is None:
            px_mm = SimplePxMmStrategy()
        d = Detector()
        p = d.add_panel()
        p.set_type(str(stype))
        p.set_name(str(name))
        p.set_local_frame(tuple(map(float, fast_axis)),
                          tuple(map(float, slow_axis)),
                          tuple(map(float, origin)))
        p.set_pixel_size(tuple(map(float, pixel_size)))
        p.set_image_size(tuple(map(int, image_size)))
        p.set_trusted_range(tuple(map(float, trusted_range)))
        p.set_thickness(thickness)
        p.set_material(material)
        p.set_px_mm_strategy(px_mm)
        p.set_identifier(identifier)
        if gain is not None:
            p.set_gain(gain)
        return d
示例#3
0
    def generate_from_phil(params, beam=None):
        '''
    Create a new detector model from phil parameters

    '''
        from cctbx.eltbx import attenuation_coefficient
        detector = Detector()

        # Create a list of panels
        panel_list = {}
        for panel_params in params.detector.panel:
            panel = Panel()
            if panel_params.name is not None:
                panel.set_name(panel_params.name)
            if panel_params.type is not None:
                panel.set_type(panel_params.type)
            if panel_params.gain is not None:
                panel.set_gain(panel_params.gain)
            if panel_params.pixel_size is not None:
                panel.set_pixel_size(panel_params.pixel_size)
            else:
                raise RuntimeError('No pixel size set')
            if panel_params.image_size is not None:
                panel.set_image_size(panel_params.image_size)
            else:
                raise RuntimeError('No image size set')
            if panel_params.trusted_range is not None:
                panel.set_trusted_range(panel_params.trusted_range)
            else:
                raise RuntimeError('No trusted range set')
            if panel_params.thickness is not None:
                panel.set_thickness(panel_params.thickness)
            if panel_params.material is not None:
                panel.set_material(panel_params.material)
            if panel_params.parallax_correction is True:
                if panel_params.material is None:
                    raise RuntimeError("No material for parallax correction")
                if panel_params.thickness is None:
                    raise RuntimeError("No thickness for parallax correction")
                if beam is None:
                    raise RuntimeError("No beam for parallax correction")
                table = attenuation_coefficient.get_table(
                    panel_params.material)
                mu = table.mu_at_angstrom(beam.get_wavelength()) / 10.0
                t0 = panel_params.thickness
                panel.set_px_mm_strategy(ParallaxCorrectedPxMmStrategy(mu, t0))
            if panel_params.fast_axis is None:
                panel_params.fast_axis = (1, 0, 0)
            if panel_params.slow_axis is None:
                panel_params.slow_axis = (0, 1, 0)
            if panel_params.origin is None:
                panel_params.origin = (0, 0, 0)
            panel.set_local_frame(panel_params.fast_axis,
                                  panel_params.slow_axis, panel_params.origin)
            if panel_params.id in panel_list:
                raise RuntimeError('Multiple panels with id=%d' %
                                   panel_params.id)
            panel_list[panel_params.id] = panel

        # Create the hierarchy
        panel_counter = 0
        root = detector.hierarchy()
        if params.detector.hierarchy.name is not None:
            root.set_name(params.detector.hierarchy.name)
        if params.detector.hierarchy.fast_axis is None:
            params.detector.hierarchy.fast_axis = (1, 0, 0)
        if params.detector.hierarchy.slow_axis is None:
            params.detector.hierarchy.slow_axis = (0, 1, 0)
        if params.detector.hierarchy.origin is None:
            params.detector.hierarchy.origin = (0, 0, 0)
        root.set_frame(params.detector.hierarchy.fast_axis,
                       params.detector.hierarchy.slow_axis,
                       params.detector.hierarchy.origin)

        def get_parent(node, index):
            if len(index) == 0:
                return node
            return get_parent(node[index[0]], index[1:])

        for group_params in params.detector.hierarchy.group:
            parent = get_parent(root, group_params.id[:-1])
            assert len(parent) == group_params.id[-1]
            group = parent.add_group()
            if group_params.name is not None:
                group.set_name(group_params.name)
            if group_params.fast_axis is None:
                group_params.fast_axis = (1, 0, 0)
            if group_params.slow_axis is None:
                group_params.slow_axis = (0, 1, 0)
            if group_params.origin is None:
                group_params.origin = (0, 0, 0)
            group.set_local_frame(group_params.fast_axis,
                                  group_params.slow_axis, group_params.origin)
            for panel_id in group_params.panel:
                assert panel_id == panel_counter
                group.add_panel(panel_list[panel_id])
                panel_counter += 1
        if panel_counter == 0:
            for panel_id in range(max(panel_list.keys()) + 1):
                detector.add_panel(panel_list[panel_id])
        elif panel_counter != len(panel_list):
            raise RuntimeError("Inconsistent number of panels in hierarchy")

        # Return detector
        return detector