<commit_before>from __future__ import absolute_import, division, print_function

import copy

from scitbx.array_family import flex


def slice_experiments(experiments, image_ranges):
    """
    :param experiments
    :type experiments: dxtbx.model.experiment_list.ExperimentList
    :param image_range:
    :type image_range: list of 2-tuples defining scan range for each experiment
    """

    # copy the experiments
    experiments = copy.deepcopy(experiments)

    if len(experiments) != len(image_ranges):
        raise ValueError(
            "Input experiment list and image_ranges are not of the same length"
        )

    for exp, sr in zip(experiments, image_ranges):
        if sr is None:
            continue
        im_range = exp.scan.get_image_range()
        if sr[0] < im_range[0] or sr[1] > im_range[1]:
            raise IndexError("requested slice outside current scan range")

        # slicing uses the array range, not the image range
        arr_start = exp.scan.get_array_range()[0]
        beg = sr[0] - 1 - arr_start
        end = sr[1] - arr_start
        exp.scan.swap(exp.scan[beg:end])
        if exp.imageset is not None:
            exp.imageset = exp.imageset[beg:end]

        # account for scan-varying crystal
        if exp.crystal.num_scan_points > 0:
            exp.crystal = slice_crystal(exp.crystal, (beg, end))<commit_msg>Bug fix: sometimes there is no crystal<commit_after>from __future__ import absolute_import, division, print_function

import copy

from scitbx.array_family import flex


def slice_experiments(experiments, image_ranges):
    """
    :param experiments
    :type experiments: dxtbx.model.experiment_list.ExperimentList
    :param image_range:
    :type image_range: list of 2-tuples defining scan range for each experiment
    """

    # copy the experiments
    experiments = copy.deepcopy(experiments)

    if len(experiments) != len(image_ranges):
        raise ValueError(
            "Input experiment list and image_ranges are not of the same length"
        )

    for exp, sr in zip(experiments, image_ranges):
        if sr is None:
            continue
        im_range = exp.scan.get_image_range()
        if sr[0] < im_range[0] or sr[1] > im_range[1]:
            raise IndexError("requested slice outside current scan range")

        # slicing uses the array range, not the image range
        arr_start = exp.scan.get_array_range()[0]
        beg = sr[0] - 1 - arr_start
        end = sr[1] - arr_start
        exp.scan.swap(exp.scan[beg:end])
        if exp.imageset is not None:
            exp.imageset = exp.imageset[beg:end]

        # account for scan-varying crystal
        if exp.crystal and exp.crystal.num_scan_points > 0:
            exp.crystal = slice_crystal(exp.crystal, (beg, end))
{'fraction_non_alphanumeric': 0.08558072635742539, 'fraction_numerical': 0.00719165767709457, 'mean_word_length': 2.67989417989418, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4282269', 'n_tokens_mistral': 875, 'n_tokens_neox': 826, 'n_words': 241}