Ejemplo n.º 1
0
def work_helper_image_files():
  '''Test the static methods in scan_helper_image_files.'''

  helper = scan_helper_image_files()

  import dxtbx
  directory = os.path.join(os.path.split(dxtbx.__file__)[0], 'tests')

  template = 'image_###.dat'

  assert(len(scan_helper_image_files.template_directory_to_indices(
      template, directory)) == 20)

  assert(scan_helper_image_files.template_directory_index_to_image(
      template, directory, 1) == os.path.join(directory, 'image_001.dat'))

  assert(scan_helper_image_files.template_index_to_image(
      template, 1) == 'image_001.dat')

  assert(scan_helper_image_files.image_to_template_directory(
      os.path.join(directory, 'image_001.dat')) == (template, directory))

  assert(scan_helper_image_files.image_to_index('image_001.dat') == 1)

  assert(scan_helper_image_files.image_to_template(
      'image_001.dat') == 'image_###.dat')

  assert(scan_helper_image_files.image_to_index("image_6.8kev_1_001.cbf") == 1)

  return
Ejemplo n.º 2
0
def work_helper_image_files():
  '''Test the static methods in scan_helper_image_files.'''

  helper = scan_helper_image_files()

  import dxtbx
  directory = os.path.join(os.path.split(dxtbx.__file__)[0], 'tests')

  template = 'image_###.dat'

  assert(len(scan_helper_image_files.template_directory_to_indices(
      template, directory)) == 20)

  assert(scan_helper_image_files.template_directory_index_to_image(
      template, directory, 1) == os.path.join(directory, 'image_001.dat'))

  assert(scan_helper_image_files.template_index_to_image(
      template, 1) == 'image_001.dat')

  assert(scan_helper_image_files.image_to_template_directory(
      os.path.join(directory, 'image_001.dat')) == (template, directory))

  assert(scan_helper_image_files.image_to_index('image_001.dat') == 1)

  assert(scan_helper_image_files.image_to_template(
      'image_001.dat') == 'image_###.dat')

  assert(scan_helper_image_files.image_to_index("image_6.8kev_1_001.cbf") == 1)

  return
Ejemplo n.º 3
0
def test_helper_image_files():
    """Test the static methods in scan_helper_image_files."""

    helper = scan_helper_image_files()

    import dxtbx

    directory = os.path.join(os.path.split(dxtbx.__file__)[0], "tests")

    template = "image_###.dat"

    assert (len(
        scan_helper_image_files.template_directory_to_indices(
            template, directory)) == 20)

    assert scan_helper_image_files.template_directory_index_to_image(
        template, directory, 1) == os.path.join(directory, "image_001.dat")

    assert (scan_helper_image_files.template_index_to_image(
        template, 1) == "image_001.dat")

    assert scan_helper_image_files.image_to_template_directory(
        os.path.join(directory, "image_001.dat")) == (template, directory)

    assert scan_helper_image_files.image_to_index("image_001.dat") == 1

    assert scan_helper_image_files.image_to_template(
        "image_001.dat") == "image_###.dat"

    assert scan_helper_image_files.image_to_index(
        "image_6.8kev_1_001.cbf") == 1
Ejemplo n.º 4
0
def test_helper_image_files(image_test_dir):
    """Test the static methods in scan_helper_image_files."""
    assert scan_helper_image_files()

    template = "image_###.dat"

    assert (
        len(
            scan_helper_image_files.template_directory_to_indices(
                template, image_test_dir
            )
        )
        == 20
    )

    assert scan_helper_image_files.template_directory_index_to_image(
        template, image_test_dir, 1
    ) == os.path.join(image_test_dir, "image_001.dat")

    assert (
        scan_helper_image_files.template_index_to_image(template, 1) == "image_001.dat"
    )

    assert scan_helper_image_files.image_to_template_directory(
        os.path.join(image_test_dir, "image_001.dat")
    ) == (template, image_test_dir)

    assert scan_helper_image_files.image_to_index("image_001.dat") == 1

    assert scan_helper_image_files.image_to_template("image_001.dat") == "image_###.dat"

    assert scan_helper_image_files.image_to_index("image_6.8kev_1_001.cbf") == 1
Ejemplo n.º 5
0
def work_xScanFactory():
    '''Test out the ScanFactory.'''

    import dxtbx
    directory = os.path.join(os.path.split(dxtbx.__file__)[0], 'tests')

    template = 'image_###.dat'

    xscans = [
        ScanFactory.single(
            scan_helper_image_files.template_directory_index_to_image(
                template, directory, j + 1),
            scan_helper_image_formats.FORMAT_CBF, 1.0, 18 + 0.5 * j, 0.5, j)
        for j in range(20)
    ]

    xscans.reverse()

    try:
        print sum(xscans[1:], xscans[0])
        print 'I should not see this message'
    except RuntimeError:
        pass

    xscans.sort()

    sum(xscans[1:], xscans[0])

    a = ScanFactory.add(xscans[:10])
    b = ScanFactory.add(xscans[10:])

    a + b

    filename = scan_helper_image_files.template_directory_index_to_image(
        template, directory, 1)

    assert (len(ScanFactory.search(filename)) == 20)

    (a + b)[1:5]
    (a + b)[:10]

    cbf = os.path.join(directory, 'phi_scan_001.cbf')

    print 'OK'
Ejemplo n.º 6
0
def test_xScanFactory():
    """Test out the ScanFactory."""

    import dxtbx

    directory = os.path.join(os.path.split(dxtbx.__file__)[0], "tests")

    template = "image_###.dat"

    xscans = [
        ScanFactory.single(
            scan_helper_image_files.template_directory_index_to_image(
                template, directory, j + 1),
            scan_helper_image_formats.FORMAT_CBF,
            1.0,
            18 + 0.5 * j,
            0.5,
            j,
        ) for j in range(20)
    ]

    xscans.reverse()

    with pytest.raises(RuntimeError):
        print(sum(xscans[1:], xscans[0]))

    xscans.sort()

    sum(xscans[1:], xscans[0])

    a = ScanFactory.add(xscans[:10])
    b = ScanFactory.add(xscans[10:])

    a + b

    filename = scan_helper_image_files.template_directory_index_to_image(
        template, directory, 1)

    assert len(ScanFactory.search(filename)) == 20

    (a + b)[1:5]
    (a + b)[:10]
Ejemplo n.º 7
0
def test_xScanFactory(image_test_dir):
    """Test out the ScanFactory."""

    template = "image_###.dat"

    xscans = [
        ScanFactory.single_file(
            scan_helper_image_files.template_directory_index_to_image(
                template, image_test_dir, j + 1
            ),
            1.0,
            18 + 0.5 * j,
            0.5,
            j,
        )
        for j in range(20)
    ]

    xscans.reverse()

    with pytest.raises(RuntimeError):
        print(sum(xscans[1:], xscans[0]))

    xscans.sort()

    sum(xscans[1:], xscans[0])

    a = ScanFactory.add(xscans[:10])
    b = ScanFactory.add(xscans[10:])

    a + b

    filename = scan_helper_image_files.template_directory_index_to_image(
        template, image_test_dir, 1
    )

    assert len(ScanFactory.search(filename)) == 20

    (a + b)[1:5]
    (a + b)[:10]
Ejemplo n.º 8
0
def test_single_deprecation(image_test_dir):
    """Test out the ScanFactory."""

    with pytest.warns(DeprecationWarning):
        ScanFactory.single(
            scan_helper_image_files.template_directory_index_to_image(
                "image_###.dat", image_test_dir, 2
            ),
            None,
            1.0,
            18 + 0.5,
            0.5,
            1,
        )
Ejemplo n.º 9
0
  def search(filename):
    '''Get a list of files which appear to match the template and
    directory implied by the input filename. This could well be used
    to get a list of image headers to read and hence construct scans
    from.'''

    template, directory = \
              scan_helper_image_files.image_to_template_directory(filename)

    indices = scan_helper_image_files.template_directory_to_indices(
        template, directory)

    return [scan_helper_image_files.template_directory_index_to_image(
        template, directory, index) for index in indices]
Ejemplo n.º 10
0
def work_xScanFactory():
  '''Test out the ScanFactory.'''

  import dxtbx
  directory = os.path.join(os.path.split(dxtbx.__file__)[0], 'tests')

  template = 'image_###.dat'

  xscans = [ScanFactory.single(
      scan_helper_image_files.template_directory_index_to_image(
          template, directory, j + 1), scan_helper_image_formats.FORMAT_CBF,
      1.0, 18 + 0.5 * j, 0.5, j) for j in range(20)]

  xscans.reverse()

  try:
    print sum(xscans[1:], xscans[0])
    print 'I should not see this message'
  except RuntimeError, e:
    pass
Ejemplo n.º 11
0
def work_xscan_factory():
  '''Test out the scan_factory.'''

  import dxtbx
  directory = os.path.join(os.path.split(dxtbx.__file__)[0], 'tests')

  template = 'image_###.dat'

  xscans = [scan_factory.single(
      scan_helper_image_files.template_directory_index_to_image(
          template, directory, j + 1), scan_helper_image_formats.FORMAT_CBF,
      1.0, 18 + 0.5 * j, 0.5, j) for j in range(20)]

  xscans.reverse()

  try:
    print sum(xscans[1:], xscans[0])
    print 'I should not see this message'
  except RuntimeError, e:
    pass
Ejemplo n.º 12
0
  try:
    print sum(xscans[1:], xscans[0])
    print 'I should not see this message'
  except RuntimeError, e:
    pass

  xscans.sort()

  sum(xscans[1:], xscans[0])

  a = ScanFactory.add(xscans[:10])
  b = ScanFactory.add(xscans[10:])

  a + b

  filename = scan_helper_image_files.template_directory_index_to_image(
      template, directory, 1)

  assert(len(ScanFactory.search(filename)) == 20)

  (a + b)[1:5]
  (a + b)[:10]

  cbf = os.path.join(directory, 'phi_scan_001.cbf')

  print 'OK'

def test_scan():
  work_helper_image_files()
  work_helper_image_formats()
  work_xScanFactory()
Ejemplo n.º 13
0
  try:
    print sum(xscans[1:], xscans[0])
    print 'I should not see this message'
  except RuntimeError, e:
    pass

  xscans.sort()

  sum(xscans[1:], xscans[0])

  a = scan_factory.add(xscans[:10])
  b = scan_factory.add(xscans[10:])

  a + b

  filename = scan_helper_image_files.template_directory_index_to_image(
      template, directory, 1)

  assert(len(scan_factory.search(filename)) == 20)

  (a + b)[1:5]
  (a + b)[:10]

  cbf = os.path.join(directory, 'phi_scan_001.cbf')

  print 'OK'

def test_scan():
  work_helper_image_files()
  work_helper_image_formats()
  work_xscan_factory()