<commit_before>"""Module of objects that resemble or contain a profile, i.e. a 1 or 2-D f(x) representation."""
import copy
from functools import lru_cache

import numpy as np
from matplotlib.patches import Circle as mpl_Circle
import matplotlib.pyplot as plt
from scipy import ndimage
from scipy.interpolate import interp1d

from .decorators import value_accept
from .geometry import Point, Circle

LEFT = 'left'
RIGHT = 'right'
VALUE = 'value'
INDEX = 'index'
BOTH = 'both'


def stretch(array, min=0, max=1):
    """'Stretch' the profile to the min and max parameter values.

    Parameters
    ----------
    min : number
        The new minimum of the values
    max : number
        The new maximum value.
    """
    old_min = array.min()
    old_max = array.max()
    old_range = old_max - old_min
    stretched_array = max - (((max - min) * (old_max - array)) / old_range)
    return stretched_array


class ProfileMixin:
    """A mixin to provide various manipulations of 1D profile data."""

    def invert(self):
        """Invert (imcomplement) the profile."""
        orig_array = self.values
        self.values = -orig_array + orig_array.max() + orig_array.min()

    def normalize(self, norm_val='max'):
        """Normalize the profile to the given value.

        Parameters
        ----------
        norm_val : str, number
            If a string, must be 'max', which normalizes the values to the maximum value.
            If a number, normalizes all values to that number.
        """
        if norm_val == 'max':
            val = self.values.max()<commit_msg>fixed stretch function<commit_after>"""Module of objects that resemble or contain a profile, i.e. a 1 or 2-D f(x) representation."""
import copy
from functools import lru_cache

import numpy as np
from matplotlib.patches import Circle as mpl_Circle
import matplotlib.pyplot as plt
from scipy import ndimage
from scipy.interpolate import interp1d

from .decorators import value_accept
from .geometry import Point, Circle

LEFT = 'left'
RIGHT = 'right'
VALUE = 'value'
INDEX = 'index'
BOTH = 'both'


def stretch(array, min=0, max=1, fill_dtype=None):
    """'Stretch' the profile to the fit a new min and max value and interpolate in between.
    From: http://www.labri.fr/perso/nrougier/teaching/numpy.100/  exercise #17

    Parameters
    ----------
    min : number
        The new minimum of the values
    max : number
        The new maximum value.
    fill_dtype : numpy data type
        If None (default), the array will be stretched to the passed min and max.
        If a numpy data type (e.g. np.int16), the array will be stretched to fit the full range of values
        of that data type. If a value is given for this parameter, it overrides ``min`` and ``max``.
    """
    new_max = max
    new_min = min
    if fill_dtype is not None:
        di = np.iinfo(fill_dtype)
        new_max = di.max
        new_min = di.min
    # perfectly normalize the array (0..1)
    stretched_array = (array - array.min())/(array.max() - array.min())
    # stretch normalized array to new max/min
    stretched_array *= new_max
    stretched_array += new_min
    return stretched_array.astype(array.dtype)


class ProfileMixin:
    """A mixin to provide various manipulations of 1D profile data."""

    def invert(self):
        """Invert (imcomplement) the profile."""
        orig_array = self.values
        self.values = -orig_array + orig_array.max() + orig_array.min()

    def normalize(self, norm_val='max'):
        """Normalize the profile to the given value.

        Parameters
        ----------
        norm_val : str, number
            If a string, must be 'max', which normalizes the values to the maximum value.
            If a number, normalizes all values to that number.
        """
        if norm_val == 'max':
            val = self.values.max()
{'fraction_non_alphanumeric': 0.1005963183821623, 'fraction_numerical': 0.0054446460980036296, 'mean_word_length': 2.6022408963585435, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '1323621', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1126, 'n_words': 434}