<commit_before>#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Utilities for FFT computation and visualization
"""
import numpy as np
import scipy.signal
import functools

__all__ = [
    "sine_wave",
    "cosine_wave",
    "square_wave",
    "triangle_wave",
    "sawtooth",
    "inverse_sawtooth",
]


def _generate_wave(genfn, frequency, samplerate, amplitude=1., length=1., phaseshift=0, offset=0):
    """
    Generate a wave using a given function of a specific frequency of a specific length.

    :param frequency A np.sin-like generator function (period shall be 2*pi)
    :param frequency The frequency in Hz
    :param samplerate The samplerate of the resulting array
    :param amplitude The peak amplitude of the sinewave
    :param length The length of the result in seconds
    :param phaseshift The phaseshift in degrees
    """
    x = np.arange(length * samplerate)
    phaseshift_add = phaseshift * samplerate / (360. * frequency)
    return offset + amplitude * genfn(frequency * (2. * np.pi) * (x + phaseshift_add) / samplerate)

sine_wave = functools.partial(_generate_wave, np.sin)
cosine_wave = functools.partial(_generate_wave, np.cos)
square_wave = functools.partial(_generate_wave, scipy.signal.square)
triangle_wave = functools.partial(_generate_wave,
    functools.partial(scipy.signal.sawtooth, width=0.5))
sawtooth = functools.partial(_generate_wave,
    functools.partial(scipy.signal.sawtooth, width=1))
inverse_sawtooth = functools.partial(_generate_wave,
    functools.partial(scipy.signal.sawtooth, width=0))
<commit_msg>Added EngineerIO for wave generation functions<commit_after>#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Utilities for FFT computation and visualization
"""
import numpy as np
import scipy.signal
import functools
from UliEngineering.EngineerIO import normalize_numeric

__all__ = [
    "sine_wave",
    "cosine_wave",
    "square_wave",
    "triangle_wave",
    "sawtooth",
    "inverse_sawtooth",
]


def _generate_wave(genfn, frequency, samplerate, amplitude=1., length=1., phaseshift=0, offset=0):
    """
    Generate a wave using a given function of a specific frequency of a specific length.

    :param frequency A np.sin-like generator function (period shall be 2*pi)
    :param frequency The frequency in Hz
    :param samplerate The samplerate of the resulting array
    :param amplitude The peak amplitude of the sinewave
    :param length The length of the result in seconds
    :param phaseshift The phaseshift in degrees
    """
    # Normalize text values, e.g. "100 kHz" => 100000.0
    frequency = normalize_numeric(frequency)
    samplerate = normalize_numeric(samplerate)
    amplitude = normalize_numeric(amplitude)
    length = normalize_numeric(length)
    phaseshift = normalize_numeric(phaseshift)
    offset = normalize_numeric(offset)
    # Perform calculations
    x = np.arange(length * samplerate)
    phaseshift_add = phaseshift * samplerate / (360. * frequency)
    return offset + amplitude * genfn(frequency * (2. * np.pi) * (x + phaseshift_add) / samplerate)

sine_wave = functools.partial(_generate_wave, np.sin)
cosine_wave = functools.partial(_generate_wave, np.cos)
square_wave = functools.partial(_generate_wave, scipy.signal.square)
triangle_wave = functools.partial(_generate_wave,
    functools.partial(scipy.signal.sawtooth, width=0.5))
sawtooth = functools.partial(_generate_wave,
    functools.partial(scipy.signal.sawtooth, width=1))
inverse_sawtooth = functools.partial(_generate_wave,
    functools.partial(scipy.signal.sawtooth, width=0))

{'fraction_non_alphanumeric': 0.09876195835678109, 'fraction_numerical': 0.011254924029262802, 'mean_word_length': 4.40273556231003, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '815545', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1114, 'n_words': 296}