Ejemplo n.º 1
0
def imagesweep_from_dict(d, check_format=True):
  '''Construct and image sweep from the dictionary.'''
  from dxtbx.imageset import ImageSetFactory
  from dxtbx.serialize import beam, detector, goniometer, scan
  from dxtbx.serialize.filename import load_path

  # Get the template (required)
  template = load_path(str(d['template']))

  # If the scan isn't set, find all available files
  scan_dict = d.get('scan')
  if scan_dict is None:
    image_range = None
  else:
    image_range = scan_dict.get('image_range')

  # Construct the sweep
  try:
    sweep = ImageSetFactory.from_template(
      template, image_range, check_format=check_format)[0]

    # Get the existing models as dictionaries
    beam_dict = beam.to_dict(sweep.get_beam())
    gonio_dict = goniometer.to_dict(sweep.get_goniometer())
    detector_dict = detector.to_dict(sweep.get_detector())
    scan_dict = scan.to_dict(sweep.get_scan())
  except Exception:
    indices = range(image_range[0], image_range[1] + 1)
    sweep = ImageSetFactory.make_sweep(
      template, indices, check_format=False)
    beam_dict = None
    gonio_dict = None
    detector_dict = None
    scan_dict = None

  # Set some external lookups
  if 'mask' in d and d['mask'] is not None:
    with open(d['mask']) as infile:
      sweep.external_lookup.mask.filename = d['mask']
      sweep.external_lookup.mask.data = pickle.load(infile)
  if 'gain' in d and d['gain'] is not None:
    with open(d['gain']) as infile:
      sweep.external_lookup.gain.filename = d['gain']
      sweep.external_lookup.gain.data = pickle.load(infile)
  if 'pedestal' in d and d['pedestal'] is not None:
    with open(d['pedestal']) as infile:
      sweep.external_lookup.pedestal.filename = d['pedestal']
      sweep.external_lookup.pedestal.data = pickle.load(infile)

  # Set the models with the exisiting models as templates
  sweep.set_beam(beam.from_dict(d.get('beam'), beam_dict))
  sweep.set_goniometer(goniometer.from_dict(d.get('goniometer'), gonio_dict))
  sweep.set_detector(detector.from_dict(d.get('detector'), detector_dict))
  sweep.set_scan(scan.from_dict(d.get('scan'), scan_dict))

  # Return the sweep
  return sweep
Ejemplo n.º 2
0
  def tst_goniometer(self):
    from dxtbx.serialize import goniometer
    from dxtbx.model import Goniometer
    g1 = Goniometer((1, 0, 0), (1, 0, 0, 0, 1, 0, 0, 0, 1))
    d = goniometer.to_dict(g1)
    g2 = goniometer.from_dict(d)
    assert(d['rotation_axis'] == (1, 0, 0))
    assert(d['fixed_rotation'] == (1, 0, 0, 0, 1, 0, 0, 0, 1))
    assert(g1 == g2)

    # Test with a template and partial dictionary
    d2 = { 'rotation_axis' : (0, 1, 0) }
    g3 = goniometer.from_dict(d2, d)
    assert(g3.get_rotation_axis() == (0, 1, 0))
    assert(g3.get_fixed_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1))
    assert(g2 != g3)

    print 'OK'
Ejemplo n.º 3
0
    def tst_goniometer(self):
        from dxtbx.serialize import goniometer
        from dxtbx.model import Goniometer
        g1 = Goniometer((1, 0, 0), (1, 0, 0, 0, 1, 0, 0, 0, 1))
        d = goniometer.to_dict(g1)
        g2 = goniometer.from_dict(d)
        assert (d['rotation_axis'] == (1, 0, 0))
        assert (d['fixed_rotation'] == (1, 0, 0, 0, 1, 0, 0, 0, 1))
        assert (g1 == g2)

        # Test with a template and partial dictionary
        d2 = {'rotation_axis': (0, 1, 0)}
        g3 = goniometer.from_dict(d2, d)
        assert (g3.get_rotation_axis() == (0, 1, 0))
        assert (g3.get_fixed_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1))
        assert (g2 != g3)

        print 'OK'