<commit_before># -*- coding: utf-8 -*-
# """
# - Author: <NAME>
# - E-mail: <EMAIL>
# - Copyright: 2015
# """
"""
Manage power spectral densities measurements.
"""
import pdb

from . import ureg
from . import name_constants as co

from .data_parser import read_PSD_parameter_file
from .data_parser import read_std_data_file
from .data_parser import save_psd_data
from .data_parser import save_psd_params

from .physics import density_H2O
from .physics import drag
from .physics import faxen_factor
from .physics import MATERIALS
from .physics import Material
from .physics import oseen_factor
from .physics import viscosity_H2O
from .physics import dviscosity_H2O

from .plotting import add_plot_to_figure
from .plotting import col_dict

from .utilities import str2u

from collections import OrderedDict

import copy

from inspect import signature

import matplotlib.pyplot as plt

from os.path import join

from scipy import absolute
from scipy import array
from scipy import inf
from scipy import logical_or
from scipy import pi
from scipy import rand
from scipy import randn
from scipy import shape
from scipy import signal
from scipy import sqrt
from scipy import zeros

from scipy.fftpack import fft, ifft, fftfreq

import time

import warnings

#####--------------------------------------------------------------------------
#---- general  ---
#####--------------------------------------------------------------------------

# generate filtered random data
def gen_filtered_data(fun, fs, T_msr, *args, **kwargs):
    """
    Generate filtered random data.

    The function simulates data by calling a random number
    from a normal distribution, which simulates a trapped
    particle with pure white noise. The signal is Fourier-
    transformed and multiplied with the square-root of the given
    filter function. Thus, the filter function must represent the shape
    of a power spectral density. After that it's
    inverse-fourier-transformed.
    The number of data points is fs * T_msr, i.e. the sampling
    frequency times the total measurment time. *args and **kwargs are
    passed to fun.

    Arguments
    ---------
    fun : function
       Filter function, e.g. a low-pass filter.
    fs : float
        Sampling frequency
    T_msr : float
        Measurement time, the total time of the measurement.

    Notes
    -----
    Other arguments and keyword arguments are directly passed to the function.
    """
    N = int(fs * T_msr)

    freq = fftfreq(N, 1/fs)

    xraw = randn(N)
    x = ifft(fft(xraw) * sqrt(fun(freq, *args, **kwargs))).real

    return x<commit_msg>added scaling possibility to gen_filtered_data().<commit_after># -*- coding: utf-8 -*-
# """
# - Author: <NAME>
# - E-mail: <EMAIL>
# - Copyright: 2015
# """
"""
Manage power spectral densities measurements.
"""
import pdb

from . import ureg
from . import name_constants as co

from .data_parser import read_PSD_parameter_file
from .data_parser import read_std_data_file
from .data_parser import save_psd_data
from .data_parser import save_psd_params

from .physics import density_H2O
from .physics import drag
from .physics import faxen_factor
from .physics import MATERIALS
from .physics import Material
from .physics import oseen_factor
from .physics import viscosity_H2O
from .physics import dviscosity_H2O

from .plotting import add_plot_to_figure
from .plotting import col_dict

from .utilities import str2u

from collections import OrderedDict

import copy

from inspect import signature

import matplotlib.pyplot as plt

from os.path import join

from scipy import absolute
from scipy import array
from scipy import inf
from scipy import logical_or
from scipy import pi
from scipy import rand
from scipy import randn
from scipy import shape
from scipy import signal
from scipy import sqrt
from scipy import zeros

from scipy.fftpack import fft, ifft, fftfreq

import time

import warnings

#####--------------------------------------------------------------------------
#---- general  ---
#####--------------------------------------------------------------------------

# generate filtered random data
def gen_filtered_data(fun, fs, T_msr, *args, **kwargs):
    """
    Generate filtered random data.

    The function simulates data by calling a random number
    from a normal distribution, which simulates a trapped
    particle with pure white noise. The signal is Fourier-
    transformed and multiplied with the square-root of the given
    filter function. Thus, the filter function must represent the shape
    of a power spectral density. After that it's
    inverse-fourier-transformed.
    The number of data points is fs * T_msr, i.e. the sampling
    frequency times the total measurment time.

    To also account for the pyhsics, one can provide the following two
    keyword arguments:
    mean : float
        Set the mean of the output data.
    std : float
        Set the standard deviation of the output data.

    All other *args and **kwargs are passed to fun(*args, **kwargs).

    Arguments
    ---------
    fun : function
       Filter function, e.g. a low-pass filter.
    fs : float
        Sampling frequency
    T_msr : float
        Measurement time, the total time of the measurement.
    """
    mean = kwargs.pop('mean') if 'mean' in kwargs else 0.0
    std = kwargs.pop('std') if 'std' in kwargs else 1.0

    N = int(fs * T_msr)

    freq = fftfreq(N, 1/fs)

    xraw = randn(N)
    x = ifft(fft(xraw) * sqrt(fun(freq, *args, **kwargs))).real
    if std != 1.0:
        x_out = x / x.std() * std + mean
    else:
        x_out = x + mean

    return x_out
{'fraction_non_alphanumeric': 0.12162886229683872, 'fraction_numerical': 0.00464368637256653, 'mean_word_length': 2.657740039190072, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2700760', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1583, 'n_words': 653}