<commit_before>#!/usr/bin/env python
"""
fill_tony_file.py

Fill in missing time frames in a Tony file, write the output to file.

Created by <NAME> <<EMAIL>>
and <NAME> <<EMAIL>>

This code is released as part of the MedleyDB library for working
with the MedleyDB dataset: http://marl.smusic.nyu.edu/medleydb. 

This code is a component of the work presented in the following publication:

<NAME>, <NAME>, <NAME>, <NAME>, <NAME> and <NAME>,
"MedleyDB: A Multitrack Dataset for Annotation-Intensive MIR Research", in
15th International Society for Music Information Retrieval Conference,
Taipei, Taiwan, Oct. 2014.
"""

import os
import numpy as np
import csv
import argparse

HOP = 256.0 #Tony default hop size
FS = 44100.0 #Tony default output sample rate


def read_tony_file(fpath):
    """Read a tony-generated csv file.

    Parameters
    ----------
    fpath : str
        Path to tony-generated csv file.

    Returns
    -------
    tony_f0 : array
        Array of tony-generated f0 values and corresponding time stamps.
    """
    assert os.path.exists(fpath), "File path does not exist."

    data_lines = [line.strip() for line in open(fpath)]
    tony_f0 = []
    for line in data_lines:
        time, f_0 = line.split(',')[0:2]
        tony_f0.append([float(time), float(f_0)])
    return tony_f0


def get_time_stamps(total_duration):
    """Get a list of evenly spaced time stamps based on Tony's parameters.

    Parameters
    ----------
    total_duration : float
        Length (in seconds) of annotation's corresponding audio file.

    Returns
    -------
    time_stamps : array
        Array of evenly spaced time stamps spanning the entire annotation.
    """
    n_stamps = int(np.ceil((total_duration*FS)/HOP))
    return np.array(range(n_stamps))*(HOP/FS)


def make_blank_f0_sequence(total_duration):<commit_msg>changed read function to use csv package<commit_after>#!/usr/bin/env python
"""
fill_tony_file.py

Fill in missing time frames in a Tony file, write the output to file.

Created by <NAME> <<EMAIL>>
and <NAME> <<EMAIL>>

This code is released as part of the MedleyDB library for working
with the MedleyDB dataset: http://marl.smusic.nyu.edu/medleydb. 

This code is a component of the work presented in the following publication:

<NAME>, <NAME>, <NAME>, <NAME>, <NAME> and <NAME>,
"MedleyDB: A Multitrack Dataset for Annotation-Intensive MIR Research", in
15th International Society for Music Information Retrieval Conference,
Taipei, Taiwan, Oct. 2014.
"""

import os
import numpy as np
import csv
import argparse

HOP = 256.0 #Tony default hop size
FS = 44100.0 #Tony default output sample rate


def read_tony_file(fpath):
    """Read a tony-generated csv file.

    Parameters
    ----------
    fpath : str
        Path to tony-generated csv file.

    Returns
    -------
    tony_f0 : array
        Array of tony-generated f0 values and corresponding time stamps.
    """

    assert os.path.exists(fpath), "File path does not exist."

    with open(fpath) as f_handle:
        tony_f0 = []
        linereader = csv.reader(f_handle)
        for line in linereader:
            tony_f0.append([float(val) for val in line])
    return tony_f0


def get_time_stamps(total_duration):
    """Get a list of evenly spaced time stamps based on Tony's parameters.

    Parameters
    ----------
    total_duration : float
        Length (in seconds) of annotation's corresponding audio file.

    Returns
    -------
    time_stamps : array
        Array of evenly spaced time stamps spanning the entire annotation.
    """
    n_stamps = int(np.ceil((total_duration*FS)/HOP))
    return np.array(range(n_stamps))*(HOP/FS)


def make_blank_f0_sequence(total_duration):
{'fraction_non_alphanumeric': 0.10592991913746631, 'fraction_numerical': 0.01293800539083558, 'mean_word_length': 3.060175054704595, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '5417152', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1125, 'n_words': 407}