<commit_before># -*- coding: utf-8 -*-
"""
Spectral analysis functions for FFR data

@author: <NAME>
"""
import nitime.algorithms as alg
import numpy as np
from math import ceil
import scipy as sci
from scipy import linalg
from .utils import logger, verbose
    
@verbose
def mtplv(x, params, verbose = None):
    """Multitaper Phase-Locking Value
    
    Parameters
    ----------
    x - NumPy Array 
        Input Data (channel x trial x time) or (trials x time)
    params - Dictionary of parameter settings
      params['Fs'] - sampling rate
      
      params['tapers'] - [TW, Number of tapers]
      
      params['fpass'] - Freqency range of interest, e.g. [5, 1000]
      
      params['pad'] - 1 or 0, to pad to the next power of 2 or not
      
      params['itc'] - 1 for ITC, 0 for PLV
    verbose : bool, str, int, or None
        The verbosity of messages to print. If a str, it can be either DEBUG,
        INFO, WARNING, ERROR, or CRITICAL.
        
    Returns
    -------
    (plvtap, f): Tuple
        plvtap - Multitapered phase-locking estimate (channel x frequency)
        
        f - Frequency vector matching plvtap
    """
    print 'The verbose level is', verbose
    logger.info('Running Multitaper PLV Estimation')
    if(len(x.shape) == 3):
        timedim = 2
        trialdim = 1
        nchans = x.shape[0]
        ntrials = x.shape[trialdim]
        logger.info('The data is of format %d channels x %d trials x time',
                    nchans, ntrials)
    elif(len(x.shape) == 2):
        timedim = 1
        trialdim = 0
        ntrials = x.shape[trialdim]
        nchans = 1
        logger.info('The data is of format %d trials x time (single channel)',
                    ntrials)
    else:
        logger.error('Sorry, The data should be a 2 or 3 dimensional array')
        
    # Calculate the tapers
    ntaps = params['tapers'][1]
    TW = params['tapers'][0]
    w,conc = alg.dpss_windows(x.shape[timedim],TW,ntaps)
    
    # Make space for the PLV result
    Fs = params['Fs']
    nfft = int(2**ceil(sci.log2(x.shape[timedim])))
    f = np.arange(0.0,nfft,1.0)*Fs/nfft
    plvtap = np.zeros((ntaps,nchans,nfft))<commit_msg>Improve verbose using decorator module<commit_after># -*- coding: utf-8 -*-
"""
Spectral analysis functions for FFR data

@author: <NAME>
"""
import nitime.algorithms as alg
import numpy as np
from math import ceil
import scipy as sci
from scipy import linalg
from .utils import logger, verbose
    
@verbose
def mtplv(x, params, verbose = None):
    """Multitaper Phase-Locking Value
    
    Parameters
    ----------
    x - NumPy Array 
        Input Data (channel x trial x time) or (trials x time)
    params - Dictionary of parameter settings
      params['Fs'] - sampling rate
      
      params['tapers'] - [TW, Number of tapers]
      
      params['fpass'] - Freqency range of interest, e.g. [5, 1000]
      
      params['pad'] - 1 or 0, to pad to the next power of 2 or not
      
      params['itc'] - 1 for ITC, 0 for PLV
    verbose : bool, str, int, or None
        The verbosity of messages to print. If a str, it can be either DEBUG,
        INFO, WARNING, ERROR, or CRITICAL.
        
    Returns
    -------
    (plvtap, f): Tuple
        plvtap - Multitapered phase-locking estimate (channel x frequency)
        
        f - Frequency vector matching plvtap
    """
    
    logger.info('Running Multitaper PLV Estimation')
    if(len(x.shape) == 3):
        timedim = 2
        trialdim = 1
        nchans = x.shape[0]
        ntrials = x.shape[trialdim]
        logger.info('The data is of format %d channels x %d trials x time',
                    nchans, ntrials)
    elif(len(x.shape) == 2):
        timedim = 1
        trialdim = 0
        ntrials = x.shape[trialdim]
        nchans = 1
        logger.info('The data is of format %d trials x time (single channel)',
                    ntrials)
    else:
        logger.error('Sorry, The data should be a 2 or 3 dimensional array')
        
    # Calculate the tapers
    ntaps = params['tapers'][1]
    TW = params['tapers'][0]
    w,conc = alg.dpss_windows(x.shape[timedim],TW,ntaps)
    
    # Make space for the PLV result
    Fs = params['Fs']
    nfft = int(2**ceil(sci.log2(x.shape[timedim])))
    f = np.arange(0.0,nfft,1.0)*Fs/nfft
    plvtap = np.zeros((ntaps,nchans,nfft))
{'fraction_non_alphanumeric': 0.11267281105990784, 'fraction_numerical': 0.013364055299539171, 'mean_word_length': 2.132034632034632, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3991748', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1402, 'n_words': 465}