def exercise_multi_axis_goniometer():
  import libtbx.load_env
  from libtbx.test_utils import approx_equal
  import os

  if not libtbx.env.has_module("dials_regression"):
    print "Skipping tstFormatCBFFull.py: dials_regression not present"
    return

  data_dir = libtbx.env.find_in_repositories(
    relative_path="dials_regression/image_examples/dials-190",
    test=os.path.isdir)

  from dxtbx.imageset import ImageSetFactory
  imgset = ImageSetFactory.new(os.path.join(data_dir, "whatev1_01_00001.cbf"))[0]
  gonio = imgset.get_goniometer()
  assert approx_equal(gonio.get_fixed_rotation(), (1,0,0,0,1,0,0,0,1))
  assert approx_equal(gonio.get_setting_rotation(), (1,0,0,0,1,0,0,0,1))

  from dxtbx.imageset import ImageSetFactory
  imgset = ImageSetFactory.new(os.path.join(data_dir, "whatev1_02_00001.cbf"))[0]
  gonio = imgset.get_goniometer()
  assert approx_equal(gonio.get_fixed_rotation(), (1,0,0,0,1,0,0,0,1))
  assert approx_equal(
    gonio.get_setting_rotation(),
    (1, 0, 0, 0, -0.5, 0.866, 0.0, -0.866, -0.5), eps=1e-4)

  from dxtbx.imageset import ImageSetFactory
  imgset = ImageSetFactory.new(os.path.join(data_dir, "whatev1_03_00001.cbf"))[0]
  gonio = imgset.get_goniometer()
  assert approx_equal(gonio.get_fixed_rotation(), (1,0,0,0,1,0,0,0,1))
  assert approx_equal(
    gonio.get_setting_rotation(),
    (1, 0, 0, 0, 0.5, 0.866, 0.0, -0.866, 0.5), eps=1e-4)
Example #2
0
def test_to_xds(dials_regression, tmpdir):
    tmpdir.chdir()

    template = os.path.join(dials_regression, 'centroid_test_data',
                            "centroid_*.cbf")
    file_names = glob.glob(template)

    expected_output = """\
DETECTOR=PILATUS MINIMUM_VALID_PIXEL_VALUE=0 OVERLOAD=495976
SENSOR_THICKNESS= 0.320
DIRECTION_OF_DETECTOR_X-AXIS= 1.00000 0.00000 0.00000
DIRECTION_OF_DETECTOR_Y-AXIS= 0.00000 1.00000 0.00000
NX=2463 NY=2527 QX=0.1720 QY=0.1720
DETECTOR_DISTANCE= 190.180
ORGX= 1235.84 ORGY= 1279.58
ROTATION_AXIS= 1.00000 0.00000 0.00000
STARTING_ANGLE= 0.000
OSCILLATION_RANGE= 0.200
X-RAY_WAVELENGTH= 0.97950
INCIDENT_BEAM_DIRECTION= -0.000 -0.000 1.021
FRACTION_OF_POLARIZATION= 0.999
POLARIZATION_PLANE_NORMAL= 0.000 1.000 0.000
NAME_TEMPLATE_OF_DATA_FRAMES= %s
TRUSTED_REGION= 0.0 1.41
UNTRUSTED_RECTANGLE= 487 495 0 2528
UNTRUSTED_RECTANGLE= 981 989 0 2528
UNTRUSTED_RECTANGLE= 1475 1483 0 2528
UNTRUSTED_RECTANGLE= 1969 1977 0 2528
UNTRUSTED_RECTANGLE= 0 2464 195 213
UNTRUSTED_RECTANGLE= 0 2464 407 425
UNTRUSTED_RECTANGLE= 0 2464 619 637
UNTRUSTED_RECTANGLE= 0 2464 831 849
UNTRUSTED_RECTANGLE= 0 2464 1043 1061
UNTRUSTED_RECTANGLE= 0 2464 1255 1273
UNTRUSTED_RECTANGLE= 0 2464 1467 1485
UNTRUSTED_RECTANGLE= 0 2464 1679 1697
UNTRUSTED_RECTANGLE= 0 2464 1891 1909
UNTRUSTED_RECTANGLE= 0 2464 2103 2121
UNTRUSTED_RECTANGLE= 0 2464 2315 2333
DATA_RANGE= 1 9
JOB=XYCORR INIT COLSPOT IDXREF DEFPIX INTEGRATE CORRECT\
""" % (template.replace("*", "????"))

    cmd = " ".join(["dxtbx.to_xds"] + file_names)
    result = easy_run.fully_buffered(cmd)
    # allow extra lines to have been added (these may be comments)
    for record in expected_output.split('\n'):
        assert record.strip() in "\n".join(result.stdout_lines), record

    # now test reading from a json file
    sweep = ImageSetFactory.new(file_names)[0]
    with open("sweep.json", mode="wb") as fh:
        dump.imageset(sweep, fh)
    cmd = " ".join(["dxtbx.to_xds", "sweep.json"])
    print(cmd)
    result = easy_run.fully_buffered(cmd)

    # allow extra lines to have been added (these may be comments)
    for record in expected_output.split('\n'):
        assert record.strip() in "\n".join(result.stdout_lines), record
def exercise_still():
    import libtbx.load_env
    from libtbx.test_utils import approx_equal
    import os

    if not libtbx.env.has_module("dials"):
        print "Skipping tstFormatCBFFull.py: dials not present"
        return
    if not libtbx.env.has_module("dials_regression"):
        print "Skipping tstFormatCBFFull.py: dials_regression not present"
        return

    data_dir = libtbx.env.find_in_repositories(
        relative_path="dials_regression/image_examples/DLS_I04",
        test=os.path.isdir)

    from dxtbx.imageset import ImageSetFactory
    imgset = ImageSetFactory.new(
        os.path.join(data_dir, "grid_full_cbf_0005.cbf"))[0]
    if imgset.get_scan(0):
        scan = imgset.get_scan(0)
        assert approx_equal(scan.get_image_oscillation(0), (30.0, 0.0),
                            eps=1e-5)
    beam = imgset.get_beam(0)
    beam.get_s0()
    assert approx_equal(beam.get_s0(), (-0.0, -0.0, -1.0209290454313424))
Example #4
0
def print_sweep(list_of_images):

  from dxtbx.imageset import ImageSetFactory
  sweeps = ImageSetFactory.new(list_of_images)

  for s in sweeps:
    print s.get_detector()
    print s.get_beam()
    print s.get_goniometer()
    print s.get_scan()

    # compute the beam centre... in mm... w.r.t. fast, slow axis

    print 'Derived quantities:'

    from scitbx import matrix

    d = s.get_detector()[0]
    b = s.get_beam()

    o = matrix.col(d.get_origin())
    f = matrix.col(d.get_fast_axis())
    s = matrix.col(d.get_slow_axis())
    s0 = matrix.col(b.get_direction())

    n = f.cross(s)

    beam_offset = o - o.dot(s0) * s0
    print '    beam centre (mm, fast, slow): %.2f %.2f' % (- beam_offset.dot(f),
                                                            - beam_offset.dot(s))
Example #5
0
def print_sweep(list_of_images):

    from dxtbx.imageset import ImageSetFactory
    sweeps = ImageSetFactory.new(list_of_images)

    for sweep in sweeps:
        print(sweep.get_detector())
        print(sweep.get_beam())
        print(sweep.get_goniometer())
        print(sweep.get_scan())

        # compute the beam centre... in mm... w.r.t. fast, slow axis

        print('Derived quantities:')

        from scitbx import matrix

        d = sweep.get_detector()[0]
        b = sweep.get_beam()

        o = matrix.col(d.get_origin())
        f = matrix.col(d.get_fast_axis())
        s = matrix.col(d.get_slow_axis())
        s0 = matrix.col(b.get_direction())

        n = f.cross(s)

        beam_offset = o - o.dot(s0) * s0
        print('    beam centre (mm, fast, slow): %.2f %.2f' %
              (-beam_offset.dot(f), -beam_offset.dot(s)))
def test_imagesetfactory(centroid_files, dials_regression):
    from dxtbx.imageset import ImageSetFactory, ImageSweep

    sweep = ImageSetFactory.new(centroid_files)

    assert isinstance(sweep[0], ImageSweep)

    template = os.path.join(dials_regression, "centroid_test_data",
                            "centroid_####.cbf")
    image_range = (3, 6)

    sweep = ImageSetFactory.from_template(template, image_range)

    assert isinstance(sweep[0], ImageSweep)
    assert len(sweep[0]) == 4
    assert sweep[0].paths()[0].endswith("3.cbf")
    assert sweep[0].paths()[-1].endswith("6.cbf")

    imageset = ImageSetFactory.make_imageset(centroid_files)
    assert len(imageset) == 9

    imageset = ImageSetFactory.make_imageset(centroid_files,
                                             check_format=False)
    assert len(imageset) == 9

    sweep = ImageSetFactory.make_sweep(template, list(range(1, 9 + 1)))
    assert len(sweep) == 9

    sweep = ImageSetFactory.make_sweep(template, list(range(3, 6 + 1)))
    assert len(sweep) == 4
Example #7
0
def basic_imageset_from_dict(d):
  ''' Construct an ImageSet class from the dictionary.'''
  from dxtbx.imageset import ImageSetFactory
  from dxtbx.serialize import beam, detector
  from dxtbx.serialize.filename import load_path

  # Get the filename list and create the imageset
  filenames = map(lambda p: load_path(p), map(str, d['filenames']))
  imageset = ImageSetFactory.new(filenames)[0]

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

  # Get the existing models as dictionaries
  beam_dict = beam.to_dict(imageset.get_beam())
  detector_dict = detector.to_dict(imageset.get_detector())

  # Set models
  imageset.set_beam(beam.from_dict(d.get('beam'), beam_dict))
  imageset.set_detector(detector.from_dict(d.get('detector'), detector_dict))

  # Return the imageset
  return imageset
  def tst_consistent(self):

    from dxtbx.imageset import ImageSetFactory
    from glob import glob
    from os.path import join
    from dxtbx.model import Scan

    # Create a sweep
    sweep_filenames = join(self.path, 'centroid_test_data', 'centroid*.cbf')
    sweep = ImageSetFactory.new(sorted(glob(sweep_filenames)))[0]

    # Create experiment with sweep and good scan
    e = Experiment(imageset=sweep, scan=sweep.get_scan())
    assert(e.is_consistent())

    # Create experiment with sweep and defective scan
    scan = sweep.get_scan()
    scan.set_image_range((1, 1))
    e = Experiment(imageset=sweep, scan=scan)
    #assert(not e.is_consistent()) # FIXME

    ## Create experiment with imageset and good scan
    #assert(e.is_consistent())

    ## Create experiment with imageset and non-still scan
    #assert(not e.is_consistent())

    ## Create experiment with imageset and scan with more than 1 image
    #assert(not e.is_consistent())

    ## Create experiment with imageset and defective scan
    #assert(not e.is_consistent())

    # Test passed
    print 'OK'
    def tst_cspad_hierarchy(self):
        from dxtbx.serialize import dump, load
        from dxtbx.imageset import ImageSetFactory
        import os
        from glob import glob
        path = libtbx.env.dist_path('dials_regression')

        # Get the imageset
        filename = os.path.join(path, "spotfinding_test_data", "idx*.cbf")
        imageset = ImageSetFactory.new(glob(filename))
        assert (len(imageset) == 1)
        imageset = imageset[0]

        # Dump and reload
        from uuid import uuid4
        filename = '%s.json' % uuid4().hex
        dump.imageset(imageset, filename)
        imageset2 = load.imageset(filename)

        # Check they're are the same
        assert (imageset2.get_beam() == imageset.get_beam())
        d1 = imageset.get_detector()
        d2 = imageset2.get_detector()
        assert (len(d1) == len(d2))
        for i, (p1, p2) in enumerate(zip(d1, d2)):
            assert (p1 == p2)
        assert (imageset2.get_detector() == imageset.get_detector())
        assert (imageset2 == imageset)

        # Test passed
        print 'OK'
Example #10
0
def test_imagesetfactory(centroid_files, dials_data):
    sequence = ImageSetFactory.new(centroid_files)

    assert isinstance(sequence[0], ImageSequence)

    template = dials_data("centroid_test_data").join("centroid_####.cbf").strpath
    image_range = (3, 6)

    sequence = ImageSetFactory.from_template(template, image_range)

    assert isinstance(sequence[0], ImageSequence)
    assert len(sequence[0]) == 4
    assert sequence[0].paths()[0].endswith("3.cbf")
    assert sequence[0].paths()[-1].endswith("6.cbf")

    imageset = ImageSetFactory.make_imageset(centroid_files)
    assert len(imageset) == 9

    imageset = ImageSetFactory.make_imageset(centroid_files, check_format=False)
    assert len(imageset) == 9

    sequence = ImageSetFactory.make_sequence(template, list(range(1, 9 + 1)))
    assert len(sequence) == 9

    sequence = ImageSetFactory.make_sequence(template, list(range(3, 6 + 1)))
    assert len(sequence) == 4
Example #11
0
def basic_imageset_from_dict(d, directory=None):
    """ Construct an ImageSet class from the dictionary."""
    # Get the filename list and create the imageset
    filenames = map(
        lambda p: load_path(p, directory=directory), map(str, d["filenames"])
    )
    imageset = ImageSetFactory.new(filenames)[0]

    # Set some external lookups
    if "mask" in d and d["mask"] is not None and d["mask"] is not "":
        path = load_path(d["mask"], directory=directory)
        with open(path) as infile:
            imageset.external_lookup.mask.filename = path
            imageset.external_lookup.mask.data = ImageBool(pickle.load(infile))
    if "gain" in d and d["gain"] is not None and d["gain"] is not "":
        path = load_path(d["gain"], directory=directory)
        with open(path) as infile:
            imageset.external_lookup.gain.filename = path
            imageset.external_lookup.gain.data = ImageDouble(pickle.load(infile))
    if "pedestal" in d and d["pedestal"] is not None and d["pedestal"] is not "":
        path = load_path(d["pedestal"], directory=directory)
        with open(path) as infile:
            imageset.external_lookup.pedestal.filename = path
            imageset.external_lookup.pedestal.data = ImageDouble(pickle.load(infile))

    # Get the existing models as dictionaries
    beam_dict = imageset.get_beam(0).to_dict()
    detector_dict = imageset.get_detector(0).to_dict()

    # Set models
    imageset.set_beam(BeamFactory.from_dict(d.get("beam"), beam_dict))
    imageset.set_detector(DetectorFactory.from_dict(d.get("detector"), detector_dict))

    # Return the imageset
    return imageset
def test_pickle_imageset(centroid_files):
    from dxtbx.imageset import ImageSetFactory

    sweep = ImageSetFactory.new(centroid_files)[0]

    # Read the 5th image
    assert sweep[4]

    # Pickle, then unpickle
    pickled_sweep = pickle.dumps(sweep)
    sweep2 = pickle.loads(pickled_sweep)

    assert sweep.get_template() == sweep2.get_template()
    assert sweep.get_array_range() == sweep2.get_array_range()
    assert sweep.get_beam() == sweep2.get_beam()
    assert sweep.get_goniometer() == sweep2.get_goniometer()
    assert sweep.get_scan() == sweep2.get_scan()
    assert sweep.paths() == sweep2.paths()
    assert sweep == sweep2

    # Check auxiliary methods after pickling
    sweep3 = sweep2[0:4]
    sweep4 = sweep3[0:2]
    sweep4.get_detectorbase(0)
    sweep4[0]
Example #13
0
def test_to_xds_multi_panel_i23(dials_regression, tmpdir):
    tmpdir.chdir()
    file_name = os.path.join(dials_regression, "image_examples", "DLS_I23",
                             "germ_13KeV_0001.cbf")
    sequence = ImageSetFactory.new([file_name])[0]
    to_xds = xds.to_xds(sequence)
    s1 = to_xds.XDS_INP()
    for expected_substr in (
            """\
!
! SEGMENT 1
!
SEGMENT= 1 2463 1 195
DIRECTION_OF_SEGMENT_X-AXIS= 1.00000 0.00000 0.00000
DIRECTION_OF_SEGMENT_Y-AXIS= 0.00000 -0.14347 0.98966
SEGMENT_DISTANCE= 250.000
SEGMENT_ORGX= 1075.00 SEGMENT_ORGY= 97.67""",
            """\
!
! SEGMENT 24
!
SEGMENT= 1 2463 4877 5071
DIRECTION_OF_SEGMENT_X-AXIS= 1.00000 0.00000 0.00000
DIRECTION_OF_SEGMENT_Y-AXIS= 0.00000 -0.06390 -0.99796
SEGMENT_DISTANCE= 250.000
SEGMENT_ORGX= 1075.00 SEGMENT_ORGY= 4973.67""",
    ):
        assert expected_substr in s1
Example #14
0
def test_make_sequence_with_percent_character(dials_data, tmp_path):
    images = [
        dials_data("centroid_test_data").join(f"centroid_{i:04}.cbf")
        for i in range(1, 10)
    ]
    directory = tmp_path / "test%"
    directory.mkdir()
    try:
        for image in images:
            try:
                (directory / image.basename).symlink_to(image)
            except OSError:
                shutil.copy(image, directory)

        template = str(directory / "centroid_####.cbf")
        sequence = ImageSetFactory.make_sequence(template, range(1, 10))
        assert len(sequence) == 9

        sequences = ImageSetFactory.new(
            [str(directory / image.basename) for image in images])
        assert len(sequences) == 1
        assert len(sequences[0]) == 9

        sequences = ImageSetFactory.from_template(template)
        assert len(sequences) == 1
        assert len(sequences[0]) == 9

    finally:  # clean up potentially copied files after running test
        for image in images:
            try:
                (directory / image.basename).unlink()
            except FileNotFoundError:
                pass
Example #15
0
def basic_imageset_from_dict(d):
    ''' Construct an ImageSet class from the dictionary.'''
    from dxtbx.model import BeamFactory, DetectorFactory
    from dxtbx.imageset import ImageSetFactory
    from dxtbx.serialize.filename import load_path

    # Get the filename list and create the imageset
    filenames = map(lambda p: load_path(p), map(str, d['filenames']))
    imageset = ImageSetFactory.new(filenames)[0]

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

    # Get the existing models as dictionaries
    beam_dict = imageset.get_beam().to_dict()
    detector_dict = imageset.get_detector().to_dict()

    # Set models
    imageset.set_beam(BeamFactory.from_dict(d.get('beam'), beam_dict))
    imageset.set_detector(
        DetectorFactory.from_dict(d.get('detector'), detector_dict))

    # Return the imageset
    return imageset
Example #16
0
def print_sequence(list_of_images):

    sequences = ImageSetFactory.new(list_of_images)

    for sequence in sequences:
        print(sequence.get_detector())
        print(sequence.get_beam())
        print(sequence.get_goniometer())
        print(sequence.get_scan())

        # compute the beam centre... in mm... w.r.t. fast, slow axis

        print("Derived quantities:")

        d = sequence.get_detector()[0]
        b = sequence.get_beam()

        o = matrix.col(d.get_origin())
        f = matrix.col(d.get_fast_axis())
        s = matrix.col(d.get_slow_axis())
        s0 = matrix.col(b.get_sample_to_source_direction())

        beam_offset = o - o.dot(s0) * s0
        print(
            "    beam centre (mm, fast, slow): %.2f %.2f"
            % (-beam_offset.dot(f), -beam_offset.dot(s))
        )
def exercise_multi_axis_goniometer():
    import libtbx.load_env
    from libtbx.test_utils import approx_equal
    import os

    if not libtbx.env.has_module("dials"):
        print "Skipping tstFormatCBFFull.py: dials not present"
        return
    if not libtbx.env.has_module("dials_regression"):
        print "Skipping tstFormatCBFFull.py: dials_regression not present"
        return

    data_dir = libtbx.env.find_in_repositories(
        relative_path="dials_regression/image_examples/dials-190",
        test=os.path.isdir)

    from dxtbx.imageset import ImageSetFactory
    imgset = ImageSetFactory.new(os.path.join(data_dir,
                                              "whatev1_01_00001.cbf"))[0]
    gonio = imgset.get_goniometer(0)
    assert approx_equal(gonio.get_fixed_rotation(),
                        (1, 0, 0, 0, 1, 0, 0, 0, 1))
    assert approx_equal(gonio.get_setting_rotation(),
                        (1, 0, 0, 0, 1, 0, 0, 0, 1))

    from dxtbx.imageset import ImageSetFactory
    imgset = ImageSetFactory.new(os.path.join(data_dir,
                                              "whatev1_02_00001.cbf"))[0]
    gonio = imgset.get_goniometer(0)
    assert approx_equal(gonio.get_fixed_rotation(),
                        (1, 0, 0, 0, 1, 0, 0, 0, 1))
    assert approx_equal(gonio.get_setting_rotation(),
                        (1, 0, 0, 0, -0.5, 0.866, 0.0, -0.866, -0.5),
                        eps=1e-4)

    from dxtbx.imageset import ImageSetFactory
    imgset = ImageSetFactory.new(os.path.join(data_dir,
                                              "whatev1_03_00001.cbf"))[0]
    gonio = imgset.get_goniometer(0)
    assert approx_equal(gonio.get_fixed_rotation(),
                        (1, 0, 0, 0, 1, 0, 0, 0, 1))
    assert approx_equal(gonio.get_setting_rotation(),
                        (1, 0, 0, 0, 0.5, 0.866, 0.0, -0.866, 0.5),
                        eps=1e-4)
Example #18
0
def run(file_names):
    if len(file_names) == 1 and file_names[0].endswith("json"):
        datablock = load.datablock(file_names[0])
        assert len(datablock) == 1
        sequence = datablock[0].extract_sequences()[0]
    else:
        sequence = ImageSetFactory.new(file_names)[0]
    detector = sequence.get_detector()
    beam = sequence.get_beam()
    print(detector.get_ray_intersection(beam.get_s0())[1])
Example #19
0
  def run(self):
    from dxtbx.imageset import ImageSetFactory, ImageSweep

    filenames = self.get_file_list()

    sweep = ImageSetFactory.new(filenames)

    assert(isinstance(sweep[0], ImageSweep) == True)

    print 'OK'
Example #20
0
def test_still(dials_regression):
    data_dir = os.path.join(dials_regression, "image_examples", "DLS_I04")

    imgset = ImageSetFactory.new(os.path.join(data_dir, "grid_full_cbf_0005.cbf"))[0]
    if imgset.get_scan(0):
        scan = imgset.get_scan(0)
        assert approx_equal(scan.get_image_oscillation(0), (30.0, 0.0), eps=1e-5)
    beam = imgset.get_beam(0)
    beam.get_s0()
    assert approx_equal(beam.get_s0(), (-0.0, -0.0, -1.0209290454313424))
Example #21
0
def run(file_names):
  if len(file_names) == 1 and file_names[0].endswith('json'):
    from dxtbx.serialize import load
    datablock = load.datablock(file_names[0])
    assert(len(datablock) == 1)
    sweep = datablock[0].extract_sweeps()[0]
  else:
    from dxtbx.imageset import ImageSetFactory
    sweep = ImageSetFactory.new(file_names)[0]
  xsx = xds.to_xds(sweep)
  xsx.XDS_INP()
def run(file_names):
  if len(file_names) == 1 and file_names[0].endswith('json'):
    from dxtbx.serialize import load
    datablock = load.datablock(file_names[0])
    assert(len(datablock) == 1)
    sweep = datablock[0].extract_sweeps()[0]
  else:
    from dxtbx.imageset import ImageSetFactory
    sweep = ImageSetFactory.new(file_names)[0]
  detector = sweep.get_detector()
  beam = sweep.get_beam()
  print detector.get_ray_intersection(beam.get_s0())[1]
Example #23
0
def run(file_names):
    if len(file_names) == 1 and file_names[0].endswith('json'):
        from dxtbx.serialize import load
        datablock = load.datablock(file_names[0])
        assert (len(datablock) == 1)
        sweep = datablock[0].extract_sweeps()[0]
    else:
        from dxtbx.imageset import ImageSetFactory
        sweep = ImageSetFactory.new(file_names)[0]
    detector = sweep.get_detector()
    beam = sweep.get_beam()
    print detector.get_ray_intersection(beam.get_s0())[1]
Example #24
0
def test_multi_axis_goniometer(dials_regression):
    from libtbx.test_utils import approx_equal

    data_dir = os.path.join(dials_regression, "image_examples", "dials-190")

    from dxtbx.imageset import ImageSetFactory

    imgset = ImageSetFactory.new(os.path.join(data_dir,
                                              "whatev1_01_00001.cbf"))[0]
    gonio = imgset.get_goniometer(0)
    assert approx_equal(gonio.get_fixed_rotation(),
                        (1, 0, 0, 0, 1, 0, 0, 0, 1))
    assert approx_equal(gonio.get_setting_rotation(),
                        (1, 0, 0, 0, 1, 0, 0, 0, 1))

    from dxtbx.imageset import ImageSetFactory

    imgset = ImageSetFactory.new(os.path.join(data_dir,
                                              "whatev1_02_00001.cbf"))[0]
    gonio = imgset.get_goniometer(0)
    assert approx_equal(gonio.get_fixed_rotation(),
                        (1, 0, 0, 0, 1, 0, 0, 0, 1))
    assert approx_equal(
        gonio.get_setting_rotation(),
        (1, 0, 0, 0, -0.5, 0.866, 0.0, -0.866, -0.5),
        eps=1e-4,
    )

    from dxtbx.imageset import ImageSetFactory

    imgset = ImageSetFactory.new(os.path.join(data_dir,
                                              "whatev1_03_00001.cbf"))[0]
    gonio = imgset.get_goniometer(0)
    assert approx_equal(gonio.get_fixed_rotation(),
                        (1, 0, 0, 0, 1, 0, 0, 0, 1))
    assert approx_equal(
        gonio.get_setting_rotation(),
        (1, 0, 0, 0, 0.5, 0.866, 0.0, -0.866, 0.5),
        eps=1e-4,
    )
Example #25
0
  def __init__(self):
    import os.path
    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)))

    from dxtbx.imageset import ImageSetFactory, ImageSweep
    self.sweep = ImageSetFactory.new(filenames)[0]
Example #26
0
def test_to_xds_multi_panel_i23(dials_regression, tmpdir, mocker):
    tmpdir.chdir()
    file_name = os.path.join(dials_regression, "image_examples", "DLS_I23",
                             "germ_13KeV_0001.cbf")
    sequence = ImageSetFactory.new([file_name])[0]
    to_xds = xds.to_xds(sequence)
    s1 = to_xds.XDS_INP()
    for expected_substr in (
            """\
!
! SEGMENT 1
!
SEGMENT= 1 2463 1 195
DIRECTION_OF_SEGMENT_X-AXIS= 1.00000 0.00000 0.00000
DIRECTION_OF_SEGMENT_Y-AXIS= 0.00000 -0.14347 0.98966
SEGMENT_DISTANCE= 250.000
SEGMENT_ORGX= 1075.00 SEGMENT_ORGY= 97.67""",
            """\
!
! SEGMENT 24
!
SEGMENT= 1 2463 4877 5071
DIRECTION_OF_SEGMENT_X-AXIS= 1.00000 0.00000 0.00000
DIRECTION_OF_SEGMENT_Y-AXIS= 0.00000 -0.06390 -0.99796
SEGMENT_DISTANCE= 250.000
SEGMENT_ORGX= 1075.00 SEGMENT_ORGY= 4973.67""",
    ):
        assert expected_substr in s1
    assert "UNTRUSTED_RECTANGLE" not in s1

    # Fool the format class into masking out a couple of bad modules
    mocked_timestamp = mocker.patch(
        "dxtbx.format.FormatCBFMiniPilatusDLS12M.get_pilatus_timestamp")
    mocked_timestamp.return_value = 1574857526.34
    sequence = ImageSetFactory.new([file_name])[0]
    to_xds = xds.to_xds(sequence)
    s = to_xds.XDS_INP()
    assert "UNTRUSTED_RECTANGLE= 0 488 3604 3800" in s
    assert "UNTRUSTED_RECTANGLE= 1976 2464 3604 3800" in s
Example #27
0
def test_to_xds_from_json(dials_data, expected_output, tmpdir):
    file_names = dials_data("centroid_test_data").listdir("centroid_*.cbf")

    # now test reading from a json file
    sequence = ImageSetFactory.new([f.strpath for f in file_names])[0]
    with tmpdir.join("sequence.json").open("wb") as fh:
        dump.imageset(sequence, fh)
    result = procrunner.run(["dxtbx.to_xds", "sequence.json"],
                            working_directory=tmpdir)
    assert not result.returncode and not result.stderr

    # allow extra lines to have been added (these may be comments)
    for record in expected_output.split("\n"):
        assert record.strip().encode("latin-1") in result.stdout, record
Example #28
0
def test_experiment_consistent(dials_regression):
    # Create a sequence
    sequence_filenames = os.path.join(dials_regression, "centroid_test_data",
                                      "centroid*.cbf")
    sequence = ImageSetFactory.new(sorted(glob(sequence_filenames)))[0]

    # Create experiment with sequence and good scan
    e = Experiment(imageset=sequence, scan=sequence.get_scan())
    assert e.is_consistent()

    # Create experiment with sequence and defective scan
    scan = sequence.get_scan()
    scan.set_image_range((1, 1))
    e = Experiment(imageset=sequence, scan=scan)
Example #29
0
def exercise_to_xds():
    if not libtbx.env.has_module("dials"):
        print "Skipping test: dials not present"
        return
    if not libtbx.env.has_module("dials_regression"):
        print "Skipping exercise_to_xds(): dials_regression not present"
        return

    data_dir = libtbx.env.find_in_repositories(
        relative_path="dials_regression/centroid_test_data",
        test=os.path.isdir)
    template = os.path.join(data_dir, "centroid_00*.cbf")
    file_names = glob.glob(template)
    sweep = ImageSetFactory.new(file_names)[0]
    to_xds = xds.to_xds(sweep)
    s1 = StringIO()
    to_xds.XDS_INP(out=s1)
    s2 = StringIO()
    real_space_a = (-5.327642, -39.034747, -4.988286)
    real_space_b = (-35.253495, 7.596265, -22.127661)
    real_space_c = (-22.673623, -1.486119, 35.793463)
    to_xds.xparm_xds(real_space_a,
                     real_space_b,
                     real_space_c,
                     space_group=1,
                     out=s2)
    # run coordinate frame converter on xparm.xds as a sanity check
    f = open_tmp_file(suffix="XPARM.XDS", mode="wb")
    s2.seek(0)
    f.writelines(s2.readlines())
    f.close()
    from rstbx.cftbx import coordinate_frame_helpers
    converter = coordinate_frame_helpers.import_xds_xparm(f.name)
    scan = sweep.get_scan()
    detector = sweep.get_detector()
    goniometer = sweep.get_goniometer()
    beam = sweep.get_beam()
    assert approx_equal(real_space_a, converter.get_real_space_a())
    assert approx_equal(real_space_b, converter.get_real_space_b())
    assert approx_equal(real_space_c, converter.get_real_space_c())
    assert approx_equal(goniometer.get_rotation_axis(),
                        converter.get_rotation_axis())
    assert approx_equal(beam.get_direction(),
                        converter.get_sample_to_source().elems)
    assert approx_equal(detector[0].get_fast_axis(),
                        converter.get_detector_fast())
    assert approx_equal(detector[0].get_slow_axis(),
                        converter.get_detector_slow())
    assert approx_equal(detector[0].get_origin(),
                        converter.get_detector_origin())
Example #30
0
  def run(self):
    from dxtbx.imageset import ImageSetFactory, ImageSweep
    from os.path import join

    filenames = self.get_file_list()

    sweep = ImageSetFactory.new(filenames)

    assert(isinstance(sweep[0], ImageSweep) == True)

    print 'OK'

    template = join(dials_regression, "centroid_test_data", "centroid_####.cbf")
    image_range = (3, 6)

    sweep = ImageSetFactory.from_template(template, image_range)

    assert(isinstance(sweep[0], ImageSweep) == True)
    assert len(sweep[0]) == 4
    assert sweep[0].paths()[0].endswith("3.cbf")
    assert sweep[0].paths()[-1].endswith("6.cbf")

    print 'OK'

    imageset = ImageSetFactory.make_imageset(filenames)
    assert len(imageset) == 9

    print 'OK'

    imageset = ImageSetFactory.make_imageset(
      filenames,
      check_format=False)
    assert len(imageset) == 9

    print 'OK'

    sweep = ImageSetFactory.make_sweep(
      template,
      list(range(1, 9+1)))
    assert len(sweep) == 9

    print 'OK'

    sweep = ImageSetFactory.make_sweep(
      template,
      list(range(3, 6+1)))
    assert len(sweep) == 4

    print 'OK'
Example #31
0
def test_still(dials_regression):
    from libtbx.test_utils import approx_equal

    data_dir = os.path.join(dials_regression, 'image_examples', 'DLS_I04')

    from dxtbx.imageset import ImageSetFactory
    imgset = ImageSetFactory.new(
        os.path.join(data_dir, "grid_full_cbf_0005.cbf"))[0]
    if imgset.get_scan(0):
        scan = imgset.get_scan(0)
        assert approx_equal(scan.get_image_oscillation(0), (30.0, 0.0),
                            eps=1e-5)
    beam = imgset.get_beam(0)
    beam.get_s0()
    assert approx_equal(beam.get_s0(), (-0.0, -0.0, -1.0209290454313424))
Example #32
0
def test_experiment_consistent(dials_data):
    # Create a sequence
    sequence_filenames = dials_data("centroid_test_data").listdir(
        "centroid*.cbf")
    sequence = ImageSetFactory.new(
        sorted(f.strpath for f in sequence_filenames))[0]

    # Create experiment with sequence and good scan
    e = Experiment(imageset=sequence, scan=sequence.get_scan())
    assert e.is_consistent()

    # Create experiment with sequence and defective scan
    scan = sequence.get_scan()
    scan.set_image_range((1, 1))
    e = Experiment(imageset=sequence, scan=scan)
Example #33
0
  def set_frame_wedge(self, start, end, apply_offset = True):
    '''Set the allowed range of images for processing.'''

    # XXX RJG Better to pass slice of imageset here?

    if apply_offset:
      start = start - self._fp_offset
      end = end - self._fp_offset

    self._fp_wedge = start, end

    if self._fp_matching_images:
      images = []
      for j in self._fp_matching_images:
        if j < start or j > end:
          continue
        images.append(j)
      self._fp_matching_images = images

      ## reload the header information as well - this will be
      ## for the old wedge...# read the image header
      ## XXX this shouldn't be needed

      from dxtbx.imageset import ImageSetFactory
      imageset = ImageSetFactory.new(self.get_image_name(start))[0]

      # print this to the debug channel
      Debug.write('Latest header information for image %d:' % start)
      print >> Debug, imageset.get_detector()
      print >> Debug, imageset.get_scan()
      print >> Debug, imageset.get_beam()
      print >> Debug, imageset.get_goniometer()

      # populate wavelength, beam etc from this

      if self._fp_wavelength_prov is None or \
                      self._fp_wavelength_prov == 'header':
        self._fp_wavelength_prov = 'header'

      if self._fp_distance_prov is None or \
                      self._fp_distance_prov == 'header':
        self._fp_distance_prov = 'header'

      if self._fp_beam_prov is None or \
            self._fp_beam_prov == 'header':
        self._fp_beam_prov = 'header'

    return
Example #34
0
def read_sequence(list_of_images):

    sequences = ImageSetFactory.new(list_of_images)

    for sequence in sequences:
        print(sequence.get_detector())
        print(sequence.get_scan())

        indices = sequence.indices()

        t0 = time.time()
        for i in indices:
            sequence.get_raw_data(i)
        t1 = time.time()

        print("Reading %d frames took %.2fs" % (len(indices), t1 - t0))
def test_experiment_consistent(dials_regression):
  from dxtbx.imageset import ImageSetFactory
  from dxtbx.model import Scan

  # Create a sweep
  sweep_filenames = os.path.join(dials_regression, 'centroid_test_data', 'centroid*.cbf')
  sweep = ImageSetFactory.new(sorted(glob(sweep_filenames)))[0]

  # Create experiment with sweep and good scan
  e = Experiment(imageset=sweep, scan=sweep.get_scan())
  assert e.is_consistent()

  # Create experiment with sweep and defective scan
  scan = sweep.get_scan()
  scan.set_image_range((1, 1))
  e = Experiment(imageset=sweep, scan=scan)
Example #36
0
def read_sequence(images: List[str]):

    sequences = ImageSetFactory.new(images)

    for sequence in sequences:
        print(sequence.get_detector())
        print(sequence.get_scan())

        indices = sequence.indices()

        t0 = time.time()
        for i in indices:
            sequence.get_raw_data(i)
        t1 = time.time()

        print(f"Reading {len(indices)} frames took {t1-t0:.2f}s")
Example #37
0
    def set_frame_wedge(self, start, end, apply_offset=True):
        '''Set the allowed range of images for processing.'''

        # XXX RJG Better to pass slice of imageset here?

        if apply_offset:
            start = start - self._fp_offset
            end = end - self._fp_offset

        self._fp_wedge = start, end

        if self._fp_matching_images:
            images = []
            for j in self._fp_matching_images:
                if j < start or j > end:
                    continue
                images.append(j)
            self._fp_matching_images = images

            ## reload the header information as well - this will be
            ## for the old wedge...# read the image header
            ## XXX this shouldn't be needed

            from dxtbx.imageset import ImageSetFactory
            imageset = ImageSetFactory.new(self.get_image_name(start))[0]

            # print this to the debug channel
            Debug.write('Latest header information for image %d:' % start)
            Debug.write(imageset.get_detector())
            Debug.write(imageset.get_scan())
            Debug.write(imageset.get_beam())
            Debug.write(imageset.get_goniometer())

            # populate wavelength, beam etc from this

            if self._fp_wavelength_prov is None or \
                            self._fp_wavelength_prov == 'header':
                self._fp_wavelength_prov = 'header'

            if self._fp_distance_prov is None or \
                            self._fp_distance_prov == 'header':
                self._fp_distance_prov = 'header'

            if self._fp_beam_prov is None or \
                  self._fp_beam_prov == 'header':
                self._fp_beam_prov = 'header'
Example #38
0
def exercise_to_xds():
  if not libtbx.env.has_module("dials_regression"):
    print "Skipping exercise_to_xds(): dials_regression not present"
    return

  data_dir = libtbx.env.find_in_repositories(
    relative_path="dials_regression/centroid_test_data",
    test=os.path.isdir)
  template = os.path.join(data_dir, "centroid_00*.cbf")
  file_names = glob.glob(template)
  sweep = ImageSetFactory.new(file_names)[0]
  to_xds = xds.to_xds(sweep)
  s1 = StringIO()
  to_xds.XDS_INP(out=s1)
  s2 = StringIO()
  real_space_a = (-5.327642, -39.034747, -4.988286)
  real_space_b = (-35.253495, 7.596265, -22.127661)
  real_space_c = (-22.673623, -1.486119, 35.793463)
  to_xds.xparm_xds(real_space_a, real_space_b, real_space_c, space_group=1, out=s2)
  # run coordinate frame converter on xparm.xds as a sanity check
  f = open_tmp_file(suffix="XPARM.XDS", mode="wb")
  s2.seek(0)
  f.writelines(s2.readlines())
  f.close()
  from rstbx.cftbx import coordinate_frame_helpers
  converter = coordinate_frame_helpers.import_xds_xparm(f.name)
  scan = sweep.get_scan()
  detector = sweep.get_detector()
  goniometer = sweep.get_goniometer()
  beam = sweep.get_beam()
  assert approx_equal(real_space_a, converter.get_real_space_a())
  assert approx_equal(real_space_b, converter.get_real_space_b())
  assert approx_equal(real_space_c, converter.get_real_space_c())
  assert approx_equal(goniometer.get_rotation_axis(),
                      converter.get_rotation_axis())
  assert approx_equal(
    beam.get_direction(), converter.get_sample_to_source().elems)
  assert approx_equal(detector[0].get_fast_axis(), converter.get_detector_fast())
  assert approx_equal(detector[0].get_slow_axis(), converter.get_detector_slow())
  assert approx_equal(detector[0].get_origin(), converter.get_detector_origin())
Example #39
0
  def tst_cspad_hierarchy(self):
    from dxtbx.serialize import dump, load
    from dxtbx.imageset import ImageSetFactory
    import libtbx.load_env
    import os
    from glob import glob
    try:
      path = libtbx.env.dist_path('dials_regression')
    except Exception:
      print "No dials_regression directory found"
      return

    # Get the imageset
    filename = os.path.join(path, "spotfinding_test_data", "idx*.cbf")
    imageset = ImageSetFactory.new(glob(filename))
    assert(len(imageset) == 1)
    imageset = imageset[0]

    # Dump and reload
    from uuid import uuid4
    filename = '%s.json' % uuid4().hex
    dump.imageset(imageset, filename)
    imageset2 = load.imageset(filename)

    # Check they're are the same
    assert(imageset2.get_beam() == imageset.get_beam())
    d1 = imageset.get_detector()
    d2 = imageset2.get_detector()
    assert(len(d1) == len(d2))
    for i, (p1, p2) in enumerate(zip(d1, d2)):
      assert(p1 == p2)
    assert(imageset2.get_detector() == imageset.get_detector())
    assert(imageset2 == imageset)

    # Test passed
    print 'OK'
  from glob import glob
  from dxtbx.imageset import ImageSetFactory

  # Check dials_regression is configured
  try:
    path = libtbx.env.dist_path('dials_regression')
  except KeyError, e:
    print 'FAIL: dials_regression not configured'
    raise

  # Find the filenames
  template = os.path.join(path, 'centroid_test_data', 'centroid_*.cbf')
  filenames = glob(template)

  # Create the sweep
  sweep = ImageSetFactory.new(filenames)
  assert(len(sweep) == 1)
  sweep = sweep[0]

  # Get the models
  beam = sweep.get_beam()
  detector = sweep.get_detector()
  gonio = sweep.get_goniometer()
  scan = sweep.get_scan()
  print beam
  print detector
  print gonio
  print scan

  print "sweep: ", sweep
  print "sweep indices: ", sweep.indices()
Example #41
0
def run(argv=None):
  if (argv is None):
    argv = sys.argv

  # XXX Could/should handle effective metrology the same way, except
  # it does not have a single scope.
  work_phil = phil.process_command_line(
    args=argv[1:],
    master_string=master_str + phil_str + additional_spotfinder_phil_defs)
  work_params = work_phil.work.extract()

  app = wx.App(0)
  wx.SystemOptions.SetOptionInt("osx.openfiledialog.always-show-types", 1)
  frame = XrayFrame(None, -1, "X-ray image display", size=(800,720))
  frame.Show()

  # show settings panel
  frame.OnShowSettings(None)
  frame.settings_frame.panel.center_ctrl.SetValue(
    work_params.beam_center)
  frame.settings_frame.panel.integ_ctrl.SetValue(
    work_params.show_integration_results)
  frame.settings_frame.panel.spots_ctrl.SetValue(
    work_params.show_spotfinder_results)
  frame.settings.show_effective_tiling = work_params.show_effective_tiling
  frame.settings_frame.panel.collect_values()

  if (work_params.effective_metrology is not None):
    from xfel.cftbx.detector.metrology import \
      master_phil, metrology_as_transformation_matrices

    stream = open(work_params.effective_metrology)
    metrology_phil = master_phil.fetch(sources=[phil.parse(stream.read())])
    stream.close()
    frame.metrology_matrices = metrology_as_transformation_matrices(
      metrology_phil.extract())

  # Update initial settings with values from the command line.  Needs
  # to be done before image is loaded (but after the frame is
  # instantiated).
  frame.params = work_params
  frame.init_pyslip()
  frame.pyslip.tiles.user_requests_antialiasing = work_params.anti_aliasing
  frame.pyslip.tiles.show_untrusted = frame.params.show_untrusted

  paths = work_phil.remaining_args
  if (len(paths) == 1 and os.path.basename(paths[0]) == "DISTL_pickle"):
    assert os.path.isfile(paths[0])
    frame.load_distl_output(paths[0])
  elif (len(paths) > 0):
    frame.CHOOSER_SIZE = 1500

    from dxtbx.imageset import ImageSetFactory
    from rstbx.slip_viewer.frame import chooser_wrapper
    sets = ImageSetFactory.new(paths)

    for imgset in sets:
      for idx in imgset.indices():
        frame.add_file_name_or_data(chooser_wrapper(imgset, idx))
    idx = sets[0].indices()[0]
    frame.load_image(chooser_wrapper(sets[0],idx))

  app.MainLoop()

  return 0
Example #42
0
def exercise_to_xds():
  if not libtbx.env.has_module("dials_regression"):
    print "Skipping exercise_to_xds(): dials_regression not present"
    return

  data_dir = libtbx.env.find_in_repositories(
    relative_path="dials_regression/centroid_test_data",
    test=os.path.isdir)
  template = os.path.join(data_dir, "centroid_*.cbf")
  file_names = glob.glob(template)

  expected_output = """\
DETECTOR=PILATUS MINIMUM_VALID_PIXEL_VALUE=0 OVERLOAD=495976
SENSOR_THICKNESS= 0.320
DIRECTION_OF_DETECTOR_X-AXIS= 1.00000 0.00000 0.00000
DIRECTION_OF_DETECTOR_Y-AXIS= 0.00000 1.00000 0.00000
NX=2463 NY=2527 QX=0.1720 QY=0.1720
DETECTOR_DISTANCE= 190.180
ORGX= 1235.84 ORGY= 1279.58
ROTATION_AXIS= 1.00000 0.00000 0.00000
STARTING_ANGLE= 0.000
OSCILLATION_RANGE= 0.200
X-RAY_WAVELENGTH= 0.97950
INCIDENT_BEAM_DIRECTION= -0.000 -0.000 1.021
FRACTION_OF_POLARIZATION= 0.999
POLARIZATION_PLANE_NORMAL= 0.000 1.000 0.000
NAME_TEMPLATE_OF_DATA_FRAMES= %s
TRUSTED_REGION= 0.0 1.41
UNTRUSTED_RECTANGLE= 487 495 0 2528
UNTRUSTED_RECTANGLE= 981 989 0 2528
UNTRUSTED_RECTANGLE= 1475 1483 0 2528
UNTRUSTED_RECTANGLE= 1969 1977 0 2528
UNTRUSTED_RECTANGLE= 0 2464 195 213
UNTRUSTED_RECTANGLE= 0 2464 407 425
UNTRUSTED_RECTANGLE= 0 2464 619 637
UNTRUSTED_RECTANGLE= 0 2464 831 849
UNTRUSTED_RECTANGLE= 0 2464 1043 1061
UNTRUSTED_RECTANGLE= 0 2464 1255 1273
UNTRUSTED_RECTANGLE= 0 2464 1467 1485
UNTRUSTED_RECTANGLE= 0 2464 1679 1697
UNTRUSTED_RECTANGLE= 0 2464 1891 1909
UNTRUSTED_RECTANGLE= 0 2464 2103 2121
UNTRUSTED_RECTANGLE= 0 2464 2315 2333
DATA_RANGE= 1 9
JOB=XYCORR INIT COLSPOT IDXREF DEFPIX INTEGRATE CORRECT\
""" %(template.replace("*", "????"))

  cmd = " ".join(["dxtbx.to_xds"] + file_names)
  result = easy_run.fully_buffered(cmd)
  # allow extra lines to have been added (these may be comments)
  for record in expected_output.split('\n'):
    assert record.strip() in "\n".join(result.stdout_lines), record

  # now test reading from a json file
  sweep = ImageSetFactory.new(file_names)[0]
  f = open_tmp_file(suffix="sweep.json", mode="wb")
  dump.imageset(sweep, f)
  f.close()
  cmd = " ".join(["dxtbx.to_xds", f.name])
  result = easy_run.fully_buffered(cmd)

  # allow extra lines to have been added (these may be comments)
  for record in expected_output.split('\n'):
    assert record.strip() in "\n".join(result.stdout_lines), record
Example #43
0
def factory(list_of_images):
  from dxtbx.imageset import ImageSetFactory
  sweeps = ImageSetFactory.new(list_of_images)
  assert(len(sweeps) == 1)
  return sweeps[0]
Example #44
0
  from optparse import OptionParser
  from dxtbx.serialize import dump
  from dxtbx.imageset import ImageSetFactory

  # Specify the command line options
  usage  = "usage: %prog [options] /path/to/image/files.ext"
  parser = OptionParser(usage)

  # Add a verbose option (False by default)
  parser.add_option('-o', '--output-file',
                    dest='output_file', type="string",
                    default="imageset.json",
                    help='Enter a destination filename for serialization')

  # Parse the arguments
  (options, args) = parser.parse_args()

  # Print help if no arguments specified, otherwise call spot prediction
  if len(args) == 0:
    print parser.print_help()

  else:
    imagesets = ImageSetFactory.new(args)
    if len(imagesets) == 0:
      print "Error: no imagesets to serialize."
    elif len(imagesets) > 1:
      print "Error: more than 1 imageset has been specified"
    else:
      dump.imageset(imagesets[0], options.output_file)
      print "Serialized imageset to {0}".format(options.output_file)