Beispiel #1
0
  def run_process(self, iterable):
    # Create ExperimentList objects from image paths (doing it in the processor
    # because I can't have Python objects in the INFO JSON file)
    adj_iterable = []
    imageseq = None
    crystal = None
    for entry in iterable:
      path = str(entry[1])
      if path.endswith('.h5'):
        exp_idx = entry[0]
        img_idx = entry[2]
        if imageseq is None:
          exps = ExLF.from_filenames(filenames=[path])
          imageseq = exps.imagesets()[0]
          crystal = exps[0].crystal
        one_image = imageseq.partial_set(img_idx, img_idx + 1)
        one_exp = ExLF.from_imageset_and_crystal(imageset=one_image,
                                                 crystal=crystal)
        adj_iterable.append([exp_idx, path, img_idx, one_exp])
      else:
        # Create ExperimentList object from CBF
        expr = ExLF.from_filenames(filenames=[path])
        exp_entry = [entry[0], entry[1], 0, expr]
        adj_iterable.append(exp_entry)

    # Run a multiprocessing job
    img_objects = parallel_map(iterable=adj_iterable,
                               func=self.import_and_process,
                               callback=self.callback,
                               processes=self.params.mp.n_processors)

    return img_objects
Beispiel #2
0
def test_no_abs_via_scheme(registry, monkeypatch):
    # Tries to construct these and relies on pickleable
    monkeypatch.setattr(dxtbx.imageset, "ImageSetData", Mock())
    monkeypatch.setattr(dxtbx.imageset, "ImageSet", Mock())

    _hits = []

    class SufficientError(Exception):
        """Stop when we've reached the test point"""

    class SchemeHandler(Format):
        schemes = ["scheme"]

        @classmethod
        def understand(cls, endpoint):
            return True

        def _start(self):
            assert self._image_file == "scheme://something"
            _hits.append(self._image_file)
            # The second reconstruction call had the issue
            if len(_hits) == 2:
                raise SufficientError

    registry.register(SchemeHandler)
    with pytest.raises(SufficientError):
        # We don't want to try doing everything here, just check construction
        ExperimentListFactory.from_filenames(["scheme://something"])

    assert _hits == ["scheme://something", "scheme://something"]
Beispiel #3
0
 def make_experiments(filename, data=None):
     # make experiments
     e_start = time.time()
     if data:
         FormatEigerStream.injected_data = data
         experiments = ExperimentListFactory.from_filenames([filename])
     else:
         experiments = ExperimentListFactory.from_filenames([filename])
     e_time = time.time() - e_start
     return experiments, e_time
Beispiel #4
0
def test_load_models(dials_regression):
    pytest.importorskip("h5py")
    filename = os.path.join(
        dials_regression,
        "image_examples",
        "SACLA_MPCCD_Cheetah",
        "run266702-0-subset.h5",
    )

    # Test different ways of loading the data
    waves1, waves2, waves3, waves4, waves5 = [], [], [], [], []
    oris1, oris2, oris3, oris4, oris5 = [], [], [], [], []

    img = dxtbx.load(filename)

    # Test using dxtbx directly
    for i in range(img.get_num_images()):
        waves1.append(img.get_beam(i).get_wavelength())
        oris1.append(img.get_detector(i)[0].get_origin())

    # Test using the imageset clases
    imageset = img.get_imageset(filename)
    for i in range(len(imageset)):
        waves2.append(imageset.get_beam(i).get_wavelength())
        oris2.append(imageset.get_detector(i)[0].get_origin())

    # Test using imageset subsets
    imageset = img.get_imageset(filename)
    for i in range(len(imageset)):
        subset = imageset[i:i + 1]
        waves3.append(subset.get_beam(0).get_wavelength())
        oris3.append(subset.get_detector(0)[0].get_origin())

    # Test using pre-loaded experiments
    experiments = ExperimentListFactory.from_filenames([filename])
    for experiment in experiments:
        waves4.append(experiment.beam.get_wavelength())
        oris4.append(experiment.detector[0].get_origin())

    # Test using post-loaded experiments
    experiments = ExperimentListFactory.from_filenames([filename],
                                                       load_models=False)
    for experiment in experiments:
        assert experiment.beam is None and experiment.detector is None
        experiment.load_models()
        waves5.append(experiment.beam.get_wavelength())
        oris5.append(experiment.detector[0].get_origin())

    for w1, w2, w3, w4, w5 in zip(waves1, waves2, waves3, waves4, waves5):
        assert w1 == w2 == w3 == w4 == w5

    for o1, o2, o3, o4, o5 in zip(oris1, oris2, oris3, oris4, oris5):
        assert o1 == o2 == o3 == o4 == o5
Beispiel #5
0
def test_rotation_scan_i04(master_h5):
    assert FormatNexusEigerDLS16M.understand(master_h5)

    expts = ExperimentListFactory.from_filenames(
        [master_h5], format_kwargs={"dynamic_shadowing": True})
    imageset = expts[0].imageset
    assert imageset.get_format_class() == FormatNexusEigerDLS16M

    detector = imageset.get_detector()
    gonio = imageset.get_goniometer()
    scan = imageset.get_scan()
    beam = imageset.get_beam()

    panel = detector[0]
    assert panel.get_pixel_size() == (0.075, 0.075)
    assert panel.get_image_size() == (4148, 4362)
    assert panel.get_trusted_range() == (-1, 65535)
    assert panel.get_fast_axis() == (1, 0, 0)
    assert panel.get_slow_axis() == (0, -1, 0)
    assert panel.get_origin() == pytest.approx(
        (-166.07661632390744, 172.5371934106162, -200.0))
    assert panel.get_distance() == 200

    assert len(gonio.get_axes()) == 3
    expected_axes = ((1, 0, 0), (0, 0, -1), (1, 0, 0))
    for a1, a2 in zip(gonio.get_axes(), expected_axes):
        assert a1 == pytest.approx(a2, abs=5e-2)
    assert gonio.get_scan_axis() == 2

    assert scan.get_oscillation() == (0, 0.2)
    assert scan.get_image_range() == (1, 900)

    assert beam.get_wavelength() == pytest.approx(0.979499)
    assert beam.get_s0() == pytest.approx((0, 0, -1 / beam.get_wavelength()))
Beispiel #6
0
def test_grid_scan_i04():
    master_h5 = "/dls/i04/data/2019/cm23004-1/20190109/Eiger/grid/Thaum/Thau_5/Thau_5_1_master.h5"
    assert FormatNexusEigerDLS16M.understand(master_h5)

    expts = ExperimentListFactory.from_filenames([master_h5])
    imageset = expts[0].imageset
    assert imageset.get_format_class() == FormatNexusEigerDLS16M

    detector = imageset.get_detector()
    gonio = imageset.get_goniometer()
    scan = imageset.get_scan()
    beam = imageset.get_beam()

    panel = detector[0]
    assert panel.get_pixel_size() == (0.075, 0.075)
    assert panel.get_image_size() == (4148, 4362)
    assert panel.get_trusted_range() == (-1, 65535)
    assert panel.get_fast_axis() == (1, 0, 0)
    assert panel.get_slow_axis() == (0, -1, 0)
    assert panel.get_origin() == pytest.approx(
        (-167.44717577120824, 172.46833023184868, -350.0))
    assert panel.get_distance() == 350

    assert len(gonio.get_axes()) == 3
    expected_axes = ((1, 0, 0), (0, 0, -1), (1, 0, 0))
    for a1, a2 in zip(gonio.get_axes(), expected_axes):
        assert a1 == pytest.approx(a2, abs=5e-2)
    # assert gonio.get_scan_axis() == 2

    if scan:
        osc = scan.get_oscillation()
        assert osc[0] == osc[1]

    assert beam.get_wavelength() == pytest.approx(0.979499)
    assert beam.get_s0() == pytest.approx((0, 0, -1 / beam.get_wavelength()))
Beispiel #7
0
def test_masked_i03_16bit(master_h5):
    assert FormatNexusEigerDLS16M.understand(master_h5)

    expts = ExperimentListFactory.from_filenames([master_h5])
    imageset = expts[0].imageset
    assert flex.min(imageset[0][0]) == -1.0
    assert flex.max(imageset[0][0]) != 0xFFFF
Beispiel #8
0
def test_dlsnxs2cbf(dials_data, tmp_path):
    screen = dials_data("thaumatin_eiger_screen")
    master = screen.join("Therm_6_1_master.h5")
    result = procrunner.run(["dxtbx.dlsnxs2cbf", master, "junk_%04d.cbf"],
                            working_directory=tmp_path)
    assert not result.returncode and not result.stderr

    output_files = ["junk_%04d.cbf" % j for j in (1, 2, 3)]
    for file in output_files:
        assert file.encode("latin-1") in result.stdout
        assert tmp_path.joinpath(file).is_file()

    expts = ExperimentListFactory.from_filenames(
        str(tmp_path / file) for file in output_files)
    assert all(imgset.get_format_class() == FormatCBFMiniEigerDLS16MSN160
               for imgset in expts.imagesets())

    with h5py.File(master) as fh:
        for i, imgset in enumerate(expts.imagesets()):
            original = fh["/entry/data/data_000001"][i][()]
            sel = np.where(original < original.max())
            np.testing.assert_equal(
                fh["/entry/data/data_000001"][i][sel],
                imgset.get_raw_data(0)[0].as_numpy_array()[sel],
            )
Beispiel #9
0
def test_vmxi_thaumatin(dials_data):
    master_h5 = dials_data("vmxi_thaumatin") / "image_15799_master.h5"
    expts = ExperimentListFactory.from_filenames([master_h5.strpath])
    to_xds = xds.to_xds(expts[0].imageset)
    s = to_xds.XDS_INP()
    assert "DETECTOR=EIGER" in s
    assert "SENSOR_THICKNESS= 0.450" in s
Beispiel #10
0
def test_experimentlist_imagesequence_stills(dials_data):
    filenames = [
        str(dials_data("thaumatin_grid_scan") / f"thau_3_2_{i:04d}.cbf.bz2")
        for i in range(1, 4)
    ]
    experiments = ExperimentListFactory.from_filenames(filenames)

    assert len(experiments) == 3
    assert len(experiments.imagesets()) == 1

    # Convert experiment list to dict
    d = experiments.to_dict()

    # Decode the dict to get a new experiment list
    experiments2 = ExperimentListDict(d).decode()

    # Verify that this experiment is as we expect
    assert len(experiments2) == 3
    assert len(experiments2.imagesets()) == 1
    assert len(experiments2.goniometers()) == 1
    assert len(experiments2.detectors()) == 1
    assert len(experiments2.beams()) == 1
    assert len(experiments2.scans()) == 3
    for expt in experiments2:
        assert expt.imageset is experiments2.imagesets()[0]
Beispiel #11
0
def test_experimentlist_imagesequence_stills():
    filenames = [
        "/Users/rjgildea/tmp/118/Puck3_10_1_000%i.cbf.gz" % i
        for i in range(1, 4)
    ]
    for f in filenames:
        if not os.path.exists(f):
            pytest.skip("%s does not exist" % f)
    experiments = ExperimentListFactory.from_filenames(filenames)

    assert len(experiments) == 3
    assert len(experiments.imagesets()) == 1

    # Convert experiment list to dict
    d = experiments.to_dict()

    # Decode the dict to get a new experiment list
    experiments2 = ExperimentListDict(d).decode()

    # Verify that this experiment is as we expect
    assert len(experiments2) == 3
    assert len(experiments2.imagesets()) == 1
    assert len(experiments2.goniometers()) == 1
    assert len(experiments2.detectors()) == 1
    assert len(experiments2.beams()) == 1
    assert len(experiments2.scans()) == 3
    for expt in experiments2:
        assert expt.imageset is experiments2.imagesets()[0]
def test_spring8_ccp4_2018_zenodo_1443110_data03():
    # https://zenodo.org/record/1443110#.XD8bD5ynzmE
    master_h5 = "/dls/mx-scratch/rjgildea/zenodo/spring8-ccp4-2018/1443110/ccp4school2018_bl41xu/05/data03/data03_master.h5"
    assert FormatHDF5EigerNearlyNexusSPring8.understand(master_h5)

    expts = ExperimentListFactory.from_filenames([master_h5])
    imageset = expts[0].imageset
    assert imageset.get_format_class() == FormatHDF5EigerNearlyNexusSPring8

    detector = imageset.get_detector()
    gonio = imageset.get_goniometer()
    scan = imageset.get_scan()
    beam = imageset.get_beam()

    panel = detector[0]
    assert panel.get_pixel_size() == pytest.approx((0.075, 0.075))
    assert panel.get_image_size() == (4150, 4371)
    assert panel.get_trusted_range() == (-1, 2.094707e06)
    assert panel.get_fast_axis() == (1, 0, 0)
    assert panel.get_slow_axis() == (0, -1, 0)
    assert panel.get_origin() == pytest.approx((-151.939, 169.629, -180),
                                               abs=1e-3)
    assert panel.get_distance() == pytest.approx(180)

    assert isinstance(gonio, Goniometer)
    assert gonio.get_rotation_axis() == (-1, 0, 0)
    assert gonio.get_fixed_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1)
    assert gonio.get_setting_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1)

    assert scan.get_oscillation() == pytest.approx((-10, 1))
    assert scan.get_image_range() == (1, 180)

    assert beam.get_wavelength() == pytest.approx(1.28241, abs=1e-5)
    assert beam.get_s0() == pytest.approx((0, 0, -1 / beam.get_wavelength()))
Beispiel #13
0
def _extract_or_read_imagesets(params):
    """
    Return a list of ImageSets, importing them via alternative means if necessary.

    The "Alternative Means" means via params.input.template or .directory,
    if the images to import haven't been specified directly.

    Args:
        params: The phil.scope_extract from dials.import

    Returns: A list of ImageSet objects
    """

    # Get the experiments
    experiments = flatten_experiments(params.input.experiments)

    # Check we have some filenames
    if len(experiments) == 0:

        # FIXME Should probably make this smarter since it requires editing here
        # and in dials.import phil scope
        try:
            format_kwargs = {
                "dynamic_shadowing": params.format.dynamic_shadowing,
                "multi_panel": params.format.multi_panel,
            }
        except AttributeError:
            format_kwargs = None

        # Check if a template has been set and print help if not, otherwise try to
        # import the images based on the template input
        if len(params.input.template) > 0:
            importer = ExperimentListTemplateImporter(
                params.input.template,
                image_range=params.geometry.scan.image_range,
                format_kwargs=format_kwargs,
            )
            experiments = importer.experiments
            if len(experiments) == 0:
                raise Sorry("No experiments found matching template %s" %
                            params.input.experiments)
        elif len(params.input.directory) > 0:
            experiments = ExperimentListFactory.from_filenames(
                params.input.directory, format_kwargs=format_kwargs)
            if len(experiments) == 0:
                raise Sorry("No experiments found in directories %s" %
                            params.input.directory)
        else:
            raise Sorry("No experiments found")

    # TODO (Nick):  This looks redundant as the experiments are immediately discarded.
    #               verify this, and remove if it is.
    if params.identifier_type:
        generate_experiment_identifiers(experiments, params.identifier_type)

    # Get a list of all imagesets
    imageset_list = experiments.imagesets()

    # Return the experiments
    return imageset_list
def test_DLS_I03_smargon(dials_data, tmpdir):
    filename_gz = (dials_data("image_examples").join(
        "DLS_I03_smargon_0001.cbf.gz").strpath)

    # The need to manually extract the file will be removed by
    # https://github.com/cctbx/dxtbx/pull/80

    filename = tmpdir.join(os.path.split(filename_gz[:-3])[-1]).strpath
    with open(filename, "wb") as f:
        with gzip.open(filename_gz, "rb") as fgz:
            f.write(fgz.read())

    assert FormatCBFFullPilatusDLS6MSN126.understand(filename)
    expts = ExperimentListFactory.from_filenames(
        [filename], format_kwargs={"dynamic_shadowing": True})
    assert len(expts) == 1
    imageset = expts[0].imageset
    assert imageset.get_format_class() == FormatCBFFullPilatusDLS6MSN126
    gonio = imageset.get_goniometer()
    assert list(gonio.get_angles()) == pytest.approx([45.0, 45.0, 45.0])
    assert list(gonio.get_axes().as_double()) == pytest.approx(
        [1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 1.0, 0.0, 0.0])
    assert list(gonio.get_names()) == ["GON_PHI", "GON_CHI", "GON_OMEGA"]
    assert imageset.has_dynamic_mask()
    masker = imageset.masker()
    assert isinstance(masker, SmarGonShadowMasker)
    assert masker.get_mask(imageset.get_detector(), 0)[0].count(False) == 0
    assert masker.get_mask(imageset.get_detector(),
                           100)[0].count(False) == 261588
Beispiel #15
0
def do_import(filename, load_models=True):
    logger.info("Loading %s" % os.path.basename(filename))
    experiments = ExperimentListFactory.from_filenames([filename],
                                                       load_models=False)
    if len(experiments) == 0:
        try:
            experiments = ExperimentListFactory.from_json_file(filename)
        except ValueError:
            raise Abort("Could not load %s" % filename)

    if len(experiments) == 0:
        raise Abort("Could not load %s" % filename)

    from dxtbx.imageset import ImageSetFactory

    for experiment in experiments:
        if load_models:
            experiment.load_models()
        imageset = ImageSetFactory.imageset_from_anyset(experiment.imageset)
        imageset.set_scan(None)
        imageset.set_goniometer(None)
        experiment.imageset = imageset
        experiment.scan = None
        experiment.goniometer = None

    return experiments
Beispiel #16
0
def test_create_multiple_blocks(multiple_block_filenames):
    experiments = ExperimentListFactory.from_filenames(
        multiple_block_filenames)
    assert len(experiments) == 24
    imagesets = experiments.imagesets()
    assert len(imagesets) == 24
    assert [len(im) for im in imagesets] == [9] + [1] * 23
Beispiel #17
0
def test_VMXi_rotation_scan():
    master_h5 = "/dls/mx/data/mx21314/mx21314-27/VMXi-AB0816/well_7/images/image_14364_master.h5"
    assert FormatNexus.understand(master_h5)

    expts = ExperimentListFactory.from_filenames([master_h5])
    imageset = expts[0].imageset
    assert imageset.get_format_class() == FormatNexus

    detector = imageset.get_detector()
    gonio = imageset.get_goniometer()
    scan = imageset.get_scan()
    beam = imageset.get_beam()

    panel = detector[0]
    assert panel.get_pixel_size() == (0.075, 0.075)
    assert panel.get_image_size() == (2068, 2162)
    assert panel.get_trusted_range() == (-1, 4096)
    assert panel.get_fast_axis() == (1, 0, 0)
    assert panel.get_slow_axis() == (0, -1, 0)
    assert panel.get_origin() == pytest.approx(
        (-78.05999999999999, 87.03, -194.5039999999999))
    assert panel.get_distance() == pytest.approx(194.504)

    assert isinstance(gonio, Goniometer)
    assert gonio.get_rotation_axis() == (0, 1, 0)
    assert gonio.get_fixed_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1)
    assert gonio.get_setting_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1)

    assert scan.get_oscillation() == pytest.approx((-30, 0.1))
    assert scan.get_image_range() == (1, 600)

    assert beam.get_wavelength() == pytest.approx(0.979492)
    assert beam.get_s0() == pytest.approx((0, 0, -1 / beam.get_wavelength()))
Beispiel #18
0
def test_multi_panel(dials_data, tmpdir):
    filename = dials_data("x4wide") / "X4_wide_M1S4_2_0001.cbf"

    assert FormatCBFMiniPilatus.understand(filename.strpath)
    expts = ExperimentListFactory.from_filenames(
        [filename.strpath], format_kwargs={"multi_panel": True})
    assert len(expts) == 1
    assert len(expts[0].detector) == 60
    assert len(expts[0].imageset.get_raw_data(0)) == 60
    expected_xoffset = [-212.47848, -127.51048, -42.54248, 42.42552, 127.39352]
    expected_yoffset = [
        220.00176,
        183.53776,
        147.07376,
        110.60976,
        74.14576,
        37.68176,
        1.21776,
        -35.24624,
        -71.71024,
        -108.17424,
        -144.63824,
        -181.10224,
    ]
    for i, p in enumerate(expts[0].detector):
        assert p.get_image_size() == (487, 195)
        origin = p.get_origin()
        assert origin[0] == pytest.approx(expected_xoffset[i % 5])
        assert origin[1] == pytest.approx(expected_yoffset[i // 5])
        assert origin[2] == pytest.approx(-190.18)
Beispiel #19
0
def test_dynamic_shadowing(path, count_only_shadow, count_mask_shadow,
                           count_mask_no_shadow, dials_regression):
    path = os.path.join(dials_regression, path)
    assert os.path.exists(path), path
    for shadowing in (libtbx.Auto, True, False):
        format_kwargs = {"dynamic_shadowing": shadowing}
        experiments = ExperimentListFactory.from_filenames(
            [path], format_kwargs=format_kwargs)
        imageset = experiments.imagesets()[0]
        detector = imageset.get_detector()
        scan = imageset.get_scan()
        masker = imageset.masker()
        if shadowing is not False:
            assert masker is not None
            mask = masker.get_mask(detector, scan.get_oscillation()[0])
            assert len(mask) == len(detector)
            # only shadowed pixels masked
            assert mask[0].count(False) == count_only_shadow, (
                mask[0].count(False),
                count_only_shadow,
            )
        mask = imageset.get_mask(0)

        # dead pixels, pixels in gaps, etc also masked
        if shadowing is libtbx.Auto or shadowing is True:
            assert mask[0].count(False) == count_mask_shadow, (
                mask[0].count(False),
                count_mask_shadow,
            )
        else:
            assert mask[0].count(False) == count_mask_no_shadow, (
                mask[0].count(False),
                count_mask_no_shadow,
            )
Beispiel #20
0
def run(args=None):
    args = args or sys.argv[1:]
    user_phil = []
    files = []
    for arg in args:
        if os.path.isfile(arg):
            files.append(arg)
        else:
            try:
                user_phil.append(parse(arg))
            except Exception:
                raise Sorry("Unrecognized argument %s" % arg)
    params = phil_scope.fetch(sources=user_phil).extract()

    fig = plt.figure()
    colormap = plt.cm.gist_ncar
    colors = [colormap(i) for i in np.linspace(0, 0.9, len(files))]
    for file_name, color in zip(files, colors):

        # read the data and get the detector models
        try:
            datablocks = DataBlockFactory.from_json_file(file_name,
                                                         check_format=False)
            detectors = sum((db.unique_detectors() for db in datablocks), [])
        except Exception:
            try:
                experiments = ExperimentListFactory.from_json_file(
                    file_name, check_format=False)
            except ValueError:
                experiments = ExperimentListFactory.from_filenames([file_name])
            detectors = experiments.detectors()
        if not params.plot_all_detectors:
            detectors = detectors[0:1]
        for detector in detectors:
            # plot the hierarchy
            if params.orthographic:
                ax = fig.gca()
            else:
                ax = fig.gca(projection="3d")
            plot_group(
                detector.hierarchy(),
                color,
                ax,
                orthographic=params.orthographic,
                show_origin_vectors=params.show_origin_vectors,
                panel_numbers=params.panel_numbers,
            )

    plt.xlabel("x")
    plt.ylabel("y")
    if params.orthographic:
        plt.axes().set_aspect("equal", "datalim")

    if params.pdf_file:
        pp = PdfPages(params.pdf_file)
        for i in plt.get_fignums():
            pp.savefig(plt.figure(i))
        pp.close()
    else:
        plt.show()
def test_MPCCD_RECONST_MODE(dials_data, monkeypatch):
    for MPCCD_RECONST_MODE in (0, 1):
        if MPCCD_RECONST_MODE:
            monkeypatch.setenv("MPCCD_RECONST_MODE", str(MPCCD_RECONST_MODE))
        else:
            monkeypatch.delenv("MPCCD_RECONST_MODE", raising=False)

        master_h5 = (dials_data("image_examples").join(
            "SACLA-MPCCD-Phase3-21528-5images.h5").strpath)
        expts = ExperimentListFactory.from_filenames([master_h5])
        imageset = expts[0].imageset
        # Horrible hack to work around format_instance caching
        imageset.reader().nullify_format_instance()
        raw_data = imageset.get_raw_data(0)
        mmm = raw_data[0].as_double().as_1d().min_max_mean()
        mmm.show()
        if MPCCD_RECONST_MODE:
            assert mmm.min == -1
            assert mmm.max == 14102
            assert mmm.mean == pytest.approx(2.93752665030144)
        else:
            assert mmm.min == 0
            assert mmm.max == 3610.0
            assert mmm.mean == pytest.approx(3.397266387939453)
    # Horrible hack to work around format_instance caching
    # This is needed to prevent an incorrect format_instance affecting
    # other tests that are run after this one.
    imageset.reader().nullify_format_instance()
def test_HDF5_format_caching(dials_data, clear_cache):
    """
    xfail: see https://github.com/cctbx/dxtbx/issues/245
    """
    img_file = "SACLA-MPCCD-Phase3-21528-5images.h5"
    master_h5 = dials_data("image_examples").join(img_file).strpath

    expts1 = ExperimentListFactory.from_filenames([master_h5])
    expts1[0].imageset.get_mask(0)
    if clear_cache:
        expts1[0].imageset.reader().nullify_format_instance()
    expts2 = ExperimentListFactory.from_filenames([master_h5])

    for e1, e2 in zip(expts1, expts2):
        assert (e1.imageset.get_beam().get_wavelength() ==
                e2.imageset.get_beam().get_wavelength())
def test_MPCCD_Phase3_21528(dials_data):
    master_h5 = (dials_data("image_examples").join(
        "SACLA-MPCCD-Phase3-21528-5images.h5").strpath)
    assert FormatHDF5SaclaMPCCD.understand(master_h5)
    expts = ExperimentListFactory.from_filenames([master_h5])
    imageset = expts[0].imageset
    assert imageset.get_format_class() == FormatHDF5SaclaMPCCD

    detector = imageset.get_detector()
    beam = imageset.get_beam()

    assert len(detector) == 8
    panel = detector[0]
    assert panel.get_pixel_size() == pytest.approx((0.05, 0.05))
    assert panel.get_image_size() == (512, 1024)
    assert panel.get_trusted_range() == (-1.0, 65535.0)
    assert panel.get_fast_axis() == pytest.approx(
        (-0.0026929852392799875, -0.9999963739086762, 0.0))
    assert panel.get_slow_axis() == pytest.approx(
        (-0.9999963739086762, 0.0026929852392799875, 0.0))
    assert panel.get_thickness() == pytest.approx(0.3)
    assert panel.get_mu() == 0
    assert panel.get_material() == ""
    assert panel.get_origin() == pytest.approx(
        (-1.8203499755859376, 51.6243984375, -99.5))
    assert panel.get_distance() == pytest.approx(99.5)

    assert imageset.get_goniometer() is None
    assert imageset.get_scan() is None

    assert beam.get_wavelength() == pytest.approx(1.2452863763694901)
    assert beam.get_sample_to_source_direction() == (0, 0, 1)
    imageset.reader().nullify_format_instance()
def test_spring8_ccp4_2018_zenodo_1443110_data03(dials_data):
    master_h5 = (dials_data("spring8_ccp4_2018").join(
        "ccp4school2018_bl41xu", "05", "data03", "data03_master.h5").strpath)
    assert FormatHDF5EigerNearlyNexusSPring8.understand(master_h5)

    expts = ExperimentListFactory.from_filenames([master_h5])
    imageset = expts[0].imageset
    assert imageset.get_format_class() == FormatHDF5EigerNearlyNexusSPring8

    detector = imageset.get_detector()
    gonio = imageset.get_goniometer()
    scan = imageset.get_scan()
    beam = imageset.get_beam()

    panel = detector[0]
    assert panel.get_pixel_size() == pytest.approx((0.075, 0.075))
    assert panel.get_image_size() == (4150, 4371)
    assert panel.get_trusted_range() == (-1, 2.094707e06)
    assert panel.get_fast_axis() == (1, 0, 0)
    assert panel.get_slow_axis() == (0, -1, 0)
    assert panel.get_origin() == pytest.approx((-151.939, 169.629, -180),
                                               abs=1e-3)
    assert panel.get_distance() == pytest.approx(180)

    assert isinstance(gonio, Goniometer)
    assert gonio.get_rotation_axis() == (-1, 0, 0)
    assert gonio.get_fixed_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1)
    assert gonio.get_setting_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1)

    assert scan.get_oscillation() == pytest.approx((-10, 1))
    assert scan.get_image_range() == (1, 180)

    assert beam.get_wavelength() == pytest.approx(1.28241, abs=1e-5)
    assert beam.get_s0() == pytest.approx((0, 0, -1 / beam.get_wavelength()))
Beispiel #25
0
def test_create_single_sequence(single_sequence_filenames):
    experiments = ExperimentListFactory.from_filenames(
        single_sequence_filenames)
    assert len(experiments) == 1
    imagesets = experiments.imagesets()
    assert imagesets[0].get_format_class()
    assert len(imagesets) == 1
    assert len(imagesets[0]) == 9
Beispiel #26
0
def test_slice_experiments_centroid_test_data(dials_data):
    files = dials_data("centroid_test_data").listdir("*.cbf", sort=True)
    experiments = ExperimentListFactory.from_filenames(f.strpath for f in files)
    sliced_image_range = [(1, 3)]
    sliced_experiments = slice_experiments(experiments, sliced_image_range)
    assert sliced_experiments[0].scan.get_image_range() == sliced_image_range[0]
    # for some reason the sliced_experiments is not copyable
    assert copy.deepcopy(sliced_experiments)
def test_screening(dials_data):
    master_h5 = dials_data("thaumatin_eiger_screen").join("Therm_6_1_master.h5").strpath
    assert FormatNexusEigerDLS16M.understand(master_h5)

    expts = ExperimentListFactory.from_filenames([master_h5])
    assert len(expts) == 3
    imagesets = expts[0].imageset
    assert imagesets[0].get_format_class() == FormatNexusEigerDLS16M
Beispiel #28
0
    def run_process(self, iterable):
        # Create ExperimentList objects from image paths (doing it in the processor
        # because I can't have Python objects in the INFO JSON file)
        adj_iterable = []
        crystal = None
        for entry in iterable:
            path = str(entry[1])
            if path.endswith(".h5"):
                exp_idx = entry[0]
                img_idx = entry[2]

                # Generate a list of single images if at img_idx = 0
                if img_idx == 0:
                    imageseqs = []
                    exps = ExLF.from_filenames(filenames=[path])
                    crystal = exps[0].crystal

                    # flatten all imagesets into a single imagesequence
                    for iset in exps.imagesets():
                        if iset.size() == 1:
                            imageseqs.append(iset)
                        else:
                            for i in range(iset.size()):
                                one_image = imageseq.partial_set(i, i + 1)
                                imageseqs.append(i)

                # Create ExperimentList object from extracted imageset
                current_image = imageseqs[img_idx]
                one_exp = ExLF.from_imageset_and_crystal(
                    imageset=current_image, crystal=crystal
                )
                adj_iterable.append([exp_idx, path, img_idx, one_exp])
            else:
                # Create ExperimentList object from CBF
                expr = ExLF.from_filenames(filenames=[path])
                exp_entry = [entry[0], entry[1], 0, expr]
                adj_iterable.append(exp_entry)

        # Run a multiprocessing job
        img_objects = parallel_map(
            iterable=adj_iterable,
            func=self.import_and_process,
            callback=self.callback,
            processes=self.params.mp.n_processors,
        )
        return img_objects
Beispiel #29
0
def test_slice_experiments_centroid_test_data_starting_from_2(dials_data):
    files = dials_data("centroid_test_data").listdir("*.cbf", sort=True)[1:]
    experiments = ExperimentListFactory.from_filenames(f.strpath
                                                       for f in files)
    sliced_image_range = [(2, 4)]
    sliced_experiments = slice_experiments(experiments, sliced_image_range)
    assert sliced_experiments[0].scan.get_image_range(
    ) == sliced_image_range[0]
Beispiel #30
0
def test_single_panel(dials_data, tmpdir):
    filename = dials_data("x4wide") / "X4_wide_M1S4_2_0001.cbf"

    assert FormatCBFMiniPilatus.understand(filename.strpath)
    expts = ExperimentListFactory.from_filenames([filename.strpath])
    assert len(expts) == 1
    assert len(expts[0].detector) == 1
    assert len(expts[0].imageset.get_raw_data(0)) == 1