<commit_before>from __future__ import absolute_import

import operator


def slice_hypercube(hdu, dimensions=[0, 1], slices=[]):
    '''
    Extract a slice from an n-dimensional FITS HDU, and return an HDU
    '''

    if type(slices) == int:
        slices = (slices, )
    else:
        slices = slices[:]

    shape = hdu.data.shape

    if len(shape) < 2:

        raise Exception("FITS file does not have enough dimensions")

    elif len(shape) == 2:

        return hdu

    else:

        n_total = reduce(operator.mul, shape)
        n_image = shape[dimensions[0]] * shape[dimensions[1]]

        if n_total == n_image:
            slices = [0 for i in range(1, len(shape) - 1)]

        if slices:

            if dimensions[0] < dimensions[1]:
                slices.insert(dimensions[0], slice(None, None, None))
                slices.insert(dimensions[1], slice(None, None, None))
            else:
                slices.insert(dimensions[1], slice(None, None, None))
                slices.insert(dimensions[0], slice(None, None, None))

            if type(slices) == list:
                slices = tuple(slices)
            hdu.data = hdu.data[slices[::-1]]
            if dimensions[1] < dimensions[0]:
                hdu.data = hdu.data.transpose()
        else:
            message = '''
    Attempted to read in %i-dimensional FITS cube, but
    dimensions and slices were not specified. Please specify these
    using the dimensions= and slices= argument. The cube dimensions
    are:\n\n''' % len(shape)
            for i in range(1, len(shape) + 1):
                message += " " * 10
                message += " %s %i\n" % (hdu.header["CTYPE%i" % i],
                                         hdu.header["NAXIS%i" % i])

            raise Exception(message)

        return hdu<commit_msg>Whitespace fixes<commit_after>from __future__ import absolute_import

import operator


def slice_hypercube(hdu, dimensions=[0, 1], slices=[]):
    '''
    Extract a slice from an n-dimensional FITS HDU, and return an HDU
    '''

    if type(slices) == int:
        slices = (slices, )
    else:
        slices = slices[:]

    shape = hdu.data.shape

    if len(shape) < 2:

        raise Exception("FITS file does not have enough dimensions")

    elif len(shape) == 2:

        return hdu

    else:

        n_total = reduce(operator.mul, shape)
        n_image = shape[dimensions[0]] * shape[dimensions[1]]

        if n_total == n_image:
            slices = [0 for i in range(1, len(shape) - 1)]

        if slices:

            if dimensions[0] < dimensions[1]:
                slices.insert(dimensions[0], slice(None, None, None))
                slices.insert(dimensions[1], slice(None, None, None))
            else:
                slices.insert(dimensions[1], slice(None, None, None))
                slices.insert(dimensions[0], slice(None, None, None))

            if type(slices) == list:
                slices = tuple(slices)

            hdu.data = hdu.data[slices[::-1]]

            if dimensions[1] < dimensions[0]:
                hdu.data = hdu.data.transpose()

        else:

            message = '''
    Attempted to read in %i-dimensional FITS cube, but
    dimensions and slices were not specified. Please specify these
    using the dimensions= and slices= argument. The cube dimensions
    are:\n\n''' % len(shape)

            for i in range(1, len(shape) + 1):

                message += " " * 10
                message += " %s %i\n" % (hdu.header["CTYPE%i" % i],
                                         hdu.header["NAXIS%i" % i])

            raise Exception(message)

        return hdu
{'fraction_non_alphanumeric': 0.12016460905349795, 'fraction_numerical': 0.012071330589849109, 'mean_word_length': 1.8663522012578617, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5782302', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1093, 'n_words': 300}