<commit_before>from flow import Node
import numpy as np
from scipy.fftpack import dct
from zounds.analyze.psychoacoustics import \
    Chroma as ChromaScale, Bark as BarkScale
from zounds.nputil import safe_log

class FFT(Node):
    
    def __init__(self, needs = None, axis = -1):
        super(FFT,self).__init__(needs = needs)
        self._axis = axis
    
    def _process(self, data):
        transformed = np.fft.rfft(data, axis = self._axis)
        sl = [slice(None) for _ in xrange(len(transformed.shape))]
        sl[self._axis] = slice(1, None)
        yield np.abs(transformed[sl])

class DCT(Node):
    
    def __init__(self, needs = None, axis = -1):
        super(DCT,self).__init__(needs = needs)
        self._axis = axis
    
    def _process(self, data):
        yield dct(data, norm = 'ortho', axis = self._axis)

# TODO: This constructor should not take a samplerate; that information should
# be encapsulated in the data that's passed in
class Chroma(Node):
    
    def __init__(\
         self, 
         needs = None, 
         samplerate = 44100., 
         nbins = 12, 
         a440 = 440.):
        
        super(Chroma,self).__init__(needs = needs)
        self._nbins = nbins
        self._a440 = a440
        self._samplerate = samplerate
        self._chroma_scale = None
    
    def _process(self, data):
        if self._chroma_scale is None:
            self._chroma_scale = ChromaScale(\
                 self._samplerate, data.shape[1] * 2, nbands = self._nbins)
        yield self._chroma_scale.transform(data)

# TODO: This constructor should not take a samplerate; that information should
# be encapsulated in the data that's passed in
class BarkBands(Node):
    <commit_msg>Start migrating nodes defined in spectral over to use ConstantRateTimeSeries<commit_after>from flow import Node
import numpy as np
from scipy.fftpack import dct
from zounds.analyze.psychoacoustics import \
    Chroma as ChromaScale, Bark as BarkScale
from zounds.nputil import safe_log
from zounds.node.timeseries import ConstantRateTimeSeries

class FFT(Node):
    
    def __init__(self, needs = None, axis = -1):
        super(FFT,self).__init__(needs = needs)
        self._axis = axis
    
    def _process(self, data):
        transformed = np.fft.rfft(data, axis = self._axis)
        sl = [slice(None) for _ in xrange(len(transformed.shape))]
        sl[self._axis] = slice(1, None)
        yield ConstantRateTimeSeries(\
             np.abs(transformed[sl]), 
             data.frequency, 
             data.duration)

class DCT(Node):
    
    def __init__(self, needs = None, axis = -1):
        super(DCT,self).__init__(needs = needs)
        self._axis = axis
    
    def _process(self, data):
        yield ConstantRateTimeSeries(\
             dct(data, norm = 'ortho', axis = self._axis),
             data.frequency,
             data.duration)

# TODO: This constructor should not take a samplerate; that information should
# be encapsulated in the data that's passed in
class Chroma(Node):
    
    def __init__(\
         self, 
         needs = None, 
         samplerate = 44100., 
         nbins = 12, 
         a440 = 440.):
        
        super(Chroma,self).__init__(needs = needs)
        self._nbins = nbins
        self._a440 = a440
        self._samplerate = samplerate
        self._chroma_scale = None
    
    def _process(self, data):
        if self._chroma_scale is None:
            self._chroma_scale = ChromaScale(\
                 self._samplerate, data.shape[1] * 2, nbands = self._nbins)
        yield self._chroma_scale.transform(data)

# TODO: This constructor should not take a samplerate; that information should
# be encapsulated in the data that's passed in
class BarkBands(Node):
    
{'fraction_non_alphanumeric': 0.09209475645461805, 'fraction_numerical': 0.012776151184455683, 'mean_word_length': 2.3855855855855856, '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': '3480325', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1130, 'n_words': 327}