def tst_dump_empty_sweep(self):
    from dxtbx.imageset import ImageSweep, NullReader, SweepFileList
    from dxtbx.model import Beam, Detector, Goniometer, Scan
    from dxtbx.model.crystal import crystal_model
    from uuid import uuid4

    imageset = ImageSweep(NullReader(SweepFileList("filename%01d.cbf", (0, 3))))
    imageset.set_beam(Beam((1, 0, 0)))
    imageset.set_detector(Detector())
    imageset.set_goniometer(Goniometer())
    imageset.set_scan(Scan((1, 3), (0.0, 1.0)))

    crystal = crystal_model((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol=1)

    experiments = ExperimentListFactory.from_imageset_and_crystal(
      imageset, crystal)

    dump = ExperimentListDumper(experiments)
    filename = 'temp%s.json' % uuid4().hex
    dump.as_json(filename)
    experiments2 = ExperimentListFactory.from_json_file(filename,
                                                        check_format=False)
    self.check(experiments, experiments2)

    print 'OK'
示例#2
0
class TestImageSweep(object):

  def __init__(self):
    pass

  def get_file_list(self):
    import libtbx.load_env
    import os
    from dxtbx.imageset import SweepFileList

    try:
      dials_regression = libtbx.env.dist_path('dials_regression')
    except KeyError, e:
      print 'FAIL: dials_regression not configured'
      return

    path = os.path.join(dials_regression, 'centroid_test_data')

    # Non-sequential Filenames and image indices
    template = os.path.join(path, 'centroid_%04d.cbf')
    array_range = (0, 9)

    filenames = SweepFileList(template, array_range)

    return filenames
  def tst_from_datablock(self):
    from dxtbx.imageset import ImageSweep, NullReader, SweepFileList
    from dxtbx.model import Beam, Detector, Goniometer, Scan
    from dxtbx.datablock import DataBlockFactory
    from dxtbx.model.crystal import crystal_model

    imageset = ImageSweep(NullReader(SweepFileList("filename%01d.cbf", (0, 2))))
    imageset.set_beam(Beam())
    imageset.set_detector(Detector())
    imageset.set_goniometer(Goniometer())
    imageset.set_scan(Scan((1, 2), (0, 1)))

    crystal = crystal_model((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol=0)

    datablock = DataBlockFactory.from_imageset(imageset)

    experiments = ExperimentListFactory.from_datablock_and_crystal(
      datablock, crystal)

    assert(len(experiments) == 1)
    assert(experiments[0].imageset is not None)
    assert(experiments[0].beam is not None)
    assert(experiments[0].detector is not None)
    assert(experiments[0].goniometer is not None)
    assert(experiments[0].scan is not None)
    assert(experiments[0].crystal is not None)

    print 'OK'
示例#4
0
    def tst_from_null_sweep(self):
        from dxtbx.datablock import DataBlockFactory
        from dxtbx.imageset import NullReader, ImageSweep, SweepFileList
        from dxtbx.model import Beam, Detector, Goniometer, Scan

        sweep = ImageSweep(
            NullReader(SweepFileList("template_%2d.cbf", (0, 10))))
        sweep.set_beam(Beam((0, 0, 1)))
        sweep.set_detector(Detector())
        sweep.set_goniometer(Goniometer((1, 0, 0)))
        sweep.set_scan(Scan((1, 10), (0, 0.1)))

        # Create the datablock
        datablock = DataBlockFactory.from_imageset(sweep)
        assert (len(datablock) == 1)
        datablock = datablock[0]

        sweeps = datablock.extract_sweeps()
        assert (len(sweeps) == 1)
        assert (sweeps[0].get_beam() == sweep.get_beam())
        assert (sweeps[0].get_detector() == sweep.get_detector())
        assert (sweeps[0].get_goniometer() == sweep.get_goniometer())
        assert (sweeps[0].get_scan() == sweep.get_scan())

        print 'OK'
示例#5
0
class TestMultiFileReader(object):
    def normal_file_list(self):

        dials_regression = libtbx.env.dist_path('dials_regression')
        path = os.path.join(dials_regression, 'centroid_test_data')

        # Non-sequential Filenames and image indices
        filenames = []
        image_indices = range(1, 10)
        for i in image_indices:
            filenames.append(
                os.path.join(path, 'centroid_000{0}.cbf'.format(i)))

        return filenames

    def sweep_file_list(self):
        from dxtbx.imageset import SweepFileList

        try:
            dials_regression = libtbx.env.dist_path('dials_regression')
        except KeyError, e:
            print 'FAIL: dials_regression not configured'
            return

        path = os.path.join(dials_regression, 'centroid_test_data')

        # Non-sequential Filenames and image indices
        template = os.path.join(path, 'centroid_%04d.cbf')
        array_range = (0, 9)

        filenames = SweepFileList(template, array_range)

        return filenames
示例#6
0
  def tst_cmp(self, filelist):
    from dxtbx.imageset import SweepFileList

    assert(filelist == filelist)

    template = template = '%s%%0%dd%s' % ('filename', 5, '.cbf')
    array_range = (0, 10)
    filelist2 = SweepFileList(template, array_range)
    assert(filelist != filelist2)

    template = template = '%s%%0%dd%s' % ('filename2', 5, '.cbf')
    array_range = (20, 50)
    filelist3 = SweepFileList(template, array_range)
    assert(filelist != filelist3)

    template = template = '%s%%0%dd%s' % ('filename', 5, '.cbf')
    array_range = (20, 50)
    filelist4 = SweepFileList(template, array_range)
    assert(filelist == filelist4)

    print 'OK'
示例#7
0
    def get_file_list(self):
        from dxtbx.imageset import SweepFileList

        dials_regression = libtbx.env.dist_path('dials_regression')
        path = os.path.join(dials_regression, 'centroid_test_data')

        # Non-sequential Filenames and image indices
        template = os.path.join(path, 'centroid_%04d.cbf')
        array_range = (0, 9)

        filenames = SweepFileList(template, array_range)

        return filenames
示例#8
0
  def tst_null_reader_sweep(self):
    from dxtbx.imageset import NullReader, ImageSweep, SweepFileList
    from dxtbx.model import Beam, Detector, Goniometer, Scan

    template = 'hello_world_%d.cbf'
    paths = [template % 1]

    # Create the null reader
    reader = NullReader(SweepFileList(template, (0, 1)))

    # Create the imageset
    imageset = ImageSweep(reader)

    # Try to get an item
    try:
      imageset[0]
      assert(False)
    except Exception:
      print 'OK'

    # Try to slice the imageset
    imageset2 = imageset[0:1]
    print 'OK'

    # Try some functions which should work
    assert(len(imageset) == 1)
    assert(imageset == imageset)
    assert(imageset.indices() == [0])
    assert(imageset.is_valid())
    assert(imageset.get_template() == template)
    print 'OK'

    # Get the image paths
    assert(imageset.paths() == paths)
    assert(imageset.get_path(0) == paths[0])
    print 'OK'

    imageset.set_beam(Beam())
    imageset.set_detector(Detector())
    imageset.set_goniometer(Goniometer())
    imageset.set_scan(Scan((1,1), (0, 1)))
    assert(isinstance(imageset.get_beam(), Beam))
    assert(isinstance(imageset.get_detector(), Detector))
    assert(isinstance(imageset.get_goniometer(), Goniometer))
    assert(isinstance(imageset.get_scan(), Scan))
    print 'OK'
示例#9
0
  def run(self):
    from dxtbx.imageset import SweepFileList

    # Create the template and array range
    template = template = '%s%%0%dd%s' % ('filename', 5, '.cbf')
    array_range = (20, 50)

    # Create the sweep file list class
    filelist = SweepFileList(template, array_range)

    # Call a load of tests
    self.tst_len(filelist, 30)
    self.tst_template(filelist, template)
    self.tst_array_range(filelist, array_range)
    self.tst_indices(filelist, range(*array_range))
    self.tst_is_index_in_range(filelist)
    self.tst_get_filename(filelist)
    self.tst_get_item(filelist)
    self.tst_iter(filelist)
    self.tst_cmp(filelist)
示例#10
0
    import os
    from dxtbx.imageset import SweepFileList

    try:
      dials_regression = libtbx.env.dist_path('dials_regression')
    except KeyError, e:
      print 'FAIL: dials_regression not configured'
      return

    path = os.path.join(dials_regression, 'centroid_test_data')

    # Non-sequential Filenames and image indices
    template = os.path.join(path, 'centroid_%04d.cbf')
    array_range = (0, 9)

    filenames = SweepFileList(template, array_range)

    return filenames

  def run(self):
    self.run_tests(self.normal_file_list())
    self.run_tests(self.sweep_file_list())

  def run_tests(self, filenames):

    from dxtbx.imageset import MultiFileReader
    from dxtbx.format.Registry import Registry

    # Get the parameters we need
    format_class = Registry.find(filenames[0])