<commit_before># Licensed under a 3-clause BSD style license - see LICENSE.rst
"""Functions to calculate lags."""

from __future__ import (absolute_import, unicode_literals, division,
                        print_function)

from .mp_fspec import mp_read_fspec
from .mp_io import MP_FILE_EXTENSION, mp_save_data, mp_load_data
import numpy as np
import logging
import os


def mp_calc_lags(freqs, cpds, pds1, pds2, n_chunks, rebin):
    """Calculate time lags."""
    lags = np.angle(cpds) / (2 * np.pi * freqs)
    sigcpd = np.absolute(cpds)

    rawcof = (sigcpd) ** 2 / ((pds1) * (pds2))

    dum = (1. - rawcof) / (2. * rawcof)

    lagse = np.sqrt(dum / n_chunks / rebin) / (2 * np.pi * freqs)

    bad = np.logical_or(lagse != lagse, lags != lags)

    if np.any(bad):
        logging.error('Bad element(s) in lag or lag error array:')
        fbad = freqs[bad]
        lbad = lags[bad]
        lebad = lagse[bad]
        cbad = cpds[bad]
        p1bad = pds1[bad]
        p2bad = pds2[bad]

        for i, f in enumerate(fbad):<commit_msg>Most docstrings are now compliant with the Astropy standard<commit_after># Licensed under a 3-clause BSD style license - see LICENSE.rst
"""Functions to calculate lags."""

from __future__ import (absolute_import, unicode_literals, division,
                        print_function)

from .mp_fspec import mp_read_fspec
from .mp_io import MP_FILE_EXTENSION, mp_save_data, mp_load_data
import numpy as np
import logging
import os


def mp_calc_lags(freqs, cpds, pds1, pds2, n_chunks, rebin):
    """Calculate time lags.

    Parameters
    ----------
    freqs : array-like
        The frequency array
    cpds : array-like
        The cross power spectrum
    pds1 : array-like
        The PDS of the first channel
    pds2 : array-like
        The PDS of the second channel
    n_chunks : int or array-like
        The number of PDSs averaged
    rebin : int or array-like
        The number of bins averaged to obtain each bin

    Returns
    -------
    lags : array-like
        The lags spectrum at frequencies corresponding to freqs
    lagse : array-like
        The errors on `lags`
    """
    lags = np.angle(cpds) / (2 * np.pi * freqs)
    sigcpd = np.absolute(cpds)

    rawcof = (sigcpd) ** 2 / ((pds1) * (pds2))

    dum = (1. - rawcof) / (2. * rawcof)

    lagse = np.sqrt(dum / n_chunks / rebin) / (2 * np.pi * freqs)

    bad = np.logical_or(lagse != lagse, lags != lags)

    if np.any(bad):
        logging.error('Bad element(s) in lag or lag error array:')
        fbad = freqs[bad]
        lbad = lags[bad]
        lebad = lagse[bad]
        cbad = cpds[bad]
        p1bad = pds1[bad]
        p2bad = pds2[bad]

        for i, f in enumerate(fbad):
{'fraction_non_alphanumeric': 0.10869565217391304, 'fraction_numerical': 0.01105379513633014, 'mean_word_length': 2.376865671641791, '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': '7107328', 'n_tokens_mistral': 990, 'n_tokens_neox': 947, 'n_words': 284}