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


import numpy as np
from astropy import units as u
from spectral_cube.spectral_cube import BaseSpectralCube
from astropy.convolution import Gaussian1DKernel


def spectral_regrid_cube(cube, channel_width):
    '''
    Spectrally regrid a SpectralCube to a given channel width. Note that, in
    order to ensure the regridded cube covers the same spectral range, the
    smoothed cube may have channels that differ slightly from the given width.
    The number of channels is chosen to be the next lowest integer when
    dividing the original number of channels by the ratio of the new and old
    channel widths.

    Parameters
    ----------
    cube : `~spectral_cube.SpectralCube`
        Spectral cube to regrid.
    channel_width : `~astropy.units.Quantity`
        The width of the new channels. This should be given in equivalent
        spectral units used in the cube, or in pixel units. For example,
        downsampling by a factor of 2 for a cube with a channel width of
        0.1 km/s can be achieved by setting `channel_width` to `2 * u.pix`
        or `0.2 km /s`.

    Returns
    -------
    regridded_cube : `spectral_cube.SpectralCube`
        The smoothed and regridded cube.
    '''

    if not isinstance(cube, BaseSpectralCube):
        raise TypeError("`cube` must be a SpectralCube object.")
<commit_msg>Add a description of the smoothing<commit_after># Licensed under an MIT open source license - see LICENSE


import numpy as np
from astropy import units as u
from spectral_cube.spectral_cube import BaseSpectralCube
from astropy.convolution import Gaussian1DKernel


def spectral_regrid_cube(cube, channel_width):
    '''
    Spectrally regrid a SpectralCube to a given channel width. The data are
    first spectrally smoothed with a Gaussian kernel. The kernel width is
    the target channel width deconvolved from the current channel width
    (http://spectral-cube.readthedocs.io/en/latest/smoothing.html#spectral-smoothing).

    Note that, in order to ensure the regridded cube covers the same spectral
    range, the smoothed cube may have channels that differ slightly from the
    given width. The number of channels is chosen to be the next lowest
    integer when dividing the original number of channels by the ratio of the
    new and old channel widths.

    Parameters
    ----------
    cube : `~spectral_cube.SpectralCube`
        Spectral cube to regrid.
    channel_width : `~astropy.units.Quantity`
        The width of the new channels. This should be given in equivalent
        spectral units used in the cube, or in pixel units. For example,
        downsampling by a factor of 2 for a cube with a channel width of
        0.1 km/s can be achieved by setting `channel_width` to `2 * u.pix`
        or `0.2 km /s`.

    Returns
    -------
    regridded_cube : `spectral_cube.SpectralCube`
        The smoothed and regridded cube.
    '''

    if not isinstance(cube, BaseSpectralCube):
        raise TypeError("`cube` must be a SpectralCube object.")

{'fraction_non_alphanumeric': 0.05970149253731343, 'fraction_numerical': 0.004542504866969501, 'mean_word_length': 2.983204134366925, 'pattern_counts': {'":': 0, '<': 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': '667980', 'n_tokens_mistral': 901, 'n_tokens_neox': 849, 'n_words': 384}