Exemplo n.º 1
0
def get_subset_for_symmetry(experiments,
                            reflection_tables,
                            exclude_images=None):
    """Select an image range for symmetry analysis, or just select
    the first 360 degrees of data."""
    refls_for_sym = []
    if exclude_images:
        experiments = exclude_image_ranges_from_scans(reflection_tables,
                                                      experiments,
                                                      exclude_images)
        for refl, exp in zip(reflection_tables, experiments):
            sel = get_selection_for_valid_image_ranges(refl, exp)
            refls_for_sym.append(refl.select(sel))
    else:
        for expt, refl in zip(experiments, reflection_tables):
            sel = get_selection_for_valid_image_ranges(refl, expt)
            if not sel.count(False):
                # Use first 360 degrees if <360 deg i.e. first measured data,
                # but only if no reflections have been exlicitly excluded
                # already
                scan_end = int(
                    math.ceil(360 / abs(expt.scan.get_oscillation()[1])))
                if scan_end < len(expt.scan):
                    sel = refl["xyzobs.px.value"].parts()[2] <= scan_end
            refls_for_sym.append(refl.select(sel))
    return refls_for_sym
Exemplo n.º 2
0
def test_exclude_image_ranges_from_scans():
    """Test for namesake function"""
    explist = ExperimentList(
        [make_scan_experiment(expid="0"),
         make_scan_experiment(expid="1")])
    exclude_images = [["0:81:100"], ["1:61:80"]]
    r1 = flex.reflection_table()
    r1.experiment_identifiers()[1] = "1"
    r0 = flex.reflection_table()
    r0.experiment_identifiers()[0] = "0"
    tables = [r0, r1]
    explist = exclude_image_ranges_from_scans(tables, explist, exclude_images)
    assert list(explist[0].scan.get_valid_image_ranges("0")) == [(1, 80)]
    assert list(explist[1].scan.get_valid_image_ranges("1")) == [(1, 60),
                                                                 (81, 100)]
    # Try excluding a range that already has been excluded
    explist = exclude_image_ranges_from_scans(tables, explist, [["1:70:80"]])
    assert list(explist[0].scan.get_valid_image_ranges("0")) == [(1, 80)]
    assert list(explist[1].scan.get_valid_image_ranges("1")) == [(1, 60),
                                                                 (81, 100)]
    scanlessexplist = ExperimentList([make_scanless_experiment()])
    with pytest.raises(ValueError):
        _ = exclude_image_ranges_from_scans(tables, scanlessexplist,
                                            [["0:1:100"]])
    # Now try excluding everything, should set an empty array
    explist = exclude_image_ranges_from_scans(tables, explist, [["1:1:100"]])
    assert list(explist[0].scan.get_valid_image_ranges("0")) == [(1, 80)]
    assert list(explist[1].scan.get_valid_image_ranges("1")) == []

    ## test what happens if a single image is left within the scan
    explist = ExperimentList(
        [make_scan_experiment(expid="0"),
         make_scan_experiment(expid="1")])
    exclude_images = [["0:81:100"], ["1:76:79"], ["1:81:99"]]
    r1 = flex.reflection_table()
    r1.experiment_identifiers()[1] = "1"
    r0 = flex.reflection_table()
    r0.experiment_identifiers()[0] = "0"
    tables = [r0, r1]
    explist = exclude_image_ranges_from_scans(tables, explist, exclude_images)
    assert list(explist[0].scan.get_valid_image_ranges("0")) == [(1, 80)]
    assert list(explist[1].scan.get_valid_image_ranges("1")) == [
        (1, 75),
        (80, 80),
        (100, 100),
    ]
Exemplo n.º 3
0
def test_exclude_image_ranges_from_scans():
    """Test for namesake function"""
    explist = ExperimentList(
        [make_scan_experiment(expid="0"),
         make_scan_experiment(expid="1")])
    exclude_images = [["0:81:100"], ["1:61:80"]]
    explist = exclude_image_ranges_from_scans(explist, exclude_images)
    assert list(explist[0].scan.get_valid_image_ranges("0")) == [(1, 80)]
    assert list(explist[1].scan.get_valid_image_ranges("1")) == [(1, 60),
                                                                 (81, 100)]
    # Try excluding a range that already has been excluded
    explist = exclude_image_ranges_from_scans(explist, [["1:70:80"]])
    assert list(explist[0].scan.get_valid_image_ranges("0")) == [(1, 80)]
    assert list(explist[1].scan.get_valid_image_ranges("1")) == [(1, 60),
                                                                 (81, 100)]
    scanlessexplist = ExperimentList([make_scanless_experiment()])
    with pytest.raises(ValueError):
        _ = exclude_image_ranges_from_scans(scanlessexplist, [["0:1:100"]])
    # Now try excluding everything, should set an empty array
    explist = exclude_image_ranges_from_scans(explist, [["1:1:100"]])
    assert list(explist[0].scan.get_valid_image_ranges("0")) == [(1, 80)]
    assert list(explist[1].scan.get_valid_image_ranges("1")) == []
Exemplo n.º 4
0
def test_get_subset_for_symmetry_prior_image_range():
    """Test that first 360 degrees are selected from each sweep with an exclude
    images command."""
    exclude_images, expts, tables = _make_input_for_exclude_tests(exclude_images=True)

    # Explicitly exclude a different image range
    expts = exclude_image_ranges_from_scans(tables, expts, [["0:1:360"], ["1:1:360"]])
    refls = get_subset_for_symmetry(expts, tables)
    assert refls[0]["i"].all_eq(1)
    assert refls[1]["i"].all_eq(1)

    # Exclude_images should be cumulative, i.e. the range exclude above should
    # be excluded in addition to the new range provided explicitly to the
    # function
    refls = get_subset_for_symmetry(expts, tables, exclude_images)
    assert len(refls[0]) == 0
    assert len(refls[1]) == 0