Example #1
0
  def tst_scan(self):
    from dxtbx.serialize import scan
    from dxtbx.model import Scan
    from scitbx.array_family import flex
    s1 = Scan((1, 3), (1.0, 0.2), flex.double([0.1, 0.1, 0.1]), flex.double([0.1, 0.2, 0.3]))
    d = scan.to_dict(s1)
    s2 = scan.from_dict(d)
    assert(d['image_range'] == (1, 3))
    assert(d['oscillation'] == (1.0, 0.2))
    assert(d['exposure_time'] == [0.1, 0.1, 0.1])
    assert(d['epochs'] == [0.1, 0.2, 0.3])
    assert(s1 == s2)

    # Test with a template and partial dictionary
    d2 = { 'exposure_time' : [0.2, 0.2, 0.2] }
    s3 = scan.from_dict(d2, d)
    assert(s3.get_image_range() == (1, 3))
    assert(s3.get_oscillation() == (1.0, 0.2))
    assert(list(s3.get_exposure_times()) == [0.2, 0.2, 0.2])
    assert(list(s3.get_epochs()) == [0.1, 0.2, 0.3])
    assert(s2 != s3)

    # Test with a partial epoch
    d3 = { 'image_range' : (1, 10), 'epochs' : [0.1, 0.2] }
    s4 = scan.from_dict(d3, d)
    assert(abs(s4.get_epochs()[2] - 0.3) < 1e-7)
    assert(abs(s4.get_epochs()[9] - 1.0) < 1e-7)

    print 'OK'
Example #2
0
    def tst_scan(self):
        from dxtbx.serialize import scan
        from dxtbx.model import Scan
        from scitbx.array_family import flex
        s1 = Scan((1, 3), (1.0, 0.2), flex.double([0.1, 0.1, 0.1]),
                  flex.double([0.1, 0.2, 0.3]))
        d = scan.to_dict(s1)
        s2 = scan.from_dict(d)
        assert (d['image_range'] == (1, 3))
        assert (d['oscillation'] == (1.0, 0.2))
        assert (d['exposure_time'] == [0.1, 0.1, 0.1])
        assert (d['epochs'] == [0.1, 0.2, 0.3])
        assert (s1 == s2)

        # Test with a template and partial dictionary
        d2 = {'exposure_time': [0.2, 0.2, 0.2]}
        s3 = scan.from_dict(d2, d)
        assert (s3.get_image_range() == (1, 3))
        assert (s3.get_oscillation() == (1.0, 0.2))
        assert (list(s3.get_exposure_times()) == [0.2, 0.2, 0.2])
        assert (list(s3.get_epochs()) == [0.1, 0.2, 0.3])
        assert (s2 != s3)

        # Test with a partial epoch
        d3 = {'image_range': (1, 10), 'epochs': [0.1, 0.2]}
        s4 = scan.from_dict(d3, d)
        assert (abs(s4.get_epochs()[2] - 0.3) < 1e-7)
        assert (abs(s4.get_epochs()[9] - 1.0) < 1e-7)

        print 'OK'
Example #3
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