<commit_before># -*- coding: utf-8 -*-
from numpy import median
from numpy import where
import numpy as np
from pitchfilter.pitchfilter import PitchFilter
from morty.pitchdistribution import PitchDistribution
from morty.converter import Converter
import matplotlib.pyplot as plt
import matplotlib.ticker
from copy import deepcopy

__author__ = 'hsercanatli'


class TonicLastNote(object):
    def __init__(self, stable_pitch_dev=25, kernel_width=7.5, step_size=7.5,
                 min_freq=64, max_freq=1024, lower_interval_thres=0.965,
                 upper_interval_thres=1.035, min_chunk_size=60):
        self.stable_pitch_dev = stable_pitch_dev  # cents, the max difference
        # between two pitches to be considered the same. Used in tonic
        # octave correction, 25 cents
        self.kernel_width = kernel_width  # cents, kernel width of the pitch
        # distribution, 7-5 cents ~1/3 Holderian comma
        self.step_size = step_size  # cents, step size of the bins of the pitch
        # distribution, 7-5 cents ~1/3 Holderian comma

        self.min_freq = min_freq  # minimum frequency allowed
        self.max_freq = max_freq  # maximum frequency allowed
        self.lower_interval_thres = lower_interval_thres  # the smallest value
        # the interval can stay before a new chunk is formed
        self.upper_interval_thres = upper_interval_thres  # the highest value
        # the interval can stay before a new chunk is formed
        self.min_chunk_size = min_chunk_size  # minimum number of samples to
        # form a chunk

    @staticmethod
    def find_nearest(array, value):
        distance = [abs(element - value) for element in array]
        idx = distance.index(min(distance))
        return array[idx]

    def identify(self, pitch, plot=False):
        """
        Identify the tonic by detecting the last note and extracting the
        frequency
        """
        pitch_sliced = np.array(deepcopy(pitch))

        # trim silence in the end
        sil_trim_len = len(np.trim_zeros(pitch_sliced[:,1], 'b'))  # remove
        pitch_sliced = pitch_sliced[:sil_trim_len, :]  # trailing zeros
<commit_msg>Fixed minor PEP8 violation<commit_after># -*- coding: utf-8 -*-
from numpy import median
from numpy import where
import numpy as np
from pitchfilter.pitchfilter import PitchFilter
from morty.pitchdistribution import PitchDistribution
from morty.converter import Converter
import matplotlib.pyplot as plt
import matplotlib.ticker
from copy import deepcopy

__author__ = 'hsercanatli'


class TonicLastNote(object):
    def __init__(self, stable_pitch_dev=25, kernel_width=7.5, step_size=7.5,
                 min_freq=64, max_freq=1024, lower_interval_thres=0.965,
                 upper_interval_thres=1.035, min_chunk_size=60):
        self.stable_pitch_dev = stable_pitch_dev  # cents, the max difference
        # between two pitches to be considered the same. Used in tonic
        # octave correction, 25 cents
        self.kernel_width = kernel_width  # cents, kernel width of the pitch
        # distribution, 7-5 cents ~1/3 Holderian comma
        self.step_size = step_size  # cents, step size of the bins of the pitch
        # distribution, 7-5 cents ~1/3 Holderian comma

        self.min_freq = min_freq  # minimum frequency allowed
        self.max_freq = max_freq  # maximum frequency allowed
        self.lower_interval_thres = lower_interval_thres  # the smallest value
        # the interval can stay before a new chunk is formed
        self.upper_interval_thres = upper_interval_thres  # the highest value
        # the interval can stay before a new chunk is formed
        self.min_chunk_size = min_chunk_size  # minimum number of samples to
        # form a chunk

    @staticmethod
    def find_nearest(array, value):
        distance = [abs(element - value) for element in array]
        idx = distance.index(min(distance))
        return array[idx]

    def identify(self, pitch, plot=False):
        """
        Identify the tonic by detecting the last note and extracting the
        frequency
        """
        pitch_sliced = np.array(deepcopy(pitch))

        # trim silence in the end
        sil_trim_len = len(np.trim_zeros(pitch_sliced[:, 1], 'b'))  # remove
        pitch_sliced = pitch_sliced[:sil_trim_len, :]  # trailing zeros

{'fraction_non_alphanumeric': 0.06898148148148148, 'fraction_numerical': 0.01597222222222222, 'mean_word_length': 2.9605866177818516, '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': '6866401', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1235, 'n_words': 402}