<commit_before>import numpy as np
import pylab as plt


def integrate(x, y, weight, xmin, xmax, vary=None):
    """
    Return integrated flux of array y (already integrated in
    each pixel) with respecto to x, with variance vary and
    weight function weigth between limits xmin and xmax.
    """

    # Keep only elements of x, y, and weight within the interval,
    # include fractional pixels
    deltax = np.diff(x)
    # Reduce x of first element for compatibility with deltax
    x = x[1:]
    cond = (xmin < x + deltax/2.0) * (x - deltax/2.0 <= xmax)

    # Compute fraction of pixel within interval
    fraction_left = 0.5 - (xmin - x[cond])/deltax[cond]
    fraction_right = 0.5 - (x[cond] - xmax)/deltax[cond]

    fraction_left = np.where(fraction_left > 1, 1.0, fraction_left)
    fraction_right = np.where(fraction_right > 1, 1.0, fraction_right)

    fraction = np.minimum(fraction_left, fraction_right)

    # Sum contributions of pixels inside interval, considering fractions
    # when necessary
    summed_y = np.sum(y[1:][cond] * weight[1:][cond] * fraction)<commit_msg>Refactoring<commit_after>import numpy as np
import pylab as plt


def integrate(x, y, weight, xmin, xmax, vary=None):
    """
    Return integrated flux of array y (already integrated in
    each pixel) with respecto to x, with variance vary and
    weight function weigth between limits xmin and xmax.
    """

    # Keep only elements of x, y, and weight within the interval,
    # include fractional pixels
    deltax = np.diff(x)
    # Reduce x of first element for compatibility with deltax
    x = x[1:]
    # cond = (xmin < x + deltax/2.0) * (x - deltax/2.0 <= xmax)
    cond = xmin - deltax/2.0 < x <= xmax + deltax/2.0

    # Compute fraction of pixel within interval
    fraction_left = 0.5 - (xmin - x[cond])/deltax[cond]
    fraction_right = 0.5 - (x[cond] - xmax)/deltax[cond]

    fraction_left = np.where(fraction_left > 1, 1.0, fraction_left)
    fraction_right = np.where(fraction_right > 1, 1.0, fraction_right)

    fraction = np.minimum(fraction_left, fraction_right)

    # Sum contributions of pixels inside interval, considering fractions
    # when necessary
    summed_y = np.sum(y[1:][cond] * weight[1:][cond] * fraction)
{'fraction_non_alphanumeric': 0.10669642857142857, 'fraction_numerical': 0.016964285714285713, 'mean_word_length': 3.228301886792453, 'pattern_counts': {'":': 0, '<': 9, '<?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': '3030412', 'n_tokens_mistral': 759, 'n_tokens_neox': 711, 'n_words': 239}