示例#1
0
def test_sort_tables_to_experiments_order_single_dataset_files():
    """Test reflection table sorting when tables contain a single dataset."""
    # Reflection tables in the wrong order
    reflection_tables = [
        mock_reflection_file_object(id_=1).data,
        mock_reflection_file_object(id_=0).data,
    ]
    experiments = ExperimentList()
    experiments.append(Experiment(identifier=str(0)))
    experiments.append(Experiment(identifier=str(1)))
    refls = sort_tables_to_experiments_order(reflection_tables, experiments)

    # Check that reflection tables are rearranged
    assert refls[0] is reflection_tables[1]
    assert refls[1] is reflection_tables[0]
    assert list(refls[0].experiment_identifiers().values()) == ["0"]
    assert list(refls[1].experiment_identifiers().values()) == ["1"]

    # Reflection tables in correct order
    reflection_tables = [
        mock_reflection_file_object(id_=0).data,
        mock_reflection_file_object(id_=1).data,
    ]
    experiments = ExperimentList()
    experiments.append(Experiment(identifier=str(0)))
    experiments.append(Experiment(identifier=str(1)))
    refls = sort_tables_to_experiments_order(reflection_tables, experiments)

    # Check that nothing has been changed
    assert refls[0] is reflection_tables[0]
    assert refls[1] is reflection_tables[1]
    assert list(refls[0].experiment_identifiers().values()) == ["0"]
    assert list(refls[1].experiment_identifiers().values()) == ["1"]
示例#2
0
def test_reflections_and_experiments_from_files():
    """Test correct extracting of reflections and experiments."""
    # Test when input reflections order matches the experiments order
    refl_file_list = [
        mock_two_reflection_file_object(ids=[0, 1]),
        mock_reflection_file_object(id_=2),
    ]

    def mock_exp_obj(id_=0):
        """Make a mock experiments file object."""
        exp = Mock()
        exp.data = ExperimentList()
        exp.data.append(Experiment(identifier=str(id_)))
        return exp

    exp_file_list = [mock_exp_obj(id_=i) for i in [0, 1, 2]]

    refls, expts = reflections_and_experiments_from_files(refl_file_list, exp_file_list)
    assert refls[0] is refl_file_list[0].data
    assert refls[1] is refl_file_list[1].data
    assert expts[0].identifier == "0"
    assert expts[1].identifier == "1"
    assert expts[2].identifier == "2"

    # Test when input reflections order does not match experiments order.
    refl_file_list = [
        mock_reflection_file_object(id_=2),
        mock_two_reflection_file_object(ids=[0, 1]),
    ]
    refls, expts = reflections_and_experiments_from_files(refl_file_list, exp_file_list)
    assert refls[0] is refl_file_list[1].data
    assert refls[1] is refl_file_list[0].data
    assert expts[0].identifier == "0"
    assert expts[1].identifier == "1"
    assert expts[2].identifier == "2"
示例#3
0
def test_renumber_table_id_columns():
    """Test the correct handling of duplicate table id values.
    Note that this function does not have the ability to update the
    experiment string identifier, only ensure that the table id values
    do not clash.
    """
    # Test the case of two single reflection tables.
    rs = [
        mock_reflection_file_object(id_=0).data,
        mock_reflection_file_object(id_=0).data,
    ]
    rs = renumber_table_id_columns(rs)
    assert list(rs[0]["id"]) == [-1, 0, 0]
    assert list(rs[0].experiment_identifiers().keys()) == [0]
    assert list(rs[0].experiment_identifiers().values()) == ["0"]
    assert list(rs[1]["id"]) == [-1, 1, 1]
    assert list(rs[1].experiment_identifiers().keys()) == [1]
    assert list(rs[1].experiment_identifiers().values()) == ["0"]

    # Now test the case where one reflection table contains two experiments
    rs = [
        mock_two_reflection_file_object().data,
        mock_reflection_file_object(id_=0).data,
    ]
    rs = renumber_table_id_columns(rs)
    assert list(rs[0]["id"]) == [-1, 0, 0, 1, 1]
    assert list(rs[0].experiment_identifiers().keys()) == [0, 1]
    assert list(rs[0].experiment_identifiers().values()) == ["0", "2"]
    assert list(rs[1]["id"]) == [-1, 2, 2]
    assert list(rs[1].experiment_identifiers().keys()) == [2]
    assert list(rs[1].experiment_identifiers().values()) == ["0"]

    rs = [
        mock_reflection_file_object(id_=0).data,
        mock_two_reflection_file_object(ids=[1, 2]).data,
    ]
    rs = renumber_table_id_columns(rs)
    assert list(rs[0]["id"]) == [-1, 0, 0]
    assert list(rs[0].experiment_identifiers().keys()) == [0]
    assert list(rs[0].experiment_identifiers().values()) == ["0"]
    assert list(rs[1]["id"]) == [-1, 1, 1, 2, 2]
    assert list(rs[1].experiment_identifiers().keys()) == [1, 2]
    assert list(rs[1].experiment_identifiers().values()) == ["1", "2"]

    rs = [
        mock_two_reflection_file_object(ids=[1, 2]).data,
        mock_reflection_file_object(id_=0).data,
    ]
    rs = renumber_table_id_columns(rs)
    assert list(rs[0]["id"]) == [-1, 0, 0, 1, 1]
    assert list(rs[0].experiment_identifiers().keys()) == [0, 1]
    assert list(rs[0].experiment_identifiers().values()) == ["1", "2"]
    assert list(rs[1]["id"]) == [-1, 2, 2]
    assert list(rs[1].experiment_identifiers().keys()) == [2]
    assert list(rs[1].experiment_identifiers().values()) == ["0"]
示例#4
0
def test_flatten_experiments_updating_id_values():
    """Test the correct handling of duplicate table id values.

    Note that this function does not have the ability to update the
    experiment string identifier, only ensure that the table id values
    do not clash (it is not possible even to load multiple experiments
    with the same identifier).
    """
    # Test the case of two single reflection tables.
    file_list = [
        mock_reflection_file_object(id_=0),
        mock_reflection_file_object(id_=0)
    ]
    rs = flatten_reflections(file_list)
    assert rs[0] is file_list[0].data
    assert list(rs[0]["id"]) == [-1, 0, 0]
    assert list(rs[0].experiment_identifiers().keys()) == [0]
    assert list(rs[0].experiment_identifiers().values()) == ["0"]
    assert rs[1] is file_list[1].data
    assert list(rs[1]["id"]) == [-1, 1, 1]
    assert list(rs[1].experiment_identifiers().keys()) == [1]
    assert list(rs[1].experiment_identifiers().values()) == ["0"]

    # Now test the case where one reflection table contains two experiments
    file_list = [
        mock_two_reflection_file_object(),
        mock_reflection_file_object(id_=0)
    ]
    rs = flatten_reflections(file_list)
    assert rs[0] is file_list[0].data
    assert list(rs[0]["id"]) == [-1, 0, 0, 1, 1]
    assert list(rs[0].experiment_identifiers().keys()) == [0, 1]
    assert list(rs[0].experiment_identifiers().values()) == ["0", "2"]
    assert rs[1] is file_list[1].data
    assert list(rs[1]["id"]) == [-1, 2, 2]
    assert list(rs[1].experiment_identifiers().keys()) == [2]
    assert list(rs[1].experiment_identifiers().values()) == ["0"]

    file_list = [
        mock_reflection_file_object(id_=0),
        mock_two_reflection_file_object(ids=[1, 2]),
    ]
    rs = flatten_reflections(file_list)
    assert rs[0] is file_list[0].data
    assert list(rs[0]["id"]) == [-1, 0, 0]
    assert list(rs[0].experiment_identifiers().keys()) == [0]
    assert list(rs[0].experiment_identifiers().values()) == ["0"]
    assert rs[1] is file_list[1].data
    assert list(rs[1]["id"]) == [-1, 1, 1, 2, 2]
    assert list(rs[1].experiment_identifiers().keys()) == [1, 2]
    assert list(rs[1].experiment_identifiers().values()) == ["1", "2"]
示例#5
0
def test_sort_tables_to_experiments_order_multi_dataset_files():
    """Test reflection table sorting when a table contains multiple datasets."""
    # Reflection tables in the wrong order
    reflection_tables = [
        mock_two_reflection_file_object(ids=[1, 2]).data,
        mock_reflection_file_object(id_=0).data,
    ]
    experiments = ExperimentList()
    experiments.append(Experiment(identifier=str(0)))
    experiments.append(Experiment(identifier=str(1)))
    experiments.append(Experiment(identifier=str(2)))

    refls = sort_tables_to_experiments_order(reflection_tables, experiments)

    # Check that reflection tables are rearranged
    assert refls[0] is reflection_tables[1]
    assert refls[1] is reflection_tables[0]
    assert list(refls[0].experiment_identifiers().values()) == ["0"]
    assert list(refls[1].experiment_identifiers().values()) == ["1", "2"]