<commit_before># Licensed under an MIT open source license - see LICENSE

from astropy.io.fits import PrimaryHDU
import numpy as np
import astropy.units as u
import re
import warnings

try:
    from spectral_cube import Projection, Slice
    SPECTRALCUBE_INSTALL = True
except ImportError:
    SPECTRALCUBE_INSTALL = False


allowed_types = ["numpy.ndarray", "astropy.io.fits.PrimaryHDU",
                 "spectral_cube.Projection", 'spectral_cube.Slice',
                 "astropy.units.Quantity"]


def input_data(data):
    '''
    Accept a variety of input data forms and return those expected by the
    various statistics.

    Parameters
    ----------
    data : astropy.io.fits.PrimaryHDU, SpectralCube,
           spectral_cube.LowerDimensionalObject, np.ndarray or a tuple/list
           with the data and the header
        Data to be used with a given statistic or distance metric. no_header
        must be enabled when passing only an array in.

    Returns
    -------
    ouput_data : tuple or np.ndarray
        A tuple containing the data and the header. Or an array when no_header
        is enabled.
    '''

    if isinstance(data, PrimaryHDU):
        squeeze_data = data.data.squeeze()
        if 'BUNIT' in data.header:
            unit = convert_bunit(data.header['BUNIT'])
        else:
            unit = u.dimensionless_unscaled
        output_data = {"data": squeeze_data * unit,
                       "header": data.header}

    elif isinstance(data, Projection) or isinstance(data, Slice):
        # spectral-cube has dimensionality checks
        output_data = (data, data.header)

    elif isinstance(data, np.ndarray) or isinstance(data, u.Quantity):
        squeeze_data = data.data.squeeze()
        if not hasattr(data, 'unit'):
            unit = u.dimensionless_unscaled
            squeeze_data = squeeze_data * unit
        output_data = {"data": squeeze_data}
    else:<commit_msg>Return quantity from sc lower dim objects<commit_after># Licensed under an MIT open source license - see LICENSE

from astropy.io.fits import PrimaryHDU
import numpy as np
import astropy.units as u
import re
import warnings

try:
    from spectral_cube import Projection, Slice
    SPECTRALCUBE_INSTALL = True
except ImportError:
    SPECTRALCUBE_INSTALL = False


allowed_types = ["numpy.ndarray", "astropy.io.fits.PrimaryHDU",
                 "spectral_cube.Projection", 'spectral_cube.Slice',
                 "astropy.units.Quantity"]


def input_data(data):
    '''
    Accept a variety of input data forms and return those expected by the
    various statistics.

    Parameters
    ----------
    data : astropy.io.fits.PrimaryHDU, SpectralCube,
           spectral_cube.LowerDimensionalObject, np.ndarray or a tuple/list
           with the data and the header
        Data to be used with a given statistic or distance metric. no_header
        must be enabled when passing only an array in.

    Returns
    -------
    ouput_data : tuple or np.ndarray
        A tuple containing the data and the header. Or an array when no_header
        is enabled.
    '''

    if isinstance(data, PrimaryHDU):
        squeeze_data = data.data.squeeze()
        if 'BUNIT' in data.header:
            unit = convert_bunit(data.header['BUNIT'])
        else:
            unit = u.dimensionless_unscaled
        output_data = {"data": squeeze_data * unit,
                       "header": data.header}

    elif isinstance(data, Projection) or isinstance(data, Slice):
        # spectral-cube has dimensionality checks
        output_data = (data.quantity, data.header)

    elif isinstance(data, np.ndarray) or isinstance(data, u.Quantity):
        squeeze_data = data.data.squeeze()
        if not hasattr(data, 'unit'):
            unit = u.dimensionless_unscaled
            squeeze_data = squeeze_data * unit
        output_data = {"data": squeeze_data}
    else:
{'fraction_non_alphanumeric': 0.0835260858391159, 'fraction_numerical': 0.0, 'mean_word_length': 2.475, 'pattern_counts': {'":': 6, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3269578', 'n_tokens_mistral': 1134, 'n_tokens_neox': 1096, 'n_words': 347}